From 416058beedc8e99e8e5c73fd6d5109bcaf025cdd Mon Sep 17 00:00:00 2001 From: etienne Date: Wed, 14 Feb 2018 19:11:00 -0500 Subject: [PATCH] fix edits for datestring referenced annotations --- src/components/annotations/draw.js | 11 +++-- test/jasmine/tests/annotations_test.js | 63 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/components/annotations/draw.js b/src/components/annotations/draw.js index 8a5188de729..2c4660a524c 100644 --- a/src/components/annotations/draw.js +++ b/src/components/annotations/draw.js @@ -636,8 +636,10 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { drawArrow(dx, dy); } else if(!subplotId) { - if(xa) update[annbase + '.x'] = options.x + dx / xa._m; - else { + if(xa) { + update[annbase + '.x'] = xa.p2r(xa.r2p(options.x) + dx); + + } else { var widthFraction = options._xsize / gs.w, xLeft = options.x + (options._xshift - options.xshift) / gs.w - widthFraction / 2; @@ -646,8 +648,9 @@ function drawRaw(gd, options, index, subplotId, xa, ya) { widthFraction, 0, 1, options.xanchor); } - if(ya) update[annbase + '.y'] = options.y + dy / ya._m; - else { + if(ya) { + update[annbase + '.y'] = ya.p2r(ya.r2p(options.y) + dy); + } else { var heightFraction = options._ysize / gs.h, yBottom = options.y - (options._yshift + options.yshift) / gs.h - heightFraction / 2; diff --git a/test/jasmine/tests/annotations_test.js b/test/jasmine/tests/annotations_test.js index 4a70710dece..9f7c323dab4 100644 --- a/test/jasmine/tests/annotations_test.js +++ b/test/jasmine/tests/annotations_test.js @@ -1151,6 +1151,69 @@ describe('annotation effects', function() { .then(done); }); + it('works date string data-referenced with no arrow', function(done) { + gd = createGraphDiv(); + + Plotly.newPlot(gd, [{ + x: ['2018-01-01', '2018-02-02'], + y: ['2017-01-03', '2017-02-04'], + }], { + annotations: [{ + showarrow: false, + text: 'YO!', + xref: 'x', + yref: 'y', + x: '2018-02-01', + y: '2017-02-05' + }], + width: 500, + height: 500, + margin: {l: 100, r: 100, t: 100, b: 100, pad: 0}, + }, { + editable: true + }) + .then(function() { + return dragAndReplot(textDrag(), -20, 20); + }) + .then(function() { + expect(gd._fullLayout.annotations[0].x).toBe('2018-01-29 13:29:41.4857'); + expect(gd._fullLayout.annotations[0].y).toBe('2017-02-02 13:28:35.6572'); + }) + .catch(failTest) + .then(done); + }); + + it('works date sting data-referenced with arrow', function(done) { + gd = createGraphDiv(); + + Plotly.newPlot(gd, [{ + x: ['2018-01-01', '2018-02-02'], + y: ['2017-01-03', '2017-02-04'], + }], { + annotations: [{ + text: 'YO!', + xref: 'x', + yref: 'y', + x: '2018-02-01', + y: '2017-02-05' + }], + width: 500, + height: 500, + margin: {l: 100, r: 100, t: 100, b: 100, pad: 0}, + }, { + editable: true + }) + .then(function() { + return dragAndReplot(arrowDrag(), -20, 20); + }) + .then(function() { + expect(gd._fullLayout.annotations[0].x).toBe('2018-01-29 13:29:41.4857'); + expect(gd._fullLayout.annotations[0].y).toBe('2017-02-02 06:36:46.8112'); + }) + .catch(failTest) + .then(done); + }); + it('should only make the clippaths it needs and delete others', function(done) { makePlot([ {x: 50, y: 50, text: 'hi', width: 50, ax: 0, ay: -20},