layerchart 2.0.0-next.1 → 2.0.0-next.3

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 (266) hide show
  1. package/dist/actions/movable.d.ts +28 -0
  2. package/dist/actions/movable.js +91 -0
  3. package/dist/components/AnnotationLine.svelte +143 -0
  4. package/dist/components/AnnotationLine.svelte.d.ts +30 -0
  5. package/dist/components/AnnotationPoint.svelte +119 -0
  6. package/dist/components/AnnotationPoint.svelte.d.ts +34 -0
  7. package/dist/components/AnnotationRange.svelte +147 -0
  8. package/dist/components/AnnotationRange.svelte.d.ts +40 -0
  9. package/dist/components/Arc.svelte +344 -151
  10. package/dist/components/Arc.svelte.d.ts +138 -0
  11. package/dist/components/Area.svelte +165 -149
  12. package/dist/components/Area.svelte.d.ts +45 -0
  13. package/dist/components/Axis.svelte +283 -180
  14. package/dist/components/Axis.svelte.d.ts +117 -0
  15. package/dist/components/Bar.svelte +166 -107
  16. package/dist/components/Bar.svelte.d.ts +51 -0
  17. package/dist/components/Bars.svelte +56 -67
  18. package/dist/components/Bars.svelte.d.ts +27 -0
  19. package/dist/components/Blur.svelte +42 -12
  20. package/dist/components/Blur.svelte.d.ts +23 -21
  21. package/dist/components/Bounds.svelte +49 -19
  22. package/dist/components/Bounds.svelte.d.ts +24 -50
  23. package/dist/components/BrushContext.svelte +296 -168
  24. package/dist/components/BrushContext.svelte.d.ts +97 -65
  25. package/dist/components/Calendar.svelte +116 -59
  26. package/dist/components/Calendar.svelte.d.ts +50 -31
  27. package/dist/components/Chart.svelte +1289 -398
  28. package/dist/components/Chart.svelte.d.ts +535 -410
  29. package/dist/components/ChartClipPath.svelte +37 -15
  30. package/dist/components/ChartClipPath.svelte.d.ts +21 -19
  31. package/dist/components/Circle.svelte +124 -85
  32. package/dist/components/Circle.svelte.d.ts +52 -0
  33. package/dist/components/CircleClipPath.svelte +76 -16
  34. package/dist/components/CircleClipPath.svelte.d.ts +46 -0
  35. package/dist/components/ClipPath.svelte +71 -21
  36. package/dist/components/ClipPath.svelte.d.ts +40 -27
  37. package/dist/components/ColorRamp.svelte +75 -9
  38. package/dist/components/ColorRamp.svelte.d.ts +37 -19
  39. package/dist/components/ComputedStyles.svelte +17 -5
  40. package/dist/components/ComputedStyles.svelte.d.ts +11 -19
  41. package/dist/components/Connector.svelte +149 -0
  42. package/dist/components/Connector.svelte.d.ts +51 -0
  43. package/dist/components/Dagre.svelte +211 -122
  44. package/dist/components/Dagre.svelte.d.ts +119 -56
  45. package/dist/components/ForceSimulation.svelte +215 -90
  46. package/dist/components/ForceSimulation.svelte.d.ts +82 -35
  47. package/dist/components/Frame.svelte +33 -13
  48. package/dist/components/Frame.svelte.d.ts +13 -17
  49. package/dist/components/GeoCircle.svelte +29 -16
  50. package/dist/components/GeoCircle.svelte.d.ts +22 -24
  51. package/dist/components/GeoContext.svelte +113 -72
  52. package/dist/components/GeoContext.svelte.d.ts +49 -41
  53. package/dist/components/GeoEdgeFade.svelte +49 -13
  54. package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
  55. package/dist/components/GeoPath.svelte +157 -127
  56. package/dist/components/GeoPath.svelte.d.ts +48 -36
  57. package/dist/components/GeoPoint.svelte +52 -20
  58. package/dist/components/GeoPoint.svelte.d.ts +25 -22
  59. package/dist/components/GeoSpline.svelte +75 -26
  60. package/dist/components/GeoSpline.svelte.d.ts +29 -20
  61. package/dist/components/GeoTile.svelte +100 -49
  62. package/dist/components/GeoTile.svelte.d.ts +38 -23
  63. package/dist/components/GeoVisible.svelte +17 -9
  64. package/dist/components/GeoVisible.svelte.d.ts +10 -18
  65. package/dist/components/Graticule.svelte +30 -14
  66. package/dist/components/Graticule.svelte.d.ts +11 -52
  67. package/dist/components/Grid.svelte +230 -117
  68. package/dist/components/Grid.svelte.d.ts +71 -0
  69. package/dist/components/Group.svelte +173 -106
  70. package/dist/components/Group.svelte.d.ts +81 -0
  71. package/dist/components/Highlight.svelte +410 -308
  72. package/dist/components/Highlight.svelte.d.ts +107 -0
  73. package/dist/components/Hull.svelte +97 -46
  74. package/dist/components/Hull.svelte.d.ts +40 -30
  75. package/dist/components/Labels.svelte +127 -47
  76. package/dist/components/Labels.svelte.d.ts +70 -27
  77. package/dist/components/Legend.svelte +374 -190
  78. package/dist/components/Legend.svelte.d.ts +95 -44
  79. package/dist/components/Line.svelte +163 -125
  80. package/dist/components/Line.svelte.d.ts +75 -0
  81. package/dist/components/LinearGradient.svelte +153 -78
  82. package/dist/components/LinearGradient.svelte.d.ts +66 -31
  83. package/dist/components/Link.svelte +160 -104
  84. package/dist/components/Link.svelte.d.ts +54 -0
  85. package/dist/components/Marker.svelte +100 -39
  86. package/dist/components/Marker.svelte.d.ts +59 -27
  87. package/dist/components/MarkerWrapper.svelte +35 -0
  88. package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
  89. package/dist/components/MonthPath.svelte +65 -20
  90. package/dist/components/MonthPath.svelte.d.ts +23 -17
  91. package/dist/components/MotionPath.svelte +80 -24
  92. package/dist/components/MotionPath.svelte.d.ts +46 -27
  93. package/dist/components/Pack.svelte +53 -17
  94. package/dist/components/Pack.svelte.d.ts +42 -21
  95. package/dist/components/Partition.svelte +64 -22
  96. package/dist/components/Partition.svelte.d.ts +49 -26
  97. package/dist/components/Pattern.svelte +297 -11
  98. package/dist/components/Pattern.svelte.d.ts +103 -19
  99. package/dist/components/Pie.svelte +122 -76
  100. package/dist/components/Pie.svelte.d.ts +65 -51
  101. package/dist/components/Point.svelte +20 -9
  102. package/dist/components/Point.svelte.d.ts +16 -20
  103. package/dist/components/Points.svelte +148 -137
  104. package/dist/components/Points.svelte.d.ts +45 -34
  105. package/dist/components/RadialGradient.svelte +143 -70
  106. package/dist/components/RadialGradient.svelte.d.ts +69 -31
  107. package/dist/components/Rect.svelte +121 -102
  108. package/dist/components/Rect.svelte.d.ts +36 -0
  109. package/dist/components/RectClipPath.svelte +82 -18
  110. package/dist/components/RectClipPath.svelte.d.ts +55 -0
  111. package/dist/components/Rule.svelte +107 -63
  112. package/dist/components/Rule.svelte.d.ts +40 -19
  113. package/dist/components/Sankey.svelte +132 -55
  114. package/dist/components/Sankey.svelte.d.ts +61 -31
  115. package/dist/components/Spline.svelte +281 -218
  116. package/dist/components/Spline.svelte.d.ts +95 -0
  117. package/dist/components/Text.svelte +437 -176
  118. package/dist/components/Text.svelte.d.ts +130 -0
  119. package/dist/components/Threshold.svelte +48 -16
  120. package/dist/components/Threshold.svelte.d.ts +29 -31
  121. package/dist/components/TileImage.svelte +103 -30
  122. package/dist/components/TileImage.svelte.d.ts +48 -23
  123. package/dist/components/TransformContext.svelte +365 -171
  124. package/dist/components/TransformControls.svelte +50 -26
  125. package/dist/components/TransformControls.svelte.d.ts +27 -19
  126. package/dist/components/Tree.svelte +74 -33
  127. package/dist/components/Tree.svelte.d.ts +42 -30
  128. package/dist/components/Treemap.svelte +119 -42
  129. package/dist/components/Treemap.svelte.d.ts +75 -27
  130. package/dist/components/Voronoi.svelte +108 -76
  131. package/dist/components/Voronoi.svelte.d.ts +40 -41
  132. package/dist/components/charts/ArcChart.svelte +464 -0
  133. package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
  134. package/dist/components/charts/AreaChart.svelte +450 -393
  135. package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
  136. package/dist/components/charts/BarChart.svelte +454 -389
  137. package/dist/components/charts/BarChart.svelte.d.ts +76 -0
  138. package/dist/components/charts/ChartAnnotations.svelte +37 -0
  139. package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
  140. package/dist/components/charts/DefaultTooltip.svelte +60 -0
  141. package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
  142. package/dist/components/charts/LineChart.svelte +369 -314
  143. package/dist/components/charts/LineChart.svelte.d.ts +53 -0
  144. package/dist/components/charts/PieChart.svelte +458 -316
  145. package/dist/components/charts/PieChart.svelte.d.ts +137 -353
  146. package/dist/components/charts/ScatterChart.svelte +334 -296
  147. package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
  148. package/dist/components/charts/index.d.ts +8 -0
  149. package/dist/components/charts/index.js +7 -0
  150. package/dist/components/charts/types.d.ts +253 -0
  151. package/dist/components/charts/utils.svelte.d.ts +30 -0
  152. package/dist/components/charts/utils.svelte.js +55 -0
  153. package/dist/components/index.d.ts +76 -4
  154. package/dist/components/index.js +76 -5
  155. package/dist/components/layout/Canvas.svelte +321 -155
  156. package/dist/components/layout/Canvas.svelte.d.ts +104 -55
  157. package/dist/components/layout/Html.svelte +82 -42
  158. package/dist/components/layout/Html.svelte.d.ts +39 -28
  159. package/dist/components/layout/Layer.svelte +39 -0
  160. package/dist/components/layout/Layer.svelte.d.ts +17 -0
  161. package/dist/components/layout/Svg.svelte +122 -70
  162. package/dist/components/layout/Svg.svelte.d.ts +53 -34
  163. package/dist/components/layout/WebGL.svelte +135 -0
  164. package/dist/components/layout/WebGL.svelte.d.ts +50 -0
  165. package/dist/components/tooltip/Tooltip.svelte +246 -78
  166. package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
  167. package/dist/components/tooltip/TooltipContext.svelte +409 -271
  168. package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
  169. package/dist/components/tooltip/TooltipHeader.svelte +100 -11
  170. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
  171. package/dist/components/tooltip/TooltipItem.svelte +167 -27
  172. package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
  173. package/dist/components/tooltip/TooltipList.svelte +22 -3
  174. package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
  175. package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
  176. package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
  177. package/dist/components/tooltip/index.d.ts +6 -0
  178. package/dist/components/tooltip/index.js +6 -0
  179. package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
  180. package/dist/components/tooltip/tooltipMetaContext.js +139 -0
  181. package/dist/components/types.d.ts +1 -0
  182. package/dist/components/types.js +1 -0
  183. package/dist/docs/Blockquote.svelte.d.ts +18 -14
  184. package/dist/docs/Code.svelte.d.ts +26 -22
  185. package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
  186. package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
  187. package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
  188. package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
  189. package/dist/docs/CurveMenuField.svelte +14 -3
  190. package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
  191. package/dist/docs/GeoDebug.svelte +47 -42
  192. package/dist/docs/GeoDebug.svelte.d.ts +4 -16
  193. package/dist/docs/Header1.svelte.d.ts +27 -16
  194. package/dist/docs/Json.svelte.d.ts +20 -16
  195. package/dist/docs/Layout.svelte.d.ts +18 -13
  196. package/dist/docs/Link.svelte.d.ts +33 -21
  197. package/dist/docs/PathDataMenuField.svelte +14 -10
  198. package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
  199. package/dist/docs/Preview.svelte +20 -7
  200. package/dist/docs/Preview.svelte.d.ts +12 -22
  201. package/dist/docs/TilesetField.svelte.d.ts +21 -17
  202. package/dist/docs/TransformDebug.svelte +5 -6
  203. package/dist/docs/TransformDebug.svelte.d.ts +18 -14
  204. package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
  205. package/dist/types/d3-shape-extentions.d.ts +7 -0
  206. package/dist/utils/afterTick.d.ts +5 -0
  207. package/dist/utils/afterTick.js +8 -0
  208. package/dist/utils/arcText.svelte.d.ts +57 -0
  209. package/dist/utils/arcText.svelte.js +262 -0
  210. package/dist/utils/array.d.ts +9 -1
  211. package/dist/utils/array.js +13 -0
  212. package/dist/utils/attributes.d.ts +29 -0
  213. package/dist/utils/attributes.js +40 -0
  214. package/dist/utils/canvas.js +47 -10
  215. package/dist/utils/chart.d.ts +78 -0
  216. package/dist/utils/chart.js +512 -0
  217. package/dist/utils/color.d.ts +1 -0
  218. package/dist/utils/color.js +8 -0
  219. package/dist/utils/common.d.ts +3 -5
  220. package/dist/utils/common.js +3 -2
  221. package/dist/utils/connectorUtils.d.ts +21 -0
  222. package/dist/utils/connectorUtils.js +111 -0
  223. package/dist/utils/createId.d.ts +7 -0
  224. package/dist/utils/createId.js +9 -0
  225. package/dist/utils/debug.d.ts +1 -0
  226. package/dist/utils/debug.js +84 -0
  227. package/dist/utils/filterObject.d.ts +9 -0
  228. package/dist/utils/filterObject.js +12 -0
  229. package/dist/utils/graph/dagre.d.ts +34 -0
  230. package/dist/utils/graph/dagre.js +78 -0
  231. package/dist/utils/graph/dagre.test.d.ts +1 -0
  232. package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
  233. package/dist/utils/graph/sankey.d.ts +28 -0
  234. package/dist/utils/{graph.js → graph/sankey.js} +13 -41
  235. package/dist/utils/index.d.ts +3 -1
  236. package/dist/utils/index.js +3 -1
  237. package/dist/utils/key.svelte.d.ts +3 -0
  238. package/dist/utils/key.svelte.js +11 -0
  239. package/dist/utils/legendPayload.d.ts +7 -0
  240. package/dist/utils/legendPayload.js +8 -0
  241. package/dist/utils/motion.svelte.d.ts +140 -0
  242. package/dist/utils/motion.svelte.js +180 -0
  243. package/dist/utils/motion.test.d.ts +1 -0
  244. package/dist/utils/motion.test.js +213 -0
  245. package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
  246. package/dist/utils/rect.svelte.js +105 -0
  247. package/dist/utils/scales.svelte.d.ts +90 -0
  248. package/dist/utils/{scales.js → scales.svelte.js} +100 -39
  249. package/dist/utils/stack.d.ts +2 -3
  250. package/dist/utils/stack.js +1 -1
  251. package/dist/utils/string.js +87 -0
  252. package/dist/utils/ticks.d.ts +8 -2
  253. package/dist/utils/ticks.js +28 -0
  254. package/dist/utils/ticks.test.d.ts +1 -0
  255. package/dist/utils/ticks.test.js +67 -0
  256. package/dist/utils/types.d.ts +81 -0
  257. package/package.json +21 -19
  258. package/dist/components/ChartContext.svelte +0 -295
  259. package/dist/components/ChartContext.svelte.d.ts +0 -139
  260. package/dist/components/TransformContext.svelte.d.ts +0 -158
  261. package/dist/stores/motionStore.d.ts +0 -30
  262. package/dist/stores/motionStore.js +0 -62
  263. package/dist/utils/graph.d.ts +0 -37
  264. package/dist/utils/rect.js +0 -107
  265. package/dist/utils/scales.d.ts +0 -66
  266. /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
@@ -1,25 +1,89 @@
1
- <script lang="ts">
2
- import type { ComponentProps } from 'svelte';
3
- import { uniqueId } from '@layerstack/utils';
1
+ <script lang="ts" module>
2
+ import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
3
+ import type { Without } from '../utils/types.js';
4
+ import type { SVGAttributes } from 'svelte/elements';
5
+ import type { Snippet } from 'svelte';
4
6
 
5
- import ClipPath from './ClipPath.svelte';
6
- import Rect from './Rect.svelte';
7
+ export type BaseRectClipPathPropsWithoutHTML = {
8
+ /**
9
+ * A unique id for the clipPath.
10
+ */
11
+ id?: string;
12
+
13
+ /**
14
+ * The x position of the clipPath.
15
+ *
16
+ * @default 0
17
+ */
18
+ x?: number;
19
+
20
+ /**
21
+ * The y position of the clipPath.
22
+ *
23
+ * @default 0
24
+ */
25
+ y?: number;
26
+
27
+ /**
28
+ * The width of the clipPath.
29
+ *
30
+ * @required
31
+ */
32
+ width: number;
33
+
34
+ /**
35
+ * The height of the clipPath.
36
+ *
37
+ * @required
38
+ */
39
+ height: number;
40
+
41
+ /**
42
+ * Whether to disable clipping (show all).
43
+ *
44
+ * @default false
45
+ */
46
+ disabled?: boolean;
7
47
 
8
- /** Unique id for clipPath */
9
- export let id: string = uniqueId('clipPath-');
48
+ /**
49
+ * The default children snippet which provides
50
+ * the id and url for the clipPath.
51
+ */
52
+ children?: Snippet<[{ id: string; url: string }]>;
53
+
54
+ motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
55
+ };
56
+
57
+ export type RectClipPathPropsWithoutHTML = BaseRectClipPathPropsWithoutHTML &
58
+ Without<RectPropsWithoutHTML, BaseRectClipPathPropsWithoutHTML>;
59
+
60
+ export type RectClipPathProps = RectClipPathPropsWithoutHTML &
61
+ Without<SVGAttributes<SVGElement>, RectClipPathPropsWithoutHTML>;
62
+ </script>
63
+
64
+ <script lang="ts">
65
+ import ClipPath from './ClipPath.svelte';
66
+ import { createId } from '../utils/createId.js';
67
+ import { extractLayerProps } from '../utils/attributes.js';
68
+ import type { MotionProp } from '../utils/motion.svelte.js';
10
69
 
11
- export let x: number = 0;
12
- export let y: number = 0;
13
- export let width: number;
14
- export let height: number;
15
- export let spring: ComponentProps<Rect>['spring'] = undefined;
16
- export let tweened: ComponentProps<Rect>['tweened'] = undefined;
70
+ const uid = $props.id();
17
71
 
18
- /** Disable clipping (show all) */
19
- export let disabled: boolean = false;
72
+ let {
73
+ id = createId('clipPath-', uid),
74
+ x = 0,
75
+ y = 0,
76
+ disabled = false,
77
+ children: childrenProp,
78
+ ...restProps
79
+ }: RectClipPathProps = $props();
20
80
  </script>
21
81
 
22
- <ClipPath {id} {disabled} let:url>
23
- <Rect slot="clip" {x} {y} {width} {height} {spring} {tweened} {...$$restProps} />
24
- <slot {id} {url} />
82
+ <ClipPath {id} {disabled}>
83
+ {#snippet clip()}
84
+ <Rect {x} {y} {...extractLayerProps(restProps, 'clip-path-rect')} />
85
+ {/snippet}
86
+ {#snippet children({ url })}
87
+ {@render childrenProp?.({ id, url })}
88
+ {/snippet}
25
89
  </ClipPath>
@@ -0,0 +1,55 @@
1
+ import { type RectPropsWithoutHTML } from './Rect.svelte';
2
+ import type { Without } from '../utils/types.js';
3
+ import type { SVGAttributes } from 'svelte/elements';
4
+ import type { Snippet } from 'svelte';
5
+ export type BaseRectClipPathPropsWithoutHTML = {
6
+ /**
7
+ * A unique id for the clipPath.
8
+ */
9
+ id?: string;
10
+ /**
11
+ * The x position of the clipPath.
12
+ *
13
+ * @default 0
14
+ */
15
+ x?: number;
16
+ /**
17
+ * The y position of the clipPath.
18
+ *
19
+ * @default 0
20
+ */
21
+ y?: number;
22
+ /**
23
+ * The width of the clipPath.
24
+ *
25
+ * @required
26
+ */
27
+ width: number;
28
+ /**
29
+ * The height of the clipPath.
30
+ *
31
+ * @required
32
+ */
33
+ height: number;
34
+ /**
35
+ * Whether to disable clipping (show all).
36
+ *
37
+ * @default false
38
+ */
39
+ disabled?: boolean;
40
+ /**
41
+ * The default children snippet which provides
42
+ * the id and url for the clipPath.
43
+ */
44
+ children?: Snippet<[{
45
+ id: string;
46
+ url: string;
47
+ }]>;
48
+ motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
49
+ };
50
+ export type RectClipPathPropsWithoutHTML = BaseRectClipPathPropsWithoutHTML & Without<RectPropsWithoutHTML, BaseRectClipPathPropsWithoutHTML>;
51
+ export type RectClipPathProps = RectClipPathPropsWithoutHTML & Without<SVGAttributes<SVGElement>, RectClipPathPropsWithoutHTML>;
52
+ import type { MotionProp } from '../utils/motion.svelte.js';
53
+ declare const RectClipPath: import("svelte").Component<RectClipPathProps, {}, "">;
54
+ type RectClipPath = ReturnType<typeof RectClipPath>;
55
+ export default RectClipPath;
@@ -1,42 +1,78 @@
1
+ <script lang="ts" module>
2
+ import type { Without } from '../utils/types.js';
3
+ import type { SVGAttributes } from 'svelte/elements';
4
+
5
+ export type BaseRulePropsWithoutHTML = {
6
+ /**
7
+ * Create a vertical `x` line
8
+ * - If true or 'left', will draw at chart left (xRange[0])
9
+ * - If 'right', will draw at chart right (xRange[1])
10
+ * - Use `0` for baseline (yScale(0))
11
+ * - Use number | Date value for annotation (yScale(value))
12
+ *
13
+ * @default false
14
+ */
15
+ x?: number | Date | boolean | 'left' | 'right';
16
+
17
+ /**
18
+ * Pixel offset to apply to `x` coordinate
19
+ *
20
+ * @default 0
21
+ */
22
+ xOffset?: number;
23
+
24
+ /**
25
+ * Create a horizontal `y` line
26
+ * - If true or 'bottom', will draw at chart bottom (yRange[0])
27
+ * - If 'top', will draw at chart top (yRange[1])
28
+ * - Use `0` for baseline (xScale(0))
29
+ * - Use number | Date value for annotation (xScale(value))
30
+ *
31
+ * @default false
32
+ */
33
+ y?: number | Date | boolean | 'top' | 'bottom';
34
+
35
+ /**
36
+ * Pixel offset to apply to `y` coordinate
37
+ * @default 0
38
+ */
39
+ yOffset?: number;
40
+ };
41
+
42
+ export type RulePropsWithoutHTML = BaseRulePropsWithoutHTML &
43
+ Without<Partial<LinePropsWithoutHTML>, BaseRulePropsWithoutHTML>;
44
+
45
+ export type RuleProps = RulePropsWithoutHTML &
46
+ Without<SVGAttributes<SVGElement>, RulePropsWithoutHTML>;
47
+ </script>
48
+
1
49
  <script lang="ts">
2
50
  import { extent } from 'd3-array';
3
51
  import { pointRadial } from 'd3-shape';
4
52
  import { cls } from '@layerstack/tailwind';
5
53
 
6
- import { chartContext } from './ChartContext.svelte';
7
54
  import Circle from './Circle.svelte';
8
- import Line from './Line.svelte';
9
-
10
- const { xScale, yScale, xRange, yRange, radial } = chartContext();
11
-
12
- $: [xRangeMin, xRangeMax] = extent<number | Date>($xRange);
13
- $: [yRangeMin, yRangeMax] = extent<number | Date>($yRange);
14
-
15
- /**
16
- * Create a vertical `x` line
17
- * - If true or 'left', will draw at chart left (xRange[0])
18
- * - If 'right', will draw at chart right (xRange[1])
19
- * - Use `0` for baseline (yScale(0))
20
- * - Use number | Date value for annotation (yScale(value))
21
- */
22
- export let x: number | Date | boolean | 'left' | 'right' = false;
23
-
24
- /** Pixel offset to apply to `x` coordinate */
25
- export let xOffset = 0;
26
-
27
- /**
28
- * Create a horizontal `y` line
29
- * - If true or 'bottom', will draw at chart bottom (yRange[0])
30
- * - If 'top', will draw at chart top (yRange[1])
31
- * - Use `0` for baseline (xScale(0))
32
- * - Use number | Date value for annotation (xScale(value))
33
- */
34
- export let y: number | Date | boolean | 'top' | 'bottom' = false;
35
-
36
- /** Pixel offset to apply to `y` coordinate */
37
- export let yOffset = 0;
38
-
39
- $: showRule = (value: typeof x | typeof y, axis: 'x' | 'y') => {
55
+ import Group from './Group.svelte';
56
+ import Line, { type LinePropsWithoutHTML } from './Line.svelte';
57
+ import { getChartContext } from './Chart.svelte';
58
+ import { layerClass } from '../utils/attributes.js';
59
+
60
+ let {
61
+ x = false,
62
+ xOffset = 0,
63
+ y = false,
64
+ yOffset = 0,
65
+ class: className,
66
+ children,
67
+ ...restProps
68
+ }: RuleProps = $props();
69
+
70
+ const ctx = getChartContext();
71
+
72
+ const xRangeMinMax = $derived(extent<number | Date>(ctx.xRange));
73
+ const yRangeMinMax = $derived(extent<number | Date>(ctx.yRange));
74
+
75
+ function showRule(value: typeof x | typeof y, axis: 'x' | 'y') {
40
76
  switch (typeof value) {
41
77
  case 'boolean':
42
78
  return value;
@@ -44,70 +80,78 @@
44
80
  return true;
45
81
  default:
46
82
  if (axis === 'x') {
47
- return $xScale(value) >= xRangeMin! && $xScale(value) <= xRangeMax!;
83
+ return ctx.xScale(value) >= xRangeMinMax[0]! && ctx.xScale(value) <= xRangeMinMax[1]!;
48
84
  } else {
49
- return $yScale(value) >= yRangeMin! && $yScale(value) <= yRangeMax!;
85
+ return ctx.yScale(value) >= yRangeMinMax[0]! && ctx.yScale(value) <= yRangeMinMax[1]!;
50
86
  }
51
87
  }
52
- };
88
+ }
53
89
  </script>
54
90
 
55
- <g class="rule">
91
+ <Group class={layerClass('rule-g')}>
56
92
  {#if showRule(x, 'x')}
57
93
  {@const xCoord =
58
- x === true || x === 'left' ? xRangeMin : x === 'right' ? xRangeMax : $xScale(x) + xOffset}
94
+ x === true || x === 'left'
95
+ ? xRangeMinMax[0]
96
+ : x === 'right'
97
+ ? xRangeMinMax[1]
98
+ : ctx.xScale(x) + xOffset}
59
99
 
60
- {#if $radial}
61
- {@const [x1, y1] = pointRadial(xCoord, Number(yRangeMin))}
62
- {@const [x2, y2] = pointRadial(xCoord, Number(yRangeMax))}
100
+ {#if ctx.radial}
101
+ {@const [x1, y1] = pointRadial(xCoord, Number(yRangeMinMax[0]))}
102
+ {@const [x2, y2] = pointRadial(xCoord, Number(yRangeMinMax[1]))}
63
103
 
64
104
  <Line
105
+ {...restProps}
65
106
  {x1}
66
107
  {y1}
67
108
  {x2}
68
109
  {y2}
69
- {...$$restProps}
70
- class={cls('stroke-surface-content/10', $$props.class)}
110
+ class={cls(layerClass('rule-x-radial-line'), 'stroke-surface-content/10', className)}
71
111
  />
72
112
  {:else}
73
113
  <Line
114
+ {...restProps}
74
115
  x1={xCoord}
75
116
  x2={xCoord}
76
- y1={$yRange[0] || 0}
77
- y2={$yRange[1] || 0}
78
- {...$$restProps}
79
- class={cls('stroke-surface-content/50', $$props.class)}
117
+ y1={ctx.yRange[0] || 0}
118
+ y2={ctx.yRange[1] || 0}
119
+ class={cls(layerClass('rule-x-line'), 'stroke-surface-content/50', className)}
80
120
  />
81
121
  {/if}
82
122
  {/if}
83
123
 
84
124
  {#if showRule(y, 'y')}
85
- {#if $radial}
125
+ {#if ctx.radial}
86
126
  <Circle
87
127
  r={y === true || y === 'bottom'
88
- ? yRangeMax
128
+ ? yRangeMinMax[1]
89
129
  : y === 'top'
90
- ? yRangeMin
91
- : $yScale(y) + yOffset}
92
- class={cls('fill-none stroke-surface-content/50', $$props.class)}
130
+ ? yRangeMinMax[0]
131
+ : ctx.yScale(y) + yOffset}
132
+ class={cls(
133
+ layerClass('rule-y-radial-circle'),
134
+ 'fill-none stroke-surface-content/50',
135
+ className
136
+ )}
93
137
  />
94
138
  {:else}
95
139
  <Line
96
- x1={$xRange[0] || 0}
97
- x2={$xRange[1] || 0}
140
+ {...restProps}
141
+ x1={ctx.xRange[0] || 0}
142
+ x2={ctx.xRange[1] || 0}
98
143
  y1={y === true || y === 'bottom'
99
- ? yRangeMax
144
+ ? yRangeMinMax[1]
100
145
  : y === 'top'
101
- ? yRangeMin
102
- : $yScale(y) + yOffset}
146
+ ? yRangeMinMax[0]
147
+ : ctx.yScale(y) + yOffset}
103
148
  y2={y === true || y === 'bottom'
104
- ? yRangeMax
149
+ ? yRangeMinMax[1]
105
150
  : y === 'top'
106
- ? yRangeMin
107
- : $yScale(y) + yOffset}
108
- {...$$restProps}
109
- class={cls('stroke-surface-content/50', $$props.class)}
151
+ ? yRangeMinMax[0]
152
+ : ctx.yScale(y) + yOffset}
153
+ class={cls(layerClass('rule-y-line'), 'stroke-surface-content/50', className)}
110
154
  />
111
155
  {/if}
112
156
  {/if}
113
- </g>
157
+ </Group>
@@ -1,20 +1,41 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- [x: string]: any;
5
- x?: (number | Date | boolean | "left" | "right") | undefined;
6
- xOffset?: number | undefined;
7
- y?: (number | Date | boolean | "top" | "bottom") | undefined;
8
- yOffset?: number | undefined;
9
- };
10
- events: {
11
- [evt: string]: CustomEvent<any>;
12
- };
13
- slots: {};
1
+ import type { Without } from '../utils/types.js';
2
+ import type { SVGAttributes } from 'svelte/elements';
3
+ export type BaseRulePropsWithoutHTML = {
4
+ /**
5
+ * Create a vertical `x` line
6
+ * - If true or 'left', will draw at chart left (xRange[0])
7
+ * - If 'right', will draw at chart right (xRange[1])
8
+ * - Use `0` for baseline (yScale(0))
9
+ * - Use number | Date value for annotation (yScale(value))
10
+ *
11
+ * @default false
12
+ */
13
+ x?: number | Date | boolean | 'left' | 'right';
14
+ /**
15
+ * Pixel offset to apply to `x` coordinate
16
+ *
17
+ * @default 0
18
+ */
19
+ xOffset?: number;
20
+ /**
21
+ * Create a horizontal `y` line
22
+ * - If true or 'bottom', will draw at chart bottom (yRange[0])
23
+ * - If 'top', will draw at chart top (yRange[1])
24
+ * - Use `0` for baseline (xScale(0))
25
+ * - Use number | Date value for annotation (xScale(value))
26
+ *
27
+ * @default false
28
+ */
29
+ y?: number | Date | boolean | 'top' | 'bottom';
30
+ /**
31
+ * Pixel offset to apply to `y` coordinate
32
+ * @default 0
33
+ */
34
+ yOffset?: number;
14
35
  };
15
- export type RuleProps = typeof __propDef.props;
16
- export type RuleEvents = typeof __propDef.events;
17
- export type RuleSlots = typeof __propDef.slots;
18
- export default class Rule extends SvelteComponentTyped<RuleProps, RuleEvents, RuleSlots> {
19
- }
20
- export {};
36
+ export type RulePropsWithoutHTML = BaseRulePropsWithoutHTML & Without<Partial<LinePropsWithoutHTML>, BaseRulePropsWithoutHTML>;
37
+ export type RuleProps = RulePropsWithoutHTML & Without<SVGAttributes<SVGElement>, RulePropsWithoutHTML>;
38
+ import { type LinePropsWithoutHTML } from './Line.svelte';
39
+ declare const Rule: import("svelte").Component<RuleProps, {}, "">;
40
+ type Rule = ReturnType<typeof Rule>;
41
+ export default Rule;
@@ -1,3 +1,81 @@
1
+ <script lang="ts" module>
2
+ import type { Snippet } from 'svelte';
3
+
4
+ export type NodeExtraProperties = Record<string, any>;
5
+
6
+ export type SankeyProps = {
7
+ /**
8
+ * The function to get the nodes from the data.
9
+ * @default (d: any) => d.nodes
10
+ */
11
+ nodes?: (d: any) => any;
12
+
13
+ /**
14
+ * The function to get the node ID from the node data.
15
+ *
16
+ * @default (d: any) => d.index
17
+ */
18
+ nodeId?: (d: any) => any;
19
+ /**
20
+ * @see https://github.com/d3/d3-sankey#alignments
21
+ *
22
+ * @default sankeyJustify
23
+ */
24
+ nodeAlign?:
25
+ | ((node: SankeyNode<any, any>, n: number) => number)
26
+ | 'left'
27
+ | 'right'
28
+ | 'center'
29
+ | 'justify';
30
+
31
+ /**
32
+ * The width of the nodes.
33
+ *
34
+ * @default 4
35
+ */
36
+ nodeWidth?: number;
37
+
38
+ /**
39
+ * The padding between nodes.
40
+ *
41
+ * @default 10
42
+ */
43
+ nodePadding?: number;
44
+
45
+ /**
46
+ * The function to sort the nodes.
47
+ */
48
+ nodeSort?: (a: SankeyNode<any, any>, b: SankeyNode<any, any>) => number | undefined;
49
+
50
+ /**
51
+ * The function to get the links from the data.
52
+ *
53
+ * @default (d: any) => d.links
54
+ */
55
+ links?: (d: any) => any;
56
+
57
+ /**
58
+ * The function to sort the links.
59
+ *
60
+ */
61
+ linkSort?: (a: SankeyLink<any, any>, b: SankeyLink<any, any>) => number | undefined;
62
+
63
+ /**
64
+ * A function to be called when the data is updated.
65
+ */
66
+ onUpdate?: (data: SankeyGraph<{}, {}>) => void;
67
+
68
+ children?: Snippet<
69
+ [
70
+ {
71
+ nodes: SankeyNode<NodeExtraProperties, any>[];
72
+ links: SankeyNode<NodeExtraProperties, any>[];
73
+ },
74
+ ]
75
+ >;
76
+ };
77
+ </script>
78
+
1
79
  <script lang="ts">
2
80
  // https://github.com/d3/d3-sankey
3
81
  import {
@@ -8,62 +86,61 @@
8
86
  sankeyJustify,
9
87
  type SankeyNode,
10
88
  type SankeyLink,
89
+ type SankeyGraph,
11
90
  } from 'd3-sankey';
12
91
 
13
- import { chartContext } from './ChartContext.svelte';
14
-
15
- const { data, width, height } = chartContext();
16
-
17
- export let nodes = (d: any) => d.nodes;
18
- export let nodeId = (d: any) => d.index;
19
- /**
20
- * see: https://github.com/d3/d3-sankey#alignments
21
- */
22
- export let nodeAlign:
23
- | ((node: SankeyNode<any, any>, n: number) => number)
24
- | 'left'
25
- | 'right'
26
- | 'center'
27
- | 'justify' = sankeyJustify;
28
- export let nodeWidth = 4;
29
- export let nodePadding = 10;
30
- export let nodeSort = undefined;
31
-
32
- export let links = (d: any) => d.links;
33
- export let linkSort = undefined;
34
-
35
- export let onupdate: ((data: typeof sankeyData) => void) | undefined = undefined;
36
-
37
- $: sankey = d3Sankey()
38
- .size([$width, $height])
39
- .nodes(nodes)
40
- .nodeId(nodeId)
41
- .nodeAlign(
42
- nodeAlign === 'left'
43
- ? sankeyLeft
44
- : nodeAlign === 'center'
45
- ? sankeyCenter
46
- : nodeAlign === 'right'
47
- ? sankeyRight
48
- : nodeAlign === 'justify'
49
- ? sankeyJustify
50
- : nodeAlign
51
- )
52
- .nodeWidth(nodeWidth)
53
- .nodePadding(nodePadding)
54
- // @ts-expect-error
55
- .nodeSort(nodeSort)
56
- .links(links)
57
- // @ts-expect-error
58
- .linkSort(linkSort);
59
-
60
- // @ts-expect-error
61
- $: sankeyData = sankey($data);
62
- type NodeExtraProperties = Record<string, any>;
63
- $: _nodes = sankeyData.nodes as SankeyNode<NodeExtraProperties, any>[];
64
- $: _links = sankeyData.links as SankeyLink<NodeExtraProperties, any>[];
65
-
66
- $: onupdate?.(sankeyData);
92
+ import { getChartContext } from './Chart.svelte';
93
+
94
+ let {
95
+ nodes: nodesProp = (d: any) => d.nodes,
96
+ nodeId = (d: any) => d.index,
97
+ nodeAlign = sankeyJustify,
98
+ nodeWidth = 4,
99
+ nodePadding = 10,
100
+ nodeSort,
101
+ links: linksProp = (d: any) => d.links,
102
+ linkSort,
103
+ onUpdate,
104
+ children,
105
+ }: SankeyProps = $props();
106
+
107
+ const ctx = getChartContext();
108
+
109
+ const sankeyData = $derived.by(() => {
110
+ if (typeof document === 'undefined') return { nodes: [], links: [] };
111
+
112
+ return (
113
+ d3Sankey()
114
+ .size([ctx.width, ctx.height])
115
+ .nodes(nodesProp)
116
+ .nodeId(nodeId)
117
+ .nodeAlign(
118
+ nodeAlign === 'left'
119
+ ? sankeyLeft
120
+ : nodeAlign === 'center'
121
+ ? sankeyCenter
122
+ : nodeAlign === 'right'
123
+ ? sankeyRight
124
+ : nodeAlign === 'justify'
125
+ ? sankeyJustify
126
+ : nodeAlign
127
+ )
128
+ .nodeWidth(nodeWidth)
129
+ .nodePadding(nodePadding)
130
+ // @ts-expect-error
131
+ .nodeSort(nodeSort)
132
+ .links(linksProp)
133
+ // @ts-expect-error
134
+ .linkSort(linkSort)(structuredClone(ctx.data))
135
+ );
136
+ });
137
+
138
+ $effect(() => {
139
+ onUpdate?.(sankeyData);
140
+ });
67
141
  </script>
68
142
 
69
- <slot nodes={_nodes} links={_links} />
143
+ {@render children?.({
144
+ nodes: sankeyData.nodes,
145
+ links: sankeyData.links,
146
+ })}