svelteplot 0.13.0 → 0.14.0

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 (32) hide show
  1. package/dist/helpers/group.d.ts +1 -1
  2. package/dist/helpers/group.js +3 -3
  3. package/dist/marks/ColorLegend.svelte +5 -1
  4. package/dist/marks/Contour.svelte +21 -30
  5. package/dist/marks/Contour.svelte.d.ts +2 -0
  6. package/dist/marks/DelaunayLink.svelte +127 -0
  7. package/dist/marks/DelaunayLink.svelte.d.ts +175 -0
  8. package/dist/marks/DelaunayMesh.svelte +102 -0
  9. package/dist/marks/DelaunayMesh.svelte.d.ts +172 -0
  10. package/dist/marks/Density.svelte +461 -0
  11. package/dist/marks/Density.svelte.d.ts +87 -0
  12. package/dist/marks/Hull.svelte +103 -0
  13. package/dist/marks/Hull.svelte.d.ts +175 -0
  14. package/dist/marks/Voronoi.svelte +118 -0
  15. package/dist/marks/Voronoi.svelte.d.ts +172 -0
  16. package/dist/marks/VoronoiMesh.svelte +109 -0
  17. package/dist/marks/VoronoiMesh.svelte.d.ts +172 -0
  18. package/dist/marks/helpers/DensityCanvas.svelte +118 -0
  19. package/dist/marks/helpers/DensityCanvas.svelte.d.ts +18 -0
  20. package/dist/marks/helpers/GeoPathCanvas.svelte +125 -0
  21. package/dist/marks/helpers/GeoPathCanvas.svelte.d.ts +24 -0
  22. package/dist/marks/helpers/GeoPathGroup.svelte +103 -0
  23. package/dist/marks/helpers/GeoPathGroup.svelte.d.ts +37 -0
  24. package/dist/marks/helpers/PathGroup.svelte +100 -0
  25. package/dist/marks/helpers/PathGroup.svelte.d.ts +16 -0
  26. package/dist/marks/helpers/PathItems.svelte +112 -0
  27. package/dist/marks/helpers/PathItems.svelte.d.ts +16 -0
  28. package/dist/marks/index.d.ts +7 -1
  29. package/dist/marks/index.js +7 -1
  30. package/dist/types/mark.d.ts +1 -1
  31. package/dist/types/plot.d.ts +25 -1
  32. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import type { ScaledDataRecord, PlotState } from '../../types/index.js';
2
+ import type { GeoPath } from 'd3-geo';
3
+ type $$ComponentProps = {
4
+ scaledData: ScaledDataRecord[];
5
+ /** d3 geoPath renderer (must NOT have a canvas context set). */
6
+ path: GeoPath;
7
+ /** Symbol key used to retrieve the GeoJSON geometry from each datum. */
8
+ geomKey: symbol;
9
+ /**
10
+ * The color keyword that, when used as fill/stroke, maps the threshold
11
+ * value through the plot's color scale. E.g. "value" for Contour,
12
+ * "density" for Density.
13
+ */
14
+ colorKeyword: string;
15
+ fill: string;
16
+ stroke: string;
17
+ strokeWidth?: number;
18
+ strokeOpacity?: number;
19
+ fillOpacity?: number;
20
+ opacity?: number;
21
+ strokeMiterlimit?: number;
22
+ clipPath?: string;
23
+ className?: string;
24
+ ariaLabel?: string;
25
+ /** Render using a canvas element instead of SVG paths. */
26
+ canvas?: boolean;
27
+ plot: PlotState;
28
+ };
29
+ /**
30
+ * Renders GeoJSON geometries as SVG <path> elements (or via canvas when
31
+ * canvas=true). Used by the Contour and Density marks. Each path's style is
32
+ * resolved per-threshold using a color keyword (e.g. "value" or "density") that
33
+ * maps the RAW_VALUE attached to each fake datum through the plot's color scale.
34
+ */
35
+ declare const GeoPathGroup: import("svelte").Component<$$ComponentProps, {}, "">;
36
+ type GeoPathGroup = ReturnType<typeof GeoPathGroup>;
37
+ export default GeoPathGroup;
@@ -0,0 +1,100 @@
1
+ <script lang="ts">
2
+ import type {
3
+ PlotState,
4
+ ScaledDataRecord,
5
+ ScaledChannelName,
6
+ ChannelAccessor,
7
+ MarkStyleProps
8
+ } from '../../types/index.js';
9
+ import { resolveStyles, resolveProp } from '../../helpers/resolve.js';
10
+
11
+ type StyleArgs = Partial<Record<ScaledChannelName | MarkStyleProps, ChannelAccessor>>;
12
+ import { resolveColor } from './canvas.js';
13
+ import type { Attachment } from 'svelte/attachments';
14
+ import CanvasLayer from './CanvasLayer.svelte';
15
+ import { devicePixelRatio } from 'svelte/reactivity/window';
16
+
17
+ let {
18
+ paths,
19
+ args,
20
+ className,
21
+ usedScales,
22
+ plot,
23
+ defaultStrokeWidth = 1,
24
+ canvas = false
25
+ }: {
26
+ paths: { path: string; datum: ScaledDataRecord }[];
27
+ args: Record<string | symbol, any>;
28
+ className: string;
29
+ usedScales: Record<ScaledChannelName, boolean>;
30
+ plot: PlotState;
31
+ defaultStrokeWidth?: number;
32
+ canvas?: boolean;
33
+ } = $props();
34
+
35
+ const render: Attachment = (el: Element) => {
36
+ const canvasEl = el as HTMLCanvasElement;
37
+ const context = canvasEl.getContext('2d');
38
+
39
+ $effect(() => {
40
+ if (!context) return;
41
+
42
+ context.resetTransform();
43
+ context.scale(devicePixelRatio.current ?? 1, devicePixelRatio.current ?? 1);
44
+
45
+ for (const { path: pathStr, datum } of paths) {
46
+ const fillColor = resolveColor(datum.fill ?? 'none', canvasEl) as string;
47
+ const strokeColor = resolveColor(datum.stroke ?? 'none', canvasEl) as string;
48
+ const opacity = datum.opacity ?? 1;
49
+ const fillOpacity = datum.fillOpacity ?? 1;
50
+ const strokeOpacity = datum.strokeOpacity ?? 1;
51
+ const strokeWidth = resolveProp(
52
+ (args as StyleArgs).strokeWidth as ChannelAccessor,
53
+ datum.datum,
54
+ defaultStrokeWidth
55
+ ) as number;
56
+
57
+ const p = new Path2D(pathStr);
58
+
59
+ if (fillColor && fillColor !== 'none') {
60
+ context.fillStyle = fillColor;
61
+ context.globalAlpha = opacity * fillOpacity;
62
+ context.fill(p);
63
+ }
64
+
65
+ if (strokeColor && strokeColor !== 'none') {
66
+ context.strokeStyle = strokeColor;
67
+ context.lineWidth = strokeWidth ?? defaultStrokeWidth;
68
+ context.globalAlpha = opacity * strokeOpacity;
69
+ context.stroke(p);
70
+ }
71
+ }
72
+
73
+ return () => {
74
+ context.clearRect(
75
+ 0,
76
+ 0,
77
+ plot.width * (devicePixelRatio.current ?? 1),
78
+ plot.height * (devicePixelRatio.current ?? 1)
79
+ );
80
+ };
81
+ });
82
+ };
83
+ </script>
84
+
85
+ {#if canvas}
86
+ <CanvasLayer {@attach render} />
87
+ {:else}
88
+ <g class={className}>
89
+ {#each paths as { path, datum }, i (i)}
90
+ {@const [style, styleClass] = resolveStyles(
91
+ plot,
92
+ datum,
93
+ { strokeWidth: defaultStrokeWidth, ...(args as StyleArgs) },
94
+ 'stroke',
95
+ usedScales
96
+ )}
97
+ <path d={path} class={styleClass} {style} />
98
+ {/each}
99
+ </g>
100
+ {/if}
@@ -0,0 +1,16 @@
1
+ import type { PlotState, ScaledDataRecord, ScaledChannelName } from '../../types/index.js';
2
+ type $$ComponentProps = {
3
+ paths: {
4
+ path: string;
5
+ datum: ScaledDataRecord;
6
+ }[];
7
+ args: Record<string | symbol, any>;
8
+ className: string;
9
+ usedScales: Record<ScaledChannelName, boolean>;
10
+ plot: PlotState;
11
+ defaultStrokeWidth?: number;
12
+ canvas?: boolean;
13
+ };
14
+ declare const PathGroup: import("svelte").Component<$$ComponentProps, {}, "">;
15
+ type PathGroup = ReturnType<typeof PathGroup>;
16
+ export default PathGroup;
@@ -0,0 +1,112 @@
1
+ <script lang="ts">
2
+ import type {
3
+ PlotState,
4
+ ScaledDataRecord,
5
+ ScaledChannelName,
6
+ ChannelAccessor,
7
+ MarkStyleProps
8
+ } from '../../types/index.js';
9
+ import { resolveStyles, resolveProp } from '../../helpers/resolve.js';
10
+
11
+ type StyleArgs = Partial<Record<ScaledChannelName | MarkStyleProps, ChannelAccessor>>;
12
+ import { resolveColor } from './canvas.js';
13
+ import type { Attachment } from 'svelte/attachments';
14
+ import CanvasLayer from './CanvasLayer.svelte';
15
+ import { devicePixelRatio } from 'svelte/reactivity/window';
16
+ import SvelteAnchor from './Anchor.svelte';
17
+ import { addEventHandlers } from './events.js';
18
+
19
+ let {
20
+ paths,
21
+ args,
22
+ options,
23
+ className,
24
+ usedScales,
25
+ plot,
26
+ canvas = false
27
+ }: {
28
+ paths: { path: string; datum: ScaledDataRecord }[];
29
+ args: Record<string | symbol, any>;
30
+ options: Record<string, any>;
31
+ className: string;
32
+ usedScales: Record<ScaledChannelName, boolean>;
33
+ plot: PlotState;
34
+ canvas?: boolean;
35
+ } = $props();
36
+
37
+ const render: Attachment = (el: Element) => {
38
+ const canvasEl = el as HTMLCanvasElement;
39
+ const context = canvasEl.getContext('2d');
40
+
41
+ $effect(() => {
42
+ if (!context) return;
43
+
44
+ context.resetTransform();
45
+ context.scale(devicePixelRatio.current ?? 1, devicePixelRatio.current ?? 1);
46
+
47
+ for (const { path: pathStr, datum } of paths) {
48
+ const fillColor = resolveColor(datum.fill ?? 'none', canvasEl) as string;
49
+ const strokeColor = resolveColor(datum.stroke ?? 'none', canvasEl) as string;
50
+ const opacity = datum.opacity ?? 1;
51
+ const fillOpacity = datum.fillOpacity ?? 1;
52
+ const strokeOpacity = datum.strokeOpacity ?? 1;
53
+ const strokeWidth = resolveProp(
54
+ (args as StyleArgs).strokeWidth as ChannelAccessor,
55
+ datum.datum,
56
+ 1
57
+ ) as number;
58
+
59
+ const p = new Path2D(pathStr);
60
+
61
+ if (fillColor && fillColor !== 'none') {
62
+ context.fillStyle = fillColor;
63
+ context.globalAlpha = opacity * fillOpacity;
64
+ context.fill(p);
65
+ }
66
+
67
+ if (strokeColor && strokeColor !== 'none') {
68
+ context.strokeStyle = strokeColor;
69
+ context.lineWidth = strokeWidth ?? 1;
70
+ context.globalAlpha = opacity * strokeOpacity;
71
+ context.stroke(p);
72
+ }
73
+ }
74
+
75
+ return () => {
76
+ context.clearRect(
77
+ 0,
78
+ 0,
79
+ plot.width * (devicePixelRatio.current ?? 1),
80
+ plot.height * (devicePixelRatio.current ?? 1)
81
+ );
82
+ };
83
+ });
84
+ };
85
+ </script>
86
+
87
+ {#if canvas}
88
+ <CanvasLayer {@attach render} />
89
+ {:else}
90
+ <g class={className}>
91
+ {#each paths as { path, datum }, i (i)}
92
+ {@const [style, styleClass] = resolveStyles(
93
+ plot,
94
+ datum,
95
+ { strokeWidth: 1, ...(args as StyleArgs) },
96
+ 'stroke',
97
+ usedScales
98
+ )}
99
+ <SvelteAnchor {options} datum={datum.datum}>
100
+ <path
101
+ d={path}
102
+ class={styleClass}
103
+ {style}
104
+ {@attach addEventHandlers({
105
+ plot,
106
+ options: args as any,
107
+ datum: datum.datum
108
+ })} />
109
+ </SvelteAnchor>
110
+ {/each}
111
+ </g>
112
+ {/if}
@@ -0,0 +1,16 @@
1
+ import type { PlotState, ScaledDataRecord, ScaledChannelName } from '../../types/index.js';
2
+ type $$ComponentProps = {
3
+ paths: {
4
+ path: string;
5
+ datum: ScaledDataRecord;
6
+ }[];
7
+ args: Record<string | symbol, any>;
8
+ options: Record<string, any>;
9
+ className: string;
10
+ usedScales: Record<ScaledChannelName, boolean>;
11
+ plot: PlotState;
12
+ canvas?: boolean;
13
+ };
14
+ declare const PathItems: import("svelte").Component<$$ComponentProps, {}, "">;
15
+ type PathItems = ReturnType<typeof PathItems>;
16
+ export default PathItems;
@@ -14,11 +14,14 @@ export { default as Brush } from './Brush.svelte';
14
14
  export { default as BrushX } from './BrushX.svelte';
15
15
  export { default as BrushY } from './BrushY.svelte';
16
16
  export { default as Cell } from './Cell.svelte';
17
- export { default as Contour } from './Contour.svelte';
18
17
  export { default as CellX } from './CellX.svelte';
19
18
  export { default as CellY } from './CellY.svelte';
19
+ export { default as Contour } from './Contour.svelte';
20
20
  export { default as CustomMark } from './CustomMark.svelte';
21
21
  export { default as CustomMarkHTML } from './CustomMarkHTML.svelte';
22
+ export { default as DelaunayLink } from './DelaunayLink.svelte';
23
+ export { default as DelaunayMesh } from './DelaunayMesh.svelte';
24
+ export { default as Density } from './Density.svelte';
22
25
  export { default as DifferenceY } from './DifferenceY.svelte';
23
26
  export { default as Dot } from './Dot.svelte';
24
27
  export { default as DotX } from './DotX.svelte';
@@ -28,6 +31,7 @@ export { default as Geo } from './Geo.svelte';
28
31
  export { default as Graticule } from './Graticule.svelte';
29
32
  export { default as GridX } from './GridX.svelte';
30
33
  export { default as GridY } from './GridY.svelte';
34
+ export { default as Hull } from './Hull.svelte';
31
35
  export { default as Image } from './Image.svelte';
32
36
  export { default as Line } from './Line.svelte';
33
37
  export { default as LineX } from './LineX.svelte';
@@ -49,6 +53,8 @@ export { default as TickX } from './TickX.svelte';
49
53
  export { default as TickY } from './TickY.svelte';
50
54
  export { default as Trail } from './Trail.svelte';
51
55
  export { default as Vector } from './Vector.svelte';
56
+ export { default as Voronoi } from './Voronoi.svelte';
57
+ export { default as VoronoiMesh } from './VoronoiMesh.svelte';
52
58
  export { default as WaffleX } from './WaffleX.svelte';
53
59
  export { default as WaffleY } from './WaffleY.svelte';
54
60
  export { default as ColorLegend } from './ColorLegend.svelte';
@@ -14,11 +14,14 @@ export { default as Brush } from './Brush.svelte';
14
14
  export { default as BrushX } from './BrushX.svelte';
15
15
  export { default as BrushY } from './BrushY.svelte';
16
16
  export { default as Cell } from './Cell.svelte';
17
- export { default as Contour } from './Contour.svelte';
18
17
  export { default as CellX } from './CellX.svelte';
19
18
  export { default as CellY } from './CellY.svelte';
19
+ export { default as Contour } from './Contour.svelte';
20
20
  export { default as CustomMark } from './CustomMark.svelte';
21
21
  export { default as CustomMarkHTML } from './CustomMarkHTML.svelte';
22
+ export { default as DelaunayLink } from './DelaunayLink.svelte';
23
+ export { default as DelaunayMesh } from './DelaunayMesh.svelte';
24
+ export { default as Density } from './Density.svelte';
22
25
  export { default as DifferenceY } from './DifferenceY.svelte';
23
26
  export { default as Dot } from './Dot.svelte';
24
27
  export { default as DotX } from './DotX.svelte';
@@ -28,6 +31,7 @@ export { default as Geo } from './Geo.svelte';
28
31
  export { default as Graticule } from './Graticule.svelte';
29
32
  export { default as GridX } from './GridX.svelte';
30
33
  export { default as GridY } from './GridY.svelte';
34
+ export { default as Hull } from './Hull.svelte';
31
35
  export { default as Image } from './Image.svelte';
32
36
  export { default as Line } from './Line.svelte';
33
37
  export { default as LineX } from './LineX.svelte';
@@ -49,6 +53,8 @@ export { default as TickX } from './TickX.svelte';
49
53
  export { default as TickY } from './TickY.svelte';
50
54
  export { default as Trail } from './Trail.svelte';
51
55
  export { default as Vector } from './Vector.svelte';
56
+ export { default as Voronoi } from './Voronoi.svelte';
57
+ export { default as VoronoiMesh } from './VoronoiMesh.svelte';
52
58
  export { default as WaffleX } from './WaffleX.svelte';
53
59
  export { default as WaffleY } from './WaffleY.svelte';
54
60
  // HTML marks
@@ -6,7 +6,7 @@ export type Mark<T> = {
6
6
  data: DataRecord<T>[];
7
7
  options: T;
8
8
  };
9
- export type MarkType = 'area' | 'arrow' | 'axisX' | 'axisY' | 'barX' | 'barY' | 'cell' | 'custom' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'image' | 'link' | 'line' | 'raster' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY' | 'trail' | 'waffleX' | 'waffleY';
9
+ export type MarkType = 'area' | 'arrow' | 'axisX' | 'axisY' | 'barX' | 'barY' | 'cell' | 'contour' | 'custom' | 'delaunayLink' | 'delaunayMesh' | 'density' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'hull' | 'image' | 'link' | 'line' | 'raster' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY' | 'trail' | 'voronoi' | 'voronoiMesh' | 'waffleX' | 'waffleY';
10
10
  export type MarkStyleProps = 'strokeDasharray' | 'strokeLinejoin' | 'strokeLinecap' | 'opacity' | 'cursor' | 'pointerEvents' | 'blend' | 'fill' | 'fillOpacity' | 'fontFamily' | 'fontWeight' | 'fontVariant' | 'fontSize' | 'fontStyle' | 'letterSpacing' | 'wordSpacing' | 'stroke' | 'strokeWidth' | 'strokeOpacity' | 'x' | 'y' | 'clipPath' | 'mask' | 'filter' | 'angle' | 'radius' | 'symbol' | 'textAnchor' | 'textTransform' | 'textDecoration' | 'width';
11
11
  import type { ChannelAccessor, ConstantAccessor, DataRecord, RawValue } from './index.js';
12
12
  import type * as CSS from 'csstype';
@@ -5,7 +5,7 @@ import type { ChannelAccessor, ChannelName, ColorScaleOptions, DataRecord, Legen
5
5
  import type { Snippet } from 'svelte';
6
6
  import type { GenericMarkOptions, Mark } from './index.js';
7
7
  import type { Clip } from '../helpers/projection.js';
8
- import type { Area, AreaX, AreaY, Arrow, AxisX, AxisY, BarX, BarY, BoxX, BoxY, Brush, BrushX, BrushY, Cell, Contour, DifferenceY, Dot, Frame, Geo, Graticule, GridX, GridY, Image, Line, Link, Pointer, Raster, Rect, RectX, RectY, RuleX, RuleY, Sphere, Spike, Text, TickX, TickY, Trail, Vector } from '../marks/index.js';
8
+ import type { Area, AreaX, AreaY, Arrow, AxisX, AxisY, BarX, BarY, BoxX, BoxY, Brush, BrushX, BrushY, Cell, Contour, DelaunayLink, DelaunayMesh, Density, DifferenceY, Dot, Frame, Geo, Graticule, GridX, GridY, Hull, Image, Line, Link, Pointer, Raster, Rect, RectX, RectY, RuleX, RuleY, Sphere, Spike, Text, TickX, TickY, Trail, Vector, Voronoi, VoronoiMesh } from '../marks/index.js';
9
9
  import type WaffleX from '../marks/WaffleX.svelte';
10
10
  import type WaffleY from '../marks/WaffleY.svelte';
11
11
  import type BaseAxisX from '../marks/helpers/BaseAxisX.svelte';
@@ -208,6 +208,18 @@ export type PlotDefaults = {
208
208
  * default props for contour marks
209
209
  */
210
210
  contour: Partial<Omit<ComponentProps<typeof Contour>, IgnoreDefaults>>;
211
+ /**
212
+ * default props for delaunayLink marks
213
+ */
214
+ delaunayLink: Partial<Omit<ComponentProps<typeof DelaunayLink>, IgnoreDefaults>>;
215
+ /**
216
+ * default props for delaunayMesh marks
217
+ */
218
+ delaunayMesh: Partial<Omit<ComponentProps<typeof DelaunayMesh>, IgnoreDefaults>>;
219
+ /**
220
+ * default props for density marks
221
+ */
222
+ density: Partial<Omit<ComponentProps<typeof Density>, IgnoreDefaults>>;
211
223
  /**
212
224
  * default props for dot marks
213
225
  */
@@ -248,6 +260,10 @@ export type PlotDefaults = {
248
260
  gridY: Partial<Omit<ComponentProps<typeof GridY>, IgnoreDefaults> & {
249
261
  implicit: boolean;
250
262
  }> | true;
263
+ /**
264
+ * default props for hull marks
265
+ */
266
+ hull: Partial<Omit<ComponentProps<typeof Hull>, IgnoreDefaults>>;
251
267
  /**
252
268
  * default props for image marks
253
269
  */
@@ -324,6 +340,14 @@ export type PlotDefaults = {
324
340
  * default props for vector marks
325
341
  */
326
342
  vector: Partial<Omit<ComponentProps<typeof Vector>, IgnoreDefaults>>;
343
+ /**
344
+ * default props for voronoi marks
345
+ */
346
+ voronoi: Partial<Omit<ComponentProps<typeof Voronoi>, IgnoreDefaults>>;
347
+ /**
348
+ * default props for voronoiMesh marks
349
+ */
350
+ voronoiMesh: Partial<Omit<ComponentProps<typeof VoronoiMesh>, IgnoreDefaults>>;
327
351
  /**
328
352
  * default props for waffle marks, applied to both waffleX and waffleY marks
329
353
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "A Svelte-native data visualization framework based on the layered grammar of graphics principles.",
5
5
  "keywords": [
6
6
  "svelte",