Skip to content

Commit 17f7013

Browse files
authored
Merge pull request #6800 from adamreeve/sankey-align
Expose the node alignment property for Sankey plots
2 parents 7234c08 + 0516c4a commit 17f7013

15 files changed

+158
-0
lines changed

draftlogs/6800_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add `align` option to Sankey nodes to control horizontal alignment [[#6800](https://github.com/plotly/plotly.js/pull/6800)]

src/traces/sankey/attributes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ var attrs = module.exports = overrideAll({
164164
description: 'Variables `sourceLinks` and `targetLinks` are arrays of link objects.',
165165
keys: ['value', 'label']
166166
}),
167+
align: {
168+
valType: 'enumerated',
169+
values: ['justify', 'left', 'right', 'center'],
170+
dflt: 'justify',
171+
description: 'Sets the alignment method used to position the nodes along the horizontal axis.'
172+
},
167173
description: 'The nodes of the Sankey plot.'
168174
},
169175

src/traces/sankey/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3434
coerceNode('hoverinfo', traceIn.hoverinfo);
3535
handleHoverLabelDefaults(nodeIn, nodeOut, coerceNode, hoverlabelDefault);
3636
coerceNode('hovertemplate');
37+
coerceNode('align');
3738

3839
var colors = layout.colorway;
3940

src/traces/sankey/render.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ function sankeyModel(layout, d, traceIndex) {
3535
var horizontal = trace.orientation === 'h';
3636
var nodePad = trace.node.pad;
3737
var nodeThickness = trace.node.thickness;
38+
var nodeAlign = {
39+
justify: d3Sankey.sankeyJustify,
40+
left: d3Sankey.sankeyLeft,
41+
right: d3Sankey.sankeyRight,
42+
center: d3Sankey.sankeyCenter
43+
}[trace.node.align];
3844

3945
var width = layout.width * (domain.x[1] - domain.x[0]);
4046
var height = layout.height * (domain.y[1] - domain.y[0]);
@@ -61,6 +67,7 @@ function sankeyModel(layout, d, traceIndex) {
6167
.nodeId(function(d) {
6268
return d.pointNumber;
6369
})
70+
.nodeAlign(nodeAlign)
6471
.nodes(nodes)
6572
.links(links);
6673

29.9 KB
Loading
33.7 KB
Loading
29.7 KB
Loading
33 KB
Loading
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"data": [
3+
{
4+
"type": "sankey",
5+
"node": {
6+
"label": ["0", "1", "2", "3", "4", "5"],
7+
"align": "center"
8+
},
9+
"link": {
10+
"source": [
11+
0, 1, 4, 2, 1
12+
],
13+
"target": [
14+
1, 4, 5, 4, 3
15+
],
16+
"value": [
17+
4, 2, 3, 1, 2
18+
]
19+
}
20+
}],
21+
"layout": {
22+
"title": {"text": "Sankey with center aligned nodes"},
23+
"width": 800,
24+
"height": 800
25+
}
26+
}

0 commit comments

Comments
 (0)