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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/dist/actions/movable.d.ts +28 -0
  2. package/dist/actions/movable.js +91 -0
  3. package/dist/components/AnnotationLine.svelte +143 -0
  4. package/dist/components/AnnotationLine.svelte.d.ts +30 -0
  5. package/dist/components/AnnotationPoint.svelte +119 -0
  6. package/dist/components/AnnotationPoint.svelte.d.ts +34 -0
  7. package/dist/components/AnnotationRange.svelte +147 -0
  8. package/dist/components/AnnotationRange.svelte.d.ts +40 -0
  9. package/dist/components/Arc.svelte +344 -151
  10. package/dist/components/Arc.svelte.d.ts +138 -0
  11. package/dist/components/Area.svelte +165 -149
  12. package/dist/components/Area.svelte.d.ts +45 -0
  13. package/dist/components/Axis.svelte +283 -180
  14. package/dist/components/Axis.svelte.d.ts +117 -0
  15. package/dist/components/Bar.svelte +166 -107
  16. package/dist/components/Bar.svelte.d.ts +51 -0
  17. package/dist/components/Bars.svelte +56 -67
  18. package/dist/components/Bars.svelte.d.ts +27 -0
  19. package/dist/components/Blur.svelte +42 -12
  20. package/dist/components/Blur.svelte.d.ts +23 -21
  21. package/dist/components/Bounds.svelte +49 -19
  22. package/dist/components/Bounds.svelte.d.ts +24 -50
  23. package/dist/components/BrushContext.svelte +296 -168
  24. package/dist/components/BrushContext.svelte.d.ts +97 -65
  25. package/dist/components/Calendar.svelte +116 -59
  26. package/dist/components/Calendar.svelte.d.ts +50 -31
  27. package/dist/components/Chart.svelte +1289 -398
  28. package/dist/components/Chart.svelte.d.ts +535 -410
  29. package/dist/components/ChartClipPath.svelte +37 -15
  30. package/dist/components/ChartClipPath.svelte.d.ts +21 -19
  31. package/dist/components/Circle.svelte +124 -85
  32. package/dist/components/Circle.svelte.d.ts +52 -0
  33. package/dist/components/CircleClipPath.svelte +76 -16
  34. package/dist/components/CircleClipPath.svelte.d.ts +46 -0
  35. package/dist/components/ClipPath.svelte +71 -21
  36. package/dist/components/ClipPath.svelte.d.ts +40 -27
  37. package/dist/components/ColorRamp.svelte +75 -9
  38. package/dist/components/ColorRamp.svelte.d.ts +37 -19
  39. package/dist/components/ComputedStyles.svelte +17 -5
  40. package/dist/components/ComputedStyles.svelte.d.ts +11 -19
  41. package/dist/components/Connector.svelte +149 -0
  42. package/dist/components/Connector.svelte.d.ts +51 -0
  43. package/dist/components/Dagre.svelte +211 -122
  44. package/dist/components/Dagre.svelte.d.ts +119 -56
  45. package/dist/components/ForceSimulation.svelte +215 -90
  46. package/dist/components/ForceSimulation.svelte.d.ts +82 -35
  47. package/dist/components/Frame.svelte +33 -13
  48. package/dist/components/Frame.svelte.d.ts +13 -17
  49. package/dist/components/GeoCircle.svelte +29 -16
  50. package/dist/components/GeoCircle.svelte.d.ts +22 -24
  51. package/dist/components/GeoContext.svelte +113 -72
  52. package/dist/components/GeoContext.svelte.d.ts +49 -41
  53. package/dist/components/GeoEdgeFade.svelte +49 -13
  54. package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
  55. package/dist/components/GeoPath.svelte +157 -127
  56. package/dist/components/GeoPath.svelte.d.ts +48 -36
  57. package/dist/components/GeoPoint.svelte +52 -20
  58. package/dist/components/GeoPoint.svelte.d.ts +25 -22
  59. package/dist/components/GeoSpline.svelte +75 -26
  60. package/dist/components/GeoSpline.svelte.d.ts +29 -20
  61. package/dist/components/GeoTile.svelte +100 -49
  62. package/dist/components/GeoTile.svelte.d.ts +38 -23
  63. package/dist/components/GeoVisible.svelte +17 -9
  64. package/dist/components/GeoVisible.svelte.d.ts +10 -18
  65. package/dist/components/Graticule.svelte +30 -14
  66. package/dist/components/Graticule.svelte.d.ts +11 -52
  67. package/dist/components/Grid.svelte +230 -117
  68. package/dist/components/Grid.svelte.d.ts +71 -0
  69. package/dist/components/Group.svelte +173 -106
  70. package/dist/components/Group.svelte.d.ts +81 -0
  71. package/dist/components/Highlight.svelte +410 -308
  72. package/dist/components/Highlight.svelte.d.ts +107 -0
  73. package/dist/components/Hull.svelte +97 -46
  74. package/dist/components/Hull.svelte.d.ts +40 -30
  75. package/dist/components/Labels.svelte +127 -47
  76. package/dist/components/Labels.svelte.d.ts +70 -27
  77. package/dist/components/Legend.svelte +374 -190
  78. package/dist/components/Legend.svelte.d.ts +95 -44
  79. package/dist/components/Line.svelte +163 -125
  80. package/dist/components/Line.svelte.d.ts +75 -0
  81. package/dist/components/LinearGradient.svelte +153 -78
  82. package/dist/components/LinearGradient.svelte.d.ts +66 -31
  83. package/dist/components/Link.svelte +160 -104
  84. package/dist/components/Link.svelte.d.ts +54 -0
  85. package/dist/components/Marker.svelte +100 -39
  86. package/dist/components/Marker.svelte.d.ts +59 -27
  87. package/dist/components/MarkerWrapper.svelte +35 -0
  88. package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
  89. package/dist/components/MonthPath.svelte +65 -20
  90. package/dist/components/MonthPath.svelte.d.ts +23 -17
  91. package/dist/components/MotionPath.svelte +80 -24
  92. package/dist/components/MotionPath.svelte.d.ts +46 -27
  93. package/dist/components/Pack.svelte +53 -17
  94. package/dist/components/Pack.svelte.d.ts +42 -21
  95. package/dist/components/Partition.svelte +64 -22
  96. package/dist/components/Partition.svelte.d.ts +49 -26
  97. package/dist/components/Pattern.svelte +297 -11
  98. package/dist/components/Pattern.svelte.d.ts +103 -19
  99. package/dist/components/Pie.svelte +122 -76
  100. package/dist/components/Pie.svelte.d.ts +65 -51
  101. package/dist/components/Point.svelte +20 -9
  102. package/dist/components/Point.svelte.d.ts +16 -20
  103. package/dist/components/Points.svelte +148 -137
  104. package/dist/components/Points.svelte.d.ts +45 -34
  105. package/dist/components/RadialGradient.svelte +143 -70
  106. package/dist/components/RadialGradient.svelte.d.ts +69 -31
  107. package/dist/components/Rect.svelte +121 -102
  108. package/dist/components/Rect.svelte.d.ts +36 -0
  109. package/dist/components/RectClipPath.svelte +82 -18
  110. package/dist/components/RectClipPath.svelte.d.ts +55 -0
  111. package/dist/components/Rule.svelte +107 -63
  112. package/dist/components/Rule.svelte.d.ts +40 -19
  113. package/dist/components/Sankey.svelte +132 -55
  114. package/dist/components/Sankey.svelte.d.ts +61 -31
  115. package/dist/components/Spline.svelte +281 -218
  116. package/dist/components/Spline.svelte.d.ts +95 -0
  117. package/dist/components/Text.svelte +437 -176
  118. package/dist/components/Text.svelte.d.ts +130 -0
  119. package/dist/components/Threshold.svelte +48 -16
  120. package/dist/components/Threshold.svelte.d.ts +29 -31
  121. package/dist/components/TileImage.svelte +103 -30
  122. package/dist/components/TileImage.svelte.d.ts +48 -23
  123. package/dist/components/TransformContext.svelte +365 -171
  124. package/dist/components/TransformControls.svelte +50 -26
  125. package/dist/components/TransformControls.svelte.d.ts +27 -19
  126. package/dist/components/Tree.svelte +74 -33
  127. package/dist/components/Tree.svelte.d.ts +42 -30
  128. package/dist/components/Treemap.svelte +119 -42
  129. package/dist/components/Treemap.svelte.d.ts +75 -27
  130. package/dist/components/Voronoi.svelte +108 -76
  131. package/dist/components/Voronoi.svelte.d.ts +40 -41
  132. package/dist/components/charts/ArcChart.svelte +464 -0
  133. package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
  134. package/dist/components/charts/AreaChart.svelte +450 -393
  135. package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
  136. package/dist/components/charts/BarChart.svelte +454 -389
  137. package/dist/components/charts/BarChart.svelte.d.ts +76 -0
  138. package/dist/components/charts/ChartAnnotations.svelte +37 -0
  139. package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
  140. package/dist/components/charts/DefaultTooltip.svelte +60 -0
  141. package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
  142. package/dist/components/charts/LineChart.svelte +369 -314
  143. package/dist/components/charts/LineChart.svelte.d.ts +53 -0
  144. package/dist/components/charts/PieChart.svelte +458 -316
  145. package/dist/components/charts/PieChart.svelte.d.ts +137 -353
  146. package/dist/components/charts/ScatterChart.svelte +334 -296
  147. package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
  148. package/dist/components/charts/index.d.ts +8 -0
  149. package/dist/components/charts/index.js +7 -0
  150. package/dist/components/charts/types.d.ts +253 -0
  151. package/dist/components/charts/utils.svelte.d.ts +30 -0
  152. package/dist/components/charts/utils.svelte.js +55 -0
  153. package/dist/components/index.d.ts +76 -4
  154. package/dist/components/index.js +76 -5
  155. package/dist/components/layout/Canvas.svelte +321 -155
  156. package/dist/components/layout/Canvas.svelte.d.ts +104 -55
  157. package/dist/components/layout/Html.svelte +82 -42
  158. package/dist/components/layout/Html.svelte.d.ts +39 -28
  159. package/dist/components/layout/Layer.svelte +39 -0
  160. package/dist/components/layout/Layer.svelte.d.ts +17 -0
  161. package/dist/components/layout/Svg.svelte +122 -70
  162. package/dist/components/layout/Svg.svelte.d.ts +53 -34
  163. package/dist/components/layout/WebGL.svelte +135 -0
  164. package/dist/components/layout/WebGL.svelte.d.ts +50 -0
  165. package/dist/components/tooltip/Tooltip.svelte +246 -78
  166. package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
  167. package/dist/components/tooltip/TooltipContext.svelte +409 -271
  168. package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
  169. package/dist/components/tooltip/TooltipHeader.svelte +100 -11
  170. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
  171. package/dist/components/tooltip/TooltipItem.svelte +167 -27
  172. package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
  173. package/dist/components/tooltip/TooltipList.svelte +22 -3
  174. package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
  175. package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
  176. package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
  177. package/dist/components/tooltip/index.d.ts +6 -0
  178. package/dist/components/tooltip/index.js +6 -0
  179. package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
  180. package/dist/components/tooltip/tooltipMetaContext.js +139 -0
  181. package/dist/components/types.d.ts +1 -0
  182. package/dist/components/types.js +1 -0
  183. package/dist/docs/Blockquote.svelte.d.ts +18 -14
  184. package/dist/docs/Code.svelte.d.ts +26 -22
  185. package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
  186. package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
  187. package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
  188. package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
  189. package/dist/docs/CurveMenuField.svelte +14 -3
  190. package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
  191. package/dist/docs/GeoDebug.svelte +47 -42
  192. package/dist/docs/GeoDebug.svelte.d.ts +4 -16
  193. package/dist/docs/Header1.svelte.d.ts +27 -16
  194. package/dist/docs/Json.svelte.d.ts +20 -16
  195. package/dist/docs/Layout.svelte.d.ts +18 -13
  196. package/dist/docs/Link.svelte.d.ts +33 -21
  197. package/dist/docs/PathDataMenuField.svelte +14 -10
  198. package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
  199. package/dist/docs/Preview.svelte +20 -7
  200. package/dist/docs/Preview.svelte.d.ts +12 -22
  201. package/dist/docs/TilesetField.svelte.d.ts +21 -17
  202. package/dist/docs/TransformDebug.svelte +5 -6
  203. package/dist/docs/TransformDebug.svelte.d.ts +18 -14
  204. package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
  205. package/dist/types/d3-shape-extentions.d.ts +7 -0
  206. package/dist/utils/afterTick.d.ts +5 -0
  207. package/dist/utils/afterTick.js +8 -0
  208. package/dist/utils/arcText.svelte.d.ts +57 -0
  209. package/dist/utils/arcText.svelte.js +262 -0
  210. package/dist/utils/array.d.ts +9 -1
  211. package/dist/utils/array.js +13 -0
  212. package/dist/utils/attributes.d.ts +29 -0
  213. package/dist/utils/attributes.js +40 -0
  214. package/dist/utils/canvas.js +47 -10
  215. package/dist/utils/chart.d.ts +78 -0
  216. package/dist/utils/chart.js +512 -0
  217. package/dist/utils/color.d.ts +1 -0
  218. package/dist/utils/color.js +8 -0
  219. package/dist/utils/common.d.ts +3 -5
  220. package/dist/utils/common.js +3 -2
  221. package/dist/utils/connectorUtils.d.ts +21 -0
  222. package/dist/utils/connectorUtils.js +111 -0
  223. package/dist/utils/createId.d.ts +7 -0
  224. package/dist/utils/createId.js +9 -0
  225. package/dist/utils/debug.d.ts +1 -0
  226. package/dist/utils/debug.js +84 -0
  227. package/dist/utils/filterObject.d.ts +9 -0
  228. package/dist/utils/filterObject.js +12 -0
  229. package/dist/utils/graph/dagre.d.ts +34 -0
  230. package/dist/utils/graph/dagre.js +78 -0
  231. package/dist/utils/graph/dagre.test.d.ts +1 -0
  232. package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
  233. package/dist/utils/graph/sankey.d.ts +28 -0
  234. package/dist/utils/{graph.js → graph/sankey.js} +13 -41
  235. package/dist/utils/index.d.ts +3 -1
  236. package/dist/utils/index.js +3 -1
  237. package/dist/utils/key.svelte.d.ts +3 -0
  238. package/dist/utils/key.svelte.js +11 -0
  239. package/dist/utils/legendPayload.d.ts +7 -0
  240. package/dist/utils/legendPayload.js +8 -0
  241. package/dist/utils/motion.svelte.d.ts +140 -0
  242. package/dist/utils/motion.svelte.js +180 -0
  243. package/dist/utils/motion.test.d.ts +1 -0
  244. package/dist/utils/motion.test.js +213 -0
  245. package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
  246. package/dist/utils/rect.svelte.js +105 -0
  247. package/dist/utils/scales.svelte.d.ts +90 -0
  248. package/dist/utils/{scales.js → scales.svelte.js} +100 -39
  249. package/dist/utils/stack.d.ts +2 -3
  250. package/dist/utils/stack.js +1 -1
  251. package/dist/utils/string.js +87 -0
  252. package/dist/utils/ticks.d.ts +8 -2
  253. package/dist/utils/ticks.js +28 -0
  254. package/dist/utils/ticks.test.d.ts +1 -0
  255. package/dist/utils/ticks.test.js +67 -0
  256. package/dist/utils/types.d.ts +81 -0
  257. package/package.json +21 -19
  258. package/dist/components/ChartContext.svelte +0 -295
  259. package/dist/components/ChartContext.svelte.d.ts +0 -139
  260. package/dist/components/TransformContext.svelte.d.ts +0 -158
  261. package/dist/stores/motionStore.d.ts +0 -30
  262. package/dist/stores/motionStore.js +0 -62
  263. package/dist/utils/graph.d.ts +0 -37
  264. package/dist/utils/rect.js +0 -107
  265. package/dist/utils/scales.d.ts +0 -66
  266. /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
@@ -0,0 +1,512 @@
1
+ import { arraysEqual } from './array.js';
2
+ import { toTitleCase } from './string.js';
3
+ import { InternSet } from 'd3-array';
4
+ /**
5
+ * Creates a function to calculate a domain based on extents and a domain directive.
6
+ * @param s The key (e.g., 'x', 'y') to look up in the extents object
7
+ * @returns A function that computes the final domain from extents and a domain input
8
+ */
9
+ export function calcDomain(s, extents, domain) {
10
+ // @ts-expect-error - TODO: fix these types
11
+ return extents ? partialDomain(extents[s], domain) : domain;
12
+ }
13
+ /**
14
+ * If we have a domain from settings (the directive), fill in
15
+ * any null values with ones from our measured extents;
16
+ * otherwise, return the measured extent.
17
+ * @param domain A two-value array of numbers representing the measured extent
18
+ * @param directive A two-value array of numbers or nulls that will have any nulls filled in from the `domain` array
19
+ * @returns A two-value array of numbers representing the filled-in domain
20
+ */
21
+ export function partialDomain(domain = [], directive) {
22
+ if (Array.isArray(directive) === true) {
23
+ return directive.map((d, i) => {
24
+ if (d === null) {
25
+ return domain[i];
26
+ }
27
+ return d;
28
+ });
29
+ }
30
+ return domain;
31
+ }
32
+ export function createChartScale(axis, { domain, scale, padding, nice, reverse, width, height, range, percentRange, }) {
33
+ const defaultRange = getDefaultRange(axis, width, height, reverse, range, percentRange);
34
+ const trueScale = scale.copy();
35
+ /* --------------------------------------------
36
+ * Set the domain
37
+ */
38
+ trueScale.domain(domain);
39
+ /* --------------------------------------------
40
+ * Set the range of the scale to our default if
41
+ * the scale doesn't have an interpolator function
42
+ * or if it does, still set the range if that function
43
+ * is the default identity function
44
+ */
45
+ if (!trueScale.interpolator ||
46
+ (typeof trueScale.interpolator === 'function' &&
47
+ trueScale.interpolator().name.startsWith('identity'))) {
48
+ trueScale.range(defaultRange);
49
+ }
50
+ if (padding) {
51
+ trueScale.domain(padScale(trueScale, padding));
52
+ }
53
+ if (nice === true || typeof nice === 'number') {
54
+ if (typeof trueScale.nice === 'function') {
55
+ trueScale.nice(typeof nice === 'number' ? nice : undefined);
56
+ }
57
+ else {
58
+ console.error(`[Layer Chart] You set \`${axis}Nice: true\` but the ${axis}Scale does not have a \`.nice\` method. Ignoring...`);
59
+ }
60
+ }
61
+ return trueScale;
62
+ }
63
+ // These scales have a discrete range so they can't be padded
64
+ const unpaddable = ['scaleThreshold', 'scaleQuantile', 'scaleQuantize', 'scaleSequentialQuantile'];
65
+ function padScale(scale, padding) {
66
+ if (typeof scale.range !== 'function') {
67
+ throw new Error('Scale method `range` must be a function');
68
+ }
69
+ if (typeof scale.domain !== 'function') {
70
+ throw new Error('Scale method `domain` must be a function');
71
+ }
72
+ if (!Array.isArray(padding) || unpaddable.includes(findScaleName(scale))) {
73
+ return scale.domain();
74
+ }
75
+ if (isOrdinalDomain(scale) === true)
76
+ return scale.domain();
77
+ const { lift, ground } = getPadFunctions(scale);
78
+ const d0 = scale.domain()[0];
79
+ const isTime = Object.prototype.toString.call(d0) === '[object Date]';
80
+ const [d1, d2] = scale.domain().map((d) => {
81
+ return isTime ? lift(d.getTime()) : lift(d);
82
+ });
83
+ const [r1, r2] = scale.range();
84
+ const paddingLeft = padding[0] || 0;
85
+ const paddingRight = padding[1] || 0;
86
+ const step = (d2 - d1) / (Math.abs(r2 - r1) - paddingLeft - paddingRight);
87
+ return [d1 - paddingLeft * step, paddingRight * step + d2].map((d) => {
88
+ return isTime ? ground(new Date(d).getTime()) : ground(d);
89
+ });
90
+ }
91
+ function f(name, modifier = '') {
92
+ return `scale${toTitleCase(modifier)}${toTitleCase(name)}`;
93
+ }
94
+ /**
95
+ * Get a D3 scale name
96
+ * https://svelte.dev/repl/ec6491055208401ca41120c9c8a67737?version=3.49.0
97
+ */
98
+ export function findScaleName(scale) {
99
+ /**
100
+ * Ordinal scales
101
+ */
102
+ // scaleBand, scalePoint
103
+ // @ts-ignore
104
+ if (typeof scale.bandwidth === 'function') {
105
+ // @ts-ignore
106
+ if (typeof scale.paddingInner === 'function') {
107
+ return f('band');
108
+ }
109
+ return f('point');
110
+ }
111
+ // scaleOrdinal
112
+ if (arraysEqual(Object.keys(scale), ['domain', 'range', 'unknown', 'copy'])) {
113
+ return f('ordinal');
114
+ }
115
+ /**
116
+ * Sequential versus diverging
117
+ */
118
+ let modifier = '';
119
+ // @ts-ignore
120
+ if (scale.interpolator) {
121
+ // @ts-ignore
122
+ if (scale.domain().length === 3) {
123
+ modifier = 'diverging';
124
+ }
125
+ else {
126
+ modifier = 'sequential';
127
+ }
128
+ }
129
+ /**
130
+ * Continuous scales
131
+ */
132
+ // @ts-ignore
133
+ if (scale.quantiles) {
134
+ return f('quantile', modifier);
135
+ }
136
+ // @ts-ignore
137
+ if (scale.thresholds) {
138
+ return f('quantize', modifier);
139
+ }
140
+ // @ts-ignore
141
+ if (scale.constant) {
142
+ return f('symlog', modifier);
143
+ }
144
+ // @ts-ignore
145
+ if (scale.base) {
146
+ return f('log', modifier);
147
+ }
148
+ // @ts-ignore
149
+ if (scale.exponent) {
150
+ // @ts-ignore
151
+ if (scale.exponent() === 0.5) {
152
+ return f('sqrt', modifier);
153
+ }
154
+ return f('pow', modifier);
155
+ }
156
+ if (arraysEqual(Object.keys(scale), ['domain', 'range', 'invertExtent', 'unknown', 'copy'])) {
157
+ return f('threshold');
158
+ }
159
+ if (arraysEqual(Object.keys(scale), [
160
+ 'invert',
161
+ 'range',
162
+ 'domain',
163
+ 'unknown',
164
+ 'copy',
165
+ 'ticks',
166
+ 'tickFormat',
167
+ 'nice',
168
+ ])) {
169
+ return f('identity');
170
+ }
171
+ if (arraysEqual(Object.keys(scale), [
172
+ 'invert',
173
+ 'domain',
174
+ 'range',
175
+ 'rangeRound',
176
+ 'round',
177
+ 'clamp',
178
+ 'unknown',
179
+ 'copy',
180
+ 'ticks',
181
+ 'tickFormat',
182
+ 'nice',
183
+ ])) {
184
+ return f('radial');
185
+ }
186
+ if (modifier) {
187
+ return f(modifier);
188
+ }
189
+ /**
190
+ * Test for scaleTime vs scaleUtc
191
+ * https://github.com/d3/d3-scale/pull/274#issuecomment-1462935595
192
+ */
193
+ if (scale.domain()[0] instanceof Date) {
194
+ const d = new Date();
195
+ let s = '';
196
+ // @ts-ignore
197
+ d.getDay = () => (s = 'time');
198
+ // @ts-ignore
199
+ d.getUTCDay = () => (s = 'utc');
200
+ scale.tickFormat(0, '%a')(d);
201
+ return f(s);
202
+ }
203
+ return f('linear');
204
+ }
205
+ /** Determine whether a scale has an ordinal domain
206
+ * https://svelte.dev/repl/ec6491055208401ca41120c9c8a67737?version=3.49.0
207
+ * @param scale A D3 scale
208
+ * @returns Whether the scale is an ordinal scale
209
+ */
210
+ function isOrdinalDomain(scale) {
211
+ // scaleBand, scalePoint
212
+ if (typeof scale.bandwidth === 'function')
213
+ return true;
214
+ // scaleOrdinal
215
+ if (arraysEqual(Object.keys(scale), ['domain', 'range', 'unknown', 'copy'])) {
216
+ return true;
217
+ }
218
+ return false;
219
+ }
220
+ /**
221
+ * Calculates scale extents for given data and scales
222
+ * @template T The type of data objects in the input array
223
+ * @param {T[]} flatData Array of data objects
224
+ * @param {FieldAccessors<T>} getters Field accessor functions
225
+ * @param {ActiveScales} activeScales Object containing scale information
226
+ * @returns {Extents} Calculated extents for each scale
227
+ */
228
+ export function calcScaleExtents(flatData, getters, activeScales) {
229
+ // group scales by domain type (ordinal vs other)
230
+ const scaleGroups = Object.entries(activeScales).reduce((groups, [key, scaleInfo]) => {
231
+ const domainType = isOrdinalDomain(scaleInfo.scale) === true ? 'ordinal' : 'other';
232
+ if (!groups[domainType]) {
233
+ groups[domainType] = {};
234
+ }
235
+ groups[domainType][key] =
236
+ getters[key];
237
+ return groups;
238
+ }, { ordinal: false, other: false });
239
+ let extents = {};
240
+ // ordinal scales
241
+ if (scaleGroups.ordinal) {
242
+ const sortOptions = Object.fromEntries(Object.entries(activeScales).map(([key, scaleInfo]) => [key, scaleInfo.sort]));
243
+ extents = calcUniques(flatData, scaleGroups.ordinal, sortOptions);
244
+ }
245
+ // other scales
246
+ if (scaleGroups.other) {
247
+ const otherExtents = calcExtents(flatData, scaleGroups.other);
248
+ extents = { ...extents, ...otherExtents };
249
+ }
250
+ return extents;
251
+ }
252
+ /**
253
+ * Calculate the unique values of desired fields
254
+ * For example, data like this: [{ x: 0, y: -10 }, { x: 10, y: 0 }, { x: 5, y: 10 }]
255
+ * and a fields object like this: {'x': d => d.x, 'y': d => d.y}
256
+ * returns an object like this: { x: [0, 10, 5], y: [-10, 0, 10] }
257
+ *
258
+ * @template T The type of data objects in the input array
259
+ * @param data A flat array of data objects
260
+ * @param fields An object containing accessor functions for fields
261
+ * @param [sortOptions={}] Sorting options for the results
262
+ * @returns An object with unique values for each specified field
263
+ * @throws {TypeError} If data is not an array or fields is not a valid object
264
+ */
265
+ function calcUniques(data, fields, sortOptions = {}) {
266
+ if (!Array.isArray(data)) {
267
+ throw new TypeError(`The first argument of calcUniques() must be an array. You passed in a ${typeof data}. If you got this error using the <Chart> component, consider passing a flat array to the \`flatData\` prop`);
268
+ }
269
+ if (Array.isArray(fields) || fields === undefined || fields === null) {
270
+ throw new TypeError('The second argument of calcUniques() must be an object with field names as keys and accessor functions as values.');
271
+ }
272
+ const uniques = {};
273
+ const keys = Object.keys(fields);
274
+ for (const key of keys) {
275
+ const set = new InternSet();
276
+ const accessor = fields[key];
277
+ if (!accessor)
278
+ continue;
279
+ for (const item of data) {
280
+ const value = accessor(item);
281
+ if (Array.isArray(value)) {
282
+ for (const val of value) {
283
+ set.add(val);
284
+ }
285
+ }
286
+ else {
287
+ set.add(value);
288
+ }
289
+ }
290
+ const results = Array.from(set);
291
+ if (sortOptions.sort === true || sortOptions[key] === true) {
292
+ results.sort((a, b) => {
293
+ // type-safe sorting for both numbers and strings
294
+ if (typeof a === 'number' && typeof b === 'number') {
295
+ return a - b;
296
+ }
297
+ return String(a).localeCompare(String(b));
298
+ });
299
+ }
300
+ uniques[key] = results;
301
+ }
302
+ return uniques;
303
+ }
304
+ function calcBaseRange(s, width, height, reverse, percentRange) {
305
+ let min;
306
+ let max;
307
+ if (percentRange === true) {
308
+ min = 0;
309
+ max = 100;
310
+ }
311
+ else {
312
+ min = s === 'r' ? 1 : 0;
313
+ max = s === 'y' ? height : s === 'r' ? 25 : width;
314
+ }
315
+ return reverse === true ? [max, min] : [min, max];
316
+ }
317
+ function getDefaultRange(s, width, height, reverse, range, percentRange = false) {
318
+ return !range
319
+ ? calcBaseRange(s, width, height, reverse, percentRange)
320
+ : typeof range === 'function'
321
+ ? range({ width, height })
322
+ : range;
323
+ }
324
+ export function identity(d) {
325
+ return d;
326
+ }
327
+ function findScaleType(scale) {
328
+ if (scale.constant) {
329
+ return 'symlog';
330
+ }
331
+ if (scale.base) {
332
+ return 'log';
333
+ }
334
+ if (typeof scale.exponent === 'function') {
335
+ const expValue = scale.exponent();
336
+ if (expValue === 0.5) {
337
+ return 'sqrt';
338
+ }
339
+ return 'pow';
340
+ }
341
+ return 'other';
342
+ }
343
+ function log(sign) {
344
+ return (x) => Math.log(sign * x);
345
+ }
346
+ function exp(sign) {
347
+ return (x) => sign * Math.exp(x);
348
+ }
349
+ function symlog(c) {
350
+ return (x) => Math.sign(x) * Math.log1p(Math.abs(x / c));
351
+ }
352
+ function symexp(c) {
353
+ return (x) => Math.sign(x) * Math.expm1(Math.abs(x)) * c;
354
+ }
355
+ function pow(exponent) {
356
+ return function powFn(x) {
357
+ return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
358
+ };
359
+ }
360
+ function getPadFunctions(scale) {
361
+ const scaleType = findScaleType(scale);
362
+ switch (scaleType) {
363
+ case 'log': {
364
+ const domain = scale.domain();
365
+ const sign = Math.sign(domain[0]);
366
+ return { lift: log(sign), ground: exp(sign), scaleType };
367
+ }
368
+ case 'pow': {
369
+ const exponent = 1;
370
+ return {
371
+ lift: pow(exponent),
372
+ ground: pow(1 / exponent),
373
+ scaleType,
374
+ };
375
+ }
376
+ case 'sqrt': {
377
+ const exponent = 0.5;
378
+ return {
379
+ lift: pow(exponent),
380
+ ground: pow(1 / exponent),
381
+ scaleType,
382
+ };
383
+ }
384
+ case 'symlog': {
385
+ const constant = 1;
386
+ return {
387
+ lift: symlog(constant),
388
+ ground: symexp(constant),
389
+ scaleType,
390
+ };
391
+ }
392
+ default:
393
+ return {
394
+ lift: (identity),
395
+ ground: (identity),
396
+ scaleType,
397
+ };
398
+ }
399
+ }
400
+ export function createGetter(accessor, scale) {
401
+ return (d) => {
402
+ const val = accessor(d);
403
+ if (!scale)
404
+ return undefined;
405
+ if (Array.isArray(val)) {
406
+ return val.map((v) => scale(v));
407
+ }
408
+ return scale(val);
409
+ };
410
+ }
411
+ /**
412
+ * Calculate the extents of desired fields, skipping `false`, `undefined`, `null` and `NaN` values
413
+ * For example, data like this:
414
+ * [{ x: 0, y: -10 }, { x: 10, y: 0 }, { x: 5, y: 10 }]
415
+ * and a fields object like this:
416
+ * `{'x': d => d.x, 'y': d => d.y}`
417
+ * returns an object like this:
418
+ * `{ x: [0, 10], y: [-10, 10] }`
419
+ * @param data A flat array of objects.
420
+ * @param fields An object containing `x`, `y`, `r` or `z` keys that equal an accessor function.
421
+ * @returns An object with the same structure as `fields` but with min/max arrays.
422
+ */
423
+ function calcExtents(data, fields) {
424
+ if (!Array.isArray(data)) {
425
+ throw new TypeError(`The first argument of calcExtents() must be an array. You passed in a ${typeof data}. If you got this error using the <Chart> component, consider passing a flat array to the \`flatData\` prop.`);
426
+ }
427
+ if (Array.isArray(fields) || fields === undefined || fields === null) {
428
+ throw new TypeError('The second argument of calcExtents() must be an ' +
429
+ 'object with field names as keys as accessor functions as values.');
430
+ }
431
+ const extents = {};
432
+ const keys = Object.keys(fields);
433
+ const kl = keys.length;
434
+ let i;
435
+ let j;
436
+ let k;
437
+ let s;
438
+ let min;
439
+ let max;
440
+ let acc;
441
+ let val;
442
+ const dl = data.length;
443
+ for (i = 0; i < kl; i += 1) {
444
+ s = keys[i];
445
+ acc = fields[s];
446
+ min = null;
447
+ max = null;
448
+ if (!acc)
449
+ continue; // Skip if accessor is undefined
450
+ for (j = 0; j < dl; j += 1) {
451
+ val = acc(data[j]);
452
+ if (Array.isArray(val)) {
453
+ const vl = val.length;
454
+ for (k = 0; k < vl; k += 1) {
455
+ if (val[k] !== undefined &&
456
+ val[k] !== null &&
457
+ (typeof val[k] === 'string' || Number.isNaN(val[k]) === false)) {
458
+ if (min === null || val[k] < min) {
459
+ min = val[k];
460
+ }
461
+ if (max === null || val[k] > max) {
462
+ max = val[k];
463
+ }
464
+ }
465
+ }
466
+ }
467
+ else if (val !== undefined &&
468
+ val !== null &&
469
+ (typeof val === 'string' || Number.isNaN(val) === false)) {
470
+ if (min === null || val < min) {
471
+ min = val;
472
+ }
473
+ if (max === null || val > max) {
474
+ max = val;
475
+ }
476
+ }
477
+ }
478
+ extents[s] = [min, max];
479
+ }
480
+ return extents;
481
+ }
482
+ /**
483
+ * Move an element to the last child of its parent.
484
+ * Adapted from d3-selection `.raise`
485
+ */
486
+ export function raise(node) {
487
+ if (node.nextSibling) {
488
+ node.parentNode?.appendChild(node);
489
+ }
490
+ }
491
+ /**
492
+ * Flatten arrays of arrays one level deep
493
+ * @param list The list to flatten
494
+ * @param accessor An optional accessor function or string property key
495
+ * @returns Flattened array
496
+ */
497
+ export default function flatten(list, accessor = (d) => d) {
498
+ // type the accessor function based on input
499
+ const acc = typeof accessor === 'string' ? (d) => d[accessor] : accessor;
500
+ // check if list is array and first element through accessor is array
501
+ const firstElement = list[0] && acc(list[0]);
502
+ if (Array.isArray(list) && Array.isArray(firstElement)) {
503
+ let flat = [];
504
+ const l = list.length;
505
+ for (let i = 0; i < l; i += 1) {
506
+ flat = flat.concat(acc(list[i]));
507
+ }
508
+ return flat;
509
+ }
510
+ // type assertion here since we know list contains U[] if not flattened
511
+ return list;
512
+ }
@@ -17,4 +17,5 @@ type RGBColor = {
17
17
  a?: number;
18
18
  };
19
19
  export declare function getColorStr(color: RGBColor): string;
20
+ export declare function getColorIfDefined(data: any): string | undefined;
20
21
  export {};
@@ -18,3 +18,11 @@ export function getColorStr(color) {
18
18
  return `rgb(${color.r},${color.g},${color.b})`;
19
19
  }
20
20
  }
21
+ export function getColorIfDefined(data) {
22
+ if (!data || typeof data !== 'object' || Array.isArray(data))
23
+ return;
24
+ if ('color' in data)
25
+ return data.color;
26
+ if ('fill' in data)
27
+ return data.fill;
28
+ }
@@ -1,12 +1,11 @@
1
- import type { ComponentProps } from 'svelte';
1
+ import type { Component, ComponentProps } from 'svelte';
2
2
  import type Chart from '../components/Chart.svelte';
3
- import type LineChart from '../components/charts/LineChart.svelte';
3
+ import type { SimplifiedChartProps } from '../components/charts/types.js';
4
4
  export type Accessor<TData = any> = number | string | ((d: TData) => any) | undefined | null | Accessor<TData>[];
5
5
  export declare function accessor<TData = any>(prop: Accessor<TData>): (d: TData) => any;
6
6
  /** Guarantee chart data is an array */
7
7
  export declare function chartDataArray<TData = any>(data: ComponentProps<Chart<TData>>['data']): any[];
8
- type SimplifiedChartProps = ComponentProps<LineChart<any>>;
9
- export declare function defaultChartPadding(axis: SimplifiedChartProps['axis'], legend: SimplifiedChartProps['legend']): {
8
+ export declare function defaultChartPadding<TData, SeriesComponent extends Component, TSnippetProps>(axis?: SimplifiedChartProps<TData, SeriesComponent, TSnippetProps>['axis'], legend?: SimplifiedChartProps<TData, SeriesComponent, TSnippetProps>['legend']): {
10
9
  top: number;
11
10
  left: number;
12
11
  bottom: number;
@@ -17,4 +16,3 @@ export declare function defaultChartPadding(axis: SimplifiedChartProps['axis'],
17
16
  * Handles complex objects such as `Date` by invoking `.valueOf()`
18
17
  */
19
18
  export declare function findRelatedData(data: any[], original: any, accessor: Function): any;
20
- export {};
@@ -27,11 +27,12 @@ export function chartDataArray(data) {
27
27
  else if ('nodes' in data) {
28
28
  return data.nodes;
29
29
  }
30
- else {
30
+ else if ('descendants' in data) {
31
31
  return data.descendants();
32
32
  }
33
+ return [];
33
34
  }
34
- export function defaultChartPadding(axis, legend) {
35
+ export function defaultChartPadding(axis = true, legend = false) {
35
36
  if (axis === false) {
36
37
  return undefined;
37
38
  }
@@ -0,0 +1,21 @@
1
+ import { type CurveFactory } from 'd3-shape';
2
+ export type ConnectorCoords = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export type PresetConnectorType = 'straight' | 'square' | 'beveled' | 'rounded';
7
+ export type ConnectorType = PresetConnectorType | 'd3';
8
+ export type ConnectorSweep = 'horizontal-vertical' | 'vertical-horizontal' | 'none';
9
+ type GetConnectorPresetPathProps = {
10
+ source: ConnectorCoords;
11
+ target: ConnectorCoords;
12
+ radius: number;
13
+ type: PresetConnectorType;
14
+ sweep: ConnectorSweep;
15
+ };
16
+ export declare function getConnectorPresetPath(opts: GetConnectorPresetPathProps): string;
17
+ type GetConnectorD3PathProps = Omit<GetConnectorPresetPathProps, 'radius' | 'type'> & {
18
+ curve: CurveFactory;
19
+ };
20
+ export declare function getConnectorD3Path({ source, target, sweep, curve }: GetConnectorD3PathProps): string;
21
+ export {};