From b5c2f35d4e14206824f86a4c37b8ff86238ee3a3 Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Mon, 11 Jun 2018 15:29:26 -0400 Subject: [PATCH] fix #2722 - get the right traces in hist calc for cross-trace coupling --- src/traces/histogram/calc.js | 3 ++- test/jasmine/tests/histogram_test.js | 40 ++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/traces/histogram/calc.js b/src/traces/histogram/calc.js index c2d8caa33f6..4cdb97514bf 100644 --- a/src/traces/histogram/calc.js +++ b/src/traces/histogram/calc.js @@ -23,7 +23,7 @@ var oneMonth = require('../../constants/numerical').ONEAVGMONTH; var getBinSpanLabelRound = require('./bin_label_vals'); module.exports = function calc(gd, trace) { - // ignore as much processing as possible (and including in autorange) if bar is not visible + // ignore as much processing as possible (and including in autorange) if not visible if(trace.visible !== true) return; // depending on orientation, set position and size axes and data ranges @@ -435,6 +435,7 @@ function getConnectedHistograms(gd, trace) { for(var i = 0; i < fullData.length; i++) { var tracei = fullData[i]; if(tracei.type === 'histogram' && + tracei.visible === true && tracei.orientation === orientation && tracei.xaxis === xid && tracei.yaxis === yid ) { diff --git a/test/jasmine/tests/histogram_test.js b/test/jasmine/tests/histogram_test.js index be23de532d4..d6728eddb5f 100644 --- a/test/jasmine/tests/histogram_test.js +++ b/test/jasmine/tests/histogram_test.js @@ -11,6 +11,7 @@ var getBinSpanLabelRound = require('@src/traces/histogram/bin_label_vals'); var createGraphDiv = require('../assets/create_graph_div'); var destroyGraphDiv = require('../assets/destroy_graph_div'); var supplyAllDefaults = require('../assets/supply_defaults'); +var failTest = require('../assets/fail_test'); describe('Test histogram', function() { @@ -690,7 +691,7 @@ describe('Test histogram', function() { expect(trace._autoBinFinished).toBeUndefined(i); }); }) - .catch(fail) + .catch(failTest) .then(done); }); @@ -703,7 +704,42 @@ describe('Test histogram', function() { .then(function() { expect(gd._fullLayout.xaxis.range).toBeCloseToArray([2, 4], 3); }) - .catch(fail) + .catch(failTest) + .then(done); + }); + + it('can recalc after the first trace is hidden', function(done) { + function assertTraceCount(n) { + expect(gd.querySelectorAll('.trace').length).toBe(n); + } + + Plotly.newPlot(gd, [{ + x: [1, 2, 3], type: 'histogram' + }, { + x: [1, 2, 3], type: 'histogram' + }, { + x: [1, 2, 3], type: 'histogram' + }]) + .then(function() { + assertTraceCount(3); + return Plotly.restyle(gd, 'visible', 'legendonly'); + }) + .then(function() { + assertTraceCount(0); + return Plotly.restyle(gd, 'visible', true, [1]); + }) + .then(function() { + assertTraceCount(1); + return Plotly.restyle(gd, 'visible', true, [2]); + }) + .then(function() { + assertTraceCount(2); + return Plotly.restyle(gd, 'visible', true); + }) + .then(function() { + assertTraceCount(3); + }) + .catch(failTest) .then(done); }); });