leeoniya / uPlot

📈 A small, fast chart for time series, lines, areas, ohlc & bars
MIT License
8.51k stars 371 forks source link

Hide drawing over axis #891

Closed 3rdBlock closed 6 months ago

3rdBlock commented 6 months ago

Is there a way to stop drawings from overflowing into the axis?

Screenshot 2023-04-07 235157

https://leeoniya.github.io/uPlot/demos/draw-hooks.html

As you can see in your example, if you zoom to specific areas the stars are visible in the axis zone. This is an issue if you have panning and zoom controls as it constantly overflows (both sides) into the axis view.

leeoniya commented 6 months ago

in that demo, you can copy these lines into drawPointsAsStars():

https://github.com/leeoniya/uPlot/blob/6221297595add587a2a877ea297eb0c5107d9928/demos/draw-hooks.html#L94-L96

you can also/instead refine the filtering conditions of the point drawing loop to exclude i0 and i1 idxs if they land outside u.scales.x.min and u.scales.x.max:

https://github.com/leeoniya/uPlot/blob/6221297595add587a2a877ea297eb0c5107d9928/demos/draw-hooks.html#L157-L159C23