svelteplot 0.8.1 → 0.9.0-pr-309.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.
Files changed (131) hide show
  1. package/README.md +4 -3
  2. package/dist/Mark.svelte +1 -1
  3. package/dist/Mark.svelte.d.ts +6 -4
  4. package/dist/constants.d.ts +3 -1
  5. package/dist/constants.js +11 -2
  6. package/dist/core/Plot.svelte +4 -4
  7. package/dist/helpers/autoScales.d.ts +1 -1
  8. package/dist/helpers/callWithProps.d.ts +1 -3
  9. package/dist/helpers/callWithProps.js +5 -3
  10. package/dist/helpers/colors.d.ts +9 -12
  11. package/dist/helpers/facets.d.ts +1 -1
  12. package/dist/helpers/getBaseStyles.d.ts +2 -4
  13. package/dist/helpers/index.d.ts +3 -3
  14. package/dist/helpers/projection.js +7 -2
  15. package/dist/helpers/reduce.d.ts +1 -1
  16. package/dist/helpers/scales.d.ts +7 -7
  17. package/dist/helpers/symbols.d.ts +2 -2
  18. package/dist/helpers/time.d.ts +3 -3
  19. package/dist/helpers/typeChecks.d.ts +8 -8
  20. package/dist/hooks/usePlot.svelte.d.ts +51 -0
  21. package/dist/hooks/usePlot.svelte.js +90 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/marks/Area.svelte +3 -5
  25. package/dist/marks/Area.svelte.d.ts +6 -4
  26. package/dist/marks/AreaX.svelte.d.ts +7 -5
  27. package/dist/marks/Arrow.svelte +3 -5
  28. package/dist/marks/Arrow.svelte.d.ts +6 -4
  29. package/dist/marks/AxisX.svelte +2 -3
  30. package/dist/marks/AxisX.svelte.d.ts +7 -5
  31. package/dist/marks/AxisY.svelte +3 -4
  32. package/dist/marks/AxisY.svelte.d.ts +7 -5
  33. package/dist/marks/BarX.svelte +2 -4
  34. package/dist/marks/BarX.svelte.d.ts +6 -4
  35. package/dist/marks/BarY.svelte +2 -4
  36. package/dist/marks/BarY.svelte.d.ts +6 -4
  37. package/dist/marks/BollingerX.svelte.d.ts +2 -76
  38. package/dist/marks/BollingerY.svelte.d.ts +2 -76
  39. package/dist/marks/BoxX.svelte +4 -138
  40. package/dist/marks/BoxY.svelte +20 -137
  41. package/dist/marks/BoxY.svelte.d.ts +6 -64
  42. package/dist/marks/Brush.svelte +3 -3
  43. package/dist/marks/Brush.svelte.d.ts +1 -63
  44. package/dist/marks/Cell.svelte +2 -4
  45. package/dist/marks/Cell.svelte.d.ts +6 -4
  46. package/dist/marks/ColorLegend.svelte +2 -4
  47. package/dist/marks/CustomMark.svelte.d.ts +2 -84
  48. package/dist/marks/CustomMarkHTML.svelte +5 -10
  49. package/dist/marks/DifferenceY.svelte +3 -5
  50. package/dist/marks/DifferenceY.svelte.d.ts +1 -63
  51. package/dist/marks/Dot.svelte +4 -5
  52. package/dist/marks/Dot.svelte.d.ts +6 -4
  53. package/dist/marks/DotX.svelte.d.ts +7 -5
  54. package/dist/marks/DotY.svelte.d.ts +7 -5
  55. package/dist/marks/Frame.svelte +3 -9
  56. package/dist/marks/Frame.svelte.d.ts +7 -5
  57. package/dist/marks/Geo.svelte +5 -5
  58. package/dist/marks/Geo.svelte.d.ts +7 -4
  59. package/dist/marks/GridX.svelte +3 -10
  60. package/dist/marks/GridX.svelte.d.ts +6 -4
  61. package/dist/marks/GridY.svelte +3 -4
  62. package/dist/marks/GridY.svelte.d.ts +6 -4
  63. package/dist/marks/HTMLTooltip.svelte +5 -5
  64. package/dist/marks/Image.svelte.d.ts +2 -75
  65. package/dist/marks/Line.svelte +7 -6
  66. package/dist/marks/Line.svelte.d.ts +6 -4
  67. package/dist/marks/LineX.svelte.d.ts +8 -6
  68. package/dist/marks/LineY.svelte.d.ts +8 -6
  69. package/dist/marks/Link.svelte +2 -4
  70. package/dist/marks/Link.svelte.d.ts +6 -4
  71. package/dist/marks/Pointer.svelte +4 -4
  72. package/dist/marks/Rect.svelte +2 -4
  73. package/dist/marks/Rect.svelte.d.ts +6 -4
  74. package/dist/marks/RectX.svelte +4 -4
  75. package/dist/marks/RectY.svelte +4 -4
  76. package/dist/marks/RuleX.svelte +2 -4
  77. package/dist/marks/RuleX.svelte.d.ts +6 -4
  78. package/dist/marks/RuleY.svelte +2 -4
  79. package/dist/marks/RuleY.svelte.d.ts +6 -4
  80. package/dist/marks/Spike.svelte.d.ts +7 -5
  81. package/dist/marks/SymbolLegend.svelte +2 -4
  82. package/dist/marks/SymbolLegend.svelte.d.ts +17 -2
  83. package/dist/marks/Text.svelte.d.ts +6 -4
  84. package/dist/marks/TickX.svelte +2 -3
  85. package/dist/marks/TickX.svelte.d.ts +6 -4
  86. package/dist/marks/TickY.svelte +2 -3
  87. package/dist/marks/TickY.svelte.d.ts +6 -4
  88. package/dist/marks/Trail.svelte +161 -0
  89. package/dist/marks/Trail.svelte.d.ts +44 -0
  90. package/dist/marks/Vector.svelte +3 -4
  91. package/dist/marks/Vector.svelte.d.ts +6 -4
  92. package/dist/marks/WaffleX.svelte +2 -3
  93. package/dist/marks/WaffleX.svelte.d.ts +2 -85
  94. package/dist/marks/WaffleY.svelte +2 -4
  95. package/dist/marks/WaffleY.svelte.d.ts +2 -83
  96. package/dist/marks/helpers/AreaCanvas.svelte +2 -4
  97. package/dist/marks/helpers/Box.svelte +271 -0
  98. package/dist/marks/helpers/Box.svelte.d.ts +55 -0
  99. package/dist/marks/helpers/CanvasLayer.svelte +2 -4
  100. package/dist/marks/helpers/DotCanvas.svelte +3 -5
  101. package/dist/marks/helpers/GeoCanvas.svelte +2 -4
  102. package/dist/marks/helpers/LineCanvas.svelte +2 -4
  103. package/dist/marks/helpers/LinearGradientX.svelte +3 -4
  104. package/dist/marks/helpers/LinearGradientY.svelte +3 -4
  105. package/dist/marks/helpers/MarkerPath.svelte +4 -5
  106. package/dist/marks/helpers/MarkerPath.svelte.d.ts +2 -102
  107. package/dist/marks/helpers/MultilineText.svelte +4 -4
  108. package/dist/marks/helpers/RectPath.svelte +5 -6
  109. package/dist/marks/helpers/Regression.svelte +4 -8
  110. package/dist/marks/helpers/TrailCanvas.svelte +138 -0
  111. package/dist/marks/helpers/TrailCanvas.svelte.d.ts +40 -0
  112. package/dist/marks/helpers/events.d.ts +2 -2
  113. package/dist/marks/helpers/events.js +4 -4
  114. package/dist/marks/helpers/trail.d.ts +23 -0
  115. package/dist/marks/helpers/trail.js +372 -0
  116. package/dist/marks/index.d.ts +1 -0
  117. package/dist/marks/index.js +1 -0
  118. package/dist/transforms/bollinger.d.ts +1 -69
  119. package/dist/transforms/centroid.d.ts +1 -4
  120. package/dist/transforms/group.d.ts +4 -12
  121. package/dist/transforms/interval.d.ts +2 -128
  122. package/dist/transforms/normalize.d.ts +23 -0
  123. package/dist/transforms/recordize.d.ts +4 -7
  124. package/dist/transforms/select.d.ts +7 -448
  125. package/dist/transforms/sort.d.ts +5 -253
  126. package/dist/transforms/stack.d.ts +3 -23
  127. package/dist/transforms/window.d.ts +2 -134
  128. package/dist/types/mark.d.ts +2 -1
  129. package/dist/types/plot.d.ts +6 -1
  130. package/dist/ui/Spiral.svelte +4 -0
  131. package/package.json +25 -23
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # SveltePlot
2
2
 
3
- ![License](https://img.shields.io/npm/l/svelteplot.svg) ![Tests](https://github.com/svelteplot/svelteplot/actions/workflows/test.yml/badge.svg)
4
-
5
- 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.
3
+ ![License](https://img.shields.io/npm/l/svelteplot.svg) ![Tests](https://github.com/svelteplot/svelteplot/actions/workflows/test.yml/badge.svg) [![Netlify Status](https://api.netlify.com/api/v1/badges/81163b24-76c1-4256-833c-919284f211ed/deploy-status)](https://app.netlify.com/projects/svelteplot/deploys)
6
4
 
7
5
  <img src="static/logo.svg" alt="SveltePlot logo" width="401" />
8
6
 
7
+ SveltePlot is a [Svelte](https://svelte.dev/)-native visualization framework based on the [layered grammar of graphics](https://vita.had.co.nz/papers/layered-grammar.html) principle. It's API is heavily inspired by [Observable Plot](https://github.com/observablehq/plot). Created by Gregor Aisch.
8
+
9
9
  ## Development
10
10
 
11
11
  Clone the repo and install dependencies:
@@ -46,3 +46,4 @@ pnpm vi:report
46
46
  ```
47
47
 
48
48
  To see the differences side by side you can open http://localhost:5173/\_\_vr/report.html
49
+
package/dist/Mark.svelte CHANGED
@@ -151,7 +151,7 @@
151
151
  // check if the mark has defined an accessor for this channel
152
152
  if (options?.[channel] !== undefined && out[channel] === undefined) {
153
153
  // resolve value
154
- out[channel] = resolveChannel(channel, row, options);
154
+ out[channel] = resolveChannel(channel, row, options, index);
155
155
  if (options[channel] === INDEX) {
156
156
  const scale = plot.scales[CHANNEL_SCALE[channel]];
157
157
  if (scale.type === 'band' || scale.type === 'point') {
@@ -1,4 +1,5 @@
1
1
  import { type Snippet } from 'svelte';
2
+ import { CHANNEL_SCALE } from './constants.js';
2
3
  import type { ScaledChannelName, MarkType, DataRecord, ChannelAccessor, ScaleName, RawValue, ScaledDataRecord, ScaleType } from './types/index.js';
3
4
  import { getUsedScales } from './helpers/scales.js';
4
5
  declare function $$render<Datum extends DataRecord>(): {
@@ -9,14 +10,14 @@ declare function $$render<Datum extends DataRecord>(): {
9
10
  fy: ChannelAccessor<Datum>;
10
11
  dx: import("./types/index.js").ConstantAccessor<number, Datum>;
11
12
  dy: import("./types/index.js").ConstantAccessor<number, Datum>;
12
- dodgeX: import("./transforms/dodge.js").DodgeXOptions;
13
- dodgeY: import("./transforms/dodge.js").DodgeYOptions;
13
+ dodgeX: CHANNEL_SCALE;
14
+ dodgeY: CHANNEL_SCALE;
14
15
  fill: ChannelAccessor<Datum>;
15
16
  fillOpacity: import("./types/index.js").ConstantAccessor<number, Datum>;
16
- sort: ((a: RawValue, b: RawValue) => number) | {
17
+ sort: {
17
18
  channel: string;
18
19
  order?: "ascending" | "descending";
19
- } | import("./types/index.js").ConstantAccessor<RawValue, Datum>;
20
+ } | ((a: RawValue, b: RawValue) => number) | import("./types/index.js").ConstantAccessor<RawValue, Datum>;
20
21
  stroke: ChannelAccessor<Datum>;
21
22
  strokeWidth: import("./types/index.js").ConstantAccessor<number, Datum>;
22
23
  strokeOpacity: import("./types/index.js").ConstantAccessor<number, Datum>;
@@ -28,6 +29,7 @@ declare function $$render<Datum extends DataRecord>(): {
28
29
  strokeDashoffset: import("./types/index.js").ConstantAccessor<number, Datum>;
29
30
  mixBlendMode: import("./types/index.js").ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
30
31
  clipPath: string;
32
+ mask: string;
31
33
  imageFilter: import("./types/index.js").ConstantAccessor<string, Datum>;
32
34
  shapeRendering: import("./types/index.js").ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
33
35
  paintOrder: import("./types/index.js").ConstantAccessor<string, Datum>;
@@ -13,4 +13,6 @@ export declare const CSS_COLOR_MIX: RegExp;
13
13
  export declare const CSS_COLOR_CONTRAST: RegExp;
14
14
  export declare const CSS_RGBA: RegExp;
15
15
  export declare const CSS_URL: RegExp;
16
- export declare const INDEX: unique symbol;
16
+ export declare const INDEX: any;
17
+ export declare const PI: number;
18
+ export declare const TAU: number;
package/dist/constants.js CHANGED
@@ -86,8 +86,15 @@ export const VALID_SCALE_TYPES = {
86
86
  'quantile',
87
87
  'quantize',
88
88
  'threshold'
89
- ])
90
- // ...
89
+ ]),
90
+ symbol: new Set(['categorical', 'ordinal']),
91
+ opacity: new Set(['linear', 'log', 'symlog', 'sqrt', 'pow']),
92
+ r: new Set(['linear', 'log', 'symlog', 'sqrt', 'pow']),
93
+ length: new Set(['linear', 'log', 'symlog', 'sqrt', 'pow']),
94
+ fx: new Set(['band']),
95
+ fy: new Set(['band']),
96
+ // projection is a special type not mapping to a D3 scale
97
+ projection: new Set()
91
98
  };
92
99
  /**
93
100
  * Map of all scaled channels
@@ -117,6 +124,8 @@ export const CSS_COLOR_CONTRAST = /^color-contrast\(/; // just check for prefix
117
124
  export const CSS_RGBA = /^rgba\(/; // just check for prefix
118
125
  export const CSS_URL = /^url\(#/; // just check for prefix
119
126
  export const INDEX = Symbol('index');
127
+ export const PI = Math.PI;
128
+ export const TAU = PI * 2;
120
129
  // export const CHANNEL_MAP: Record<ScaleName, ValueOf<typeof SCALE_TYPES>> = {
121
130
  // x: SCALE_TYPES.x,
122
131
  // y: SCALE_TYPES.y,
@@ -31,6 +31,7 @@
31
31
  import { CHANNEL_SCALE, SCALES } from '../constants.js';
32
32
  import { getPlotDefaults, setPlotDefaults } from '../hooks/plotDefaults.js';
33
33
  import { maybeNumber } from '../helpers/index.js';
34
+ import { setPlot, usePlot } from '../hooks/usePlot.svelte.js';
34
35
 
35
36
  // automatic margins can be applied by the marks, registered
36
37
  // with their respective unique identifier as keys
@@ -261,11 +262,10 @@
261
262
  let facetWidth: number | null = $state(null);
262
263
  let facetHeight: number | null = $state(null);
263
264
 
264
- // eslint-disable-next-line svelte/prefer-writable-derived
265
- let plotState: PlotState = $state(computePlotState());
265
+ let plotState = setPlot(computePlotState());
266
266
 
267
267
  $effect(() => {
268
- plotState = computePlotState();
268
+ plotState.update(computePlotState());
269
269
  });
270
270
 
271
271
  function computePlotState() {
@@ -337,7 +337,7 @@
337
337
  if (facetHeight !== h) facetHeight = h;
338
338
  },
339
339
  updatePlotState() {
340
- plotState = computePlotState();
340
+ plotState.update(computePlotState());
341
341
  }
342
342
  });
343
343
 
@@ -9,7 +9,7 @@ export declare function autoScale({ name, type, domain, scaleOptions, plotOption
9
9
  plotHeight: number;
10
10
  plotHasFilledDotMarks: boolean;
11
11
  plotDefaults: PlotDefaults;
12
- }): Record<string, (v: any) => void>;
12
+ }): (val: any) => any;
13
13
  export declare function autoScaleColor({ type, domain, scaleOptions, plotOptions, plotWidth, plotHeight, plotHasFilledDotMarks, plotDefaults }: {
14
14
  name: ScaleName;
15
15
  type: ScaleType;
@@ -1,8 +1,6 @@
1
1
  import type { RawValue } from '../types/index.js';
2
- type Setter = (v: any) => void;
3
2
  /**
4
3
  * Helper function to call a D3 "function class" while also calling
5
4
  * property setter functions on the result.
6
5
  */
7
- export default function (d3func: () => Record<string, Setter>, args: RawValue[], props?: Record<string, RawValue>): Record<string, Setter>;
8
- export {};
6
+ export default function <T extends object>(d3func: (...args: RawValue[]) => T, args?: RawValue[], props?: Record<string, RawValue>): T;
@@ -2,12 +2,14 @@
2
2
  * Helper function to call a D3 "function class" while also calling
3
3
  * property setter functions on the result.
4
4
  */
5
- export default function (d3func, args, props = {}) {
5
+ export default function (d3func, args = [], props = {}) {
6
6
  const res = d3func(...args);
7
+ const resWithKeys = res;
7
8
  for (const [key, val] of Object.entries(props)) {
8
- if (typeof res[key] !== 'function')
9
+ const setter = resWithKeys[key];
10
+ if (typeof setter !== 'function')
9
11
  throw new Error(`function ${key} does not exist`);
10
- res[key](val);
12
+ setter(val);
11
13
  }
12
14
  return res;
13
15
  }
@@ -1,13 +1,10 @@
1
- import { interpolateBrBG } from 'd3-scale-chromatic';
2
1
  import type { ColorScheme } from '../types/index.js';
3
- export declare const categoricalSchemes: Map<string, readonly string[]>;
4
- export declare function isCategoricalScheme(scheme: string): boolean;
5
- type SchemeGetter = (n: number) => readonly string[];
6
- export declare function isOrdinalScheme(scheme: ColorScheme): boolean;
7
- export declare function ordinalScheme(scheme: string): SchemeGetter | undefined;
8
- export declare function ordinalRange(scheme: string, length: number): readonly string[] | undefined;
9
- export declare function maybeBooleanRange(domain: boolean[], scheme?: string): unknown[] | undefined;
10
- export declare function isQuantitativeScheme(scheme: string): boolean;
11
- export declare function quantitativeScheme(scheme: string): typeof interpolateBrBG | undefined;
12
- export declare function isDivergingScheme(scheme: string): boolean;
13
- export {};
2
+ export declare const categoricalSchemes: any;
3
+ export declare function isCategoricalScheme(scheme: string): any;
4
+ export declare function isOrdinalScheme(scheme: ColorScheme): any;
5
+ export declare function ordinalScheme(scheme: string): any;
6
+ export declare function ordinalRange(scheme: string, length: number): any;
7
+ export declare function maybeBooleanRange(domain: boolean[], scheme?: string): any[] | undefined;
8
+ export declare function isQuantitativeScheme(scheme: string): any;
9
+ export declare function quantitativeScheme(scheme: string): any;
10
+ export declare function isDivergingScheme(scheme: string): any;
@@ -9,4 +9,4 @@ import type { GenericMarkOptions, Mark, RawValue } from '../types/index.js';
9
9
  * @param fyValues y facet domain
10
10
  * @returns
11
11
  */
12
- export declare function getEmptyFacets(marks: Mark<GenericMarkOptions>[], fxValues: RawValue[], fyValues: RawValue[]): Map<RawValue, Map<RawValue, boolean>>;
12
+ export declare function getEmptyFacets(marks: Mark<GenericMarkOptions>[], fxValues: RawValue[], fyValues: RawValue[]): any;
@@ -1,9 +1,7 @@
1
1
  import type { Channels } from '../types/index.js';
2
2
  import type { DataRow } from '../types/index.js';
3
- export declare function getBaseStylesObject(datum: DataRow, props: Partial<Channels>): {
4
- [k: string]: string | number;
5
- };
6
- export default function (datum: DataRow, props: Partial<Channels>): string;
3
+ export declare function getBaseStylesObject(datum: DataRow, props: Partial<Channels>): any;
4
+ export default function (datum: DataRow, props: Partial<Channels>): any;
7
5
  export declare function maybeToPixel(cssKey: string, value: string | number): string | number;
8
6
  export declare function maybeFromPixel(value: string | number): string | number;
9
7
  export declare function maybeFromRem(value: string | number, rootFontSize?: number): string | number;
@@ -3,8 +3,8 @@ import type { Snippet } from 'svelte';
3
3
  /**
4
4
  * Returns first argument that is not null or undefined
5
5
  */
6
- export declare function coalesce(...args: (RawValue | undefined | null)[]): string | number | boolean | symbol | object | null;
7
- export declare function testFilter<T>(datum: T, options: Channels<T>): true | T | null;
6
+ export declare function coalesce(...args: (RawValue | undefined | null)[]): any;
7
+ export declare function testFilter<T>(datum: T, options: Channels<T>): any;
8
8
  export declare function randomId(): string;
9
9
  export declare function isSnippet(value: unknown): value is Snippet;
10
10
  export declare function isValid(value: RawValue | undefined): value is number | Date | string;
@@ -15,4 +15,4 @@ export declare const POSITION_CHANNELS: Set<ChannelName>;
15
15
  export declare function parseInset(inset: number | string, width: number): number;
16
16
  export declare function omit<T extends {}, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
17
17
  export declare function identity<T>(x: T): T;
18
- export declare const GEOJSON_PREFER_STROKE: Set<string>;
18
+ export declare const GEOJSON_PREFER_STROKE: any;
@@ -50,7 +50,7 @@ export function createProjection({ projOptions, inset: globalInset = 2, insetTop
50
50
  let transform;
51
51
  let invertTransform = (d) => d;
52
52
  // If a domain is specified, fit the projection to the frame.
53
- if (domain != null) {
53
+ if (domain != null && dx > 0 && dy > 0) {
54
54
  const [[x0, y0], [x1, y1]] = geoPath(projInstance).bounds(domain);
55
55
  const k = Math.min(dx / (x1 - x0), dy / (y1 - y0));
56
56
  aspectRatio = (y1 - y0) / (x1 - x0);
@@ -66,9 +66,14 @@ export function createProjection({ projOptions, inset: globalInset = 2, insetTop
66
66
  invertTransform = ([x, y]) => [(x - tx) / k, (y - ty) / k];
67
67
  }
68
68
  else {
69
- throw new Error(`Warning: the projection could not be fit to the specified domain; using the default scale.`);
69
+ // eslint-disable-next-line no-console
70
+ console.warn(`Warning: the projection could not be fit to the specified domain; using the default scale.`);
70
71
  }
71
72
  }
73
+ else if (domain != null) {
74
+ // eslint-disable-next-line no-console
75
+ console.warn(`Warning: the projection could not be fit to the specified domain; using the default scale.`);
76
+ }
72
77
  transform ??=
73
78
  tx === 0 && ty === 0
74
79
  ? identity()
@@ -4,7 +4,7 @@ type ReducerOption = ReducerName | ReducerFunc;
4
4
  type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
5
5
  export type ReducerPercentile = (`p${Digit}${Digit}` & Record<never, never>) | 'p25' | 'p50' | 'p75';
6
6
  export type ReducerName = 'count' | 'deviation' | 'difference' | 'first' | 'last' | 'max' | 'mean' | 'median' | 'min' | 'mode' | 'ratio' | 'sum' | 'variance' | ReducerPercentile;
7
- export declare const Reducer: Record<ReducerName, ReducerFunc>;
7
+ export declare const Reducer: any;
8
8
  export declare function mayberReducer(r: ReducerOption): ReducerFunc;
9
9
  export declare function reduceOutputs(newDatum: DataRecord, data: DataRecord[], options: Record<ChannelName, ReducerOption>, outputs: Iterable<ChannelName>, channels: Channels, newChannels: Channels): void;
10
10
  export {};
@@ -1,4 +1,4 @@
1
- import type { ChannelAccessor, GenericMarkOptions, Mark, MarkType, PlotDefaults, PlotOptions, PlotScales, PlotState, RawValue, ScaleName, ScaleOptions, ScaleType, ScaledChannelName, UsedScales } from '../types/index.js';
1
+ import type { GenericMarkOptions, Mark, MarkType, PlotDefaults, PlotOptions, PlotScales, PlotState, RawValue, ScaleName, ScaleOptions, ScaleType, UsedScales } from '../types/index.js';
2
2
  /**
3
3
  * compute the plot scales
4
4
  */
@@ -8,19 +8,19 @@ export declare function createScale<T extends ScaleOptions>(name: ScaleName, sca
8
8
  domain: number[];
9
9
  range: number[];
10
10
  fn: (() => string) | (() => number);
11
- skip: Map<any, any>;
11
+ skip: any;
12
12
  isDummy: boolean;
13
13
  manualActiveMarks?: undefined;
14
14
  uniqueScaleProps?: undefined;
15
15
  autoTitle?: undefined;
16
16
  } | {
17
17
  type: ScaleType;
18
- domain: RawValue[] | [undefined, undefined];
18
+ domain: any;
19
19
  range: any;
20
20
  fn: any;
21
- skip: Map<ScaledChannelName, Set<symbol>>;
21
+ skip: any;
22
22
  manualActiveMarks: number;
23
- uniqueScaleProps: Set<ChannelAccessor>;
23
+ uniqueScaleProps: any;
24
24
  autoTitle: string | null;
25
25
  isDummy?: undefined;
26
26
  };
@@ -36,8 +36,8 @@ export declare function inferScaleType(name: ScaleName, dataValues: RawValue[],
36
36
  * not. That's what this function is used for.
37
37
  */
38
38
  export declare function getUsedScales(plot: PlotState, options: GenericMarkOptions, mark: Mark<GenericMarkOptions>): UsedScales;
39
- export declare function looksLikeANumber(input: string | number): boolean;
39
+ export declare function looksLikeANumber(input: string | number): any;
40
40
  export declare function projectXY(scales: PlotScales, x: RawValue, y: RawValue, useXScale?: boolean, useYScale?: boolean): [number, number];
41
41
  export declare function projectX(channel: 'x' | 'x1' | 'x2', scales: PlotScales, value: RawValue): number;
42
42
  export declare function projectY(channel: 'y' | 'y1' | 'y2', scales: PlotScales, value: RawValue): number;
43
- export declare function isOrdinalScale(scaleType: ScaleType): scaleType is "ordinal" | "point" | "band" | "categorical" | "threshold";
43
+ export declare function isOrdinalScale(scaleType: ScaleType): scaleType is "point" | "ordinal" | "band" | "categorical" | "threshold";
@@ -1,5 +1,5 @@
1
1
  import { type SymbolType } from 'd3-shape';
2
2
  export declare const sqrt3: number;
3
3
  export declare const sqrt4_3: number;
4
- export declare function isSymbol(value: string | SymbolType): boolean;
5
- export declare function maybeSymbol(symbol: SymbolType | string): SymbolType;
4
+ export declare function isSymbol(value: string | SymbolType): any;
5
+ export declare function maybeSymbol(symbol: SymbolType | string): any;
@@ -1,6 +1,6 @@
1
- export declare const durations: Map<string, number>;
2
- export declare const intervalDuration: unique symbol;
3
- export declare const intervalType: unique symbol;
1
+ export declare const durations: any;
2
+ export declare const intervalDuration: any;
3
+ export declare const intervalType: any;
4
4
  export declare function parseTimeInterval(input: string): [string, number];
5
5
  export declare function maybeTimeInterval(input: string): any;
6
6
  export declare function maybeUtcInterval(input: string): any;
@@ -1,10 +1,10 @@
1
1
  import type { RawValue } from '../types/index.js';
2
- export declare function isBooleanOrNull(v: RawValue): v is boolean;
2
+ export declare function isBooleanOrNull(v: RawValue): boolean;
3
3
  export declare function isDate(v: RawValue): v is Date;
4
- export declare function isDateOrNull(v: RawValue | null | undefined): v is Date | null | undefined;
5
- export declare function isNumberOrNull(v: RawValue | null | undefined): boolean;
6
- export declare function isNumberOrNullOrNaN(v: RawValue | null | undefined): boolean;
7
- export declare function isStringOrNull(v: RawValue | null | undefined): v is string | null | undefined;
8
- export declare function isSymbolOrNull(v: RawValue | null | undefined): boolean;
9
- export declare function isColorOrNull(v: RawValue | null | undefined): boolean;
10
- export declare function isOpacityOrNull(v: RawValue): boolean;
4
+ export declare function isDateOrNull(v: RawValue | null | undefined): boolean;
5
+ export declare function isNumberOrNull(v: RawValue | null | undefined): any;
6
+ export declare function isNumberOrNullOrNaN(v: RawValue | null | undefined): any;
7
+ export declare function isStringOrNull(v: RawValue | null | undefined): boolean;
8
+ export declare function isSymbolOrNull(v: RawValue | null | undefined): any;
9
+ export declare function isColorOrNull(v: RawValue | null | undefined): any;
10
+ export declare function isOpacityOrNull(v: RawValue): any;
@@ -0,0 +1,51 @@
1
+ import type { PlotOptions } from '../types/plot';
2
+ import type { PlotScales, PlotState as TPlotState } from '../types';
3
+ /**
4
+ * Internal state representation of a Plot.
5
+ */
6
+ declare class PlotState implements TPlotState {
7
+ width: number;
8
+ height: number;
9
+ options: PlotOptions;
10
+ facetWidth: number;
11
+ facetHeight: number;
12
+ plotWidth: number;
13
+ plotHeight: number;
14
+ scales: PlotScales;
15
+ body: HTMLDivElement;
16
+ /**
17
+ * True if there's a color scale and a symbol scale and both are bound to the same
18
+ * single channel accessor.
19
+ */
20
+ colorSymbolRedundant: boolean;
21
+ /**
22
+ * True if the plot is using filled dot marks.
23
+ */
24
+ hasFilledDotMarks: boolean;
25
+ css: ((d: string) => string) | null;
26
+ constructor(state: PlotState);
27
+ update(newState: Partial<PlotState>): void;
28
+ get publicState(): PublicPlotState;
29
+ }
30
+ /**
31
+ * A public-facing wrapper around PlotState that exposes only read-only properties.
32
+ */
33
+ declare class PublicPlotState {
34
+ #private;
35
+ constructor(plotState: PlotState);
36
+ get width(): number;
37
+ get height(): number;
38
+ get options(): PlotOptions;
39
+ get scales(): PlotScales;
40
+ get plotWidth(): number;
41
+ get plotHeight(): number;
42
+ get facetWidth(): number;
43
+ get facetHeight(): number;
44
+ get body(): HTMLDivElement;
45
+ get colorSymbolRedundant(): boolean;
46
+ get hasFilledDotMarks(): boolean;
47
+ get css(): ((d: string) => string) | null;
48
+ }
49
+ export declare function setPlot(initialState: PlotState): PlotState;
50
+ export declare function usePlot(): Readonly<TPlotState>;
51
+ export {};
@@ -0,0 +1,90 @@
1
+ import { getContext } from 'svelte';
2
+ /**
3
+ * Internal state representation of a Plot.
4
+ */
5
+ class PlotState {
6
+ // Define properties and methods for PlotState as needed
7
+ width = $state(50);
8
+ height = $state(50);
9
+ options = $state({});
10
+ facetWidth = $state(0);
11
+ facetHeight = $state(0);
12
+ plotWidth = $state(0);
13
+ plotHeight = $state(0);
14
+ scales = $state();
15
+ body = $state();
16
+ /**
17
+ * True if there's a color scale and a symbol scale and both are bound to the same
18
+ * single channel accessor.
19
+ */
20
+ colorSymbolRedundant = $state(false);
21
+ /**
22
+ * True if the plot is using filled dot marks.
23
+ */
24
+ hasFilledDotMarks = $state(false);
25
+ css = $state(null);
26
+ constructor(state) {
27
+ // Initialization code here
28
+ Object.assign(this, state);
29
+ }
30
+ update(newState) {
31
+ Object.assign(this, newState);
32
+ }
33
+ get publicState() {
34
+ return new PublicPlotState(this);
35
+ }
36
+ }
37
+ /**
38
+ * A public-facing wrapper around PlotState that exposes only read-only properties.
39
+ */
40
+ class PublicPlotState {
41
+ #plotState;
42
+ constructor(plotState) {
43
+ this.#plotState = plotState;
44
+ }
45
+ get width() {
46
+ return this.#plotState.width;
47
+ }
48
+ get height() {
49
+ return this.#plotState.height;
50
+ }
51
+ get options() {
52
+ return this.#plotState.options;
53
+ }
54
+ get scales() {
55
+ return this.#plotState.scales;
56
+ }
57
+ get plotWidth() {
58
+ return this.#plotState.plotWidth;
59
+ }
60
+ get plotHeight() {
61
+ return this.#plotState.plotHeight;
62
+ }
63
+ get facetWidth() {
64
+ return this.#plotState.facetWidth;
65
+ }
66
+ get facetHeight() {
67
+ return this.#plotState.facetHeight;
68
+ }
69
+ get body() {
70
+ return this.#plotState.body;
71
+ }
72
+ get colorSymbolRedundant() {
73
+ return this.#plotState.colorSymbolRedundant;
74
+ }
75
+ get hasFilledDotMarks() {
76
+ return this.#plotState.hasFilledDotMarks;
77
+ }
78
+ get css() {
79
+ return this.#plotState.css;
80
+ }
81
+ }
82
+ export function setPlot(initialState) {
83
+ return new PlotState({
84
+ ...initialState
85
+ });
86
+ }
87
+ export function usePlot() {
88
+ const { getPlotState } = getContext('svelteplot');
89
+ return getPlotState().publicState;
90
+ }
package/dist/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './transforms/index.js';
5
5
  export { formatMonth } from './helpers/formats.js';
6
6
  export { default as wordwrap } from './helpers/wordwrap.js';
7
7
  export * from './hooks/plotDefaults.js';
8
+ export { usePlot } from './hooks/usePlot.svelte.js';
package/dist/index.js CHANGED
@@ -7,3 +7,4 @@ export { formatMonth } from './helpers/formats.js';
7
7
  export { default as wordwrap } from './helpers/wordwrap.js';
8
8
  // hooks
9
9
  export * from './hooks/plotDefaults.js';
10
+ export { usePlot } from './hooks/usePlot.svelte.js';
@@ -19,7 +19,6 @@
19
19
 
20
20
  import Mark from '../Mark.svelte';
21
21
  import GroupMultiple from './helpers/GroupMultiple.svelte';
22
- import { getContext } from 'svelte';
23
22
  import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
24
23
  import { groups as d3Groups } from 'd3-array';
25
24
  import { area, type CurveFactory } from 'd3-shape';
@@ -31,7 +30,6 @@
31
30
 
32
31
  import type {
33
32
  CurveName,
34
- PlotContext,
35
33
  DataRecord,
36
34
  BaseMarkProps,
37
35
  ConstantAccessor,
@@ -43,6 +41,7 @@
43
41
  import type { StackOptions } from '../transforms/stack.js';
44
42
  import { addEventHandlers } from './helpers/events';
45
43
  import { getPlotDefaults } from '../hooks/plotDefaults.js';
44
+ import { usePlot } from '../hooks/usePlot.svelte.js';
46
45
 
47
46
  let markProps: AreaMarkProps = $props();
48
47
 
@@ -64,8 +63,7 @@
64
63
  ...options
65
64
  }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
66
65
 
67
- const { getPlotState } = getContext<PlotContext>('svelteplot');
68
- const plot = $derived(getPlotState());
66
+ const plot = usePlot();
69
67
 
70
68
  const groupByKey = $derived(options.z || options.fill || options.stroke);
71
69
 
@@ -144,7 +142,7 @@
144
142
  clip-path={options.clipPath}
145
143
  d={areaPath(areaData)}
146
144
  {@attach addEventHandlers({
147
- getPlotState,
145
+ plot,
148
146
  options,
149
147
  datum: datum?.datum
150
148
  })}
@@ -1,4 +1,5 @@
1
1
  import { type CurveFactory } from 'd3-shape';
2
+ import callWithProps from '../helpers/callWithProps.js';
2
3
  import type { CurveName, DataRecord, ConstantAccessor, ChannelAccessor, LinkableMarkProps, RawValue } from '../types/index.js';
3
4
  import type { StackOptions } from '../transforms/stack.js';
4
5
  declare function $$render<Datum extends DataRecord>(): {
@@ -9,14 +10,14 @@ declare function $$render<Datum extends DataRecord>(): {
9
10
  fy: ChannelAccessor<Datum>;
10
11
  dx: ConstantAccessor<number, Datum>;
11
12
  dy: ConstantAccessor<number, Datum>;
12
- dodgeX: import("../transforms/dodge").DodgeXOptions;
13
- dodgeY: import("../transforms/dodge").DodgeYOptions;
13
+ dodgeX: callWithProps;
14
+ dodgeY: callWithProps;
14
15
  fill: ChannelAccessor<Datum>;
15
16
  fillOpacity: ConstantAccessor<number, Datum>;
16
- sort: ((a: RawValue, b: RawValue) => number) | {
17
+ sort: {
17
18
  channel: string;
18
19
  order?: "ascending" | "descending";
19
- } | ConstantAccessor<RawValue, Datum>;
20
+ } | ((a: RawValue, b: RawValue) => number) | ConstantAccessor<RawValue, Datum>;
20
21
  stroke: ChannelAccessor<Datum>;
21
22
  strokeWidth: ConstantAccessor<number, Datum>;
22
23
  strokeOpacity: ConstantAccessor<number, Datum>;
@@ -28,6 +29,7 @@ declare function $$render<Datum extends DataRecord>(): {
28
29
  strokeDashoffset: ConstantAccessor<number, Datum>;
29
30
  mixBlendMode: ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
30
31
  clipPath: string;
32
+ mask: string;
31
33
  imageFilter: ConstantAccessor<string, Datum>;
32
34
  shapeRendering: ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
33
35
  paintOrder: ConstantAccessor<string, Datum>;
@@ -1,3 +1,4 @@
1
+ import { renameChannels } from '../transforms/rename.js';
1
2
  import type { ChannelAccessor, DataRow } from '../types/index.js';
2
3
  declare function $$render<Datum extends DataRow>(): {
3
4
  props: Omit<Partial<{
@@ -7,14 +8,14 @@ declare function $$render<Datum extends DataRow>(): {
7
8
  fy: ChannelAccessor<Record<string | symbol, import("../types/data").RawValue>>;
8
9
  dx: import("../types/index.js").ConstantAccessor<number, Record<string | symbol, import("../types/data").RawValue>>;
9
10
  dy: import("../types/index.js").ConstantAccessor<number, Record<string | symbol, import("../types/data").RawValue>>;
10
- dodgeX: import("../transforms/dodge").DodgeXOptions;
11
- dodgeY: import("../transforms/dodge").DodgeYOptions;
11
+ dodgeX: renameChannels;
12
+ dodgeY: renameChannels;
12
13
  fill: ChannelAccessor<Record<string | symbol, import("../types/data").RawValue>>;
13
14
  fillOpacity: import("../types/index.js").ConstantAccessor<number, Record<string | symbol, import("../types/data").RawValue>>;
14
- sort: ((a: import("../types/data").RawValue, b: import("../types/data").RawValue) => number) | {
15
+ sort: {
15
16
  channel: string;
16
17
  order?: "ascending" | "descending";
17
- } | import("../types/index.js").ConstantAccessor<import("../types/data").RawValue, Record<string | symbol, import("../types/data").RawValue>>;
18
+ } | ((a: import("../types/data").RawValue, b: import("../types/data").RawValue) => number) | import("../types/index.js").ConstantAccessor<import("../types/data").RawValue, Record<string | symbol, import("../types/data").RawValue>>;
18
19
  stroke: ChannelAccessor<Record<string | symbol, import("../types/data").RawValue>>;
19
20
  strokeWidth: import("../types/index.js").ConstantAccessor<number, Record<string | symbol, import("../types/data").RawValue>>;
20
21
  strokeOpacity: import("../types/index.js").ConstantAccessor<number, Record<string | symbol, import("../types/data").RawValue>>;
@@ -26,6 +27,7 @@ declare function $$render<Datum extends DataRow>(): {
26
27
  strokeDashoffset: import("../types/index.js").ConstantAccessor<number, Record<string | symbol, import("../types/data").RawValue>>;
27
28
  mixBlendMode: import("../types/index.js").ConstantAccessor<import("csstype").Property.MixBlendMode, Record<string | symbol, import("../types/data").RawValue>>;
28
29
  clipPath: string;
30
+ mask: string;
29
31
  imageFilter: import("../types/index.js").ConstantAccessor<string, Record<string | symbol, import("../types/data").RawValue>>;
30
32
  shapeRendering: import("../types/index.js").ConstantAccessor<import("csstype").Property.ShapeRendering, Record<string | symbol, import("../types/data").RawValue>>;
31
33
  paintOrder: import("../types/index.js").ConstantAccessor<string, Record<string | symbol, import("../types/data").RawValue>>;
@@ -74,7 +76,7 @@ declare function $$render<Datum extends DataRow>(): {
74
76
  sort?: import("../types/index.js").ConstantAccessor<import("../types/data").RawValue> | {
75
77
  channel: "stroke" | "fill";
76
78
  };
77
- stack?: Partial<import("../transforms/stack.js").StackOptions>;
79
+ stack?: Partial<renameChannels>;
78
80
  canvas?: boolean;
79
81
  areaClass?: import("../types/index.js").ConstantAccessor<string, Record<string | symbol, import("../types/data").RawValue>>;
80
82
  }, "y1" | "y2"> & {