Skip to content

Commit 0078626

Browse files
authored
Merge pull request #3352 from plotly/one-more-contour-label-reversed-ax-fix
Adapt contour label clipPath segments for reversed axes
2 parents 6cf847c + ce8d06f commit 0078626

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

src/traces/contour/plot.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
240240
.classed('contourlabels', true);
241241

242242
if(showLabels) {
243-
var labelClipPathData = [perimeter];
244-
243+
var labelClipPathData = [];
245244
var labelData = [];
246245

247246
// invalidate the getTextLocation cache in case paths changed
@@ -287,6 +286,13 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
287286
bounds.middle = (bounds.top + bounds.bottom) / 2;
288287
bounds.center = (bounds.left + bounds.right) / 2;
289288

289+
labelClipPathData.push([
290+
[bounds.left, bounds.top],
291+
[bounds.right, bounds.top],
292+
[bounds.right, bounds.bottom],
293+
[bounds.left, bounds.bottom]
294+
]);
295+
290296
var plotDiagonal = Math.sqrt(xLen * xLen + yLen * yLen);
291297

292298
// the path length to use to scale the number of labels to draw:
Loading

test/image/mocks/contour_label-reversed-axes.json

+52-12
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,61 @@
33
{
44
"type": "contour",
55
"z": [
6-
[1, 2, 1],
7-
[2, 1, 2],
8-
[2, 1, 2]
6+
[1, 2, 3],
7+
[2, 0, 0],
8+
[3, 0, 3]
99
],
10-
"contours": {
11-
"showlabels": true
12-
}
10+
"contours": {"showlabels": true},
11+
"showscale": false
12+
},
13+
{
14+
"type": "contour",
15+
"z": [
16+
[1, 2, 3],
17+
[2, 0, 0],
18+
[3, 0, 3]
19+
],
20+
"contours": {"showlabels": true},
21+
"showscale": false,
22+
"xaxis": "x2",
23+
"yaxis": "y2"
24+
},
25+
{
26+
"type": "contour",
27+
"z": [
28+
[1, 2, 3],
29+
[2, 0, 0],
30+
[3, 0, 3]
31+
],
32+
"contours": {"showlabels": true},
33+
"showscale": false,
34+
"xaxis": "x3",
35+
"yaxis": "y3"
36+
},
37+
{
38+
"type": "contour",
39+
"z": [
40+
[1, 2, 3],
41+
[2, 0, 0],
42+
[3, 0, 3]
43+
],
44+
"contours": {"showlabels": true},
45+
"showscale": false,
46+
"xaxis": "x4",
47+
"yaxis": "y4"
1348
}
1449
],
1550
"layout": {
16-
"yaxis": {
17-
"autorange": "reversed"
18-
},
19-
"xaxis": {
20-
"autorange": "reversed"
21-
}
51+
"grid": {"rows": 2, "columns": 2, "pattern": "independent"},
52+
53+
"xaxis": {"autorange": "reversed"},
54+
"yaxis": {"autorange": "reversed"},
55+
56+
"xaxis2": {"autorange": "reversed"},
57+
58+
"yaxis3": {"autorange": "reversed"},
59+
60+
"xaxis4": {"range": [2.05, -0.05]},
61+
"yaxis4": {"range": [2.2, -0.2]}
2262
}
2363
}

0 commit comments

Comments
 (0)