8000 Fix getPixelShift for reversed axes, add reversed axis to mock · plotly/plotly.js@78a7e5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 78a7e5e

Browse files
committed
Fix getPixelShift for reversed axes, add reversed axis to mock
1 parent 8cf665a commit 78a7e5e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/components/shapes/helpers.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,8 @@ function convertPath(options, x2p, y2p) {
287287
function getPixelShift(axis, shift) {
288288
shift = shift || 0;
289289
var shiftPixels = 0;
290-
if(axis && shift) {
291-
var isVertical = axis._id.charAt(0) === 'y';
292-
if(axis.type === 'category' || axis.type === 'multicategory') {
293-
if(isVertical) {
294-
shiftPixels = ((axis.r2p(1) - axis.r2p(0)) * shift);
295-
} else {
296-
shiftPixels = axis.r2p(0.5) * shift;
297-
}
298-
}
290+
if(shift && axis && (axis.type === 'category' || axis.type === 'multicategory')) {
291+
shiftPixels = (axis.r2p(1) - axis.r2p(0)) * shift;
299292
}
300293
return shiftPixels;
301294
}

test/image/mocks/zzz_shape_shift_vertical.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
],
2222
"layout": {
2323
"width": 600,
24+
"xaxis": {
25+
"autorange": "reversed"
26+
},
2427
"shapes": [
2528
{
2629
"layer": "above",
2730
"type": "line",
2831
"label": {
29-
"text": "right from A",
32+
"text": "after A",
3033
"textposition": "end",
3134
"textangle": 0
3235
},
@@ -46,7 +49,7 @@
4649
"layer": "above",
4750
"type": "line",
4851
"label": {
49-
"text": "slightly left from D",
52+
"text": "slightly before D",
5053
"textposition": "end",
5154
"textangle": 0
5255
},

0 commit comments

Comments
 (0)
0