Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5aa2d9a

Browse files
committed
Annotations: Update to use translations for positioning
When removing the last nested svg elements, annotations changed to use translations for positioning. This fixes dragging when `context.editable: true`.
1 parent d8e27dd commit 5aa2d9a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/components/annotations/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ annotations.draw = function(gd, index, opt, value) {
498498

499499
var annX = Math.round(annPosPx.x - outerwidth / 2),
500500
annY = Math.round(annPosPx.y - outerheight / 2);
501-
ann.attr('transform', 'translate(' + annX + ', ' + annY + ')');
501+
ann.call(Lib.setTranslate, annX, annY);
502502

503503
var annbase = 'annotations['+index+']';
504504

@@ -591,8 +591,10 @@ annotations.draw = function(gd, index, opt, value) {
591591
dragElement.init({
592592
element: arrowdrag.node(),
593593
prepFn: function() {
594-
annx0 = Number(ann.attr('x'));
595-
anny0 = Number(ann.attr('y'));
594+
var pos = Lib.getTranslate(ann);
595+
596+
annx0 = pos.x;
597+
anny0 = pos.y;
596598
update = {};
597599
if(xa && xa.autorange) {
598600
update[xa._name+'.autorange'] = true;
@@ -607,7 +609,7 @@ annotations.draw = function(gd, index, opt, value) {
607609
var annxy0 = applyTransform(annx0, anny0),
608610
xcenter = annxy0[0] + dx,
609611
ycenter = annxy0[1] + dy;
610-
ann.call(Drawing.setPosition, xcenter, ycenter);
612+
ann.call(Lib.setTranslate, xcenter, ycenter);
611613

612614
update[annbase+'.x'] = xa ?
613615
(options.x + dx / xa._m) :
@@ -648,12 +650,14 @@ annotations.draw = function(gd, index, opt, value) {
648650
dragElement.init({
649651
element: ann.node(),
650652
prepFn: function() {
651-
x0 = Number(ann.attr('x'));
652-
y0 = Number(ann.attr('y'));
653+
var pos = Lib.getTranslate(ann);
654+
655+
x0 = pos.x;
656+
y0 = pos.y;
653657
update = {};
654658
},
655659
moveFn: function(dx, dy) {
656-
ann.call(Drawing.setPosition, x0 + dx, y0 + dy);
660+
ann.call(Lib.setTranslate, x0 + dx, y0 + dy);
657661
var csr = 'pointer';
658662
if(options.showarrow) {
659663
update[annbase+'.ax'] = options.ax + dx;
@@ -679,7 +683,7 @@ annotations.draw = function(gd, index, opt, value) {
679683
heightFraction, 0, 1, options.yanchor);
680684
}
681685
if(!xa || !ya) {
682-
csr = dragElement.cursor(
686+
csr = dragElement.getCursor(
683687
xa ? 0.5 : update[annbase + '.x'],
684688
ya ? 0.5 : update[annbase + '.y'],
685689
options.xanchor, options.yanchor
@@ -691,7 +695,7 @@ annotations.draw = function(gd, index, opt, value) {
691695
x1 = xy1[0] + dx,
692696
y1 = xy1[1] + dy;
693697

694-
ann.call(Drawing.setPosition, x1, y1);
698+
ann.call(Lib.setTranslate, x0 + dx, y0 + dy);
695699

696700
anng.attr({
697701
transform: 'rotate(' + textangle + ',' +

0 commit comments

Comments
 (0)