8000 More single-value overlaid histogram fixes by etpinard · Pull Request #3935 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

More single-value overlaid histogram fixes #3935

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

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix single-value overlay w/ bingroup edge cases
  • Loading branch information
etpinard committed Jun 5, 2019
commit 9faab6c7cd10cbab6ec82f649bc5bed00e3343f5
17 changes: 9 additions & 8 deletions src/traces/histogram/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
}
}

// TODO how does work with bingroup ????
// - https://github.com/plotly/plotly.js/issues/3881
//
// Edge case: single-valued histogram overlaying others
// Use them all together to calculate the bin size for the single-valued one
if(isOverlay && !Registry.traceIs(trace, '2dMap') && newBinSpec._dataSpan === 0 &&
Expand Down Expand Up @@ -410,11 +407,15 @@ function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
// - single-valued traces
for(i = 0; i < overlaidTraceGroup.length; i++) {
tracei = overlaidTraceGroup[i];
if(tracei === trace) pastThisTrace = true;
else if(!pastThisTrace) {
// This trace has already had its autobins calculated
// (so must not have been single-valued).
minSize = Math.min(minSize, tracei[binAttr].size);

if(tracei === trace) {
pastThisTrace = true;
} else if(!pastThisTrace) {
// This trace has already had its autobins calculated, so either:
// - it is part of a bingroup
// - it is NOT a single-valued trace
binOpts = fullLayout._histogramBinOpts[tracei['_' + mainData + 'bingroup']];
minSize = Math.min(minSize, binOpts.size || tracei[binAttr].size);
} else {
var resulti = calcAllAutoBins(gd, tracei, pa, mainData, true);
var binSpeci = resulti[0];
Expand Down
55 changes: 55 additions & 0 deletions test/jasmine/tests/histogram_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Plotly = require('@lib/index');
var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
var setConvert = require('@src/plots/cartesian/set_convert');

Expand Down Expand Up @@ -760,6 +761,60 @@ describe('Test histogram', function() {
]);
});

// from issue #3881
it('handle single-value edge case 1', function() {
var gd = {
data: [
{uid: 'a', type: 'histogram', y: [1]},
{uid: 'b', type: 'histogram', y: [2]},

{uid: 'c', type: 'histogram', y: [1], xaxis: 'x2'},
{uid: 'd', type: 'histogram', y: [3], xaxis: 'x2'},

{uid: 'e', type: 'histogram', y: [3]},
{uid: 'f', type: 'histogram', y: [2], xaxis: 'x2'},

{uid: 'g', type: 'histogram', x: [1]},
{uid: 'h', type: 'histogram', x: [2], yaxis: 'y2'},
{uid: 'i', type: 'histogram', x: [2]}
],
layout: {barmode: 'overlay'}
};
supplyAllDefaults(gd);
Plots.doCalcdata(gd);

var allBinOpts = gd._fullLayout._histogramBinOpts;
var groups = Object.keys(allBinOpts);
expect(groups).toEqual(
['a__y', 'b__y', 'c__y', 'd__y', 'e__y', 'f__y', 'g__x', 'h__x', 'i__x'],
'bin groups'
);
});

// from issue #3881
it('handle single-value edge case 2', function() {
var gd = {
data: [
{bingroup: '1', type: 'histogram', y: [1]},
{uid: 'b', type: 'histogram', y: [2]},
{bingroup: '2', type: 'histogram', y: [1], xaxis: 'x2'},
{bingroup: '1', type: 'histogram', y: [3], xaxis: 'x2'},
{bingroup: '2', type: 'histogram', y: [3]},
{uid: 'f', type: 'histogram', y: [2], xaxis: 'x2'},
{bingroup: '3', type: 'histogram', x: [1]},
{bingroup: '1', type: 'histogram', x: [2], yaxis: 'y2'},
{bingroup: '3', type: 'histogram', x: [2]}
],
layout: {barmode: 'overlay'}
};
supplyAllDefaults(gd);
Plots.doCalcdata(gd);

var allBinOpts = gd._fullLayout._histogramBinOpts;
var groups = Object.keys(allBinOpts);
expect(groups).toEqual(['1', '2', '3', 'b__y', 'f__y'], 'bin groups');
});

function calcPositions(opts, extraTraces, prepend) {
return _calc(opts, extraTraces, {}, prepend).map(function(v) { return v.p; });
}
Expand Down
0