svelteplot 0.2.8 → 0.2.9-pr-95.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.
@@ -33,6 +33,7 @@
33
33
  dy: ConstantAccessor<number>;
34
34
  filter: ChannelAccessor;
35
35
  };
36
+ text: boolean;
36
37
  plot: PlotState;
37
38
  };
38
39
 
@@ -50,7 +51,8 @@
50
51
  height,
51
52
  options,
52
53
  plot,
53
- title
54
+ title,
55
+ text = true
54
56
  }: BaseAxisXProps = $props();
55
57
 
56
58
  function splitTick(tick: string | string[]) {
@@ -86,15 +88,17 @@
86
88
  })
87
89
  );
88
90
  const T = tickObjects.length;
89
- for (let i = 0; i < T; i++) {
90
- let j = i;
91
- // find the preceding tick that was not hidden
92
- do {
93
- j--;
94
- } while (j >= 0 && tickObjects[j].hidden);
95
- if (j >= 0) {
96
- const tickLabelSpace = Math.abs(tickObjects[i].x - tickObjects[j].x);
97
- tickObjects[i].hidden = tickLabelSpace < 15;
91
+ if (text) {
92
+ for (let i = 0; i < T; i++) {
93
+ let j = i;
94
+ // find the preceding tick that was not hidden
95
+ do {
96
+ j--;
97
+ } while (j >= 0 && tickObjects[j].hidden);
98
+ if (j >= 0) {
99
+ const tickLabelSpace = Math.abs(tickObjects[i].x - tickObjects[j].x);
100
+ tickObjects[i].hidden = tickLabelSpace < 15;
101
+ }
98
102
  }
99
103
  }
100
104
  return tickObjects;
@@ -102,6 +106,7 @@
102
106
 
103
107
  $effect(() => {
104
108
  untrack(() => [$autoMarginTop, $autoMarginBottom]);
109
+ if (!text) return;
105
110
  const outsideTextAnchor = anchor === 'top' ? 'end' : 'start';
106
111
  // measure tick label heights
107
112
  const maxLabelHeight =
@@ -144,26 +149,7 @@
144
149
  <g class="axis-x">
145
150
  {#each positionedTicks as tick, t (t)}
146
151
  {#if testFilter(tick.value, options) && !tick.hidden}
147
- {@const textLines = tick.text}
148
- {@const prevTextLines = t && positionedTicks[t - 1].text}
149
- {@const fontSize = resolveProp(tickFontSize, tick)}
150
152
  {@const tickClass_ = resolveProp(tickClass, tick.value)}
151
- {@const estLabelWidth = max(textLines.map((t) => t.length)) * fontSize * 0.2}
152
- {@const moveDown =
153
- (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize * 0.35 : 0)) *
154
- (anchor === 'bottom' ? 1 : -1)}
155
- {@const [textStyle, textClass] = resolveStyles(
156
- plot,
157
- tick,
158
- {
159
- fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
160
- ...options,
161
- fontSize: tickFontSize,
162
- stroke: null
163
- },
164
- 'fill',
165
- { x: true }
166
- )}
167
153
  <g
168
154
  class="tick {tickClass_ || ''}"
169
155
  transform="translate({tick.x + tick.dx}, {tickY + tick.dy})"
@@ -182,31 +168,51 @@
182
168
  y2={anchor === 'bottom' ? tickSize : -tickSize} />
183
169
  {/if}
184
170
 
185
- <text
186
- bind:this={tickTextElements[t]}
187
- transform="translate(0, {moveDown}) rotate({tickRotate})"
188
- style={textStyle}
189
- class={textClass}
190
- x={0}
191
- y={0}
192
- dominant-baseline={tickRotate !== 0
193
- ? 'central'
194
- : anchor === 'bottom'
195
- ? 'hanging'
196
- : 'auto'}>
197
- {#if ticks.length > 0 || t === 0 || t === ticks.length - 1}
198
- {#if textLines.length === 1}
199
- {textLines[0]}
200
- {:else}
201
- {#each textLines as line, i (i)}
202
- <tspan x="0" dy={i ? 12 : 0}
203
- >{!prevTextLines || prevTextLines[i] !== line
204
- ? line
205
- : ''}</tspan>
206
- {/each}
171
+ {#if text}
172
+ {@const textLines = tick.text}
173
+ {@const prevTextLines = t && positionedTicks[t - 1].text}
174
+
175
+ {@const moveDown =
176
+ (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize * 0.35 : 0)) *
177
+ (anchor === 'bottom' ? 1 : -1)}
178
+ {@const [textStyle, textClass] = resolveStyles(
179
+ plot,
180
+ tick,
181
+ {
182
+ fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
183
+ ...options,
184
+ fontSize: tickFontSize,
185
+ stroke: null
186
+ },
187
+ 'fill',
188
+ { x: true }
189
+ )}
190
+ <text
191
+ bind:this={tickTextElements[t]}
192
+ transform="translate(0, {moveDown}) rotate({tickRotate})"
193
+ style={textStyle}
194
+ class={textClass}
195
+ x={0}
196
+ y={0}
197
+ dominant-baseline={tickRotate !== 0
198
+ ? 'central'
199
+ : anchor === 'bottom'
200
+ ? 'hanging'
201
+ : 'auto'}>
202
+ {#if ticks.length > 0 || t === 0 || t === ticks.length - 1}
203
+ {#if textLines.length === 1}
204
+ {textLines[0]}
205
+ {:else}
206
+ {#each textLines as line, i (i)}
207
+ <tspan x="0" dy={i ? 12 : 0}
208
+ >{!prevTextLines || prevTextLines[i] !== line
209
+ ? line
210
+ : ''}</tspan>
211
+ {/each}
212
+ {/if}
207
213
  {/if}
208
- {/if}
209
- </text>
214
+ </text>
215
+ {/if}
210
216
  </g>
211
217
  {/if}
212
218
  {/each}
@@ -17,6 +17,7 @@ type BaseAxisXProps = {
17
17
  dy: ConstantAccessor<number>;
18
18
  filter: ChannelAccessor;
19
19
  };
20
+ text: boolean;
20
21
  plot: PlotState;
21
22
  };
22
23
  declare const BaseAxisX: import("svelte").Component<BaseAxisXProps, {}, "">;
@@ -29,6 +29,7 @@
29
29
  dy: ConstantAccessor<number>;
30
30
  };
31
31
  plot: PlotState;
32
+ text: boolean | null;
32
33
  };
33
34
 
34
35
  let {
@@ -46,7 +47,8 @@
46
47
  width,
47
48
  title,
48
49
  plot,
49
- options
50
+ options,
51
+ text = true
50
52
  }: BaseAxisYProps = $props();
51
53
 
52
54
  const LINE_ANCHOR = {
@@ -67,16 +69,18 @@
67
69
  element: null as SVGTextElement | null
68
70
  };
69
71
  });
70
- const T = tickObjects.length;
71
- for (let i = 0; i < T; i++) {
72
- let j = i;
73
- // find the preceding tick that was not hidden
74
- do {
75
- j--;
76
- } while (j >= 0 && tickObjects[j].hidden);
77
- if (j >= 0) {
78
- const tickLabelSpace = Math.abs(tickObjects[i].y - tickObjects[j].y);
79
- tickObjects[i].hidden = tickLabelSpace < 15;
72
+ if (text) {
73
+ const T = tickObjects.length;
74
+ for (let i = 0; i < T; i++) {
75
+ let j = i;
76
+ // find the preceding tick that was not hidden
77
+ do {
78
+ j--;
79
+ } while (j >= 0 && tickObjects[j].hidden);
80
+ if (j >= 0) {
81
+ const tickLabelSpace = Math.abs(tickObjects[i].y - tickObjects[j].y);
82
+ tickObjects[i].hidden = tickLabelSpace < 15;
83
+ }
80
84
  }
81
85
  }
82
86
  return tickObjects;
@@ -176,13 +180,15 @@
176
180
  class={tickLineClass}
177
181
  x2={anchor === 'left' ? -tickSize : tickSize} />
178
182
  {/if}
179
- <text
180
- bind:this={tickTexts[t]}
181
- class={[textClass, { 'is-left': anchor === 'left' }]}
182
- style={textStyle}
183
- x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
184
- dominant-baseline={LINE_ANCHOR[lineAnchor]}
185
- >{Array.isArray(tick.text) ? tick.text.join(' ') : tick.text}</text>
183
+ {#if text}
184
+ <text
185
+ bind:this={tickTexts[t]}
186
+ class={[textClass, { 'is-left': anchor === 'left' }]}
187
+ style={textStyle}
188
+ x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
189
+ dominant-baseline={LINE_ANCHOR[lineAnchor]}
190
+ >{Array.isArray(tick.text) ? tick.text.join(' ') : tick.text}</text>
191
+ {/if}
186
192
  </g>
187
193
  {/if}
188
194
  {/each}
@@ -17,6 +17,7 @@ type BaseAxisYProps = {
17
17
  dy: ConstantAccessor<number>;
18
18
  };
19
19
  plot: PlotState;
20
+ text: boolean | null;
20
21
  };
21
22
  declare const BaseAxisY: import("svelte").Component<BaseAxisYProps, {}, "">;
22
23
  type BaseAxisY = ReturnType<typeof BaseAxisY>;
@@ -1,44 +1,4 @@
1
- import { type MarkerShape } from './Marker.svelte';
2
- import type { BaseMarkProps, ConstantAccessor, DataRecord, Mark, PlotScales } from '../../types.js';
3
- type MarkerPathProps = BaseMarkProps & {
4
- /**
5
- * the datum associated with this path, usually the first
6
- * element of the data array group
7
- */
8
- datum: DataRecord;
9
- /**
10
- * the marker shape to use at the start of the path, defaults to
11
- * circle
12
- */
13
- markerStart?: boolean | MarkerShape;
14
- /**
15
- * the marker shape to use at the middle of the path, defaults to circle
16
- */
17
- markerMid?: boolean | MarkerShape;
18
- /**
19
- * the marker shape to use at the end of the path, defaults to circle
20
- */
21
- markerEnd?: boolean | MarkerShape;
22
- /**
23
- * shorthand for setting all markers
24
- */
25
- marker?: boolean | MarkerShape;
26
- /**
27
- * path string
28
- */
29
- d: string;
30
- style: string;
31
- startOffset: string;
32
- textStyle: string;
33
- textStyleClass?: string | null;
34
- text: string;
35
- transform: string;
36
- color: string;
37
- strokeWidth: ConstantAccessor<number>;
38
- mark: Mark<BaseMarkProps>;
39
- scales: PlotScales;
40
- };
41
1
  /** Helper component for paths with markers and optional text along the path. */
42
- declare const MarkerPath: import("svelte").Component<MarkerPathProps, {}, "">;
2
+ declare const MarkerPath: import("svelte").Component<any, {}, "">;
43
3
  type MarkerPath = ReturnType<typeof MarkerPath>;
44
4
  export default MarkerPath;
@@ -11,11 +11,4 @@ export type BollingerOptions = {
11
11
  };
12
12
  export declare function bollingerX(args: TransformArg<DataRecord>, options?: BollingerOptions): TransformArg<DataRecord>;
13
13
  export declare function bollingerY(args: TransformArg<DataRecord>, options?: BollingerOptions): TransformArg<DataRecord>;
14
- export declare function bollingerDim(dim: 'x' | 'y', { data, ...channels }: TransformArg<DataRecord>, options?: BollingerOptions): {
15
- data: {
16
- __x: import("../types.js").RawValue;
17
- __lo: number;
18
- __avg: number;
19
- __hi: number;
20
- }[];
21
- };
14
+ export declare function bollingerDim(dim: 'x' | 'y', { data, ...channels }: TransformArg<DataRecord>, options?: BollingerOptions): any;
@@ -1,9 +1,2 @@
1
1
  import type { DataRecord, TransformArg } from '../types.js';
2
- export declare function geoCentroid({ data, ...options }: TransformArg<DataRecord>): {
3
- x: (d: any) => any;
4
- y: (d: any) => any;
5
- data: {
6
- __centroid__: [number, number];
7
- ___orig___?: import("../types.js").RawValue | [import("../types.js").RawValue, import("../types.js").RawValue];
8
- }[];
9
- };
2
+ export declare function geoCentroid({ data, ...options }: TransformArg<DataRecord>): any;
@@ -38,29 +38,21 @@ type GroupZOptions = GroupXOptions | GroupYOptions;
38
38
  * groups the dataset by x and y channel and optionally reduces the group items
39
39
  * to output channels fill, stroke, r, opacity, fillOpacity, or strokeOpacity
40
40
  */
41
- export declare function group({ data, ...channels }: TransformArg<T, DataRecord>, options?: GroupXOptions): {
42
- data: DataRecord[];
43
- };
41
+ export declare function group({ data, ...channels }: TransformArg<T, DataRecord>, options?: GroupXOptions): any;
44
42
  /**
45
43
  * groups the dataset by the x channel and optionally reduces the group items
46
44
  * to output channels y, y1, y2, fill, stroke, r, opacity, fillOpacity, or strokeOpacity
47
45
  */
48
- export declare function groupX(input: TransformArg<T, DataRecord>, options?: GroupXOptions): {
49
- data: DataRecord[];
50
- };
46
+ export declare function groupX(input: TransformArg<T, DataRecord>, options?: GroupXOptions): any;
51
47
  /**
52
48
  * groups the dataset by the y channel and optionally reduces the group items
53
49
  * to output channels x, x1, x2, fill, stroke, r, opacity, fillOpacity, or strokeOpacity
54
50
  */
55
- export declare function groupY(input: TransformArg<T, DataRecord>, options?: GroupYOptions): {
56
- data: DataRecord[];
57
- };
51
+ export declare function groupY(input: TransformArg<T, DataRecord>, options?: GroupYOptions): any;
58
52
  /**
59
53
  * groups the dataset by the z channel and optionally reduces the group items
60
54
  * to output channels x, x1, x2, y, y1, y2, fill, stroke, r, opacity, fillOpacity,
61
55
  * or strokeOpacity
62
56
  */
63
- export declare function groupZ(input: TransformArg<T, DataRecord>, options?: GroupZOptions): {
64
- data: DataRecord[];
65
- };
57
+ export declare function groupZ(input: TransformArg<T, DataRecord>, options?: GroupZOptions): any;
66
58
  export {};
@@ -1,11 +1,7 @@
1
1
  import type { PlotState, TransformArg } from '../types.js';
2
2
  export declare function intervalX<T>(args: TransformArg<T>, { plot }: {
3
3
  plot: PlotState;
4
- }): {
5
- data: T[];
6
- };
4
+ }): any;
7
5
  export declare function intervalY<T>(args: TransformArg<T>, { plot }: {
8
6
  plot: PlotState;
9
- }): {
10
- data: T[];
11
- };
7
+ }): any;
@@ -1,10 +1,4 @@
1
- import type { TransformArg, MapOptions, MapMethod, DataRecord } from '../types.js';
2
- export declare function map<T>(args: TransformArg<T>, options: MapOptions): {
3
- data: DataRecord[];
4
- };
5
- export declare function mapX<T>(args: TransformArg<T>, mapper: MapMethod): {
6
- data: DataRecord[];
7
- };
8
- export declare function mapY<T>(args: TransformArg<T>, mapper: MapMethod): {
9
- data: DataRecord[];
10
- };
1
+ import type { TransformArg, MapOptions, MapMethod } from '../types.js';
2
+ export declare function map<T>(args: TransformArg<T>, options: MapOptions): any;
3
+ export declare function mapX<T>(args: TransformArg<T>, mapper: MapMethod): any;
4
+ export declare function mapY<T>(args: TransformArg<T>, mapper: MapMethod): any;
@@ -1,9 +1,5 @@
1
1
  import type { TransformArg, MapIndexObject } from '../types.js';
2
2
  type NormalizeBasis = 'deviation' | 'first' | 'last' | 'min' | 'max' | 'mean' | 'median' | 'sum' | 'extent' | MapIndexObject;
3
- export declare function normalizeX<T>(args: TransformArg<T>, basis: NormalizeBasis): {
4
- data: import("../types.js").DataRecord[];
5
- };
6
- export declare function normalizeY<T>(args: TransformArg<T>, basis: NormalizeBasis): {
7
- data: import("../types.js").DataRecord[];
8
- };
3
+ export declare function normalizeX<T>(args: TransformArg<T>, basis: NormalizeBasis): any;
4
+ export declare function normalizeY<T>(args: TransformArg<T>, basis: NormalizeBasis): any;
9
5
  export {};
@@ -5,31 +5,17 @@ type AtLeastOne<T, U = {
5
5
  type SelectOptions = 'first' | 'last' | AtLeastOne<{
6
6
  [k in ChannelName]: 'min' | 'max';
7
7
  }>;
8
- export declare function select({ data, ...channels }: TransformArg<DataRecord>, options: SelectOptions): {
9
- data: DataRecord[];
10
- };
8
+ export declare function select({ data, ...channels }: TransformArg<DataRecord>, options: SelectOptions): any;
11
9
  /**
12
10
  * Keeps only the first item of each group
13
11
  */
14
- export declare function selectFirst(args: TransformArg<DataRecord>): {
15
- data: DataRecord[];
16
- };
12
+ export declare function selectFirst(args: TransformArg<DataRecord>): any;
17
13
  /**
18
14
  * Keeps only the last item of each group
19
15
  */
20
- export declare function selectLast(args: TransformArg<DataRecord>): {
21
- data: DataRecord[];
22
- };
23
- export declare function selectMinX(args: TransformArg<DataRecord>): {
24
- data: DataRecord[];
25
- };
26
- export declare function selectMaxX(args: TransformArg<DataRecord>): {
27
- data: DataRecord[];
28
- };
29
- export declare function selectMinY(args: TransformArg<DataRecord>): {
30
- data: DataRecord[];
31
- };
32
- export declare function selectMaxY(args: TransformArg<DataRecord>): {
33
- data: DataRecord[];
34
- };
16
+ export declare function selectLast(args: TransformArg<DataRecord>): any;
17
+ export declare function selectMinX(args: TransformArg<DataRecord>): any;
18
+ export declare function selectMaxX(args: TransformArg<DataRecord>): any;
19
+ export declare function selectMinY(args: TransformArg<DataRecord>): any;
20
+ export declare function selectMaxY(args: TransformArg<DataRecord>): any;
35
21
  export {};
@@ -2,27 +2,14 @@ import type { DataRecord, DataRow, TransformArg } from '../types.js';
2
2
  export declare const SORT_KEY: unique symbol;
3
3
  export declare function sort({ data, ...channels }: TransformArg<DataRecord>, options?: {
4
4
  reverse?: boolean;
5
- }): {
6
- sort: null;
7
- data: {
8
- ___orig___?: import("../types.js").RawValue | [import("../types.js").RawValue, import("../types.js").RawValue];
9
- }[];
10
- } | {
11
- data: DataRecord[];
12
- };
5
+ }): any;
13
6
  /**
14
7
  * reverses the data row order
15
8
  */
16
9
  export declare function shuffle({ data, ...channels }: TransformArg<DataRow[]>, options?: {
17
10
  seed?: number;
18
- }): {
19
- sort: null;
20
- data: DataRow[][];
21
- };
11
+ }): any;
22
12
  /**
23
13
  * reverses the data row order
24
14
  */
25
- export declare function reverse({ data, ...channels }: TransformArg<DataRow[]>): {
26
- sort: null;
27
- data: DataRow[][];
28
- };
15
+ export declare function reverse({ data, ...channels }: TransformArg<DataRow[]>): any;
@@ -7,18 +7,6 @@ type WindowOptions = {
7
7
  reduce: ReducerName;
8
8
  strict: boolean;
9
9
  };
10
- export declare function windowX(args: TransformArg<DataRecord>, options: WindowOptions): {
11
- data: {
12
- [x: string]: import("../types.js").RawValue;
13
- [x: symbol]: import("../types.js").RawValue;
14
- ___orig___?: import("../types.js").RawValue | [import("../types.js").RawValue, import("../types.js").RawValue];
15
- }[];
16
- };
17
- export declare function windowY(args: TransformArg<DataRecord>, options: WindowOptions): {
18
- data: {
19
- [x: string]: import("../types.js").RawValue;
20
- [x: symbol]: import("../types.js").RawValue;
21
- ___orig___?: import("../types.js").RawValue | [import("../types.js").RawValue, import("../types.js").RawValue];
22
- }[];
23
- };
10
+ export declare function windowX(args: TransformArg<DataRecord>, options: WindowOptions): any;
11
+ export declare function windowY(args: TransformArg<DataRecord>, options: WindowOptions): any;
24
12
  export {};
@@ -0,0 +1,64 @@
1
+ <script>
2
+ let { examples } = $props();
3
+ </script>
4
+
5
+ <div class="list">
6
+ {#each examples as page, i (i)}
7
+ <a href={page.url}>
8
+ <div>
9
+ {#if page.screenshot}
10
+ <img src={page.screenshot} alt={page.title} />{/if}
11
+ </div>
12
+ <h4>
13
+ {page.title}
14
+ </h4>
15
+ </a>
16
+ {/each}
17
+ </div>
18
+
19
+ <style>
20
+ .list {
21
+ display: grid;
22
+ grid-template-columns: repeat(3, 1fr);
23
+ gap: 1rem;
24
+ width: 100%;
25
+ margin: 2rem 0;
26
+ }
27
+
28
+ .list > a {
29
+ display: flex;
30
+ flex-direction: column;
31
+ align-items: left;
32
+ row-gap: 0.3rem;
33
+ text-decoration: none;
34
+
35
+ > div {
36
+ border: 1px solid #88888822;
37
+ border-radius: 2px;
38
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
39
+ padding: 1.5ex;
40
+ }
41
+
42
+ &:hover {
43
+ text-decoration: underline;
44
+ color: var(--svp-text);
45
+ > div {
46
+ border: 1px solid var(--svp-text);
47
+ }
48
+ }
49
+ }
50
+
51
+ .list img {
52
+ width: 100%;
53
+ box-sizing: border-box;
54
+ border-radius: 3px;
55
+ transition: transform 0.2s ease-in-out;
56
+ }
57
+
58
+ .list h4 {
59
+ margin: 0rem;
60
+ font-weight: normal;
61
+ font-size: 13px;
62
+ line-height: 1;
63
+ }
64
+ </style>
@@ -0,0 +1,11 @@
1
+ export default ExamplesGrid;
2
+ type ExamplesGrid = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<$$ComponentProps>): void;
5
+ };
6
+ declare const ExamplesGrid: import("svelte").Component<{
7
+ examples: any;
8
+ }, {}, "">;
9
+ type $$ComponentProps = {
10
+ examples: any;
11
+ };