8000 Expose the node alignment property for Sankey plots by adamreeve · Pull Request #6800 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Expose the node alignment property for Sankey plots #6800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Sankey node align property
  • Loading branch information
adamreeve committed Nov 28, 2023
commit bd525ea600d414cfe631620b503e17ae049de748
6 changes: 6 additions & 0 deletions src/traces/sankey/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ var attrs = module.exports = overrideAll({
description: 'Variables `sourceLinks` and `targetLinks` are arrays of link objects.',
keys: ['value', 'label']
}),
align: {
valType: 'enumerated',
values: ['justify', 'left', 'right', 'center'],
dflt: 'justify',
description: 'Sets the alignment method used to position the nodes along the horizontal axis.'
},
description: 'The nodes of the Sankey plot.'
},

Expand Down
1 change: 1 addition & 0 deletions src/traces/sankey/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerceNode('hoverinfo', traceIn.hoverinfo);
handleHoverLabelDefaults(nodeIn, nodeOut, coerceNode, hoverlabelDefault);
coerceNode('hovertemplate');
coerceNode('align');

var colors = layout.colorway;

Expand Down
7 changes: 7 additions & 0 deletions src/traces/sankey/render.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function sankeyModel(layout, d, traceIndex) {
var horizontal = trace.orientation === 'h';
var nodePad = trace.node.pad;
var nodeThickness = trace.node.thickness;
var nodeAlign = {
'justify': d3Sankey.sankeyJustify,
'left': d3Sankey.sankeyLeft,
'right': d3Sankey.sankeyRight,
'center': d3Sankey.sankeyCenter
}[trace.node.align];

var width = layout.width * (domain.x[1] - domain.x[0]);
var height = layout.height * (domain.y[1] - domain.y[0]);
Expand All @@ -61,6 +67,7 @@ function sankeyModel(layout, d, traceIndex) {
.nodeId(function(d) {
return d.pointNumber;
})
.nodeAlign(nodeAlign)
.nodes(nodes)
.links(links);

Expand Down
12 changes: 12 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -44358,6 +44358,18 @@
"valType": "string"
},
"node": {
"align": {
"description": "Sets the alignment method used to position the nodes along the horizontal axis.",
"dflt": "justify",
"editType": "calc",
"valType": "enumerated",
"values": [
"justify",
"left",
"right",
"center"
]
},
"color": {
"arrayOk": true,
"description": "Sets the `node` color. It can be a single value, or an array for specifying color for each `node`. If `node.color` is omitted, then the default `Plotly` color palette will be cycled through to have a variety of colors. These defaults are not fully opaque, to allow some visibility of what is beneath the node.",
Expand Down
0