Skip to content

Add labels on sankey links#7888

Open
wf-r wants to merge 3 commits into
plotly:masterfrom
wf-r:text_on_sankey_links
Open

Add labels on sankey links#7888
wf-r wants to merge 3 commits into
plotly:masterfrom
wf-r:text_on_sankey_links

Conversation

@wf-r

@wf-r wf-r commented Jul 3, 2026

Copy link
Copy Markdown

Add permanent text labels to Sankey links

What

Adds persistent, always-visible text labels to Sankey links, analogous to the existing node
labels. Five new attributes under link:

Attribute Type Description
link.textinfo flaglist: "label", "value", "none" Which information to show permanently on links
link.texttemplate string / arrayOk Template string, overrides textinfo when set
link.textfont font Font for link labels
link.valueformat string d3 format string for the value component
link.valuesuffix string Unit suffix appended to the formatted value

Why

Link information is currently hover-only, making Sankey diagrams unsuitable for static export
(PNG/SVG/print) wherever flow values or names need to be visible at all times. There is
long-standing community interest in this — see #4746.

External SVG overlays (the current workaround) are fragile: they break on node drags, require
timing hacks after layout transitions, and are excluded from toImage export. Native labels
solve all three problems.

How

Labels are rendered as real SVG <text> elements inside the .sankey group, immediately after
the link paths. This means:

  • The existing group-level orientation transform applies automatically — labels stay upright in
    h and v layouts with no extra handling.
  • Labels follow node drags via the existing updateShapes hook — no separate drag listener
    needed.
  • Labels are included in toImage/PNG/SVG export — no overlay required.
    For circular (backward) links the label anchor reuses the same circularPathData midpoint as
    the hover label, so the position is consistent. Vertical centering on the anchor uses
    dominant-baseline="central".

Template rendering follows the established funnel/pie pattern via Lib.texttemplateString.
Available template variables: %{label}, %{value}, %{valueLabel} (formatted value +
suffix), %{source}, %{target}, %{customdata}.

Backward compatibility

Fully backward compatible. All new attributes default to textinfo: 'none' / texttemplate: '',
so existing figures render identically. No existing tests or baselines are affected.

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant