Skip to content

Commit 065ac8a

Browse files
committed
fix annotation drag on date axes, and test date/log annotations
1 parent a29ce33 commit 065ac8a

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/components/annotations/draw.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,21 +579,21 @@ function drawOne(gd, index, opt, value) {
579579
ann.call(Lib.setTranslate, xcenter, ycenter);
580580

581581
update[annbase + '.x'] = xa ?
582-
(options.x + dx / xa._m) :
582+
xa.l2r(xa.p2l(xa.l2p(xa.r2l(options.x)) + dx)) :
583583
((arrowX + dx - gs.l) / gs.w);
584584
update[annbase + '.y'] = ya ?
585-
(options.y + dy / ya._m) :
585+
ya.l2r(ya.p2l(ya.l2p(ya.r2l(options.y)) + dy)) :
586586
(1 - ((arrowY + dy - gs.t) / gs.h));
587587

588588
if(options.axref === options.xref) {
589589
update[annbase + '.ax'] = xa ?
590-
(options.ax + dx / xa._m) :
590+
xa.l2r(xa.p2l(xa.l2p(xa.r2l(options.ax)) + dx)) :
591591
((arrowX + dx - gs.l) / gs.w);
592592
}
593593

594594
if(options.ayref === options.yref) {
595595
update[annbase + '.ay'] = ya ?
596-
(options.ay + dy / ya._m) :
596+
ya.l2r(ya.p2l(ya.l2p(ya.r2l(options.ay)) + dy)) :
597597
(1 - ((arrowY + dy - gs.t) / gs.h));
598598
}
599599

@@ -640,13 +640,13 @@ function drawOne(gd, index, opt, value) {
640640
var csr = 'pointer';
641641
if(options.showarrow) {
642642
if(options.axref === options.xref) {
643-
update[annbase + '.ax'] = xa.p2l(xa.l2p(options.ax) + dx);
643+
update[annbase + '.ax'] = xa.l2r(xa.p2l(xa.l2p(xa.r2l(options.ax)) + dx));
644644
} else {
645645
update[annbase + '.ax'] = options.ax + dx;
646646
}
647647

648648
if(options.ayref === options.yref) {
649-
update[annbase + '.ay'] = ya.p2l(ya.l2p(options.ay) + dy);
649+
update[annbase + '.ay'] = ya.l2r(ya.p2l(ya.l2p(ya.r2l(options.ay)) + dy));
650650
} else {
651651
update[annbase + '.ay'] = options.ay + dy;
652652
}
3.42 KB
Loading

test/image/mocks/annotations-autorange.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"anchor":"y2",
2121
"mirror":true,
2222
"zeroline":false,
23-
"showline":true
23+
"showline":true,
24+
"type": "date"
2425
},
2526
"xaxis3":{
2627
"domain":[0.7,1],
@@ -38,7 +39,8 @@
3839
"anchor":"x2",
3940
"mirror":true,
4041
"zeroline":false,
41-
"showline":true
42+
"showline":true,
43+
"type": "log"
4244
},
4345
"yaxis3":{
4446
"anchor":"x3",
@@ -54,10 +56,10 @@
5456
{"ay":0,"ax":-50,"x":2,"y":1.5,"text":"Right"},
5557
{"x":1.5,"y":2,"text":"Top","ay":50,"ax":0},
5658
{"x":1.5,"y":1,"text":"Bottom","ay":-50,"ax":0},
57-
{"xref":"x2","yref":"y2","text":"From left","y":1.5,"ax":-50,"ay":0,"x":1},
58-
{"xref":"x2","yref":"y2","text":"From right","y":1.5,"x":2,"ay":0,"ax":50},
59-
{"xref":"x2","yref":"y2","text":"From top","y":2,"ax":0,"ay":-50,"x":1.5},
60-
{"xref":"x2","yref":"y2","text":"From Bottom","y":1,"ax":0,"ay":50,"x":1.5},
59+
{"xref":"x2","yref":"y2","text":"From left","y":2,"ax":-50,"ay":0,"x":"2001-01-01"},
60+
{"xref":"x2","yref":"y2","text":"From right","y":2,"x":"2001-03-01","ay":0,"ax":50},
61+
{"xref":"x2","yref":"y2","text":"From top","y":3,"ax":0,"ay":-50,"x":"2001-02-01"},
62+
{"xref":"x2","yref":"y2","text":"From Bottom","y":1,"ax":0,"ay":50,"x":"2001-02-01"},
6163
{"xref":"x3","yref":"y3","text":"Left<br>no<br>arrow","y":1.5,"x":1,"showarrow":false},
6264
{"xref":"x3","yref":"y3","text":"Right<br>no<br>arrow","y":1.5,"x":2,"showarrow":false},
6365
{"xref":"x3","yref":"y3","text":"Bottom<br>no<br>arrow","y":1,"x":1.5,"showarrow":false},

0 commit comments

Comments
 (0)