8000 expose d3sankey.nodeAlign() as attribute node.align · plotly/plotly.js@130cc4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 130cc4c

Browse files
committed
expose d3sankey.nodeAlign() as attribute node.align
1 parent 212a219 commit 130cc4c

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

src/traces/sankey/attributes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ var attrs = module.exports = overrideAll({
121121
].join(' ')
122122
}
123123
},
124+
align: {
125+
valType: 'enumerated',
126+
values: ['justify', 'left', 'right', 'center'],
127+
dflt: 'justify',
128+
role: 'calc',
129+
description: [
130+
'Sets the alignment method used to position the nodes along the horizontal axis.'
131+
].join(' ')
132+
},
124133
pad: {
125134
valType: 'number',
126135
arrayOk: false,

src/traces/sankey/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3939
coerceNode('hoverinfo', traceIn.hoverinfo);
4040
handleHoverLabelDefaults(nodeIn, nodeOut, coerceNode, hoverlabelDefault);
4141
coerceNode('hovertemplate');
42+
coerceNode('align');
4243

4344
var colors = layout.colorway;
4445

src/traces/sankey/render.js

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

3642
var width = layout.width * (domain.x[1] - domain.x[0]);
3743
var height = layout.height * (domain.y[1] - domain.y[0]);
@@ -58,6 +64,7 @@ function sankeyModel(layout, d, traceIndex) {
5864
.size(horizontal ? [width, height] : [height, width])
5965
.nodeWidth(nodeThickness)
6066
.nodePadding(nodePad)
67+
.nodeAlign(nodeAlign)
6168
.nodes(nodes)
6269
.links(links);
6370

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

0 commit comments

Comments
 (0)
0