感染爆発は起こらないことが閣議決定されました[Tableau] あなたのvizにフィットする所望の位置、回転角のテキスト画像を作成する方法 / How to create a text image with the desired position and rotation angle that fits your viz.

2021年12月15日

今回は先日開催されたJTUG(Japan Tableau User Group)冬におけるLM-7の講演内容を一部アップデートしてTableauのマニアックなテクニックを紹介する。なお、本手法は講演内容を考えているときに試行錯誤して見出したものなので、先に思いついている人がいなければ世界初のテクニックとなるはずだ。まず完成版のvizを示す。

This entry introduces a maniacal technique of Tableau by updating a part of the content of my presentation at the recent JTUG (Japan Tableau User Group) Winter. This technique was discovered through trial and error when I was thinking about the content of the talk, so it should be the world's first technique if no one else has thought of it before me. First of all, I will show the completed version of the viz.

viz03


一見簡単そうに見えるが、このvizは通常の方法では作れない。形状に画像を割り当て、色に所望のフィールドを適用させればできる気がする。

At first glance it looks simple, but this viz cannot be created in the usual way. It may seem that it can be done by assigning an image to the shape and applying the desired field to the color.

viz04


しかし、実際にやってみると、画像が単色で塗りつぶされてしまう。これは、画像のRGBチャネルがすべて指定した色で置き換えられるためだ。ただし、透明度を扱うアルファチャネルは維持されている。

However, when I actually try it, the image is filled with a single color. This is because all RGB channels of the image are replaced by the specified color. However, the alpha channel, which controls the transparency, is not changed.

viz05


つまり、冒頭のようなvizを実現するには、画像のハイライト色である白色を透明度に置き換えたベース画像を用意し、背景をマスクする白色のマスク画像と重ねて利用すれば良いことになる。もちろん、背景が白色であるならばマスク画像は不要だ。

In other words, to achieve the viz shown at the beginning of this article, you should prepare a base image in which the highlight color of the image, white, is replaced by transparency, and use it overlaid with a white mask image that masks the background. Of course, if the background is white, the mask image is unnecessary.

viz06


ベース画像の作り方 How to create a base image


画像の作成には適当な画像編集ソフトがあれば良い。Photoshopなども利用可能だが、ここでは無料で利用可能なGIMP (GNU Image Manipulation Program)を用いた方法を紹介する。

To create an image, all you need is a suitable image editing software, such as Photoshop, but here I' ll introduce a method using GIMP (GNU Image Manipulation Program), which is available for free.
  1. GIMPに画像を読み込み、[画像] > [内容で切り抜き] から周囲の余白を削る。
    Load the image into GIMP and select [Image] > [Crop to context] to crop the surrounding margins.
    gimp01

  2. [色] > [色を透明度に...] を選択し、白色を透明度に置き換える。
    Select [Colors] > [Color to Alpha...] and replace the white color with transparency.
    gimp02

  3. [ファイル] > [エクスポート...]を選択し、マイ Tableau リポジトリ\形状\ 以下に適当なフォルダ(例えばEarth)を作成し、"base.png"として保存する。透明度を維持するために画像の種類はPNGでなければならない。
    Select [File] > [Export As...] and create a folder (e.g. Earth) under My Tableau Repository\Shapes\ and save it as "base.png".The image type must be PNG to keep transparency.

マスク画像の作り方 How to create a mask image

  1. アンドゥして透明度をもとに戻す。
    Undo to restore the transparency.
  2. [色] > [明るさ-コントラスト...] ([Colors] > [Brightness-Contrast...])を選択する。
    Select [Color] > [Brightness-Contrast...].
  3. 明るさとコントラストを最高値の127まで上げると、白色のマスク画像ができる。
    By increasing the brightness and contrast to the highest value of 127, a white mask image is created.
    gimp03

  4. [ファイル] > [エクスポート...]を選択し、先ほどと同じフォルダに、"mask.png"として保存する。
    Select [File] > [Export As...] and save the file as "mask.png" in the same folder as before.

NOTE: 後になって、マスク画像をわざわざ作らなくても、元画像を使えば良いことに気づいた。Tableauにおいて元画像の色に白を指定すればいいのだ。
Later, I realized that I didn't need to create a mask image, I could just use the original image and specify white as the color of the original image in Tableau.

Tableau上での利用 Use on Tableau

Tableauでは二重軸を用いてベース画像とマスク画像を重ねて利用する。ここではプレースホルダを利用した重ね方だけ紹介する。
In Tableau, the base image and mask image can be stacked using the dual axis. In this section, I will only introduce the method of stacking using placeholders.
  1. [PH]という計算フィールドを作成し、min(1)とする。
    Create a calculated field named [PH] and set it to min(1).
  2. [PH]を2つ列シェルフに配置する。
    Place two [PH] on the column shelf.
  3. マークタイプを形状とし、片方にマスク画像、もう片方にベース画像を設定する。
    Set the mark type as shape, and set the mask image on one side and the base image on the other.
    tableau01

  4. 二重軸として、余計なヘッダや線を消す。
    Change to a double axis and remove unnecessary headers and lines.
  5. ベース画像を設定した方の色にメジャーを配置して、色を変化させる。
    Place a measure field in the color of the base image to change the color.
    tableau02


完成版のワークブックは以下からアクセス可能なので確認してみてほしい。この方法によってvizの表現力を大きく広げることができるようになる。ぜひ活用してもらいたい。

The completed workbook can be accessed below, so please check it out. This method will greatly expand the expressive power of the viz. I hope you will make use of it.



lunarmodule7 at 19:36│Comments(0)││Tableau 

コメントする

名前
 
  絵文字
 
 
感染爆発は起こらないことが閣議決定されました[Tableau] あなたのvizにフィットする所望の位置、回転角のテキスト画像を作成する方法 / How to create a text image with the desired position and rotation angle that fits your viz.