Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Tooltip smooth transaction movement on points

Open moohhoom opened this issue 10 years ago • 10 comments

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 avatar Sep 21 '16 07:09 moohhoom

@moohhoom can you post a fiddle with your fix? alternatively, can you open a PR?

etimberg avatar Sep 21 '16 18:09 etimberg

Here you go

With : https://jsfiddle.net/zek4ucgL/

Without: https://jsfiddle.net/zek4ucgL/2/

try to Hover on points and see how tooltip move.

moohhoom avatar Sep 22 '16 06:09 moohhoom

Hmm, the issue I see is that it's impossible to remove the tooltip once it is visible in the first fiddle

etimberg avatar Sep 22 '16 19:09 etimberg

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

moohhoom avatar Sep 22 '16 19:09 moohhoom

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?

etimberg avatar Sep 22 '16 23:09 etimberg

thanks @moohhoom was looking for this feature. it will be great if this can enabled through chart options

nakkeeran avatar Sep 23 '16 05:09 nakkeeran

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

simonbrunel avatar Sep 23 '16 07:09 simonbrunel

I'm quite sure that will be fixed by @etimberg PR #3400 :)

simonbrunel avatar Oct 02 '16 19:10 simonbrunel

thanks @etimberg @simonbrunel 👍

nakkeeran avatar Oct 03 '16 05:10 nakkeeran

Done in #3400

etimberg avatar Oct 05 '16 23:10 etimberg