Skip to content

Commit bd7fefa

Browse files
authored
Merge pull request #3293 from plotly/contour-labels-on-reversed-axes
Fix contour label px bounds for reversed axes
2 parents 1e1495f + 3cea060 commit bd7fefa

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

src/traces/contour/plot.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,37 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
255255
.attr('data-notex', 1)
256256
.call(Drawing.font, contours.labelfont);
257257

258-
var xLen = pathinfo[0].xaxis._length;
259-
var yLen = pathinfo[0].yaxis._length;
258+
var xa = pathinfo[0].xaxis;
259+
var ya = pathinfo[0].yaxis;
260+
var xLen = xa._length;
261+
var yLen = ya._length;
262+
var xRng = xa.range;
263+
var yRng = ya.range;
264+
var x0 = Math.max(perimeter[0][0], 0);
265+
var x1 = Math.min(perimeter[2][0], xLen);
266+
var y0 = Math.max(perimeter[0][1], 0);
267+
var y1 = Math.min(perimeter[2][1], yLen);
260268

261269
// visible bounds of the contour trace (and the midpoints, to
262270
// help with cost calculations)
263-
var bounds = {
264-
left: Math.max(perimeter[0][0], 0),
265-
right: Math.min(perimeter[2][0], xLen),
266-
top: Math.max(perimeter[0][1], 0),
267-
bottom: Math.min(perimeter[2][1], yLen)
268-
};
271+
var bounds = {};
272+
273+
if(xRng[0] < xRng[1]) {
274+
bounds.left = x0;
275+
bounds.right = x1;
276+
} else {
277+
bounds.left = x1;
278+
bounds.right = x0;
279+
}
280+
281+
if(yRng[0] < yRng[1]) {
282+
bounds.top = y0;
283+
bounds.bottom = y1;
284+
} else {
285+
bounds.top = y1;
286+
bounds.bottom = y0;
287+
}
288+
269289
bounds.middle = (bounds.top + bounds.bottom) / 2;
270290
bounds.center = (bounds.left + bounds.right) / 2;
271291

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"data": [
3+
{
4+
"type": "contour",
5+
"z": [
6+
[1, 2, 1],
7+
[2, 1, 2],
8+
[2, 1, 2]
9+
],
10+
"contours": {
11+
"showlabels": true
12+
}
13+
}
14+
],
15+
"layout": {
16+
"yaxis": {
17+
"autorange": "reversed"
18+
},
19+
"xaxis": {
20+
"autorange": "reversed"
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)