Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3cea060

Browse filesBrowse files
committed
fix contour label px bounds for reversed axes
1 parent 1e1495f commit 3cea060
Copy full SHA for 3cea060

File tree

Expand file treeCollapse file tree

3 files changed

+51
-8
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+51
-8
lines changed

‎src/traces/contour/plot.js

Copy file name to clipboardExpand all lines: src/traces/contour/plot.js
+28-8Lines changed: 28 additions & 8 deletions
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
+23Lines changed: 23 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.