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

Update tooltip content and styling on update() #6181

Closed
wants to merge 6 commits into from
Closed

Update tooltip content and styling on update() #6181

wants to merge 6 commits into from

Conversation

Evertvdw
Copy link

@Evertvdw Evertvdw commented Apr 2, 2019

Fixes issue #4991

Another attempt at this issue, credits go to @kurkle.

The tooltip is now updated based on the new data that is visible under the mouse and hides if that point is no longer visible.

To do this the last mouse event is stored and passed to the eventhandler upon update. The data for the tooltip is updated during transition as well as the hover styling of the point.

For a working example of this PR: https://codepen.io/Evertvdw/pen/PgqbWq

Current behaviour: https://codepen.io/Evertvdw/pen/QPbdLQ

@Evertvdw
Copy link
Author

Evertvdw commented Apr 2, 2019

Found a mistake still that did not set lastActive to an empty initially. This resulted in #3791 breaking again, so needed to fix it.

@benmccann
Copy link
Contributor

I believe there was an objection to calling me.eventHandler in #5817 and it looks like that's still being done. Is it possible to call tooltip.update instead? #5817 (comment)

@kurkle
Copy link
Member

kurkle commented Apr 10, 2019

I believe there was an objection to calling me.eventHandler in #5817 and it looks like that's still being done. Is it possible to call tooltip.update instead? #5817 (comment)

I don't think its possible.

@benmccann
Copy link
Contributor

@kurkle can you clarify why you don't think it's possible?

@kurkle
Copy link
Member

kurkle commented Apr 15, 2019

@kurkle can you clarify why you don't think it's possible?

To clarify, it certainly is possible, it just does not work correctly 😏

And the reason is: tooltip._active array might contain items that are no longer available and / or under the mouse.
So those active items need to be re-evaluated and that's what eventHandler does (for both hover and tooltip).

@kurkle kurkle requested a review from nagix April 15, 2019 18:39
@Evertvdw
Copy link
Author

I guess this PR basically does what was proposed here:

#4991 (comment)

src/core/core.tooltip.js Outdated Show resolved Hide resolved

if (me._lastEvent && me.animating) {
// If, during animation, element under mouse changes, let's react to that.
me.active = me.getElementsAtEventForMode(me._lastEvent, hoverOptions.mode, hoverOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply calling eventHandler but duplicating code in handleEvent? I think other logic such as calling the onHover callback is also needed.

Copy link
Author

Choose a reason for hiding this comment

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

That is probably right, I replaced these lines now with a call to eventHandler.

} else {
me.active = me.getElementsAtEventForMode(e, hoverOptions.mode, hoverOptions);
me._lastEvent = e;
Copy link
Contributor

Choose a reason for hiding this comment

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

If 'click' event is picked here, this issue will occur.

Copy link
Author

Choose a reason for hiding this comment

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

I cannot reproduce that issue in the codepen I have provided with the PR code, I think that issue there was with refiring the actual click event.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this issue when clicking the legend in your codepen.

} else {
me._active = me._chart.getElementsAtEventForMode(e, options.mode, options);
me._lastEvent = e;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

@benmccann
Copy link
Contributor

@Evertvdw will you be able to address @nagix's comments?

@Evertvdw
Copy link
Author

@Evertvdw will you be able to address @nagix's comments?

Sorry I forgot about this for a bit, but yes I think I can store the lastEvent only if that is not a click of course. About his first comment I need to look into that, but don't have the time right now.

@Evertvdw
Copy link
Author

Evertvdw commented Jun 5, 2019

Updated codepen: PR 6181 Updated

@ylor
Copy link

ylor commented Jul 1, 2019

I'd love to see this merged. Require it for project with a constantly updating dataset.

Thanks for all your hard work @Evertvdw

@Evertvdw
Copy link
Author

Evertvdw commented Jul 2, 2019

@benmccann @nagix can you review this?

@benmccann
Copy link
Contributor

It looks fine to me though I'm not very familiar with this part of the code, so I'll defer to @etimberg @nagix @kurkle on this one. Thanks for having been patient on this one and for following up on it

src/core/core.controller.js Outdated Show resolved Hide resolved
src/core/core.tooltip.js Show resolved Hide resolved
src/core/core.controller.js Outdated Show resolved Hide resolved
src/core/core.tooltip.js Outdated Show resolved Hide resolved
src/core/core.tooltip.js Show resolved Hide resolved
etimberg
etimberg previously approved these changes Sep 7, 2019
@Evertvdw
Copy link
Author

Implemented the rieview, so everything is good now?

@kurkle
Copy link
Member

kurkle commented Sep 12, 2019

Can you update the pen too?

@Evertvdw
Copy link
Author

Yes, updated the PR pen: https://codepen.io/Evertvdw/pen/PgqbWq

src/core/core.controller.js Outdated Show resolved Hide resolved
Copy link
Member

@kurkle kurkle left a comment

Choose a reason for hiding this comment

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

LGTM

@kurkle kurkle requested review from benmccann and nagix October 14, 2019 10:51
@SebZar
Copy link

SebZar commented Oct 15, 2019

Hi,
can someone fix the codeclimate issue and force the merge.

I' also waiting for this update. :-)

@benmccann
Copy link
Contributor

@Evertvdw thanks so much for your patience. I think this PR is ready to be merged since it has been approved by @kurkle, @etimberg, and myself. Unfortunately there's a merge conflict. Would you be able to rebase this PR against master so we can merge it?

@benmccann
Copy link
Contributor

Rebased and merged in #6635

@benmccann benmccann closed this Oct 29, 2019
@Evertvdw
Copy link
Author

@benmccann Sorry, I forgot about it again, but thanks for doing it!

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.

7 participants