svelteplot 0.1.3-next.9 → 0.2.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 (51) hide show
  1. package/README.md +4 -2
  2. package/dist/Mark.svelte +18 -2
  3. package/dist/Plot.svelte +45 -29
  4. package/dist/helpers/index.d.ts +2 -1
  5. package/dist/helpers/index.js +1 -0
  6. package/dist/helpers/resolve.js +7 -6
  7. package/dist/helpers/scales.d.ts +2 -2
  8. package/dist/helpers/scales.js +8 -5
  9. package/dist/helpers/typeChecks.js +14 -10
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +3 -0
  12. package/dist/marks/BarX.svelte +15 -5
  13. package/dist/marks/BarY.svelte +20 -12
  14. package/dist/marks/BarY.svelte.d.ts +22 -1
  15. package/dist/marks/Brush.svelte +364 -0
  16. package/dist/marks/Brush.svelte.d.ts +32 -0
  17. package/dist/marks/BrushX.svelte +7 -0
  18. package/dist/marks/BrushX.svelte.d.ts +4 -0
  19. package/dist/marks/BrushY.svelte +7 -0
  20. package/dist/marks/BrushY.svelte.d.ts +4 -0
  21. package/dist/marks/Cell.svelte +0 -7
  22. package/dist/marks/ColorLegend.svelte +6 -10
  23. package/dist/marks/Dot.svelte +11 -20
  24. package/dist/marks/Dot.svelte.d.ts +8 -8
  25. package/dist/marks/Frame.svelte +10 -5
  26. package/dist/marks/Frame.svelte.d.ts +6 -1
  27. package/dist/marks/Geo.svelte +50 -41
  28. package/dist/marks/Geo.svelte.d.ts +3 -1
  29. package/dist/marks/GridX.svelte +17 -8
  30. package/dist/marks/GridY.svelte +17 -8
  31. package/dist/marks/Pointer.svelte +4 -3
  32. package/dist/marks/Pointer.svelte.d.ts +2 -2
  33. package/dist/marks/Rect.svelte +12 -19
  34. package/dist/marks/Sphere.svelte.d.ts +14 -4
  35. package/dist/marks/Text.svelte +2 -2
  36. package/dist/marks/Text.svelte.d.ts +2 -2
  37. package/dist/marks/helpers/CanvasLayer.svelte +10 -16
  38. package/dist/marks/helpers/CanvasLayer.svelte.d.ts +2 -6
  39. package/dist/marks/helpers/DotCanvas.svelte +82 -159
  40. package/dist/marks/helpers/DotCanvas.svelte.d.ts +2 -4
  41. package/dist/marks/helpers/GeoCanvas.svelte +95 -145
  42. package/dist/marks/helpers/GeoCanvas.svelte.d.ts +3 -5
  43. package/dist/marks/helpers/events.d.ts +13 -0
  44. package/dist/marks/helpers/events.js +32 -3
  45. package/dist/transforms/bin.d.ts +7 -7
  46. package/dist/transforms/recordize.d.ts +2 -0
  47. package/dist/transforms/recordize.js +20 -10
  48. package/dist/transforms/stack.js +10 -7
  49. package/dist/transforms/window.d.ts +2 -0
  50. package/dist/types.d.ts +34 -13
  51. package/package.json +23 -20
@@ -1,15 +1,22 @@
1
1
  <script lang="ts">
2
2
  import { getContext } from 'svelte';
3
- import type { DataRecord, PlotContext, BaseMarkProps } from '../types.js';
3
+ import type {
4
+ DataRecord,
5
+ PlotContext,
6
+ BaseMarkProps,
7
+ FacetContext,
8
+ ConstantAccessor,
9
+ UsedScales
10
+ } from '../types.js';
4
11
  import Mark from '../Mark.svelte';
5
12
  import { geoPath } from 'd3-geo';
6
- import { resolveChannel, resolveProp, resolveScaledStyles } from '../helpers/resolve.js';
7
- import { getUsedScales } from '../helpers/scales.js';
13
+ import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
8
14
  import callWithProps from '../helpers/callWithProps.js';
9
15
  import { sort } from '../index.js';
10
- import { testFilter } from '../helpers/index.js';
11
16
  import { addEventHandlers } from './helpers/events.js';
12
17
  import GeoCanvas from './helpers/GeoCanvas.svelte';
18
+ import { recordize } from '../transforms/recordize.js';
19
+ import { GEOJSON_PREFER_STROKE } from '../helpers/index.js';
13
20
 
14
21
  const { getPlotState } = getContext<PlotContext>('svelteplot');
15
22
  const plot = $derived(getPlotState());
@@ -19,6 +26,8 @@
19
26
  geoType?: 'sphere' | 'graticule';
20
27
  dragRotate: boolean;
21
28
  canvas: boolean;
29
+ href: ConstantAccessor<string>;
30
+ target: ConstantAccessor<string>;
22
31
  } & BaseMarkProps;
23
32
 
24
33
  let {
@@ -39,60 +48,60 @@
39
48
  );
40
49
 
41
50
  const args = $derived(
42
- sort({
43
- data,
44
- ...(options.r ? { sort: { channel: '-r' } } : {}),
45
- ...options
46
- })
51
+ sort(
52
+ recordize({
53
+ data,
54
+ ...(options.r ? { sort: { channel: '-r' } } : {}),
55
+ ...options
56
+ })
57
+ )
47
58
  );
48
- const preferStroke = new Set(['MultiLineString', 'LineString']);
49
-
50
- const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
51
- const testFacet = $derived(getTestFacet());
52
59
  </script>
53
60
 
54
61
  <Mark
55
62
  type="geo"
56
63
  channels={['fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity', 'r']}
57
64
  {...args}>
58
- {#snippet children({ mark, usedScales })}
65
+ {#snippet children({ mark, scaledData, usedScales })}
66
+ {#snippet el(d)}
67
+ {@const title = resolveProp(args.title, d.datum, '')}
68
+ {@const geometry = resolveProp(args.geometry, d.datum, d.datum)}
69
+ {@const [style, styleClass] = resolveStyles(
70
+ plot,
71
+ d,
72
+ args,
73
+ GEOJSON_PREFER_STROKE.has(geometry.type) ? 'stroke' : 'fill',
74
+ usedScales
75
+ )}
76
+ <path
77
+ d={path(geometry)}
78
+ {style}
79
+ class={[styleClass]}
80
+ use:addEventHandlers={{
81
+ getPlotState,
82
+ options: args,
83
+ datum: d.datum
84
+ }}>
85
+ {#if title}<title>{title}</title>{/if}
86
+ </path>
87
+ {/snippet}
59
88
  <g
60
89
  aria-label="geo"
61
90
  class={['geo', geoType && `geo-${geoType}`, className]}
62
91
  style="fill:currentColor">
63
92
  {#if canvas}
64
- <GeoCanvas data={args.data} {mark} {plot} {testFacet} {usedScales} {path} />
93
+ <GeoCanvas data={scaledData} {path} {mark} {usedScales} />
65
94
  {:else}
66
- {#each args.data as datum}
67
- {#if testFilter(datum, mark.options) && testFacet(datum, mark.options)}
68
- {#snippet el(datum)}
69
- {@const title = resolveProp(args.title, datum, '')}
70
- {@const geometry = resolveProp(args.geometry, datum, datum)}
71
- <path
72
- d={path(geometry)}
73
- style={resolveScaledStyles(
74
- datum,
75
- args,
76
- usedScales,
77
- plot,
78
- preferStroke.has(geometry.type) ? 'stroke' : 'fill'
79
- )}
80
- use:addEventHandlers={{
81
- getPlotState,
82
- options: args,
83
- datum
84
- }}>
85
- {#if title}<title>{title}</title>{/if}
86
- </path>
87
- {/snippet}
95
+ {#each scaledData as d}
96
+ {#if d.valid}
88
97
  {#if options.href}
89
98
  <a
90
- href={resolveProp(args.href, datum, '')}
91
- target={resolveProp(args.target, datum, '_self')}>
92
- {@render el(datum)}
99
+ href={resolveProp(args.href, d.datum, '')}
100
+ target={resolveProp(args.target, d.datum, '_self')}>
101
+ {@render el(d)}
93
102
  </a>
94
103
  {:else}
95
- {@render el(datum)}
104
+ {@render el(d)}
96
105
  {/if}
97
106
  {/if}
98
107
  {/each}
@@ -1,9 +1,11 @@
1
- import type { DataRecord, BaseMarkProps } from '../types.js';
1
+ import type { DataRecord, BaseMarkProps, ConstantAccessor } from '../types.js';
2
2
  type GeoMarkProps = {
3
3
  data: DataRecord[];
4
4
  geoType?: 'sphere' | 'graticule';
5
5
  dragRotate: boolean;
6
6
  canvas: boolean;
7
+ href: ConstantAccessor<string>;
8
+ target: ConstantAccessor<string>;
7
9
  } & BaseMarkProps;
8
10
  declare const Geo: import("svelte").Component<GeoMarkProps, {}, "">;
9
11
  type Geo = ReturnType<typeof Geo>;
@@ -2,10 +2,10 @@
2
2
  import { getContext } from 'svelte';
3
3
  import Mark from '../Mark.svelte';
4
4
  import type { PlotContext, BaseMarkProps, RawValue } from '../types.js';
5
- import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
5
+ import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
6
6
  import { autoTicks } from '../helpers/autoTicks.js';
7
- import { getUsedScales } from '../helpers/scales.js';
8
7
  import { testFilter } from '../helpers/index.js';
8
+ import { RAW_VALUE } from '../transforms/recordize.js';
9
9
 
10
10
  type GrixXMarkProps = BaseMarkProps & {
11
11
  data?: RawValue[];
@@ -15,13 +15,13 @@
15
15
  let { data = [], automatic = false, ...options }: GrixXMarkProps = $props();
16
16
 
17
17
  const { getPlotState } = getContext<PlotContext>('svelteplot');
18
- let plot = $derived(getPlotState());
18
+ const plot = $derived(getPlotState());
19
19
 
20
- let autoTickCount = $derived(
20
+ const autoTickCount = $derived(
21
21
  Math.max(3, Math.round(plot.facetWidth / plot.options.x.tickSpacing))
22
22
  );
23
23
 
24
- let ticks: RawValue[] = $derived(
24
+ const ticks: RawValue[] = $derived(
25
25
  data.length > 0
26
26
  ? // use custom tick values if user passed any as prop
27
27
  data
@@ -39,9 +39,9 @@
39
39
 
40
40
  <Mark
41
41
  type="gridX"
42
- data={data.length ? data.map((tick) => ({ __x: tick })) : []}
42
+ data={data.length ? data.map((tick) => ({ [RAW_VALUE]: tick })) : []}
43
43
  channels={['y1', 'y2', 'x', 'stroke', 'strokeOpacity']}
44
- {...{ ...options, x: '__x' }}
44
+ {...{ ...options, x: RAW_VALUE }}
45
45
  {automatic}>
46
46
  {#snippet children({ usedScales })}
47
47
  <g class="grid-x">
@@ -54,9 +54,18 @@
54
54
  {@const y2_ = resolveChannel('y2', tick, options)}
55
55
  {@const y1 = options.y1 != null ? plot.scales.y.fn(y1_) : 0}
56
56
  {@const y2 = options.y2 != null ? plot.scales.y.fn(y2_) : plot.facetHeight}
57
+ {@const [style, styleClass] = resolveStyles(
58
+ plot,
59
+ { datum: { [RAW_VALUE]: tick } },
60
+ options,
61
+ 'stroke',
62
+ usedScales,
63
+ true
64
+ )}
57
65
  <line
66
+ class={styleClass}
58
67
  transform="translate({x},{plot.options.marginTop})"
59
- style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
68
+ {style}
60
69
  {y1}
61
70
  {y2} />
62
71
  {/if}
@@ -2,23 +2,23 @@
2
2
  import { getContext } from 'svelte';
3
3
  import Mark from '../Mark.svelte';
4
4
  import type { PlotContext, BaseMarkProps, RawValue, DataRecord } from '../types.js';
5
- import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
5
+ import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
6
6
  import { autoTicks } from '../helpers/autoTicks.js';
7
- import { getUsedScales } from '../helpers/scales.js';
8
7
  import { testFilter } from '../helpers/index.js';
8
+ import { RAW_VALUE } from '../transforms/recordize.js';
9
9
 
10
10
  type GridYMarkProps = BaseMarkProps & { data?: RawValue[]; automatic?: boolean };
11
11
 
12
12
  let { data = [], automatic = false, ...options }: GridYMarkProps = $props();
13
13
 
14
14
  const { getPlotState } = getContext<PlotContext>('svelteplot');
15
- let plot = $derived(getPlotState());
15
+ const plot = $derived(getPlotState());
16
16
 
17
- let autoTickCount = $derived(
17
+ const autoTickCount = $derived(
18
18
  Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
19
19
  );
20
20
 
21
- let ticks: RawValue[] = $derived(
21
+ const ticks: RawValue[] = $derived(
22
22
  data.length > 0
23
23
  ? // use custom tick values if user passed any as prop
24
24
  data
@@ -36,9 +36,9 @@
36
36
 
37
37
  <Mark
38
38
  type="gridY"
39
- data={data.length ? data.map((tick) => ({ ___orig___: tick })) : []}
39
+ data={data.length ? data.map((tick) => ({ [RAW_VALUE]: tick })) : []}
40
40
  channels={['x1', 'x2', 'y', 'stroke', 'strokeOpacity']}
41
- {...{ ...options, y: '___orig___' }}
41
+ {...{ ...options, y: RAW_VALUE }}
42
42
  {automatic}>
43
43
  {#snippet children({ usedScales })}
44
44
  <g class="grid-y">
@@ -51,9 +51,18 @@
51
51
  {@const x2_ = resolveChannel('x2', tick, options)}
52
52
  {@const x1 = options.x1 != null ? plot.scales.x.fn(x1_) : 0}
53
53
  {@const x2 = options.x2 != null ? plot.scales.x.fn(x2_) : plot.facetWidth}
54
+ {@const [style, styleClass] = resolveStyles(
55
+ plot,
56
+ { datum: { [RAW_VALUE]: tick } },
57
+ options,
58
+ 'stroke',
59
+ usedScales,
60
+ true
61
+ )}
54
62
  <line
63
+ {style}
64
+ class={styleClass}
55
65
  transform="translate({plot.options.marginLeft},{y})"
56
- style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
57
66
  {x1}
58
67
  {x2} />
59
68
  {/if}
@@ -10,12 +10,12 @@
10
10
  /**
11
11
  * maximum cursor distance to select data points
12
12
  */
13
- maxDistance: number;
13
+ maxDistance?: number;
14
14
  /**
15
15
  * called whenever the selection changes
16
16
  * @param data
17
17
  */
18
- onupdate: (data: DataRow[]) => void;
18
+ onupdate?: (data: DataRow[]) => void;
19
19
  };
20
20
  </script>
21
21
 
@@ -31,6 +31,7 @@
31
31
  import { quadtree } from 'd3-quadtree';
32
32
  import { projectXY } from '../helpers/scales.js';
33
33
  import isDataRecord from '../helpers/isDataRecord.js';
34
+ import { RAW_VALUE } from '../transforms/recordize.js';
34
35
 
35
36
  let {
36
37
  data = [{}],
@@ -109,7 +110,7 @@
109
110
  true
110
111
  );
111
112
  return {
112
- ...(isDataRecord(d) ? d : { ___orig___: d }),
113
+ ...(isDataRecord(d) ? d : { [RAW_VALUE]: d }),
113
114
  __pointerX: px,
114
115
  __pointerY: py
115
116
  };
@@ -10,12 +10,12 @@ export type PointerMarkProps = {
10
10
  /**
11
11
  * maximum cursor distance to select data points
12
12
  */
13
- maxDistance: number;
13
+ maxDistance?: number;
14
14
  /**
15
15
  * called whenever the selection changes
16
16
  * @param data
17
17
  */
18
- onupdate: (data: DataRow[]) => void;
18
+ onupdate?: (data: DataRow[]) => void;
19
19
  };
20
20
  import { type Snippet } from 'svelte';
21
21
  declare const Pointer: import("svelte").Component<PointerMarkProps, {}, "">;
@@ -5,15 +5,9 @@
5
5
  <script lang="ts">
6
6
  import Mark from '../Mark.svelte';
7
7
  import { getContext } from 'svelte';
8
- import { recordizeY, intervalX, intervalY } from '../index.js';
9
- import {
10
- resolveChannel,
11
- resolveProp,
12
- resolveScaledStyles,
13
- resolveStyles
14
- } from '../helpers/resolve.js';
15
- import { getUsedScales, projectX, projectY } from '../helpers/scales.js';
16
- import { coalesce, testFilter, maybeNumber } from '../helpers/index.js';
8
+ import { intervalX, intervalY } from '../index.js';
9
+ import { resolveProp, resolveStyles } from '../helpers/resolve.js';
10
+ import { coalesce, maybeNumber } from '../helpers/index.js';
17
11
  import type {
18
12
  PlotContext,
19
13
  DataRecord,
@@ -21,7 +15,6 @@
21
15
  BaseRectMarkProps,
22
16
  ChannelAccessor
23
17
  } from '../types.js';
24
- import { isValid } from '../helpers/isValid.js';
25
18
  import { addEventHandlers } from './helpers/events.js';
26
19
  import GroupMultiple from './helpers/GroupMultiple.svelte';
27
20
 
@@ -36,7 +29,7 @@
36
29
  interval?: number | string;
37
30
  } & BaseRectMarkProps;
38
31
 
39
- let { data = [{}], class: className = null, ...options }: RectMarkProps = $props();
32
+ let { data = [{}], class: className = 'rect', ...options }: RectMarkProps = $props();
40
33
 
41
34
  const { getPlotState } = getContext<PlotContext>('svelteplot');
42
35
  let plot = $derived(getPlotState());
@@ -51,8 +44,8 @@
51
44
  required={[]}
52
45
  channels={['x1', 'x2', 'y1', 'y2', 'fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity']}
53
46
  {...args}>
54
- {#snippet children({ mark, usedScales, scaledData })}
55
- <g class="rect">
47
+ {#snippet children({ usedScales, scaledData })}
48
+ <GroupMultiple class={scaledData.length > 1 ? className : null} length={scaledData.length}>
56
49
  {#each scaledData as d}
57
50
  {#if d.valid}
58
51
  {@const x1 = d.x1 == null ? plot.options.marginLeft : d.x1}
@@ -69,14 +62,14 @@
69
62
  {@const insetRight = resolveProp(args.insetRight, d.datum)}
70
63
  {@const insetTop = resolveProp(args.insetTop, d.datum)}
71
64
  {@const insetBottom = resolveProp(args.insetBottom, d.datum)}
72
- {@const insetL = maybeNumber(coalesce(insetLeft, inset, 0))}
73
- {@const insetT = maybeNumber(coalesce(insetTop, inset, 0))}
74
- {@const insetR = maybeNumber(coalesce(insetRight, inset, 0))}
75
- {@const insetB = maybeNumber(coalesce(insetBottom, inset, 0))}
65
+ {@const insetL = maybeNumber(coalesce(insetLeft, inset, 0)) ?? 0}
66
+ {@const insetT = maybeNumber(coalesce(insetTop, inset, 0)) ?? 0}
67
+ {@const insetR = maybeNumber(coalesce(insetRight, inset, 0)) ?? 0}
68
+ {@const insetB = maybeNumber(coalesce(insetBottom, inset, 0)) ?? 0}
76
69
 
77
70
  {@const [style, styleClass] = resolveStyles(plot, d, args, 'fill', usedScales)}
78
71
  <rect
79
- class={[styleClass]}
72
+ class={[scaledData.length === 1 && className, styleClass]}
80
73
  {style}
81
74
  x={minx + insetL}
82
75
  y={miny + insetT}
@@ -91,7 +84,7 @@
91
84
  }} />
92
85
  {/if}
93
86
  {/each}
94
- </g>
87
+ </GroupMultiple>
95
88
  {/snippet}
96
89
  </Mark>
97
90
 
@@ -10,16 +10,16 @@ declare const Sphere: import("svelte").Component<Partial<{
10
10
  stroke: import("../types.js").ConstantAccessor<string>;
11
11
  strokeWidth: import("../types.js").ConstantAccessor<number>;
12
12
  strokeOpacity: import("../types.js").ConstantAccessor<number>;
13
- strokeLinejoin: import("../types.js").ConstantAccessor<"bevel" | "miter" | "miter-clip" | "round">;
14
- strokeLinecap: import("../types.js").ConstantAccessor<"butt" | "square" | "round">;
13
+ strokeLinejoin: import("../types.js").ConstantAccessor<import("csstype").Property.StrokeLinejoin>;
14
+ strokeLinecap: import("../types.js").ConstantAccessor<import("csstype").Property.StrokeLinecap>;
15
15
  strokeMiterlimit: import("../types.js").ConstantAccessor<number>;
16
16
  opacity: import("../types.js").ConstantAccessor<number>;
17
17
  strokeDasharray: import("../types.js").ConstantAccessor<string>;
18
18
  strokeDashoffset: import("../types.js").ConstantAccessor<number>;
19
- mixBlendMode: import("../types.js").ConstantAccessor<"normal" | "multiply" | "screen" | "overlay" | "darken" | "lighten" | "color-dodge" | "color-burn" | "hard-light" | "soft-light" | "difference" | "exclusion" | "hue" | "saturation" | "color" | "luminosity" | "plus-darker" | "plus-lighter">;
19
+ mixBlendMode: import("../types.js").ConstantAccessor<import("csstype").Property.MixBlendMode>;
20
20
  clipPath: string;
21
21
  imageFilter: import("../types.js").ConstantAccessor<string>;
22
- shapeRendering: import("../types.js").ConstantAccessor<"crispEdges" | "geometricPrecision" | "optimizeSpeed" | "auto">;
22
+ shapeRendering: import("../types.js").ConstantAccessor<import("csstype").Property.ShapeRendering>;
23
23
  paintOrder: import("../types.js").ConstantAccessor<string>;
24
24
  onclick?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
25
25
  ondblclick?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
@@ -29,6 +29,15 @@ declare const Sphere: import("svelte").Component<Partial<{
29
29
  onmousemove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
30
30
  onmouseleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
31
31
  onmouseout?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
32
+ onmouseover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
33
+ onpointercancel?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
34
+ onpointerdown?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
35
+ onpointerup?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
36
+ onpointerenter?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
37
+ onpointerleave?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
38
+ onpointermove?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
39
+ onpointerover?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
40
+ onpointerout?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
32
41
  ondrag?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
33
42
  ondrop?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
34
43
  ondragstart?: import("svelte/elements").MouseEventHandler<SVGPathElement>;
@@ -46,6 +55,7 @@ declare const Sphere: import("svelte").Component<Partial<{
46
55
  href: import("../types.js").ConstantAccessor<string>;
47
56
  target: import("../types.js").ConstantAccessor<"_self" | "_blank" | string>;
48
57
  class: string;
58
+ cursor: import("../types.js").ConstantAccessor<import("csstype").Property.Cursor>;
49
59
  }>, {}, "">;
50
60
  type Sphere = ReturnType<typeof Sphere>;
51
61
  export default Sphere;
@@ -22,11 +22,11 @@
22
22
  dx?: ConstantAccessor<number>;
23
23
  dy?: ConstantAccessor<number>;
24
24
  text: ConstantAccessor<string>;
25
- title: ConstantAccessor<string>;
25
+ title?: ConstantAccessor<string>;
26
26
  /**
27
27
  * if you want to apply class names to individual text elements
28
28
  */
29
- textClass: ConstantAccessor<string>;
29
+ textClass?: ConstantAccessor<string>;
30
30
  /**
31
31
  * the line anchor for vertical position; top, bottom, or middle
32
32
  */
@@ -10,11 +10,11 @@ type TextMarkProps = BaseMarkProps & {
10
10
  dx?: ConstantAccessor<number>;
11
11
  dy?: ConstantAccessor<number>;
12
12
  text: ConstantAccessor<string>;
13
- title: ConstantAccessor<string>;
13
+ title?: ConstantAccessor<string>;
14
14
  /**
15
15
  * if you want to apply class names to individual text elements
16
16
  */
17
- textClass: ConstantAccessor<string>;
17
+ textClass?: ConstantAccessor<string>;
18
18
  /**
19
19
  * the line anchor for vertical position; top, bottom, or middle
20
20
  */
@@ -1,18 +1,12 @@
1
1
  <script lang="ts">
2
- let {
3
- canvas = $bindable(),
4
- devicePixelRatio = $bindable(1),
5
- plot
6
- }: {
7
- canvas: HTMLCanvasElement;
8
- devicePixelRatio: number;
9
- plot: PlotState;
10
- } = $props();
2
+ import { getContext } from 'svelte';
3
+ import type { PlotContext } from '../../types';
4
+ import { devicePixelRatio } from 'svelte/reactivity/window';
11
5
 
12
- $effect(() => {
13
- devicePixelRatio = window.devicePixelRatio || 1;
14
- const ctx = canvas.getContext('2d');
15
- });
6
+ let restProps: {} = $props();
7
+
8
+ const { getPlotState } = getContext<PlotContext>('svelteplot');
9
+ const plot = $derived(getPlotState());
16
10
  </script>
17
11
 
18
12
  <!--
@@ -24,9 +18,9 @@
24
18
  <foreignObject x="0" y="0" width={plot.width} height={plot.height}>
25
19
  <canvas
26
20
  xmlns="http://www.w3.org/1999/xhtml"
27
- bind:this={canvas}
28
- width={plot.width * devicePixelRatio}
29
- height={plot.height * devicePixelRatio}
21
+ {...restProps}
22
+ width={plot.width * (devicePixelRatio.current ?? 1)}
23
+ height={plot.height * (devicePixelRatio.current ?? 1)}
30
24
  style="width: {plot.width}px; height: {plot.height}px;"></canvas>
31
25
  </foreignObject>
32
26
 
@@ -1,13 +1,9 @@
1
- type $$ComponentProps = {
2
- canvas: HTMLCanvasElement;
3
- devicePixelRatio: number;
4
- plot: PlotState;
5
- };
1
+ type $$ComponentProps = {};
6
2
  /**
7
3
  * The CanvasLayer component is a helper component that inserts a
8
4
  * canvas element inside a foreignObject for use in a plot and takes care of
9
5
  * scaling it to the device pixel ratio.
10
6
  */
11
- declare const CanvasLayer: import("svelte").Component<$$ComponentProps, {}, "canvas" | "devicePixelRatio">;
7
+ declare const CanvasLayer: import("svelte").Component<$$ComponentProps, {}, "">;
12
8
  type CanvasLayer = ReturnType<typeof CanvasLayer>;
13
9
  export default CanvasLayer;