diff --git a/src/traces/sankey/attributes.js b/src/traces/sankey/attributes.js index b9144ad0e4c..ccd3a6867d6 100644 --- a/src/traces/sankey/attributes.js +++ b/src/traces/sankey/attributes.js @@ -121,6 +121,15 @@ var attrs = module.exports = overrideAll({ ].join(' ') } }, + align: { + valType: 'enumerated', + values: ['justify', 'left', 'right', 'center'], + dflt: 'justify', + role: 'calc', + description: [ + 'Sets the alignment method used to position the nodes along the horizontal axis.' + ].join(' ') + }, pad: { valType: 'number', arrayOk: false, diff --git a/src/traces/sankey/defaults.js b/src/traces/sankey/defaults.js index c5283910ade..362f6031d71 100644 --- a/src/traces/sankey/defaults.js +++ b/src/traces/sankey/defaults.js @@ -39,6 +39,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; diff --git a/src/traces/sankey/render.js b/src/traces/sankey/render.js index 88b27dbdafc..097a7273164 100644 --- a/src/traces/sankey/render.js +++ b/src/traces/sankey/render.js @@ -32,6 +32,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]); @@ -58,6 +64,7 @@ function sankeyModel(layout, d, traceIndex) { .size(horizontal ? [width, height] : [height, width]) .nodeWidth(nodeThickness) .nodePadding(nodePad) + .nodeAlign(nodeAlign) .nodes(nodes) .links(links); diff --git a/test/image/baselines/sankey_circular_align_right.png b/test/image/baselines/sankey_circular_align_right.png new file mode 100644 index 00000000000..052687e782d Binary files /dev/null and b/test/image/baselines/sankey_circular_align_right.png differ diff --git a/test/image/mocks/sankey_circular_align_right.json b/test/image/mocks/sankey_circular_align_right.json new file mode 100644 index 00000000000..b9a93b44ae4 --- /dev/null +++ b/test/image/mocks/sankey_circular_align_right.json @@ -0,0 +1,27 @@ +{ + "data": [ + { + "type": "sankey", + "node": { + "pad": 5, + "align": "right", + "label": ["0", "1", "2", "3", "4", "5", "6"] + }, + "link": { + "source": [ + 0, 0, 1, 2, 5, 4, 3 + ], + "target": [ + 5, 3, 4, 3, 0, 2, 2 + ], + "value": [ + 1, 2, 1, 1, 1, 1, 1 + ] + } + }], + "layout": { + "title": "Sankey with circular data, aligned right", + "width": 800, + "height": 800 + } +}