Skip to content

Commit d807259

Browse files
committed
add ax.r2p and ax.p2r
1 parent 5e11571 commit d807259

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

src/components/annotations/draw.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function drawOne(gd, index, opt, value) {
370370

371371
if(annotationIsOffscreen) return;
372372
}
373-
annPosPx[axLetter] = ax._offset + ax.l2p(ax.r2l(options[axLetter]));
373+
annPosPx[axLetter] = ax._offset + ax.r2p(options[axLetter]);
374374
alignPosition = 0.5;
375375
}
376376
else {
@@ -383,7 +383,7 @@ function drawOne(gd, index, opt, value) {
383383

384384
var alignShift = 0;
385385
if(options['a' + axLetter + 'ref'] === axRef) {
386-
annPosPx['aa' + axLetter] = ax._offset + ax.l2p(ax.r2l(options['a' + axLetter]));
386+
annPosPx['aa' + axLetter] = ax._offset + ax.r2p(options['a' + axLetter]);
387387
} else {
388388
if(options.showarrow) {
389389
alignShift = options['a' + axLetter];
@@ -583,22 +583,22 @@ function drawOne(gd, index, opt, value) {
583583
ann.call(Lib.setTranslate, xcenter, ycenter);
584584

585585
update[annbase + '.x'] = xa ?
586-
xa.l2r(xa.p2l(xa.l2p(xa.r2l(options.x)) + dx)) :
586+
xa.p2r(xa.r2p(options.x) + dx) :
587587
((arrowX + dx - gs.l) / gs.w);
588588
update[annbase + '.y'] = ya ?
589-
ya.l2r(ya.p2l(ya.l2p(ya.r2l(options.y)) + dy)) :
589+
ya.p2r(ya.r2p(options.y) + dy) :
590590
(1 - ((arrowY + dy - gs.t) / gs.h));
591591

592592
if(options.axref === options.xref) {
593593
update[annbase + '.ax'] = xa ?
594-
xa.l2r(xa.p2l(xa.l2p(xa.r2l(options.ax)) + dx)) :
595-
((arrowX + dx - gs.l) / gs.w);
594+
xa.p2r(xa.r2p(options.ax) + dx) :
595+
((arrowX + dx - gs.l) / gs.w);
596596
}
597597

598598
if(options.ayref === options.yref) {
599599
update[annbase + '.ay'] = ya ?
600-
ya.l2r(ya.p2l(ya.l2p(ya.r2l(options.ay)) + dy)) :
601-
(1 - ((arrowY + dy - gs.t) / gs.h));
600+
ya.p2r(ya.r2p(options.ay) + dy) :
601+
(1 - ((arrowY + dy - gs.t) / gs.h));
602602
}
603603

604604
anng.attr({
@@ -644,13 +644,13 @@ function drawOne(gd, index, opt, value) {
644644
var csr = 'pointer';
645645
if(options.showarrow) {
646646
if(options.axref === options.xref) {
647-
update[annbase + '.ax'] = xa.l2r(xa.p2l(xa.l2p(xa.r2l(options.ax)) + dx));
647+
update[annbase + '.ax'] = xa.p2r(xa.r2p(options.ax) + dx);
648648
} else {
649649
update[annbase + '.ax'] = options.ax + dx;
650650
}
651651

652652
if(options.ayref === options.yref) {
653-
update[annbase + '.ay'] = ya.l2r(ya.p2l(ya.l2p(ya.r2l(options.ay)) + dy));
653+
update[annbase + '.ay'] = ya.p2r(ya.r2p(options.ay) + dy);
654654
} else {
655655
update[annbase + '.ay'] = options.ay + dy;
656656
}

src/components/images/draw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ module.exports = function draw(gd) {
113113
var sizing = anchors.x[d.xanchor].sizing + anchors.y[d.yanchor].sizing;
114114

115115
// Final positions
116-
var xPos = (xa ? xa.l2p(xa.r2l(d.x)) + xa._offset : d.x * size.w + size.l) + xOffset,
117-
yPos = (ya ? ya.l2p(ya.r2l(d.y)) + ya._offset : size.h - d.y * size.h + size.t) + yOffset;
116+
var xPos = (xa ? xa.r2p(d.x) + xa._offset : d.x * size.w + size.l) + xOffset,
117+
yPos = (ya ? ya.r2p(d.y) + ya._offset : size.h - d.y * size.h + size.t) + yOffset;
118118

119119

120120
// Construct the proper aspectRatio attribute

src/components/shapes/draw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,15 @@ function getPathString(gd, options) {
473473

474474
if(xa) {
475475
x2r = helpers.shapePositionToRange(xa);
476-
x2p = function(v) { return xa._offset + xa.l2p(xa.r2l(x2r(v, true))); };
476+
x2p = function(v) { return xa._offset + xa.r2p(x2r(v, true)); };
477477
}
478478
else {
479479
x2p = function(v) { return gs.l + gs.w * v; };
480480
}
481481

482482
if(ya) {
483483
y2r = helpers.shapePositionToRange(ya);
484-
y2p = function(v) { return ya._offset + ya.l2p(ya.r2l(y2r(v, true))); };
484+
y2p = function(v) { return ya._offset + ya.r2p(y2r(v, true)); };
485485
}
486486
else {
487487
y2p = function(v) { return gs.t + gs.h * (1 - v); };

src/components/shapes/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ exports.getDataToPixel = function(gd, axis, isVertical) {
4545
var d2r = exports.shapePositionToRange(axis);
4646

4747
dataToPixel = function(v) {
48-
return axis._offset + axis.l2p(axis.r2l(d2r(v, true)));
48+
return axis._offset + axis.r2p(d2r(v, true));
4949
};
5050

5151
if(axis.type === 'date') dataToPixel = exports.decodeDate(dataToPixel);
@@ -66,7 +66,7 @@ exports.getPixelToData = function(gd, axis, isVertical) {
6666

6767
if(axis) {
6868
var r2d = exports.rangeToShapePosition(axis);
69-
pixelToData = function(p) { return r2d(axis.l2r(axis.p2l(p - axis._offset))); };
69+
pixelToData = function(p) { return r2d(axis.p2r(p - axis._offset)); };
7070
}
7171
else if(isVertical) {
7272
pixelToData = function(p) { return 1 - (p - gs.t) / gs.h; };

src/plots/cartesian/set_convert.js

+5
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ module.exports = function setConvert(ax) {
232232
ax.c2p = function(v, clip) { return ax.l2p(ax.c2l(v, clip)); };
233233
ax.p2c = function(px) { return ax.l2c(ax.p2l(px)); };
234234

235+
// clip doesn't do anything here yet, but in v2.0 when log axes get
236+
// refactored it will... so including it now so we don't forget.
237+
ax.r2p = function(v, clip) { return ax.l2p(ax.r2l(v, clip)); };
238+
ax.p2r = function(px) { return ax.l2r(ax.p2l(px)); };
239+
235240
if(['linear', 'log', '-'].indexOf(ax.type) !== -1) {
236241
ax.c2d = num;
237242
ax.d2c = Lib.cleanNumber;

0 commit comments

Comments
 (0)