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,30 +0,0 @@
1
- import { spring, tweened } from 'svelte/motion';
2
- export type SpringOptions = Parameters<typeof spring<any>>[1];
3
- export type TweenedOptions = Parameters<typeof tweened<any>>[1];
4
- export type MotionOptions = {
5
- spring?: boolean | SpringOptions;
6
- tweened?: boolean | TweenedOptions;
7
- };
8
- export type PropMotionOptions = {
9
- spring?: boolean | SpringOptions | {
10
- [prop: string]: SpringOptions;
11
- };
12
- tweened?: boolean | TweenedOptions | {
13
- [prop: string]: TweenedOptions;
14
- };
15
- };
16
- /**
17
- * Convenient wrapper to create a motion store (spring(), tweened()) based on properties, or fall back to basic writable() store
18
- */
19
- export declare function motionStore<T = any>(value: T, options: MotionOptions): import("svelte/motion").Spring<T> | import("svelte/motion").Tweened<T> | import("svelte/store").Writable<T>;
20
- /**
21
- * Helper to resolve motion options with specific property option (useful for specifying per-prop delays)
22
- */
23
- export declare function resolveOptions(prop: string, options: PropMotionOptions): {
24
- spring: any;
25
- tweened: any;
26
- };
27
- export declare function motionFinishHandler(): {
28
- subscribe: (this: void, run: import("svelte/store").Subscriber<boolean>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
29
- handle: (promise: Promise<void> | void) => void;
30
- };
@@ -1,62 +0,0 @@
1
- import { writable } from 'svelte/store';
2
- import { spring, tweened } from 'svelte/motion';
3
- /**
4
- * Convenient wrapper to create a motion store (spring(), tweened()) based on properties, or fall back to basic writable() store
5
- */
6
- export function motionStore(value, options) {
7
- if (options.spring) {
8
- return spring(value, options.spring === true ? undefined : options.spring);
9
- }
10
- else if (options.tweened) {
11
- return tweened(value, options.tweened === true ? undefined : options.tweened);
12
- }
13
- else {
14
- return writable(value);
15
- }
16
- }
17
- /**
18
- * Helper to resolve motion options with specific property option (useful for specifying per-prop delays)
19
- */
20
- export function resolveOptions(prop, options) {
21
- return {
22
- spring: typeof options.spring === 'boolean' || options.spring == null
23
- ? options.spring
24
- : prop in options.spring
25
- ? //@ts-expect-error
26
- options.spring[prop]
27
- : Object.keys(options.spring).some((key) => ['precision', 'damping', 'stiffness'].includes(key))
28
- ? options.tweened
29
- : false,
30
- tweened: typeof options.tweened === 'boolean' || options.tweened == null
31
- ? options.tweened
32
- : prop in options.tweened
33
- ? //@ts-expect-error
34
- options.tweened[prop]
35
- : Object.keys(options.tweened).some((key) => ['delay', 'duration', 'easing'].includes(key))
36
- ? options.tweened
37
- : false,
38
- };
39
- }
40
- export function motionFinishHandler() {
41
- let latestIndex = 0;
42
- const moving = writable(false);
43
- const handle = function (promise) {
44
- latestIndex += 1;
45
- if (!promise) {
46
- // The store returned nothing, which means that the motion store is immediate.
47
- moving.set(false);
48
- return;
49
- }
50
- let thisIndex = latestIndex;
51
- moving.set(true);
52
- promise.then(() => {
53
- if (thisIndex === latestIndex) {
54
- moving.set(false);
55
- }
56
- });
57
- };
58
- return {
59
- subscribe: moving.subscribe,
60
- handle,
61
- };
62
- }
@@ -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
- };