Virtual columns
Sometimes your data source may not be in quite the format you need for your visualisation. For instance, say that you'd like to include a functioning link in a table or tooltip. The solution is to create a "virtual column".
A virtual column can be built from any existing values that exist as a column in the data. So, if your data source contains a column titled Title
and a column titled URL
you could build a new column named Link
using e.g.:
columns:
- name: 'Link'
template: '<a href="{{ URL }}">{{ Title }}</a>'
Virtual columns must have name
and template
properties. The template
can make use of string templates, filter functions, and any existing columns in the data.
For example, let's create a new Tooltip contents
column:
columns:
- name: 'Tooltip contents'
template: '{{ name }}: {{ value | toLocaleString() }}'
This new column is built from existing name
and value
columns but we pass the value
into the filter toLocaleString()
to format it. The new column can be referenced elsewhere using Tooltip contents
in the same way as you would any pre-existing column in the data. You could have achieved the same result by creating this content directly in the data file but using virtual columns may help to keep that file cleaner.
Defining virtual columns
is also a very simple way to rename an exisiting column heading if you need to.