Handling long Sankey labels
By default, labels on a Sankey Diagram will be truncated with an ellipsis if they are longer than 150 pixels. This tutorial explores other options for handling long labels.
Base chart
Section titled “Base chart”Here’s a Sankey Diagram with some overly long node names.
All labels are cut off and not overly informative. Let’s see how we can fix that.
Increasing label width
Section titled “Increasing label width”First option is to give labels more space. We can do that by increasing the default width of 150 pixels.
chart.nodes.template.nameLabel.label.width = 200;chart.nodes.template.nameLabel.label.width = 200;{ // ... "nodes": { "nameLabel": { "label": { "width": 200 } } }}Now we can see that some labels fit, some don’t.
Let’s explore other options.
Wrapping labels
Section titled “Wrapping labels”We can keep increasing the width until ultimately all labels fit. However, very long labels a) might not fit into chart width, and b) are not easy to read.
In this case, wrapping labels instead of truncating them might be a better option.
chart.nodes.template.nameLabel.label.truncate = false;chart.nodes.template.nameLabel.label.wrap = true;chart.nodes.template.nameLabel.label.truncate = false;chart.nodes.template.nameLabel.label.wrap = true;{ // ... "nodes": { "nameLabel": { "label": { "truncate": false, "wrap": true } } }}