layerchart 2.0.0-next.2 → 2.0.0-next.20

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 (115) hide show
  1. package/dist/components/AnnotationLine.svelte +17 -29
  2. package/dist/components/AnnotationLine.svelte.d.ts +4 -2
  3. package/dist/components/AnnotationPoint.svelte +11 -13
  4. package/dist/components/AnnotationPoint.svelte.d.ts +4 -2
  5. package/dist/components/AnnotationRange.svelte +3 -3
  6. package/dist/components/Arc.svelte +2 -2
  7. package/dist/components/Axis.svelte +52 -24
  8. package/dist/components/Axis.svelte.d.ts +14 -3
  9. package/dist/components/Bar.svelte +7 -4
  10. package/dist/components/Bar.svelte.d.ts +4 -1
  11. package/dist/components/Bars.svelte +9 -6
  12. package/dist/components/Bars.svelte.d.ts +3 -3
  13. package/dist/components/Blur.svelte +20 -12
  14. package/dist/components/Blur.svelte.d.ts +2 -5
  15. package/dist/components/Calendar.svelte +10 -6
  16. package/dist/components/Calendar.svelte.d.ts +2 -1
  17. package/dist/components/Chart.svelte +2 -2
  18. package/dist/components/ClipPath.svelte +14 -9
  19. package/dist/components/Connector.svelte +2 -2
  20. package/dist/components/Connector.svelte.d.ts +1 -1
  21. package/dist/components/Ellipse.svelte +187 -0
  22. package/dist/components/Ellipse.svelte.d.ts +64 -0
  23. package/dist/components/ForceSimulation.svelte +168 -50
  24. package/dist/components/ForceSimulation.svelte.d.ts +80 -21
  25. package/dist/components/GeoEdgeFade.svelte +4 -3
  26. package/dist/components/GeoEdgeFade.svelte.d.ts +2 -2
  27. package/dist/components/GeoPath.svelte +12 -5
  28. package/dist/components/GeoPoint.svelte +1 -2
  29. package/dist/components/GeoSpline.svelte +4 -4
  30. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  31. package/dist/components/Graticule.svelte +3 -2
  32. package/dist/components/Grid.svelte +8 -7
  33. package/dist/components/Grid.svelte.d.ts +2 -1
  34. package/dist/components/Group.svelte +45 -5
  35. package/dist/components/Group.svelte.d.ts +32 -4
  36. package/dist/components/Highlight.svelte +1 -1
  37. package/dist/components/Hull.svelte +4 -4
  38. package/dist/components/Hull.svelte.d.ts +2 -2
  39. package/dist/components/Labels.svelte +6 -4
  40. package/dist/components/Labels.svelte.d.ts +2 -2
  41. package/dist/components/Legend.svelte +8 -5
  42. package/dist/components/Legend.svelte.d.ts +3 -3
  43. package/dist/components/MonthPath.svelte +14 -11
  44. package/dist/components/MonthPath.svelte.d.ts +4 -3
  45. package/dist/components/Polygon.svelte +285 -0
  46. package/dist/components/Polygon.svelte.d.ts +115 -0
  47. package/dist/components/RadialGradient.svelte +1 -3
  48. package/dist/components/Rule.svelte +3 -2
  49. package/dist/components/Spline.svelte +30 -18
  50. package/dist/components/Spline.svelte.d.ts +12 -4
  51. package/dist/components/Text.svelte +60 -48
  52. package/dist/components/Text.svelte.d.ts +6 -0
  53. package/dist/components/Treemap.svelte +63 -26
  54. package/dist/components/Treemap.svelte.d.ts +11 -11
  55. package/dist/components/Voronoi.svelte +55 -36
  56. package/dist/components/Voronoi.svelte.d.ts +5 -3
  57. package/dist/components/charts/ArcChart.svelte +2 -2
  58. package/dist/components/charts/AreaChart.svelte +9 -10
  59. package/dist/components/charts/BarChart.svelte +63 -53
  60. package/dist/components/charts/DefaultTooltip.svelte +1 -1
  61. package/dist/components/charts/LineChart.svelte +8 -5
  62. package/dist/components/charts/PieChart.svelte +2 -2
  63. package/dist/components/charts/ScatterChart.svelte +0 -2
  64. package/dist/components/charts/utils.svelte.d.ts +3 -3
  65. package/dist/components/charts/utils.svelte.js +7 -3
  66. package/dist/components/index.d.ts +4 -0
  67. package/dist/components/index.js +4 -0
  68. package/dist/components/layout/Canvas.svelte +67 -49
  69. package/dist/components/layout/Canvas.svelte.d.ts +6 -0
  70. package/dist/components/layout/Layer.svelte +6 -4
  71. package/dist/components/layout/Layer.svelte.d.ts +6 -4
  72. package/dist/components/tooltip/Tooltip.svelte +14 -7
  73. package/dist/components/tooltip/TooltipContext.svelte +25 -8
  74. package/dist/components/tooltip/TooltipContext.svelte.d.ts +1 -1
  75. package/dist/components/tooltip/TooltipHeader.svelte +5 -4
  76. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
  77. package/dist/components/tooltip/TooltipItem.svelte +5 -4
  78. package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
  79. package/dist/components/tooltip/TooltipList.svelte +1 -1
  80. package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
  81. package/dist/docs/Blockquote.svelte +3 -1
  82. package/dist/docs/Blockquote.svelte.d.ts +4 -19
  83. package/dist/docs/Code.svelte +20 -12
  84. package/dist/docs/Code.svelte.d.ts +9 -23
  85. package/dist/docs/Header1.svelte +4 -2
  86. package/dist/docs/Header1.svelte.d.ts +4 -28
  87. package/dist/docs/Json.svelte +11 -3
  88. package/dist/docs/Json.svelte.d.ts +9 -21
  89. package/dist/docs/Layout.svelte +10 -7
  90. package/dist/docs/Layout.svelte.d.ts +4 -19
  91. package/dist/docs/Link.svelte +7 -3
  92. package/dist/docs/Link.svelte.d.ts +4 -38
  93. package/dist/docs/TilesetField.svelte +20 -19
  94. package/dist/docs/TilesetField.svelte.d.ts +5 -22
  95. package/dist/docs/ViewSourceButton.svelte +7 -4
  96. package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
  97. package/dist/utils/arcText.svelte.js +4 -4
  98. package/dist/utils/canvas.d.ts +77 -0
  99. package/dist/utils/canvas.js +105 -41
  100. package/dist/utils/genData.d.ts +14 -0
  101. package/dist/utils/genData.js +24 -6
  102. package/dist/utils/path.d.ts +10 -0
  103. package/dist/utils/path.js +30 -0
  104. package/dist/utils/scales.svelte.d.ts +3 -2
  105. package/dist/utils/scales.svelte.js +7 -3
  106. package/dist/utils/shape.d.ts +43 -0
  107. package/dist/utils/shape.js +59 -0
  108. package/dist/utils/string.d.ts +49 -0
  109. package/dist/utils/string.js +4 -2
  110. package/dist/utils/ticks.d.ts +4 -4
  111. package/dist/utils/ticks.js +106 -159
  112. package/dist/utils/ticks.test.js +6 -16
  113. package/dist/utils/treemap.d.ts +1 -1
  114. package/package.json +25 -22
  115. package/dist/utils/object.js +0 -2
@@ -1,44 +1,91 @@
1
- import { type Force, type Simulation, type SimulationNodeDatum } from 'd3-force';
1
+ import { type Force, type Simulation, type SimulationLinkDatum, type SimulationNodeDatum } from 'd3-force';
2
2
  import type { Snippet } from 'svelte';
3
- type Forces = Record<string, Force<any, any>>;
3
+ export type Forces<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = Record<string, Force<NodeDatum, LinkDatum>>;
4
+ export type Data<TNode = any, TLink = any> = {
5
+ nodes: TNode[];
6
+ links?: TLink[];
7
+ };
4
8
  export type LinkPosition = {
5
9
  x1: number;
6
10
  y1: number;
7
11
  x2: number;
8
12
  y2: number;
9
13
  };
10
- export type ForceSimulationProps = {
14
+ export type OnStartEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
15
+ alpha: number;
16
+ alphaTarget: number;
17
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
18
+ };
19
+ export type OnTickEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
20
+ alpha: number;
21
+ alphaTarget: number;
22
+ nodes: NodeDatumFor<NodeDatum>[];
23
+ links: LinkDatumFor<NodeDatum, LinkDatum>[];
24
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
25
+ };
26
+ export type OnEndEvent<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
27
+ alpha: number;
28
+ alphaTarget: number;
29
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
30
+ };
31
+ /**
32
+ * Default initial alpha value of the simulation.
33
+ */
34
+ export declare const DEFAULT_ALPHA: number;
35
+ /**
36
+ * Default target alpha value for the simulation.
37
+ */
38
+ export declare const DEFAULT_ALPHA_TARGET: number;
39
+ /**
40
+ * Default alpha decay rate per tick.
41
+ *
42
+ * Formula: `1 - Math.pow(0.001, 1 / 300)`.
43
+ */
44
+ export declare const DEFAULT_ALPHA_DECAY: number;
45
+ /**
46
+ * Default minimum alpha value at which simulation stops.
47
+ */
48
+ export declare const DEFAULT_ALPHA_MIN: number;
49
+ /**
50
+ * Default velocity decay factor applied to nodes each tick.
51
+ */
52
+ export declare const DEFAULT_VELOCITY_DECAY: number;
53
+ type NodeDatumFor<NodeDatum> = NodeDatum & SimulationNodeDatum;
54
+ type LinkDatumFor<NodeDatum, LinkDatum> = LinkDatum & SimulationLinkDatum<NodeDatumFor<NodeDatum>>;
55
+ type SimulationFor<NodeDatum, LinkDatum> = Simulation<NodeDatumFor<NodeDatum>, LinkDatumFor<NodeDatum, LinkDatum>>;
56
+ export type ForceSimulationProps<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = {
11
57
  /**
12
58
  * Force simulation parameters
13
59
  */
14
- forces: Forces;
60
+ forces: Forces<NodeDatum, LinkDatum>;
15
61
  /**
16
- * An array of links to be used for position calculation.
62
+ * An object with arrays of nodes and links,
63
+ * to be used for position calculation.
17
64
  */
18
- links?: any[];
65
+ data: Data<NodeDatum, LinkDatum>;
19
66
  /**
20
67
  * Current alpha value of the simulation
21
- * @default 1
68
+ * @default DEFAULT_ALPHA
22
69
  */
23
70
  alpha?: number;
24
71
  /**
25
72
  * Target alpha value for the simulation
26
- * @default 0
73
+ * @default DEFAULT_ALPHA_TARGET
27
74
  */
28
75
  alphaTarget?: number;
29
76
  /**
30
77
  * Alpha decay rate per tick
31
- * @default 1 - Math.pow(0.001, 1 / 300)
78
+ * @default DEFAULT_ALPHA_DECAY
32
79
  */
33
80
  alphaDecay?: number;
34
81
  /**
35
82
  * Minimum alpha value at which simulation stops
36
- * @default 0.01
83
+ * @default DEFAULT_ALPHA_MIN
37
84
  */
38
85
  alphaMin?: number;
39
86
  /**
40
87
  * Velocity decay factor applied to nodes each tick
41
- * @default 0.4
88
+ * @default DEFAULT_VELOCITY_DECAY
42
89
  */
43
90
  velocityDecay?: number;
44
91
  /**
@@ -59,26 +106,38 @@ export type ForceSimulationProps = {
59
106
  /**
60
107
  * Callback function triggered when simulation starts
61
108
  */
62
- onStart?: () => void;
109
+ onStart?: (e: OnStartEvent<NodeDatum, LinkDatum | undefined>) => void;
63
110
  /**
64
111
  * Callback function triggered on each simulation tick
65
112
  */
66
- onTick?: (e: {
67
- alpha: number;
68
- alphaTarget: number;
69
- }) => void;
113
+ onTick?: (e: OnTickEvent<NodeDatum, LinkDatum | undefined>) => void;
70
114
  /**
71
115
  * Callback function triggered when simulation ends
72
116
  */
73
- onEnd?: () => void;
117
+ onEnd?: (e: OnEndEvent<NodeDatum, LinkDatum | undefined>) => void;
74
118
  children?: Snippet<[
75
119
  {
76
- nodes: any[];
77
- simulation: Simulation<SimulationNodeDatum, undefined>;
120
+ nodes: NodeDatumFor<NodeDatum>[];
121
+ links: LinkDatumFor<NodeDatum, LinkDatum>[];
78
122
  linkPositions: LinkPosition[];
123
+ simulation: SimulationFor<NodeDatum, LinkDatum>;
79
124
  }
80
125
  ]>;
81
126
  };
82
- declare const ForceSimulation: import("svelte").Component<ForceSimulationProps, {}, "alpha">;
83
- type ForceSimulation = ReturnType<typeof ForceSimulation>;
127
+ declare class __sveltets_Render<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
128
+ props(): ForceSimulationProps<NodeDatum, LinkDatum>;
129
+ events(): {};
130
+ slots(): {};
131
+ bindings(): "alpha";
132
+ exports(): {};
133
+ }
134
+ interface $$IsomorphicComponent {
135
+ new <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['events']>, ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['slots']>> & {
136
+ $$bindings?: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['bindings']>;
137
+ } & ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
138
+ <NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined>(internal: unknown, props: ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['props']> & {}): ReturnType<__sveltets_Render<NodeDatum, LinkDatum>['exports']>;
139
+ z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
140
+ }
141
+ declare const ForceSimulation: $$IsomorphicComponent;
142
+ type ForceSimulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> = InstanceType<typeof ForceSimulation<NodeDatum, LinkDatum>>;
84
143
  export default ForceSimulation;
@@ -15,7 +15,7 @@
15
15
  };
16
16
 
17
17
  export type GeoEdgeFadeProps = GeoEdgeFadePropsWithoutHTML &
18
- Without<SVGAttributes<SVGGElement>, GeoEdgeFadePropsWithoutHTML>;
18
+ Without<GroupProps, GeoEdgeFadePropsWithoutHTML>;
19
19
  </script>
20
20
 
21
21
  <script lang="ts">
@@ -23,6 +23,7 @@
23
23
  import { geoDistance } from 'd3-geo';
24
24
 
25
25
  import { getGeoContext } from './GeoContext.svelte';
26
+ import Group, { type GroupProps } from './Group.svelte';
26
27
  import { extractLayerProps } from '../utils/attributes.js';
27
28
 
28
29
  let {
@@ -55,6 +56,6 @@
55
56
  const opacity = $derived(opacityProp ?? clamper(fade(distance)));
56
57
  </script>
57
58
 
58
- <g {opacity} bind:this={ref} {...extractLayerProps(restProps, 'geo-edge-fade')}>
59
+ <Group {opacity} bind:ref {...extractLayerProps(restProps, 'geo-edge-fade')}>
59
60
  {@render children?.()}
60
- </g>
61
+ </Group>
@@ -1,6 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { Without } from '../utils/types.js';
3
- import type { SVGAttributes } from 'svelte/elements';
4
3
  export type GeoEdgeFadePropsWithoutHTML = {
5
4
  link: {
6
5
  source: [number, number];
@@ -13,7 +12,8 @@ export type GeoEdgeFadePropsWithoutHTML = {
13
12
  ref?: SVGGElement;
14
13
  children?: Snippet;
15
14
  };
16
- export type GeoEdgeFadeProps = GeoEdgeFadePropsWithoutHTML & Without<SVGAttributes<SVGGElement>, GeoEdgeFadePropsWithoutHTML>;
15
+ export type GeoEdgeFadeProps = GeoEdgeFadePropsWithoutHTML & Without<GroupProps, GeoEdgeFadePropsWithoutHTML>;
16
+ import { type GroupProps } from './Group.svelte';
17
17
  declare const GeoEdgeFade: import("svelte").Component<GeoEdgeFadeProps, {}, "ref">;
18
18
  type GeoEdgeFade = ReturnType<typeof GeoEdgeFade>;
19
19
  export default GeoEdgeFade;
@@ -5,6 +5,7 @@
5
5
  import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
6
6
  import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
7
7
  import {
8
+ geoPath as d3GeoPath,
8
9
  geoTransform as d3geoTransform,
9
10
  type GeoIdentityTransform,
10
11
  type GeoPermissibleObjects,
@@ -105,6 +106,10 @@
105
106
  const geoPath = $derived.by(() => {
106
107
  geojson;
107
108
  if (!projection) return;
109
+ // Only use geoCurvePath for custom curves (performance impact)
110
+ if (curve === curveLinearClosed) {
111
+ return d3GeoPath(projection);
112
+ }
108
113
  return geoCurvePath(projection, curve);
109
114
  });
110
115
 
@@ -157,16 +162,18 @@
157
162
  name: 'GeoPath',
158
163
  render,
159
164
  events: {
160
- click: _onClick,
161
- pointerenter: _onPointerEnter,
162
- pointermove: _onPointerMove,
163
- pointerleave: _onPointerLeave,
165
+ // Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
166
+ click: onclick ? _onClick : undefined,
167
+ pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
168
+ pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
169
+ pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
164
170
  pointerdown: restProps.onpointerdown,
165
171
  touchmove: restProps.ontouchmove,
166
172
  },
167
173
  deps: () => [
168
- geojson,
169
174
  projection,
175
+ geojson,
176
+ curve,
170
177
  fillKey.current,
171
178
  strokeKey.current,
172
179
  strokeWidth,
@@ -1,7 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from 'svelte';
3
- import type { SVGAttributes } from 'svelte/elements';
4
- import Circle, { type CircleProps, type CirclePropsWithoutHTML } from './Circle.svelte';
3
+ import Circle, { type CircleProps } from './Circle.svelte';
5
4
  import type { Without } from '../utils/types.js';
6
5
 
7
6
  export type GeoPointPropsWithoutHTML = {
@@ -42,13 +42,13 @@
42
42
  link,
43
43
  loft = 1.0,
44
44
  curve = curveNatural,
45
- splineRef: splineRefProp = $bindable(),
45
+ pathRef: pathRefProp = $bindable(),
46
46
  ...restProps
47
47
  }: GeoSplineProps = $props();
48
48
 
49
- let splineRef = $state<SVGPathElement>();
49
+ let pathRef = $state<SVGPathElement>();
50
50
  $effect.pre(() => {
51
- splineRefProp = splineRef;
51
+ pathRefProp = pathRef;
52
52
  });
53
53
 
54
54
  const geoCtx = getGeoContext();
@@ -76,7 +76,7 @@
76
76
  </script>
77
77
 
78
78
  <Spline
79
- bind:splineRef
79
+ bind:pathRef
80
80
  data={[source, middle, target]}
81
81
  x={(d) => d[0]}
82
82
  y={(d) => d[1]}
@@ -27,6 +27,6 @@ export type GeoSplinePropsWithoutHTML = {
27
27
  curve?: CurveFactory | CurveFactoryLineOnly;
28
28
  };
29
29
  export type GeoSplineProps = GeoSplinePropsWithoutHTML & Without<SplineProps, GeoSplinePropsWithoutHTML>;
30
- declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "splineRef">;
30
+ declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "pathRef">;
31
31
  type GeoSpline = ReturnType<typeof GeoSpline>;
32
32
  export default GeoSpline;
@@ -16,6 +16,7 @@
16
16
  <script lang="ts">
17
17
  import { geoGraticule } from 'd3-geo';
18
18
  import { extractLayerProps, layerClass } from '../utils/attributes.js';
19
+ import Group from './Group.svelte';
19
20
 
20
21
  let { lines, outline, step = [10, 10], ...restProps }: GraticuleProps = $props();
21
22
 
@@ -26,7 +27,7 @@
26
27
  });
27
28
  </script>
28
29
 
29
- <g class={layerClass('graticule-g')}>
30
+ <Group class={layerClass('graticule-g')}>
30
31
  <!-- TODO: Any reason to still render the single `MultiLineString` path if using `lines` and/or `outline` -->
31
32
  {#if !lines && !outline}
32
33
  <GeoPath geojson={graticule()} {...extractLayerProps(restProps, 'graticule-geo-path')} />
@@ -44,4 +45,4 @@
44
45
  {...extractLayerProps(outline, 'graticule-geo-outline')}
45
46
  />
46
47
  {/if}
47
- </g>
48
+ </Group>
@@ -77,7 +77,7 @@
77
77
  };
78
78
 
79
79
  export type GridProps<In extends Transition = Transition> = Omit<
80
- GridPropsWithoutHTML<In> & Without<SVGAttributes<SVGGElement>, GridPropsWithoutHTML<In>>,
80
+ GridPropsWithoutHTML<In> & Without<GroupProps, GridPropsWithoutHTML<In>>,
81
81
  'children'
82
82
  >;
83
83
  </script>
@@ -93,6 +93,7 @@
93
93
  import { isScaleBand } from '../utils/scales.svelte.js';
94
94
 
95
95
  import Circle from './Circle.svelte';
96
+ import Group, { type GroupProps } from './Group.svelte';
96
97
  import Line from './Line.svelte';
97
98
  import Rule from './Rule.svelte';
98
99
  import Spline from './Spline.svelte';
@@ -150,11 +151,11 @@
150
151
  );
151
152
  </script>
152
153
 
153
- <g bind:this={ref} class={cls(layerClass('grid'), classes.root, className)} {...restProps}>
154
+ <Group bind:ref class={cls(layerClass('grid'), classes.root, className)} {...restProps}>
154
155
  {#if x}
155
156
  {@const splineProps = extractLayerProps(x, 'grid-x-line')}
156
157
 
157
- <g in:transitionIn={transitionInParams} class={layerClass('grid-x')}>
158
+ <Group {transitionIn} {transitionInParams} class={layerClass('grid-x')}>
158
159
  {#each xTickVals as x (x)}
159
160
  {#if ctx.radial}
160
161
  {@const [x1, y1] = pointRadial(ctx.xScale(x), ctx.yRange[0])}
@@ -204,12 +205,12 @@
204
205
  )}
205
206
  />
206
207
  {/if}
207
- </g>
208
+ </Group>
208
209
  {/if}
209
210
 
210
211
  {#if y}
211
212
  {@const splineProps = extractLayerProps(y, 'grid-y-line')}
212
- <g in:transitionIn={transitionInParams} class={layerClass('grid-y')}>
213
+ <Group {transitionIn} {transitionInParams} class={layerClass('grid-y')}>
213
214
  {#each yTickVals as y (y)}
214
215
  {#if ctx.radial}
215
216
  {#if radialY === 'circle'}
@@ -285,6 +286,6 @@
285
286
  />
286
287
  {/if}
287
288
  {/if}
288
- </g>
289
+ </Group>
289
290
  {/if}
290
- </g>
291
+ </Group>
@@ -63,7 +63,8 @@ export type GridPropsWithoutHTML<In extends Transition = Transition> = {
63
63
  ref?: SVGGElement;
64
64
  motion?: MotionProp;
65
65
  };
66
- export type GridProps<In extends Transition = Transition> = Omit<GridPropsWithoutHTML<In> & Without<SVGAttributes<SVGGElement>, GridPropsWithoutHTML<In>>, 'children'>;
66
+ export type GridProps<In extends Transition = Transition> = Omit<GridPropsWithoutHTML<In> & Without<GroupProps, GridPropsWithoutHTML<In>>, 'children'>;
67
+ import { type GroupProps } from './Group.svelte';
67
68
  import { type TicksConfig } from '../utils/ticks.js';
68
69
  declare const Grid: import("svelte").Component<GridProps<Transition>, {}, "ref">;
69
70
  type Grid = ReturnType<typeof Grid>;
@@ -1,10 +1,10 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from 'svelte';
3
3
  import type { HTMLAttributes, TouchEventHandler } from 'svelte/elements';
4
- import type { Without } from '../utils/types.js';
5
- import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
4
+ import type { Transition, TransitionParams, Without } from '../utils/types.js';
5
+ import { createMotion, extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
6
6
 
7
- export type GroupPropsWithoutHTML = {
7
+ export type GroupPropsWithoutHTML<In extends Transition = Transition> = {
8
8
  /**
9
9
  * Translate x
10
10
  */
@@ -44,6 +44,11 @@
44
44
  */
45
45
  preventTouchMove?: boolean;
46
46
 
47
+ /**
48
+ * The opacity of the element. (0 to 1)
49
+ */
50
+ opacity?: number;
51
+
47
52
  children?: Snippet;
48
53
 
49
54
  /**
@@ -56,13 +61,28 @@
56
61
  ref?: Element;
57
62
 
58
63
  motion?: MotionProp;
64
+
65
+ /**
66
+ * Transition function for entering elements
67
+ * @default defaults to fade if the motion prop is set to tweened
68
+ */
69
+ transitionIn?: In;
70
+
71
+ /**
72
+ * Parameters for the transitionIn function
73
+ * @default { easing: cubicIn }
74
+ */
75
+ transitionInParams?: TransitionParams<In>;
59
76
  };
60
77
 
61
78
  export type GroupProps = GroupPropsWithoutHTML &
62
79
  Without<HTMLAttributes<Element>, GroupPropsWithoutHTML>;
63
80
  </script>
64
81
 
65
- <script lang="ts">
82
+ <script lang="ts" generics="T extends Transition = Transition">
83
+ import { fade } from 'svelte/transition';
84
+ import { cubicIn } from 'svelte/easing';
85
+
66
86
  import { cls } from '@layerstack/tailwind';
67
87
 
68
88
  import { getRenderContext } from './Chart.svelte';
@@ -80,7 +100,10 @@
80
100
  initialY: initialYProp,
81
101
  center = false,
82
102
  preventTouchMove = false,
103
+ opacity = undefined,
83
104
  motion,
105
+ transitionIn: transitionInProp,
106
+ transitionInParams: transitionInParamsProp,
84
107
  class: className,
85
108
  children,
86
109
  ref: refProp = $bindable(),
@@ -101,6 +124,13 @@
101
124
  const motionX = createMotion(initialX, () => trueX, motion);
102
125
  const motionY = createMotion(initialY, () => trueY, motion);
103
126
 
127
+ const transitionIn = $derived(
128
+ transitionInProp ? transitionInProp : extractTweenConfig(motion)?.options ? fade : () => {}
129
+ ) as T;
130
+ const transitionInParams = $derived(
131
+ transitionInParamsProp ? transitionInParamsProp : { easing: cubicIn }
132
+ );
133
+
104
134
  const transform = $derived.by(() => {
105
135
  if (center || x != null || y != null) {
106
136
  return `translate(${motionX.current}px, ${motionY.current}px)`;
@@ -113,7 +143,13 @@
113
143
  registerCanvasComponent({
114
144
  name: 'Group',
115
145
  render: (ctx) => {
146
+ const currentGlobalAlpha = ctx.globalAlpha;
147
+ ctx.globalAlpha = opacity ?? 1;
148
+
116
149
  ctx.translate(motionX.current ?? 0, motionY.current ?? 0);
150
+
151
+ // Restore in case it was modified by `opacity`
152
+ ctx.globalAlpha = currentGlobalAlpha;
117
153
  },
118
154
  retainState: true,
119
155
  events: {
@@ -124,7 +160,7 @@
124
160
  pointerleave: restProps.onpointerleave,
125
161
  pointerdown: restProps.onpointerdown,
126
162
  },
127
- deps: () => [motionX.current, motionY.current],
163
+ deps: () => [motionX.current, motionY.current, opacity],
128
164
  });
129
165
  }
130
166
 
@@ -143,6 +179,8 @@
143
179
  <g
144
180
  style:transform
145
181
  class={cls(layerClass('group-g'), className)}
182
+ in:transitionIn={transitionInParams}
183
+ {opacity}
146
184
  {...restProps}
147
185
  ontouchmove={handleTouchMove}
148
186
  bind:this={ref}
@@ -153,6 +191,8 @@
153
191
  <div
154
192
  bind:this={ref}
155
193
  style:transform
194
+ style:opacity
195
+ in:transitionIn={transitionInParams}
156
196
  {...restProps}
157
197
  class={cls(layerClass('group-div'), 'absolute', className)}
158
198
  ontouchmove={handleTouchMove}
@@ -1,8 +1,8 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
- import type { Without } from '../utils/types.js';
3
+ import type { Transition, TransitionParams, Without } from '../utils/types.js';
4
4
  import { type MotionProp } from '../utils/motion.svelte.js';
5
- export type GroupPropsWithoutHTML = {
5
+ export type GroupPropsWithoutHTML<In extends Transition = Transition> = {
6
6
  /**
7
7
  * Translate x
8
8
  */
@@ -36,6 +36,10 @@ export type GroupPropsWithoutHTML = {
36
36
  * @default false
37
37
  */
38
38
  preventTouchMove?: boolean;
39
+ /**
40
+ * The opacity of the element. (0 to 1)
41
+ */
42
+ opacity?: number;
39
43
  children?: Snippet;
40
44
  /**
41
45
  * A reference to the rendered DOM element, which could be
@@ -46,8 +50,32 @@ export type GroupPropsWithoutHTML = {
46
50
  */
47
51
  ref?: Element;
48
52
  motion?: MotionProp;
53
+ /**
54
+ * Transition function for entering elements
55
+ * @default defaults to fade if the motion prop is set to tweened
56
+ */
57
+ transitionIn?: In;
58
+ /**
59
+ * Parameters for the transitionIn function
60
+ * @default { easing: cubicIn }
61
+ */
62
+ transitionInParams?: TransitionParams<In>;
49
63
  };
50
64
  export type GroupProps = GroupPropsWithoutHTML & Without<HTMLAttributes<Element>, GroupPropsWithoutHTML>;
51
- declare const Group: import("svelte").Component<GroupProps, {}, "ref">;
52
- type Group = ReturnType<typeof Group>;
65
+ declare class __sveltets_Render<T extends Transition = Transition> {
66
+ props(): GroupProps;
67
+ events(): {};
68
+ slots(): {};
69
+ bindings(): "ref";
70
+ exports(): {};
71
+ }
72
+ interface $$IsomorphicComponent {
73
+ new <T extends Transition = Transition>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
74
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
75
+ } & ReturnType<__sveltets_Render<T>['exports']>;
76
+ <T extends Transition = Transition>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
77
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
78
+ }
79
+ declare const Group: $$IsomorphicComponent;
80
+ type Group<T extends Transition = Transition> = InstanceType<typeof Group<T>>;
53
81
  export default Group;
@@ -471,7 +471,7 @@
471
471
  {:else}
472
472
  <Bar
473
473
  motion={motion === 'spring' ? 'spring' : undefined}
474
- bar={highlightData}
474
+ data={highlightData}
475
475
  {...barProps}
476
476
  class={cls(!barProps.fill && 'fill-primary', barProps.class)}
477
477
  onclick={onBarClick && ((e) => onBarClick(e, { data: highlightData }))}
@@ -49,8 +49,7 @@
49
49
  ref?: SVGGElement;
50
50
  };
51
51
 
52
- export type HullProps = HullPropsWithoutHTML &
53
- Without<SVGAttributes<SVGElement>, HullPropsWithoutHTML>;
52
+ export type HullProps = HullPropsWithoutHTML & Without<GroupProps, HullPropsWithoutHTML>;
54
53
  </script>
55
54
 
56
55
  <script lang="ts">
@@ -62,6 +61,7 @@
62
61
  import { cls } from '@layerstack/tailwind';
63
62
 
64
63
  import GeoPath from './GeoPath.svelte';
64
+ import Group, { type GroupProps } from './Group.svelte';
65
65
  import Spline from './Spline.svelte';
66
66
  import { getChartContext } from './Chart.svelte';
67
67
  import { getGeoContext } from './GeoContext.svelte';
@@ -104,7 +104,7 @@
104
104
  );
105
105
  </script>
106
106
 
107
- <g {...restProps} class={cls(layerClass('hull-g'), classes.root, className)} bind:this={ref}>
107
+ <Group {...restProps} class={cls(layerClass('hull-g'), classes.root, className)} bind:ref>
108
108
  {#if geoCtx.projection}
109
109
  {@const polygon = geoVoronoi().hull(points)}
110
110
  <GeoPath
@@ -129,4 +129,4 @@
129
129
  {onpointerleave}
130
130
  />
131
131
  {/if}
132
- </g>
132
+ </Group>
@@ -1,5 +1,4 @@
1
1
  import type { Without } from '../utils/types.js';
2
- import type { SVGAttributes } from 'svelte/elements';
3
2
  import type { ComponentProps } from 'svelte';
4
3
  export type HullPropsWithoutHTML = {
5
4
  /**
@@ -34,8 +33,9 @@ export type HullPropsWithoutHTML = {
34
33
  */
35
34
  ref?: SVGGElement;
36
35
  };
37
- export type HullProps = HullPropsWithoutHTML & Without<SVGAttributes<SVGElement>, HullPropsWithoutHTML>;
36
+ export type HullProps = HullPropsWithoutHTML & Without<GroupProps, HullPropsWithoutHTML>;
38
37
  import { Delaunay } from 'd3-delaunay';
38
+ import { type GroupProps } from './Group.svelte';
39
39
  import Spline from './Spline.svelte';
40
40
  declare const Hull: import("svelte").Component<HullProps, {}, "ref">;
41
41
  type Hull = ReturnType<typeof Hull>;
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" module>
2
2
  import Text, { type TextProps } from './Text.svelte';
3
3
  import { type ComponentProps, type Snippet } from 'svelte';
4
- import { format as formatValue, type FormatType } from '@layerstack/utils';
4
+ import { format as formatValue, type FormatType, type FormatConfig } from '@layerstack/utils';
5
5
  import type { Without } from '../utils/types.js';
6
6
  import Points, { type Point } from './Points.svelte';
7
7
  import { accessor, type Accessor } from '../utils/common.js';
@@ -51,7 +51,7 @@
51
51
  /**
52
52
  * The format of the label
53
53
  */
54
- format?: FormatType;
54
+ format?: FormatType | FormatConfig;
55
55
 
56
56
  /**
57
57
  * Define unique value for {#each} `(key)` expressions to improve transitions.
@@ -73,6 +73,7 @@
73
73
 
74
74
  import { isScaleBand } from '../utils/scales.svelte.js';
75
75
  import { getChartContext } from './Chart.svelte';
76
+ import Group from './Group.svelte';
76
77
  import { extractLayerProps, layerClass } from '../utils/attributes.js';
77
78
 
78
79
  const ctx = getChartContext();
@@ -108,6 +109,7 @@
108
109
 
109
110
  const formattedValue = formatValue(
110
111
  displayValue,
112
+ // @ts-expect-error - improve types
111
113
  format ??
112
114
  (value
113
115
  ? undefined
@@ -172,7 +174,7 @@
172
174
  }
173
175
  </script>
174
176
 
175
- <g class={layerClass('labels-g')}>
177
+ <Group class={layerClass('labels-g')}>
176
178
  <Points {data} {x} {y}>
177
179
  {#snippet children({ points })}
178
180
  {#each points as point, i (key(point.data, i))}
@@ -196,4 +198,4 @@
196
198
  {/each}
197
199
  {/snippet}
198
200
  </Points>
199
- </g>
201
+ </Group>