Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Expose plot internals via usePlot hook #215

Labels
enhancementNew feature or request
Milestone
@gka

Description

@gka

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 hooksetPlotDefaults introduced 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp