From 326cb04f9f1fbf1d0f8133b8e4853ca8b2dd98ee Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 23 Jan 2020 13:54:36 -0500 Subject: [PATCH 1/2] remove invisible pathbar - add test to show/hide pathbar using react --- src/traces/treemap/plot.js | 4 +++ test/jasmine/tests/treemap_test.js | 49 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/traces/treemap/plot.js b/src/traces/treemap/plot.js index 4f2deb49b33..a083e2faef9 100644 --- a/src/traces/treemap/plot.js +++ b/src/traces/treemap/plot.js @@ -103,6 +103,10 @@ function plotOne(gd, cd, element, transitionOpts) { return; } + if(!trace.pathbar.visible) { + selAncestors.remove(); + } + var isRoot = helpers.isHierarchyRoot(entry); var hasTransition = !fullLayout.uniformtext.mode && helpers.hasTransition(transitionOpts); diff --git a/test/jasmine/tests/treemap_test.js b/test/jasmine/tests/treemap_test.js index 45297d53d85..f5788260b2d 100644 --- a/test/jasmine/tests/treemap_test.js +++ b/test/jasmine/tests/treemap_test.js @@ -17,6 +17,7 @@ var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle; var assertHoverLabelContent = customAssertions.assertHoverLabelContent; var checkTextTemplate = require('../assets/check_texttemplate'); +var SLICES_SELECTOR = '.treemaplayer path.surface'; var SLICES_TEXT_SELECTOR = '.treemaplayer text.slicetext'; function _mouseEvent(type, gd, v) { @@ -1889,3 +1890,51 @@ describe('treemap uniformtext', function() { .then(done); }); }); + +describe('treemap pathbar react', function() { + 'use strict'; + + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(destroyGraphDiv); + + it('should show and hide pathbar', function(done) { + var fig = { + data: [{ + type: 'treemap', + parents: ['', 'A', 'B', 'C'], + labels: ['A', 'B', 'C', 'D'], + level: 'C' + }], + layout: {} + }; + + function _assert(msg, exp) { + return function() { + var selection = d3.selectAll(SLICES_SELECTOR); + var size = selection.size(); + + expect(size).toBe(exp, msg); + }; + } + + Plotly.plot(gd, fig) + .then(_assert('default pathbar.visible: true', 4)) + .then(function() { + fig.data[0].pathbar = {visible: false}; + return Plotly.react(gd, fig); + }) + .then(_assert('disable pathbar', 2)) + .then(function() { + fig.data[0].pathbar = {visible: true}; + return Plotly.react(gd, fig); + }) + .then(_assert('enable pathbar', 4)) + .catch(failTest) + .then(done); + }); +}); From 838d1c39c076afca631b42fdfe208fc052fe7434 Mon Sep 17 00:00:00 2001 From: archmoj Date: Mon, 27 Jan 2020 14:44:46 -0500 Subject: [PATCH 2/2] move pathbar.remove call after pathbar.draw --- src/traces/treemap/plot.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/traces/treemap/plot.js b/src/traces/treemap/plot.js index a083e2faef9..a60e1495fdd 100644 --- a/src/traces/treemap/plot.js +++ b/src/traces/treemap/plot.js @@ -103,10 +103,6 @@ function plotOne(gd, cd, element, transitionOpts) { return; } - if(!trace.pathbar.visible) { - selAncestors.remove(); - } - var isRoot = helpers.isHierarchyRoot(entry); var hasTransition = !fullLayout.uniformtext.mode && helpers.hasTransition(transitionOpts); @@ -631,5 +627,7 @@ function plotOne(gd, cd, element, transitionOpts) { hasTransition: hasTransition, strTransform: strTransform }); + } else { + selAncestors.remove(); } }