layerchart 2.0.0-next.1 → 2.0.0-next.2

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 +155 -0
  4. package/dist/components/AnnotationLine.svelte.d.ts +28 -0
  5. package/dist/components/AnnotationPoint.svelte +121 -0
  6. package/dist/components/AnnotationPoint.svelte.d.ts +32 -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 +287 -174
  14. package/dist/components/Axis.svelte.d.ts +116 -0
  15. package/dist/components/Bar.svelte +163 -107
  16. package/dist/components/Bar.svelte.d.ts +48 -0
  17. package/dist/components/Bars.svelte +54 -68
  18. package/dist/components/Bars.svelte.d.ts +27 -0
  19. package/dist/components/Blur.svelte +31 -7
  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 +60 -15
  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 +47 -12
  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 +28 -13
  66. package/dist/components/Graticule.svelte.d.ts +11 -52
  67. package/dist/components/Grid.svelte +226 -114
  68. package/dist/components/Grid.svelte.d.ts +70 -0
  69. package/dist/components/Group.svelte +132 -105
  70. package/dist/components/Group.svelte.d.ts +53 -0
  71. package/dist/components/Highlight.svelte +409 -307
  72. package/dist/components/Highlight.svelte.d.ts +107 -0
  73. package/dist/components/Hull.svelte +96 -45
  74. package/dist/components/Hull.svelte.d.ts +40 -30
  75. package/dist/components/Labels.svelte +125 -46
  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 +105 -62
  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 +106 -75
  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,148 +1,225 @@
1
- <script lang="ts">
2
- import { type ComponentProps } from 'svelte';
1
+ <script lang="ts" module>
2
+ import type { Transition, TransitionParams, Without } from '../utils/types.js';
3
+
4
+ export type AxisPropsWithoutHTML<In extends Transition = Transition> = {
5
+ /**
6
+ * Location of axis
7
+ */
8
+ placement: 'top' | 'bottom' | 'left' | 'right' | 'angle' | 'radius';
9
+
10
+ /**
11
+ * The label for the axis.
12
+ *
13
+ * Can either be a string or a snippet to render custom content.
14
+ * The snippet receives spreadable props to apply to the label.
15
+ */
16
+ label?: string | Snippet<[{ props: ComponentProps<typeof Text> }]>;
17
+
18
+ /**
19
+ * Location of axis label
20
+ * @default 'middle'
21
+ */
22
+ labelPlacement?: 'start' | 'middle' | 'end';
23
+
24
+ /**
25
+ * Props applied to label Text
26
+ */
27
+ labelProps?: Partial<ComponentProps<typeof Text>>;
28
+
29
+ /**
30
+ * Draw a rule line. Use Rule component for greater rendering order control
31
+ * @default false
32
+ */
33
+ rule?: boolean | Partial<ComponentProps<typeof Rule>>;
34
+
35
+ /**
36
+ * Draw grid lines
37
+ * @default false
38
+ */
39
+ grid?: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'>;
40
+
41
+ /**
42
+ * Control the number of ticks
43
+ */
44
+ ticks?: TicksConfig;
45
+
46
+ /**
47
+ * Length of the tick line
48
+ * @default 4
49
+ */
50
+ tickLength?: number;
51
+
52
+ /**
53
+ * Whether to render tick marks.
54
+ *
55
+ * @default true
56
+ */
57
+ tickMarks?: boolean;
58
+
59
+ /**
60
+ * Format tick labels
61
+ */
62
+ format?: FormatType;
63
+
64
+ /**
65
+ * Props to apply to each tick label
66
+ */
67
+ tickLabelProps?: Partial<ComponentProps<typeof Text>>;
68
+
69
+ /**
70
+ * A snippet to render your own custom tick label.
71
+ */
72
+ tickLabel?: Snippet<[{ props: ComponentProps<typeof Text>; index: number }]>;
73
+
74
+ /**
75
+ * Transition function for entering elements
76
+ * @default defaults to fade if the motion prop is set to tweened
77
+ */
78
+ transitionIn?: In;
79
+
80
+ /**
81
+ * Parameters for the transitionIn function
82
+ * @default { easing: cubicIn }
83
+ */
84
+ transitionInParams?: TransitionParams<In>;
85
+
86
+ /**
87
+ * Scale for the axis
88
+ */
89
+ scale?: any;
90
+
91
+ /**
92
+ * Classes for styling various parts of the axis
93
+ * @default {}
94
+ */
95
+ classes?: {
96
+ root?: string;
97
+ label?: string;
98
+ rule?: string;
99
+ tick?: string;
100
+ tickLabel?: string;
101
+ };
102
+
103
+ motion?: MotionProp;
104
+ };
105
+
106
+ export type AxisProps<In extends Transition = Transition> = AxisPropsWithoutHTML<In> &
107
+ Without<SVGAttributes<SVGGElement>, AxisPropsWithoutHTML<In>>;
108
+ </script>
109
+
110
+ <script lang="ts" generics="T extends Transition = Transition">
111
+ import { type ComponentProps, type Snippet } from 'svelte';
3
112
  import { fade } from 'svelte/transition';
4
113
  import { cubicIn } from 'svelte/easing';
5
114
  import type { SVGAttributes } from 'svelte/elements';
6
- import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
7
- import type { TimeInterval } from 'd3-time';
8
115
 
9
116
  import { extent } from 'd3-array';
10
117
  import { pointRadial } from 'd3-shape';
11
118
 
12
- import { format as formatValue, isLiteralObject, type FormatType } from '@layerstack/utils';
119
+ import { format as formatValue, type FormatType } from '@layerstack/utils';
13
120
  import { cls } from '@layerstack/tailwind';
14
- import type { TransitionParams } from 'svelte-ux'; // TODO: Replace with `@layerstack/svelte-types` or similar
15
121
 
16
- import { chartContext } from './ChartContext.svelte';
17
122
  import Line from './Line.svelte';
18
123
  import Rule from './Rule.svelte';
19
124
  import Text from './Text.svelte';
20
- import { isScaleBand, type AnyScale } from '../utils/scales.js';
21
-
22
- const { xScale, yScale, xRange, yRange, width, height, padding } = chartContext();
23
-
24
- /** Location of axis */
25
- export let placement: 'top' | 'bottom' | 'left' | 'right' | 'angle' | 'radius';
26
-
27
- /** Axis label */
28
- export let label = '';
29
-
30
- /** Location of axis label */
31
- export let labelPlacement: 'start' | 'middle' | 'end' = 'middle';
32
-
33
- /** Props applied label Text */
34
- export let labelProps: Partial<ComponentProps<Text>> | undefined = undefined;
35
-
36
- /** Draw a rule line. Use Rule component for greater rendering order control */
37
- export let rule: boolean | Partial<ComponentProps<Rule>> = false;
38
-
39
- /** Draw a grid lines */
40
- export let grid: boolean | Pick<SVGAttributes<SVGElement>, 'class' | 'style'> = false;
41
-
42
- /** Control the number of ticks*/
43
- export let ticks:
44
- | number
45
- | any[]
46
- | ((scale: AnyScale) => any)
47
- | { interval: TimeInterval | null }
48
- | null
49
- | undefined = undefined;
50
-
51
- /** Length of the tick line */
52
- export let tickLength = 4;
53
-
54
- /** Format tick labels */
55
- export let format: FormatType | undefined = undefined;
56
-
57
- /** Props to apply to each tick label */
58
- export let tickLabelProps: Partial<ComponentProps<Text>> | undefined = undefined;
59
-
60
- export let spring: boolean | Parameters<typeof springStore>[1] = undefined;
61
- export let tweened: boolean | Parameters<typeof tweenedStore>[1] = undefined;
62
-
63
- export let transitionIn = tweened
64
- ? fade
65
- : () => {
66
- return {};
67
- };
68
- export let transitionInParams: TransitionParams = { easing: cubicIn };
69
-
70
- $: orientation =
125
+ import { isScaleBand } from '../utils/scales.svelte.js';
126
+
127
+ import { getChartContext } from './Chart.svelte';
128
+ import { extractLayerProps, layerClass } from '../utils/attributes.js';
129
+ import { extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
130
+ import { resolveTickVals, type TicksConfig } from '../utils/ticks.js';
131
+
132
+ let {
133
+ placement,
134
+ label = '',
135
+ labelPlacement = 'middle',
136
+ labelProps,
137
+ rule = false,
138
+ grid = false,
139
+ ticks,
140
+ tickLength = 4,
141
+ tickMarks = true,
142
+ format,
143
+ tickLabelProps,
144
+ motion,
145
+ transitionIn: transitionInProp,
146
+ transitionInParams: transitionInParamsProp,
147
+ scale: scaleProp,
148
+ classes = {},
149
+ class: className,
150
+ tickLabel,
151
+ ...restProps
152
+ }: AxisProps<T> = $props();
153
+
154
+ const transitionIn = $derived(
155
+ transitionInProp ? transitionInProp : extractTweenConfig(motion)?.options ? fade : () => {}
156
+ ) as T;
157
+ const transitionInParams = $derived(
158
+ transitionInParamsProp ? transitionInParamsProp : { easing: cubicIn }
159
+ );
160
+
161
+ const ctx = getChartContext();
162
+
163
+ const orientation = $derived(
71
164
  placement === 'angle'
72
165
  ? 'angle'
73
166
  : placement === 'radius'
74
167
  ? 'radius'
75
168
  : ['top', 'bottom'].includes(placement)
76
169
  ? 'horizontal'
77
- : 'vertical';
78
-
79
- export let scale: any = undefined;
80
- $: _scale = scale ?? (['horizontal', 'angle'].includes(orientation) ? $xScale : $yScale);
81
-
82
- export let classes: {
83
- root?: string;
84
- label?: string;
85
- rule?: string;
86
- tick?: string;
87
- tickLabel?: string;
88
- } = {};
89
-
90
- $: [xRangeMin, xRangeMax] = extent<number>($xRange) as [number, number];
91
- $: [yRangeMin, yRangeMax] = extent<number>($yRange) as [number, number];
92
-
93
- $: tickVals = Array.isArray(ticks)
94
- ? ticks
95
- : typeof ticks === 'function'
96
- ? ticks(_scale)
97
- : isLiteralObject(ticks)
98
- ? _scale.ticks(ticks.interval) // d3-time interval such as `timeDay.every(1)`
99
- : isScaleBand(_scale)
100
- ? ticks
101
- ? _scale.domain().filter((v: any, i: number) => i % ticks === 0)
102
- : _scale.domain()
103
- : _scale.ticks(ticks ?? (placement === 'left' || placement === 'right' ? 4 : undefined));
170
+ : 'vertical'
171
+ );
172
+
173
+ const scale = $derived(
174
+ scaleProp ?? (['horizontal', 'angle'].includes(orientation) ? ctx.xScale : ctx.yScale)
175
+ );
176
+
177
+ const xRangeMinMax = $derived(extent<number>(ctx.xRange)) as [number, number];
178
+ const yRangeMinMax = $derived(extent<number>(ctx.yRange)) as [number, number];
179
+
180
+ const tickVals = $derived(resolveTickVals(scale, ticks, placement));
104
181
 
105
182
  function getCoords(tick: any) {
106
183
  switch (placement) {
107
184
  case 'top':
108
185
  return {
109
- x: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
110
- y: yRangeMin,
186
+ x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
187
+ y: yRangeMinMax[0],
111
188
  };
112
189
 
113
190
  case 'bottom':
114
191
  return {
115
- x: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
116
- y: yRangeMax,
192
+ x: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
193
+ y: yRangeMinMax[1],
117
194
  };
118
195
 
119
196
  case 'left':
120
197
  return {
121
- x: xRangeMin,
122
- y: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
198
+ x: xRangeMinMax[0],
199
+ y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
123
200
  };
124
201
 
125
202
  case 'right':
126
203
  return {
127
- x: xRangeMax,
128
- y: _scale(tick) + (isScaleBand(_scale) ? _scale.bandwidth() / 2 : 0),
204
+ x: xRangeMinMax[1],
205
+ y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
129
206
  };
130
207
 
131
208
  case 'angle':
132
209
  return {
133
- x: _scale(tick),
134
- y: yRangeMax,
210
+ x: scale(tick),
211
+ y: yRangeMinMax[1],
135
212
  };
136
213
 
137
214
  case 'radius':
138
215
  return {
139
- x: xRangeMin,
140
- y: _scale(tick),
216
+ x: xRangeMinMax[0],
217
+ y: scale(tick) + (isScaleBand(scale) ? scale.bandwidth() / 2 : 0),
141
218
  };
142
219
  }
143
220
  }
144
221
 
145
- function getDefaultTickLabelProps(tick: any): ComponentProps<Text> {
222
+ function getDefaultTickLabelProps(tick: any): ComponentProps<typeof Text> {
146
223
  switch (placement) {
147
224
  case 'top':
148
225
  return {
@@ -175,7 +252,7 @@
175
252
  };
176
253
 
177
254
  case 'angle':
178
- const xValue = _scale(tick); // angle in radians
255
+ const xValue = scale(tick); // angle in radians
179
256
  return {
180
257
  textAnchor:
181
258
  xValue === 0 ||
@@ -200,59 +277,90 @@
200
277
  }
201
278
  }
202
279
 
203
- $: resolvedLabelProps = {
204
- value: label,
205
- x:
206
- placement === 'left' || (orientation === 'horizontal' && labelPlacement === 'start')
207
- ? -$padding.left
208
- : placement === 'right' || (orientation === 'horizontal' && labelPlacement === 'end')
209
- ? $width + $padding.right
210
- : $width / 2,
211
- y:
212
- placement === 'top' || (orientation === 'vertical' && labelPlacement === 'start')
213
- ? -$padding.top
214
- : orientation === 'vertical' && labelPlacement === 'middle'
215
- ? $height / 2
216
- : placement === 'bottom' || labelPlacement === 'end'
217
- ? $height + $padding.bottom
218
- : 0,
219
- textAnchor:
220
- labelPlacement === 'middle'
221
- ? 'middle'
222
- : placement === 'right' || (orientation === 'horizontal' && labelPlacement === 'end')
223
- ? 'end'
224
- : 'start',
225
- verticalAnchor:
280
+ const resolvedLabelX = $derived.by(() => {
281
+ if (placement === 'left' || (orientation === 'horizontal' && labelPlacement === 'start')) {
282
+ return -ctx.padding.left;
283
+ } else if (
284
+ placement === 'right' ||
285
+ (orientation === 'horizontal' && labelPlacement === 'end')
286
+ ) {
287
+ return ctx.width + ctx.padding.right;
288
+ }
289
+
290
+ return ctx.width / 2;
291
+ });
292
+
293
+ const resolvedLabelY = $derived.by(() => {
294
+ if (placement === 'top' || (orientation === 'vertical' && labelPlacement === 'start')) {
295
+ return -ctx.padding.top;
296
+ } else if (orientation === 'vertical' && labelPlacement === 'middle') {
297
+ return ctx.height / 2;
298
+ } else if (placement === 'bottom' || labelPlacement === 'end') {
299
+ return ctx.height + ctx.padding.bottom;
300
+ }
301
+ return '0';
302
+ });
303
+
304
+ const resolvedLabelTextAnchor = $derived.by(() => {
305
+ if (labelPlacement === 'middle') {
306
+ return 'middle';
307
+ } else if (
308
+ placement === 'right' ||
309
+ (orientation === 'horizontal' && labelPlacement === 'end')
310
+ ) {
311
+ return 'end';
312
+ }
313
+ return 'start';
314
+ });
315
+
316
+ const resolvedLabelVerticalAnchor = $derived.by(() => {
317
+ if (
226
318
  placement === 'top' ||
227
319
  (orientation === 'vertical' && labelPlacement === 'start') ||
228
320
  (placement === 'left' && labelPlacement === 'middle')
229
- ? 'start'
230
- : 'end',
321
+ ) {
322
+ return 'start';
323
+ }
324
+ return 'end';
325
+ });
326
+
327
+ const resolvedLabelProps = $derived({
328
+ value: typeof label === 'function' ? '' : undefined,
329
+ x: resolvedLabelX,
330
+ y: resolvedLabelY,
331
+ textAnchor: resolvedLabelTextAnchor,
332
+ verticalAnchor: resolvedLabelVerticalAnchor,
231
333
  rotate: orientation === 'vertical' && labelPlacement === 'middle' ? -90 : 0,
232
334
  capHeight: '.5rem', // text-[10px]
233
335
  ...labelProps,
234
336
  class: cls(
235
- 'label text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
337
+ layerClass('axis-label'),
338
+ 'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
236
339
  classes.label,
237
340
  labelProps?.class
238
341
  ),
239
- } satisfies ComponentProps<Text>;
342
+ }) satisfies ComponentProps<typeof Text>;
240
343
  </script>
241
344
 
242
- <g class={cls('Axis placement-{placement}', classes.root, $$props.class)}>
345
+ <g
346
+ {...restProps}
347
+ data-placement={placement}
348
+ class={cls(layerClass('axis'), `placement-${placement}`, classes.root, className)}
349
+ >
243
350
  {#if rule !== false}
244
- {@const ruleProps = typeof rule === 'object' ? rule : null}
351
+ {@const ruleProps = extractLayerProps(rule, 'axis-rule')}
245
352
  <Rule
246
353
  x={placement === 'left' || placement === 'right' ? placement : placement === 'angle'}
247
354
  y={placement === 'top' || placement === 'bottom' ? placement : placement === 'radius'}
248
- {tweened}
249
- {spring}
355
+ {motion}
250
356
  {...ruleProps}
251
- class={cls('rule stroke-surface-content/50', classes.rule, ruleProps?.class)}
357
+ class={cls('stroke-surface-content/50', classes.rule, ruleProps?.class)}
252
358
  />
253
359
  {/if}
254
360
 
255
- {#if label}
361
+ {#if typeof label === 'function'}
362
+ {@render label({ props: resolvedLabelProps })}
363
+ {:else if label}
256
364
  <Text {...resolvedLabelProps} />
257
365
  {/if}
258
366
 
@@ -266,68 +374,73 @@
266
374
  {@const resolvedTickLabelProps = {
267
375
  x: orientation === 'angle' ? radialTickCoordsX : tickCoords.x,
268
376
  y: orientation === 'angle' ? radialTickCoordsY : tickCoords.y,
269
- value: formatValue(tick, format ?? _scale.tickFormat?.() ?? ((v) => v)),
377
+ value: formatValue(tick, format ?? scale.tickFormat?.() ?? ((v) => v)),
270
378
  ...getDefaultTickLabelProps(tick),
271
- tweened,
272
- spring,
379
+ motion,
273
380
  ...tickLabelProps,
274
381
  class: cls(
275
- 'tickLabel text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
382
+ layerClass('axis-tick-label'),
383
+ 'text-[10px] stroke-surface-100 [stroke-width:2px] font-light',
276
384
  classes.tickLabel,
277
385
  tickLabelProps?.class
278
386
  ),
279
387
  }}
280
388
 
281
- <g in:transitionIn={transitionInParams}>
389
+ <g in:transitionIn={transitionInParams} class={layerClass('axis-tick-group')}>
282
390
  {#if grid !== false}
283
- {@const ruleProps = typeof grid === 'object' ? grid : null}
391
+ {@const ruleProps = extractLayerProps(grid, 'axis-grid')}
284
392
  <Rule
285
393
  x={orientation === 'horizontal' || orientation === 'angle' ? tick : false}
286
394
  y={orientation === 'vertical' || orientation === 'radius' ? tick : false}
287
- {tweened}
288
- {spring}
395
+ {motion}
289
396
  {...ruleProps}
290
- class={cls('grid stroke-surface-content/10', classes.rule, ruleProps?.class)}
397
+ class={cls('stroke-surface-content/10', classes.rule, ruleProps?.class)}
291
398
  />
292
399
  {/if}
293
400
 
294
- <!-- Tick marks -->
295
- {#if orientation === 'horizontal'}
296
- <Line
297
- x1={tickCoords.x}
298
- y1={tickCoords.y}
299
- x2={tickCoords.x}
300
- y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
301
- {tweened}
302
- {spring}
303
- class={cls('tick stroke-surface-content/50', classes.tick)}
304
- />
305
- {:else if orientation === 'vertical'}
306
- <Line
307
- x1={tickCoords.x}
308
- y1={tickCoords.y}
309
- x2={tickCoords.x + (placement === 'left' ? -tickLength : tickLength)}
310
- y2={tickCoords.y}
311
- {tweened}
312
- {spring}
313
- class={cls('tick stroke-surface-content/50', classes.tick)}
314
- />
315
- {:else if orientation === 'angle'}
316
- <Line
317
- x1={radialTickCoordsX}
318
- y1={radialTickCoordsY}
319
- x2={radialTickMarkCoordsX}
320
- y2={radialTickMarkCoordsY}
321
- {tweened}
322
- {spring}
323
- class={cls('tick stroke-surface-content/50', classes.tick)}
324
- />
401
+ {#if tickMarks}
402
+ {@const tickClasses = cls(
403
+ layerClass('axis-tick'),
404
+ 'stroke-surface-content/50',
405
+ classes.tick
406
+ )}
407
+ <!-- Tick marks -->
408
+ {#if orientation === 'horizontal'}
409
+ <Line
410
+ x1={tickCoords.x}
411
+ y1={tickCoords.y}
412
+ x2={tickCoords.x}
413
+ y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
414
+ {motion}
415
+ class={tickClasses}
416
+ />
417
+ {:else if orientation === 'vertical'}
418
+ <Line
419
+ x1={tickCoords.x}
420
+ y1={tickCoords.y}
421
+ x2={tickCoords.x + (placement === 'left' ? -tickLength : tickLength)}
422
+ y2={tickCoords.y}
423
+ {motion}
424
+ class={tickClasses}
425
+ />
426
+ {:else if orientation === 'angle'}
427
+ <Line
428
+ x1={radialTickCoordsX}
429
+ y1={radialTickCoordsY}
430
+ x2={radialTickMarkCoordsX}
431
+ y2={radialTickMarkCoordsY}
432
+ {motion}
433
+ class={tickClasses}
434
+ />
435
+ {/if}
325
436
  {/if}
326
437
  <!-- TODO: Add tick marks for radial (angle)? -->
327
438
 
328
- <slot name="tickLabel" labelProps={resolvedTickLabelProps} {index}>
439
+ {#if tickLabel}
440
+ {@render tickLabel({ props: resolvedTickLabelProps, index })}
441
+ {:else}
329
442
  <Text {...resolvedTickLabelProps} />
330
- </slot>
443
+ {/if}
331
444
  </g>
332
445
  {/each}
333
446
  </g>