svelteplot 0.4.5-pr-208.4 → 0.4.5-pr-208.5

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 (53) hide show
  1. package/dist/core/Plot.svelte +54 -31
  2. package/dist/hooks/plotDefaults.d.ts +3 -0
  3. package/dist/hooks/plotDefaults.js +16 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/marks/Area.svelte +2 -1
  7. package/dist/marks/AreaX.svelte +4 -3
  8. package/dist/marks/AreaY.svelte +4 -5
  9. package/dist/marks/Arrow.svelte +3 -2
  10. package/dist/marks/AxisX.svelte +3 -4
  11. package/dist/marks/AxisY.svelte +3 -4
  12. package/dist/marks/AxisY.svelte.d.ts +5 -6
  13. package/dist/marks/BarX.svelte +4 -4
  14. package/dist/marks/BarY.svelte +3 -3
  15. package/dist/marks/BoxX.svelte +4 -4
  16. package/dist/marks/BoxY.svelte +4 -4
  17. package/dist/marks/BoxY.svelte.d.ts +1 -0
  18. package/dist/marks/Brush.svelte +13 -7
  19. package/dist/marks/Brush.svelte.d.ts +10 -1
  20. package/dist/marks/BrushX.svelte +4 -4
  21. package/dist/marks/BrushY.svelte +4 -4
  22. package/dist/marks/Cell.svelte +3 -4
  23. package/dist/marks/ColorLegend.svelte +5 -4
  24. package/dist/marks/DifferenceY.svelte +3 -3
  25. package/dist/marks/Dot.svelte +2 -2
  26. package/dist/marks/Frame.svelte +2 -2
  27. package/dist/marks/Geo.svelte +2 -2
  28. package/dist/marks/Graticule.svelte +3 -3
  29. package/dist/marks/GridX.svelte +3 -3
  30. package/dist/marks/GridY.svelte +4 -9
  31. package/dist/marks/HTMLTooltip.svelte +7 -19
  32. package/dist/marks/Line.svelte +3 -2
  33. package/dist/marks/Link.svelte +3 -3
  34. package/dist/marks/Pointer.svelte +3 -3
  35. package/dist/marks/Rect.svelte +2 -3
  36. package/dist/marks/RectX.svelte +4 -3
  37. package/dist/marks/RectY.svelte +4 -3
  38. package/dist/marks/RuleX.svelte +3 -3
  39. package/dist/marks/RuleY.svelte +4 -4
  40. package/dist/marks/Sphere.svelte +2 -2
  41. package/dist/marks/Spike.svelte +4 -3
  42. package/dist/marks/Spike.svelte.d.ts +3 -2
  43. package/dist/marks/Text.svelte +4 -4
  44. package/dist/marks/TickX.svelte +3 -3
  45. package/dist/marks/TickY.svelte +4 -4
  46. package/dist/marks/Vector.svelte +3 -3
  47. package/dist/marks/helpers/CanvasLayer.svelte +1 -1
  48. package/dist/marks/helpers/Marker.svelte +2 -1
  49. package/dist/marks/helpers/MarkerPath.svelte +4 -4
  50. package/dist/marks/helpers/MarkerPath.svelte.d.ts +17 -2
  51. package/dist/types/plot.d.ts +15 -8
  52. package/package.json +19 -19
  53. package/dist/marks/AreaY.svelte.d.ts +0 -102
@@ -8,7 +8,7 @@
8
8
  this component.
9
9
  -->
10
10
  <script lang="ts">
11
- import { getContext, setContext } from 'svelte';
11
+ import { setContext } from 'svelte';
12
12
  import { SvelteMap } from 'svelte/reactivity';
13
13
  import { writable } from 'svelte/store';
14
14
 
@@ -21,13 +21,15 @@
21
21
  PlotScale,
22
22
  PlotDefaults,
23
23
  PlotState,
24
- RawValue
24
+ RawValue,
25
+ PlotMargin
25
26
  } from '../types/index.js';
26
27
  import FacetGrid from './FacetGrid.svelte';
27
28
 
28
29
  import mergeDeep from '../helpers/mergeDeep.js';
29
30
  import { computeScales, projectXY } from '../helpers/scales.js';
30
31
  import { CHANNEL_SCALE, SCALES } from '../constants.js';
32
+ import { getPlotDefaults, setPlotDefaults } from '../hooks/plotDefaults.js';
31
33
 
32
34
  // automatic margins can be applied by the marks, registered
33
35
  // with their respective unique identifier as keys
@@ -51,7 +53,7 @@
51
53
  const maxMarginBottom = $derived(Math.max(...$autoMarginBottom.values()));
52
54
  const maxMarginTop = $derived(Math.max(...$autoMarginTop.values()));
53
55
 
54
- const USER_DEFAULTS = getContext<Partial<PlotDefaults>>('svelteplot/defaults') || {};
56
+ const USER_DEFAULTS = getPlotDefaults();
55
57
 
56
58
  // default settings in the plot and marks can be overwritten by
57
59
  // defining the svelteplot/defaults context outside of Plot
@@ -59,6 +61,7 @@
59
61
  height: 350,
60
62
  initialWidth: 500,
61
63
  inset: 0,
64
+ margin: 'auto',
62
65
  colorScheme: 'turbo',
63
66
  unknown: '#cccccc99',
64
67
 
@@ -115,14 +118,14 @@
115
118
 
116
119
  let width = $state(DEFAULTS.initialWidth);
117
120
 
118
- setContext('svelteplot/_defaults', DEFAULTS);
121
+ setPlotDefaults(DEFAULTS);
119
122
 
120
123
  // information that influences the default plot options
121
124
  type PlotOptionsParameters = {
122
125
  explicitScales: Set<ScaleName>;
123
126
  explicitDomains: Set<ScaleName>;
124
127
  hasProjection: boolean;
125
- margins?: number;
128
+ margin?: number | 'auto';
126
129
  inset?: number;
127
130
  };
128
131
 
@@ -173,7 +176,7 @@
173
176
  explicitScales,
174
177
  explicitDomains,
175
178
  hasProjection: !!initialOpts.projection,
176
- margins: initialOpts.margins,
179
+ margin: initialOpts.margin,
177
180
  inset: initialOpts.inset
178
181
  })
179
182
  );
@@ -363,6 +366,38 @@
363
366
  return mergeDeep<PlotOptions>({}, smartDefaultPlotOptions(opts), initialOpts);
364
367
  }
365
368
 
369
+ function maybeMargin(
370
+ // the margin option provided to the <Plot> component
371
+ margin: number | 'auto' | PlotMargin | undefined,
372
+ // direction to extract from the margin object
373
+ direction: 'left' | 'right' | 'top' | 'bottom',
374
+ // the margin option defined in the plot defaults
375
+ defaultValue: PlotMargin | number | 'auto',
376
+ // automatic margins computed from the marks
377
+ autoMargins: {
378
+ left: number;
379
+ right: number;
380
+ top: number;
381
+ bottom: number;
382
+ }
383
+ ): number {
384
+ // direction-specific margin value takes precedence
385
+ const marginValue =
386
+ typeof margin === 'object' && margin[direction] != null
387
+ ? margin[direction]
388
+ : // use the margin value if it's a number
389
+ typeof margin === 'number' || margin === 'auto'
390
+ ? margin
391
+ : // use direction-specific default value if defined
392
+ typeof defaultValue === 'object' && defaultValue[direction] != null
393
+ ? defaultValue[direction]
394
+ : typeof defaultValue === 'number' || defaultValue === 'auto'
395
+ ? defaultValue
396
+ : 'auto';
397
+
398
+ return marginValue === 'auto' ? autoMargins[direction] : marginValue;
399
+ }
400
+
366
401
  /**
367
402
  * compute smart default options for the plot based on the scales and marks
368
403
  */
@@ -370,43 +405,31 @@
370
405
  explicitScales,
371
406
  explicitDomains,
372
407
  hasProjection,
373
- margins
408
+ margin
374
409
  }: PlotOptionsParameters): PlotOptions {
375
410
  const autoXAxis = explicitScales.has('x') || explicitDomains.has('x');
376
411
  const autoYAxis = explicitScales.has('y') || explicitDomains.has('y');
377
412
  const isOneDimensional = autoXAxis !== autoYAxis;
378
413
  const oneDimX = autoXAxis && !autoYAxis;
379
414
  const oneDimY = autoYAxis && !autoXAxis;
415
+
416
+ const autoMargins = {
417
+ left: hasProjection ? 0 : Math.max(maxMarginLeft + 1, 1),
418
+ right: hasProjection ? 0 : oneDimY ? 0 : Math.max(maxMarginRight + 1, 4),
419
+ top: hasProjection ? 0 : oneDimX ? 0 : Math.max(5, maxMarginTop),
420
+ bottom: hasProjection ? 0 : Math.max(5, maxMarginBottom)
421
+ };
422
+
380
423
  return {
381
424
  title: '',
382
425
  subtitle: '',
383
426
  caption: '',
384
427
  height: 'auto',
385
428
  // maxWidth: oneDimY ? `${60 * e}px` : undefined,
386
- marginLeft: hasProjection
387
- ? 0
388
- : margins != null
389
- ? margins
390
- : Math.max(maxMarginLeft + 1, 1),
391
- marginRight: hasProjection
392
- ? 0
393
- : margins != null
394
- ? margins
395
- : oneDimY
396
- ? 0
397
- : Math.max(maxMarginRight + 1, 4),
398
- marginTop: hasProjection
399
- ? 0
400
- : margins != null
401
- ? margins
402
- : oneDimX
403
- ? 0
404
- : Math.max(5, maxMarginTop),
405
- marginBottom: hasProjection
406
- ? 0
407
- : margins != null
408
- ? margins
409
- : Math.max(5, maxMarginBottom),
429
+ marginLeft: maybeMargin(margin, 'left', DEFAULTS.margin, autoMargins),
430
+ marginRight: maybeMargin(margin, 'right', DEFAULTS.margin, autoMargins),
431
+ marginTop: maybeMargin(margin, 'top', DEFAULTS.margin, autoMargins),
432
+ marginBottom: maybeMargin(margin, 'bottom', DEFAULTS.margin, autoMargins),
410
433
  inset: isOneDimensional ? 10 : DEFAULTS.inset,
411
434
  grid: (DEFAULTS.gridX?.implicit ?? false) && (DEFAULTS.gridY?.implicit ?? false),
412
435
  axes: (DEFAULTS.axisX?.implicit ?? false) && (DEFAULTS.axisY?.implicit ?? false),
@@ -0,0 +1,3 @@
1
+ import type { PlotDefaults } from '../types';
2
+ export declare function setPlotDefaults(plotDefaults: Partial<PlotDefaults>): void;
3
+ export declare function getPlotDefaults(): Partial<PlotDefaults>;
@@ -0,0 +1,16 @@
1
+ import { getContext, hasContext, setContext } from 'svelte';
2
+ const PLOT_DEFAULTS_KEY = Symbol('svelteplot/defaults');
3
+ export function setPlotDefaults(plotDefaults) {
4
+ const existingDefaults = getPlotDefaults();
5
+ const mergedDefaults = { ...existingDefaults, ...plotDefaults };
6
+ setContext(PLOT_DEFAULTS_KEY, mergedDefaults);
7
+ }
8
+ export function getPlotDefaults() {
9
+ return hasContext(PLOT_DEFAULTS_KEY)
10
+ ? getContext(PLOT_DEFAULTS_KEY)
11
+ : // Fallback for backward compatibility
12
+ hasContext('svelteplot/defaults')
13
+ ? (console.error(`svelteplot: Please use new setPlotDefaults hook instead of 'svelteplot/defaults' context`),
14
+ getContext('svelteplot/defaults'))
15
+ : {};
16
+ }
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { default as PlotCore } from './core/Plot.svelte';
3
3
  export * from './marks/index.js';
4
4
  export * from './transforms/index.js';
5
5
  export { formatMonth } from './helpers/formats.js';
6
+ export * from './hooks/plotDefaults.js';
package/dist/index.js CHANGED
@@ -4,3 +4,5 @@ export * from './marks/index.js';
4
4
  export * from './transforms/index.js';
5
5
  // helpers
6
6
  export { formatMonth } from './helpers/formats.js';
7
+ // hooks
8
+ export * from './hooks/plotDefaults.js';
@@ -42,6 +42,7 @@
42
42
  } from '../types/index.js';
43
43
  import type { StackOptions } from '../transforms/stack.js';
44
44
  import { addEventHandlers } from './helpers/events';
45
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
45
46
 
46
47
  let markProps: AreaMarkProps = $props();
47
48
 
@@ -49,7 +50,7 @@
49
50
  fill: 'currentColor',
50
51
  curve: 'linear' as CurveName,
51
52
  tension: 0,
52
- ...getContext<PlotDefaults>('svelteplot/_defaults').area
53
+ ...getPlotDefaults().area
53
54
  };
54
55
 
55
56
  const {
@@ -11,12 +11,13 @@
11
11
  import { renameChannels } from '../transforms/rename.js';
12
12
  import { stackX } from '../transforms/stack.js';
13
13
  import { recordizeX } from '../transforms/recordize.js';
14
- import type { ChannelAccessor, DataRow, PlotDefaults } from '../types/index.js';
15
- import { getContext, type ComponentProps } from 'svelte';
14
+ import type { ChannelAccessor, DataRow } from '../types/index.js';
15
+ import { type ComponentProps } from 'svelte';
16
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
16
17
 
17
18
  let markProps: AreaXMarkProps = $props();
18
19
 
19
- const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaX;
20
+ const DEFAULTS = getPlotDefaults().areaX;
20
21
 
21
22
  const { data, stack, ...options }: AreaXMarkProps = $derived({
22
23
  ...(markProps.x == undefined ? { x1: 0, x2: 0 } : {}),
@@ -10,14 +10,13 @@
10
10
  import Area from './Area.svelte';
11
11
  import { renameChannels } from '../transforms/rename.js';
12
12
  import { stackY } from '../transforms/stack.js';
13
- import { RAW_VALUE, recordizeY } from '../transforms/recordize.js';
14
- import type { ChannelAccessor, DataRow, PlotDefaults } from '../types/index.js';
15
- import { getContext, type Component, type ComponentProps } from 'svelte';
16
- import { area } from 'd3-shape';
13
+ import { recordizeY } from '../transforms/recordize.js';
14
+ import type { ChannelAccessor, DataRow } from '../types/index.js';
15
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
17
16
 
18
17
  let markProps: AreaYMarkProps = $props();
19
18
 
20
- const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaY;
19
+ const DEFAULTS = getPlotDefaults().areaY;
21
20
 
22
21
  const { data, stack, ...options }: AreaYMarkProps = $derived({
23
22
  ...(markProps.y == undefined ? { y1: 0, y2: 0 } : {}),
@@ -47,7 +47,7 @@
47
47
  RawValue,
48
48
  PlotDefaults
49
49
  } from '../types/index.js';
50
- import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
50
+ import { resolveProp, resolveStyles } from '../helpers/resolve.js';
51
51
  import { coalesce, maybeNumber } from '../helpers/index.js';
52
52
  import Mark from '../Mark.svelte';
53
53
  import { arrowPath, maybeSweep, type SweepOption } from '../helpers/arrowPath.js';
@@ -56,6 +56,7 @@
56
56
  import GroupMultiple from './helpers/GroupMultiple.svelte';
57
57
  import { sort } from '../transforms/sort.js';
58
58
  import { indexData } from '../transforms/recordize.js';
59
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
59
60
 
60
61
  let markProps: ArrowMarkProps = $props();
61
62
 
@@ -63,7 +64,7 @@
63
64
  headAngle: 60,
64
65
  headLength: 8,
65
66
  inset: 0,
66
- ...getContext<PlotDefaults>('svelteplot/_defaults').arrow
67
+ ...getPlotDefaults().arrow
67
68
  };
68
69
 
69
70
  const {
@@ -11,14 +11,13 @@
11
11
  RawValue,
12
12
  ConstantAccessor,
13
13
  FacetContext,
14
- PlotDefaults,
15
14
  ChannelName
16
15
  } from '../types/index.js';
17
16
  import type * as CSS from 'csstype';
18
17
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
19
- import { derived } from 'svelte/store';
20
18
  import { autoTicks } from '../helpers/autoTicks.js';
21
19
  import { resolveScaledStyles } from '../helpers/resolve.js';
20
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
22
21
 
23
22
  interface AxisXMarkProps
24
23
  extends Omit<
@@ -64,8 +63,8 @@
64
63
  textAnchor: 'auto',
65
64
  opacity: 0.8,
66
65
  anchor: 'bottom',
67
- ...getContext<PlotDefaults>('svelteplot/_defaults').axis,
68
- ...getContext<PlotDefaults>('svelteplot/_defaults').axisX
66
+ ...getPlotDefaults().axis,
67
+ ...getPlotDefaults().axisX
69
68
  };
70
69
 
71
70
  const {
@@ -10,14 +10,13 @@
10
10
  BaseMarkProps,
11
11
  RawValue,
12
12
  FacetContext,
13
- PlotDefaults,
14
13
  ChannelName,
15
14
  ConstantAccessor
16
15
  } from '../types/index.js';
17
- import type * as CSS from 'csstype';
18
16
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
19
17
  import { autoTicks } from '../helpers/autoTicks.js';
20
18
  import { resolveScaledStyles } from '../helpers/resolve.js';
19
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
21
20
 
22
21
  interface AxisYMarkProps
23
22
  extends Omit<
@@ -62,8 +61,8 @@
62
61
  opacity: 0.8,
63
62
  anchor: 'left',
64
63
  textAnchor: 'auto',
65
- ...getContext<PlotDefaults>('svelteplot/_defaults').axis,
66
- ...getContext<PlotDefaults>('svelteplot/_defaults').axisY
64
+ ...getPlotDefaults().axis,
65
+ ...getPlotDefaults().axisY
67
66
  };
68
67
 
69
68
  const {
@@ -1,5 +1,4 @@
1
1
  import type { RawValue, ConstantAccessor } from '../types/index.js';
2
- import type * as CSS from 'csstype';
3
2
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
4
3
  declare class __sveltets_Render<Datum extends RawValue> {
5
4
  props(): Omit<Partial<{
@@ -20,16 +19,16 @@ declare class __sveltets_Render<Datum extends RawValue> {
20
19
  stroke: import("../types/channel").ChannelAccessor<Datum>;
21
20
  strokeWidth: ConstantAccessor<number, Datum>;
22
21
  strokeOpacity: ConstantAccessor<number, Datum>;
23
- strokeLinejoin: ConstantAccessor<CSS.Property.StrokeLinejoin, Datum>;
24
- strokeLinecap: ConstantAccessor<CSS.Property.StrokeLinecap, Datum>;
22
+ strokeLinejoin: ConstantAccessor<import("csstype").Property.StrokeLinejoin, Datum>;
23
+ strokeLinecap: ConstantAccessor<import("csstype").Property.StrokeLinecap, Datum>;
25
24
  strokeMiterlimit: ConstantAccessor<number, Datum>;
26
25
  opacity: import("../types/channel").ChannelAccessor<Datum>;
27
26
  strokeDasharray: ConstantAccessor<string, Datum>;
28
27
  strokeDashoffset: ConstantAccessor<number, Datum>;
29
- mixBlendMode: ConstantAccessor<CSS.Property.MixBlendMode, Datum>;
28
+ mixBlendMode: ConstantAccessor<import("csstype").Property.MixBlendMode, Datum>;
30
29
  clipPath: string;
31
30
  imageFilter: ConstantAccessor<string, Datum>;
32
- shapeRendering: ConstantAccessor<CSS.Property.ShapeRendering, Datum>;
31
+ shapeRendering: ConstantAccessor<import("csstype").Property.ShapeRendering, Datum>;
33
32
  paintOrder: ConstantAccessor<string, Datum>;
34
33
  onclick: import("svelte/elements").MouseEventHandler<SVGPathElement>;
35
34
  ondblclick: import("svelte/elements").MouseEventHandler<SVGPathElement>;
@@ -63,7 +62,7 @@ declare class __sveltets_Render<Datum extends RawValue> {
63
62
  onwheel: import("svelte/elements").MouseEventHandler<SVGPathElement>;
64
63
  class: string;
65
64
  style: string;
66
- cursor: ConstantAccessor<CSS.Property.Cursor, Datum>;
65
+ cursor: ConstantAccessor<import("csstype").Property.Cursor, Datum>;
67
66
  }>, "fillOpacity" | "href" | "target" | "title" | "paintOrder"> & {
68
67
  data?: Datum[] | undefined;
69
68
  automatic?: boolean;
@@ -33,14 +33,14 @@
33
33
  BaseMarkProps,
34
34
  BaseRectMarkProps,
35
35
  ChannelAccessor,
36
- LinkableMarkProps,
37
- PlotDefaults
36
+ LinkableMarkProps
38
37
  } from '../types/index.js';
38
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
39
39
 
40
40
  const DEFAULTS = {
41
41
  fill: 'currentColor',
42
- ...getContext<PlotDefaults>('svelteplot/_defaults').bar,
43
- ...getContext<PlotDefaults>('svelteplot/_defaults').barX
42
+ ...getPlotDefaults().bar,
43
+ ...getPlotDefaults().barX
44
44
  };
45
45
 
46
46
  let markProps: BarXMarkProps = $props();
@@ -34,16 +34,16 @@
34
34
  BaseRectMarkProps,
35
35
  ChannelAccessor,
36
36
  DataRow,
37
- PlotDefaults,
38
37
  LinkableMarkProps
39
38
  } from '../types/index.js';
39
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
40
40
 
41
41
  const { getPlotState } = getContext<PlotContext>('svelteplot');
42
42
  const plot = $derived(getPlotState());
43
43
 
44
44
  const DEFAULTS = {
45
- ...getContext<PlotDefaults>('svelteplot/_defaults').bar,
46
- ...getContext<PlotDefaults>('svelteplot/_defaults').barY
45
+ ...getPlotDefaults().bar,
46
+ ...getPlotDefaults().barY
47
47
  };
48
48
 
49
49
  let markProps: BarYMarkProps = $props();
@@ -7,17 +7,17 @@
7
7
  import GroupMultiple from './helpers/GroupMultiple.svelte';
8
8
  import { BarX, TickX, RuleY, Dot, groupY } from '../index.js';
9
9
  import { resolveChannel } from '../helpers/resolve.js';
10
- import { getContext, type ComponentProps } from 'svelte';
11
- import type { PlotDefaults } from '../types/index.js';
10
+ import { type ComponentProps } from 'svelte';
12
11
  import type BoxY from './BoxY.svelte';
12
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
13
13
 
14
14
  let markProps: BoxXMarkProps = $props();
15
15
 
16
16
  const DEFAULTS = {
17
17
  tickMedian: true,
18
18
  tickMinMax: false,
19
- ...getContext<PlotDefaults>('svelteplot/_defaults').box,
20
- ...getContext<PlotDefaults>('svelteplot/_defaults').boxX
19
+ ...getPlotDefaults().box,
20
+ ...getPlotDefaults().boxX
21
21
  };
22
22
 
23
23
  const {
@@ -31,16 +31,16 @@
31
31
  import GroupMultiple from './helpers/GroupMultiple.svelte';
32
32
  import { groupX, BarY, TickY, RuleX, Dot } from '../index.js';
33
33
  import { resolveChannel } from '../helpers/resolve.js';
34
- import { getContext, type ComponentProps } from 'svelte';
35
- import type { PlotDefaults } from '../types/index.js';
34
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
35
+ import type { BaseMarkProps, ChannelAccessor, DataRecord } from '../types';
36
36
 
37
37
  let markProps: BoxYMarkProps = $props();
38
38
 
39
39
  const DEFAULTS = {
40
40
  tickMedian: true,
41
41
  tickMinMax: false,
42
- ...getContext<PlotDefaults>('svelteplot/_defaults').box,
43
- ...getContext<PlotDefaults>('svelteplot/_defaults').boxY
42
+ ...getPlotDefaults().box,
43
+ ...getPlotDefaults().boxY
44
44
  };
45
45
 
46
46
  const {
@@ -1,3 +1,4 @@
1
+ import type { ChannelAccessor, DataRecord } from '../types';
1
2
  declare class __sveltets_Render<Datum extends DataRecord> {
2
3
  props(): Pick<BaseMarkProps<Datum_1>, "fill" | "stroke" | "fx" | "fy" | "class"> & {
3
4
  data: Datum[];
@@ -35,14 +35,10 @@
35
35
  }
36
36
  import { getContext } from 'svelte';
37
37
  import Rect from './Rect.svelte';
38
- import type {
39
- BaseMarkProps,
40
- DataRecord,
41
- PlotContext,
42
- PlotDefaults
43
- } from '../types/index.js';
38
+ import type { BaseMarkProps, DataRecord, PlotContext } from '../types/index.js';
44
39
  import { clientToLayerCoordinates } from './helpers/events.js';
45
40
  import Frame from './Frame.svelte';
41
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
46
42
 
47
43
  let { brush = $bindable({ enabled: false }), ...markProps }: BrushMarkProps = $props();
48
44
 
@@ -52,9 +48,19 @@
52
48
  strokeOpacity: 0.6,
53
49
  resizeHandleSize: 10,
54
50
  constrainToDomain: false,
55
- ...getContext<PlotDefaults>('svelteplot/_defaults').brush
51
+ ...getPlotDefaults().brush
56
52
  };
57
53
 
54
+ type Brush = {
55
+ x1?: number | Date;
56
+ x2?: number | Date;
57
+ y1?: number | Date;
58
+ y2?: number | Date;
59
+ enabled: boolean;
60
+ };
61
+
62
+ type BrushEvent = MouseEvent & { brush: Brush };
63
+
58
64
  const {
59
65
  data = [{} as Datum],
60
66
  stroke,
@@ -1,4 +1,14 @@
1
1
  import type { BaseMarkProps, DataRecord } from '../types/index.js';
2
+ type Brush = {
3
+ x1?: number | Date;
4
+ x2?: number | Date;
5
+ y1?: number | Date;
6
+ y2?: number | Date;
7
+ enabled: boolean;
8
+ };
9
+ type BrushEvent = MouseEvent & {
10
+ brush: Brush;
11
+ };
2
12
  interface BrushMarkProps extends Pick<BaseMarkProps<Datum>, 'cursor' | 'stroke' | 'strokeDasharray' | 'strokeOpacity' | 'strokeWidth' | 'strokeLinecap' | 'strokeDashoffset' | 'strokeLinejoin' | 'strokeMiterlimit'> {
3
13
  brush: Brush;
4
14
  /**
@@ -33,5 +43,4 @@ interface $$IsomorphicComponent {
33
43
  }
34
44
  /** For creating a two-dimensional brush selection */
35
45
  declare const Brush: $$IsomorphicComponent;
36
- type Brush<Datum extends DataRecord> = InstanceType<typeof Brush<Datum>>;
37
46
  export default Brush;
@@ -6,13 +6,13 @@
6
6
  interface BrushXMarkProps extends Omit<ComponentProps<typeof Brush>, 'limitDimension'> {}
7
7
 
8
8
  import Brush from './Brush.svelte';
9
- import type { PlotDefaults } from '../types/index.js';
10
- import { getContext, type ComponentProps } from 'svelte';
9
+ import { type ComponentProps } from 'svelte';
10
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
11
11
 
12
12
  let { brush = $bindable({ enabled: false }), ...options }: BrushXMarkProps = $props();
13
13
  const DEFAULTS = {
14
- ...getContext<PlotDefaults>('svelteplot/_defaults').brush,
15
- ...getContext<PlotDefaults>('svelteplot/_defaults').brushX
14
+ ...getPlotDefaults().brush,
15
+ ...getPlotDefaults().brushX
16
16
  };
17
17
  </script>
18
18
 
@@ -4,15 +4,15 @@
4
4
  -->
5
5
  <script lang="ts">
6
6
  import Brush from './Brush.svelte';
7
- import type { PlotDefaults } from '../types/index.js';
8
- import { getContext, type ComponentProps } from 'svelte';
7
+ import { type ComponentProps } from 'svelte';
8
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
9
9
 
10
10
  interface BrushYMarkProps extends Omit<ComponentProps<typeof Brush>, 'limitDimension'> {}
11
11
 
12
12
  let { brush = $bindable({ enabled: false }), ...options }: BrushYMarkProps = $props();
13
13
  const DEFAULTS = {
14
- ...getContext<PlotDefaults>('svelteplot/_defaults').brush,
15
- ...getContext<PlotDefaults>('svelteplot/_defaults').brushY
14
+ ...getPlotDefaults().brush,
15
+ ...getPlotDefaults().brushY
16
16
  };
17
17
  </script>
18
18
 
@@ -17,9 +17,7 @@
17
17
  BaseMarkProps,
18
18
  BaseRectMarkProps,
19
19
  ChannelAccessor,
20
- PlotDefaults,
21
- LinkableMarkProps,
22
- MarkType
20
+ LinkableMarkProps
23
21
  } from '../types/index.js';
24
22
  import Mark from '../Mark.svelte';
25
23
  import { getContext } from 'svelte';
@@ -28,11 +26,12 @@
28
26
 
29
27
  import { isValid } from '../helpers/index.js';
30
28
  import RectPath from './helpers/RectPath.svelte';
29
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
31
30
 
32
31
  let markProps: CellMarkProps = $props();
33
32
 
34
33
  const DEFAULTS = {
35
- ...getContext<PlotDefaults>('svelteplot/_defaults').cell
34
+ ...getPlotDefaults().cell
36
35
  };
37
36
 
38
37
  const {
@@ -10,14 +10,15 @@
10
10
  import { range as d3Range, extent } from 'd3-array';
11
11
  import { maybeSymbol } from '../helpers/symbols.js';
12
12
 
13
- import type { PlotDefaults, PlotContext } from '../types/plot.js';
13
+ import type { PlotContext } from '../types/plot.js';
14
+ import { getPlotDefaults } from '../hooks/plotDefaults';
14
15
 
15
16
  let { class: className = null }: ColorLegendMarkProps = $props();
16
17
 
17
18
  const { getPlotState } = getContext<PlotContext>('svelteplot');
18
19
  const plot = $derived(getPlotState());
19
20
 
20
- const DEFAULTS = getContext<Partial<PlotDefaults>>('svelteplot/_defaults');
21
+ const DEFAULTS = getPlotDefaults();
21
22
 
22
23
  const legendTitle = $derived(plot.options.color.label);
23
24
  const scaleType = $derived(plot.scales.color.type);
@@ -88,7 +89,7 @@
88
89
  ).slice(1)}
89
90
  <Plot
90
91
  maxWidth="240px"
91
- margins={1}
92
+ margin={1}
92
93
  marginLeft={1}
93
94
  marginRight={1}
94
95
  marginTop={6}
@@ -121,7 +122,7 @@
121
122
 
122
123
  <Plot
123
124
  maxWidth="240px"
124
- margins={1}
125
+ margin={1}
125
126
  marginLeft={10}
126
127
  marginRight={10}
127
128
  marginTop={6}
@@ -50,8 +50,7 @@
50
50
  ChannelAccessor,
51
51
  CurveName,
52
52
  DataRecord,
53
- PlotContext,
54
- PlotDefaults
53
+ PlotContext
55
54
  } from '../types/index.js';
56
55
  import { Line, Area } from './index.js';
57
56
  import { randomId, coalesce } from '../helpers/index.js';
@@ -59,6 +58,7 @@
59
58
  import { extent, max, min } from 'd3-array';
60
59
  import { resolveChannel } from '../helpers/resolve.js';
61
60
  import type { CurveFactory } from 'd3-shape';
61
+ import { getPlotDefaults } from '../hooks/plotDefaults.js';
62
62
 
63
63
  const { getPlotState } = getContext<PlotContext>('svelteplot');
64
64
  let plot = $derived(getPlotState());
@@ -72,7 +72,7 @@
72
72
  negativeFillOpacity: 1,
73
73
  curve: 'linear' as CurveName,
74
74
  tension: 0,
75
- ...getContext<PlotDefaults>('svelteplot/_defaults').differenceY
75
+ ...getPlotDefaults().differenceY
76
76
  };
77
77
 
78
78
  const {