leeoniya / uPlot

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

A question about setSelect #879

Closed zefirka closed 7 months ago

zefirka commented 7 months ago

Hi! I have a question about setSelect and initialization of plot. I discovered that on init setSelect will be triggered based on select.show, which leads to triggering setSelect every time chart inits. Why does that happen?

I have some handler on setSelect. I try to understand may I rely on u.select.width === 0 to skip my handler. Are there any cases when setSelect fired but select width is 0 except the first initialization fire?

leeoniya commented 7 months ago

I discovered that on init setSelect will be triggered based on select.show, which leads to triggering setSelect every time chart inits. Why does that happen?

i think the intent was to allow setting the selection at the time of initialization, or maybe to allow default hidden styling. maybe this can be skipped during init if width or height is 0. :thinking:

I try to understand may I rely on u.select.width === 0 to skip my handler.

yes

Are there any cases when setSelect fired but select width is 0 except the first initialization fire?

if you manually call u.setSelect() with a width of 0 (to hide it), it will call the hook. unless fireHook arg is false: https://github.com/leeoniya/uPlot/blob/cf139ff2e0e1eef64694033f86ac003a36b7a5a6/dist/uPlot.d.ts#L105

leeoniya commented 7 months ago

should be fixed now.

since uPlot doesn't invoke setSelect hooks for its own auto-hide actions (like during zoom mouseup), it shouldn't run it during init either (unless the initial selection dims are non-zero)