Skip to content

Commit 9118505

Browse files
committed
align autobinning of histogram traces on matching axes
1 parent 6621419 commit 9118505

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

src/traces/histogram/cross_trace_defaults.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
5050
binDirection = traceOut.orientation === 'v' ? 'x' : 'y';
5151
// in overlay mode make a separate group for each trace
5252
// otherwise collect all traces of the same subplot & orientation
53-
group = isOverlay ? traceOut.uid : (traceOut.xaxis + traceOut.yaxis + binDirection);
54-
traceOut._groupName = group;
55-
53+
group = traceOut._groupName = isOverlay ? traceOut.uid : (
54+
getAxisGroup(fullLayout, traceOut.xaxis) +
55+
getAxisGroup(fullLayout, traceOut.yaxis) +
56+
binDirection
57+
);
5658
binOpts = allBinOpts[group];
5759

5860
if(binOpts) {
5961
binOpts.traces.push(traceOut);
60-
}
61-
else {
62+
} else {
6263
binOpts = allBinOpts[group] = {
6364
traces: [traceOut],
6465
direction: binDirection
@@ -110,3 +111,13 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
110111
}
111112
}
112113
};
114+
115+
function getAxisGroup(fullLayout, axId) {
116+
var matchGroups = fullLayout._axisMatchGroups;
117+
118+
for(var i = 0; i < matchGroups.length; i++) {
119+
var group = matchGroups[i];
120+
if(group[axId]) return 'g' + i;
121+
}
122+
return axId;
123+
}
23.3 KB
Loading
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"data": [
3+
{
4+
"type": "histogram",
5+
"name": "sample A - <b>matched</b>",
6+
"x": [1, 2, 3, 1, 1, 2, 3, 3],
7+
"hoverlabel": {
8+
"namelength": -1
9+
}
10+
},
11+
{
12+
"type": "histogram",
13+
"name": "sample B - <b>matched</b>",
14+
"x": [2.1, 2.1, 3.4, 1.3, 2.2, 2.1, 3.2, 4.1, 3.1],
15+
"hoverlabel": {
16+
"namelength": -1
17+
},
18+
"xaxis": "x2",
19+
"yaxis": "y2"
20+
},
21+
{
22+
"type": "histogram",
23+
"name": "sample A - <b>not</b> on matching axes",
24+
"x": [1, 2, 3, 1, 1, 2, 3, 3],
25+
"hoverlabel": {
26+
"namelength": -1
27+
},
28+
"xaxis": "x3",
29+
"yaxis": "y3"
30+
},
31+
{
32+
"type": "histogram",
33+
"name": "sample B - <b>not</b> on matching axes",
34+
"x": [2.1, 2.1, 3.4, 1.3, 2.2, 2.1, 3.2, 4.1, 3.1],
35+
"hoverlabel": {
36+
"namelength": -1
37+
},
38+
"xaxis": "x4",
39+
"yaxis": "y4"
40+
}
41+
],
42+
"layout": {
43+
"margin": {"t": 20, "b": 20},
44+
"showlegend": false,
45+
"xaxis": {
46+
"domain": [0, 0.4]
47+
},
48+
"yaxis": {
49+
"domain": [0.45, 1],
50+
"title": {
51+
"text": "Matched Axes"
52+
}
53+
},
54+
"xaxis2": {
55+
"domain": [0.45, 1],
56+
"anchor": "y2",
57+
"matches": "x"
58+
},
59+
"yaxis2": {
60+
"domain": [0.45, 1],
61+
"anchor": "x2",
62+
"matches": "y"
63+
},
64+
"xaxis3": {
65+
"domain": [0, 0.4],
66+
"anchor": "y3"
67+
},
68+
"yaxis3": {
69+
"domain": [0, 0.4],
70+
"anchor": "x3",
71+
"title": {
72+
"text": "<b>NOT</b> Matched Axes"
73+
}
74+
},
75+
"xaxis4": {
76+
"domain": [0.45, 1],
77+
"anchor": "y4"
78+
},
79+
"yaxis4": {
80+
"domain": [0, 0.4],
81+
"anchor": "x4"
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)