Skip to content

[FEATURE]: Add Bottom-up Sankey Diagram Option #7865

Description

@wf-r

Summary

Sankey supports orientation: 'h' and 'v', where 'v' always renders top-down (sources at the top, flow downward). There is currently no way to render a vertical Sankey bottom-up (sources at the bottom, flow upward), which is a common convention for "stack/build-up" style flow charts.

Proposed change

Extend orientation to accept two explicit vertical values while keeping full backward compatibility:

  • top-down — sources at top, flow downward (new explicit name)
  • bottom-up — sources at bottom, flow upward (new behavior)
  • v — kept as a synonym of top-down; h unchanged; default stays h

The vertical layout is already produced by transposing the horizontal layout via a single group-level SVG transform in sankeyTransform() (matrix(0 1 1 0 0 0), a reflection about y=x). Bottom-up is the vertical mirror of that, achievable with a pure 90° rotation matrix(0 -1 1 0 0 0) plus a + height y-translate. Because nodes, links, and the optional arrowheads are all geometry in the same horizontal reference frame, they rotate together — arrows keep pointing at the target with no extra handling.

Touched files:

  • attributes.js — extend the orientation enum + description.
  • render.js — derive a bottomUp flag, thread it through the trace/node models, branch sankeyTransform(), and adjust the node-label counter-transform (rotate(90) without the scale(-1,1) mirror, so labels stay upright).
  • plot.js — generalize the link-hover check from === 'v' to !== 'h' and mirror the flow axis for bottom-up. (Node hover relies on getBoundingClientRect() and needs no change.)
  • defaults.js — no change (the enum coercion picks up the new values automatically).

Tests

  • Defaults coercion test for the new/legacy orientation values.
  • A render test asserting the group transform matrix per orientation (including v === top-down).

Backward compatibility

Existing figures using 'v'/'h' render identically; only additive enum values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions