svelteplot 0.7.0-pr-276.0 → 0.7.0-pr-277.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.
@@ -3,7 +3,7 @@ export { bollingerX, bollingerY } from './bollinger.js';
3
3
  export { geoCentroid } from './centroid.js';
4
4
  export { filter } from './filter.js';
5
5
  export { map, mapX, mapY } from './map.js';
6
- export { normalizeX, normalizeY } from './normalize.js';
6
+ export { normalizeX, normalizeY, normalizeParallelX, normalizeParallelY } from './normalize.js';
7
7
  export { group, groupX, groupY, groupZ } from './group.js';
8
8
  export { intervalX, intervalY } from './interval.js';
9
9
  export { jitterX, jitterY } from './jitter.js';
@@ -3,7 +3,7 @@ export { bollingerX, bollingerY } from './bollinger.js';
3
3
  export { geoCentroid } from './centroid.js';
4
4
  export { filter } from './filter.js';
5
5
  export { map, mapX, mapY } from './map.js';
6
- export { normalizeX, normalizeY } from './normalize.js';
6
+ export { normalizeX, normalizeY, normalizeParallelX, normalizeParallelY } from './normalize.js';
7
7
  export { group, groupX, groupY, groupZ } from './group.js';
8
8
  export { intervalX, intervalY } from './interval.js';
9
9
  export { jitterX, jitterY } from './jitter.js';
@@ -2,4 +2,22 @@ import type { TransformArg, MapIndexObject } from '../types/index.js';
2
2
  type NormalizeBasis = 'deviation' | 'first' | 'last' | 'min' | 'max' | 'mean' | 'median' | 'sum' | 'extent' | MapIndexObject;
3
3
  export declare function normalizeX<T>(args: TransformArg<T>, basis: NormalizeBasis): any;
4
4
  export declare function normalizeY<T>(args: TransformArg<T>, basis: NormalizeBasis): any;
5
+ /**
6
+ * Convenience wrapper for normalizeY for parallel coordinates.
7
+ *
8
+ * Channels:
9
+ * - x: the categorical axis (e.g., 'Measurement')
10
+ * - y: the value to normalize (e.g., 'Value')
11
+ * - z: the grouping variable (e.g., 'Id')
12
+ */
13
+ export declare function normalizeParallelY<T>(args: TransformArg<T>, basis: NormalizeBasis): any;
14
+ /**
15
+ * Convenience wrapper for normalizeY for parallel coordinates.
16
+ *
17
+ * Channels:
18
+ * - x: the categorical axis (e.g., 'Measurement')
19
+ * - y: the value to normalize (e.g., 'Value')
20
+ * - z: the grouping variable (e.g., 'Id')
21
+ */
22
+ export declare function normalizeParallelX<T>(args: TransformArg<T>, basis: NormalizeBasis): any;
5
23
  export {};
@@ -1,5 +1,6 @@
1
1
  import { mapX, mapY } from './map.js';
2
2
  import { min, max, mean, median, sum, deviation, extent } from 'd3-array';
3
+ import { sort } from './sort.js';
3
4
  export function normalizeX(args, basis) {
4
5
  return mapX(args, normalize(basis));
5
6
  }
@@ -84,3 +85,47 @@ const normalizeMean = normalizeAccessor(mean);
84
85
  const normalizeMedian = normalizeAccessor(median);
85
86
  const normalizeMin = normalizeAccessor(min);
86
87
  const normalizeSum = normalizeAccessor(sum);
88
+ /**
89
+ * Convenience wrapper for normalizeY for parallel coordinates.
90
+ *
91
+ * Channels:
92
+ * - x: the categorical axis (e.g., 'Measurement')
93
+ * - y: the value to normalize (e.g., 'Value')
94
+ * - z: the grouping variable (e.g., 'Id')
95
+ */
96
+ export function normalizeParallelY(args, basis) {
97
+ return sort({
98
+ ...normalizeY({
99
+ ...args,
100
+ // use x as the grouping variable for normalization to normalize
101
+ // each axis independently
102
+ z: args.x
103
+ }, basis),
104
+ // restore original grouping by line
105
+ z: args.z,
106
+ // sort by original order
107
+ sort: args.z
108
+ });
109
+ }
110
+ /**
111
+ * Convenience wrapper for normalizeY for parallel coordinates.
112
+ *
113
+ * Channels:
114
+ * - x: the categorical axis (e.g., 'Measurement')
115
+ * - y: the value to normalize (e.g., 'Value')
116
+ * - z: the grouping variable (e.g., 'Id')
117
+ */
118
+ export function normalizeParallelX(args, basis) {
119
+ return sort({
120
+ ...normalizeX({
121
+ ...args,
122
+ // use x as the grouping variable for normalization to normalize
123
+ // each axis independently
124
+ z: args.y
125
+ }, basis),
126
+ // restore original grouping by line
127
+ z: args.z,
128
+ // sort by original order
129
+ sort: args.z
130
+ });
131
+ }
@@ -1,14 +1,30 @@
1
1
  <script>
2
2
  import { resolve } from '$app/paths';
3
+ import { useDark } from './isDark.svelte';
3
4
  let { examples } = $props();
5
+
6
+ const exampleImages = import.meta.glob('../../snapshots/*/*.png', {
7
+ eager: true,
8
+ query: {
9
+ enhanced: true,
10
+ w: 640
11
+ }
12
+ });
13
+
14
+ const ds = useDark();
4
15
  </script>
5
16
 
6
17
  <div class="list">
7
18
  {#each examples as page, i (i)}
8
19
  <a href={resolve(page.url)}>
9
20
  <div>
10
- {#if page.screenshot}
11
- <img src={page.screenshot} alt={page.title} />{/if}
21
+ {#if exampleImages[`../../snapshots/${page.key}.png`]}
22
+ <enhanced:img
23
+ src={ds.isDark
24
+ ? exampleImages[`../../snapshots/${page.key}.dark.png`].default.img.src
25
+ : exampleImages[`../../snapshots/${page.key}.png`].default.img.src}
26
+ alt={page.title} />
27
+ {/if}
12
28
  </div>
13
29
  <h4>
14
30
  {page.title}
@@ -49,7 +65,7 @@
49
65
  }
50
66
  }
51
67
 
52
- .list img {
68
+ .list :global(img) {
53
69
  width: 100%;
54
70
  box-sizing: border-box;
55
71
  border-radius: 3px;
@@ -1,7 +1,8 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
+ import { useDark } from './isDark.svelte';
3
4
 
4
- const exampleImages = import.meta.glob('../../../static/examples/*/*.png', {
5
+ const exampleImages = import.meta.glob('../../snapshots/*/*.png', {
5
6
  eager: true,
6
7
  query: {
7
8
  enhanced: true,
@@ -11,8 +12,7 @@
11
12
 
12
13
  let {
13
14
  paths,
14
- pages,
15
- isDark
15
+ pages
16
16
  }: {
17
17
  paths: Record<string, string[]>;
18
18
  pages: Record<
@@ -24,9 +24,10 @@
24
24
  transforms?: string[];
25
25
  }
26
26
  >;
27
- isDark: boolean;
28
27
  } = $props();
29
28
 
29
+ const ds = useDark();
30
+
30
31
  function sortPages(a: string, b: string) {
31
32
  const sortA = pages[a].sortKey ?? 10;
32
33
  const sortB = pages[b].sortKey ?? 10;
@@ -53,9 +54,9 @@
53
54
  <enhanced:img
54
55
  title={pages[page].title}
55
56
  src={exampleImages[
56
- `../../../static/examples/${page
57
+ `../../snapshots/${page
57
58
  .replace('./', '')
58
- .replace('.svelte', isDark ? '.dark.png' : '.png')}`
59
+ .replace('.svelte', ds.isDark ? '.dark.png' : '.png')}`
59
60
  ].default}
60
61
  alt={pages[page].title} />
61
62
  <div class="title">{pages[page].title}</div>
@@ -6,7 +6,6 @@ type $$ComponentProps = {
6
6
  sortKey?: number;
7
7
  transforms?: string[];
8
8
  }>;
9
- isDark: boolean;
10
9
  };
11
10
  declare const ExamplesPagePreview: import("svelte").Component<$$ComponentProps, {}, "">;
12
11
  type ExamplesPagePreview = ReturnType<typeof ExamplesPagePreview>;
@@ -0,0 +1,6 @@
1
+ declare class DarkState {
2
+ isDark: boolean;
3
+ constructor();
4
+ }
5
+ export declare function useDark(): DarkState;
6
+ export {};
@@ -0,0 +1,10 @@
1
+ class DarkState {
2
+ isDark = $state(false);
3
+ constructor() {
4
+ this.isDark = false;
5
+ }
6
+ }
7
+ const darkState = new DarkState();
8
+ export function useDark() {
9
+ return darkState;
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.7.0-pr-276.0",
3
+ "version": "0.7.0-pr-277.0",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",