Skip to content

Commit 506da4c

Browse files
committed
sankey: reset to initial view (x, y and groups)
1 parent a25c1ad commit 506da4c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/components/modebar/buttons.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,18 @@ modeBarButtons.resetSankeyGroup = {
518518
title: function(gd) { return _(gd, 'Ungroup all nodes'); },
519519
icon: Icons.home,
520520
click: function(gd) {
521-
Registry.call('restyle', gd, {
522-
'node.groups': [[]],
523-
});
521+
var aObj = {
522+
'node.groups': [],
523+
'node.x': [],
524+
'node.y': []
525+
};
526+
for(var i = 0; i < gd._fullData.length; i++) {
527+
var viewInitial = gd._fullData[i]._viewInitial;
528+
aObj['node.groups'].push(viewInitial.node.groups.slice());
529+
aObj['node.x'].push(viewInitial.node.x.slice());
530+
aObj['node.y'].push(viewInitial.node.y.slice());
531+
}
532+
Registry.call('restyle', gd, aObj);
524533
}
525534
};
526535

src/traces/sankey/plot.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ module.exports = function plot(gd, calcData) {
127127
var svg = fullLayout._paper;
128128
var size = fullLayout._size;
129129

130+
// stash initial view
131+
for(var i = 0; i < calcData.length; i++) {
132+
if(!gd._fullData[i]._viewInitial) {
133+
var node = gd._fullData[i].node;
134+
gd._fullData[i]._viewInitial = {
135+
node: {
136+
groups: node.groups.slice(),
137+
x: node.x.slice(),
138+
y: node.y.slice()
139+
}
140+
};
141+
}
142+
}
143+
130144
var linkSelect = function(element, d) {
131145
var evt = d.link;
132146
evt.originalEvent = d3.event;

0 commit comments

Comments
 (0)