Skip to content
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

Add an example of using popper.js to show a tooltip #894

Merged
merged 3 commits into from
Jul 31, 2018

Conversation

cnwangjie
Copy link
Contributor

No description provided.

Copy link
Collaborator

@wlach wlach left a comment

Choose a reason for hiding this comment

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

Code looks good except for the text, where I have some changes suggested for the wording. I played a bit with the actual examples: they work well, but it seems like the tooltip stays in place even after the user hovers away from the graph. Is there a way around that?

data = MG.convert.date(data, 'date');
MG.data_graphic({
title: "Tooltip on line chart",
description: "This is an example to use popper.js to show a tooltip on line chart.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change this (here and below, too bad we duplicate the code in two places for these examples) to:

Using popper.js and the mouseover callback, you can easily create a tooltip when the user hovers over a particular datapoint.

d3.json('data/points1.json', function(data) {
MG.data_graphic({
title: "Tooltip on point chart",
description: "This is an example to use popper.js to show a tooltip on point chart.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change text to: This technique also works for point charts

tooltipEl.innerText = `date: ${d3.timeFormat('%b %e, %Y')(d.date)}\nvalue: ${d.value}`;
tooltip.reference = d3.select(`#tooltip-line-chart .mg-line-rollover-circle`).node();
tooltip.update();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the mouseout callback to make the tooltip disappear when the user hovers away from the graph?

@cnwangjie
Copy link
Contributor Author

@wlach Ok, I've submitted the changes. I found that if just hide tooltip on mouse out of point, the tooltip will flash. So I also bind an event on the tooltip element to avoid this.

@wlach wlach merged commit 0e03630 into metricsgraphics:master Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants