leeoniya / uPlot

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

I want to modify series.stroke in the form of an API #863

Open dingjunweibjkanyun opened 9 months ago

dingjunweibjkanyun commented 9 months ago
image

When can we support it?

leeoniya commented 9 months ago

i think the main reason i left out style opts like width or stroke/fill is that some can be callbacks and it's kinda weird to redefine the callback (some of them are internally cached...though i don't think these are).

for style related changes you can always mutate and redraw, which is how i've done it:

u.series[1].stroke = 'orange';
u.redraw();

https://github.com/leeoniya/uPlot/blob/e8a1e8d6b70ca72f6e70d1f14894bc4a98cb47f2/dist/uPlot.d.ts#L64-L65

you can also have


let myStroke = 'red';

let opts = {
  series: [
    {},  
    {
      stoke: () => myStroke,
    }
  ]
}

// then...

myStroke = 'orange';
u.redraw();

setSeries was meant for more complex stuff that required multiple internal (or unknown/auto) state changes. e.g. show can actually auto-toggle axes visibility, it can trigger rescaling & path rebuilding, changes legend styling, etc.

i guess the above mutation strategy would not affect the legend, which is in the DOM, and the styles are only set at initialization time :thinking:. you'd have to also mutate the legend's items style directly in DOM, which is more gross.

i'll think about it.

dingjunweibjkanyun commented 9 months ago

tks very much