Tooltip smooth transaction movement on points
i think you need to add the below in bold if condition to prevent tool-tip from disappearing between points to give it smooth movement.
Chart.bundle.js in eventHandler for tool-tip :
. . . .
// On Hover hook
if (hoverOptions.onHover) {
hoverOptions.onHover.call(me, me.active);
}
if (e.type === 'mouseup' || e.type === 'click') {
if (options.onClick) {
options.onClick.call(me, e, me.active);
}
if (me.legend && me.legend.handleEvent) {
me.legend.handleEvent(e);
}
}
if (me.active.length) {
// Remove styling for last active (even if it may still be active)
if (me.lastActive.length) {
me.updateHoverStyle(me.lastActive, hoverOptions.mode, false);
}
. .
// We only need to render at this point. Updating will cause scales to be
// recomputed generating flicker & using more memory than necessary.
me.render(700, true);
}
}
}
else {
// Remember Last Actives
me.active = me.lastActive;
me.tooltipActive = me.lastTooltipActive;
}
me.lastActive = me.active;
me.lastTooltipActive = me.tooltipActive;
return me;
}
@moohhoom can you post a fiddle with your fix? alternatively, can you open a PR?
Here you go
With : https://jsfiddle.net/zek4ucgL/
Without: https://jsfiddle.net/zek4ucgL/2/
try to Hover on points and see how tooltip move.
Hmm, the issue I see is that it's impossible to remove the tooltip once it is visible in the first fiddle
why ?
check this : https://jsfiddle.net/zek4ucgL/3/
try to leave the chart ..
i just added
$("#" + me.chart.canvas.id).on("mouseleave", function () {
if (xxx == undefined) {
var xxx = setTimeout(function () {
if (me.active != undefined || me.lastActive != undefined) {
me.active = me.lastActive = undefined;
//tooltip.initialize();
tooltip._active = me.tooltipActive = [];
tooltip.update(true);
//tooltip.pivot();
me.render(700, true);
// console.log("YES");
return;
}
}, 1000)
}
});
after the IF condition.
Edit: fixed code formatting
That does remove the tooltip on leave, but not all users want the last tooltip to remain before they hit the next one.
CC @chartjs/maintainers thoughts?
thanks @moohhoom was looking for this feature. it will be great if this can enabled through chart options
Agree, not all users want this behavior so as @nakkeeran suggested, an option is required in order to expose that new feature. But I don't think that's the best approach because having tooltips always visible while on the chart might be annoying and can be perceived as a bug.
Since your initial issue is "smooth transition between tooltips", I would rather add an hideDelay option to control how long the tooltip is displayed after the user has moved the mouse away (default to 0ms), but implementing this could be more complex.
Linking to your associated PR #3350
I'm quite sure that will be fixed by @etimberg PR #3400 :)
thanks @etimberg @simonbrunel 👍
Done in #3400