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

Close the tooltip after certain delay

Open BaptisteMartinet opened this issue 3 years ago • 1 comments

Feature Proposal

I would like a way to force the tooltip to close after a certain delay if the mouse/pointer has not moved. This would be super usefull, especially on mobile devices where the tooltip sometimes stays open indefinitely. My suggestion would be to add an option to the tooltip, specifying a way to close the tooltip after a certain delay.

Possible Implementation

I believe debouncing should be used here to reset the timer to the closeAfterDelay value when clicking/hovering a new datapoint.

  options: {
    plugins: {
      tooltip: {
        closeAfterDelay: 3000, // Force the tooltip to close after 3 seconds
      }
    }
  }
}

BaptisteMartinet avatar Nov 22 '22 11:11 BaptisteMartinet

I think the best approach here would be to write a custom plugin that listens to the beforeEvent hook, and set a timeOut, reset this once the hook is called again.

If the timeout is done you can setActiveElements function on the tooltip with an empty array and an xy object both set to 0

LeeLenaleee avatar Nov 22 '22 22:11 LeeLenaleee