String templates
Sometimes you may need to construct a simple tooltip
or label
for each data point using attributes in the data. The simplest method would be to create a column in your original data file that contains the text for each tooltip. But you may not have the luxury of editing the original data. In those cases you can use simple text templates to construct a "virtual column" and refer to this column for the tooltip.
We've allowed pattern-based-strings to be defined which will take values from the data using a double curly braces syntax e.g. {{ key }}
. For instance, say the data rows for a visualisation contain the attributes/columns ConstituencyName
and population
. We can build a very simple tooltip string as {{ ConstituencyName }}: {{ population }}
. In this case {{ ConstituencyName }}
will be replaced by that row's ConstituencyName
value and {{ population }}
by the population
value.
Filter functions§
You can also use the following filters:
colourScale(scale,min,max)
- get a colour to, for example, use as a background stylecontrastColour
- get a contrasting colour (black or white)multiply(n)
- to multiply a value by nstrftime("%Y-%m-%d")
- convert an ISO8601 date or Unix timestamp into a specific date formattoFixed(n)
- to limit a value to n decimal placestoLocaleString()
- to use the locale's (of the server) preferred formatting for a value
For instance, to convert {{ 1500 }}
to a locale string:
{{ 1500 | toLocaleString("en-GB") }}
Then 1500
becomes 1,500
.