svelteplot 0.10.3-pr-486.0 → 0.10.3-pr-487.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.
@@ -2,16 +2,6 @@
2
2
  @component
3
3
  For creating a two-dimensional brush selection
4
4
  -->
5
- <script module lang="ts">
6
- export type Brush = {
7
- x1?: number | Date;
8
- x2?: number | Date;
9
- y1?: number | Date;
10
- y2?: number | Date;
11
- enabled: boolean;
12
- };
13
- </script>
14
-
15
5
  <script lang="ts" generics="Datum extends DataRecord">
16
6
  interface BrushMarkProps extends Pick<
17
7
  BaseMarkProps<Datum>,
@@ -68,9 +58,18 @@
68
58
  ...getPlotDefaults().brush
69
59
  };
70
60
 
61
+ type Brush = {
62
+ x1?: number | Date;
63
+ x2?: number | Date;
64
+ y1?: number | Date;
65
+ y2?: number | Date;
66
+ enabled: boolean;
67
+ };
68
+
71
69
  type BrushEvent = MouseEvent & { brush: Brush };
72
70
 
73
71
  const {
72
+ data = [{} as Datum],
74
73
  stroke,
75
74
  strokeWidth,
76
75
  strokeDasharray,
@@ -86,7 +85,7 @@
86
85
  onbrushstart,
87
86
  onbrushend,
88
87
  onbrush
89
- }: Omit<BrushMarkProps, 'brush'> = $derived({
88
+ }: BrushMarkProps = $derived({
90
89
  ...DEFAULTS,
91
90
  ...markProps
92
91
  });
@@ -283,10 +282,10 @@
283
282
  // draw new brush selection
284
283
  action = 'draw';
285
284
  if (typeof xScaleFn.invert === 'function' && limitDimension !== 'y') {
286
- x1 = x2 = xScaleFn.invert(dragStart[0]) as number | Date;
285
+ x1 = x2 = xScaleFn.invert(dragStart[0]);
287
286
  }
288
287
  if (typeof yScaleFn.invert === 'function' && limitDimension !== 'x') {
289
- y1 = y2 = yScaleFn.invert(dragStart[1]) as number | Date;
288
+ y1 = y2 = yScaleFn.invert(dragStart[1]);
290
289
  }
291
290
  }
292
291
  onbrushstart?.({ ...e, brush });
@@ -328,10 +327,10 @@
328
327
  const hasX = limitDimension !== 'y';
329
328
  const hasY = limitDimension !== 'x';
330
329
 
331
- const dx1 = (!hasX ? 0 : xScaleFn.invert(xScaleFn(x1) + px)) as number | Date;
332
- const dx2 = (!hasX ? 0 : xScaleFn.invert(xScaleFn(x2) + px)) as number | Date;
333
- const dy1 = (!hasY ? 0 : yScaleFn.invert(yScaleFn(y1) + py)) as number | Date;
334
- const dy2 = (!hasY ? 0 : yScaleFn.invert(yScaleFn(y2) + py)) as number | Date;
330
+ const dx1 = !hasX ? 0 : xScaleFn.invert(xScaleFn(x1) + px);
331
+ const dx2 = !hasX ? 0 : xScaleFn.invert(xScaleFn(x2) + px);
332
+ const dy1 = !hasY ? 0 : yScaleFn.invert(yScaleFn(y1) + py);
333
+ const dy2 = !hasY ? 0 : yScaleFn.invert(yScaleFn(y2) + py);
335
334
 
336
335
  if (action === 'move') {
337
336
  // move edges
@@ -340,8 +339,8 @@
340
339
  y1 = dy1;
341
340
  y2 = dy2;
342
341
  } else if (action === 'draw') {
343
- x2 = (!hasX ? 0 : xScaleFn.invert(newPos[0])) as number | Date;
344
- y2 = (!hasY ? 0 : yScaleFn.invert(newPos[1])) as number | Date;
342
+ x2 = !hasX ? 0 : xScaleFn.invert(newPos[0]);
343
+ y2 = !hasY ? 0 : yScaleFn.invert(newPos[1]);
345
344
 
346
345
  if (constrainToDomain) {
347
346
  x2 = constrain(x2, xDomain as [typeof x2, typeof x2]);
@@ -384,7 +383,7 @@
384
383
  action: ActionType,
385
384
  swapDir1: string,
386
385
  swapDir2: string
387
- ): [number | Date, number | Date, ActionType] {
386
+ ) {
388
387
  if (action && v2 < v1) {
389
388
  return [
390
389
  v2,
@@ -427,5 +426,5 @@
427
426
  stroke="transparent"
428
427
  inset={-20}
429
428
  {cursor}
430
- onpointerdown={onpointerdown as any}
431
- onpointermove={onpointermove as any} />
429
+ {onpointerdown}
430
+ {onpointermove} />
@@ -1,10 +1,3 @@
1
- export type Brush = {
2
- x1?: number | Date;
3
- x2?: number | Date;
4
- y1?: number | Date;
5
- y2?: number | Date;
6
- enabled: boolean;
7
- };
8
1
  import type { DataRecord } from '../types/index.js';
9
2
  declare function $$render<Datum extends DataRecord>(): {
10
3
  props: Pick<Partial<{
@@ -144,7 +137,13 @@ declare function $$render<Datum extends DataRecord>(): {
144
137
  title: import("../types/index.js").ConstantAccessor<string, Datum>;
145
138
  }>, "stroke" | "strokeWidth" | "strokeOpacity" | "strokeLinejoin" | "strokeLinecap" | "strokeMiterlimit" | "strokeDasharray" | "strokeDashoffset" | "cursor"> & {
146
139
  /** the brush state object (bindable); contains x1, x2, y1, y2, and enabled */
147
- brush: Brush;
140
+ brush: {
141
+ x1?: number | Date;
142
+ x2?: number | Date;
143
+ y1?: number | Date;
144
+ y2?: number | Date;
145
+ enabled: boolean;
146
+ };
148
147
  /**
149
148
  * limit brushing to x or y dimension
150
149
  */
@@ -159,15 +158,33 @@ declare function $$render<Datum extends DataRecord>(): {
159
158
  resizeHandleSize?: number;
160
159
  /** called when the user starts dragging to create or move a brush */
161
160
  onbrushstart?: (evt: MouseEvent & {
162
- brush: Brush;
161
+ brush: {
162
+ x1?: number | Date;
163
+ x2?: number | Date;
164
+ y1?: number | Date;
165
+ y2?: number | Date;
166
+ enabled: boolean;
167
+ };
163
168
  }) => void;
164
169
  /** called when the user finishes dragging the brush */
165
170
  onbrushend?: (evt: MouseEvent & {
166
- brush: Brush;
171
+ brush: {
172
+ x1?: number | Date;
173
+ x2?: number | Date;
174
+ y1?: number | Date;
175
+ y2?: number | Date;
176
+ enabled: boolean;
177
+ };
167
178
  }) => void;
168
179
  /** called continuously while the user is dragging the brush */
169
180
  onbrush?: (evt: MouseEvent & {
170
- brush: Brush;
181
+ brush: {
182
+ x1?: number | Date;
183
+ x2?: number | Date;
184
+ y1?: number | Date;
185
+ y2?: number | Date;
186
+ enabled: boolean;
187
+ };
171
188
  }) => void;
172
189
  };
173
190
  exports: {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.10.3-pr-486.0",
3
+ "version": "0.10.3-pr-487.0",
4
4
  "description": "A Svelte-native data visualization framework based on the layered grammar of graphics principles.",
5
5
  "keywords": [
6
6
  "svelte",