svelteplot 0.3.7-pr-133.0 → 0.3.7-pr-131.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.
package/dist/Mark.svelte CHANGED
@@ -11,7 +11,7 @@
11
11
  {
12
12
  mark: Mark<GenericMarkOptions>;
13
13
  usedScales: ReturnType<typeof getUsedScales>;
14
- scaledData: ScaledDataRecord[];
14
+ scaledData: ScaledDataRecord<Datum>[];
15
15
  }
16
16
  ]
17
17
  >;
@@ -71,7 +71,7 @@ declare class __sveltets_Render<Datum extends DataRecord> {
71
71
  children?: Snippet<[{
72
72
  mark: any;
73
73
  usedScales: ReturnType<typeof getUsedScales>;
74
- scaledData: ScaledDataRecord[];
74
+ scaledData: ScaledDataRecord<Datum>[];
75
75
  }]> | undefined;
76
76
  defaults?: Partial<Record<ScaledChannelName, RawValue>>;
77
77
  };
@@ -4,10 +4,18 @@
4
4
  -->
5
5
  <script lang="ts" generics="Datum extends DataRecord">
6
6
  interface CustomMarkProps extends BaseMarkProps<Datum> {
7
- data: Datum[];
7
+ data?: Datum[];
8
8
  x?: ChannelAccessor<Datum>;
9
+ x1?: ChannelAccessor<Datum>;
10
+ x2?: ChannelAccessor<Datum>;
9
11
  y?: ChannelAccessor<Datum>;
10
- children: Snippet<[{ datum: Datum; x: number; y: number }]>;
12
+ y1?: ChannelAccessor<Datum>;
13
+ y2?: ChannelAccessor<Datum>;
14
+ r?: ChannelAccessor<Datum>;
15
+ mark?: Snippet<
16
+ [{ record: ScaledDataRecord<Datum>; index: number; usedScales: UsedScales }]
17
+ >;
18
+ marks?: Snippet<[{ records: ScaledDataRecord<Datum>[]; usedScales: UsedScales }]>;
11
19
  }
12
20
 
13
21
  import { getContext } from 'svelte';
@@ -15,36 +23,47 @@
15
23
  PlotContext,
16
24
  DataRecord,
17
25
  ChannelAccessor,
18
- BaseMarkProps
26
+ BaseMarkProps,
27
+ ScaledDataRecord,
28
+ UsedScales,
29
+ ScaledChannelName
19
30
  } from '../types/index.js';
20
31
  import type { Snippet } from 'svelte';
32
+ import { sort } from '../index.js';
21
33
 
22
- const { getPlotState } = getContext<PlotContext>('svelteplot');
23
- let plot = $derived(getPlotState());
34
+ import Mark from '../Mark.svelte';
24
35
 
25
- import { resolveChannel } from '../helpers/resolve.js';
26
- import { projectXY } from '../helpers/scales.js';
27
- import { isValid } from '../helpers/index.js';
28
- import GroupMultiple from './helpers/GroupMultiple.svelte';
36
+ let { data = [{} as Datum], mark, marks, ...options }: CustomMarkProps = $props();
29
37
 
30
- let {
31
- data = [{} as Datum],
32
- x,
33
- y,
34
- children,
35
- class: className = null
36
- }: CustomMarkProps = $props();
38
+ const args = $derived(sort({ data, ...options })) as CustomMarkProps;
39
+
40
+ const channels: ScaledChannelName[] = [
41
+ 'x',
42
+ 'x1',
43
+ 'x2',
44
+ 'y',
45
+ 'y1',
46
+ 'y2',
47
+ 'r',
48
+ 'fill',
49
+ 'stroke',
50
+ 'opacity',
51
+ 'fillOpacity',
52
+ 'strokeOpacity'
53
+ ];
37
54
  </script>
38
55
 
39
- <GroupMultiple class="g-custom-mark {className || ''}" length={className ? 2 : data.length}>
40
- {#each data as datum, i (i)}
41
- {@const x_ = resolveChannel<Datum>('x', datum, { x, y })}
42
- {@const y_ = resolveChannel<Datum>('y', datum, { x, y })}
43
- {#if isValid(x_) && isValid(y_)}
44
- {@const [px, py] = projectXY(plot.scales, x_, y_)}
45
- <g transform="translate({px}, {py})">
46
- {@render children({ datum, x: px, y: py })}
47
- </g>
56
+ <Mark type="custom" required={[]} channels={channels.filter((d) => !!options[d])} {...args}>
57
+ {#snippet children({ scaledData, usedScales })}
58
+ {#if marks}
59
+ {@render marks({ records: scaledData.filter((d) => d.valid), usedScales })}
60
+ {/if}
61
+ {#if mark}
62
+ {#each scaledData as datum, i (i)}
63
+ {#if datum.valid}
64
+ {@render mark({ record: datum, index: i, usedScales })}
65
+ {/if}
66
+ {/each}
48
67
  {/if}
49
- {/each}
50
- </GroupMultiple>
68
+ {/snippet}
69
+ </Mark>
@@ -8,4 +8,5 @@ export type ChannelAccessor<T = Record<string | symbol, RawValue>> = ChannelValu
8
8
  };
9
9
  export type ChannelValue<T = Record<string | symbol, RawValue>> = RawValue | keyof T | ((d: T) => RawValue) | null | undefined;
10
10
  export type ScaledChannelName = 'fill' | 'fillOpacity' | 'opacity' | 'r' | 'length' | 'stroke' | 'strokeOpacity' | 'symbol' | 'fx' | 'fy' | 'x' | 'x1' | 'x2' | 'y' | 'y1' | 'y2';
11
+ export type ScaledChannelType<T extends ScaledChannelName> = T extends 'fill' | 'stroke' | 'symbol' ? string : number;
11
12
  export type ChannelName = ScaledChannelName | 'z' | 'sort' | 'filter' | 'interval';
@@ -1,4 +1,4 @@
1
- import type { ScaledChannelName } from './channel.js';
1
+ import type { ScaledChannelName, ScaledChannelType } from './channel.js';
2
2
  export type RawValue = number | Date | boolean | string | symbol;
3
3
  export type DataRecord<T = Record<string | symbol, RawValue>> = T & {
4
4
  ___orig___?: RawValue | [RawValue, RawValue];
@@ -6,7 +6,9 @@ export type DataRecord<T = Record<string | symbol, RawValue>> = T & {
6
6
  export type ResolvedDataRecord<T = Record<string | symbol, RawValue>> = Partial<Record<ScaledChannelName, any>> & {
7
7
  datum: DataRecord<T>;
8
8
  };
9
- export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<Record<ScaledChannelName, number | string | boolean | undefined>> & {
9
+ export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<{
10
+ [K in ScaledChannelName]?: ScaledChannelType<K>;
11
+ }> & {
10
12
  datum: DataRecord<T>;
11
13
  valid: Boolean;
12
14
  };
@@ -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' | 'barX' | 'barY' | 'cell' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'line' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY';
9
+ export type MarkType = 'area' | 'arrow' | 'barX' | 'barY' | 'cell' | 'custom' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'line' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY';
10
10
  export type MarkStyleProps = 'strokeDasharray' | 'strokeLinejoin' | 'strokeLinecap' | 'opacity' | 'cursor' | 'pointerEvents' | 'blend' | 'fill' | 'fillOpacity' | 'fontWeight' | 'fontVariant' | 'fontSize' | 'fontStyle' | 'stroke' | 'strokeWidth' | 'strokeOpacity' | 'x' | 'y' | 'clipPath' | 'mask' | 'filter' | 'angle' | 'radius' | 'symbol' | 'textAnchor' | 'width';
11
11
  import type { MouseEventHandler } from 'svelte/elements';
12
12
  import type { ChannelAccessor, ConstantAccessor, DataRecord, RawValue } from './index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.3.7-pr-133.0",
3
+ "version": "0.3.7-pr-131.1",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",