svelteplot 0.5.1-pr-238.7 → 0.5.2-pr-251.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 })}
@@ -0,0 +1,67 @@
1
+ <script lang="ts" generics="Datum extends DataRecord">
2
+ interface ImageMarkProps extends BaseMarkProps<Datum>, LinkableMarkProps<Datum> {
3
+ data: Datum[];
4
+ x: ChannelAccessor<Datum>;
5
+ y: ChannelAccessor<Datum>;
6
+ r?: ChannelAccessor<Datum>;
7
+ width?: ConstantAccessor<number, Datum>;
8
+ height?: ConstantAccessor<number, Datum>;
9
+ src?: ConstantAccessor<string, Datum>;
10
+ title?: ConstantAccessor<string, Datum>;
11
+ preserveAspectRatio?: string;
12
+ // canvas?: boolean;
13
+ imageClass?: ConstantAccessor<string, Datum>;
14
+ }
15
+
16
+ import type {
17
+ BaseMarkProps,
18
+ ChannelAccessor,
19
+ ConstantAccessor,
20
+ DataRecord,
21
+ LinkableMarkProps
22
+ } from '../types';
23
+ import { resolveProp } from '../helpers/resolve';
24
+ import CustomMark from './CustomMark.svelte';
25
+ import { getPlotDefaults } from '../hooks/plotDefaults';
26
+ import { sort } from '../transforms';
27
+
28
+ let markProps: ImageMarkProps = $props();
29
+
30
+ const DEFAULTS: Partial<ImageMarkProps> = {
31
+ width: 20,
32
+ preserveAspectRatio: 'xMidYMin slice',
33
+ ...getPlotDefaults().image
34
+ };
35
+
36
+ const {
37
+ data = [{} as Datum],
38
+ width,
39
+ height,
40
+ src,
41
+ title,
42
+ preserveAspectRatio,
43
+ ...options
44
+ }: ImageMarkProps = $derived({
45
+ ...DEFAULTS,
46
+ ...markProps
47
+ });
48
+
49
+ const args = $derived(sort({ data, ...options }));
50
+ </script>
51
+
52
+ <CustomMark type="image" {...args}>
53
+ {#snippet mark({ record, index, usedScales })}
54
+ {@const w = record.r !== undefined ? record.r * 2 : resolveProp(width, record.datum, 20)}
55
+ {@const h =
56
+ record.r !== undefined ? record.r * 2 : resolveProp(height || width, record.datum, 20)}
57
+ <image
58
+ href={resolveProp(src, record.datum, '')}
59
+ x={record.x - w * 0.5}
60
+ y={record.y - h * 0.5}
61
+ {preserveAspectRatio}
62
+ clip-path={record.r !== undefined ? `circle(${record.r}px)` : null}
63
+ width={w}
64
+ height={h}
65
+ >{#if title}<title>{resolveProp(title, record.datum, '')}</title>{/if}</image>
66
+ {/snippet}
67
+ </CustomMark>
@@ -0,0 +1,18 @@
1
+ import type { DataRecord } from '../types';
2
+ declare class __sveltets_Render<Datum extends DataRecord> {
3
+ props(): any;
4
+ events(): {};
5
+ slots(): {};
6
+ bindings(): "";
7
+ exports(): {};
8
+ }
9
+ interface $$IsomorphicComponent {
10
+ 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']>> & {
11
+ $$bindings?: ReturnType<__sveltets_Render<Datum>['bindings']>;
12
+ } & ReturnType<__sveltets_Render<Datum>['exports']>;
13
+ <Datum extends DataRecord>(internal: unknown, props: ReturnType<__sveltets_Render<Datum>['props']> & {}): ReturnType<__sveltets_Render<Datum>['exports']>;
14
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
15
+ }
16
+ declare const Image: $$IsomorphicComponent;
17
+ type Image<Datum extends DataRecord> = InstanceType<typeof Image<Datum>>;
18
+ export default Image;
@@ -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.1-pr-238.7",
3
+ "version": "0.5.2-pr-251.0",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",