Skip to content

Commit 3c7f125

Browse files
authored
Merge pull request #2724 from plotly/hist-calc-fix
fix #2722 - get the right traces in hist calc for cross-trace coupling
2 parents 3255d0f + b5c2f35 commit 3c7f125

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/traces/histogram/calc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var oneMonth = require('../../constants/numerical').ONEAVGMONTH;
2323
var getBinSpanLabelRound = require('./bin_label_vals');
2424

2525
module.exports = function calc(gd, trace) {
26-
// ignore as much processing as possible (and including in autorange) if bar is not visible
26+
// ignore as much processing as possible (and including in autorange) if not visible
2727
if(trace.visible !== true) return;
2828

2929
// depending on orientation, set position and size axes and data ranges
@@ -435,6 +435,7 @@ function getConnectedHistograms(gd, trace) {
435435
for(var i = 0; i < fullData.length; i++) {
436436
var tracei = fullData[i];
437437
if(tracei.type === 'histogram' &&
438+
tracei.visible === true &&
438439
tracei.orientation === orientation &&
439440
tracei.xaxis === xid && tracei.yaxis === yid
440441
) {

test/jasmine/tests/histogram_test.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var getBinSpanLabelRound = require('@src/traces/histogram/bin_label_vals');
1111
var createGraphDiv = require('../assets/create_graph_div');
1212
var destroyGraphDiv = require('../assets/destroy_graph_div');
1313
var supplyAllDefaults = require('../assets/supply_defaults');
14+
var failTest = require('../assets/fail_test');
1415

1516

1617
describe('Test histogram', function() {
@@ -690,7 +691,7 @@ describe('Test histogram', function() {
690691
expect(trace._autoBinFinished).toBeUndefined(i);
691692
});
692693
})
693-
.catch(fail)
694+
.catch(failTest)
694695
.then(done);
695696
});
696697

@@ -703,7 +704,42 @@ describe('Test histogram', function() {
703704
.then(function() {
704705
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([2, 4], 3);
705706
})
706-
.catch(fail)
707+
.catch(failTest)
708+
.then(done);
709+
});
710+
711+
it('can recalc after the first trace is hidden', function(done) {
712+
function assertTraceCount(n) {
713+
expect(gd.querySelectorAll('.trace').length).toBe(n);
714+
}
715+
716+
Plotly.newPlot(gd, [{
717+
x: [1, 2, 3], type: 'histogram'
718+
}, {
719+
x: [1, 2, 3], type: 'histogram'
720+
}, {
721+
x: [1, 2, 3], type: 'histogram'
722+
}])
723+
.then(function() {
724+
assertTraceCount(3);
725+
return Plotly.restyle(gd, 'visible', 'legendonly');
726+
})
727+
.then(function() {
728+
assertTraceCount(0);
729+
return Plotly.restyle(gd, 'visible', true, [1]);
730+
})
731+
.then(function() {
732+
assertTraceCount(1);
733+
return Plotly.restyle(gd, 'visible', true, [2]);
734+
})
735+
.then(function() {
736+
assertTraceCount(2);
737+
return Plotly.restyle(gd, 'visible', true);
738+
})
739+
.then(function() {
740+
assertTraceCount(3);
741+
})
742+
.catch(failTest)
707743
.then(done);
708744
});
709745
});

0 commit comments

Comments
 (0)