@ember-joinery/chart 0.0.0-stage → 1.1.0

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 (121) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/LICENSE.md +9 -0
  3. package/NOTICE +532 -0
  4. package/README.md +69 -2
  5. package/addon-main.cjs +4 -0
  6. package/declarations/-private/cartesian-chart.d.ts +413 -0
  7. package/declarations/-private/cartesian-chart.d.ts.map +1 -0
  8. package/declarations/-private/cartesian.d.ts +236 -0
  9. package/declarations/-private/cartesian.d.ts.map +1 -0
  10. package/declarations/-private/config.d.ts +13 -0
  11. package/declarations/-private/config.d.ts.map +1 -0
  12. package/declarations/-private/dots.d.ts +27 -0
  13. package/declarations/-private/dots.d.ts.map +1 -0
  14. package/declarations/-private/nice-ticks.d.ts +17 -0
  15. package/declarations/-private/nice-ticks.d.ts.map +1 -0
  16. package/declarations/-private/parts.d.ts +596 -0
  17. package/declarations/-private/parts.d.ts.map +1 -0
  18. package/declarations/-private/paths.d.ts +26 -0
  19. package/declarations/-private/paths.d.ts.map +1 -0
  20. package/declarations/-private/pie-chart.d.ts +244 -0
  21. package/declarations/-private/pie-chart.d.ts.map +1 -0
  22. package/declarations/-private/polar-chart.d.ts +423 -0
  23. package/declarations/-private/polar-chart.d.ts.map +1 -0
  24. package/declarations/-private/polar-geometry.d.ts +230 -0
  25. package/declarations/-private/polar-geometry.d.ts.map +1 -0
  26. package/declarations/-private/polar-parts.d.ts +315 -0
  27. package/declarations/-private/polar-parts.d.ts.map +1 -0
  28. package/declarations/-private/polar.d.ts +156 -0
  29. package/declarations/-private/polar.d.ts.map +1 -0
  30. package/declarations/-private/registry.d.ts +9 -0
  31. package/declarations/-private/registry.d.ts.map +1 -0
  32. package/declarations/-private/text-size.d.ts +13 -0
  33. package/declarations/-private/text-size.d.ts.map +1 -0
  34. package/declarations/-private/tick-interval.d.ts +35 -0
  35. package/declarations/-private/tick-interval.d.ts.map +1 -0
  36. package/declarations/components/area-chart.d.ts +16 -0
  37. package/declarations/components/area-chart.d.ts.map +1 -0
  38. package/declarations/components/bar-chart.d.ts +16 -0
  39. package/declarations/components/bar-chart.d.ts.map +1 -0
  40. package/declarations/components/chart-container.d.ts +66 -0
  41. package/declarations/components/chart-container.d.ts.map +1 -0
  42. package/declarations/components/chart-legend-content.d.ts +42 -0
  43. package/declarations/components/chart-legend-content.d.ts.map +1 -0
  44. package/declarations/components/chart-style.d.ts +19 -0
  45. package/declarations/components/chart-style.d.ts.map +1 -0
  46. package/declarations/components/chart-tooltip-content.d.ts +94 -0
  47. package/declarations/components/chart-tooltip-content.d.ts.map +1 -0
  48. package/declarations/components/dot.d.ts +22 -0
  49. package/declarations/components/dot.d.ts.map +1 -0
  50. package/declarations/components/line-chart.d.ts +16 -0
  51. package/declarations/components/line-chart.d.ts.map +1 -0
  52. package/declarations/components/pie-chart.d.ts +13 -0
  53. package/declarations/components/pie-chart.d.ts.map +1 -0
  54. package/declarations/components/radar-chart.d.ts +21 -0
  55. package/declarations/components/radar-chart.d.ts.map +1 -0
  56. package/declarations/components/radial-bar-chart.d.ts +17 -0
  57. package/declarations/components/radial-bar-chart.d.ts.map +1 -0
  58. package/declarations/components/rectangle.d.ts +32 -0
  59. package/declarations/components/rectangle.d.ts.map +1 -0
  60. package/declarations/components/sector.d.ts +47 -0
  61. package/declarations/components/sector.d.ts.map +1 -0
  62. package/declarations/index.d.ts +24 -0
  63. package/declarations/index.d.ts.map +1 -0
  64. package/declarations/test-support/chart.d.ts +162 -0
  65. package/declarations/test-support/chart.d.ts.map +1 -0
  66. package/declarations/test-support/index.d.ts +3 -0
  67. package/declarations/test-support/index.d.ts.map +1 -0
  68. package/declarations/test-support/polar-chart.d.ts +62 -0
  69. package/declarations/test-support/polar-chart.d.ts.map +1 -0
  70. package/declarations/test-support.d.ts +2 -0
  71. package/declarations/types.d.ts +138 -0
  72. package/declarations/types.d.ts.map +1 -0
  73. package/dist/cartesian-D9hWDamz.js +1217 -0
  74. package/dist/cartesian-D9hWDamz.js.map +1 -0
  75. package/dist/cartesian-chart-BLj6Q_OB.js +1123 -0
  76. package/dist/cartesian-chart-BLj6Q_OB.js.map +1 -0
  77. package/dist/components/area-chart.js +20 -0
  78. package/dist/components/area-chart.js.map +1 -0
  79. package/dist/components/bar-chart.js +20 -0
  80. package/dist/components/bar-chart.js.map +1 -0
  81. package/dist/components/chart-container.js +54 -0
  82. package/dist/components/chart-container.js.map +1 -0
  83. package/dist/components/chart-legend-content.js +48 -0
  84. package/dist/components/chart-legend-content.js.map +1 -0
  85. package/dist/components/chart-style.js +35 -0
  86. package/dist/components/chart-style.js.map +1 -0
  87. package/dist/components/chart-tooltip-content.js +131 -0
  88. package/dist/components/chart-tooltip-content.js.map +1 -0
  89. package/dist/components/dot.js +18 -0
  90. package/dist/components/dot.js.map +1 -0
  91. package/dist/components/line-chart.js +20 -0
  92. package/dist/components/line-chart.js.map +1 -0
  93. package/dist/components/pie-chart.js +6 -0
  94. package/dist/components/pie-chart.js.map +1 -0
  95. package/dist/components/radar-chart.js +22 -0
  96. package/dist/components/radar-chart.js.map +1 -0
  97. package/dist/components/radial-bar-chart.js +20 -0
  98. package/dist/components/radial-bar-chart.js.map +1 -0
  99. package/dist/components/rectangle.js +5 -0
  100. package/dist/components/rectangle.js.map +1 -0
  101. package/dist/components/sector.js +5 -0
  102. package/dist/components/sector.js.map +1 -0
  103. package/dist/config-DnsUmxOT.js +35 -0
  104. package/dist/config-DnsUmxOT.js.map +1 -0
  105. package/dist/index.js +15 -0
  106. package/dist/index.js.map +1 -0
  107. package/dist/parts-BWLhFFjB.js +355 -0
  108. package/dist/parts-BWLhFFjB.js.map +1 -0
  109. package/dist/pie-chart-CmDtW_Ge.js +646 -0
  110. package/dist/pie-chart-CmDtW_Ge.js.map +1 -0
  111. package/dist/polar-chart-GhgOSsH9.js +2242 -0
  112. package/dist/polar-chart-GhgOSsH9.js.map +1 -0
  113. package/dist/rectangle-Cl7tbXuZ.js +166 -0
  114. package/dist/rectangle-Cl7tbXuZ.js.map +1 -0
  115. package/dist/sector-7shQPJuQ.js +565 -0
  116. package/dist/sector-7shQPJuQ.js.map +1 -0
  117. package/dist/test-support.js +470 -0
  118. package/dist/test-support.js.map +1 -0
  119. package/dist/types.js +56 -0
  120. package/dist/types.js.map +1 -0
  121. package/package.json +117 -3
@@ -0,0 +1,1217 @@
1
+ /*!
2
+ * @ember-joinery/chart ports recharts 3.8.0 (https://github.com/recharts/recharts): its tick
3
+ * selection, nice tick values, text measurement, cartesian, pie and polar layout, tooltip
4
+ * placement, and rectangle, sector and polygon paths.
5
+ *
6
+ * The MIT License (MIT). Copyright (c) 2015-present recharts
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9
+ * and associated documentation files (the "Software"), to deal in the Software without
10
+ * restriction, including without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
12
+ * Software is furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all copies or
15
+ * substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ import { isUndefined, isString, isFunction } from '@sindresorhus/is';
24
+ import { scaleBand, scalePoint, scaleLinear } from 'd3-scale';
25
+ import { stackOffsetWiggle, stackOffsetSilhouette, stackOffsetExpand, stackOffsetNone, stack, stackOrderNone } from 'd3-shape';
26
+
27
+ /*
28
+ * Nice tick values for a numeric axis, as recharts 3 computes them
29
+ * (recharts/src/util/scale/getNiceTickValues.ts, its "adaptive" algorithm): ticks that are easy
30
+ * to read, which may reach past the data's own range. recharts does the arithmetic with
31
+ * decimal.js-light; here every result is rounded to 12 significant digits, which gives the same
32
+ * numbers for any axis a chart draws.
33
+ *
34
+ * recharts is MIT licensed; its notice is in NOTICE, and the build keeps it in the module that
35
+ * ships this (see rollup.config.mjs).
36
+ */
37
+
38
+ /** Rounds away floating-point noise: 0.1 + 0.2 becomes 0.3. */
39
+ function clean(value) {
40
+ return Number.isFinite(value) ? Number(value.toPrecision(12)) : value;
41
+ }
42
+
43
+ /** The number of digits before the decimal point (1 for 0). */
44
+ function getDigitCount(value) {
45
+ if (value === 0) return 1;
46
+ return Math.floor(Math.log10(Math.abs(value))) + 1;
47
+ }
48
+
49
+ /** The adaptive step: the rough step rounded up to a multiple of 0.05 (or 0.1) of its magnitude. */
50
+ function getAdaptiveStep(roughStep, allowDecimals, correctionFactor) {
51
+ if (roughStep <= 0) return 0;
52
+ const digitCount = getDigitCount(roughStep);
53
+ const digitCountValue = 10 ** digitCount;
54
+ const stepRatio = clean(roughStep / digitCountValue);
55
+ const stepRatioScale = digitCount !== 1 ? 0.05 : 0.1;
56
+ const amendStepRatio = clean((Math.ceil(clean(stepRatio / stepRatioScale)) + correctionFactor) * stepRatioScale);
57
+ const formatStep = clean(amendStepRatio * digitCountValue);
58
+ return allowDecimals ? formatStep : Math.ceil(formatStep);
59
+ }
60
+
61
+ /** Ticks around a single value. */
62
+ function getTickOfSingleValue(value, tickCount, allowDecimals) {
63
+ let step = 1;
64
+ let middle = value;
65
+ if (!Number.isInteger(value) && allowDecimals) {
66
+ const absVal = Math.abs(value);
67
+ if (absVal < 1) {
68
+ step = 10 ** (getDigitCount(value) - 1);
69
+ middle = clean(Math.floor(value / step) * step);
70
+ } else if (absVal > 1) {
71
+ middle = Math.floor(value);
72
+ }
73
+ } else if (value === 0) {
74
+ middle = Math.floor((tickCount - 1) / 2);
75
+ } else if (!allowDecimals) {
76
+ middle = Math.floor(value);
77
+ }
78
+ const middleIndex = Math.floor((tickCount - 1) / 2);
79
+ return Array.from({
80
+ length: tickCount
81
+ }, (_, i) => clean(middle + (i - middleIndex) * step));
82
+ }
83
+ function calculateStep(min, max, tickCount, allowDecimals, correctionFactor = 0) {
84
+ if (!Number.isFinite((max - min) / (tickCount - 1))) return {
85
+ step: 0,
86
+ tickMin: 0,
87
+ tickMax: 0
88
+ };
89
+ const step = getAdaptiveStep(clean((max - min) / (tickCount - 1)), allowDecimals, correctionFactor);
90
+ let middle;
91
+ if (min <= 0 && max >= 0) {
92
+ middle = 0;
93
+ } else {
94
+ middle = clean((min + max) / 2);
95
+ middle = clean(middle - middle % step);
96
+ }
97
+ let belowCount = Math.ceil(clean((middle - min) / step));
98
+ let upCount = Math.ceil(clean((max - middle) / step));
99
+ const scaleCount = belowCount + upCount + 1;
100
+ if (scaleCount > tickCount) {
101
+ return calculateStep(min, max, tickCount, allowDecimals, correctionFactor + 1);
102
+ }
103
+ if (scaleCount < tickCount) {
104
+ upCount = max > 0 ? upCount + (tickCount - scaleCount) : upCount;
105
+ belowCount = max > 0 ? belowCount : belowCount + (tickCount - scaleCount);
106
+ }
107
+ return {
108
+ step,
109
+ tickMin: clean(middle - belowCount * step),
110
+ tickMax: clean(middle + upCount * step)
111
+ };
112
+ }
113
+ function rangeStep(start, end, step) {
114
+ const result = [];
115
+ let value = start;
116
+ for (let i = 0; value < end && i < 100000; i++) {
117
+ result.push(value);
118
+ value = clean(value + step);
119
+ }
120
+ return result;
121
+ }
122
+
123
+ /**
124
+ * The ticks of `[min, max]`, `tickCount` of them, rounded to nice values: `[0, 305]` with five
125
+ * ticks gives `[0, 80, 160, 240, 320]`. The ticks can reach past the interval.
126
+ */
127
+ function getNiceTickValues([min, max], tickCount = 6, allowDecimals = true) {
128
+ const count = Math.max(tickCount, 2);
129
+ const [cormin, cormax] = min > max ? [max, min] : [min, max];
130
+ if (cormin === -Infinity || cormax === Infinity) {
131
+ const values = cormax === Infinity ? [cormin, ...Array(tickCount - 1).fill(Infinity)] : [...Array(tickCount - 1).fill(-Infinity), cormax];
132
+ return min > max ? values.reverse() : values;
133
+ }
134
+ if (cormin === cormax) return getTickOfSingleValue(cormin, tickCount, allowDecimals);
135
+ const {
136
+ step,
137
+ tickMin,
138
+ tickMax
139
+ } = calculateStep(cormin, cormax, count, allowDecimals);
140
+ const values = rangeStep(tickMin, clean(tickMax + 0.1 * step), step);
141
+ return min > max ? values.reverse() : values;
142
+ }
143
+
144
+ /**
145
+ * The ticks of a fixed `[min, max]`, kept inside it: for an axis whose domain is given as
146
+ * numbers.
147
+ */
148
+ function getTickValuesFixedDomain([min, max], tickCount, allowDecimals = true) {
149
+ const [cormin, cormax] = min > max ? [max, min] : [min, max];
150
+ if (cormin === -Infinity || cormax === Infinity) return [min, max];
151
+ if (cormin === cormax) return [cormin];
152
+ const count = Math.max(tickCount, 2);
153
+ const step = getAdaptiveStep(clean((cormax - cormin) / (count - 1)), allowDecimals, 0);
154
+ let values = [...rangeStep(cormin, cormax, step), cormax];
155
+ if (!allowDecimals) values = values.map(value => Math.round(value));
156
+ return min > max ? values.reverse() : values;
157
+ }
158
+
159
+ /*
160
+ * The size a string takes on screen, measured the way recharts measures tick labels
161
+ * (recharts/src/util/DOMUtils.ts): in a hidden span appended to <body>, with the font size and
162
+ * letter spacing given. The axes use it to drop ticks whose labels would overlap, so measuring
163
+ * the same way keeps the same ticks.
164
+ *
165
+ * recharts is MIT licensed; its notice is in NOTICE, and the build keeps it in the module that
166
+ * ships this (see rollup.config.mjs).
167
+ */
168
+
169
+ const SPAN_ID = 'jn_chart_measurement_span';
170
+ const SPAN_STYLE = {
171
+ position: 'absolute',
172
+ top: '-20000px',
173
+ left: '0',
174
+ padding: '0',
175
+ margin: '0',
176
+ border: 'none',
177
+ whiteSpace: 'pre'
178
+ };
179
+ const cache = new Map();
180
+ const CACHE_SIZE = 2000;
181
+ function measure(text, style) {
182
+ if (isUndefined(globalThis.document)) return {
183
+ width: 0,
184
+ height: 0
185
+ };
186
+ let span = document.getElementById(SPAN_ID);
187
+ if (!span) {
188
+ span = document.createElement('span');
189
+ span.id = SPAN_ID;
190
+ span.setAttribute('aria-hidden', 'true');
191
+ document.body.appendChild(span);
192
+ }
193
+ Object.assign(span.style, SPAN_STYLE, {
194
+ fontSize: style.fontSize ?? '',
195
+ letterSpacing: style.letterSpacing ?? ''
196
+ });
197
+ span.textContent = text;
198
+ const rect = span.getBoundingClientRect();
199
+ return {
200
+ width: rect.width,
201
+ height: rect.height
202
+ };
203
+ }
204
+
205
+ /** The width and height of `text` in the page's font, at the given size and letter spacing. */
206
+ function getStringSize(text, style = {}) {
207
+ if (text === undefined || text === null) return {
208
+ width: 0,
209
+ height: 0
210
+ };
211
+ const value = String(text);
212
+ const key = `${value}|${style.fontSize ?? ''}|${style.letterSpacing ?? ''}`;
213
+ const cached = cache.get(key);
214
+ if (cached) return cached;
215
+ const size = measure(value, style);
216
+ // A zero size means nothing was laid out (a detached document); don't remember it.
217
+ if (size.width || size.height) {
218
+ if (cache.size >= CACHE_SIZE) cache.delete(cache.keys().next().value);
219
+ cache.set(key, size);
220
+ }
221
+ return size;
222
+ }
223
+
224
+ /** Forgets every measurement, for a test that changes the page's fonts. */
225
+ function clearStringSizeCache() {
226
+ cache.clear();
227
+ }
228
+
229
+ /*
230
+ * Which of an axis's ticks to show, so their labels don't overlap: recharts' `interval`
231
+ * (recharts/src/cartesian/getTicks.ts and getEquidistantTicks.ts), ported as is.
232
+ *
233
+ * recharts is MIT licensed; its notice is in NOTICE, and the build keeps it in the module that
234
+ * ships this (see rollup.config.mjs).
235
+ */
236
+
237
+ /** One tick: its value, where it sits along the axis, and its index among the axis's ticks. */
238
+
239
+ /** How an axis thins its ticks: as recharts' `interval` prop. */
240
+
241
+ function isVisible(sign, position, getSize, start, end) {
242
+ if (sign * position < sign * start || sign * position > sign * end) return false;
243
+ const size = getSize();
244
+ return sign * (position - sign * size / 2 - start) >= 0 && sign * (position + sign * size / 2 - end) <= 0;
245
+ }
246
+ function everyNth(items, n) {
247
+ if (n < 1) return [];
248
+ if (n === 1) return items;
249
+ return items.filter((_, i) => i % n === 0);
250
+ }
251
+ function ticksEnd(sign, start, end, getSize, ticks, gap) {
252
+ const result = ticks.slice();
253
+ for (let i = result.length - 1; i >= 0; i--) {
254
+ let entry = result[i];
255
+ let size;
256
+ const tickSize = () => size ??= getSize(ticks[i], i);
257
+ if (i === result.length - 1) {
258
+ const overflow = sign * (entry.coordinate + sign * tickSize() / 2 - end);
259
+ entry = {
260
+ ...entry,
261
+ tickCoord: overflow > 0 ? entry.coordinate - overflow * sign : entry.coordinate
262
+ };
263
+ } else {
264
+ entry = {
265
+ ...entry,
266
+ tickCoord: entry.coordinate
267
+ };
268
+ }
269
+ result[i] = entry;
270
+ if (isVisible(sign, entry.tickCoord, tickSize, start, end)) {
271
+ end = entry.tickCoord - sign * (tickSize() / 2 + gap);
272
+ result[i] = {
273
+ ...entry,
274
+ isShow: true
275
+ };
276
+ }
277
+ }
278
+ return result;
279
+ }
280
+ function ticksStart(sign, start, end, getSize, ticks, gap, preserveEnd) {
281
+ const result = ticks.slice();
282
+ const len = result.length;
283
+ if (preserveEnd) {
284
+ const tail = ticks[len - 1];
285
+ if (tail) {
286
+ const tailSize = getSize(tail, len - 1);
287
+ const overflow = sign * (tail.coordinate + sign * tailSize / 2 - end);
288
+ const entry = {
289
+ ...tail,
290
+ tickCoord: overflow > 0 ? tail.coordinate - overflow * sign : tail.coordinate
291
+ };
292
+ result[len - 1] = entry;
293
+ if (isVisible(sign, entry.tickCoord, () => tailSize, start, end)) {
294
+ end = entry.tickCoord - sign * (tailSize / 2 + gap);
295
+ result[len - 1] = {
296
+ ...entry,
297
+ isShow: true
298
+ };
299
+ }
300
+ }
301
+ }
302
+ const count = preserveEnd ? len - 1 : len;
303
+ for (let i = 0; i < count; i++) {
304
+ let entry = result[i];
305
+ let size;
306
+ const tickSize = () => size ??= getSize(ticks[i], i);
307
+ if (i === 0) {
308
+ const overflow = sign * (entry.coordinate - sign * tickSize() / 2 - start);
309
+ entry = {
310
+ ...entry,
311
+ tickCoord: overflow < 0 ? entry.coordinate - overflow * sign : entry.coordinate
312
+ };
313
+ } else {
314
+ entry = {
315
+ ...entry,
316
+ tickCoord: entry.coordinate
317
+ };
318
+ }
319
+ result[i] = entry;
320
+ if (isVisible(sign, entry.tickCoord, tickSize, start, end)) {
321
+ start = entry.tickCoord + sign * (tickSize() / 2 + gap);
322
+ result[i] = {
323
+ ...entry,
324
+ isShow: true
325
+ };
326
+ }
327
+ }
328
+ return result;
329
+ }
330
+ function equidistant(sign, initialStart, end, getSize, ticks, gap) {
331
+ for (let step = 1; step <= ticks.length; step++) {
332
+ let start = initialStart;
333
+ let ok = true;
334
+ for (let index = 0; index < ticks.length; index += step) {
335
+ const entry = ticks[index];
336
+ let size;
337
+ const tickSize = () => size ??= getSize(entry, index);
338
+ if (index !== 0 && !isVisible(sign, entry.coordinate, tickSize, start, end)) {
339
+ ok = false;
340
+ break;
341
+ }
342
+ start = entry.coordinate + sign * (tickSize() / 2 + gap);
343
+ }
344
+ if (ok) return everyNth(ticks, step);
345
+ }
346
+ return [];
347
+ }
348
+ function equidistantPreserveEnd(sign, initialStart, end, getSize, ticks, gap) {
349
+ const len = ticks.length;
350
+ for (let step = 1; step <= len; step++) {
351
+ const offset = (len - 1) % step;
352
+ let start = initialStart;
353
+ let ok = true;
354
+ for (let index = offset; index < len; index += step) {
355
+ const entry = ticks[index];
356
+ let size;
357
+ const tickSize = () => size ??= getSize(entry, index);
358
+ if (index !== offset && !isVisible(sign, entry.coordinate, tickSize, start, end)) {
359
+ ok = false;
360
+ break;
361
+ }
362
+ start = entry.coordinate + sign * (tickSize() / 2 + gap);
363
+ }
364
+ if (ok) {
365
+ const kept = [];
366
+ for (let index = offset; index < len; index += step) kept.push(ticks[index]);
367
+ return kept;
368
+ }
369
+ }
370
+ return [];
371
+ }
372
+
373
+ /** The width a label takes along a horizontal axis once rotated by `angle` degrees. */
374
+ function angledWidth(size, angle = 0) {
375
+ if (angle % 180 === 0) return size.width;
376
+ const radians = angle * Math.PI / 180;
377
+ const sinAngle = Math.abs(Math.sin(radians));
378
+ const cosAngle = Math.abs(Math.cos(radians));
379
+ const angleThreshold = Math.atan(size.height / size.width);
380
+ return radians > angleThreshold && radians < Math.PI - angleThreshold ? size.height / sinAngle : size.width / cosAngle;
381
+ }
382
+
383
+ /** The ticks to draw, each with where its label goes (`tickCoord`). */
384
+ function visibleTicks(options) {
385
+ const {
386
+ ticks,
387
+ viewBox,
388
+ orientation,
389
+ interval,
390
+ minTickGap,
391
+ tickFormatter,
392
+ unit,
393
+ style
394
+ } = options;
395
+ if (!ticks.length || !options.tick) return [];
396
+ if (!isString(interval)) return everyNth(ticks, interval + 1);
397
+ const sizeKey = orientation === 'top' || orientation === 'bottom' ? 'width' : 'height';
398
+ const unitSize = unit && sizeKey === 'width' ? getStringSize(unit, style) : {
399
+ width: 0,
400
+ height: 0
401
+ };
402
+ const getSize = (tick, index) => {
403
+ const value = tickFormatter ? tickFormatter(tick.value, index) : tick.value;
404
+ const size = getStringSize(value, style);
405
+ return sizeKey === 'width' ? angledWidth({
406
+ width: size.width + unitSize.width,
407
+ height: size.height + unitSize.height
408
+ }, options.angle) : size.height;
409
+ };
410
+ const [first, second] = ticks;
411
+ const sign = second ? Math.sign(second.coordinate - first.coordinate) || 1 : 1;
412
+ const isWidth = sizeKey === 'width';
413
+ const {
414
+ x,
415
+ y,
416
+ width,
417
+ height
418
+ } = viewBox;
419
+ const start = sign === 1 ? isWidth ? x : y : isWidth ? x + width : y + height;
420
+ const end = sign === 1 ? isWidth ? x + width : y + height : isWidth ? x : y;
421
+ if (interval === 'equidistantPreserveStart') return equidistant(sign, start, end, getSize, ticks, minTickGap);
422
+ if (interval === 'equidistantPreserveEnd') return equidistantPreserveEnd(sign, start, end, getSize, ticks, minTickGap);
423
+ const candidates = interval === 'preserveStart' || interval === 'preserveStartEnd' ? ticksStart(sign, start, end, getSize, ticks, minTickGap, interval === 'preserveStartEnd') : ticksEnd(sign, start, end, getSize, ticks, minTickGap);
424
+ return candidates.filter(tick => tick.isShow);
425
+ }
426
+
427
+ /*
428
+ * The geometry of a cartesian chart (area, bar and line charts), computed the way recharts 3
429
+ * computes it, so a Joinery chart draws the same marks in the same places: the plot area left
430
+ * by the margins, axes and legend; each axis's domain, scale and ticks; the grid's lines; and
431
+ * each series' points, stacked where they share a `stackId`.
432
+ *
433
+ * Everything here is a pure function of the chart's settings and size, except text
434
+ * measurement (./text-size.ts), which the axes use to drop overlapping ticks.
435
+ *
436
+ * recharts is MIT licensed; its notice is in NOTICE, and the build keeps it in the module that
437
+ * ships this (see rollup.config.mjs).
438
+ */
439
+
440
+ /** One row of a chart's `@data`. */
441
+
442
+ /** Where a value comes from in a row: a key, or a function of the row. */
443
+
444
+ /** The value at `dataKey` in a row. */
445
+ function valueOf(datum, dataKey, fallback) {
446
+ if (dataKey === undefined || datum === null || datum === undefined) return fallback;
447
+ if (isFunction(dataKey)) return dataKey(datum);
448
+ return datum[dataKey] ?? fallback;
449
+ }
450
+
451
+ /** The space around the plot area, in pixels. */
452
+
453
+ /** A domain bound: a number, `auto`, `dataMin`/`dataMax`, `dataMin - 10`, or a function. */
454
+
455
+ /** What an axis does, with recharts' defaults filled in. */
456
+
457
+ const DEFAULT_Y_AXIS_WIDTH = 60;
458
+ const DEFAULT_X_AXIS_HEIGHT = 30;
459
+
460
+ /** recharts' defaults for an axis, before an `XAxis` or `YAxis` overrides them. */
461
+ function defaultAxis(axis, implicit) {
462
+ return {
463
+ axis,
464
+ implicit,
465
+ type: axis === 'x' ? 'category' : 'number',
466
+ hide: implicit,
467
+ height: DEFAULT_X_AXIS_HEIGHT,
468
+ width: DEFAULT_Y_AXIS_WIDTH,
469
+ orientation: axis === 'x' ? 'bottom' : 'left',
470
+ mirror: false,
471
+ reversed: false,
472
+ padding: {
473
+ start: 0,
474
+ end: 0
475
+ },
476
+ allowDataOverflow: false,
477
+ allowDecimals: true,
478
+ tickCount: 5,
479
+ tick: true,
480
+ tickLine: true,
481
+ axisLine: true,
482
+ tickSize: 6,
483
+ tickMargin: 2,
484
+ minTickGap: 5,
485
+ interval: 'preserveEnd',
486
+ angle: 0,
487
+ stroke: '#666',
488
+ scale: 'auto'
489
+ };
490
+ }
491
+
492
+ /** A series as the chart reads it: its kind, where its values come from, and its stack. */
493
+
494
+ /** A point of a series, with the value it shows and the row it came from. */
495
+
496
+ /** A bar: its rectangle and the value it shows. */
497
+
498
+ /** A tick an axis draws: its line, its label's position, and its text. */
499
+
500
+ /** A percentage of `total` (`'10%'`), or a number as is. */
501
+ function percentValue(value, total, fallback = 0) {
502
+ if (value === undefined || value === null) return fallback;
503
+ if (!isString(value)) return value;
504
+ const trimmed = value.trim();
505
+ if (trimmed.endsWith('%')) {
506
+ const ratio = parseFloat(trimmed) / 100;
507
+ return Number.isFinite(ratio) ? total * ratio : fallback;
508
+ }
509
+ const number = parseFloat(trimmed);
510
+ return Number.isFinite(number) ? number : fallback;
511
+ }
512
+ function isNumber(value) {
513
+ return Number.isFinite(value);
514
+ }
515
+
516
+ /** recharts' plot area: the chart less its margins, its drawn axes and its legend. */
517
+ function plotArea(input) {
518
+ const {
519
+ margin,
520
+ xAxis,
521
+ yAxis,
522
+ legend
523
+ } = input;
524
+ const shown = axis => !axis.hide && !axis.mirror;
525
+ const offset = {
526
+ top: margin.top + (shown(xAxis) && xAxis.orientation === 'top' ? xAxis.height : 0),
527
+ bottom: margin.bottom + (shown(xAxis) && xAxis.orientation === 'bottom' ? xAxis.height : 0),
528
+ left: margin.left + (shown(yAxis) && yAxis.orientation === 'left' ? yAxis.width : 0),
529
+ right: margin.right + (shown(yAxis) && yAxis.orientation === 'right' ? yAxis.width : 0)
530
+ };
531
+ if (legend) {
532
+ const {
533
+ align,
534
+ verticalAlign,
535
+ layout
536
+ } = legend;
537
+ if ((layout === 'vertical' || layout === 'horizontal' && verticalAlign === 'middle') && align !== 'center') {
538
+ offset[align] += legend.width;
539
+ } else if ((layout === 'horizontal' || layout === 'vertical' && align === 'center') && verticalAlign !== 'middle') {
540
+ offset[verticalAlign] += legend.height;
541
+ }
542
+ }
543
+ return {
544
+ ...offset,
545
+ width: Math.max(input.width - offset.left - offset.right, 0),
546
+ height: Math.max(input.height - offset.top - offset.bottom, 0)
547
+ };
548
+ }
549
+
550
+ /** Which axis lays out the categories: x, unless the chart is vertical. */
551
+ function categoryAxisOf(layout) {
552
+ return layout === 'horizontal' ? 'x' : 'y';
553
+ }
554
+
555
+ /** recharts' `combineRealScaleType`: a line or area chart puts categories on points, bars in bands. */
556
+ function scaleTypeOf(axis, chartName, hasBar) {
557
+ if (axis.scale !== 'auto') return axis.scale;
558
+ if (axis.type === 'category') {
559
+ if (chartName === 'LineChart' || chartName === 'AreaChart' || chartName === 'ComposedChart' && !hasBar) {
560
+ return 'point';
561
+ }
562
+ return 'band';
563
+ }
564
+ return 'linear';
565
+ }
566
+
567
+ /** The pixel range an axis maps to, before `reversed`. */
568
+ function rangeOf(axis, offset, layout) {
569
+ if (axis.axis === 'x') {
570
+ return [offset.left + axis.padding.start, offset.left + offset.width - axis.padding.end];
571
+ }
572
+ // A y-axis runs bottom to top, but categories in a vertical chart run top to bottom.
573
+ if (layout === 'horizontal' || axis.type === 'number') {
574
+ return [offset.top + offset.height - axis.padding.end, offset.top + axis.padding.start];
575
+ }
576
+ return [offset.top + axis.padding.start, offset.top + offset.height - axis.padding.end];
577
+ }
578
+ const OFFSETS = {
579
+ none: stackOffsetNone,
580
+ expand: stackOffsetExpand,
581
+ silhouette: stackOffsetSilhouette,
582
+ wiggle: stackOffsetWiggle
583
+ };
584
+
585
+ /** recharts' `sign` offset: positives stack up from 0, negatives down. */
586
+ function offsetSign(series, order) {
587
+ const n = series[0]?.length ?? 0;
588
+ for (let j = 0; j < n; ++j) {
589
+ let positive = 0;
590
+ let negative = 0;
591
+ for (const i of order) {
592
+ const point = series[i][j];
593
+ const value = Number.isNaN(point[1]) ? point[0] : point[1];
594
+ if (value >= 0) {
595
+ point[0] = positive;
596
+ point[1] = positive + value;
597
+ positive = point[1];
598
+ } else {
599
+ point[0] = negative;
600
+ point[1] = negative + value;
601
+ negative = point[1];
602
+ }
603
+ }
604
+ }
605
+ }
606
+
607
+ /** recharts' `positive` offset: only positives stack; negatives count as 0. */
608
+ function offsetPositive(series, order) {
609
+ const n = series[0]?.length ?? 0;
610
+ for (let j = 0; j < n; ++j) {
611
+ let positive = 0;
612
+ for (const i of order) {
613
+ const point = series[i][j];
614
+ const value = Number.isNaN(point[1]) ? point[0] : point[1];
615
+ if (value >= 0) {
616
+ point[0] = positive;
617
+ point[1] = positive + value;
618
+ positive = point[1];
619
+ } else {
620
+ point[0] = 0;
621
+ point[1] = 0;
622
+ }
623
+ }
624
+ }
625
+ }
626
+
627
+ /** Each stacked series' `[bottom, top]` per row, by series id. */
628
+ function stackGroups(input) {
629
+ const groups = new Map();
630
+ for (const series of input.series) {
631
+ if (series.hide || series.stackId === undefined || series.stackId === null) continue;
632
+ // Bars and areas stack separately, as recharts keeps one group per kind and stack id.
633
+ const key = `${series.type}:${series.stackId}`;
634
+ groups.set(key, [...(groups.get(key) ?? []), series]);
635
+ }
636
+ const result = new Map();
637
+ for (const members of groups.values()) {
638
+ const offset = input.stackOffset === 'sign' ? offsetSign : input.stackOffset === 'positive' ? offsetPositive : OFFSETS[input.stackOffset];
639
+ const stacked = stack().keys(members.map((_, i) => i)).value((datum, i) => {
640
+ const value = Number(valueOf(datum, members[i].dataKey));
641
+ return Number.isFinite(value) ? value : 0;
642
+ }).order(stackOrderNone).offset(offset)(input.data);
643
+ stacked.forEach((layer, i) => {
644
+ result.set(members[i].id, layer.map(point => [point[0], point[1]]));
645
+ });
646
+ }
647
+ return result;
648
+ }
649
+
650
+ /** A domain bound the chart resolves from the data: `auto`, `dataMin - 5`, a function. */
651
+ function resolveBound(bound, data, which) {
652
+ if (isNumber(bound)) return bound;
653
+ if (isFunction(bound)) return bound(data[which]);
654
+ if (bound === 'auto') return data[which];
655
+ const match = /^data(Min|Max)\s*([+-])?\s*(\d+(?:\.\d+)?)?$/.exec(String(bound));
656
+ if (match) {
657
+ const base = match[1] === 'Min' ? data[0] : data[1];
658
+ const delta = match[3] ? Number(match[3]) : 0;
659
+ return match[2] === '-' ? base - delta : base + delta;
660
+ }
661
+ return undefined;
662
+ }
663
+
664
+ /** The value axis's domain: the data's (stacked) extent, the user's `domain`, and nice ticks. */
665
+ function valueDomain(input, axis, stacks) {
666
+ const definition = axis.domain ?? [0, 'auto'];
667
+ if (input.stackOffset === 'expand' && stacks.size) {
668
+ const ticks = getNiceTickValues([0, 1], axis.tickCount, axis.allowDecimals);
669
+ return {
670
+ domain: [0, 1],
671
+ niceTicks: ticks
672
+ };
673
+ }
674
+ let min = Infinity;
675
+ let max = -Infinity;
676
+ for (const series of input.series) {
677
+ if (series.hide) continue;
678
+ const stacked = stacks.get(series.id);
679
+ if (stacked) {
680
+ for (const [bottom, top] of stacked) {
681
+ min = Math.min(min, bottom, top);
682
+ max = Math.max(max, bottom, top);
683
+ }
684
+ continue;
685
+ }
686
+ for (const datum of input.data) {
687
+ const raw = valueOf(datum, series.dataKey);
688
+ const values = Array.isArray(raw) ? raw : [raw];
689
+ for (const value of values) {
690
+ const number = Number(value);
691
+ if (value === null || value === undefined || value === '' || !Number.isFinite(number)) continue;
692
+ min = Math.min(min, number);
693
+ max = Math.max(max, number);
694
+ }
695
+ }
696
+ }
697
+ const data = Number.isFinite(min) ? [min, max] : [0, 0];
698
+ let lower = resolveBound(definition[0], data, 0) ?? data[0];
699
+ let upper = resolveBound(definition[1], data, 1) ?? data[1];
700
+ if (!axis.allowDataOverflow) {
701
+ lower = Math.min(lower, data[0]);
702
+ upper = Math.max(upper, data[1]);
703
+ }
704
+ const hasAuto = definition[0] === 'auto' || definition[1] === 'auto';
705
+ let niceTicks;
706
+ if (axis.ticks) {
707
+ niceTicks = undefined;
708
+ } else if (hasAuto) {
709
+ niceTicks = getNiceTickValues([lower, upper], axis.tickCount, axis.allowDecimals);
710
+ } else {
711
+ niceTicks = getTickValuesFixedDomain([lower, upper], axis.tickCount, axis.allowDecimals);
712
+ }
713
+ if (niceTicks?.length) {
714
+ lower = Math.min(lower, niceTicks[0]);
715
+ upper = Math.max(upper, niceTicks[niceTicks.length - 1]);
716
+ }
717
+ return {
718
+ domain: [lower, upper],
719
+ niceTicks
720
+ };
721
+ }
722
+
723
+ /** recharts' `getBaseValue`: where an area or bar starts on the value axis. */
724
+ function baseValueOf(domain, baseValue) {
725
+ const [a, b] = domain;
726
+ const domainMax = Math.max(a, b);
727
+ const domainMin = Math.min(a, b);
728
+ if (isNumber(baseValue)) return baseValue;
729
+ if (baseValue === 'dataMin') return domainMin;
730
+ if (baseValue === 'dataMax') return domainMax;
731
+ return domainMax < 0 ? domainMax : Math.max(domainMin, 0);
732
+ }
733
+ /** recharts' `getBarPositions`: each bar slot's offset in the band and its width. */
734
+ function barPositions(bandSize, slots, barGap, barCategoryGap, maxBarSize) {
735
+ const len = slots.length;
736
+ if (len < 1) return [];
737
+ let realBarGap = percentValue(barGap, bandSize);
738
+ if (isNumber(slots[0].barSize)) {
739
+ let useFull = false;
740
+ let fullBarSize = bandSize / len;
741
+ let sum = slots.reduce((total, slot) => total + (slot.barSize ?? 0), 0) + (len - 1) * realBarGap;
742
+ if (sum >= bandSize) {
743
+ sum -= (len - 1) * realBarGap;
744
+ realBarGap = 0;
745
+ }
746
+ if (sum >= bandSize && fullBarSize > 0) {
747
+ useFull = true;
748
+ fullBarSize *= 0.9;
749
+ sum = len * fullBarSize;
750
+ }
751
+ const offset = (bandSize - sum) / 2 >> 0;
752
+ let previous = {
753
+ offset: offset - realBarGap,
754
+ size: 0
755
+ };
756
+ return slots.map(slot => {
757
+ const position = {
758
+ offset: previous.offset + previous.size + realBarGap,
759
+ size: useFull ? fullBarSize : slot.barSize ?? 0
760
+ };
761
+ previous = position;
762
+ return position;
763
+ });
764
+ }
765
+ const offset = percentValue(barCategoryGap, bandSize);
766
+ if (bandSize - 2 * offset - (len - 1) * realBarGap <= 0) realBarGap = 0;
767
+ let originalSize = (bandSize - 2 * offset - (len - 1) * realBarGap) / len;
768
+ if (originalSize > 1) originalSize >>= 0;
769
+ const size = isNumber(maxBarSize) ? Math.min(originalSize, maxBarSize) : originalSize;
770
+ return slots.map((_, i) => ({
771
+ offset: offset + (originalSize + realBarGap) * i + (originalSize - size) / 2,
772
+ size
773
+ }));
774
+ }
775
+ function formatTick(axis, value, index) {
776
+ const formatted = axis.tickFormatter ? axis.tickFormatter(value, index) : value;
777
+ return `${formatted ?? ''}${axis.unit ?? ''}`;
778
+ }
779
+
780
+ /** recharts' `getTickLineCoord`: a tick's line and where its label is anchored. */
781
+ function tickGeometry(tick, box, axis) {
782
+ const {
783
+ x,
784
+ y,
785
+ width,
786
+ height
787
+ } = box;
788
+ const sign = axis.mirror ? -1 : 1;
789
+ const size = axis.tickSize;
790
+ const margin = axis.tickMargin;
791
+ const coord = isNumber(tick.tickCoord) ? tick.tickCoord : tick.coordinate;
792
+ let x1, x2, y1, y2, tx, ty;
793
+ switch (axis.orientation) {
794
+ case 'top':
795
+ x1 = x2 = tick.coordinate;
796
+ y2 = y + Number(!axis.mirror) * height;
797
+ y1 = y2 - sign * size;
798
+ ty = y1 - sign * margin;
799
+ tx = coord;
800
+ break;
801
+ case 'left':
802
+ y1 = y2 = tick.coordinate;
803
+ x2 = x + Number(!axis.mirror) * width;
804
+ x1 = x2 - sign * size;
805
+ tx = x1 - sign * margin;
806
+ ty = coord;
807
+ break;
808
+ case 'right':
809
+ y1 = y2 = tick.coordinate;
810
+ x2 = x + Number(axis.mirror) * width;
811
+ x1 = x2 + sign * size;
812
+ tx = x1 + sign * margin;
813
+ ty = coord;
814
+ break;
815
+ default:
816
+ x1 = x2 = tick.coordinate;
817
+ y2 = y + Number(axis.mirror) * height;
818
+ y1 = y2 + sign * size;
819
+ ty = y1 + sign * margin;
820
+ tx = coord;
821
+ }
822
+ return {
823
+ line: {
824
+ x1,
825
+ y1,
826
+ x2,
827
+ y2
828
+ },
829
+ label: {
830
+ x: tx,
831
+ y: ty
832
+ }
833
+ };
834
+ }
835
+ function axisLineOf(axis, box) {
836
+ const {
837
+ x,
838
+ y,
839
+ width,
840
+ height
841
+ } = box;
842
+ if (axis.orientation === 'top' || axis.orientation === 'bottom') {
843
+ const needHeight = Number(axis.orientation === 'top' && !axis.mirror || axis.orientation === 'bottom' && axis.mirror);
844
+ return {
845
+ x1: x,
846
+ y1: y + needHeight * height,
847
+ x2: x + width,
848
+ y2: y + needHeight * height
849
+ };
850
+ }
851
+ const needWidth = Number(axis.orientation === 'left' && !axis.mirror || axis.orientation === 'right' && axis.mirror);
852
+ return {
853
+ x1: x + needWidth * width,
854
+ y1: y,
855
+ x2: x + needWidth * width,
856
+ y2: y + height
857
+ };
858
+ }
859
+
860
+ /** An axis's box, beside the plot area on its side. */
861
+ function axisBox(axis, offset) {
862
+ if (axis.axis === 'x') {
863
+ const y = axis.orientation === 'top' ? offset.top - axis.height : offset.top + offset.height;
864
+ return {
865
+ x: offset.left,
866
+ y: axis.mirror ? axis.orientation === 'top' ? offset.top : offset.top + offset.height - axis.height : y,
867
+ width: offset.width,
868
+ height: axis.height
869
+ };
870
+ }
871
+ const x = axis.orientation === 'left' ? axis.mirror ? offset.left : offset.left - axis.width : axis.mirror ? offset.left + offset.width - axis.width : offset.left + offset.width;
872
+ return {
873
+ x,
874
+ y: offset.top,
875
+ width: axis.width,
876
+ height: offset.height
877
+ };
878
+ }
879
+
880
+ /**
881
+ * Everything a cartesian chart draws, in pixels. recharts' selectors, in one pass: the plot
882
+ * area, both axes' scales and ticks, the grid, and every series' points and bars.
883
+ */
884
+ function cartesianGeometry(input) {
885
+ const {
886
+ layout,
887
+ data
888
+ } = input;
889
+ const offset = plotArea(input);
890
+ const categoryKey = categoryAxisOf(layout);
891
+ const categoryAxis = categoryKey === 'x' ? input.xAxis : input.yAxis;
892
+ const valueAxis = categoryKey === 'x' ? input.yAxis : input.xAxis;
893
+ const hasBar = input.series.some(series => series.type === 'bar' && !series.hide);
894
+
895
+ // The category axis: one slot per row (or the axis's own numbers, for type="number").
896
+ const categoryValues = data.map((datum, index) => categoryAxis.dataKey === undefined ? index : valueOf(datum, categoryAxis.dataKey));
897
+ const categoryScaleType = scaleTypeOf(categoryAxis, input.chartName, hasBar);
898
+ let categoryRange = rangeOf(categoryAxis, offset, layout);
899
+ if (categoryAxis.reversed) categoryRange = [categoryRange[1], categoryRange[0]];
900
+ let bandSize = 0;
901
+ let categoryPosition;
902
+ if (categoryScaleType === 'band' || categoryScaleType === 'point') {
903
+ const indexes = data.map((_, index) => index);
904
+ const scale = categoryScaleType === 'band' ? scaleBand().domain(indexes).range(categoryRange) : scalePoint().domain(indexes).range(categoryRange);
905
+ bandSize = scale.bandwidth();
906
+ categoryPosition = index => scale(index) ?? null;
907
+ } else {
908
+ const numbers = categoryValues.map(Number).filter(Number.isFinite);
909
+ const extent = numbers.length ? [Math.min(...numbers), Math.max(...numbers)] : [0, 0];
910
+ const scale = scaleLinear().domain(extent).range(categoryRange);
911
+ categoryPosition = index => {
912
+ const value = Number(categoryValues[index]);
913
+ return Number.isFinite(value) ? scale(value) : null;
914
+ };
915
+ }
916
+ const categoryOffset = categoryScaleType === 'band' ? bandSize / 2 : 0;
917
+ const categoryTicks = data.map((_, index) => ({
918
+ index,
919
+ coordinate: (categoryPosition(index) ?? 0) + categoryOffset,
920
+ value: categoryValues[index]
921
+ }));
922
+
923
+ // The value axis: the data's extent, stacked, made nice.
924
+ const stacks = stackGroups(input);
925
+ const {
926
+ domain,
927
+ niceTicks
928
+ } = valueDomain(input, valueAxis, stacks);
929
+ let valueRange = rangeOf(valueAxis, offset, layout);
930
+ if (valueAxis.reversed) valueRange = [valueRange[1], valueRange[0]];
931
+ const valueScale = scaleLinear().domain(domain).range(valueRange);
932
+
933
+ // Ticks: every category, or the value axis's nice ticks.
934
+ const valueTickValues = valueAxis.ticks ?? niceTicks ?? valueScale.ticks(valueAxis.tickCount);
935
+ const rawCategoryTicks = (categoryAxis.ticks ? categoryAxis.ticks.map((value, index) => ({
936
+ index,
937
+ value,
938
+ coordinate: (categoryPosition(categoryValues.indexOf(value)) ?? NaN) + categoryOffset
939
+ })) : categoryTicks.map(tick => ({
940
+ ...tick
941
+ }))).filter(tick => Number.isFinite(tick.coordinate));
942
+ const rawValueTicks = valueTickValues.map((value, index) => ({
943
+ index,
944
+ value,
945
+ coordinate: valueScale(value)
946
+ })).filter(tick => Number.isFinite(tick.coordinate));
947
+ const viewBox = {
948
+ x: 0,
949
+ y: 0,
950
+ width: input.width,
951
+ height: input.height
952
+ };
953
+ const axisGeometry = (axis, rawTicks) => {
954
+ const box = axisBox(axis, offset);
955
+ const style = axis.axis === 'x' ? input.tickStyle.x : input.tickStyle.y;
956
+ const shown = input.measure ? visibleTicks({
957
+ ticks: rawTicks,
958
+ viewBox,
959
+ orientation: axis.orientation,
960
+ interval: axis.interval,
961
+ minTickGap: axis.minTickGap,
962
+ tickFormatter: axis.tickFormatter,
963
+ unit: axis.unit,
964
+ tick: axis.tick,
965
+ angle: axis.angle,
966
+ style
967
+ }) : rawTicks.filter((_, i) => isString(axis.interval) || i % (axis.interval + 1) === 0);
968
+ const vertical = axis.orientation === 'left' || axis.orientation === 'right';
969
+ return {
970
+ settings: axis,
971
+ box,
972
+ line: axisLineOf(axis, box),
973
+ ticks: shown.map(tick => ({
974
+ value: tick.value,
975
+ index: tick.index,
976
+ coordinate: tick.coordinate,
977
+ ...tickGeometry(tick, box, axis),
978
+ text: formatTick(axis, tick.value, tick.index)
979
+ })),
980
+ textAnchor: axis.orientation === 'left' ? axis.mirror ? 'start' : 'end' : axis.orientation === 'right' ? axis.mirror ? 'end' : 'start' : 'middle',
981
+ dy: vertical ? '0.355em' : axis.orientation === 'top' !== axis.mirror ? '0em' : '0.71em'
982
+ };
983
+ };
984
+ const xTicks = categoryKey === 'x' ? rawCategoryTicks : rawValueTicks;
985
+ const yTicks = categoryKey === 'x' ? rawValueTicks : rawCategoryTicks;
986
+ const xAxis = axisGeometry(input.xAxis, xTicks);
987
+ const yAxis = axisGeometry(input.yAxis, yTicks);
988
+
989
+ // The grid: the ticks each axis would draw (measured in the page's own font, as recharts'
990
+ // grid measures them), plus the plot area's edges.
991
+ const gridTicks = (axis, rawTicks) => {
992
+ const shown = input.measure ? visibleTicks({
993
+ ticks: rawTicks,
994
+ viewBox,
995
+ orientation: axis.orientation,
996
+ interval: axis.interval,
997
+ minTickGap: axis.minTickGap,
998
+ tickFormatter: axis.tickFormatter,
999
+ unit: axis.unit,
1000
+ tick: axis.tick,
1001
+ angle: axis.angle,
1002
+ style: {}
1003
+ }) : rawTicks;
1004
+ return shown.map(tick => tick.coordinate);
1005
+ };
1006
+ const withEdges = (coordinates, min, max) => {
1007
+ const result = coordinates.slice();
1008
+ if (!result.includes(min)) result.push(min);
1009
+ if (!result.includes(max)) result.push(max);
1010
+ return result;
1011
+ };
1012
+ // The grid of a band axis sits on the band's middle, like its ticks; a point axis's on the points.
1013
+ const grid = {
1014
+ horizontal: withEdges(gridTicks(input.yAxis, yTicks), offset.top, offset.top + offset.height),
1015
+ vertical: withEdges(gridTicks(input.xAxis, xTicks), offset.left, offset.left + offset.width)
1016
+ };
1017
+
1018
+ // The series.
1019
+ const toPixel = (category, value) => layout === 'horizontal' ? {
1020
+ x: category,
1021
+ y: value
1022
+ } : {
1023
+ x: value,
1024
+ y: category
1025
+ };
1026
+ const visibleBars = input.series.filter(series => series.type === 'bar' && !series.hide);
1027
+ const slots = [];
1028
+ for (const bar of visibleBars) {
1029
+ const key = bar.stackId !== undefined && bar.stackId !== null ? `stack:${bar.stackId}` : `bar:${bar.id}`;
1030
+ if (!slots.some(slot => slot.key === key)) slots.push({
1031
+ key,
1032
+ barSize: bar.barSize ?? input.barSize
1033
+ });
1034
+ }
1035
+ const positions = barPositions(bandSize, slots, input.barGap, input.barCategoryGap, input.maxBarSize);
1036
+ const series = input.series.map(settings => {
1037
+ const stacked = stacks.get(settings.id);
1038
+ const seriesBase = baseValueOf(domain, settings.baseValue);
1039
+ if (settings.type === 'bar') {
1040
+ const key = settings.stackId !== undefined && settings.stackId !== null ? `stack:${settings.stackId}` : `bar:${settings.id}`;
1041
+ const position = positions[slots.findIndex(slot => slot.key === key)];
1042
+ const bars = [];
1043
+ if (!settings.hide && position) {
1044
+ data.forEach((datum, index) => {
1045
+ const start = categoryPosition(index);
1046
+ if (start === null) return;
1047
+ const raw = valueOf(datum, settings.dataKey);
1048
+ let low;
1049
+ let high;
1050
+ if (stacked) {
1051
+ [low, high] = stacked[index];
1052
+ } else if (Array.isArray(raw)) {
1053
+ [low, high] = [Number(raw[0]), Number(raw[1])];
1054
+ } else {
1055
+ low = seriesBase;
1056
+ high = Number(raw);
1057
+ }
1058
+ if (!Number.isFinite(high) || !Number.isFinite(low)) return;
1059
+ const valueStart = valueScale(low);
1060
+ const valueEnd = valueScale(high);
1061
+ // recharts leaves out a bar with no length (a zero), unless it has a shape of its own.
1062
+ if ((valueStart === valueEnd || position.size === 0) && !settings.hasCustomShape) return;
1063
+ const bandStart = start + position.offset;
1064
+ const background = layout === 'horizontal' ? {
1065
+ x: bandStart,
1066
+ y: offset.top,
1067
+ width: position.size,
1068
+ height: offset.height
1069
+ } : {
1070
+ x: offset.left,
1071
+ y: bandStart,
1072
+ width: offset.width,
1073
+ height: position.size
1074
+ };
1075
+ bars.push(layout === 'horizontal' ? {
1076
+ x: bandStart,
1077
+ y: valueEnd,
1078
+ width: position.size,
1079
+ height: valueStart - valueEnd,
1080
+ value: raw,
1081
+ payload: datum,
1082
+ index,
1083
+ background
1084
+ } : {
1085
+ x: valueStart,
1086
+ y: bandStart,
1087
+ width: valueEnd - valueStart,
1088
+ height: position.size,
1089
+ value: raw,
1090
+ payload: datum,
1091
+ index,
1092
+ background
1093
+ });
1094
+ });
1095
+ }
1096
+ return {
1097
+ settings,
1098
+ points: [],
1099
+ base: valueScale(seriesBase),
1100
+ bars
1101
+ };
1102
+ }
1103
+ const points = data.map((datum, index) => {
1104
+ const category = categoryPosition(index);
1105
+ const center = category === null ? null : category + categoryOffset;
1106
+ const raw = valueOf(datum, settings.dataKey);
1107
+ let top;
1108
+ if (stacked) {
1109
+ top = raw === null || raw === undefined ? null : valueScale(stacked[index][1]);
1110
+ } else if (Array.isArray(raw)) {
1111
+ top = Number.isFinite(Number(raw[1])) ? valueScale(Number(raw[1])) : null;
1112
+ } else {
1113
+ const number = Number(raw);
1114
+ top = raw === null || raw === undefined || raw === '' || !Number.isFinite(number) ? null : valueScale(number);
1115
+ }
1116
+ return {
1117
+ ...toPixel(center, top),
1118
+ value: raw,
1119
+ payload: datum,
1120
+ index
1121
+ };
1122
+ });
1123
+ let areaBase = valueScale(seriesBase);
1124
+ if (settings.type === 'area') {
1125
+ if (stacked) {
1126
+ areaBase = data.map((datum, index) => {
1127
+ const category = categoryPosition(index);
1128
+ const center = category === null ? null : category + categoryOffset;
1129
+ return {
1130
+ ...toPixel(center, valueScale(stacked[index][0])),
1131
+ value: undefined,
1132
+ payload: datum,
1133
+ index
1134
+ };
1135
+ });
1136
+ } else if (data.some(datum => Array.isArray(valueOf(datum, settings.dataKey)))) {
1137
+ areaBase = data.map((datum, index) => {
1138
+ const category = categoryPosition(index);
1139
+ const center = category === null ? null : category + categoryOffset;
1140
+ const raw = valueOf(datum, settings.dataKey);
1141
+ const low = Array.isArray(raw) ? Number(raw[0]) : seriesBase;
1142
+ return {
1143
+ ...toPixel(center, valueScale(low)),
1144
+ value: undefined,
1145
+ payload: datum,
1146
+ index
1147
+ };
1148
+ });
1149
+ }
1150
+ }
1151
+ return {
1152
+ settings,
1153
+ points,
1154
+ base: areaBase,
1155
+ bars: []
1156
+ };
1157
+ });
1158
+ return {
1159
+ offset,
1160
+ xAxis,
1161
+ yAxis,
1162
+ categoryTicks,
1163
+ bandSize,
1164
+ grid,
1165
+ series,
1166
+ valueDomain: domain
1167
+ };
1168
+ }
1169
+
1170
+ /** The row under a pointer at `position` along the category axis: the nearest tick. */
1171
+ function activeIndexAt(ticks, position) {
1172
+ if (!ticks.length) return null;
1173
+ let best = ticks[0];
1174
+ for (const tick of ticks) {
1175
+ if (Math.abs(tick.coordinate - position) < Math.abs(best.coordinate - position)) best = tick;
1176
+ }
1177
+ return best.index;
1178
+ }
1179
+
1180
+ /** recharts' `getTooltipTranslateXY`: where the tooltip box goes on one axis. */
1181
+ function tooltipTranslate(options) {
1182
+ const {
1183
+ coordinate,
1184
+ offset,
1185
+ tooltipSize,
1186
+ viewBoxStart,
1187
+ viewBoxSize,
1188
+ allowEscape,
1189
+ reverse,
1190
+ position
1191
+ } = options;
1192
+ if (isNumber(position)) return position;
1193
+ const negative = coordinate - tooltipSize - (offset > 0 ? offset : 0);
1194
+ const positive = coordinate + offset;
1195
+ if (allowEscape) return reverse ? negative : positive;
1196
+ if (reverse) {
1197
+ return negative < viewBoxStart ? Math.max(positive, viewBoxStart) : Math.max(negative, viewBoxStart);
1198
+ }
1199
+ return positive + tooltipSize > viewBoxStart + viewBoxSize ? Math.max(negative, viewBoxStart) : Math.max(positive, viewBoxStart);
1200
+ }
1201
+
1202
+ /**
1203
+ * recharts' `resolveTransitionProperty`: the tooltip box's transition as it moves, as a style
1204
+ * declaration (with a leading space), or nothing. By default (`'auto'`) it moves smoothly unless
1205
+ * the user prefers reduced motion; `true` always, `false` never.
1206
+ */
1207
+ function tooltipTransition(isAnimationActive = 'auto') {
1208
+ if (isAnimationActive === false) return '';
1209
+ if (isAnimationActive === 'auto' && prefersReducedMotion()) return '';
1210
+ return ' transition: transform 400ms ease;';
1211
+ }
1212
+ function prefersReducedMotion() {
1213
+ return !isUndefined(globalThis.window) && isFunction(window.matchMedia) && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
1214
+ }
1215
+
1216
+ export { activeIndexAt as a, clearStringSizeCache as b, cartesianGeometry as c, defaultAxis as d, tooltipTransition as e, getTickValuesFixedDomain as f, getNiceTickValues as g, plotArea as p, tooltipTranslate as t, valueOf as v };
1217
+ //# sourceMappingURL=cartesian-D9hWDamz.js.map