Skip to content

Tooltip not destroyed #20969

Closed
Closed

Description

@markoberholzer-es

Expected behaviour

Tooltip should always be destroyed when a mouse out event occurs.

Actual behaviour

On slower clients, tooltips may not be destroyed if the user moves the mouse rapidly across multiple charts.

Live demo with steps to reproduce

JsFiddle: JSFiddle Demo
Video: Tooltip Demo Video

  1. Open DevTools
  2. Select Performance
  3. Set CPU to 6x Slowdown (easier to reproduce)
  4. Move mouse quickly a couple of times over all charts and then move it out of the canvas ex. devtools

Product version

Most likely the problem started to occur since after upgrading from 11.1.0 to 11.2.0 (newest version is affected as well)

Activity

  1. hubertkozik commented on Apr 9, 2024

    @hubertkozik
    Member

    Hi @markoberholzer-es!

    Indeed, I would treat it as a bug, because the tooltip should be destroyed after the delay time.

    Internal note:
    I tried to bisect, but there are too many issues in compiling between version 11.1.0 and 11.2.0.

  2. markoberholzer-es commented on Apr 9, 2024

    @markoberholzer-es
    Author

    @hubertkozik - thx for your feedback and digging into that topic!

  3. markoberholzer-es commented on Apr 16, 2024

    @markoberholzer-es
    Author

    For all that come across this issue - the following workaround fixed the issue in our case:

    import * as Highcharts from 'highcharts'
    
    /**
     * This module contains a fix for the tooltip issues stated in https://github.com/highcharts/highcharts/issues/20969
     * TODO: Remove this module once the issue is fixed in highcharts
     * @param {Highcharts} H Highcharts
     * @constructor
     * @remarks this module hides the tooltip when the mouse leaves the chart
     */
    export function HideTooltipOnLeave(H: typeof Highcharts) {
      const timeoutIds: Record<string, ReturnType<typeof setTimeout>> = {}
    
      H.addEvent(H.Chart, 'load', function (e) {
        const chart = e?.target
        const chartId = chart.container.id
        if (!chart) return
    
        // Delay for hiding the tooltip - the default is 500ms - we add 200ms to give highcharts time to handle itself
        const delay = (chart.tooltip?.options?.hideDelay ?? 500) + 200
    
        /**
         * Event-Handler for mouseleave event on chart-container
         */
        H.addEvent(chart.container, 'mouseleave', function () {
          // Clear any existing timeout for this chart
          if (timeoutIds[chartId]) {
            clearTimeout(timeoutIds[chartId])
            delete timeoutIds[chartId] // remove the entry
          }
    
          timeoutIds[chartId] = setTimeout(() => {
            const tooltip = chart.tooltip
            //Hide the tooltip (#20969)
            if (!chart.tooltip?.label || tooltip?.label?.visibility === 'hidden') return
    
            chart.tooltip.label.hide()
            // Clear the container for outside tooltip (#18490)
            if (chart.tooltip.container) {
              chart.tooltip.container.remove()
            }
          }, delay)
        })
    
        /**
         * Event-Handler for mouseenter event on chart-container
         */
        H.addEvent(chart.container, 'mouseenter', function () {
          // Clear the timeout when re-entering the chart
          if (timeoutIds[chartId]) {
            clearTimeout(timeoutIds[chartId])
            delete timeoutIds[chartId] // remove the entry
          }
        })
      })
    }
    
    
  4. MarkusBarstad commented on May 22, 2024

    @MarkusBarstad
    Contributor

    Just a note on the example fiddle, @markoberholzer-es ;

    The charts in the fiddle seem to overlap in area. When I add some space between the charts plot areas (I used the margin css property) I am not able to reproduce the bug anymore.

    Could this be the culprit?

  5. h3mpti commented on May 22, 2024

    @h3mpti

    Just a note on the example fiddle, @markoberholzer-es ;

    The charts in the fiddle seem to overlap in area. When I add some space between the charts plot areas (I used the margin css property) I am not able to reproduce the bug anymore.

    Could this be the culprit?

    Hi there, thanks for the feedback. Maybe it’s a workaround, but the behavior changed with the versions, so this is an undocumented breaking change with no real reason IMHO (and unfortunately that doesn’t seem to be the only case). An official fix/documented solution would be really appreciated.

  6. linked a pull request that will close this issuebugfix/20969-tooltip-not-destroyed #21212on May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions