Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
63 changes: 63 additions & 0 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down