svelteplot 0.2.9 → 0.2.10-pr-110.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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/Mark.svelte +5 -4
  3. package/dist/Plot.svelte +3 -2
  4. package/dist/core/Plot.svelte +37 -20
  5. package/dist/helpers/colors.d.ts +1 -1
  6. package/dist/helpers/index.d.ts +2 -2
  7. package/dist/helpers/scales.d.ts +1 -1
  8. package/dist/helpers/scales.js +9 -1
  9. package/dist/helpers/typeChecks.d.ts +4 -4
  10. package/dist/marks/Area.svelte +31 -29
  11. package/dist/marks/AreaX.svelte +7 -3
  12. package/dist/marks/AreaX.svelte.d.ts +1 -6
  13. package/dist/marks/AreaY.svelte +7 -2
  14. package/dist/marks/AreaY.svelte.d.ts +1 -9
  15. package/dist/marks/Arrow.svelte +21 -7
  16. package/dist/marks/AxisX.svelte +24 -21
  17. package/dist/marks/AxisX.svelte.d.ts +3 -4
  18. package/dist/marks/AxisY.svelte +23 -20
  19. package/dist/marks/AxisY.svelte.d.ts +3 -4
  20. package/dist/marks/BarX.svelte +18 -2
  21. package/dist/marks/BarX.svelte.d.ts +2 -2
  22. package/dist/marks/BarY.svelte +18 -3
  23. package/dist/marks/BarY.svelte.d.ts +2 -2
  24. package/dist/marks/BollingerX.svelte.d.ts +1 -1
  25. package/dist/marks/BollingerY.svelte.d.ts +1 -1
  26. package/dist/marks/BrushX.svelte +1 -1
  27. package/dist/marks/BrushY.svelte +1 -1
  28. package/dist/marks/Cell.svelte +1 -0
  29. package/dist/marks/Cell.svelte.d.ts +2 -2
  30. package/dist/marks/ColorLegend.svelte +3 -2
  31. package/dist/marks/Dot.svelte +29 -24
  32. package/dist/marks/Dot.svelte.d.ts +2 -2
  33. package/dist/marks/Frame.svelte +24 -4
  34. package/dist/marks/Frame.svelte.d.ts +2 -2
  35. package/dist/marks/Geo.svelte +27 -33
  36. package/dist/marks/Geo.svelte.d.ts +4 -2
  37. package/dist/marks/Graticule.svelte +2 -2
  38. package/dist/marks/Rect.svelte +1 -0
  39. package/dist/marks/Rect.svelte.d.ts +2 -2
  40. package/dist/marks/Sphere.svelte +2 -2
  41. package/dist/marks/Sphere.svelte.d.ts +3 -58
  42. package/dist/marks/helpers/Anchor.svelte +37 -0
  43. package/dist/marks/helpers/Anchor.svelte.d.ts +15 -0
  44. package/dist/marks/helpers/BaseAxisX.svelte +59 -53
  45. package/dist/marks/helpers/BaseAxisX.svelte.d.ts +1 -0
  46. package/dist/marks/helpers/BaseAxisY.svelte +24 -18
  47. package/dist/marks/helpers/BaseAxisY.svelte.d.ts +1 -0
  48. package/dist/marks/helpers/MarkerPath.svelte.d.ts +1 -41
  49. package/dist/marks/helpers/RectPath.svelte +33 -30
  50. package/dist/marks/helpers/Regression.svelte +1 -1
  51. package/dist/transforms/bollinger.d.ts +1 -8
  52. package/dist/transforms/centroid.d.ts +1 -8
  53. package/dist/transforms/group.d.ts +4 -12
  54. package/dist/transforms/interval.d.ts +2 -6
  55. package/dist/transforms/map.d.ts +4 -10
  56. package/dist/transforms/normalize.d.ts +2 -6
  57. package/dist/transforms/select.d.ts +7 -21
  58. package/dist/transforms/sort.d.ts +5 -17
  59. package/dist/transforms/sort.js +23 -13
  60. package/dist/transforms/window.d.ts +2 -14
  61. package/dist/types.d.ts +232 -78
  62. package/dist/ui/ExamplesGrid.svelte +1 -1
  63. package/package.json +121 -120
@@ -26,16 +26,13 @@
26
26
  tickClass?: ConstantAccessor<string>;
27
27
  /** ticks is a shorthand for defining data, tickCount or interval */
28
28
  ticks?: number | string | RawValue[];
29
- } & XOR<
30
- {
31
- /** approximate number of ticks to be generated */
32
- tickCount?: number;
33
- },
34
- {
35
- /** approximate number of pixels between generated ticks */
36
- tickSpacing?: number;
37
- }
38
- >;
29
+ /** set to false or null to disable tick labels */
30
+ text: boolean | null;
31
+ /** approximate number of ticks to be generated */
32
+ tickCount?: number;
33
+ /** approximate number of pixels between generated ticks */
34
+ tickSpacing?: number;
35
+ };
39
36
  </script>
40
37
 
41
38
  <script lang="ts">
@@ -47,39 +44,44 @@
47
44
  BaseMarkProps,
48
45
  RawValue,
49
46
  FacetContext,
50
- DefaultOptions
47
+ PlotDefaults,
48
+ ChannelName
51
49
  } from '../types.js';
52
50
  import autoTimeFormat from '../helpers/autoTimeFormat.js';
53
51
  import type { ConstantAccessor } from '../types.js';
54
52
  import { autoTicks } from '../helpers/autoTicks.js';
55
53
  import { resolveScaledStyles } from '../helpers/resolve.js';
56
54
 
57
- const DEFAULTS = {
55
+ let markProps: AxisYMarkProps = $props();
56
+
57
+ const DEFAULTS: Omit<AxisYMarkProps, 'data' | ChannelName> = {
58
58
  tickSize: 6,
59
59
  tickPadding: 3,
60
60
  tickFontSize: 11,
61
- axisYAnchor: 'left',
62
- ...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
61
+ anchor: 'left',
62
+ ...getContext<PlotDefaults>('svelteplot/_defaults').axis,
63
+ ...getContext<PlotDefaults>('svelteplot/_defaults').axisY
63
64
  };
64
65
 
65
- let {
66
+ const {
66
67
  ticks: magicTicks,
67
68
  data = Array.isArray(magicTicks) ? magicTicks : [],
68
69
  automatic = false,
69
70
  title,
70
- anchor = DEFAULTS.axisYAnchor as 'left' | 'right',
71
+ anchor,
71
72
  facetAnchor = 'auto',
72
73
  interval = typeof magicTicks === 'string' ? magicTicks : undefined,
73
74
  lineAnchor = 'center',
74
- tickSize = DEFAULTS.tickSize,
75
- tickFontSize = DEFAULTS.tickFontSize,
76
- tickPadding = DEFAULTS.tickPadding,
75
+ tickSize,
76
+ tickFontSize,
77
+ tickPadding,
77
78
  tickFormat,
78
79
  tickClass,
79
80
  tickCount = typeof magicTicks === 'number' ? magicTicks : undefined,
80
81
  tickSpacing,
82
+ text = true,
81
83
  ...options
82
- }: AxisYMarkProps = $props();
84
+ }: AxisYMarkProps = $derived({ ...DEFAULTS, ...markProps });
83
85
 
84
86
  const { getPlotState } = getContext<PlotContext>('svelteplot');
85
87
  const plot = $derived(getPlotState());
@@ -200,6 +202,7 @@
200
202
  {tickFontSize}
201
203
  {tickClass}
202
204
  {options}
205
+ {text}
203
206
  title={useTitle}
204
207
  {plot} />
205
208
  {/if}
@@ -1,4 +1,3 @@
1
- import type { XOR } from 'ts-essentials';
2
1
  export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target'> & {
3
2
  data?: RawValue[];
4
3
  automatic?: boolean;
@@ -15,13 +14,13 @@ export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
15
14
  tickClass?: ConstantAccessor<string>;
16
15
  /** ticks is a shorthand for defining data, tickCount or interval */
17
16
  ticks?: number | string | RawValue[];
18
- } & XOR<{
17
+ /** set to false or null to disable tick labels */
18
+ text: boolean | null;
19
19
  /** approximate number of ticks to be generated */
20
20
  tickCount?: number;
21
- }, {
22
21
  /** approximate number of pixels between generated ticks */
23
22
  tickSpacing?: number;
24
- }>;
23
+ };
25
24
  import type { BaseMarkProps, RawValue } from '../types.js';
26
25
  import type { ConstantAccessor } from '../types.js';
27
26
  /** Renders a vertical axis with labels and tick marks */
@@ -7,10 +7,13 @@
7
7
  PlotContext,
8
8
  BaseMarkProps,
9
9
  BaseRectMarkProps,
10
- ChannelAccessor
10
+ ChannelAccessor,
11
+ LinkableMarkProps,
12
+ PlotDefaults
11
13
  } from '../types.js';
12
14
 
13
15
  export type BarXMarkProps = BaseMarkProps &
16
+ LinkableMarkProps &
14
17
  BaseRectMarkProps & {
15
18
  data: DataRow[];
16
19
  x?: ChannelAccessor;
@@ -36,7 +39,20 @@
36
39
  import GroupMultiple from './helpers/GroupMultiple.svelte';
37
40
  import RectPath from './helpers/RectPath.svelte';
38
41
 
39
- let { data = [{}], class: className = null, stack, ...options }: BarXMarkProps = $props();
42
+ const DEFAULTS = {
43
+ fill: 'currentColor',
44
+ ...getContext<PlotDefaults>('svelteplot/_defaults').bar,
45
+ ...getContext<PlotDefaults>('svelteplot/_defaults').barX
46
+ };
47
+
48
+ let markProps: BarXMarkProps = $props();
49
+
50
+ const {
51
+ data = [{}],
52
+ class: className = null,
53
+ stack,
54
+ ...options
55
+ }: BarXMarkProps = $derived({ ...DEFAULTS, ...markProps });
40
56
 
41
57
  const { getPlotState } = getContext<PlotContext>('svelteplot');
42
58
  const plot = $derived(getPlotState());
@@ -1,5 +1,5 @@
1
- import type { BaseMarkProps, BaseRectMarkProps, ChannelAccessor } from '../types.js';
2
- export type BarXMarkProps = BaseMarkProps & BaseRectMarkProps & {
1
+ import type { BaseMarkProps, BaseRectMarkProps, ChannelAccessor, LinkableMarkProps } from '../types.js';
2
+ export type BarXMarkProps = BaseMarkProps & LinkableMarkProps & BaseRectMarkProps & {
3
3
  data: DataRow[];
4
4
  x?: ChannelAccessor;
5
5
  x1?: ChannelAccessor;
@@ -8,10 +8,12 @@
8
8
  BaseMarkProps,
9
9
  BaseRectMarkProps,
10
10
  ChannelAccessor,
11
- DataRow
11
+ DataRow,
12
+ PlotDefaults
12
13
  } from '../types.js';
13
14
 
14
15
  export type BarYMarkProps = BaseMarkProps &
16
+ LinkableMarkProps &
15
17
  BaseRectMarkProps & {
16
18
  data: DataRow[];
17
19
  x?: ChannelAccessor;
@@ -36,11 +38,24 @@
36
38
  import GroupMultiple from './helpers/GroupMultiple.svelte';
37
39
  import RectPath from './helpers/RectPath.svelte';
38
40
 
39
- let { data = [{}], class: className = null, stack, ...options }: BarYMarkProps = $props();
40
-
41
41
  const { getPlotState } = getContext<PlotContext>('svelteplot');
42
42
  const plot = $derived(getPlotState());
43
43
 
44
+ const DEFAULTS = {
45
+ fill: 'currentColor',
46
+ ...getContext<PlotDefaults>('svelteplot/_defaults').bar,
47
+ ...getContext<PlotDefaults>('svelteplot/_defaults').barY
48
+ };
49
+
50
+ let markProps: BarYMarkProps = $props();
51
+
52
+ const {
53
+ data = [{}],
54
+ class: className = null,
55
+ stack,
56
+ ...options
57
+ }: BarYMarkProps = $derived({ ...DEFAULTS, ...markProps });
58
+
44
59
  const args = $derived(
45
60
  stackY(
46
61
  intervalY(
@@ -1,5 +1,5 @@
1
1
  import type { BaseMarkProps, BaseRectMarkProps, ChannelAccessor, DataRow } from '../types.js';
2
- export type BarYMarkProps = BaseMarkProps & BaseRectMarkProps & {
2
+ export type BarYMarkProps = BaseMarkProps & LinkableMarkProps & BaseRectMarkProps & {
3
3
  data: DataRow[];
4
4
  x?: ChannelAccessor;
5
5
  y?: ChannelAccessor;
@@ -14,6 +14,6 @@ export type BarYMarkProps = BaseMarkProps & BaseRectMarkProps & {
14
14
  };
15
15
  import type { StackOptions } from '../transforms/stack.js';
16
16
  /** For vertical column charts using a band scale as x axis */
17
- declare const BarY: import("svelte").Component<BarYMarkProps, {}, "">;
17
+ declare const BarY: import("svelte").Component<any, {}, "">;
18
18
  type BarY = ReturnType<typeof BarY>;
19
19
  export default BarY;
@@ -13,6 +13,6 @@ export type BollingerXMarkProps = BaseMarkProps & {
13
13
  };
14
14
  import type { BaseMarkProps, ChannelAccessor, DataRow } from '../types.js';
15
15
  /** line representing a moving average and an area representing volatility as a band */
16
- declare const BollingerX: import("svelte").Component<BollingerXMarkProps, {}, "">;
16
+ declare const BollingerX: import("svelte").Component<any, {}, "">;
17
17
  type BollingerX = ReturnType<typeof BollingerX>;
18
18
  export default BollingerX;
@@ -13,6 +13,6 @@ export type BollingerYMarkProps = BaseMarkProps & {
13
13
  };
14
14
  import type { BaseMarkProps, ChannelAccessor, DataRow } from '../types.js';
15
15
  /** line representing a moving average and an area representing volatility as a band */
16
- declare const BollingerY: import("svelte").Component<BollingerYMarkProps, {}, "">;
16
+ declare const BollingerY: import("svelte").Component<any, {}, "">;
17
17
  type BollingerY = ReturnType<typeof BollingerY>;
18
18
  export default BollingerY;
@@ -1,4 +1,4 @@
1
- <script module type="ts">
1
+ <script module lang="ts">
2
2
  export type BrushXMarkProps = Omit<BrushMarkProps, 'limitDimension'>;
3
3
  </script>
4
4
 
@@ -1,4 +1,4 @@
1
- <script module type="ts">
1
+ <script module lang="ts">
2
2
  export type BrushYMarkProps = Omit<BrushMarkProps, 'limitDimension'>;
3
3
  </script>
4
4
 
@@ -12,6 +12,7 @@
12
12
  } from '../types.js';
13
13
 
14
14
  export type CellMarkProps = BaseMarkProps &
15
+ LinkableMarkProps &
15
16
  BaseRectMarkProps & {
16
17
  data: DataRecord[];
17
18
  x?: ChannelAccessor;
@@ -1,10 +1,10 @@
1
1
  import type { DataRecord, BaseMarkProps, BaseRectMarkProps, ChannelAccessor } from '../types.js';
2
- export type CellMarkProps = BaseMarkProps & BaseRectMarkProps & {
2
+ export type CellMarkProps = BaseMarkProps & LinkableMarkProps & BaseRectMarkProps & {
3
3
  data: DataRecord[];
4
4
  x?: ChannelAccessor;
5
5
  y?: ChannelAccessor;
6
6
  };
7
7
  /** For arbitrary rectangles, requires band x and y scales */
8
- declare const Cell: import("svelte").Component<CellMarkProps, {}, "">;
8
+ declare const Cell: import("svelte").Component<any, {}, "">;
9
9
  type Cell = ReturnType<typeof Cell>;
10
10
  export default Cell;
@@ -11,14 +11,14 @@
11
11
  import { range as d3Range, extent } from 'd3-array';
12
12
  import { maybeSymbol } from '../helpers/symbols.js';
13
13
 
14
- import type { DefaultOptions, PlotContext } from '../types.js';
14
+ import type { PlotDefaults, PlotContext } from '../types.js';
15
15
 
16
16
  let { class: className = null }: ColorLegendMarkProps = $props();
17
17
 
18
18
  const { getPlotState } = getContext<PlotContext>('svelteplot');
19
19
  const plot = $derived(getPlotState());
20
20
 
21
- const DEFAULTS = getContext<Partial<DefaultOptions>>('svelteplot/_defaults');
21
+ const DEFAULTS = getContext<Partial<PlotDefaults>>('svelteplot/_defaults');
22
22
 
23
23
  const legendTitle = $derived(plot.options.color.label);
24
24
  const scaleType = $derived(plot.scales.color.type);
@@ -167,6 +167,7 @@
167
167
  .swatch {
168
168
  display: inline-flex;
169
169
  align-items: center;
170
+ column-gap: 0.3rem;
170
171
  }
171
172
  .item-label {
172
173
  vertical-align: super;
@@ -10,7 +10,7 @@
10
10
  symbol?: ChannelAccessor | Snippet<[number, string]>;
11
11
  canvas?: boolean;
12
12
  dotClass?: ConstantAccessor<string>;
13
- };
13
+ } & LinkableMarkProps;
14
14
  </script>
15
15
 
16
16
  <script lang="ts">
@@ -21,8 +21,8 @@
21
21
  BaseMarkProps,
22
22
  ConstantAccessor,
23
23
  ChannelAccessor,
24
- FacetContext,
25
- PlotDefaults
24
+ PlotDefaults,
25
+ LinkableMarkProps
26
26
  } from '../types.js';
27
27
  import { resolveProp, resolveStyles } from '../helpers/resolve.js';
28
28
  import { maybeSymbol } from '../helpers/symbols.js';
@@ -33,14 +33,21 @@
33
33
  import { maybeData, isValid } from '../helpers/index.js';
34
34
  import { recordizeXY } from '../transforms/recordize.js';
35
35
  import { addEventHandlers } from './helpers/events.js';
36
+ import Anchor from './helpers/Anchor.svelte';
37
+
38
+ const DEFAULTS = {
39
+ ...getContext<PlotDefaults>('svelteplot/_defaults').dot
40
+ };
36
41
 
37
- let {
42
+ let markProps: DotMarkProps = $props();
43
+
44
+ const {
38
45
  data = [{}],
39
46
  canvas = false,
40
47
  class: className = '',
41
48
  dotClass = null,
42
49
  ...options
43
- }: DotMarkProps = $props();
50
+ }: DotMarkProps = $derived({ ...DEFAULTS, ...markProps });
44
51
 
45
52
  const { getPlotState } = getContext<PlotContext>('svelteplot');
46
53
  const plot = $derived(getPlotState());
@@ -49,10 +56,6 @@
49
56
  return d3Symbol(maybeSymbol(symbolType), size)();
50
57
  }
51
58
 
52
- const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
53
- const { dotRadius } = getContext<PlotDefaults>('svelteplot/_defaults');
54
- let testFacet = $derived(getTestFacet());
55
-
56
59
  const args = $derived(
57
60
  // todo: move sorting to Mark
58
61
  sort(
@@ -81,10 +84,10 @@
81
84
  'fillOpacity',
82
85
  'strokeOpacity'
83
86
  ]}
84
- defaults={{ r: dotRadius, symbol: 'circle' }}
87
+ defaults={{ r: 3, symbol: 'circle' }}
85
88
  {...args}>
86
89
  {#snippet children({ mark, usedScales, scaledData })}
87
- <g class="dots {className || ''}">
90
+ <g class="dot {className || ''}">
88
91
  {#if canvas}
89
92
  <DotCanvas data={scaledData} {mark} />
90
93
  {:else}
@@ -97,19 +100,21 @@
97
100
  'stroke',
98
101
  usedScales
99
102
  )}
100
- <path
101
- transform="translate({d.x}, {d.y})"
102
- d={getSymbolPath(d.symbol, d.r ** 2 * Math.PI)}
103
- class={[
104
- dotClass ? resolveProp(dotClass, d.datum, null) : null,
105
- styleClass
106
- ]}
107
- {style}
108
- use:addEventHandlers={{
109
- getPlotState,
110
- options: args,
111
- datum: d.datum
112
- }} />
103
+ <Anchor {options} datum={d.datum}>
104
+ <path
105
+ transform="translate({d.x}, {d.y})"
106
+ d={getSymbolPath(d.symbol, d.r ** 2 * Math.PI)}
107
+ class={[
108
+ dotClass ? resolveProp(dotClass, d.datum, null) : null,
109
+ styleClass
110
+ ]}
111
+ {style}
112
+ use:addEventHandlers={{
113
+ getPlotState,
114
+ options: args,
115
+ datum: d.datum
116
+ }} />
117
+ </Anchor>
113
118
  {/if}
114
119
  {/each}
115
120
  {/if}
@@ -6,9 +6,9 @@ export type DotMarkProps = BaseMarkProps & {
6
6
  symbol?: ChannelAccessor | Snippet<[number, string]>;
7
7
  canvas?: boolean;
8
8
  dotClass?: ConstantAccessor<string>;
9
- };
9
+ } & LinkableMarkProps;
10
10
  import { type Snippet } from 'svelte';
11
- import type { DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor } from '../types.js';
11
+ import type { DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor, LinkableMarkProps } from '../types.js';
12
12
  /** Creates dots or symbols at specified positions with customizable size and appearance */
13
13
  declare const Dot: import("svelte").Component<DotMarkProps, {}, "">;
14
14
  type Dot = ReturnType<typeof Dot>;
@@ -7,6 +7,7 @@
7
7
  BaseMarkProps,
8
8
  'fill' | 'stroke' | 'fillOpacity' | 'strokeOpacity'
9
9
  > &
10
+ LinkableMarkProps &
10
11
  Omit<
11
12
  BaseRectMarkProps,
12
13
  'inset' | 'insetLeft' | 'insetRight' | 'insetTop' | 'insetBottom'
@@ -27,19 +28,38 @@
27
28
  <script lang="ts">
28
29
  import Mark from '../Mark.svelte';
29
30
  import { getContext } from 'svelte';
30
- import type { PlotContext, BaseRectMarkProps } from '../types.js';
31
+ import type {
32
+ PlotContext,
33
+ BaseRectMarkProps,
34
+ LinkableMarkProps,
35
+ PlotDefaults
36
+ } from '../types.js';
31
37
  import type { BaseMarkProps } from '../types.js';
32
38
  import RectPath from './helpers/RectPath.svelte';
33
39
 
34
- let {
40
+ let markProps: FrameMarkProps = $props();
41
+
42
+ const DEFAULTS: FrameMarkProps = {
43
+ fill: 'none',
44
+ class: 'frame',
45
+ stroke: 'currentColor',
46
+ fillOpacity: 1,
47
+ strokeOpacity: 1,
48
+ ...getContext<PlotDefaults>('svelteplot/_defaults').frame
49
+ };
50
+
51
+ const {
35
52
  automatic,
36
- class: className = 'frame',
53
+ class: className,
37
54
  fill,
38
55
  stroke,
39
56
  fillOpacity,
40
57
  strokeOpacity,
41
58
  ...options
42
- }: FrameMarkProps = $props();
59
+ }: FrameMarkProps = $derived({
60
+ ...DEFAULTS,
61
+ ...markProps
62
+ });
43
63
 
44
64
  const { getPlotState } = getContext<PlotContext>('svelteplot');
45
65
  const plot = $derived(getPlotState());
@@ -1,4 +1,4 @@
1
- export type FrameMarkProps = Omit<BaseMarkProps, 'fill' | 'stroke' | 'fillOpacity' | 'strokeOpacity'> & Omit<BaseRectMarkProps, 'inset' | 'insetLeft' | 'insetRight' | 'insetTop' | 'insetBottom'> & {
1
+ export type FrameMarkProps = Omit<BaseMarkProps, 'fill' | 'stroke' | 'fillOpacity' | 'strokeOpacity'> & LinkableMarkProps & Omit<BaseRectMarkProps, 'inset' | 'insetLeft' | 'insetRight' | 'insetTop' | 'insetBottom'> & {
2
2
  fill: string;
3
3
  stroke: string;
4
4
  fillOpacity: number;
@@ -10,7 +10,7 @@ export type FrameMarkProps = Omit<BaseMarkProps, 'fill' | 'stroke' | 'fillOpacit
10
10
  insetTop?: number;
11
11
  insetBottom?: number;
12
12
  };
13
- import type { BaseRectMarkProps } from '../types.js';
13
+ import type { BaseRectMarkProps, LinkableMarkProps } from '../types.js';
14
14
  import type { BaseMarkProps } from '../types.js';
15
15
  /** Renders a simple frame around the entire plot domain */
16
16
  declare const Frame: import("svelte").Component<FrameMarkProps, {}, "">;
@@ -7,8 +7,10 @@
7
7
  geoType?: 'sphere' | 'graticule';
8
8
  dragRotate: boolean;
9
9
  canvas: boolean;
10
- href: ConstantAccessor<string>;
11
- target: ConstantAccessor<string>;
10
+ /**
11
+ * simple browser tooltip to be displayed on mouseover
12
+ */
13
+ title: ConstantAccessor<string>;
12
14
  } & BaseMarkProps &
13
15
  LinkableMarkProps;
14
16
  </script>
@@ -31,6 +33,7 @@
31
33
  import GeoCanvas from './helpers/GeoCanvas.svelte';
32
34
  import { recordize } from '../transforms/recordize.js';
33
35
  import { GEOJSON_PREFER_STROKE } from '../helpers/index.js';
36
+ import Anchor from './helpers/Anchor.svelte';
34
37
 
35
38
  const { getPlotState } = getContext<PlotContext>('svelteplot');
36
39
  const plot = $derived(getPlotState());
@@ -68,28 +71,6 @@
68
71
  channels={['fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity', 'r']}
69
72
  {...args}>
70
73
  {#snippet children({ mark, scaledData, usedScales })}
71
- {#snippet el(d)}
72
- {@const title = resolveProp(args.title, d.datum, '')}
73
- {@const geometry = resolveProp(args.geometry, d.datum, d.datum)}
74
- {@const [style, styleClass] = resolveStyles(
75
- plot,
76
- d,
77
- args,
78
- GEOJSON_PREFER_STROKE.has(geometry.type) ? 'stroke' : 'fill',
79
- usedScales
80
- )}
81
- <path
82
- d={path(geometry)}
83
- {style}
84
- class={[styleClass]}
85
- use:addEventHandlers={{
86
- getPlotState,
87
- options: args,
88
- datum: d.datum
89
- }}>
90
- {#if title}<title>{title}</title>{/if}
91
- </path>
92
- {/snippet}
93
74
  <g
94
75
  aria-label="geo"
95
76
  class={['geo', geoType && `geo-${geoType}`, className]}
@@ -99,15 +80,28 @@
99
80
  {:else}
100
81
  {#each scaledData as d, i (i)}
101
82
  {#if d.valid}
102
- {#if options.href}
103
- <a
104
- href={resolveProp(args.href, d.datum, '')}
105
- target={resolveProp(args.target, d.datum, '_self')}>
106
- {@render el(d)}
107
- </a>
108
- {:else}
109
- {@render el(d)}
110
- {/if}
83
+ <Anchor {options} datum={d.datum}>
84
+ {@const title = resolveProp(args.title, d.datum, '')}
85
+ {@const geometry = resolveProp(args.geometry, d.datum, d.datum)}
86
+ {@const [style, styleClass] = resolveStyles(
87
+ plot,
88
+ d,
89
+ args,
90
+ GEOJSON_PREFER_STROKE.has(geometry.type) ? 'stroke' : 'fill',
91
+ usedScales
92
+ )}
93
+ <path
94
+ d={path(geometry)}
95
+ {style}
96
+ class={[styleClass]}
97
+ use:addEventHandlers={{
98
+ getPlotState,
99
+ options: args,
100
+ datum: d.datum
101
+ }}>
102
+ {#if title}<title>{title}</title>{/if}
103
+ </path>
104
+ </Anchor>
111
105
  {/if}
112
106
  {/each}
113
107
  {/if}
@@ -3,8 +3,10 @@ export type GeoMarkProps = {
3
3
  geoType?: 'sphere' | 'graticule';
4
4
  dragRotate: boolean;
5
5
  canvas: boolean;
6
- href: ConstantAccessor<string>;
7
- target: ConstantAccessor<string>;
6
+ /**
7
+ * simple browser tooltip to be displayed on mouseover
8
+ */
9
+ title: ConstantAccessor<string>;
8
10
  } & BaseMarkProps & LinkableMarkProps;
9
11
  import type { DataRecord, BaseMarkProps, ConstantAccessor, LinkableMarkProps } from '../types.js';
10
12
  /** Renders geographical data using projections and GeoJSON geometries */
@@ -2,7 +2,7 @@
2
2
  Renders a geographic graticule grid with customizable step sizes
3
3
  -->
4
4
  <script module lang="ts">
5
- import type { DefaultOptions, BaseMarkProps } from '../types.js';
5
+ import type { PlotDefaults, BaseMarkProps } from '../types.js';
6
6
  export type GraticuleMarkProps = Omit<
7
7
  BaseMarkProps,
8
8
  'fill' | 'fillOpacity' | 'paintOrder' | 'title' | 'href' | 'target' | 'cursor'
@@ -20,7 +20,7 @@
20
20
 
21
21
  const DEFAULTS = {
22
22
  graticuleStep: 10,
23
- ...getContext<Partial<DefaultOptions>>('svelteplot/defaults')
23
+ ...getContext<Partial<PlotDefaults>>('svelteplot/defaults')
24
24
  };
25
25
 
26
26
  let { step = DEFAULTS.graticuleStep, stepX, stepY, ...options }: GraticuleMarkProps = $props();
@@ -13,6 +13,7 @@
13
13
  y2?: ChannelAccessor;
14
14
  interval?: number | string;
15
15
  } & BaseMarkProps &
16
+ LinkableMarkProps &
16
17
  BaseRectMarkProps;
17
18
  </script>
18
19
 
@@ -7,9 +7,9 @@ export type RectMarkProps = {
7
7
  y1?: ChannelAccessor;
8
8
  y2?: ChannelAccessor;
9
9
  interval?: number | string;
10
- } & BaseMarkProps & BaseRectMarkProps;
10
+ } & BaseMarkProps & LinkableMarkProps & BaseRectMarkProps;
11
11
  import type { DataRecord, BaseMarkProps, BaseRectMarkProps, ChannelAccessor } from '../types.js';
12
12
  /** For arbitrary rectangles, requires quantitative x and y scales */
13
- declare const Rect: import("svelte").Component<RectMarkProps, {}, "">;
13
+ declare const Rect: import("svelte").Component<any, {}, "">;
14
14
  type Rect = ReturnType<typeof Rect>;
15
15
  export default Rect;
@@ -2,8 +2,8 @@
2
2
  Geo mark with Sphere geometry object -->
3
3
 
4
4
  <script module lang="ts">
5
- import { type BaseMarkProps } from '../types.js';
6
- export type SphereMarkProps = BaseMarkProps;
5
+ import { type BaseMarkProps, type LinkableMarkProps } from '../types.js';
6
+ export type SphereMarkProps = BaseMarkProps & LinkableMarkProps;
7
7
  </script>
8
8
 
9
9
  <script lang="ts">