svelteplot 0.1.3-next.11 → 0.1.3-next.12

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/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # SveltePlot
2
2
 
3
- SveltePlot is a new reactive visualization framework based on the [layered grammar of graphics](https://vita.had.co.nz/papers/layered-grammar.html) ideas. It's API is heavily inspired by [Observable Plot](https://github.com/observablehq/plot). Created by Gregor Aisch.
3
+ SveltePlot is a visualization framework based on the [layered grammar of graphics](https://vita.had.co.nz/papers/layered-grammar.html) ideas. It's API is heavily inspired by [Observable Plot](https://github.com/observablehq/plot). Created by Gregor Aisch.
4
+
5
+ <img src="static/logo.png" alt="SveltePlot logo" width="400" />
4
6
 
5
- <img src="static/logo.png" alt="logo" width="400" />
@@ -147,7 +147,9 @@ export function createScale(name, scaleOptions, marks, plotOptions, plotWidth, p
147
147
  valueArr.sort(ascending);
148
148
  }
149
149
  const domain = scaleOptions.domain
150
- ? extent(scaleOptions.zero ? [0, ...scaleOptions.domain] : scaleOptions.domain)
150
+ ? isOrdinal
151
+ ? scaleOptions.domain
152
+ : extent(scaleOptions.zero ? [0, ...scaleOptions.domain] : scaleOptions.domain)
151
153
  : type === 'band' ||
152
154
  type === 'point' ||
153
155
  type === 'ordinal' ||
@@ -46,8 +46,6 @@
46
46
  stack
47
47
  )
48
48
  );
49
-
50
- $inspect({ args });
51
49
  </script>
52
50
 
53
51
  <Mark
@@ -64,16 +62,25 @@
64
62
  {@const insetLeft = resolveProp(args.insetLeft, d.datum, 0)}
65
63
  {@const insetRight = resolveProp(args.insetRight, d.datum, 0)}
66
64
  {@const insetTop = resolveProp(args.insetTop || args.inset, d.datum, 0)}
67
- {@const insetBottom = resolveProp(args.insetBottom || args.inset, d.datum, 0)}
65
+ {@const insetBottom = resolveProp(args.insetBottom || args.inset, d.datum, 0)}
68
66
  {@const dx = resolveProp(args.dx, d.datum, 0)}
69
67
  {@const dy = resolveProp(args.dy, d.datum, 0)}
70
68
  {#if d.valid}
71
69
  {@const [style, styleClass] = resolveStyles(plot, d, args, 'fill', usedScales)}
72
70
  <path
73
- d={roundedRect(0, 0, maxx - minx - insetLeft - insetRight, bw - insetTop - insetBottom, options.borderRadius)}
71
+ d={roundedRect(
72
+ 0,
73
+ 0,
74
+ maxx - minx - insetLeft - insetRight,
75
+ bw - insetTop - insetBottom,
76
+ options.borderRadius
77
+ )}
74
78
  class={[styleClass, className]}
75
79
  {style}
76
- transform="translate({[minx + dx + insetLeft, d.y + insetTop + dy - bw * 0.5]})"
80
+ transform="translate({[
81
+ minx + dx + insetLeft,
82
+ d.y + insetTop + dy - bw * 0.5
83
+ ]})"
77
84
  use:addEventHandlers={{
78
85
  getPlotState,
79
86
  options: args,
@@ -11,10 +11,8 @@
11
11
  import {
12
12
  type PlotContext,
13
13
  type BaseMarkProps,
14
- type RectMarkProps,
15
14
  type ChannelAccessor,
16
- type DataRow,
17
- type FacetContext
15
+ type DataRow
18
16
  } from '../types.js';
19
17
  import type { StackOptions } from '../transforms/stack.js';
20
18
  import { maybeData } from '../helpers/index.js';
@@ -41,25 +39,23 @@
41
39
  bottomRight?: number;
42
40
  bottomLeft?: number;
43
41
  };
44
- } & RectMarkProps;
42
+ };
45
43
 
46
44
  let { data = [{}], class: className = null, stack, ...options }: BarYProps = $props();
47
45
 
48
46
  const { getPlotState } = getContext<PlotContext>('svelteplot');
49
- let plot = $derived(getPlotState());
47
+ const plot = $derived(getPlotState());
50
48
 
51
- let args = $derived(
49
+ const args = $derived(
52
50
  stackY(
53
51
  intervalY(
54
52
  // by default, sort by x channel (the ordinal labels)
55
- sort(recordizeY({ data: maybeData(data), sort: { channel: 'x' }, ...options })),
53
+ sort(recordizeY({ data, sort: { channel: 'x' }, ...options })),
56
54
  { plot }
57
55
  ),
58
56
  stack
59
57
  )
60
58
  );
61
-
62
- const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
63
59
  </script>
64
60
 
65
61
  <Mark
@@ -82,10 +78,19 @@
82
78
  {#if d.valid}
83
79
  {@const [style, styleClass] = resolveStyles(plot, d, args, 'fill', usedScales)}
84
80
  <path
85
- d={roundedRect(0, 0, bw - insetLeft - insetRight, maxy - miny - insetTop - insetBottom, options.borderRadius)}
81
+ d={roundedRect(
82
+ 0,
83
+ 0,
84
+ bw - insetLeft - insetRight,
85
+ maxy - miny - insetTop - insetBottom,
86
+ options.borderRadius
87
+ )}
86
88
  class={[styleClass, className]}
87
89
  {style}
88
- transform="translate({[d.x + insetLeft + dx - bw * 0.5, miny + dy + insetTop]})"
90
+ transform="translate({[
91
+ d.x + insetLeft + dx - bw * 0.5,
92
+ miny + dy + insetTop
93
+ ]})"
89
94
  use:addEventHandlers={{
90
95
  getPlotState,
91
96
  options: args,
@@ -1,4 +1,25 @@
1
+ import { type BaseMarkProps, type ChannelAccessor, type DataRow } from '../types.js';
2
+ import type { StackOptions } from '../transforms/stack.js';
3
+ type BarYProps = BaseMarkProps & {
4
+ data: DataRow[];
5
+ x?: ChannelAccessor;
6
+ y?: ChannelAccessor;
7
+ y1?: ChannelAccessor;
8
+ y2?: ChannelAccessor;
9
+ stack?: StackOptions;
10
+ /**
11
+ * Converts y into y1/y2 ranges based on the provided interval. Disables the
12
+ * implicit stacking
13
+ */
14
+ interval?: number | string;
15
+ borderRadius?: number | {
16
+ topLeft?: number;
17
+ topRight?: number;
18
+ bottomRight?: number;
19
+ bottomLeft?: number;
20
+ };
21
+ };
1
22
  /** For vertical column charts using a band scale as x axis */
2
- declare const BarY: import("svelte").Component<any, {}, "">;
23
+ declare const BarY: import("svelte").Component<BarYProps, {}, "">;
3
24
  type BarY = ReturnType<typeof BarY>;
4
25
  export default BarY;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import type { TransformArgsRow, TransformArgsRecord } from '../types.js';
2
+ export declare const INDEX: unique symbol;
2
3
  export declare const RAW_VALUE: unique symbol;
3
4
  export declare function recordizeX({ data, ...channels }: TransformArgsRow, { withIndex }?: {
4
5
  withIndex: boolean;
@@ -1,5 +1,6 @@
1
1
  import isDataRecord from '../helpers/isDataRecord.js';
2
- export const RAW_VALUE = Symbol();
2
+ export const INDEX = Symbol('index');
3
+ export const RAW_VALUE = Symbol('originalValue');
3
4
  /*
4
5
  * This transform takes an array of raw values as input and returns data records
5
6
  * in which the values are interpreted as x channel and their index as y
@@ -12,7 +13,6 @@ export function recordizeX({ data, ...channels }, { withIndex } = { withIndex: t
12
13
  __value: value,
13
14
  ...(withIndex ? { __index: index } : {}),
14
15
  [RAW_VALUE]: value,
15
- // TODO: remove ___orig___ references
16
16
  ___orig___: value
17
17
  })),
18
18
  ...channels,
@@ -33,14 +33,13 @@ export function recordizeY({ data, ...channels }, { withIndex } = { withIndex: t
33
33
  if (dataIsRawValueArray) {
34
34
  return {
35
35
  data: Array.from(data).map((value, index) => ({
36
- __value: value,
37
36
  ...(withIndex ? { __index: index } : {}),
38
37
  [RAW_VALUE]: value,
39
38
  ___orig___: value
40
39
  })),
41
40
  ...channels,
42
41
  ...(withIndex ? { x: '__index' } : {}),
43
- y: '__value'
42
+ y: RAW_VALUE
44
43
  };
45
44
  }
46
45
  return {
@@ -66,7 +65,7 @@ export function recordizeXY({ data, ...channels }) {
66
65
  channels.y === undefined) {
67
66
  return {
68
67
  data: data.map(([x, y, ...rest]) => ({
69
- ___orig___: [x, y, ...rest],
68
+ [RAW_VALUE]: [x, y, ...rest],
70
69
  __x: x,
71
70
  __y: y
72
71
  })),
@@ -10,12 +10,14 @@ type WindowOptions = {
10
10
  export declare function windowX(args: TransformArg<DataRecord>, options: WindowOptions): {
11
11
  data: {
12
12
  [x: string]: import("../types.js").RawValue;
13
+ [x: symbol]: import("../types.js").RawValue;
13
14
  ___orig___?: import("../types.js").RawValue | [import("../types.js").RawValue, import("../types.js").RawValue];
14
15
  }[];
15
16
  };
16
17
  export declare function windowY(args: TransformArg<DataRecord>, options: WindowOptions): {
17
18
  data: {
18
19
  [x: string]: import("../types.js").RawValue;
20
+ [x: symbol]: import("../types.js").RawValue;
19
21
  ___orig___?: import("../types.js").RawValue | [import("../types.js").RawValue, import("../types.js").RawValue];
20
22
  }[];
21
23
  };
package/dist/types.d.ts CHANGED
@@ -331,7 +331,7 @@ export type PlotDefaults = {
331
331
  markerDotRadius: number;
332
332
  };
333
333
  export type GenericMarkOptions = Record<string, any>;
334
- export type DataRecord = Record<string, RawValue> & {
334
+ export type DataRecord = Record<string | symbol, RawValue> & {
335
335
  ___orig___?: RawValue | [RawValue, RawValue];
336
336
  };
337
337
  export type ResolvedDataRecord = Partial<Record<ScaledChannelName, any>> & {
@@ -544,7 +544,7 @@ export type BaseRectMarkProps = {
544
544
  insetRight?: ConstantAccessor<number>;
545
545
  insetBottom?: ConstantAccessor<number>;
546
546
  };
547
- export type Channels = Record<string, ChannelAccessor | ConstantAccessor<string | number | boolean>>;
547
+ export type Channels = Record<string, ChannelAccessor | ConstantAccessor<string | number | boolean | symbol>>;
548
548
  export type TransformArg<K> = Channels & {
549
549
  data: K[];
550
550
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.1.3-next.11",
3
+ "version": "0.1.3-next.12",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",
@@ -87,7 +87,7 @@
87
87
  "svelte-highlight": "^7.8.3",
88
88
  "topojson-client": "^3.1.0",
89
89
  "tslib": "^2.8.1",
90
- "typedoc": "^0.28.3",
90
+ "typedoc": "^0.28.4",
91
91
  "typedoc-plugin-markdown": "^4.6.3",
92
92
  "typescript": "^5.8.3",
93
93
  "vite": "^6.3.4",
@@ -109,7 +109,7 @@
109
109
  "d3-scale-chromatic": "^3.1.0",
110
110
  "d3-shape": "^3.2.0",
111
111
  "d3-time": "^3.1.0",
112
- "es-toolkit": "^1.37.1",
112
+ "es-toolkit": "^1.37.2",
113
113
  "fast-equals": "^5.2.2",
114
114
  "merge-deep": "^3.0.3",
115
115
  "svelte": "5.28.2"