Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2722 - get the right traces in hist calc for cross-trace coupling #2724

Merged
merged 1 commit into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/traces/histogram/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the condition above filtering out invisible traces. Interestingly the initial draw (if you just set visible: 'legendonly' on the first trace as of newPlot) works OK, though I suspect that in certain cases this will lead us to choose the wrong autobins... this fixes that potential problem as well.

tracei.orientation === orientation &&
tracei.xaxis === xid && tracei.yaxis === yid
) {
Expand Down
40 changes: 38 additions & 2 deletions test/jasmine/tests/histogram_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -690,7 +691,7 @@ describe('Test histogram', function() {
expect(trace._autoBinFinished).toBeUndefined(i);
});
})
.catch(fail)
.catch(failTest)
.then(done);
});

Expand All @@ -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);
});
});
Expand Down