layerchart icon indicating copy to clipboard operation
layerchart copied to clipboard

Expose `SeriesState` for simplified charts

Open techniq opened this issue 8 months ago • 4 comments

Expose SeriesState for simplified charts to enable:

  • Setting initial selected series
  • Externally controlling selection
  • Reading/writing selection to local storage, etc

techniq avatar May 05 '25 14:05 techniq

I would also find it useful to expose BrushState for persisting in localstorage. This allows for persistence of series and selected range.

cycle4passion avatar Jul 11 '25 18:07 cycle4passion

I would also find it useful to expose BrushState for persisting in localstorage. This allows for persistence of series and selected range.

100% agree, and actually started on this a bit ago and need to resume. Encapsulating the state in a new BrushState class will enable and simplify state management (this is a pattern I plan to lean into with more state management). Also looking at supporting band scales and fixing some element click interop.

Progress here: https://github.com/techniq/layerchart/pull/605

techniq avatar Jul 14 '25 12:07 techniq

In addition to exposing SereisState, BrushState, others, what about a prop like ...

<Chart persist="localStorage" / >

and Layerchart goes ahead and does the heavy lifting read/write to localStorage or sessionStorage?

cycle4passion avatar Jul 16 '25 10:07 cycle4passion

In addition to exposing SereisState, BrushState, others, what about a prop like ...

<Chart persist="localStorage" / >

and Layerchart goes ahead and does the heavy lifting read/write to localStorage or sessionStorage?

Hmm... we would need to generate a unique ID per chart instance (could use $props.id()).

Initially I would prefer to have some callback hooks, similar to SvelteKit snapshots (capture / restore) and leave it to the user where the would like to persist (localStorage, sessionStorage, query string, API/db call, etc).

I think we approach this iteratively - expose the state, expose the hooks, and then maybe add convenient adapters if needed.

techniq avatar Jul 16 '25 12:07 techniq