Skip to content

Adding the ability to specify the tail of an annotation arrow in abso… #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ed8295a
Adding the ability to specify the tail of an annotation arrow in abso…
Jun 3, 2016
a2e9c72
Adding the ability to specify the tail of an annotation arrow in abso…
Jun 3, 2016
8fcb9dd
Merge remote-tracking branch 'origin/trendline' into trendline
Jun 5, 2016
a7e0e88
Fixing text and editing.
Jun 7, 2016
722a1ca
code review feedback
Jun 7, 2016
a1da755
Adding the ability to specify the tail of an annotation arrow in abso…
Jun 7, 2016
a2ecd65
Adding the ability to specify the tail of an annotation arrow in abso…
Jun 7, 2016
8697050
Merge remote-tracking branch 'origin/trendline' into trendline
Jun 7, 2016
49d9c7e
Trying to fix tests for absolutetail.
Jun 7, 2016
91dd08a
Removing these unit tests because they are of dubious value relative …
Jun 7, 2016
dbdcaac
fixing the unit tests for annotations and adding them back.
Jun 7, 2016
253a3fa
fixing timezone problem in annotations test.
Jun 7, 2016
4aa569d
fixing lint for annotation tests.
Jun 7, 2016
a008354
Switching absolutetail to axref, ayref based on code review feedback.…
Jun 14, 2016
925360f
Merge remote-tracking branch 'upstream/master' into trendline
Jun 14, 2016
3a827a6
Merge remote-tracking branch 'origin/absolutetail' into absolutetail
Jun 14, 2016
d07b676
somehow I lost this change in my screw up with the branches.
Jun 14, 2016
143328d
Not hardcoding axis references but using regex and coerce. Purposeful…
Jun 14, 2016
e83b947
Fixing bug where annotation would be marked as offscreen if the head …
Jun 16, 2016
9358a56
Fixing a bug where the x,y of the arrow would be changed to stay on t…
Jun 20, 2016
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
4 changes: 2 additions & 2 deletions src/components/annotations/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module.exports = {
dflt: 'pixel',
values: [
'pixel',
'x'
cartesianConstants.idRegex.x.toString()
],
role: 'info',
description: [
Expand All @@ -177,7 +177,7 @@ module.exports = {
dflt: 'pixel',
values: [
'pixel',
'y'
cartesianConstants.idRegex.y.toString()
],
role: 'info',
description: [
Expand Down
52 changes: 33 additions & 19 deletions src/components/annotations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function handleAnnotationDefaults(annIn, fullLayout) {
// xref, yref
var axRef = Axes.coerceRef(annIn, annOut, tdMock, axLetter);

//todo: should be refactored in conjunction with Axes
// axref, ayref
var aaxRef = Axes.coerceARef(annIn, annOut, tdMock, axLetter);

// x, y
var defaultPosition = 0.5;
if(axRef !== 'paper') {
Expand All @@ -92,7 +96,7 @@ function handleAnnotationDefaults(annIn, fullLayout) {
newval = Lib.dateTime2ms(annIn[axLetter]);
if(newval !== false) annIn[axLetter] = newval;

if(annIn['a' + axLetter + 'ref'] === axRef) {
if(aaxRef === axRef) {
var newvalB = Lib.dateTime2ms(annIn['a' + axLetter]);
if(newvalB !== false) annIn['a' + axLetter] = newvalB;
}
Expand Down Expand Up @@ -487,15 +491,17 @@ annotations.draw = function(gd, index, opt, value) {
// make sure the arrowhead (if there is one)
// and the annotation center are visible
if(options.showarrow) {
if(options.axref === options.xref)
if(options.axref === options.xref) {
arrowX = Lib.constrain(annPosPx.x, 1, fullLayout.width - 1);
else
} else {
arrowX = Lib.constrain(annPosPx.x - options.ax, 1, fullLayout.width - 1);
}

if(options.ayref === options.yref)
if(options.ayref === options.yref) {
arrowY = Lib.constrain(annPosPx.y, 1, fullLayout.height - 1);
else
} else {
arrowY = Lib.constrain(annPosPx.y - options.ay, 1, fullLayout.height - 1);
}
}
annPosPx.x = Lib.constrain(annPosPx.x, 1, fullLayout.width - 1);
annPosPx.y = Lib.constrain(annPosPx.y, 1, fullLayout.height - 1);
Expand All @@ -515,15 +521,17 @@ annotations.draw = function(gd, index, opt, value) {
outerwidth - borderwidth, outerheight - borderwidth);

var annX = 0, annY = 0;
if(options.axref === options.xref)
if(options.axref === options.xref) {
annX = Math.round(annPosPx.aax - outerwidth / 2);
else
} else {
annX = Math.round(annPosPx.x - outerwidth / 2);
}

if(options.ayref === options.yref)
if(options.ayref === options.yref) {
annY = Math.round(annPosPx.aay - outerheight / 2);
else
} else {
annY = Math.round(annPosPx.y - outerheight / 2);
}

ann.call(Lib.setTranslate, annX, annY);

Expand All @@ -544,15 +552,17 @@ annotations.draw = function(gd, index, opt, value) {
// how-to-get-the-width-of-an-svg-tspan-element
var arrowX0, arrowY0;

if(options.axref === options.xref)
if(options.axref === options.xref) {
arrowX0 = annPosPx.aax + dx;
else
} else {
arrowX0 = annPosPx.x + dx;
}

if(options.ayref === options.yref)
if(options.ayref === options.yref) {
arrowY0 = annPosPx.aay + dy;
else
} else {
arrowY0 = annPosPx.y + dy;
}

// create transform matrix and related functions
var transform =
Expand Down Expand Up @@ -654,15 +664,17 @@ annotations.draw = function(gd, index, opt, value) {
(options.y + dy / ya._m) :
(1 - ((arrowY + dy - gs.t) / gs.h));

if(options.axref === options.xref)
if(options.axref === options.xref) {
update[annbase + '.ax'] = xa ?
(options.ax + dx / xa._m) :
((arrowX + dx - gs.l) / gs.w);
}

if(options.ayref === options.yref)
if(options.ayref === options.yref) {
update[annbase + '.ay'] = ya ?
(options.ay + dy / ya._m) :
(1 - ((arrowY + dy - gs.t) / gs.h));
}

anng.attr({
transform: 'rotate(' + textangle + ',' +
Expand Down Expand Up @@ -706,15 +718,17 @@ annotations.draw = function(gd, index, opt, value) {
ann.call(Lib.setTranslate, x0 + dx, y0 + dy);
var csr = 'pointer';
if(options.showarrow) {
if(options.axref === options.xref)
if(options.axref === options.xref) {
update[annbase + '.ax'] = xa.p2l(xa.l2p(options.ax) + dx);
else
} else {
update[annbase + '.ax'] = options.ax + dx;
}

if(options.ayref === options.yref)
if(options.ayref === options.yref) {
update[annbase + '.ay'] = ya.p2l(ya.l2p(options.ay) + dy);
else
} else {
update[annbase + '.ay'] = options.ay + dy;
}

drawArrow(dx, dy);
}
Expand Down
20 changes: 20 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ axes.coerceRef = function(containerIn, containerOut, gd, axLetter, dflt) {
return Lib.coerce(containerIn, containerOut, attrDef, refAttr);
};

//todo: duplicated per github PR 610. Should be consolidated with axes.coerceRef.
// find the list of possible axes to reference with an axref or ayref attribute
// and coerce it to that list
axes.coerceARef = function(containerIn, containerOut, gd, axLetter, dflt) {
var axlist = gd._fullLayout._has('gl2d') ? [] : axes.listIds(gd, axLetter),
refAttr = 'a' + axLetter + 'ref',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicely done.

attrDef = {};

// data-ref annotations are not supported in gl2d yet

attrDef[refAttr] = {
valType: 'enumerated',
values: axlist.concat(['pixel']),
dflt: dflt || 'pixel' || axlist[0]
};

// axref, ayref
return Lib.coerce(containerIn, containerOut, attrDef, refAttr);
};

// empty out types for all axes containing these traces
// so we auto-set them again
axes.clearTypes = function(gd, traces) {
Expand Down