JavaScript Expressions
When: applicable for fields that support data-based attribute values.
Consider that LabelFontWeight
, Offset
, TextAngle
attributes accept an expression that's evaluated using data. Below are valid examples:
Attribute |
Value |
Description |
Alternative value |
LabelFontWeight |
datum['y'] > 20 ? 'bold' : 'normal' |
Here, y is a data column. Font weight is set as bold for arcs with values greater than 20 otherwise as normal weight. |
'normal' (or 'bold' or other acceptable font-weight value) which sets all text to normal font weight. |
Offset |
datum['y'] > 10 ? 10 : 50 |
Here, y is a data column. Radial offset (in pixels) is evaluated to 50 if a specific arc's value is greater than 10. |
10 (or any other value) which applies offset to all text elements. |
TextAngle |
datum['y'] < 10 ? 0 : -10 |
Here, y is a data column. Text Angle is evaluated to -10 degrees for values greater than and equal to 10. |
-10 (or any other value) which rotates all text by -10 degrees. |
All these can be read as:
condition ? value_if_true : value_if_false
.