svelteplot 0.1.3-next.14 → 0.1.3-next.17

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,6 +1,7 @@
1
1
  # SveltePlot
2
2
 
3
+ ![Tests](https://github.com/svelteplot/svelteplot/actions/workflows/test.yml/badge.svg)
4
+
3
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.
4
6
 
5
7
  <img src="static/logo.png" alt="SveltePlot logo" width="400" />
6
-
package/dist/Mark.svelte CHANGED
@@ -227,7 +227,12 @@
227
227
  );
228
228
  out[`x${suffix}`] = x;
229
229
  out[`y${suffix}`] = y;
230
- out.valid = out.valid && isValid(row.x) && isValid(row.y);
230
+ out.valid =
231
+ out.valid &&
232
+ isValid(row.x) &&
233
+ isValid(row.y) &&
234
+ isValid(x) &&
235
+ isValid(y);
231
236
  }
232
237
  }
233
238
  }
@@ -9,15 +9,9 @@
9
9
  FacetContext,
10
10
  PlotDefaults
11
11
  } from '../types.js';
12
- import {
13
- resolveChannel,
14
- resolveProp,
15
- resolveScaledStyles,
16
- resolveStyles
17
- } from '../helpers/resolve.js';
12
+ import { resolveProp, resolveStyles } from '../helpers/resolve.js';
18
13
  import { maybeSymbol } from '../helpers/symbols.js';
19
14
  import { symbol as d3Symbol } from 'd3-shape';
20
- import { projectXY } from '../helpers/scales.js';
21
15
  import { sort } from '../index.js';
22
16
  import Mark from '../Mark.svelte';
23
17
  import DotCanvas from './helpers/DotCanvas.svelte';
@@ -36,14 +30,14 @@
36
30
  children?: Snippet;
37
31
  dx?: ConstantAccessor<number>;
38
32
  dy?: ConstantAccessor<number>;
39
- canvas: boolean;
40
- dotClass: ConstantAccessor<string>;
41
- in: any;
42
- inParams: any;
43
- out: any;
44
- outParams: any;
45
- transition: any;
46
- wrap: Snippet;
33
+ canvas?: boolean;
34
+ dotClass?: ConstantAccessor<string>;
35
+ in?: any;
36
+ inParams?: any;
37
+ out?: any;
38
+ outParams?: any;
39
+ transition?: any;
40
+ wrap?: Snippet;
47
41
  };
48
42
 
49
43
  let {
@@ -132,6 +126,3 @@
132
126
  </g>
133
127
  {/snippet}
134
128
  </Mark>
135
-
136
- <style>
137
- </style>
@@ -11,14 +11,14 @@ type DotProps = BaseMarkProps & {
11
11
  children?: Snippet;
12
12
  dx?: ConstantAccessor<number>;
13
13
  dy?: ConstantAccessor<number>;
14
- canvas: boolean;
15
- dotClass: ConstantAccessor<string>;
16
- in: any;
17
- inParams: any;
18
- out: any;
19
- outParams: any;
20
- transition: any;
21
- wrap: Snippet;
14
+ canvas?: boolean;
15
+ dotClass?: ConstantAccessor<string>;
16
+ in?: any;
17
+ inParams?: any;
18
+ out?: any;
19
+ outParams?: any;
20
+ transition?: any;
21
+ wrap?: Snippet;
22
22
  };
23
23
  declare const Dot: import("svelte").Component<DotProps, {}, "">;
24
24
  type Dot = ReturnType<typeof Dot>;
@@ -2,10 +2,10 @@
2
2
  import { getContext } from 'svelte';
3
3
  import Mark from '../Mark.svelte';
4
4
  import type { PlotContext, BaseMarkProps, RawValue } from '../types.js';
5
- import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
5
+ import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
6
6
  import { autoTicks } from '../helpers/autoTicks.js';
7
- import { getUsedScales } from '../helpers/scales.js';
8
7
  import { testFilter } from '../helpers/index.js';
8
+ import { RAW_VALUE } from '../transforms/recordize.js';
9
9
 
10
10
  type GrixXMarkProps = BaseMarkProps & {
11
11
  data?: RawValue[];
@@ -15,13 +15,13 @@
15
15
  let { data = [], automatic = false, ...options }: GrixXMarkProps = $props();
16
16
 
17
17
  const { getPlotState } = getContext<PlotContext>('svelteplot');
18
- let plot = $derived(getPlotState());
18
+ const plot = $derived(getPlotState());
19
19
 
20
- let autoTickCount = $derived(
20
+ const autoTickCount = $derived(
21
21
  Math.max(3, Math.round(plot.facetWidth / plot.options.x.tickSpacing))
22
22
  );
23
23
 
24
- let ticks: RawValue[] = $derived(
24
+ const ticks: RawValue[] = $derived(
25
25
  data.length > 0
26
26
  ? // use custom tick values if user passed any as prop
27
27
  data
@@ -54,9 +54,18 @@
54
54
  {@const y2_ = resolveChannel('y2', tick, options)}
55
55
  {@const y1 = options.y1 != null ? plot.scales.y.fn(y1_) : 0}
56
56
  {@const y2 = options.y2 != null ? plot.scales.y.fn(y2_) : plot.facetHeight}
57
+ {@const [style, styleClass] = resolveStyles(
58
+ plot,
59
+ { datum: { [RAW_VALUE]: tick } },
60
+ options,
61
+ 'stroke',
62
+ usedScales,
63
+ true
64
+ )}
57
65
  <line
66
+ class={styleClass}
58
67
  transform="translate({x},{plot.options.marginTop})"
59
- style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
68
+ {style}
60
69
  {y1}
61
70
  {y2} />
62
71
  {/if}
@@ -2,23 +2,23 @@
2
2
  import { getContext } from 'svelte';
3
3
  import Mark from '../Mark.svelte';
4
4
  import type { PlotContext, BaseMarkProps, RawValue, DataRecord } from '../types.js';
5
- import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
5
+ import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
6
6
  import { autoTicks } from '../helpers/autoTicks.js';
7
- import { getUsedScales } from '../helpers/scales.js';
8
7
  import { testFilter } from '../helpers/index.js';
8
+ import { RAW_VALUE } from '../transforms/recordize.js';
9
9
 
10
10
  type GridYMarkProps = BaseMarkProps & { data?: RawValue[]; automatic?: boolean };
11
11
 
12
12
  let { data = [], automatic = false, ...options }: GridYMarkProps = $props();
13
13
 
14
14
  const { getPlotState } = getContext<PlotContext>('svelteplot');
15
- let plot = $derived(getPlotState());
15
+ const plot = $derived(getPlotState());
16
16
 
17
- let autoTickCount = $derived(
17
+ const autoTickCount = $derived(
18
18
  Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
19
19
  );
20
20
 
21
- let ticks: RawValue[] = $derived(
21
+ const ticks: RawValue[] = $derived(
22
22
  data.length > 0
23
23
  ? // use custom tick values if user passed any as prop
24
24
  data
@@ -51,9 +51,18 @@
51
51
  {@const x2_ = resolveChannel('x2', tick, options)}
52
52
  {@const x1 = options.x1 != null ? plot.scales.x.fn(x1_) : 0}
53
53
  {@const x2 = options.x2 != null ? plot.scales.x.fn(x2_) : plot.facetWidth}
54
+ {@const [style, styleClass] = resolveStyles(
55
+ plot,
56
+ { datum: { [RAW_VALUE]: tick } },
57
+ options,
58
+ 'stroke',
59
+ usedScales,
60
+ true
61
+ )}
54
62
  <line
63
+ {style}
64
+ class={styleClass}
55
65
  transform="translate({plot.options.marginLeft},{y})"
56
- style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
57
66
  {x1}
58
67
  {x2} />
59
68
  {/if}
@@ -10,12 +10,12 @@
10
10
  /**
11
11
  * maximum cursor distance to select data points
12
12
  */
13
- maxDistance: number;
13
+ maxDistance?: number;
14
14
  /**
15
15
  * called whenever the selection changes
16
16
  * @param data
17
17
  */
18
- onupdate: (data: DataRow[]) => void;
18
+ onupdate?: (data: DataRow[]) => void;
19
19
  };
20
20
  </script>
21
21
 
@@ -10,12 +10,12 @@ export type PointerMarkProps = {
10
10
  /**
11
11
  * maximum cursor distance to select data points
12
12
  */
13
- maxDistance: number;
13
+ maxDistance?: number;
14
14
  /**
15
15
  * called whenever the selection changes
16
16
  * @param data
17
17
  */
18
- onupdate: (data: DataRow[]) => void;
18
+ onupdate?: (data: DataRow[]) => void;
19
19
  };
20
20
  import { type Snippet } from 'svelte';
21
21
  declare const Pointer: import("svelte").Component<PointerMarkProps, {}, "">;
@@ -22,11 +22,11 @@
22
22
  dx?: ConstantAccessor<number>;
23
23
  dy?: ConstantAccessor<number>;
24
24
  text: ConstantAccessor<string>;
25
- title: ConstantAccessor<string>;
25
+ title?: ConstantAccessor<string>;
26
26
  /**
27
27
  * if you want to apply class names to individual text elements
28
28
  */
29
- textClass: ConstantAccessor<string>;
29
+ textClass?: ConstantAccessor<string>;
30
30
  /**
31
31
  * the line anchor for vertical position; top, bottom, or middle
32
32
  */
@@ -10,11 +10,11 @@ type TextMarkProps = BaseMarkProps & {
10
10
  dx?: ConstantAccessor<number>;
11
11
  dy?: ConstantAccessor<number>;
12
12
  text: ConstantAccessor<string>;
13
- title: ConstantAccessor<string>;
13
+ title?: ConstantAccessor<string>;
14
14
  /**
15
15
  * if you want to apply class names to individual text elements
16
16
  */
17
- textClass: ConstantAccessor<string>;
17
+ textClass?: ConstantAccessor<string>;
18
18
  /**
19
19
  * the line anchor for vertical position; top, bottom, or middle
20
20
  */
@@ -1,7 +1,7 @@
1
1
  import type { DataRecord, RawValue } from '../types.js';
2
2
  import type { TransformArg } from '../types.js';
3
3
  import { type ThresholdCountGenerator } from 'd3-array';
4
- import { Reducer, type ReducerName } from '../helpers/reduce.js';
4
+ import { type ReducerName } from '../helpers/reduce.js';
5
5
  type NamedThresholdsGenerator = 'auto' | 'scott' | 'sturges' | 'freedman-diaconis';
6
6
  type BinBaseOptions = {
7
7
  domain?: [number, number];
@@ -20,14 +20,14 @@ type AdditionalOutputChannels = Partial<{
20
20
  strokeOpacity: ReducerOption;
21
21
  }>;
22
22
  export type BinXOptions = BinBaseOptions & AdditionalOutputChannels & Partial<{
23
- y: typeof Reducer;
24
- y1: typeof Reducer;
25
- y2: typeof Reducer;
23
+ y: ReducerOption;
24
+ y1: ReducerOption;
25
+ y2: ReducerOption;
26
26
  }>;
27
27
  export type BinYOptions = BinBaseOptions & AdditionalOutputChannels & Partial<{
28
- x: typeof Reducer;
29
- x1: typeof Reducer;
30
- x2: typeof Reducer;
28
+ x: ReducerOption;
29
+ x1: ReducerOption;
30
+ x2: ReducerOption;
31
31
  }>;
32
32
  type BinOptions = BinBaseOptions & AdditionalOutputChannels;
33
33
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.1.3-next.14",
3
+ "version": "0.1.3-next.17",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",