svelteplot 0.5.3 → 0.6.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.
@@ -5,6 +5,7 @@
5
5
  <script lang="ts" generics="Datum extends DataRecord">
6
6
  interface CustomMarkProps extends BaseMarkProps<Datum> {
7
7
  data?: Datum[];
8
+ type?: string;
8
9
  x?: ChannelAccessor<Datum>;
9
10
  x1?: ChannelAccessor<Datum>;
10
11
  x2?: ChannelAccessor<Datum>;
@@ -18,7 +19,6 @@
18
19
  marks?: Snippet<[{ records: ScaledDataRecord<Datum>[]; usedScales: UsedScales }]>;
19
20
  }
20
21
 
21
- import { getContext } from 'svelte';
22
22
  import type {
23
23
  PlotContext,
24
24
  DataRecord,
@@ -33,7 +33,13 @@
33
33
 
34
34
  import Mark from '../Mark.svelte';
35
35
 
36
- let { data = [{} as Datum], mark, marks, ...options }: CustomMarkProps = $props();
36
+ let {
37
+ data = [{} as Datum],
38
+ mark,
39
+ type = 'custom',
40
+ marks,
41
+ ...options
42
+ }: CustomMarkProps = $props();
37
43
 
38
44
  const args = $derived(sort({ data, ...options })) as CustomMarkProps;
39
45
 
@@ -53,7 +59,7 @@
53
59
  ];
54
60
  </script>
55
61
 
56
- <Mark type="custom" required={[]} channels={channels.filter((d) => !!options[d])} {...args}>
62
+ <Mark {type} required={[]} channels={channels.filter((d) => !!options[d])} {...args}>
57
63
  {#snippet children({ scaledData, usedScales })}
58
64
  {#if marks}
59
65
  {@render marks({ records: scaledData.filter((d) => d.valid), usedScales })}
@@ -65,6 +65,7 @@ declare class __sveltets_Render<Datum extends DataRecord> {
65
65
  cursor: import("../types/index.js").ConstantAccessor<import("csstype").Property.Cursor, Datum>;
66
66
  }> & {
67
67
  data?: Datum[] | undefined;
68
+ type?: string;
68
69
  x?: ChannelAccessor<Datum>;
69
70
  x1?: ChannelAccessor<Datum>;
70
71
  x2?: ChannelAccessor<Datum>;
@@ -0,0 +1,76 @@
1
+ <!--
2
+ @component
3
+ For showing images positioned at x/y coordinates
4
+ -->
5
+ <script lang="ts" generics="Datum extends DataRecord">
6
+ interface ImageMarkProps extends BaseMarkProps<Datum>, LinkableMarkProps<Datum> {
7
+ data: Datum[];
8
+ x: ChannelAccessor<Datum>;
9
+ y: ChannelAccessor<Datum>;
10
+ r?: ChannelAccessor<Datum>;
11
+ width?: ConstantAccessor<number, Datum>;
12
+ height?: ConstantAccessor<number, Datum>;
13
+ src?: ConstantAccessor<string, Datum>;
14
+ title?: ConstantAccessor<string, Datum>;
15
+ preserveAspectRatio?: string;
16
+ // canvas?: boolean;
17
+ imageClass?: ConstantAccessor<string, Datum>;
18
+ }
19
+
20
+ import type {
21
+ BaseMarkProps,
22
+ ChannelAccessor,
23
+ ConstantAccessor,
24
+ DataRecord,
25
+ LinkableMarkProps
26
+ } from '../types';
27
+ import { resolveProp } from '../helpers/resolve';
28
+ import CustomMark from './CustomMark.svelte';
29
+ import { getPlotDefaults } from '../hooks/plotDefaults';
30
+ import { sort } from '../transforms';
31
+ import Anchor from './helpers/Anchor.svelte';
32
+
33
+ let markProps: ImageMarkProps = $props();
34
+
35
+ const DEFAULTS: Partial<ImageMarkProps> = {
36
+ width: 20,
37
+ preserveAspectRatio: 'xMidYMin slice',
38
+ ...getPlotDefaults().image
39
+ };
40
+
41
+ const {
42
+ data = [{} as Datum],
43
+ width,
44
+ height,
45
+ src,
46
+ title,
47
+ imageClass,
48
+ preserveAspectRatio,
49
+ ...options
50
+ }: ImageMarkProps = $derived({
51
+ ...DEFAULTS,
52
+ ...markProps
53
+ });
54
+
55
+ const args = $derived(sort({ data, ...options }));
56
+ </script>
57
+
58
+ <CustomMark type="image" {...args}>
59
+ {#snippet mark({ record, index, usedScales })}
60
+ {@const w = record.r !== undefined ? record.r * 2 : resolveProp(width, record.datum, 20)}
61
+ {@const h =
62
+ record.r !== undefined ? record.r * 2 : resolveProp(height || width, record.datum, 20)}
63
+ <Anchor {options} datum={record.datum}>
64
+ <image
65
+ class={resolveProp(imageClass, record.datum, null)}
66
+ href={resolveProp(src, record.datum, '')}
67
+ x={record.x - w * 0.5}
68
+ y={record.y - h * 0.5}
69
+ {preserveAspectRatio}
70
+ clip-path={record.r !== undefined ? `circle(${record.r}px)` : null}
71
+ width={w}
72
+ height={h}
73
+ >{#if title}<title>{resolveProp(title, record.datum, '')}</title>{/if}</image>
74
+ </Anchor>
75
+ {/snippet}
76
+ </CustomMark>
@@ -0,0 +1,92 @@
1
+ import type { ChannelAccessor, ConstantAccessor, DataRecord, LinkableMarkProps } from '../types';
2
+ declare class __sveltets_Render<Datum extends DataRecord> {
3
+ props(): Partial<{
4
+ filter: ConstantAccessor<boolean, Datum>;
5
+ facet: "auto" | "include" | "exclude";
6
+ fx: ChannelAccessor<Datum>;
7
+ fy: ChannelAccessor<Datum>;
8
+ dx: ConstantAccessor<number, Datum>;
9
+ dy: ConstantAccessor<number, Datum>;
10
+ dodgeX: import("../transforms/dodge").DodgeXOptions;
11
+ dodgeY: import("../transforms/dodge").DodgeYOptions;
12
+ fill: ChannelAccessor<Datum>;
13
+ fillOpacity: ConstantAccessor<number, Datum>;
14
+ sort: ((a: import("../types").RawValue, b: import("../types").RawValue) => number) | {
15
+ channel: string;
16
+ order?: "ascending" | "descending";
17
+ } | ConstantAccessor<import("../types").RawValue, Datum>;
18
+ stroke: ChannelAccessor<Datum>;
19
+ strokeWidth: ConstantAccessor<number, Datum>;
20
+ strokeOpacity: ConstantAccessor<number, Datum>;
21
+ strokeLinejoin: ConstantAccessor<import("csstype").Property.StrokeLinejoin, Datum>;
22
+ strokeLinecap: ConstantAccessor<import("csstype").Property.StrokeLinecap, Datum>;
23
+ strokeMiterlimit: ConstantAccessor<number, Datum>;
24
+ opacity: ChannelAccessor<Datum>;
25
+ strokeDasharray: ConstantAccessor<string, Datum>;
26
+ strokeDashoffset: ConstantAccessor<number, Datum>;
27
+ mixBlendMode: ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
28
+ clipPath: string;
29
+ imageFilter: ConstantAccessor<string, Datum>;
30
+ shapeRendering: ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
31
+ paintOrder: ConstantAccessor<string, Datum>;
32
+ onclick: import("svelte/elements").MouseEventHandler<SVGPathElement>;
33
+ ondblclick: import("svelte/elements").MouseEventHandler<SVGPathElement>;
34
+ onmouseup: import("svelte/elements").MouseEventHandler<SVGPathElement>;
35
+ onmousedown: import("svelte/elements").MouseEventHandler<SVGPathElement>;
36
+ onmouseenter: import("svelte/elements").MouseEventHandler<SVGPathElement>;
37
+ onmousemove: import("svelte/elements").MouseEventHandler<SVGPathElement>;
38
+ onmouseleave: import("svelte/elements").MouseEventHandler<SVGPathElement>;
39
+ onmouseout: import("svelte/elements").MouseEventHandler<SVGPathElement>;
40
+ onmouseover: import("svelte/elements").MouseEventHandler<SVGPathElement>;
41
+ onpointercancel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
42
+ onpointerdown: import("svelte/elements").MouseEventHandler<SVGPathElement>;
43
+ onpointerup: import("svelte/elements").MouseEventHandler<SVGPathElement>;
44
+ onpointerenter: import("svelte/elements").MouseEventHandler<SVGPathElement>;
45
+ onpointerleave: import("svelte/elements").MouseEventHandler<SVGPathElement>;
46
+ onpointermove: import("svelte/elements").MouseEventHandler<SVGPathElement>;
47
+ onpointerover: import("svelte/elements").MouseEventHandler<SVGPathElement>;
48
+ onpointerout: import("svelte/elements").MouseEventHandler<SVGPathElement>;
49
+ ondrag: import("svelte/elements").MouseEventHandler<SVGPathElement>;
50
+ ondrop: import("svelte/elements").MouseEventHandler<SVGPathElement>;
51
+ ondragstart: import("svelte/elements").MouseEventHandler<SVGPathElement>;
52
+ ondragenter: import("svelte/elements").MouseEventHandler<SVGPathElement>;
53
+ ondragleave: import("svelte/elements").MouseEventHandler<SVGPathElement>;
54
+ ondragover: import("svelte/elements").MouseEventHandler<SVGPathElement>;
55
+ ondragend: import("svelte/elements").MouseEventHandler<SVGPathElement>;
56
+ ontouchstart: import("svelte/elements").MouseEventHandler<SVGPathElement>;
57
+ ontouchmove: import("svelte/elements").MouseEventHandler<SVGPathElement>;
58
+ ontouchend: import("svelte/elements").MouseEventHandler<SVGPathElement>;
59
+ ontouchcancel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
60
+ oncontextmenu: import("svelte/elements").MouseEventHandler<SVGPathElement>;
61
+ onwheel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
62
+ class: string;
63
+ style: string;
64
+ cursor: ConstantAccessor<import("csstype").Property.Cursor, Datum>;
65
+ }> & LinkableMarkProps<Datum> & {
66
+ data: Datum[];
67
+ x: ChannelAccessor<Datum>;
68
+ y: ChannelAccessor<Datum>;
69
+ r?: ChannelAccessor<Datum>;
70
+ width?: ConstantAccessor<number, Datum>;
71
+ height?: ConstantAccessor<number, Datum>;
72
+ src?: ConstantAccessor<string, Datum>;
73
+ title?: ConstantAccessor<string, Datum>;
74
+ preserveAspectRatio?: string;
75
+ imageClass?: ConstantAccessor<string, Datum>;
76
+ };
77
+ events(): {};
78
+ slots(): {};
79
+ bindings(): "";
80
+ exports(): {};
81
+ }
82
+ interface $$IsomorphicComponent {
83
+ new <Datum extends DataRecord>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Datum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Datum>['props']>, ReturnType<__sveltets_Render<Datum>['events']>, ReturnType<__sveltets_Render<Datum>['slots']>> & {
84
+ $$bindings?: ReturnType<__sveltets_Render<Datum>['bindings']>;
85
+ } & ReturnType<__sveltets_Render<Datum>['exports']>;
86
+ <Datum extends DataRecord>(internal: unknown, props: ReturnType<__sveltets_Render<Datum>['props']> & {}): ReturnType<__sveltets_Render<Datum>['exports']>;
87
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
88
+ }
89
+ /** For showing images positioned at x/y coordinates */
90
+ declare const Image: $$IsomorphicComponent;
91
+ type Image<Datum extends DataRecord> = InstanceType<typeof Image<Datum>>;
92
+ export default Image;
@@ -201,7 +201,7 @@
201
201
  : args.textStroke
202
202
  ? 2
203
203
  : 0,
204
- fill: args.textFill || args.stroke,
204
+ fill: args.textFill || lineData[0].stroke,
205
205
  stroke: args.textStroke
206
206
  },
207
207
  'fill',
@@ -222,7 +222,7 @@
222
222
  color={lineData[0].stroke || 'currentColor'}
223
223
  {style}
224
224
  class={styleClass}
225
- text={text ? resolveProp(text, lineData[0]) : null}
225
+ text={text ? resolveProp(text, lineData[0].datum) : null}
226
226
  startOffset={resolveProp(
227
227
  args.textStartOffset,
228
228
  lineData[0].datum,
@@ -1,7 +1,21 @@
1
- <script>
1
+ <script lang="ts" generics="Datum extends Record<string, any>">
2
2
  import { resolveProp } from '../../helpers/resolve.js';
3
+ import type { ConstantAccessor } from '../../types';
3
4
 
4
- let { datum = {}, options = {}, children } = $props();
5
+ interface AnchorProps {
6
+ datum?: Datum;
7
+ options?: {
8
+ href?: ConstantAccessor<string, Datum>;
9
+ target?: ConstantAccessor<string, Datum>;
10
+ rel?: ConstantAccessor<string, Datum>;
11
+ type?: ConstantAccessor<string, Datum>;
12
+ download?: ConstantAccessor<string, Datum>;
13
+ [key: string]: any;
14
+ };
15
+ children?: () => any;
16
+ }
17
+
18
+ let { datum = {}, options = {}, children }: AnchorProps = $props();
5
19
 
6
20
  const href = $derived(resolveProp(options.href, datum, null));
7
21
  const target = $derived(resolveProp(options.target, datum, null));
@@ -1,15 +1,29 @@
1
+ import type { ConstantAccessor } from '../../types';
2
+ declare class __sveltets_Render<Datum extends Record<string, any>> {
3
+ props(): {
4
+ datum?: Datum | undefined;
5
+ options?: {
6
+ [key: string]: any;
7
+ href?: ConstantAccessor<string, Datum>;
8
+ target?: ConstantAccessor<string, Datum>;
9
+ rel?: ConstantAccessor<string, Datum>;
10
+ type?: ConstantAccessor<string, Datum>;
11
+ download?: ConstantAccessor<string, Datum>;
12
+ } | undefined;
13
+ children?: (() => any) | undefined;
14
+ };
15
+ events(): {};
16
+ slots(): {};
17
+ bindings(): "";
18
+ exports(): {};
19
+ }
20
+ interface $$IsomorphicComponent {
21
+ new <Datum extends Record<string, any>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Datum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Datum>['props']>, ReturnType<__sveltets_Render<Datum>['events']>, ReturnType<__sveltets_Render<Datum>['slots']>> & {
22
+ $$bindings?: ReturnType<__sveltets_Render<Datum>['bindings']>;
23
+ } & ReturnType<__sveltets_Render<Datum>['exports']>;
24
+ <Datum extends Record<string, any>>(internal: unknown, props: ReturnType<__sveltets_Render<Datum>['props']> & {}): ReturnType<__sveltets_Render<Datum>['exports']>;
25
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
26
+ }
27
+ declare const Anchor: $$IsomorphicComponent;
28
+ type Anchor<Datum extends Record<string, any>> = InstanceType<typeof Anchor<Datum>>;
1
29
  export default Anchor;
2
- type Anchor = {
3
- $on?(type: string, callback: (e: any) => void): () => void;
4
- $set?(props: Partial<$$ComponentProps>): void;
5
- };
6
- declare const Anchor: import("svelte").Component<{
7
- datum?: Record<string, any>;
8
- options?: Record<string, any>;
9
- children: any;
10
- }, {}, "">;
11
- type $$ComponentProps = {
12
- datum?: Record<string, any>;
13
- options?: Record<string, any>;
14
- children: any;
15
- };
@@ -27,6 +27,7 @@ export { default as Geo } from './Geo.svelte';
27
27
  export { default as Graticule } from './Graticule.svelte';
28
28
  export { default as GridX } from './GridX.svelte';
29
29
  export { default as GridY } from './GridY.svelte';
30
+ export { default as Image } from './Image.svelte';
30
31
  export { default as Line } from './Line.svelte';
31
32
  export { default as LineX } from './LineX.svelte';
32
33
  export { default as LineY } from './LineY.svelte';
@@ -27,6 +27,7 @@ export { default as Geo } from './Geo.svelte';
27
27
  export { default as Graticule } from './Graticule.svelte';
28
28
  export { default as GridX } from './GridX.svelte';
29
29
  export { default as GridY } from './GridY.svelte';
30
+ export { default as Image } from './Image.svelte';
30
31
  export { default as Line } from './Line.svelte';
31
32
  export { default as LineX } from './LineX.svelte';
32
33
  export { default as LineY } from './LineY.svelte';
@@ -3,7 +3,7 @@ import type { ColorScheme } from './colorScheme.js';
3
3
  import type { GeoProjection } from 'd3-geo';
4
4
  import type { ChannelAccessor, ChannelName, ColorScaleOptions, DataRecord, LegendScaleOptions, PlotScales, ScaleOptions, XScaleOptions, YScaleOptions } from './index.js';
5
5
  import type { Snippet } from 'svelte';
6
- import type { Area, AreaX, AreaY, Arrow, AxisX, AxisY, BarX, BarY, BoxX, BoxY, Brush, BrushX, BrushY, Cell, DifferenceY, Dot, Frame, Geo, Graticule, GridX, GridY, Line, Link, Pointer, Rect, RectX, RectY, RuleX, RuleY, Sphere, Spike, Text, TickX, TickY, Vector } from '../marks/index.js';
6
+ import type { Area, AreaX, AreaY, Arrow, AxisX, AxisY, BarX, BarY, BoxX, BoxY, Brush, BrushX, BrushY, Cell, DifferenceY, Dot, Frame, Geo, Graticule, GridX, GridY, Image, Line, Link, Pointer, Rect, RectX, RectY, RuleX, RuleY, Sphere, Spike, Text, TickX, TickY, Vector } from '../marks/index.js';
7
7
  export type PlotState = {
8
8
  width: number;
9
9
  height: number;
@@ -230,6 +230,10 @@ export type PlotDefaults = {
230
230
  gridY: Partial<Omit<ComponentProps<typeof GridY>, IgnoreDefaults> & {
231
231
  implicit: boolean;
232
232
  }>;
233
+ /**
234
+ * default props for image marks
235
+ */
236
+ image: Partial<Omit<ComponentProps<typeof Image>, IgnoreDefaults>>;
233
237
  /**
234
238
  * default props for line marks
235
239
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",