Skip to content

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

Merged
merged 5 commits into from
Apr 11, 2017
Merged

annotation hover text #1573

merged 5 commits into from
Apr 11, 2017

Conversation

alexcjohnson
Copy link
Collaborator

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:

{
  annotations: [
    {
      ...,
      hovertext: "hello!",
      hoverlabel: {
        font: {
          family: "courier",
          size: 20,
          color: "#f00"
        },
        bgcolor: "#0ff",
        bordercolor: "#080"
      }
    }
  ]
}

screen shot 2017-04-10 at 10 28 21 am


var annTextGroupInner = annTextGroup.append('g')
.style('pointer-events', 'all')
.call(setCursor, 'default')
.on('click', function() {
Copy link
Collaborator Author

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.

Copy link
Contributor

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.


var newColor = tc.isDark() ?
(lightAmount ? tc.lighten(lightAmount) : '#fff') :
(darkAmount ? tc.darken(darkAmount) : '#000');
Copy link
Collaborator Author

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)

Copy link
Contributor

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!

Copy link
Collaborator Author

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({
Copy link
Contributor

@etpinard etpinard Apr 10, 2017

Choose a reason for hiding this comment

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

peek 2017-04-10 12-07

so this means the annotation hover takes precedence over trace hover. I don't think this a big deal. But perhaps we could make annotation hover pass by Fx.hover so that they don't conflict sort of speak.

Copy link
Collaborator Author

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.

Copy link
Member

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?

Copy link
Collaborator Author

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);
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right. My bad.

@etpinard etpinard added this to the v1.26.0 milestone Apr 11, 2017
@etpinard
Copy link
Contributor

Nicely done 💃 1.26.0 will be a good one.

@alexcjohnson alexcjohnson merged commit 00355fb into master Apr 11, 2017
@alexcjohnson alexcjohnson deleted the note-hover branch April 11, 2017 00:43
etpinard added a commit that referenced this pull request Apr 11, 2017
- 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
@etpinard etpinard mentioned this pull request Apr 11, 2017
3 tasks
@rpaskowitz
Copy link
Contributor

CI tests of master seem to be failing since this merge (local tests are ok for me):

Chrome 54.0.2840 (Linux 0.0.0) annotation effects should register clicks and show hover effects on the text box only FAILED
	Expected 0 to equal 1, '0 only (0)'.
	    at /tmp/tests/annotations_test.js:1084:0 <- /tmp/ba4b1756258f0bb2a60f96899bbad74d.browserify:196097:46

Merge build: https://circleci.com/gh/plotly/plotly.js/4087#tests/containers/1

Currently affecting #1588 and #1589

@alexcjohnson
Copy link
Collaborator Author

CI tests of master seem to be failing since this merge

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.

@etpinard
Copy link
Contributor

Not sure if this is an intermittent issue

It's intermittent. I've encountered this since Monday too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants