Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork21
Open
Milestone
Description
When working on custom mark components in user land one currently has to access the plot internals (scales, dimensions, etc) via
import{getContext}from'svelte';importtype{PlotContext}from'svelteplot/types/plot';const{ getPlotState}=getContext<PlotContext>('svelteplot');constplot=$derived(getPlotState());// now you can use plot.width, plot.scales, etc
This is rather verbose and it would be nicer to use the component hook pattern
import{usePlot}from'svelteplot';constplot=usePlot()// now you can use plot.width, plot.scales, etc
Example implementation
@ixxie kindly provided a sketch for how this implementation could work:https://stackblitz.com/edit/sveltefoo?file=src%2Flib%2Fwidget%2FuseWidget.svelte.ts
Open questions
- Should this hook also be used for setting plot defaults or should this be a different hook? -> No, we use a separate hook
setPlotDefaultsintroduced infeat: add setPlotDefaults and getPlotDefaults hooks #219 - Should we provide a way to access internals from a plotinside the component that is using the hook? The common use case would be to use the hook in a child component of a Plot, but in some scenarios (e.g. a Plot wrapper component) it may be useful to access the internals of a plot outside it. This would have to be done carefully since there could potentially be multiple plots competing for the same context state.