Skip to content

Commit d9c2d4e

Browse files
committed
link ax._categories & ax._categoriesMap to same ref for matching axes
- that way, they are appends across matching axes and the category-to-position maps just works!
1 parent 9118505 commit d9c2d4e

File tree

3 files changed

+149
-12
lines changed

3 files changed

+149
-12
lines changed

src/plots/cartesian/set_convert.js

+57-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var d3 = require('d3');
@@ -63,7 +62,8 @@ function isValidCategory(v) {
6362
module.exports = function setConvert(ax, fullLayout) {
6463
fullLayout = fullLayout || {};
6564

66-
var axLetter = (ax._id || 'x').charAt(0);
65+
var axId = (ax._id || 'x');
66+
var axLetter = axId.charAt(0);
6767

6868
function toLog(v, clip) {
6969
if(v > 0) return Math.log(v) / Math.LN10;
@@ -307,10 +307,25 @@ module.exports = function setConvert(ax, fullLayout) {
307307
var traceIndices = ax._traceIndices;
308308
var i, j;
309309

310+
var matchGroups = fullLayout._axisMatchGroups;
311+
if(matchGroups && matchGroups.length && ax._categories.length === 0) {
312+
for(i = 0; i < matchGroups.length; i++) {
313+
var group = matchGroups[i];
314+
if(group[axId]) {
315+
for(var axId2 in group) {
316+
if(axId2 !== axId) {
317+
var ax2 = fullLayout[axisIds.id2name(axId2)];
318+
traceIndices = traceIndices.concat(ax2._traceIndices);
319+
}
320+
}
321+
}
322+
}
323+
}
324+
310325
// [ [cnt, {$cat: index}], for 1,2 ]
311-
var seen = ax._multicatSeen = [[0, {}], [0, {}]];
326+
var seen = [[0, {}], [0, {}]];
312327
// [ [arrayIn[0][i], arrayIn[1][i]], for i .. N ]
313-
var list = ax._multicatList = [];
328+
var list = [];
314329

315330
for(i = 0; i < traceIndices.length; i++) {
316331
var trace = fullData[traceIndices[i]];
@@ -558,15 +573,45 @@ module.exports = function setConvert(ax, fullLayout) {
558573
}
559574
};
560575

576+
// should skip if not category nor multicategory
561577
ax.clearCalc = function() {
562-
// initialize the category list, if there is one, so we start over
563-
// to be filled in later by ax.d2c
564-
ax._categories = (ax._initialCategories || []).slice();
565-
566-
// Build the lookup map for initialized categories
567-
ax._categoriesMap = {};
568-
for(var j = 0; j < ax._categories.length; j++) {
569-
ax._categoriesMap[ax._categories[j]] = j;
578+
var matchGroups = fullLayout._axisMatchGroups;
579+
580+
if(matchGroups && matchGroups.length) {
581+
for(var i = 0; i < matchGroups.length; i++) {
582+
var group = matchGroups[i];
583+
584+
if(group[axId]) {
585+
var categories = null;
586+
var categoriesMap = null;
587+
588+
for(var axId2 in group) {
589+
var ax2 = fullLayout[axisIds.id2name(axId2)];
590+
if(ax2._categories) {
591+
categories = ax2._categories;
592+
categoriesMap = ax2._categoriesMap;
593+
break;
594+
}
595+
}
596+
597+
if(categories && categoriesMap) {
598+
ax._categories = categories;
599+
ax._categoriesMap = categoriesMap;
600+
} else {
601+
ax._categories = [];
602+
ax._categoriesMap = {};
603+
}
604+
}
605+
}
606+
} else {
607+
ax._categories = [];
608+
ax._categoriesMap = {};
609+
}
610+
611+
if(ax._initialCategories) {
612+
for(var j = 0; j < ax._initialCategories.length; j++) {
613+
setCategoryIndex(ax._initialCategories[j]);
614+
}
570615
}
571616
};
572617

43.1 KB
Loading
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"data": [
3+
{
4+
"x": [ "a", "b", "c" ],
5+
"y": [ 1, 2, 1 ]
6+
},
7+
{
8+
"x": [ "b", "c", "d", "e" ],
9+
"y": [ 2, 1, 2, 3 ],
10+
"xaxis": "x2",
11+
"yaxis": "y2"
12+
},
13+
{
14+
"x": [
15+
[ 2018, 2019, 2019 ],
16+
[ "q1", "q1", "q2" ]
17+
],
18+
"y": [ 1, 2, 1 ],
19+
"xaxis": "x3",
20+
"yaxis": "y3"
21+
},
22+
{
23+
"x": [
24+
[ 2018, 2018, 2019, 2019 ],
25+
[ "q1", "q2", "q1", "q2" ]
26+
],
27+
"y": [ 2, 1, 2, 3 ],
28+
"xaxis": "x4",
29+
"yaxis": "y4"
30+
}
31+
],
32+
"layout": {
33+
"xaxis": {
34+
"domain": [ 0, 0.2 ]
35+
},
36+
"yaxis": {
37+
"domain": [ 0.65, 1 ]
38+
},
39+
"xaxis2": {
40+
"matches": "x",
41+
"anchor": "y2",
42+
"domain": [ 0.3, 1 ]
43+
},
44+
"yaxis2": {
45+
"anchor": "x2",
46+
"domain": [ 0.65, 1 ]
47+
},
48+
"xaxis3": {
49+
"anchor": "y3",
50+
"domain": [ 0, 0.2 ]
51+
},
52+
"yaxis3": {
53+
"anchor": "x3",
54+
"domain": [ 0, 0.5 ]
55+
},
56+
"xaxis4": {
57+
"matches": "x3",
58+
"anchor": "y4",
59+
"domain": [ 0.3, 1 ]
60+
},
61+
"yaxis4": {
62+
"anchor": "x4",
63+
"domain": [ 0, 0.5 ]
64+
},
65+
"showlegend": false,
66+
"margin": { "t": 40, "b": 40, "l": 20, "r": 20 },
67+
"annotations": [
68+
{
69+
"text": "matching category x-axes",
70+
"showarrow": false,
71+
"xref": "paper",
72+
"yref": "paper",
73+
"x": 0,
74+
"xanchor": "left",
75+
"y": 1,
76+
"yanchor": "bottom",
77+
"bgcolor": "#d3d3d3"
78+
},
79+
{
80+
"text": "matching multicategory x-axes",
81+
"showarrow": false,
82+
"xref": "paper",
83+
"yref": "paper",
84+
"x": 0,
85+
"xanchor": "left",
86+
"y": 0.5,
87+
"yanchor": "bottom",
88+
"bgcolor": "#d3d3d3"
89+
}
90+
]
91+
}
92+
}

0 commit comments

Comments
 (0)