From a65bdc87bd2596613ca6b43a15510bef239438ca Mon Sep 17 00:00:00 2001 From: Antoine Roy-Gobeil Date: Tue, 9 Apr 2019 10:39:07 -0400 Subject: [PATCH] sankey: support uirevision for node.groups --- src/plot_api/plot_api.js | 2 +- test/jasmine/tests/sankey_test.js | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 449fdb259c8..35c66506311 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2503,7 +2503,7 @@ var traceUIControlPatterns = [ // "visible" includes trace.transforms[i].styles[j].value.visible {pattern: /(^|value\.)visible$/, attr: 'legend.uirevision'}, {pattern: /^dimensions\[\d+\]\.constraintrange/}, - {pattern: /^node\.(x|y)/}, // for Sankey nodes + {pattern: /^node\.(x|y|groups)/}, // for Sankey nodes {pattern: /^level$/}, // for Sunburst traces // below this you must be in editable: true mode diff --git a/test/jasmine/tests/sankey_test.js b/test/jasmine/tests/sankey_test.js index 7d1f0599459..b0613a0cc1c 100644 --- a/test/jasmine/tests/sankey_test.js +++ b/test/jasmine/tests/sankey_test.js @@ -10,6 +10,7 @@ var mockCircular = require('@mocks/sankey_circular.json'); var mockCircularLarge = require('@mocks/sankey_circular_large.json'); var mockXY = require('@mocks/sankey_x_y.json'); var Sankey = require('@src/traces/sankey'); +var Registry = require('@src/registry'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); @@ -608,6 +609,48 @@ describe('sankey tests', function() { .catch(failTest) .then(done); }); + + ['0', '1'].forEach(function(finalUIRevision) { + it('on Plotly.react, it preserves the groups depending on layout.uirevision', function(done) { + var uirevisions = ['0', finalUIRevision]; + + var mockCopy = Lib.extendDeep({}, mockCircular); + mockCopy.layout.uirevision = uirevisions[0]; + + Plotly.plot(gd, mockCopy) + .then(function() { + // Create a group via guiRestyle + return Registry.call('_guiRestyle', gd, 'node.groups', [[[0, 1]]]); + }) + .then(function() { + // Check that the nodes are grouped + expect(gd._fullData[0].node.groups).toEqual([[0, 1]]); + + // Change color of nodes + mockCopy = Lib.extendDeep({}, mockCircular); + mockCopy.data[0].node.color = 'orange'; + mockCopy.layout.uirevision = uirevisions[1]; + return Plotly.react(gd, mockCopy); + }) + .then(function() { + if(uirevisions[0] === uirevisions[1]) { + // If uirevision is the same, the groups should stay the same + expect(gd._fullData[0].node.groups).toEqual( + [[0, 1]], + 'should stay the same because uirevision did not change' + ); + } else { + // If uirevision changed, the groups should be empty as in the figure obj + expect(gd._fullData[0].node.groups).toEqual( + [], + 'should go back to its default because uirevision changed' + ); + } + }) + .catch(failTest) + .then(done); + }); + }); }); describe('Test hover/click interactions:', function() {