Skip to content

Commit 416058b

Browse files
committed
fix edits for datestring referenced annotations
1 parent 4aa511a commit 416058b

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

src/components/annotations/draw.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,10 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
636636
drawArrow(dx, dy);
637637
}
638638
else if(!subplotId) {
639-
if(xa) update[annbase + '.x'] = options.x + dx / xa._m;
640-
else {
639+
if(xa) {
640+
update[annbase + '.x'] = xa.p2r(xa.r2p(options.x) + dx);
641+
642+
} else {
641643
var widthFraction = options._xsize / gs.w,
642644
xLeft = options.x + (options._xshift - options.xshift) / gs.w -
643645
widthFraction / 2;
@@ -646,8 +648,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
646648
widthFraction, 0, 1, options.xanchor);
647649
}
648650

649-
if(ya) update[annbase + '.y'] = options.y + dy / ya._m;
650-
else {
651+
if(ya) {
652+
update[annbase + '.y'] = ya.p2r(ya.r2p(options.y) + dy);
653+
} else {
651654
var heightFraction = options._ysize / gs.h,
652655
yBottom = options.y - (options._yshift + options.yshift) / gs.h -
653656
heightFraction / 2;

test/jasmine/tests/annotations_test.js

+63
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,69 @@ describe('annotation effects', function() {
11511151
.then(done);
11521152
});
11531153

1154+
it('works date string data-referenced with no arrow', function(done) {
1155+
gd = createGraphDiv();
1156+
1157+
Plotly.newPlot(gd, [{
1158+
x: ['2018-01-01', '2018-02-02'],
1159+
y: ['2017-01-03', '2017-02-04'],
1160+
}], {
1161+
annotations: [{
1162+
showarrow: false,
1163+
text: 'YO!',
1164+
xref: 'x',
1165+
yref: 'y',
1166+
x: '2018-02-01',
1167+
y: '2017-02-05'
1168+
}],
1169+
width: 500,
1170+
height: 500,
1171+
margin: {l: 100, r: 100, t: 100, b: 100, pad: 0},
1172+
}, {
1173+
editable: true
1174+
})
1175+
.then(function() {
1176+
return dragAndReplot(textDrag(), -20, 20);
1177+
})
1178+
.then(function() {
1179+
expect(gd._fullLayout.annotations[0].x).toBe('2018-01-29 13:29:41.4857');
1180+
expect(gd._fullLayout.annotations[0].y).toBe('2017-02-02 13:28:35.6572');
1181+
})
1182+
.catch(failTest)
1183+
.then(done);
1184+
});
1185+
1186+
it('works date sting data-referenced with arrow', function(done) {
1187+
gd = createGraphDiv();
1188+
1189+
Plotly.newPlot(gd, [{
1190+
x: ['2018-01-01', '2018-02-02'],
1191+
y: ['2017-01-03', '2017-02-04'],
1192+
}], {
1193+
annotations: [{
1194+
text: 'YO!',
1195+
xref: 'x',
1196+
yref: 'y',
1197+
x: '2018-02-01',
1198+
y: '2017-02-05'
1199+
}],
1200+
width: 500,
1201+
height: 500,
1202+
margin: {l: 100, r: 100, t: 100, b: 100, pad: 0},
1203+
}, {
1204+
editable: true
1205+
})
1206+
.then(function() {
1207+
return dragAndReplot(arrowDrag(), -20, 20);
1208+
})
1209+
.then(function() {
1210+
expect(gd._fullLayout.annotations[0].x).toBe('2018-01-29 13:29:41.4857');
1211+
expect(gd._fullLayout.annotations[0].y).toBe('2017-02-02 06:36:46.8112');
1212+
})
1213+
.catch(failTest)
1214+
.then(done);
1215+
});
1216+
11541217
it('should only make the clippaths it needs and delete others', function(done) {
11551218
makePlot([
11561219
{x: 50, y: 50, text: 'hi', width: 50, ax: 0, ay: -20},

0 commit comments

Comments
 (0)