layerchart 2.0.0-next.0 → 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 +25 -24
  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,73 +1,105 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import { type Readable } from 'svelte/store';
3
- export declare const brushContextKey: unique symbol;
1
+ export type BrushRange = {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ };
4
7
  export type BrushContextValue = {
5
8
  xDomain: DomainType;
6
9
  yDomain: DomainType;
7
10
  isActive: boolean;
8
- range: {
9
- x: number;
10
- y: number;
11
- width: number;
12
- height: number;
13
- };
11
+ range: BrushRange;
14
12
  handleSize: number;
15
13
  };
16
- export type BrushContext = Readable<BrushContextValue>;
17
- export declare function brushContext(): BrushContext;
18
- import type { DomainType } from '../utils/scales.js';
19
- import type { HTMLAttributes } from 'svelte/elements';
20
- declare const __propDef: {
21
- props: {
22
- /** Axis to apply brushing */ axis?: "x" | "y" | "both";
23
- /** Size of draggable handles (width/height) */ handleSize?: number;
24
- /** Only show range while actively brushing. Useful with `brushEnd` event */ resetOnEnd?: boolean;
25
- xDomain?: DomainType;
26
- yDomain?: DomainType;
27
- /** Mode of operation
28
- * `integrated`: use with single chart
29
- * `separated`: use with separate (typically smaller) chart and state can be managed externally (sync with other charts, etc). Show active selection when domain does not equal original
30
- */ mode?: "integrated" | "separated";
31
- /** Disable brush */ disabled?: boolean;
32
- /** Attributes passed to range <div> element */ range?: Partial<HTMLAttributes<HTMLDivElement>> | undefined;
33
- /** Attributes passed to handle <div> elements */ handle?: Partial<HTMLAttributes<HTMLDivElement>> | undefined;
34
- classes?: {
35
- root?: string;
36
- frame?: string;
37
- range?: string;
38
- handle?: string;
39
- labels?: string;
40
- };
41
- onchange?: (detail: {
42
- xDomain?: DomainType;
43
- yDomain?: DomainType;
44
- }) => void;
45
- onbrushstart?: (detail: {
46
- xDomain?: DomainType;
47
- yDomain?: DomainType;
48
- }) => void;
49
- onbrushend?: (detail: {
50
- xDomain?: DomainType;
51
- yDomain?: DomainType;
52
- }) => void;
53
- onreset?: (detail: {
54
- xDomain?: DomainType;
55
- yDomain?: DomainType;
56
- }) => void;
57
- /** Exposed to allow binding in Chart */ brush?: import("svelte/store").Writable<BrushContextValue>;
58
- };
59
- events: {
60
- [evt: string]: CustomEvent<any>;
61
- };
62
- slots: {
63
- default: {
64
- brush: BrushContextValue;
65
- };
14
+ export declare function getBrushContext(): BrushContextValue;
15
+ export declare function setBrushContext(brush: BrushContextValue): BrushContextValue;
16
+ type BrushEventPayload = {
17
+ xDomain: DomainType | null;
18
+ yDomain: DomainType | null;
19
+ };
20
+ type BrushContextPropsWithoutHTML = {
21
+ /**
22
+ * The axis to apply brushing
23
+ *
24
+ * @default 'x'
25
+ */
26
+ axis?: 'x' | 'y' | 'both';
27
+ /**
28
+ * Size of the draggable handles (width/height)
29
+ *
30
+ * @default 5
31
+ */
32
+ handleSize?: number;
33
+ /**
34
+ * Only show range while actively brushing.
35
+ * Useful with `brushEnd` event
36
+ *
37
+ * @default false
38
+ */
39
+ resetOnEnd?: boolean;
40
+ /**
41
+ * Ignore click to reset.
42
+ * Useful to add click handlers to marks. Requires external resetting (button, another chart, etc)
43
+ *
44
+ * @default false
45
+ */
46
+ ignoreResetClick?: boolean;
47
+ xDomain?: DomainType;
48
+ yDomain?: DomainType;
49
+ /**
50
+ * Mode of operation
51
+ * - `integrated`: use with single chart
52
+ * - `separated`: use with separate (typically smaller) chart and state can be managed
53
+ * externally (sync with other charts, etc). Show active selection when domain does not equal
54
+ * original
55
+ *
56
+ * @default 'integrated'
57
+ */
58
+ mode?: 'integrated' | 'separated';
59
+ /**
60
+ * Disable brush
61
+ *
62
+ * @default false
63
+ */
64
+ disabled?: boolean;
65
+ /**
66
+ * Attributes passed to the range <div> element
67
+ */
68
+ range?: Partial<HTMLAttributes<HTMLElement>>;
69
+ /**
70
+ * Attributes passed to the handle <div> elements
71
+ */
72
+ handle?: Partial<HTMLAttributes<HTMLElement>>;
73
+ /**
74
+ * Classes to apply to the various elements rendered
75
+ *
76
+ * @default {}
77
+ */
78
+ classes?: {
79
+ root?: string;
80
+ frame?: string;
81
+ range?: string;
82
+ handle?: string;
83
+ labels?: string;
66
84
  };
85
+ onChange?: (detail: BrushEventPayload) => void;
86
+ onBrushStart?: (detail: BrushEventPayload) => void;
87
+ onBrushEnd?: (detail: BrushEventPayload) => void;
88
+ onReset?: (detail: BrushEventPayload) => void;
89
+ /**
90
+ * A reference to this brush's context for use in parent
91
+ * components.
92
+ *
93
+ * @bindable
94
+ */
95
+ brushContext?: BrushContextValue;
96
+ children?: Snippet<[{
97
+ brushContext: BrushContextValue;
98
+ }]>;
67
99
  };
68
- export type BrushContextProps = typeof __propDef.props;
69
- export type BrushContextEvents = typeof __propDef.events;
70
- export type BrushContextSlots = typeof __propDef.slots;
71
- export default class BrushContext extends SvelteComponentTyped<BrushContextProps, BrushContextEvents, BrushContextSlots> {
72
- }
73
- export {};
100
+ import { type DomainType } from '../utils/scales.svelte.js';
101
+ import type { HTMLAttributes } from 'svelte/elements';
102
+ import type { Snippet } from 'svelte';
103
+ declare const BrushContext: import("svelte").Component<BrushContextPropsWithoutHTML, {}, "brushContext">;
104
+ type BrushContext = ReturnType<typeof BrushContext>;
105
+ export default BrushContext;
@@ -1,90 +1,147 @@
1
+ <script lang="ts" module>
2
+ export type CalendarCell = {
3
+ x: number;
4
+ y: number;
5
+ color: any;
6
+ data: any;
7
+ };
8
+
9
+ export type CalendarPropsWithoutHTML = {
10
+ /**
11
+ * The start date of the calendar.
12
+ */
13
+ start: Date;
14
+
15
+ /**
16
+ * The end date of the calendar.
17
+ */
18
+ end: Date;
19
+
20
+ /**
21
+ * Size of the cell in the calendar.
22
+ *
23
+ * - `number`: sets width/height as same value (square).
24
+ * - `array`: sets as [width,height].
25
+ * - `undefined/omitted`: is derived from Chart width/height
26
+ */
27
+ cellSize?: number | [number, number];
28
+
29
+ /**
30
+ * Enable drawing path around each month. If object, pass as props to underlying <path>
31
+ *
32
+ * @default false
33
+ */
34
+ monthPath?: boolean | Partial<ComponentProps<typeof MonthPath>>;
35
+
36
+ /**
37
+ * Props to pass to the `<text>` element for month labels.
38
+ */
39
+ monthLabel?: Partial<ComponentProps<typeof Text>>;
40
+
41
+ /**
42
+ * Tooltip context to setup mouse events to show tooltip for related data
43
+ */
44
+ tooltipContext?: TooltipContextValue;
45
+
46
+ children?: Snippet<[{ cells: CalendarCell[] }]>;
47
+ } & Omit<
48
+ RectPropsWithoutHTML,
49
+ 'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'
50
+ >;
51
+
52
+ export type CalendarProps = CalendarPropsWithoutHTML &
53
+ Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;
54
+ </script>
55
+
1
56
  <script lang="ts">
2
- import { type ComponentProps } from 'svelte';
57
+ import { type ComponentProps, type Snippet } from 'svelte';
3
58
  import { timeDays, timeMonths, timeWeek, timeYear } from 'd3-time';
4
59
  import { index } from 'd3-array';
5
60
  import { format } from 'date-fns';
6
61
 
7
- import { chartContext } from './ChartContext.svelte';
8
- import Rect from './Rect.svelte';
62
+ import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
9
63
  import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
10
64
  import MonthPath from './MonthPath.svelte';
11
65
  import Text from './Text.svelte';
12
66
  import { chartDataArray } from '../utils/common.js';
67
+ import { getChartContext } from './Chart.svelte';
68
+ import type { SVGAttributes } from 'svelte/elements';
69
+ import type { Without } from '../utils/types.js';
70
+ import { extractLayerProps } from '../utils/attributes.js';
71
+
72
+ let {
73
+ end,
74
+ start,
75
+ cellSize: cellSizeProp,
76
+ monthPath = false,
77
+ tooltipContext: tooltip,
78
+ children,
79
+ monthLabel,
80
+ ...restProps
81
+ }: CalendarPropsWithoutHTML = $props();
82
+
83
+ const ctx = getChartContext();
84
+
85
+ const yearDays = $derived(timeDays(start, end));
86
+ const yearMonths = $derived(timeMonths(start, end));
87
+ const yearWeeks = $derived(timeWeek.count(start, end));
88
+ const chartCellWidth = $derived(ctx.width / (yearWeeks + 1));
89
+ const chartCellHeight = $derived(ctx.height / 7);
90
+ // Use smallest to fit, and keep square aspect
91
+ const chartCellSize = $derived(Math.min(chartCellWidth, chartCellHeight));
13
92
 
14
- export let start: Date;
15
- export let end: Date;
16
-
17
- /**
18
- * Size of cell. If `number`, sets width/height as same value (square). If array, sets as [width,height]. If undefined, is derived from Chart width/height
19
- */
20
- export let cellSize: number | [number, number] | undefined = undefined;
21
-
22
- /** Enable drawing path around each month. If object, pass as props to underlying <path> */
23
- export let monthPath: boolean | Partial<ComponentProps<MonthPath>> = false;
24
-
25
- /**
26
- * Tooltip context to setup mouse events to show tooltip for related data
27
- */
28
- export let tooltip: TooltipContextValue | undefined = undefined;
29
-
30
- const { width, height, x, cGet, data, config } = chartContext();
31
-
32
- $: yearDays = timeDays(start, end);
33
- $: yearMonths = timeMonths(start, end);
34
- $: yearWeeks = timeWeek.count(start, end);
35
-
36
- $: chartCellWidth = $width / (yearWeeks + 1);
37
- $: chartCellHeight = $height / 7;
38
- $: chartCellSize = Math.min(chartCellWidth, chartCellHeight); // Use smallest to fit, and keep square aspect
39
-
40
- $: [cellWidth, cellHeight] = Array.isArray(cellSize)
41
- ? cellSize
42
- : typeof cellSize === 'number'
43
- ? [cellSize, cellSize]
44
- : [chartCellSize, chartCellSize];
45
-
46
- $: dataByDate = data && $config.x ? index(chartDataArray($data), (d) => $x(d)) : new Map();
47
-
48
- $: cells = yearDays.map((date) => {
49
- const cellData = dataByDate.get(date) ?? { date };
50
- return {
51
- x: timeWeek.count(timeYear(date), date) * cellWidth,
52
- y: date.getDay() * cellHeight,
53
- color: $config.c ? $cGet(cellData) : 'transparent',
54
- data: cellData,
55
- };
56
- });
93
+ // [width, height]
94
+ const cellSize: [number, number] = $derived(
95
+ Array.isArray(cellSizeProp)
96
+ ? cellSizeProp
97
+ : typeof cellSizeProp === 'number'
98
+ ? [cellSizeProp, cellSizeProp]
99
+ : [chartCellSize, chartCellSize]
100
+ );
101
+
102
+ const dataByDate = $derived(
103
+ ctx.data && ctx.config.x ? index(chartDataArray(ctx.data), (d) => ctx.x(d)) : new Map()
104
+ );
105
+
106
+ const cells = $derived(
107
+ yearDays.map((date) => {
108
+ const cellData = dataByDate.get(date) ?? { date };
109
+ return {
110
+ x: timeWeek.count(timeYear(date), date) * cellSize[0],
111
+ y: date.getDay() * cellSize[1],
112
+ color: ctx.config.c ? ctx.cGet(cellData) : 'transparent',
113
+ data: cellData,
114
+ };
115
+ })
116
+ ) satisfies CalendarCell[];
57
117
  </script>
58
118
 
59
- <slot {cells}>
119
+ {#if children}
120
+ {@render children({ cells })}
121
+ {:else}
60
122
  {#each cells as cell}
61
123
  <Rect
62
124
  x={cell.x}
63
125
  y={cell.y}
64
- width={cellWidth}
65
- height={cellHeight}
126
+ width={cellSize[0]}
127
+ height={cellSize[1]}
66
128
  fill={cell.color}
67
129
  onpointermove={(e) => tooltip?.show(e, cell.data)}
68
130
  onpointerleave={(e) => tooltip?.hide()}
69
- class="stroke-surface-content/5"
70
- {...$$restProps}
131
+ {...extractLayerProps(restProps, 'calendar-cell', 'stroke-surface-content/5')}
71
132
  />
72
133
  {/each}
73
- </slot>
134
+ {/if}
74
135
 
75
136
  {#if monthPath}
76
137
  {#each yearMonths as date}
77
- <MonthPath
78
- {date}
79
- cellSize={[cellWidth, cellHeight]}
80
- {...typeof monthPath === 'object' ? monthPath : null}
81
- />
138
+ <MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'calendar-month-path')} />
82
139
 
83
140
  <Text
84
- x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellWidth}
141
+ x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
85
142
  y={-4}
86
143
  value={format(date, 'MMM')}
87
- class="text-xs"
144
+ {...extractLayerProps(monthLabel, 'calendar-month-label', 'text-xs')}
88
145
  />
89
146
  {/each}
90
147
  {/if}
@@ -1,33 +1,52 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import { type ComponentProps } from 'svelte';
1
+ export type CalendarCell = {
2
+ x: number;
3
+ y: number;
4
+ color: any;
5
+ data: any;
6
+ };
7
+ export type CalendarPropsWithoutHTML = {
8
+ /**
9
+ * The start date of the calendar.
10
+ */
11
+ start: Date;
12
+ /**
13
+ * The end date of the calendar.
14
+ */
15
+ end: Date;
16
+ /**
17
+ * Size of the cell in the calendar.
18
+ *
19
+ * - `number`: sets width/height as same value (square).
20
+ * - `array`: sets as [width,height].
21
+ * - `undefined/omitted`: is derived from Chart width/height
22
+ */
23
+ cellSize?: number | [number, number];
24
+ /**
25
+ * Enable drawing path around each month. If object, pass as props to underlying <path>
26
+ *
27
+ * @default false
28
+ */
29
+ monthPath?: boolean | Partial<ComponentProps<typeof MonthPath>>;
30
+ /**
31
+ * Props to pass to the `<text>` element for month labels.
32
+ */
33
+ monthLabel?: Partial<ComponentProps<typeof Text>>;
34
+ /**
35
+ * Tooltip context to setup mouse events to show tooltip for related data
36
+ */
37
+ tooltipContext?: TooltipContextValue;
38
+ children?: Snippet<[{
39
+ cells: CalendarCell[];
40
+ }]>;
41
+ } & Omit<RectPropsWithoutHTML, 'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'>;
42
+ export type CalendarProps = CalendarPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;
43
+ import { type ComponentProps, type Snippet } from 'svelte';
44
+ import { type RectPropsWithoutHTML } from './Rect.svelte';
3
45
  import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
4
46
  import MonthPath from './MonthPath.svelte';
5
- declare const __propDef: {
6
- props: {
7
- [x: string]: any;
8
- start: Date;
9
- end: Date;
10
- cellSize?: number | [number, number] | undefined | undefined;
11
- monthPath?: (boolean | Partial<ComponentProps<MonthPath>>) | undefined;
12
- tooltip?: TooltipContextValue | undefined;
13
- };
14
- events: {
15
- [evt: string]: CustomEvent<any>;
16
- };
17
- slots: {
18
- default: {
19
- cells: {
20
- x: number;
21
- y: number;
22
- color: any;
23
- data: any;
24
- }[];
25
- };
26
- };
27
- };
28
- export type CalendarProps = typeof __propDef.props;
29
- export type CalendarEvents = typeof __propDef.events;
30
- export type CalendarSlots = typeof __propDef.slots;
31
- export default class Calendar extends SvelteComponentTyped<CalendarProps, CalendarEvents, CalendarSlots> {
32
- }
33
- export {};
47
+ import Text from './Text.svelte';
48
+ import type { SVGAttributes } from 'svelte/elements';
49
+ import type { Without } from '../utils/types.js';
50
+ declare const Calendar: import("svelte").Component<CalendarPropsWithoutHTML, {}, "">;
51
+ type Calendar = ReturnType<typeof Calendar>;
52
+ export default Calendar;