svelteplot 0.3.7-pr-131.0 → 0.3.7-pr-132.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<Datum>[];
14
+ scaledData: ScaledDataRecord[];
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<Datum>[];
74
+ scaledData: ScaledDataRecord[];
75
75
  }]> | undefined;
76
76
  defaults?: Partial<Record<ScaledChannelName, RawValue>>;
77
77
  };
@@ -41,6 +41,7 @@
41
41
  RawValue
42
42
  } from '../types/index.js';
43
43
  import type { StackOptions } from '../transforms/stack.js';
44
+ import { addEventHandlers } from './helpers/events';
44
45
 
45
46
  let markProps: AreaMarkProps = $props();
46
47
 
@@ -135,6 +136,11 @@
135
136
  class={['svelteplot-area', className, styleClass]}
136
137
  clip-path={options.clipPath}
137
138
  d={areaPath(areaData)}
139
+ use:addEventHandlers={{
140
+ getPlotState,
141
+ options,
142
+ datum: datum.datum
143
+ }}
138
144
  {style}
139
145
  >{#if title}<title>{title}</title>{/if}</path>
140
146
  </Anchor>
@@ -4,18 +4,10 @@
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>;
11
9
  y?: ChannelAccessor<Datum>;
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 }]>;
10
+ children: Snippet<[{ datum: Datum; x: number; y: number }]>;
19
11
  }
20
12
 
21
13
  import { getContext } from 'svelte';
@@ -23,47 +15,36 @@
23
15
  PlotContext,
24
16
  DataRecord,
25
17
  ChannelAccessor,
26
- BaseMarkProps,
27
- ScaledDataRecord,
28
- UsedScales,
29
- ScaledChannelName
18
+ BaseMarkProps
30
19
  } from '../types/index.js';
31
20
  import type { Snippet } from 'svelte';
32
- import { sort } from '../index.js';
33
21
 
34
- import Mark from '../Mark.svelte';
22
+ const { getPlotState } = getContext<PlotContext>('svelteplot');
23
+ let plot = $derived(getPlotState());
35
24
 
36
- let { data = [{} as Datum], mark, marks, ...options }: CustomMarkProps = $props();
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';
37
29
 
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
- ];
30
+ let {
31
+ data = [{} as Datum],
32
+ x,
33
+ y,
34
+ children,
35
+ class: className = null
36
+ }: CustomMarkProps = $props();
54
37
  </script>
55
38
 
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}
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>
67
48
  {/if}
68
- {/snippet}
69
- </Mark>
49
+ {/each}
50
+ </GroupMultiple>
@@ -8,5 +8,4 @@ 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;
12
11
  export type ChannelName = ScaledChannelName | 'z' | 'sort' | 'filter' | 'interval';
@@ -1,4 +1,4 @@
1
- import type { ScaledChannelName, ScaledChannelType } from './channel.js';
1
+ import type { ScaledChannelName } 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,9 +6,7 @@ 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<{
10
- [K in ScaledChannelName]?: ScaledChannelType<K>;
11
- }> & {
9
+ export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<Record<ScaledChannelName, number | string | boolean | undefined>> & {
12
10
  datum: DataRecord<T>;
13
11
  valid: Boolean;
14
12
  };
@@ -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' | 'custom' | 'dot' | 'vector' | 'frame' | 'geo' | 'gridX' | 'gridY' | 'line' | 'rect' | 'regression' | 'ruleX' | 'ruleY' | 'swoopyArrow' | 'text' | 'tickX' | 'tickY';
9
+ export type MarkType = 'area' | 'arrow' | 'barX' | 'barY' | 'cell' | '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-131.0",
3
+ "version": "0.3.7-pr-132.1",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",