layerchart 2.0.0-next.1 → 2.0.0-next.11

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 (275) 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 +320 -179
  14. package/dist/components/Axis.svelte.d.ts +127 -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 +148 -77
  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 +463 -197
  118. package/dist/components/Text.svelte.d.ts +136 -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 +153 -103
  131. package/dist/components/Voronoi.svelte.d.ts +42 -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 +444 -393
  135. package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
  136. package/dist/components/charts/BarChart.svelte +463 -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 +366 -315
  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 +332 -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 +59 -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 +347 -171
  156. package/dist/components/layout/Canvas.svelte.d.ts +110 -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 +253 -78
  166. package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
  167. package/dist/components/tooltip/TooltipContext.svelte +426 -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 +3 -1
  184. package/dist/docs/Blockquote.svelte.d.ts +5 -16
  185. package/dist/docs/Code.svelte +20 -12
  186. package/dist/docs/Code.svelte.d.ts +12 -22
  187. package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
  188. package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
  189. package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
  190. package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
  191. package/dist/docs/CurveMenuField.svelte +14 -3
  192. package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
  193. package/dist/docs/GeoDebug.svelte +47 -42
  194. package/dist/docs/GeoDebug.svelte.d.ts +4 -16
  195. package/dist/docs/Header1.svelte +4 -2
  196. package/dist/docs/Header1.svelte.d.ts +5 -18
  197. package/dist/docs/Json.svelte +11 -3
  198. package/dist/docs/Json.svelte.d.ts +9 -17
  199. package/dist/docs/Layout.svelte +10 -7
  200. package/dist/docs/Layout.svelte.d.ts +5 -15
  201. package/dist/docs/Link.svelte +7 -3
  202. package/dist/docs/Link.svelte.d.ts +5 -27
  203. package/dist/docs/PathDataMenuField.svelte +14 -10
  204. package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
  205. package/dist/docs/Preview.svelte +20 -7
  206. package/dist/docs/Preview.svelte.d.ts +12 -22
  207. package/dist/docs/TilesetField.svelte +20 -19
  208. package/dist/docs/TilesetField.svelte.d.ts +6 -19
  209. package/dist/docs/TransformDebug.svelte +5 -6
  210. package/dist/docs/TransformDebug.svelte.d.ts +18 -14
  211. package/dist/docs/ViewSourceButton.svelte +7 -4
  212. package/dist/docs/ViewSourceButton.svelte.d.ts +8 -18
  213. package/dist/types/d3-shape-extentions.d.ts +7 -0
  214. package/dist/utils/afterTick.d.ts +5 -0
  215. package/dist/utils/afterTick.js +8 -0
  216. package/dist/utils/arcText.svelte.d.ts +57 -0
  217. package/dist/utils/arcText.svelte.js +262 -0
  218. package/dist/utils/array.d.ts +9 -1
  219. package/dist/utils/array.js +13 -0
  220. package/dist/utils/attributes.d.ts +29 -0
  221. package/dist/utils/attributes.js +40 -0
  222. package/dist/utils/canvas.js +47 -10
  223. package/dist/utils/chart.d.ts +78 -0
  224. package/dist/utils/chart.js +512 -0
  225. package/dist/utils/color.d.ts +1 -0
  226. package/dist/utils/color.js +8 -0
  227. package/dist/utils/common.d.ts +3 -5
  228. package/dist/utils/common.js +3 -2
  229. package/dist/utils/connectorUtils.d.ts +21 -0
  230. package/dist/utils/connectorUtils.js +111 -0
  231. package/dist/utils/createId.d.ts +7 -0
  232. package/dist/utils/createId.js +9 -0
  233. package/dist/utils/debug.d.ts +1 -0
  234. package/dist/utils/debug.js +84 -0
  235. package/dist/utils/filterObject.d.ts +9 -0
  236. package/dist/utils/filterObject.js +12 -0
  237. package/dist/utils/graph/dagre.d.ts +34 -0
  238. package/dist/utils/graph/dagre.js +78 -0
  239. package/dist/utils/graph/dagre.test.d.ts +1 -0
  240. package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
  241. package/dist/utils/graph/sankey.d.ts +28 -0
  242. package/dist/utils/{graph.js → graph/sankey.js} +13 -41
  243. package/dist/utils/index.d.ts +3 -1
  244. package/dist/utils/index.js +3 -1
  245. package/dist/utils/key.svelte.d.ts +3 -0
  246. package/dist/utils/key.svelte.js +11 -0
  247. package/dist/utils/legendPayload.d.ts +7 -0
  248. package/dist/utils/legendPayload.js +8 -0
  249. package/dist/utils/motion.svelte.d.ts +140 -0
  250. package/dist/utils/motion.svelte.js +180 -0
  251. package/dist/utils/motion.test.d.ts +1 -0
  252. package/dist/utils/motion.test.js +213 -0
  253. package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
  254. package/dist/utils/rect.svelte.js +105 -0
  255. package/dist/utils/scales.svelte.d.ts +91 -0
  256. package/dist/utils/scales.svelte.js +201 -0
  257. package/dist/utils/stack.d.ts +2 -3
  258. package/dist/utils/stack.js +1 -1
  259. package/dist/utils/string.js +87 -0
  260. package/dist/utils/ticks.d.ts +9 -3
  261. package/dist/utils/ticks.js +122 -147
  262. package/dist/utils/ticks.test.d.ts +1 -0
  263. package/dist/utils/ticks.test.js +57 -0
  264. package/dist/utils/types.d.ts +81 -0
  265. package/package.json +28 -24
  266. package/dist/components/ChartContext.svelte +0 -295
  267. package/dist/components/ChartContext.svelte.d.ts +0 -139
  268. package/dist/components/TransformContext.svelte.d.ts +0 -158
  269. package/dist/stores/motionStore.d.ts +0 -30
  270. package/dist/stores/motionStore.js +0 -62
  271. package/dist/utils/graph.d.ts +0 -37
  272. package/dist/utils/rect.js +0 -107
  273. package/dist/utils/scales.d.ts +0 -66
  274. package/dist/utils/scales.js +0 -136
  275. /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
@@ -1,37 +0,0 @@
1
- import type { SankeyExtraProperties, SankeyGraph, SankeyLink, SankeyNodeMinimal } from 'd3-sankey';
2
- import type { hierarchy as d3Hierarchy } from 'd3-hierarchy';
3
- import dagre from '@dagrejs/dagre';
4
- /**
5
- * Convert CSV rows in format: 'source,target,value' to SankeyGraph
6
- */
7
- export declare function graphFromCsv(csv: string): SankeyGraph<any, any>;
8
- /**
9
- * Convert d3-hierarchy to graph (nodes/links)
10
- */
11
- export declare function graphFromHierarchy(hierarchy: ReturnType<typeof d3Hierarchy>): {
12
- nodes: import("d3-hierarchy").HierarchyNode<unknown>[];
13
- links: {
14
- value: number | undefined;
15
- source: import("d3-hierarchy").HierarchyNode<unknown>;
16
- target: import("d3-hierarchy").HierarchyNode<unknown>;
17
- }[];
18
- };
19
- /**
20
- * Create graph from node (and target node/links downward)
21
- */
22
- export declare function graphFromNode(node: SankeyNodeMinimal<any, any>): {
23
- nodes: any[];
24
- links: any[];
25
- };
26
- /**
27
- * Get distinct nodes from link.source and link.target
28
- */
29
- export declare function nodesFromLinks<N extends SankeyExtraProperties, L extends SankeyExtraProperties>(links: Array<SankeyLink<N, L>>): any[];
30
- /**
31
- * Get all upstream predecessors for dagre nodeId
32
- */
33
- export declare function ancestors(graph: dagre.graphlib.Graph, nodeId: string, maxDepth?: number, currentDepth?: number): dagre.Node[];
34
- /**
35
- * Get all downstream descendants for dagre nodeId
36
- */
37
- export declare function descendants(graph: dagre.graphlib.Graph, nodeId: string, maxDepth?: number, currentDepth?: number): dagre.Node[];
@@ -1,107 +0,0 @@
1
- import { derived } from 'svelte/store';
2
- import { max, min } from 'd3-array';
3
- import { isScaleBand } from './scales.js';
4
- import { accessor } from './common.js';
5
- export function createDimensionGetter(context, options) {
6
- const { xScale, yScale, x: xAccessor, y: yAccessor, x1: x1Accessor, y1: y1Accessor, x1Scale, y1Scale, } = context;
7
- return derived([xScale, x1Scale, yScale, y1Scale, xAccessor, yAccessor, x1Accessor, y1Accessor], ([$xScale, $x1Scale, $yScale, $y1Scale, $xAccessor, $yAccessor, $x1Accessor, $y1Accessor]) => {
8
- const insets = resolveInsets(options?.insets);
9
- // Use `xscale.domain()` instead of `$xDomain` to include `nice()` being applied
10
- const [minXDomain, maxXDomain] = $xScale.domain();
11
- const [minYDomain, maxYDomain] = $yScale.domain();
12
- const _x = accessor(options?.x ?? $xAccessor);
13
- const _y = accessor(options?.y ?? $yAccessor);
14
- const _x1 = accessor(options?.x1 ?? $x1Accessor);
15
- const _y1 = accessor(options?.y1 ?? $y1Accessor);
16
- // @ts-expect-error
17
- return function getter(item) {
18
- if (isScaleBand($yScale)) {
19
- // Horizontal band
20
- const y = firstValue($yScale(_y(item)) ?? 0) + ($y1Scale ? $y1Scale(_y1(item)) : 0) + insets.top;
21
- const height = Math.max(0, $yScale.bandwidth
22
- ? ($y1Scale ? ($y1Scale.bandwidth?.() ?? 0) : $yScale.bandwidth()) -
23
- insets.bottom -
24
- insets.top
25
- : 0);
26
- const xValue = _x(item);
27
- let left = 0;
28
- let right = 0;
29
- if (Array.isArray(xValue)) {
30
- // Array contains both top and bottom values (stack, etc);
31
- left = min(xValue);
32
- right = max(xValue);
33
- }
34
- else if (xValue == null) {
35
- // null/undefined value
36
- left = 0;
37
- right = 0;
38
- }
39
- else if (xValue > 0) {
40
- // Positive value
41
- left = max([0, minXDomain]);
42
- right = xValue;
43
- }
44
- else {
45
- // Negative value
46
- left = xValue;
47
- right = min([0, maxXDomain]);
48
- }
49
- const x = $xScale(left) + insets.left;
50
- const width = Math.max(0, $xScale(right) - $xScale(left) - insets.left - insets.right);
51
- return { x, y, width, height };
52
- }
53
- else {
54
- // Vertical band or linear
55
- const x = firstValue($xScale(_x(item))) + ($x1Scale ? $x1Scale(_x1(item)) : 0) + insets.left;
56
- const width = Math.max(0, $xScale.bandwidth
57
- ? ($x1Scale ? ($x1Scale.bandwidth?.() ?? 0) : $xScale.bandwidth()) -
58
- insets.left -
59
- insets.right
60
- : 0);
61
- const yValue = _y(item);
62
- let top = 0;
63
- let bottom = 0;
64
- if (Array.isArray(yValue)) {
65
- // Array contains both top and bottom values (stack, etc);
66
- top = max(yValue);
67
- bottom = min(yValue);
68
- }
69
- else if (yValue == null) {
70
- // null/undefined value
71
- top = 0;
72
- bottom = 0;
73
- }
74
- else if (yValue > 0) {
75
- // Positive value
76
- top = yValue;
77
- bottom = max([0, minYDomain]);
78
- }
79
- else {
80
- // Negative value
81
- top = min([0, maxYDomain]);
82
- bottom = yValue;
83
- }
84
- const y = $yScale(top) + insets.top;
85
- const height = $yScale(bottom) - $yScale(top) - insets.bottom - insets.top;
86
- return { x, y, width, height };
87
- }
88
- };
89
- });
90
- }
91
- /**
92
- * If value is an array, returns first item, else returns original value
93
- * Useful when x/y getters for band scale are an array (such as for histograms)
94
- */
95
- export function firstValue(value) {
96
- return Array.isArray(value) ? value[0] : value;
97
- }
98
- function resolveInsets(insets) {
99
- const all = insets?.all ?? 0;
100
- const x = insets?.x ?? all;
101
- const y = insets?.y ?? all;
102
- const left = insets?.left ?? x;
103
- const right = insets?.right ?? x;
104
- const top = insets?.top ?? y;
105
- const bottom = insets?.bottom ?? y;
106
- return { left, right, bottom, top };
107
- }
@@ -1,66 +0,0 @@
1
- import { tweened, spring } from 'svelte/motion';
2
- import { type MotionOptions } from '../stores/motionStore.js';
3
- import { type ScaleBand } from 'd3-scale';
4
- export interface AnyScale<Domain = any, Range = any, Input = Domain, Output = any> {
5
- (value: Input): Output;
6
- invert?: (value: Output) => Input;
7
- domain(): Domain[];
8
- domain(domain: Iterable<Domain>): this;
9
- range(): Range[];
10
- range(range: Iterable<Range>): this;
11
- bandwidth?: Function;
12
- ticks?: Function;
13
- tickFormat?: Function;
14
- copy(): Function;
15
- }
16
- export type DomainType = (number | string | Date | null | undefined)[] | null;
17
- /**
18
- * Implemenation for missing `scaleBand().invert()`
19
- *
20
- * See: https://stackoverflow.com/questions/38633082/d3-getting-invert-value-of-band-scales
21
- * https://github.com/d3/d3-scale/pull/64
22
- * https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
23
- * https://observablehq.com/@d3/ordinal-brushing
24
- * https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
25
- * https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
26
- */
27
- export declare function scaleBandInvert(scale: ScaleBand<any>): (value: number) => any;
28
- export declare function isScaleBand(scale: AnyScale<any, any>): scale is ScaleBand<any>;
29
- /**
30
- * Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
31
- * Useful to map mouse event location (x,y) to domain value
32
- */
33
- export declare function scaleInvert(scale: AnyScale<any, any>, value: number): any;
34
- /** Create new copy of scale with domain and range */
35
- export declare function createScale(scale: AnyScale, domain: DomainType, range: any[] | readonly any[] | Function, context?: Record<any, any>): AnyScale<any, any, any, any>;
36
- /** Create a `scaleBand()` within another scaleBand()'s bandwidth (typically a x1 of an x0 scale, used for grouping) */
37
- export declare function groupScaleBand<Domain extends {
38
- toString(): string;
39
- }>(scale: ScaleBand<Domain>, flatData: any[], groupBy: string, padding?: {
40
- inner?: number;
41
- outer?: number;
42
- }): ScaleBand<string>;
43
- /**
44
- * Animate d3-scale as domain and/or range are updated using tweened store
45
- */
46
- export declare function tweenedScale<Domain, Range>(scale: any, tweenedOptions?: Parameters<typeof tweened<any>>[1]): {
47
- subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
48
- domain: (values: Domain) => Promise<void>;
49
- range: (values: Range) => Promise<void>;
50
- };
51
- /**
52
- * Animate d3-scale as domain and/or range are updated using spring store
53
- */
54
- export declare function springScale<Domain, Range>(scale: AnyScale, springOptions?: Parameters<typeof spring>[1]): {
55
- subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
56
- domain: (values: Domain) => Promise<void>;
57
- range: (values: Range) => Promise<void>;
58
- };
59
- /**
60
- * Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` store if not interpolating
61
- */
62
- export declare function motionScale<Domain, Range>(scale: AnyScale, options: MotionOptions): {
63
- subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
64
- domain: (values: Domain) => void | Promise<void>;
65
- range: (values: Range) => void | Promise<void>;
66
- };
@@ -1,136 +0,0 @@
1
- import { derived } from 'svelte/store';
2
- import { tweened, spring } from 'svelte/motion';
3
- import { motionStore } from '../stores/motionStore.js';
4
- import { scaleBand } from 'd3-scale';
5
- import { unique } from '@layerstack/utils';
6
- /**
7
- * Implemenation for missing `scaleBand().invert()`
8
- *
9
- * See: https://stackoverflow.com/questions/38633082/d3-getting-invert-value-of-band-scales
10
- * https://github.com/d3/d3-scale/pull/64
11
- * https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
12
- * https://observablehq.com/@d3/ordinal-brushing
13
- * https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
14
- * https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
15
- */
16
- export function scaleBandInvert(scale) {
17
- const domain = scale.domain();
18
- const eachBand = scale.step();
19
- const paddingOuter = eachBand * (scale.paddingOuter?.() ?? scale.padding()); // `scaleBand` uses paddingOuter(), while `scalePoint` uses padding() for outer paddding - https://github.com/d3/d3-scale#point_padding
20
- return function (value) {
21
- const index = Math.floor((value - paddingOuter / 2) / eachBand);
22
- return domain[Math.max(0, Math.min(index, domain.length - 1))];
23
- };
24
- }
25
- export function isScaleBand(scale) {
26
- return typeof scale.bandwidth === 'function';
27
- }
28
- /**
29
- * Generic way to invert a scale value, handling scaleBand and continuous scales (linear, time, etc).
30
- * Useful to map mouse event location (x,y) to domain value
31
- */
32
- export function scaleInvert(scale, value) {
33
- if (isScaleBand(scale)) {
34
- return scaleBandInvert(scale)(value);
35
- }
36
- else {
37
- return scale.invert?.(value);
38
- }
39
- }
40
- /** Create new copy of scale with domain and range */
41
- export function createScale(scale, domain, range, context) {
42
- const scaleCopy = scale.copy();
43
- if (domain) {
44
- scaleCopy.domain(domain);
45
- }
46
- if (typeof range === 'function') {
47
- scaleCopy.range(range(context));
48
- }
49
- else {
50
- scaleCopy.range(range);
51
- }
52
- return scaleCopy;
53
- }
54
- /** Create a `scaleBand()` within another scaleBand()'s bandwidth (typically a x1 of an x0 scale, used for grouping) */
55
- export function groupScaleBand(scale, flatData, groupBy, padding) {
56
- //
57
- const groupKeys = unique(flatData.map((d) => d[groupBy]));
58
- let newScale = scaleBand().domain(groupKeys).range([0, scale.bandwidth()]);
59
- if (padding) {
60
- if (padding.inner) {
61
- newScale = newScale.paddingInner(padding.inner);
62
- }
63
- if (padding.outer) {
64
- newScale = newScale.paddingOuter(padding.outer);
65
- }
66
- }
67
- return newScale;
68
- }
69
- /**
70
- * Animate d3-scale as domain and/or range are updated using tweened store
71
- */
72
- export function tweenedScale(scale, tweenedOptions = {}) {
73
- const tweenedDomain = tweened(undefined, tweenedOptions);
74
- const tweenedRange = tweened(undefined, tweenedOptions);
75
- const tweenedScale = derived([tweenedDomain, tweenedRange], ([domain, range]) => {
76
- const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
77
- if (domain) {
78
- scaleInstance.domain(domain);
79
- }
80
- if (range) {
81
- scaleInstance.range(range);
82
- }
83
- return scaleInstance;
84
- });
85
- return {
86
- subscribe: tweenedScale.subscribe,
87
- domain: (values) => tweenedDomain.set(values),
88
- range: (values) => tweenedRange.set(values),
89
- };
90
- }
91
- /**
92
- * Animate d3-scale as domain and/or range are updated using spring store
93
- */
94
- export function springScale(scale, springOptions = {}) {
95
- const domainStore = spring(undefined, springOptions);
96
- const rangeStore = spring(undefined, springOptions);
97
- const tweenedScale = derived([domainStore, rangeStore], ([domain, range]) => {
98
- // @ts-expect-error
99
- const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
100
- if (domain) {
101
- scaleInstance.domain(domain);
102
- }
103
- if (range) {
104
- scaleInstance.range(range);
105
- }
106
- return scaleInstance;
107
- });
108
- return {
109
- subscribe: tweenedScale.subscribe,
110
- domain: (values) => domainStore.set(values),
111
- range: (values) => rangeStore.set(values),
112
- };
113
- }
114
- /**
115
- * Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` store if not interpolating
116
- */
117
- export function motionScale(scale, options) {
118
- const domainStore = motionStore(undefined, options);
119
- const rangeStore = motionStore(undefined, options);
120
- const tweenedScale = derived([domainStore, rangeStore], ([domain, range]) => {
121
- // @ts-expect-error
122
- const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
123
- if (domain) {
124
- scaleInstance.domain(domain);
125
- }
126
- if (range) {
127
- scaleInstance.range(range);
128
- }
129
- return scaleInstance;
130
- });
131
- return {
132
- subscribe: tweenedScale.subscribe,
133
- domain: (values) => domainStore.set(values),
134
- range: (values) => rangeStore.set(values),
135
- };
136
- }