Skip to content

Commit

Permalink
align autobinning of histogram traces on matching axes
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Feb 1, 2019
1 parent 6621419 commit 9118505
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/traces/histogram/cross_trace_defaults.js
Expand Up @@ -50,15 +50,16 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
binDirection = traceOut.orientation === 'v' ? 'x' : 'y';
// in overlay mode make a separate group for each trace
// otherwise collect all traces of the same subplot & orientation
group = isOverlay ? traceOut.uid : (traceOut.xaxis + traceOut.yaxis + binDirection);
traceOut._groupName = group;

group = traceOut._groupName = isOverlay ? traceOut.uid : (
getAxisGroup(fullLayout, traceOut.xaxis) +
getAxisGroup(fullLayout, traceOut.yaxis) +
binDirection
);
binOpts = allBinOpts[group];

if(binOpts) {
binOpts.traces.push(traceOut);
}
else {
} else {
binOpts = allBinOpts[group] = {
traces: [traceOut],
direction: binDirection
Expand Down Expand Up @@ -110,3 +111,13 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
}
}
};

function getAxisGroup(fullLayout, axId) {
var matchGroups = fullLayout._axisMatchGroups;

for(var i = 0; i < matchGroups.length; i++) {
var group = matchGroups[i];
if(group[axId]) return 'g' + i;
}
return axId;
}
Binary file added test/image/baselines/hists-on-matching-axes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions test/image/mocks/hists-on-matching-axes.json
@@ -0,0 +1,84 @@
{
"data": [
{
"type": "histogram",
"name": "sample A - <b>matched</b>",
"x": [1, 2, 3, 1, 1, 2, 3, 3],
"hoverlabel": {
"namelength": -1
}
},
{
"type": "histogram",
"name": "sample B - <b>matched</b>",
"x": [2.1, 2.1, 3.4, 1.3, 2.2, 2.1, 3.2, 4.1, 3.1],
"hoverlabel": {
"namelength": -1
},
"xaxis": "x2",
"yaxis": "y2"
},
{
"type": "histogram",
"name": "sample A - <b>not</b> on matching axes",
"x": [1, 2, 3, 1, 1, 2, 3, 3],
"hoverlabel": {
"namelength": -1
},
"xaxis": "x3",
"yaxis": "y3"
},
{
"type": "histogram",
"name": "sample B - <b>not</b> on matching axes",
"x": [2.1, 2.1, 3.4, 1.3, 2.2, 2.1, 3.2, 4.1, 3.1],
"hoverlabel": {
"namelength": -1
},
"xaxis": "x4",
"yaxis": "y4"
}
],
"layout": {
"margin": {"t": 20, "b": 20},
"showlegend": false,
"xaxis": {
"domain": [0, 0.4]
},
"yaxis": {
"domain": [0.45, 1],
"title": {
"text": "Matched Axes"
}
},
"xaxis2": {
"domain": [0.45, 1],
"anchor": "y2",
"matches": "x"
},
"yaxis2": {
"domain": [0.45, 1],
"anchor": "x2",
"matches": "y"
},
"xaxis3": {
"domain": [0, 0.4],
"anchor": "y3"
},
"yaxis3": {
"domain": [0, 0.4],
"anchor": "x3",
"title": {
"text": "<b>NOT</b> Matched Axes"
}
},
"xaxis4": {
"domain": [0.45, 1],
"anchor": "y4"
},
"yaxis4": {
"domain": [0, 0.4],
"anchor": "x4"
}
}
}

0 comments on commit 9118505

Please sign in to comment.