leeoniya / uPlot

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

Preserve selection #882

Open d0z0 opened 6 months ago

d0z0 commented 6 months ago

Firstly thanks for this amazing library.

I've been trying to preserve selection when I've got cursor.drag.setScale = false in a sync'd ranger. I had a look at the https://leeoniya.github.io/uPlot/demos/zoom-ranger.html demo, and once a selection is made, if you click anywhere else, the selection is reset in the ranger.

Is there an easy way to prevent that reset? I've tried setting cursor.bind.click to () => null, but that didn't work.

leeoniya commented 6 months ago

does this help? https://github.com/leeoniya/uPlot/issues/867#issuecomment-1763709227

d0z0 commented 6 months ago

Thanks for your reply.

I was wondering if a better alternative would be to have a configuration option to preserve the selection such that when it's enabled, it wouldn't do a hideSelect() https://github.com/leeoniya/uPlot/blob/38f63de6843d64e703fa23596d9525c15d003ecd/src/uPlot.js#L2916 We could cache the selection and restore the cached selection if there is a cancel mid selection? (eg: Escape modifier key during the mouseup?) or if the width of the new selection is 0

If you feel this makes sense, I can take a stab at it