Skip to content

Commit 1dcee93

Browse files
authored
Merge pull request #3750 from plotly/sankey-uirevision-groups
sankey: support uirevision for node.groups
2 parents 636a356 + a65bdc8 commit 1dcee93

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/plot_api/plot_api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,7 @@ var traceUIControlPatterns = [
25032503
// "visible" includes trace.transforms[i].styles[j].value.visible
25042504
{pattern: /(^|value\.)visible$/, attr: 'legend.uirevision'},
25052505
{pattern: /^dimensions\[\d+\]\.constraintrange/},
2506-
{pattern: /^node\.(x|y)/}, // for Sankey nodes
2506+
{pattern: /^node\.(x|y|groups)/}, // for Sankey nodes
25072507
{pattern: /^level$/}, // for Sunburst traces
25082508

25092509
// below this you must be in editable: true mode

test/jasmine/tests/sankey_test.js

+43
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var mockCircular = require('@mocks/sankey_circular.json');
1010
var mockCircularLarge = require('@mocks/sankey_circular_large.json');
1111
var mockXY = require('@mocks/sankey_x_y.json');
1212
var Sankey = require('@src/traces/sankey');
13+
var Registry = require('@src/registry');
1314

1415
var createGraphDiv = require('../assets/create_graph_div');
1516
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -608,6 +609,48 @@ describe('sankey tests', function() {
608609
.catch(failTest)
609610
.then(done);
610611
});
612+
613+
['0', '1'].forEach(function(finalUIRevision) {
614+
it('on Plotly.react, it preserves the groups depending on layout.uirevision', function(done) {
615+
var uirevisions = ['0', finalUIRevision];
616+
617+
var mockCopy = Lib.extendDeep({}, mockCircular);
618+
mockCopy.layout.uirevision = uirevisions[0];
619+
620+
Plotly.plot(gd, mockCopy)
621+
.then(function() {
622+
// Create a group via guiRestyle
623+
return Registry.call('_guiRestyle', gd, 'node.groups', [[[0, 1]]]);
624+
})
625+
.then(function() {
626+
// Check that the nodes are grouped
627+
expect(gd._fullData[0].node.groups).toEqual([[0, 1]]);
628+
629+
// Change color of nodes
630+
mockCopy = Lib.extendDeep({}, mockCircular);
631+
mockCopy.data[0].node.color = 'orange';
632+
mockCopy.layout.uirevision = uirevisions[1];
633+
return Plotly.react(gd, mockCopy);
634+
})
635+
.then(function() {
636+
if(uirevisions[0] === uirevisions[1]) {
637+
// If uirevision is the same, the groups should stay the same
638+
expect(gd._fullData[0].node.groups).toEqual(
639+
[[0, 1]],
640+
'should stay the same because uirevision did not change'
641+
);
642+
} else {
643+
// If uirevision changed, the groups should be empty as in the figure obj
644+
expect(gd._fullData[0].node.groups).toEqual(
645+
[],
646+
'should go back to its default because uirevision changed'
647+
);
648+
}
649+
})
650+
.catch(failTest)
651+
.then(done);
652+
});
653+
});
611654
});
612655

613656
describe('Test hover/click interactions:', function() {

0 commit comments

Comments
 (0)