-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
annotation hover text #1573
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
annotation hover text #1573
Conversation
src/components/annotations/draw.js
Outdated
|
||
var annTextGroupInner = annTextGroup.append('g') | ||
.style('pointer-events', 'all') | ||
.call(setCursor, 'default') | ||
.on('click', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plotly_clickannotation
was present, but didn't actually work before this, as far as I can tell, because it didn't have pointer-events
turned back on. Anyway I had to do this to make hover work. A potential downside to this is that annotations grab mouse interactions even if you don't use them, so if you have a data point that's entirely under an annotation you won't see it in hover. You could imagine only grabbing mouse events if you are using them for hover, but then you won't get click events, and at draw time it's generally not known yet whether click events are going to be captured... so I don't see any way around this.
Anyway, I only attached click and hover to the text box, not to the arrows, and both are included in the new test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only attached click and hover to the text box, not to the arrows
That's sounds like the desired behavior to me.
src/components/color/index.js
Outdated
|
||
var newColor = tc.isDark() ? | ||
(lightAmount ? tc.lighten(lightAmount) : '#fff') : | ||
(darkAmount ? tc.darken(darkAmount) : '#000'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched from tc.isLight
to tc.isDark
just because isLight
calls isDark
anyway 🐎 .
Thoughts about my TODO?
TODO: black is what we've always done for hover, but should it be #444 instead?
(ie Color.defaultLine
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts about my TODO?
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 919580e
var bBox = this.getBoundingClientRect(); | ||
var bBoxRef = gd.getBoundingClientRect(); | ||
|
||
Fx.loneHover({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a new attribute captureevents
in da1e9d7
This one defaults to false (so data point hover comes through) unless hovertext
is provided. But as noted in the description, if you use plotly_clickannotation
events you must explicitly turn this on.
@cldougl once this is merged we should update the (currently broken) example in https://plot.ly/javascript/text-and-annotations/#styling-and-formatting-annotations, and add a section about plotly_clickannotation
in https://plot.ly/javascript/plotlyjs-events/ that specifically mentions captureevents
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it-- just made an issue to keep track.
@alexcjohnson was there something specifically broken in https://plot.ly/javascript/text-and-annotations/#styling-and-formatting-annotations (just took a quick look and it seemed to work as expected) or should it just be updated to use plotly_clickannotation
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cldougl - I moved further discussion of this into the docs issue you made.
@@ -120,6 +120,7 @@ module.exports = function handleAnnotationDefaults(annIn, annOut, fullLayout, op | |||
color: hoverBorder | |||
}); | |||
} | |||
coerce('captureevents', !!hoverText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe hoverText.length > 0
, as !![] \\ => true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For annotations, hovertext
is a string, I think this is OK. But you're absolutely right when this moves into traces and can be an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right. My bad.
Nicely done 💃 |
- to that there (as opposed to in trace module hoverPoints) to have to repeat this logic across all trace modules - note that PR #1573 already added the relevant `createHoverText` logic
CI tests of master seem to be failing since this merge (local tests are ok for me):
Merge build: https://circleci.com/gh/plotly/plotly.js/4087#tests/containers/1 |
Huh, thanks for the heads up @rpaskowitz. Not sure if this is an intermittent issue or a merge issue but I'll sort it out tonight. |
It's intermittent. I've encountered this since Monday too. |
Provides hover text for annotations, using the existing hover label framework so you get stuff like automatic left/right flipping built in. Because this is a bit of a custom scenario anyway, and it's not always clear what style these hover labels should get, I included explicit styling. @etpinard and I iterated on this separately to come up with a structure that should work for styling trace hover items as well: