uPlot icon indicating copy to clipboard operation
uPlot copied to clipboard

the tooltip stick to points

Open Sam-tech94 opened this issue 1 year ago • 1 comments

Screenshot 2024-02-29 at 11 34 11

How to make the tooltip stick to points

Measure / Datums
<link rel="stylesheet" href="../dist/uPlot.min.css">

Sam-tech94 avatar Feb 29 '24 07:02 Sam-tech94

Hi Sam, I was implementing same feature to lock tooltip when user click inside uPlot and i want to share my solution.

funtion initTooltip(){
  // first we make variable to track if tooltip should be locked
  let locked = false;
  // initalize tooltip plugin
  const tooltip = {
    init: (u)=>{
      // initialize overlay like yours
      // add click listener on u.over
      u.over.addEventListener("click", ()=>{
        // toogle locked variable
        locked = !locked;
        // here to lock uPlot, user cannot interact to uPlot instance until lock is released (next click).
        // this is from option uPlot.Cursor after initialization
        u.cursor._lock = locked;
      })
    },
    setCursor: (u)=>{
      if(locked) return;
      // the rest of your update function
    }
  }
  return tooltip;
}

capture

poetrasapoetra avatar Jun 05 '24 05:06 poetrasapoetra