Skip to content

Commit 7a1ed7b

Browse files
authored
Merge pull request #3927 from plotly/carpet-label-reverse-bug
Fix carpet axis title position for decreasing a/b coords
2 parents 297ecb7 + fb8b229 commit 7a1ed7b

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

src/traces/carpet/plot.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,20 @@ function drawAxisLabels(gd, xaxis, yaxis, trace, t, layer, labels, labelClass) {
173173
function drawAxisTitles(gd, layer, trace, t, xa, ya, labelOrientationA, labelOrientationB) {
174174
var a, b, xy, dxy;
175175

176-
a = 0.5 * (trace.a[0] + trace.a[trace.a.length - 1]);
177-
b = trace.b[0];
176+
var _a = trace.a.slice().sort(Lib.sorterAsc);
177+
var _b = trace.b.slice().sort(Lib.sorterAsc);
178+
179+
a = 0.5 * (_a[0] + _a[_a.length - 1]);
180+
b = _b[0];
178181
xy = trace.ab2xy(a, b, true);
179182
dxy = trace.dxyda_rough(a, b);
180183
if(labelOrientationA.angle === undefined) {
181184
Lib.extendFlat(labelOrientationA, orientText(trace, xa, ya, xy, trace.dxydb_rough(a, b)));
182185
}
183186
drawAxisTitle(gd, layer, trace, t, xy, dxy, trace.aaxis, xa, ya, labelOrientationA, 'a-title');
184187

185-
a = trace.a[0];
186-
b = 0.5 * (trace.b[0] + trace.b[trace.b.length - 1]);
188+
a = _a[0];
189+
b = 0.5 * (_b[0] + _b[_b.length - 1]);
187190
xy = trace.ab2xy(a, b, true);
188191
dxy = trace.dxydb_rough(a, b);
189192
if(labelOrientationB.angle === undefined) {
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"data": [
3+
{
4+
"type": "carpet",
5+
"a": [3, 2, 1, 3, 2, 1, 3, 2, 1],
6+
"aaxis": {
7+
"title": { "text": "a" }
8+
},
9+
"b": [3, 3, 3, 2, 2, 2, 1, 1, 1],
10+
"baxis": {
11+
"title": { "text": "b" }
12+
},
13+
"y": [10, 7, 4, 7, 5, 3, 4, 3, 2]
14+
},
15+
{
16+
"type": "carpet",
17+
"a": [1, 2, 3, 1, 2, 3, 1, 2, 3],
18+
"aaxis": {
19+
"title": { "text": "a" }
20+
},
21+
"b": [1, 1, 1, 2, 2, 2, 3, 3, 3],
22+
"baxis": {
23+
"title": { "text": "b" }
24+
},
25+
"y": [2, 3, 4, 3, 5, 7, 4, 7, 10],
26+
"yaxis": "y2"
27+
}
28+
],
29+
"layout": {
30+
"grid": {
31+
"rows": 2,
32+
"columns": 1
33+
},
34+
"yaxis": {
35+
"title": {
36+
"text": "decreaing a/b ordering"
37+
}
38+
},
39+
"yaxis2": {
40+
"title": {
41+
"text": "increaing a/b ordering"
42+
}
43+
},
44+
"width": 600,
45+
"height": 800
46+
}
47+
}

0 commit comments

Comments
 (0)