svelteplot 0.8.1-pr-298.7 → 0.8.1-pr-301.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/core/Plot.svelte +4 -4
  3. package/dist/hooks/usePlot.svelte.d.ts +51 -0
  4. package/dist/hooks/usePlot.svelte.js +90 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/marks/Area.svelte +3 -5
  8. package/dist/marks/Arrow.svelte +3 -5
  9. package/dist/marks/AxisX.svelte +2 -3
  10. package/dist/marks/AxisY.svelte +2 -3
  11. package/dist/marks/BarX.svelte +2 -4
  12. package/dist/marks/BarY.svelte +2 -4
  13. package/dist/marks/Brush.svelte +3 -3
  14. package/dist/marks/Cell.svelte +2 -4
  15. package/dist/marks/ColorLegend.svelte +2 -4
  16. package/dist/marks/CustomMarkHTML.svelte +5 -10
  17. package/dist/marks/DifferenceY.svelte +3 -5
  18. package/dist/marks/Dot.svelte +4 -5
  19. package/dist/marks/Frame.svelte +3 -9
  20. package/dist/marks/Geo.svelte +3 -5
  21. package/dist/marks/GridX.svelte +3 -10
  22. package/dist/marks/GridY.svelte +3 -4
  23. package/dist/marks/HTMLTooltip.svelte +5 -5
  24. package/dist/marks/Line.svelte +2 -4
  25. package/dist/marks/Link.svelte +2 -4
  26. package/dist/marks/Pointer.svelte +4 -4
  27. package/dist/marks/Rect.svelte +2 -4
  28. package/dist/marks/RectX.svelte +4 -4
  29. package/dist/marks/RectY.svelte +4 -4
  30. package/dist/marks/RuleX.svelte +2 -4
  31. package/dist/marks/RuleY.svelte +2 -4
  32. package/dist/marks/SymbolLegend.svelte +2 -4
  33. package/dist/marks/SymbolLegend.svelte.d.ts +17 -2
  34. package/dist/marks/TickX.svelte +2 -3
  35. package/dist/marks/TickY.svelte +2 -3
  36. package/dist/marks/Trail.svelte +3 -5
  37. package/dist/marks/Vector.svelte +3 -4
  38. package/dist/marks/WaffleX.svelte +2 -3
  39. package/dist/marks/WaffleY.svelte +2 -4
  40. package/dist/marks/helpers/AreaCanvas.svelte +2 -4
  41. package/dist/marks/helpers/CanvasLayer.svelte +2 -4
  42. package/dist/marks/helpers/DotCanvas.svelte +3 -5
  43. package/dist/marks/helpers/GeoCanvas.svelte +2 -4
  44. package/dist/marks/helpers/LineCanvas.svelte +2 -4
  45. package/dist/marks/helpers/LinearGradientX.svelte +3 -4
  46. package/dist/marks/helpers/LinearGradientY.svelte +3 -4
  47. package/dist/marks/helpers/MarkerPath.svelte +4 -5
  48. package/dist/marks/helpers/MultilineText.svelte +4 -4
  49. package/dist/marks/helpers/RectPath.svelte +5 -6
  50. package/dist/marks/helpers/Regression.svelte +4 -8
  51. package/dist/marks/helpers/TrailCanvas.svelte +2 -4
  52. package/dist/marks/helpers/events.d.ts +2 -2
  53. package/dist/marks/helpers/events.js +4 -4
  54. package/dist/types/plot.d.ts +1 -0
  55. package/dist/ui/Spiral.svelte +4 -0
  56. package/package.json +1 -1
@@ -8,14 +8,14 @@
8
8
  x1?: ChannelAccessor<Datum>;
9
9
  x2?: ChannelAccessor<Datum>;
10
10
  }
11
- import { getContext } from 'svelte';
12
11
  import Mark from '../Mark.svelte';
13
- import type { PlotContext, BaseMarkProps, RawValue, ChannelAccessor } from '../types/index.js';
12
+ import type { BaseMarkProps, RawValue, ChannelAccessor } from '../types/index.js';
14
13
  import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
15
14
  import { autoTicks } from '../helpers/autoTicks.js';
16
15
  import { testFilter } from '../helpers/index.js';
17
16
  import { RAW_VALUE } from '../transforms/recordize.js';
18
17
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
18
+ import { usePlot } from '../hooks/usePlot.svelte.js';
19
19
 
20
20
  let markProps: GridYMarkProps = $props();
21
21
 
@@ -33,8 +33,7 @@
33
33
  ...markProps
34
34
  });
35
35
 
36
- const { getPlotState } = getContext<PlotContext>('svelteplot');
37
- const plot = $derived(getPlotState());
36
+ const plot = usePlot();
38
37
 
39
38
  const autoTickCount = $derived(
40
39
  Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
@@ -12,17 +12,17 @@
12
12
  fy?: ChannelAccessor<Datum>;
13
13
  children: Snippet<[{ datum: Datum }]>;
14
14
  }
15
- import { getContext, type Snippet } from 'svelte';
16
- import type { ChannelAccessor, DataRow, PlotContext } from '../types/index.js';
17
-
18
- const { getPlotState } = getContext<PlotContext>('svelteplot');
19
- let plot = $derived(getPlotState());
15
+ import { type Snippet } from 'svelte';
16
+ import type { ChannelAccessor, DataRow } from '../types/index.js';
17
+ import { usePlot } from '../hooks/usePlot.svelte.js';
20
18
 
21
19
  import { resolveChannel } from '../helpers/resolve.js';
22
20
  import { quadtree } from 'd3-quadtree';
23
21
  import { projectX, projectY } from '../helpers/scales.js';
24
22
  import { groupFacetsAndZ } from '../helpers/group.js';
25
23
 
24
+ const plot = usePlot();
25
+
26
26
  let { data, x, y, r, fx, fy, children }: HTMLTooltipMarkProps = $props();
27
27
 
28
28
  let datum = $state(false);
@@ -23,7 +23,6 @@
23
23
  }
24
24
  import type {
25
25
  CurveName,
26
- PlotContext,
27
26
  DataRecord,
28
27
  BaseMarkProps,
29
28
  ConstantAccessor,
@@ -33,7 +32,6 @@
33
32
  } from '../types/index.js';
34
33
  import Mark from '../Mark.svelte';
35
34
  import MarkerPath from './helpers/MarkerPath.svelte';
36
- import { getContext } from 'svelte';
37
35
  import { resolveProp, resolveStyles } from '../helpers/resolve.js';
38
36
  import { line, type CurveFactory, type Line as D3Line } from 'd3-shape';
39
37
  import { geoPath } from 'd3-geo';
@@ -48,6 +46,7 @@
48
46
  import { recordizeXY } from '../transforms/recordize.js';
49
47
  import GroupMultiple from './helpers/GroupMultiple.svelte';
50
48
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
49
+ import { usePlot } from '../hooks/usePlot.svelte.js';
51
50
 
52
51
  let markProps: LineMarkProps = $props();
53
52
 
@@ -100,8 +99,7 @@
100
99
 
101
100
  const groupByKey = $derived(args.z || args.stroke) as ChannelAccessor<Datum> | null;
102
101
 
103
- const { getPlotState } = getContext<PlotContext>('svelteplot');
104
- const plot = $derived(getPlotState());
102
+ const plot = usePlot();
105
103
 
106
104
  const linePath: D3Line<ScaledDataRecord> = $derived(
107
105
  plot.scales.projection && curve === 'auto'
@@ -34,9 +34,7 @@
34
34
  */
35
35
  text?: ConstantAccessor<string, Datum>;
36
36
  }
37
- import { getContext } from 'svelte';
38
37
  import type {
39
- PlotContext,
40
38
  DataRecord,
41
39
  BaseMarkProps,
42
40
  ConstantAccessor,
@@ -58,6 +56,7 @@
58
56
  import { sort } from '../transforms/sort.js';
59
57
  import { indexData } from '../transforms/recordize.js';
60
58
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
59
+ import { usePlot } from '../hooks/usePlot.svelte.js';
61
60
 
62
61
  let markProps: LinkMarkProps = $props();
63
62
  const DEFAULTS = {
@@ -75,8 +74,7 @@
75
74
  ...markProps
76
75
  });
77
76
 
78
- const { getPlotState } = getContext<PlotContext>('svelteplot');
79
- let plot = $derived(getPlotState());
77
+ const plot = usePlot();
80
78
 
81
79
  const args = $derived(
82
80
  replaceChannels(
@@ -23,8 +23,8 @@
23
23
  onupdate?: (data: Datum[]) => void;
24
24
  }
25
25
 
26
- import { getContext, type Snippet } from 'svelte';
27
- import type { ChannelAccessor, DataRow, PlotContext } from '../types/index.js';
26
+ import { type Snippet } from 'svelte';
27
+ import type { ChannelAccessor, DataRow } from '../types/index.js';
28
28
  import { resolveChannel } from '../helpers/resolve.js';
29
29
  import { quadtree } from 'd3-quadtree';
30
30
  import { projectXY } from '../helpers/scales.js';
@@ -32,9 +32,9 @@
32
32
  import { indexData, RAW_VALUE } from '../transforms/recordize.js';
33
33
  import { groupFacetsAndZ } from '../helpers/group.js';
34
34
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
35
+ import { usePlot } from '../hooks/usePlot.svelte.js';
35
36
 
36
- const { getPlotState } = getContext<PlotContext>('svelteplot');
37
- const plot = $derived(getPlotState());
37
+ const plot = usePlot();
38
38
 
39
39
  const POINTER_X = Symbol('pointerX');
40
40
  const POINTER_Y = Symbol('pointerY');
@@ -16,10 +16,8 @@
16
16
  className?: string;
17
17
  }
18
18
  import Mark from '../Mark.svelte';
19
- import { getContext } from 'svelte';
20
19
  import { intervalX, intervalY } from '../index.js';
21
20
  import type {
22
- PlotContext,
23
21
  DataRecord,
24
22
  BaseMarkProps,
25
23
  BaseRectMarkProps,
@@ -30,6 +28,7 @@
30
28
  import RectPath from './helpers/RectPath.svelte';
31
29
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
32
30
  import { IS_SORTED } from '../transforms/sort';
31
+ import { usePlot } from '../hooks/usePlot.svelte.js';
33
32
 
34
33
  let markProps: RectMarkProps = $props();
35
34
 
@@ -46,8 +45,7 @@
46
45
  ...markProps
47
46
  });
48
47
 
49
- const { getPlotState } = getContext<PlotContext>('svelteplot');
50
- let plot = $derived(getPlotState());
48
+ const plot = usePlot();
51
49
 
52
50
  const args = $derived(
53
51
  intervalY(intervalX({ data, ...options }, { plot }), { plot }) as RectMarkProps
@@ -9,10 +9,11 @@
9
9
 
10
10
  import Rect from './Rect.svelte';
11
11
  import { intervalY, stackX, recordizeX } from '../index.js';
12
- import type { DataRecord, PlotContext } from '../types/index.js';
13
- import { getContext, type ComponentProps } from 'svelte';
12
+ import type { DataRecord } from '../types/index.js';
13
+ import { type ComponentProps } from 'svelte';
14
14
  import type { StackOptions } from '../transforms/stack.js';
15
15
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
16
+ import { usePlot } from '../hooks/usePlot.svelte.js';
16
17
 
17
18
  let markProps: RectXMarkProps = $props();
18
19
 
@@ -30,8 +31,7 @@
30
31
  ...markProps
31
32
  });
32
33
 
33
- const { getPlotState } = getContext<PlotContext>('svelteplot');
34
- let plot = $derived(getPlotState());
34
+ const plot = usePlot();
35
35
 
36
36
  const args = $derived(stackX(intervalY(recordizeX({ data, ...options }), { plot }), stack));
37
37
  </script>
@@ -7,10 +7,11 @@
7
7
  }
8
8
  import Rect from './Rect.svelte';
9
9
  import { intervalX, stackY, recordizeY } from '../index.js';
10
- import type { DataRecord, PlotContext } from '../types/index.js';
11
- import { getContext, type ComponentProps } from 'svelte';
10
+ import type { DataRecord } from '../types/index.js';
11
+ import { type ComponentProps } from 'svelte';
12
12
  import type { StackOptions } from '../transforms/stack.js';
13
13
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
14
+ import { usePlot } from '../hooks/usePlot.svelte.js';
14
15
 
15
16
  let markProps: RectYMarkProps = $props();
16
17
 
@@ -28,8 +29,7 @@
28
29
  ...markProps
29
30
  });
30
31
 
31
- const { getPlotState } = getContext<PlotContext>('svelteplot');
32
- const plot = $derived(getPlotState());
32
+ const plot = usePlot();
33
33
 
34
34
  const args = $derived(stackY(intervalX(recordizeY({ data, ...options }), { plot }), stack));
35
35
  </script>
@@ -13,11 +13,9 @@
13
13
  }
14
14
  import Mark from '../Mark.svelte';
15
15
  import GroupMultiple from './helpers/GroupMultiple.svelte';
16
- import { getContext } from 'svelte';
17
16
  import { recordizeX } from '../transforms/recordize.js';
18
17
  import { resolveProp, resolveStyles } from '../helpers/resolve.js';
19
18
  import type {
20
- PlotContext,
21
19
  DataRecord,
22
20
  BaseMarkProps,
23
21
  ConstantAccessor,
@@ -25,6 +23,7 @@
25
23
  RawValue
26
24
  } from '../types/index.js';
27
25
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
26
+ import { usePlot } from '../hooks/usePlot.svelte.js';
28
27
 
29
28
  let markProps: RuleXMarkProps = $props();
30
29
  const DEFAULTS = {
@@ -40,8 +39,7 @@
40
39
  ...markProps
41
40
  });
42
41
 
43
- const { getPlotState } = getContext<PlotContext>('svelteplot');
44
- const plot = $derived(getPlotState());
42
+ const plot = usePlot();
45
43
  const args = $derived(recordizeX({ data, ...options }, { withIndex: false }));
46
44
  </script>
47
45
 
@@ -13,11 +13,9 @@
13
13
  }
14
14
  import Mark from '../Mark.svelte';
15
15
  import GroupMultiple from './helpers/GroupMultiple.svelte';
16
- import { getContext } from 'svelte';
17
16
  import { recordizeY } from '../transforms/recordize.js';
18
17
  import { resolveProp, resolveStyles } from '../helpers/resolve.js';
19
18
  import type {
20
- PlotContext,
21
19
  DataRecord,
22
20
  BaseMarkProps,
23
21
  ConstantAccessor,
@@ -25,6 +23,7 @@
25
23
  } from '../types/index.js';
26
24
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
27
25
  import { IS_SORTED } from '../transforms/sort';
26
+ import { usePlot } from '../hooks/usePlot.svelte.js';
28
27
 
29
28
  let markProps: RuleYMarkProps = $props();
30
29
  const DEFAULTS = {
@@ -40,8 +39,7 @@
40
39
  ...markProps
41
40
  });
42
41
 
43
- const { getPlotState } = getContext<PlotContext>('svelteplot');
44
- const plot = $derived(getPlotState());
42
+ const plot = usePlot();
45
43
  const args = $derived(recordizeY({ data, ...options }, { withIndex: false }));
46
44
  </script>
47
45
 
@@ -1,11 +1,9 @@
1
1
  <script lang="ts">
2
- import { getContext } from 'svelte';
3
2
  import { symbol as d3Symbol } from 'd3-shape';
4
3
  import { maybeSymbol } from '../helpers/symbols.js';
5
- import type { PlotContext } from '../types/index.js';
4
+ import { usePlot } from '../hooks/usePlot.svelte.js';
6
5
 
7
- const { getPlotState } = getContext<PlotContext>('svelteplot');
8
- let plot = $derived(getPlotState());
6
+ const plot = usePlot();
9
7
 
10
8
  // TODO: allow styling of legend
11
9
  </script>
@@ -1,8 +1,23 @@
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
1
14
  /**
2
15
  * The SymbolLegend is an HTML mark that can be placed in the header, footer and overlay
3
16
  * snippets. You can activate an implicit SymbolLegend above the chart using the global
4
17
  * symbol.legend scale option.
5
18
  */
6
- declare const SymbolLegend: import("svelte").Component<Record<string, never>, {}, "">;
7
- type SymbolLegend = ReturnType<typeof SymbolLegend>;
19
+ declare const SymbolLegend: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
20
+ [evt: string]: CustomEvent<any>;
21
+ }, {}, {}, string>;
22
+ type SymbolLegend = InstanceType<typeof SymbolLegend>;
8
23
  export default SymbolLegend;
@@ -25,7 +25,6 @@
25
25
  import { getContext } from 'svelte';
26
26
  import { resolveChannel, resolveProp, resolveScaledStyles } from '../helpers/resolve.js';
27
27
  import type {
28
- PlotContext,
29
28
  BaseMarkProps,
30
29
  ChannelAccessor,
31
30
  DataRow,
@@ -37,9 +36,9 @@
37
36
  import { isValid } from '../helpers/index.js';
38
37
  import { testFilter, parseInset } from '../helpers/index.js';
39
38
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
39
+ import { usePlot } from '../hooks/usePlot.svelte.js';
40
40
 
41
- const { getPlotState } = getContext<PlotContext>('svelteplot');
42
- let plot = $derived(getPlotState());
41
+ const plot = usePlot();
43
42
 
44
43
  let markProps: TickXMarkProps = $props();
45
44
  const DEFAULTS = {
@@ -24,7 +24,6 @@
24
24
  import { getContext } from 'svelte';
25
25
  import { resolveChannel, resolveProp, resolveScaledStyles } from '../helpers/resolve.js';
26
26
  import type {
27
- PlotContext,
28
27
  BaseMarkProps,
29
28
  ChannelAccessor,
30
29
  DataRow,
@@ -36,9 +35,9 @@
36
35
  import { isValid } from '../helpers/index.js';
37
36
  import { testFilter, parseInset } from '../helpers/index.js';
38
37
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
38
+ import { usePlot } from '../hooks/usePlot.svelte.js';
39
39
 
40
- const { getPlotState } = getContext<PlotContext>('svelteplot');
41
- let plot = $derived(getPlotState());
40
+ const plot = usePlot();
42
41
 
43
42
  let markProps: TickYMarkProps = $props();
44
43
  const DEFAULTS = {
@@ -25,12 +25,10 @@
25
25
  BaseMarkProps,
26
26
  ConstantAccessor,
27
27
  RawValue,
28
- PlotContext,
29
28
  ScaledDataRecord,
30
29
  CurveName
31
30
  } from '../types';
32
31
  import Mark from '../Mark.svelte';
33
- import { getContext } from 'svelte';
34
32
  import { path as d3Path } from 'd3-path';
35
33
  import { resolveProp, resolveStyles } from '../helpers/resolve.js';
36
34
  import { getPlotDefaults } from '../hooks/plotDefaults';
@@ -39,6 +37,7 @@
39
37
  import TrailCanvas from './helpers/TrailCanvas.svelte';
40
38
  import { addEventHandlers } from './helpers/events';
41
39
  import type { CurveFactory } from 'd3-shape';
40
+ import { usePlot } from '../hooks/usePlot.svelte.js';
42
41
 
43
42
  let markProps: TrailMarkProps = $props();
44
43
 
@@ -68,8 +67,7 @@
68
67
 
69
68
  const args = $derived(sort({ data, ...options })) as TrailMarkProps;
70
69
 
71
- const { getPlotState } = getContext<PlotContext>('svelteplot');
72
- const plot = $derived(getPlotState());
70
+ const plot = usePlot();
73
71
 
74
72
  /**
75
73
  * Groups the data by the specified key
@@ -151,7 +149,7 @@
151
149
  {style}
152
150
  class={styleClass}
153
151
  {@attach addEventHandlers({
154
- getPlotState,
152
+ plot,
155
153
  options: mark.options,
156
154
  datum: trailData[0].datum
157
155
  })} />
@@ -29,7 +29,6 @@
29
29
  canvas?: boolean;
30
30
  }
31
31
  import type {
32
- PlotContext,
33
32
  DataRecord,
34
33
  BaseMarkProps,
35
34
  ChannelAccessor,
@@ -47,6 +46,7 @@
47
46
  import { addEventHandlers } from './helpers/events.js';
48
47
  import { indexData } from '../transforms/recordize.js';
49
48
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
49
+ import { usePlot } from '../hooks/usePlot.svelte.js';
50
50
 
51
51
  const defaultRadius = 3.5;
52
52
 
@@ -72,8 +72,7 @@
72
72
  ...markProps
73
73
  });
74
74
 
75
- const { getPlotState } = getContext<PlotContext>('svelteplot');
76
- const plot = $derived(getPlotState());
75
+ const plot = usePlot();
77
76
 
78
77
  const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
79
78
  const testFacet = $derived(getTestFacet());
@@ -203,7 +202,7 @@
203
202
  : `translate(0, ${d.length / 2})`}"
204
203
  {style}
205
204
  {@attach addEventHandlers({
206
- getPlotState,
205
+ plot,
207
206
  options: args,
208
207
  datum: d?.datum
209
208
  })}
@@ -15,9 +15,9 @@
15
15
  import { intervalX, recordizeX, sort, stackX } from '../transforms';
16
16
  import type { StackOptions } from '../transforms/stack';
17
17
  import Mark from '../Mark.svelte';
18
- import { getContext } from 'svelte';
19
18
  import { resolveProp, resolveStyles } from '../helpers/resolve';
20
19
  import { roundedRect } from '../helpers/roundedRect';
20
+ import { usePlot } from '../hooks/usePlot.svelte.js';
21
21
 
22
22
  interface WaffleXMarkProps
23
23
  extends BaseMarkProps<Datum>, LinkableMarkProps<Datum>, WaffleOptions<Datum> {
@@ -58,8 +58,7 @@
58
58
  ...options
59
59
  }: WaffleXMarkProps = $derived({ ...DEFAULTS, ...markProps });
60
60
 
61
- const { getPlotState } = getContext<PlotContext>('svelteplot');
62
- const plot = $derived(getPlotState());
61
+ const plot = usePlot();
63
62
 
64
63
  const args = $derived(
65
64
  stackX(
@@ -8,17 +8,16 @@
8
8
  ChannelAccessor,
9
9
  BaseMarkProps,
10
10
  LinkableMarkProps,
11
- PlotContext,
12
11
  BorderRadius
13
12
  } from '../types';
14
13
  import { wafflePolygon, type WaffleOptions } from './helpers/waffle';
15
14
  import { getPlotDefaults } from '../hooks/plotDefaults';
16
- import { getContext } from 'svelte';
17
15
  import { intervalY, recordizeY, sort, stackY } from '../transforms';
18
16
  import Mark from '../Mark.svelte';
19
17
  import { resolveProp, resolveStyles } from '../helpers/resolve';
20
18
  import { roundedRect } from '../helpers/roundedRect';
21
19
  import GroupMultiple from './helpers/GroupMultiple.svelte';
20
+ import { usePlot } from '../hooks/usePlot.svelte.js';
22
21
 
23
22
  interface WaffleYMarkProps
24
23
  extends BaseMarkProps<Datum>, LinkableMarkProps<Datum>, WaffleOptions<Datum> {
@@ -56,8 +55,7 @@
56
55
  ...options
57
56
  }: WaffleYMarkProps = $derived({ ...DEFAULTS, ...markProps });
58
57
 
59
- const { getPlotState } = getContext<PlotContext>('svelteplot');
60
- const plot = $derived(getPlotState());
58
+ const plot = usePlot();
61
59
 
62
60
  const args = $derived(
63
61
  stackY(
@@ -2,17 +2,16 @@
2
2
  import type {
3
3
  Mark,
4
4
  BaseMarkProps,
5
- PlotContext,
6
5
  ScaledDataRecord,
7
6
  UsedScales
8
7
  } from '../../types/index.js';
9
8
  import { resolveProp, resolveScaledStyleProps } from '../../helpers/resolve.js';
10
- import { getContext } from 'svelte';
11
9
  import { type Area } from 'd3-shape';
12
10
  import CanvasLayer from './CanvasLayer.svelte';
13
11
  import type { Attachment } from 'svelte/attachments';
14
12
  import { devicePixelRatio } from 'svelte/reactivity/window';
15
13
  import { resolveColor } from './canvas.js';
14
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
16
15
 
17
16
  let {
18
17
  mark,
@@ -26,8 +25,7 @@
26
25
  areaPath: Area<ScaledDataRecord>;
27
26
  } = $props();
28
27
 
29
- const { getPlotState } = getContext<PlotContext>('svelteplot');
30
- const plot = $derived(getPlotState());
28
+ const plot = usePlot();
31
29
 
32
30
  function maybeOpacity(value: unknown) {
33
31
  return value == null ? 1 : +value;
@@ -1,9 +1,8 @@
1
1
  <script lang="ts">
2
- import { getContext } from 'svelte';
3
- import type { PlotContext } from '../../types/plot';
4
2
  import { devicePixelRatio } from 'svelte/reactivity/window';
5
3
  import { MediaQuery } from 'svelte/reactivity';
6
4
  import type { Attachment } from 'svelte/attachments';
5
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
7
6
 
8
7
  const darkMode = new MediaQuery('prefers-color-scheme: dark');
9
8
  let colorScheme = $state();
@@ -26,8 +25,7 @@
26
25
 
27
26
  let restProps: {} = $props();
28
27
 
29
- const { getPlotState } = getContext<PlotContext>('svelteplot');
30
- const plot = $derived(getPlotState());
28
+ const plot = usePlot();
31
29
  </script>
32
30
 
33
31
  <!--
@@ -3,20 +3,18 @@
3
3
  PlotState,
4
4
  Mark,
5
5
  BaseMarkProps,
6
- ScaledDataRecord,
7
- PlotContext
6
+ ScaledDataRecord
8
7
  } from '../../types/index.js';
9
8
  import { resolveProp } from '../../helpers/resolve.js';
10
9
  import { maybeSymbol } from '../../helpers/symbols.js';
11
10
  import { symbol as d3Symbol } from 'd3-shape';
12
11
  import type { Attachment } from 'svelte/attachments';
13
12
  import CanvasLayer from './CanvasLayer.svelte';
14
- import { getContext } from 'svelte';
15
13
  import { devicePixelRatio } from 'svelte/reactivity/window';
16
14
  import { resolveColor } from './canvas.js';
15
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
17
16
 
18
- const { getPlotState } = getContext<PlotContext>('svelteplot');
19
- const plot = $derived(getPlotState());
17
+ const plot = usePlot();
20
18
 
21
19
  let {
22
20
  mark,
@@ -2,18 +2,17 @@
2
2
  import type {
3
3
  Mark,
4
4
  BaseMarkProps,
5
- PlotContext,
6
5
  ScaledDataRecord,
7
6
  UsedScales
8
7
  } from '../../types/index.js';
9
8
  import { CSS_VAR } from '../../constants.js';
10
9
  import { resolveProp, resolveScaledStyleProps } from '../../helpers/resolve.js';
11
- import { getContext } from 'svelte';
12
10
  import { type GeoPath } from 'd3-geo';
13
11
  import CanvasLayer from './CanvasLayer.svelte';
14
12
  import type { Attachment } from 'svelte/attachments';
15
13
  import { devicePixelRatio } from 'svelte/reactivity/window';
16
14
  import { GEOJSON_PREFER_STROKE } from '../../helpers/index.js';
15
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
17
16
 
18
17
  let {
19
18
  mark,
@@ -27,8 +26,7 @@
27
26
  usedScales: UsedScales;
28
27
  } = $props();
29
28
 
30
- const { getPlotState } = getContext<PlotContext>('svelteplot');
31
- const plot = $derived(getPlotState());
29
+ const plot = usePlot();
32
30
 
33
31
  function maybeOpacity(value) {
34
32
  return value == null ? 1 : +value;
@@ -2,17 +2,16 @@
2
2
  import type {
3
3
  Mark,
4
4
  BaseMarkProps,
5
- PlotContext,
6
5
  ScaledDataRecord,
7
6
  UsedScales
8
7
  } from '../../types/index.js';
9
8
  import { resolveProp, resolveScaledStyleProps } from '../../helpers/resolve.js';
10
- import { getContext } from 'svelte';
11
9
  import { type Line } from 'd3-shape';
12
10
  import CanvasLayer from './CanvasLayer.svelte';
13
11
  import type { Attachment } from 'svelte/attachments';
14
12
  import { devicePixelRatio } from 'svelte/reactivity/window';
15
13
  import { resolveColor } from './canvas.js';
14
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
16
15
 
17
16
  let {
18
17
  mark,
@@ -27,8 +26,7 @@
27
26
  groupByKey?: unknown;
28
27
  } = $props();
29
28
 
30
- const { getPlotState } = getContext<PlotContext>('svelteplot');
31
- const plot = $derived(getPlotState());
29
+ const plot = usePlot();
32
30
 
33
31
  function maybeOpacity(value: unknown) {
34
32
  return value == null ? 1 : +value;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
- import { getContext } from 'svelte';
3
- import type { PlotContext, RawValue } from '../../index.js';
2
+ import type { RawValue } from '../../index.js';
3
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
4
4
 
5
5
  let {
6
6
  id,
@@ -10,8 +10,7 @@
10
10
  stops: { x: RawValue; color: string }[];
11
11
  } = $props();
12
12
 
13
- const { getPlotState } = getContext<PlotContext>('svelteplot');
14
- const plot = $derived(getPlotState());
13
+ const plot = usePlot();
15
14
 
16
15
  const projectedStops = $derived(
17
16
  stops
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
- import { getContext } from 'svelte';
3
- import type { PlotContext, RawValue } from '../../index.js';
2
+ import type { RawValue } from '../../index.js';
3
+ import { usePlot } from '../../hooks/usePlot.svelte.js';
4
4
 
5
5
  let {
6
6
  id,
@@ -10,8 +10,7 @@
10
10
  stops: { y: RawValue; color: string }[];
11
11
  } = $props();
12
12
 
13
- const { getPlotState } = getContext<PlotContext>('svelteplot');
14
- const plot = $derived(getPlotState());
13
+ const plot = usePlot();
15
14
 
16
15
  const projectedStops = $derived(
17
16
  stops