@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,2242 @@
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 { isString, isFunction, isNumber as isNumber$1, isObject } from '@sindresorhus/is';
24
+ import Component from '@glimmer/component';
25
+ import { tracked, cached } from '@glimmer/tracking';
26
+ import { hash } from '@ember/helper';
27
+ import { on } from '@ember/modifier';
28
+ import { htmlSafe } from '@ember/template';
29
+ import { modifier } from 'ember-modifier';
30
+ import { idFor } from '@ember-joinery/primitives/id';
31
+ import { resizeObserver } from '@ember-joinery/primitives/resize-observer';
32
+ import { R as Registry, C as ChartTooltip, a as ChartLegend, i as isPlainObject } from './parts-BWLhFFjB.js';
33
+ import { v as valueOf, g as getNiceTickValues, f as getTickValuesFixedDomain, p as plotArea, d as defaultAxis, t as tooltipTranslate, e as tooltipTransition } from './cartesian-D9hWDamz.js';
34
+ import { scaleBand, scalePoint, scaleLinear } from 'd3-scale';
35
+ import { stackOffsetWiggle, stackOffsetSilhouette, stackOffsetExpand, stackOffsetNone, stack, stackOrderNone } from 'd3-shape';
36
+ import { precompileTemplate } from '@ember/template-compilation';
37
+ import { setComponentTemplate } from '@ember/component';
38
+ import ChartTooltipContent from './components/chart-tooltip-content.js';
39
+ import ChartLegendContent from './components/chart-legend-content.js';
40
+ import templateOnly from '@ember/component/template-only';
41
+ import { g, i, n } from 'decorator-transforms/runtime';
42
+
43
+ /*
44
+ * The geometry of a polar chart (radar and radial bar charts), computed the way recharts 3
45
+ * computes it, so a Joinery chart draws the same marks in the same places: the chart's ring
46
+ * (its centre and radii, left by the margins and the legend); each polar axis's domain, scale and
47
+ * ticks; a radar's points; and each radial bar's sector, stacked where bars share a `stackId`.
48
+ * It also has recharts' sector and polygon paths, the path a radial label runs along, and the
49
+ * hit test that finds the row under the pointer.
50
+ *
51
+ * Everything here is a pure function of the chart's settings and size.
52
+ *
53
+ * recharts is MIT licensed; its notice is in NOTICE, and the build keeps it in the module that
54
+ * ships this (see rollup.config.mjs).
55
+ */
56
+ const RADIAN = Math.PI / 180;
57
+ /** recharts' `polarToCartesian`: the point at `angle` degrees (counter-clockwise from 3 o'clock). */
58
+ function polarToCartesian(cx, cy, radius, angle) {
59
+ return {
60
+ x: cx + Math.cos(-RADIAN * angle) * radius,
61
+ y: cy + Math.sin(-RADIAN * angle) * radius
62
+ };
63
+ }
64
+ function mathSign(value) {
65
+ if (value === 0) return 0;
66
+ return value > 0 ? 1 : -1;
67
+ }
68
+ function isNumber(value) {
69
+ return Number.isFinite(value);
70
+ }
71
+
72
+ /**
73
+ * recharts' `getPercentValue`: a percentage of `total` (`'80%'`), or a number as is. With
74
+ * `validate`, never more than `total`. It multiplies before it divides, as recharts does, so the
75
+ * radii come out as recharts' do to the last digit.
76
+ */
77
+ function percentValue(value, total, fallback = 0, validate = false) {
78
+ if (!isString(value) && !isNumber(value)) return fallback;
79
+ let result;
80
+ if (isString(value) && value.includes('%')) {
81
+ result = total * parseFloat(value.slice(0, value.indexOf('%'))) / 100;
82
+ } else {
83
+ result = +value;
84
+ }
85
+ if (Number.isNaN(result)) result = fallback;
86
+ if (validate && result > total) result = total;
87
+ return result;
88
+ }
89
+
90
+ /** recharts' `round`: four decimals, and never `-0`. */
91
+ function round4(value) {
92
+ const rounded = Math.round(value * 10000) / 10000;
93
+ return Object.is(rounded, -0) ? 0 : rounded;
94
+ }
95
+
96
+ /** recharts' `roundTemplateLiteral`: a path with each number rounded to four decimals. */
97
+ function path(strings, ...values) {
98
+ return strings.reduce((out, string, i) => {
99
+ if (i === 0) return string;
100
+ const value = values[i - 1];
101
+ return out + (isString(value) ? value : round4(value)) + string;
102
+ }, '');
103
+ }
104
+
105
+ // ---------------------------------------------------------------------------------------------
106
+ // Settings
107
+
108
+ /** `centric`: categories around the ring (a radar). `radial`: categories out from the centre. */
109
+
110
+ /** What a polar axis does, with recharts' defaults filled in. */
111
+
112
+ /** recharts' defaults for an angle axis (`PolarAngleAxis`, or the one a chart makes up). */
113
+ function defaultAngleAxis() {
114
+ return {
115
+ type: 'auto',
116
+ allowDecimals: false,
117
+ allowDataOverflow: false,
118
+ // PolarAngleAxis always lays its axis out as if this were false.
119
+ allowDuplicatedCategory: false,
120
+ reversed: false,
121
+ scale: 'auto'
122
+ };
123
+ }
124
+
125
+ /** recharts' defaults for a radius axis (`PolarRadiusAxis`, or the one a chart makes up). */
126
+ function defaultRadiusAxis() {
127
+ return {
128
+ type: 'auto',
129
+ allowDecimals: false,
130
+ allowDataOverflow: false,
131
+ allowDuplicatedCategory: true,
132
+ tickCount: 5,
133
+ reversed: false,
134
+ scale: 'auto'
135
+ };
136
+ }
137
+
138
+ // ---------------------------------------------------------------------------------------------
139
+ // Output
140
+
141
+ /** The chart's ring: recharts' polar view box. */
142
+
143
+ // ---------------------------------------------------------------------------------------------
144
+ // Axes
145
+
146
+ /** recharts' `isCategoricalAxis` for a polar chart. */
147
+ function isCategoricalAxis(layout, axisType) {
148
+ return layout === 'centric' && axisType === 'angleAxis' || layout === 'radial' && axisType === 'radiusAxis';
149
+ }
150
+ function range(start, end) {
151
+ return Array.from({
152
+ length: Math.max(end - start, 0)
153
+ }, (_, i) => start + i);
154
+ }
155
+ function hasDuplicate(values) {
156
+ return new Set(values).size !== values.length;
157
+ }
158
+ function makeNumber(value) {
159
+ if (value === null || value === undefined || value === '') return undefined;
160
+ const number = Number(value);
161
+ return Number.isFinite(number) ? number : undefined;
162
+ }
163
+
164
+ /** recharts' `makeDomain`: a value's extent (a pair for a range value). */
165
+ function makeDomain(value) {
166
+ if (Array.isArray(value)) {
167
+ const low = makeNumber(value[0]);
168
+ const high = makeNumber(value[1]);
169
+ return low !== undefined && high !== undefined ? [low, high] : undefined;
170
+ }
171
+ const number = makeNumber(value);
172
+ return number === undefined ? undefined : [number, number];
173
+ }
174
+ const MIN_VALUE_REG = /^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/;
175
+ const MAX_VALUE_REG = /^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/;
176
+
177
+ /** recharts' `parseNumericalUserDomain`: the user's domain resolved against the data's. */
178
+ function parseNumericalDomain(definition, data, allowDataOverflow) {
179
+ if (!allowDataOverflow && !data) return undefined;
180
+ const bound = (value, which) => {
181
+ const regex = which === 0 ? MIN_VALUE_REG : MAX_VALUE_REG;
182
+ if (value === 'auto') {
183
+ return data ? which === 0 ? Math.min(...data) : Math.max(...data) : undefined;
184
+ }
185
+ if (isNumber(value)) return value;
186
+ if (isFunction(value)) {
187
+ try {
188
+ return data ? value(data[which]) : undefined;
189
+ } catch {
190
+ return undefined;
191
+ }
192
+ }
193
+ if (isString(value) && regex.test(value)) {
194
+ const match = regex.exec(value);
195
+ if (!match?.[1] || !data) return undefined;
196
+ return which === 0 ? data[0] - Number(match[1]) : data[1] + Number(match[1]);
197
+ }
198
+ return data?.[which];
199
+ };
200
+ const low = bound(definition[0], 0);
201
+ const high = bound(definition[1], 1);
202
+ if (!isNumber(low) || !isNumber(high)) return undefined;
203
+ if (!data || allowDataOverflow) return [low, high];
204
+ return [Math.min(low, data[0]), Math.max(high, data[1])];
205
+ }
206
+
207
+ /** recharts' `getDomainDefinition`. */
208
+ function domainDefinition(axis, type) {
209
+ if (axis.domain) return axis.domain;
210
+ if (axis.ticks && type === 'number') {
211
+ const values = axis.ticks.map(makeNumber).filter(isNumber);
212
+ return [Math.min(...values), Math.max(...values)];
213
+ }
214
+ return [0, 'auto'];
215
+ }
216
+ /** recharts' `combineAppliedValues`: the values an axis lays out. */
217
+ function appliedValues(data, axis, items) {
218
+ if (axis.dataKey !== undefined) return data.map(row => valueOf(row, axis.dataKey));
219
+ if (items.length) return items.flatMap(item => data.map(row => valueOf(row, item.dataKey)));
220
+ return [...data];
221
+ }
222
+ function resolveAxis(input, axisType, items) {
223
+ const {
224
+ layout,
225
+ data
226
+ } = input;
227
+ const settings = axisType === 'angleAxis' ? input.angleAxis : input.radiusAxis;
228
+ const isCategorical = isCategoricalAxis(layout, axisType);
229
+ const type = settings.type === 'auto' ? isCategorical ? 'category' : 'number' : settings.type;
230
+ const axis = {
231
+ ...settings};
232
+ const applied = appliedValues(data, settings, items);
233
+
234
+ // combineAxisDomain
235
+ let domain;
236
+ if (isCategorical && settings.dataKey === undefined) {
237
+ domain = range(0, data.length);
238
+ } else if (type === 'category') {
239
+ const categories = applied.filter(value => isString(value) || isNumber(value) || value instanceof Date);
240
+ if (isCategorical && (settings.dataKey === undefined || settings.allowDuplicatedCategory && hasDuplicate(categories))) {
241
+ domain = range(0, applied.length);
242
+ } else {
243
+ domain = settings.allowDuplicatedCategory ? categories : [...new Set(categories)];
244
+ }
245
+ } else if (input.stackOffset === 'expand') {
246
+ domain = [0, 1];
247
+ } else {
248
+ // combineNumericalDomain: the items' values (and the axis's own data key's); a polar chart
249
+ // leaves stacking out of its domain, as recharts does.
250
+ let low;
251
+ let high;
252
+ const extend = value => {
253
+ const extent = makeDomain(value);
254
+ if (!extent) return;
255
+ low = low === undefined ? extent[0] : Math.min(low, extent[0]);
256
+ high = high === undefined ? extent[1] : Math.max(high, extent[1]);
257
+ };
258
+ for (const row of data) {
259
+ for (const item of items) extend(valueOf(row, settings.dataKey ?? item.dataKey));
260
+ }
261
+ if (settings.dataKey !== undefined) for (const row of data) extend(valueOf(row, settings.dataKey));
262
+ const extent = isNumber(low) && isNumber(high) ? [low, high] : undefined;
263
+ domain = parseNumericalDomain(domainDefinition(axis, type), extent, settings.allowDataOverflow) ?? [];
264
+ }
265
+
266
+ // combineRealScaleType
267
+ const realScale = settings.scale !== 'auto' ? settings.scale : type === 'category' ? 'band' : 'linear';
268
+
269
+ // combineNiceTicks, and the domain they extend (the angle axis's they don't)
270
+ let niceTicks;
271
+ const numeric = domain.length === 2 && isNumber(domain[0]) && isNumber(domain[1]);
272
+ if (realScale === 'linear' && settings.tickCount && numeric) {
273
+ const definition = domainDefinition(axis, type);
274
+ const hasAuto = definition[0] === 'auto' || definition[1] === 'auto';
275
+ const pair = domain;
276
+ if (hasAuto) niceTicks = getNiceTickValues(pair, settings.tickCount, settings.allowDecimals);else if (type === 'number') niceTicks = getTickValuesFixedDomain(pair, settings.tickCount, settings.allowDecimals);
277
+ }
278
+ if (axisType !== 'angleAxis' && type === 'number' && numeric && niceTicks?.length) {
279
+ domain = [Math.min(domain[0], niceTicks[0]), Math.max(domain[1], niceTicks[niceTicks.length - 1])];
280
+ }
281
+
282
+ // The range: the angles, or the radii; then `reversed`.
283
+ const viewBox = viewBoxOf(input);
284
+ let axisRange = axisType === 'angleAxis' ? [input.startAngle, input.endAngle] : [viewBox.innerRadius, viewBox.outerRadius];
285
+ if (settings.reversed) axisRange = [axisRange[1], axisRange[0]];
286
+ let bandwidth = 0;
287
+ let scale;
288
+ let scaleTicks;
289
+ if (realScale === 'band') {
290
+ const band = scaleBand().domain(domain.map(value => value)).range(axisRange);
291
+ bandwidth = band.bandwidth();
292
+ scale = value => band(value);
293
+ } else if (realScale === 'point') {
294
+ const point = scalePoint().domain(domain.map(value => value)).range(axisRange);
295
+ bandwidth = point.bandwidth();
296
+ scale = value => point(value);
297
+ } else {
298
+ const linear = scaleLinear().domain(domain).range(axisRange);
299
+ scale = value => {
300
+ const number = makeNumber(value);
301
+ return number === undefined ? undefined : linear(number);
302
+ };
303
+ scaleTicks = count => linear.ticks(count);
304
+ }
305
+
306
+ // combineDuplicateDomain and combineCategoricalDomain
307
+ const allValues = applied;
308
+ const duplicateDomain = settings.dataKey !== undefined && isCategorical && type === 'category' && settings.allowDuplicatedCategory && hasDuplicate(allValues) ? allValues : undefined;
309
+ const categoricalDomain = settings.dataKey !== undefined && isCategorical && (type === 'number' || settings.scale !== 'auto') ? allValues : undefined;
310
+
311
+ // combineAxisTicks: a band's ticks sit at its middle; around the ring, recharts moves them a
312
+ // whole band along, in the direction the angles run.
313
+ let offset = type === 'category' && realScale !== 'linear' ? bandwidth / 2 : 0;
314
+ if (axisType === 'angleAxis') offset = mathSign(axisRange[0] - axisRange[1]) * 2 * offset;
315
+ const tick = (value, index, scaled, at) => isNumber(scaled) ? {
316
+ index,
317
+ coordinate: scaled + at,
318
+ value,
319
+ offset: at
320
+ } : null;
321
+ // mode `axis`: combineAxisTicks; `item`: combineGraphicalItemTicks; `tooltip`:
322
+ // combineTicksOfTooltipAxis. They differ in whether they take the axis's own and nice ticks,
323
+ // and a linear scale's.
324
+ const ticksFrom = (at, mode) => {
325
+ const list = mode === 'axis' ? settings.ticks ?? niceTicks : undefined;
326
+ let result;
327
+ if (list) {
328
+ result = list.map((entry, index) => tick(entry, index, scale(duplicateDomain ? duplicateDomain.indexOf(entry) : entry), at));
329
+ } else if (isCategorical && categoricalDomain) {
330
+ result = categoricalDomain.map((entry, index) => tick(entry, index, scale(entry), at));
331
+ } else if (scaleTicks && mode !== 'tooltip') {
332
+ result = scaleTicks(settings.tickCount).map((entry, index) => tick(entry, index, scale(entry), at));
333
+ } else {
334
+ result = domain.map((entry, index) => tick(duplicateDomain ? duplicateDomain[entry] : entry, index, scale(entry), at));
335
+ }
336
+ return result.filter(entry => entry !== null);
337
+ };
338
+ return {
339
+ axisType,
340
+ settings,
341
+ type,
342
+ isCategorical,
343
+ domain,
344
+ range: axisRange,
345
+ ticks: ticksFrom(offset, 'axis'),
346
+ itemTicks: axisRange[0] === axisRange[1] ? [] : ticksFrom(0, 'item'),
347
+ tooltipTicks: ticksFrom(offset, 'tooltip'),
348
+ bandwidth,
349
+ scale,
350
+ niceTicks,
351
+ realScale
352
+ };
353
+ }
354
+
355
+ /** recharts' `getBandSizeOfAxis`. */
356
+ function bandSizeOf(axis, ticks, isBar) {
357
+ if (axis.bandwidth && (!isBar || axis.bandwidth > 0)) return axis.bandwidth;
358
+ if (ticks.length >= 2) {
359
+ const sorted = [...ticks].sort((a, b) => a.coordinate - b.coordinate);
360
+ let size = Infinity;
361
+ for (let i = 1; i < sorted.length; i++) {
362
+ size = Math.min(sorted[i].coordinate - sorted[i - 1].coordinate, size);
363
+ }
364
+ return size === Infinity ? 0 : size;
365
+ }
366
+ return isBar ? undefined : 0;
367
+ }
368
+
369
+ // ---------------------------------------------------------------------------------------------
370
+ // The ring
371
+
372
+ function offsetOf(input) {
373
+ return plotArea({
374
+ width: input.width,
375
+ height: input.height,
376
+ margin: input.margin,
377
+ xAxis: defaultAxis('x', true),
378
+ yAxis: defaultAxis('y', true),
379
+ legend: input.legend
380
+ });
381
+ }
382
+
383
+ /** recharts' `selectPolarViewBox`: the ring's centre, radii and angles. */
384
+ function viewBoxOf(input) {
385
+ const offset = offsetOf(input);
386
+ const maxRadius = Math.min(Math.abs(input.width - offset.left - offset.right), Math.abs(input.height - offset.top - offset.bottom)) / 2;
387
+ return {
388
+ cx: percentValue(input.cx, input.width, input.width / 2),
389
+ cy: percentValue(input.cy, input.height, input.height / 2),
390
+ innerRadius: percentValue(input.innerRadius, maxRadius, 0),
391
+ outerRadius: percentValue(input.outerRadius, maxRadius, maxRadius * 0.8),
392
+ startAngle: input.startAngle,
393
+ endAngle: input.endAngle,
394
+ clockWise: false
395
+ };
396
+ }
397
+
398
+ // ---------------------------------------------------------------------------------------------
399
+ // Stacking and bars
400
+
401
+ const OFFSETS = {
402
+ none: stackOffsetNone,
403
+ expand: stackOffsetExpand,
404
+ silhouette: stackOffsetSilhouette,
405
+ wiggle: stackOffsetWiggle
406
+ };
407
+
408
+ /** recharts' `sign` and `positive` offsets. */
409
+ function signedOffset(onlyPositive) {
410
+ return (series, order) => {
411
+ const n = series[0]?.length ?? 0;
412
+ for (let j = 0; j < n; ++j) {
413
+ let positive = 0;
414
+ let negative = 0;
415
+ for (const i of order) {
416
+ const point = series[i][j];
417
+ const value = Number.isNaN(point[1]) ? point[0] : point[1];
418
+ if (value >= 0) {
419
+ point[0] = positive;
420
+ point[1] = positive + value;
421
+ positive = point[1];
422
+ } else if (onlyPositive) {
423
+ point[0] = 0;
424
+ point[1] = 0;
425
+ } else {
426
+ point[0] = negative;
427
+ point[1] = negative + value;
428
+ negative = point[1];
429
+ }
430
+ }
431
+ }
432
+ };
433
+ }
434
+
435
+ /** Each stacked bar's `[bottom, top]` per row, by bar id. */
436
+ function stackBars(input, bars) {
437
+ const groups = new Map();
438
+ for (const bar of bars) {
439
+ if (bar.stackId === undefined || bar.stackId === null) continue;
440
+ const key = String(bar.stackId);
441
+ groups.set(key, [...(groups.get(key) ?? []), bar]);
442
+ }
443
+ const result = new Map();
444
+ for (const members of groups.values()) {
445
+ const offset = input.stackOffset === 'sign' ? signedOffset(false) : input.stackOffset === 'positive' ? signedOffset(true) : OFFSETS[input.stackOffset];
446
+ const stacked = stack().keys(members.map((_, i) => i)).value((row, i) => makeNumber(valueOf(row, members[i].dataKey)) ?? 0).order(stackOrderNone).offset(offset)(input.data);
447
+ stacked.forEach((layer, i) => {
448
+ result.set(members[i].id, layer.map(point => [point[0], point[1]]));
449
+ });
450
+ }
451
+ return result;
452
+ }
453
+ /** recharts' `combineBarSizeList`: one slot per stack, and one per unstacked bar. */
454
+ function barSlots(bars, globalSize) {
455
+ const stacks = new Map();
456
+ for (const bar of bars) {
457
+ if (bar.stackId === undefined || bar.stackId === null) continue;
458
+ const key = String(bar.stackId);
459
+ stacks.set(key, [...(stacks.get(key) ?? []), bar]);
460
+ }
461
+ return [...[...stacks.values()].map(members => ({
462
+ stackId: members[0].stackId,
463
+ ids: members.map(bar => bar.id),
464
+ barSize: members[0].barSize ?? globalSize
465
+ })), ...bars.filter(bar => bar.stackId === undefined || bar.stackId === null).map(bar => ({
466
+ stackId: undefined,
467
+ ids: [bar.id],
468
+ barSize: bar.barSize ?? globalSize
469
+ }))];
470
+ }
471
+
472
+ /** recharts' `getBarPositions`: each slot's offset in the band and its size. */
473
+ function barPositions(bandSize, slots, barGap, barCategoryGap, maxBarSize) {
474
+ const len = slots.length;
475
+ if (len < 1) return [];
476
+ let gap = percentValue(barGap, bandSize, 0, true);
477
+ if (isNumber(slots[0].barSize)) {
478
+ let useFull = false;
479
+ let fullBarSize = bandSize / len;
480
+ let sum = slots.reduce((total, slot) => total + (slot.barSize ?? 0), 0) + (len - 1) * gap;
481
+ if (sum >= bandSize) {
482
+ sum -= (len - 1) * gap;
483
+ gap = 0;
484
+ }
485
+ if (sum >= bandSize && fullBarSize > 0) {
486
+ useFull = true;
487
+ fullBarSize *= 0.9;
488
+ sum = len * fullBarSize;
489
+ }
490
+ const start = (bandSize - sum) / 2 >> 0;
491
+ let previous = {
492
+ offset: start - gap,
493
+ size: 0
494
+ };
495
+ return slots.map(slot => {
496
+ const position = {
497
+ offset: previous.offset + previous.size + gap,
498
+ size: useFull ? fullBarSize : slot.barSize ?? 0
499
+ };
500
+ previous = position;
501
+ return position;
502
+ });
503
+ }
504
+ const offset = percentValue(barCategoryGap, bandSize, 0, true);
505
+ if (bandSize - 2 * offset - (len - 1) * gap <= 0) gap = 0;
506
+ let originalSize = (bandSize - 2 * offset - (len - 1) * gap) / len;
507
+ if (originalSize > 1) originalSize >>= 0;
508
+ const size = isNumber(maxBarSize) ? Math.min(originalSize, maxBarSize) : originalSize;
509
+ return slots.map((_, i) => ({
510
+ offset: offset + (originalSize + gap) * i + (originalSize - size) / 2,
511
+ size
512
+ }));
513
+ }
514
+
515
+ /** recharts' `truncateByDomain`: a stacked bar cut to the axis's domain. */
516
+ function truncateByDomain(value, domain) {
517
+ const [a, b] = domain;
518
+ if (!isNumber(a) || !isNumber(b)) return value;
519
+ const min = Math.min(a, b);
520
+ const max = Math.max(a, b);
521
+ const result = [value[0], value[1]];
522
+ if (!isNumber(value[0]) || value[0] < min) result[0] = min;
523
+ if (!isNumber(value[1]) || value[1] > max) result[1] = max;
524
+ if (result[0] > max) result[0] = max;
525
+ if (result[1] < min) result[1] = min;
526
+ return result;
527
+ }
528
+
529
+ /** recharts' `getBaseValueOfBar`: where an unstacked bar starts on the number axis. */
530
+ function baseValueOf(axis) {
531
+ const [a, b] = axis.domain;
532
+ if (axis.type === 'number' && isNumber(a) && isNumber(b)) {
533
+ const min = Math.min(a, b);
534
+ const max = Math.max(a, b);
535
+ if (min <= 0 && max >= 0) return 0;
536
+ return max < 0 ? max : min;
537
+ }
538
+ return axis.domain[0];
539
+ }
540
+
541
+ /** recharts' `getCateCoordinateOfBar`: where a bar starts on the category axis. */
542
+ function categoryCoordinateOf(axis, row, index, bandSize, offset) {
543
+ if (axis.type === 'category') {
544
+ const tick = axis.itemTicks[index];
545
+ return tick ? tick.coordinate + offset : null;
546
+ }
547
+ const value = valueOf(row, axis.settings.dataKey, axis.domain[index]);
548
+ if (value === null || value === undefined) return null;
549
+ const scaled = axis.scale(value);
550
+ return isNumber(scaled) ? scaled - bandSize / 2 + offset : null;
551
+ }
552
+
553
+ // ---------------------------------------------------------------------------------------------
554
+ // The layout
555
+
556
+ function polarGeometry(input) {
557
+ const {
558
+ layout,
559
+ data
560
+ } = input;
561
+ const viewBox = viewBoxOf(input);
562
+ const visibleBars = input.radialBars.filter(bar => !bar.hide);
563
+ const items = [...input.radars.filter(radar => !radar.hide), ...visibleBars];
564
+ const angleAxis = resolveAxis(input, 'angleAxis', items);
565
+ const radiusAxis = resolveAxis(input, 'radiusAxis', items);
566
+
567
+ // selectPolarAngleAxisTicks: around a full circle, 0° and 360° are one tick.
568
+ const seen = new Set();
569
+ const angleAxisTicks = angleAxis.ticks.filter(tick => {
570
+ const normalized = (tick.coordinate + 360) % 360;
571
+ if (seen.has(normalized)) return false;
572
+ seen.add(normalized);
573
+ return true;
574
+ });
575
+
576
+ // Radars: computeRadarPoints
577
+ const radarBandSize = layout === 'radial' ? bandSizeOf(radiusAxis, radiusAxis.ticks, false) ?? 0 : bandSizeOf(angleAxis, angleAxis.ticks, false) ?? 0;
578
+ const radars = input.radars.map(settings => {
579
+ const angleBand = angleAxis.type !== 'number' ? radarBandSize : 0;
580
+ let isRange = false;
581
+ const points = data.map((row, index) => {
582
+ const name = valueOf(row, angleAxis.settings.dataKey, index);
583
+ const value = valueOf(row, settings.dataKey);
584
+ const angle = (angleAxis.scale(name) ?? 0) + angleBand;
585
+ const pointValue = Array.isArray(value) ? value[value.length - 1] : value;
586
+ const radius = pointValue === null || pointValue === undefined ? 0 : radiusAxis.scale(pointValue) ?? 0;
587
+ if (Array.isArray(value) && value.length >= 2) isRange = true;
588
+ return {
589
+ ...polarToCartesian(viewBox.cx, viewBox.cy, radius, angle),
590
+ cx: viewBox.cx,
591
+ cy: viewBox.cy,
592
+ radius,
593
+ angle,
594
+ name,
595
+ value,
596
+ payload: row,
597
+ index
598
+ };
599
+ });
600
+ const baseLinePoints = isRange ? points.map(point => {
601
+ if (!Array.isArray(point.value)) return point;
602
+ const base = point.value[0];
603
+ const radius = base === null || base === undefined ? 0 : radiusAxis.scale(base) ?? 0;
604
+ return {
605
+ ...point,
606
+ radius,
607
+ ...polarToCartesian(viewBox.cx, viewBox.cy, radius, point.angle)
608
+ };
609
+ }) : [];
610
+ return {
611
+ settings,
612
+ points,
613
+ isRange,
614
+ baseLinePoints
615
+ };
616
+ });
617
+
618
+ // Radial bars: computeRadialBarDataItems
619
+ const categoryAxis = layout === 'centric' ? angleAxis : radiusAxis;
620
+ const numericAxis = layout === 'centric' ? radiusAxis : angleAxis;
621
+ const barBandSize = bandSizeOf(categoryAxis, categoryAxis.itemTicks, true) ?? input.maxBarSize ?? 0;
622
+ const bandSize = bandSizeOf(categoryAxis, categoryAxis.itemTicks, false) ?? 0;
623
+ const slots = barSlots(visibleBars, input.barSize);
624
+ const stacks = stackBars(input, visibleBars);
625
+ const baseValue = baseValueOf(numericAxis);
626
+ const radialBars = input.radialBars.map(settings => {
627
+ if (settings.hide) return {
628
+ settings,
629
+ sectors: []
630
+ };
631
+ const slotIndex = slots.findIndex(slot => slot.ids.includes(settings.id));
632
+ const positions = barPositions(barBandSize !== bandSize ? barBandSize : bandSize, slots, input.barGap, input.barCategoryGap, settings.maxBarSize ?? input.maxBarSize).map(position => barBandSize !== bandSize ? {
633
+ ...position,
634
+ offset: position.offset - barBandSize / 2
635
+ } : position);
636
+ const position = positions[slotIndex];
637
+ if (!position) return {
638
+ settings,
639
+ sectors: []
640
+ };
641
+ const stacked = stacks.get(settings.id);
642
+ const sectors = [];
643
+ data.forEach((row, index) => {
644
+ let value;
645
+ if (stacked) {
646
+ value = truncateByDomain(stacked[index], numericAxis.domain);
647
+ } else {
648
+ const raw = valueOf(row, settings.dataKey);
649
+ value = Array.isArray(raw) ? [raw[0], raw[1]] : [baseValue, raw];
650
+ }
651
+ let innerRadius;
652
+ let outerRadius;
653
+ let startAngle;
654
+ let endAngle;
655
+ let background;
656
+ if (layout === 'radial') {
657
+ startAngle = angleAxis.scale(value[0]) ?? input.startAngle;
658
+ endAngle = angleAxis.scale(value[1]) ?? input.endAngle;
659
+ innerRadius = categoryCoordinateOf(radiusAxis, row, index, bandSize, position.offset);
660
+ if (isNumber(innerRadius)) {
661
+ outerRadius = innerRadius + position.size;
662
+ const delta = endAngle - startAngle;
663
+ const min = settings.minPointSize;
664
+ if (Math.abs(min) > 0 && Math.abs(delta) < Math.abs(min)) {
665
+ endAngle += mathSign(delta || min) * (Math.abs(min) - Math.abs(delta));
666
+ }
667
+ background = {
668
+ cx: viewBox.cx,
669
+ cy: viewBox.cy,
670
+ innerRadius,
671
+ outerRadius,
672
+ startAngle: input.startAngle,
673
+ endAngle: input.endAngle
674
+ };
675
+ }
676
+ } else {
677
+ innerRadius = radiusAxis.scale(value[0]);
678
+ outerRadius = radiusAxis.scale(value[1]);
679
+ startAngle = categoryCoordinateOf(angleAxis, row, index, bandSize, position.offset);
680
+ if (isNumber(innerRadius) && isNumber(outerRadius) && isNumber(startAngle)) {
681
+ endAngle = startAngle + position.size;
682
+ const delta = outerRadius - innerRadius;
683
+ const min = settings.minPointSize;
684
+ if (Math.abs(min) > 0 && Math.abs(delta) < Math.abs(min)) {
685
+ outerRadius += mathSign(delta || min) * (Math.abs(min) - Math.abs(delta));
686
+ }
687
+ }
688
+ }
689
+ if (!isNumber(innerRadius) || !isNumber(outerRadius) || !isNumber(startAngle) || !isNumber(endAngle)) {
690
+ return;
691
+ }
692
+ sectors.push({
693
+ index,
694
+ value: stacked ? value : value[1],
695
+ payload: row,
696
+ cx: viewBox.cx,
697
+ cy: viewBox.cy,
698
+ innerRadius,
699
+ outerRadius,
700
+ startAngle,
701
+ endAngle,
702
+ background
703
+ });
704
+ });
705
+ return {
706
+ settings,
707
+ sectors
708
+ };
709
+ });
710
+ const tooltipAxis = layout === 'centric' ? angleAxis : radiusAxis;
711
+ return {
712
+ offset: offsetOf(input),
713
+ viewBox,
714
+ angleAxis,
715
+ radiusAxis,
716
+ angleAxisTicks,
717
+ tooltipAxis,
718
+ tooltipTicks: tooltipAxis.tooltipTicks,
719
+ radars,
720
+ radialBars
721
+ };
722
+ }
723
+
724
+ // ---------------------------------------------------------------------------------------------
725
+ // Paths
726
+
727
+ /** recharts' `getSinglePolygonPath`, for points that are all defined. */
728
+ function polygonSegmentPath(points) {
729
+ return points.reduce((d, point, index) => path`${d}${index === 0 ? 'M' : 'L'}${point.x},${point.y}`, '');
730
+ }
731
+
732
+ /**
733
+ * recharts' `Polygon` path through `points`, back to the first and closed. A point that isn't a
734
+ * number breaks the outline, unless `connectNulls` joins over it.
735
+ */
736
+ function polygonPath(points, connectNulls = false) {
737
+ if (!points.length) return null;
738
+ const valid = point => !!point && isNumber(point.x) && isNumber(point.y);
739
+ let segments = [[]];
740
+ for (const point of points) {
741
+ const last = segments[segments.length - 1];
742
+ if (valid(point)) last.push(point);else if (last.length) segments.push([]);
743
+ }
744
+ if (valid(points[0])) segments[segments.length - 1].push(points[0]);
745
+ if (!segments[segments.length - 1].length) segments = segments.slice(0, -1);
746
+ if (connectNulls) segments = [segments.flat()];
747
+ const d = segments.map(polygonSegmentPath).join('');
748
+ return segments.length === 1 ? `${d}Z` : d;
749
+ }
750
+
751
+ /** recharts' `getRanglePath`: a ring between a range radar's outline and its baseline. */
752
+ function rangePolygonPath(points, baseLinePoints, connectNulls = false) {
753
+ const outer = polygonPath(points, connectNulls) ?? '';
754
+ const inner = polygonPath([...baseLinePoints].reverse(), connectNulls) ?? '';
755
+ return `${outer.endsWith('Z') ? outer.slice(0, -1) : outer}L${inner.slice(1)}`;
756
+ }
757
+
758
+ /** A polar grid's polygon at `radius`, through `angles` (recharts' `getPolygonPath`, unrounded). */
759
+ function gridPolygonPath(radius, cx, cy, angles) {
760
+ let d = '';
761
+ angles.forEach((angle, i) => {
762
+ const point = polarToCartesian(cx, cy, radius, angle);
763
+ d += `${i ? 'L' : 'M'} ${point.x},${point.y}`;
764
+ });
765
+ return `${d}Z`;
766
+ }
767
+ function deltaAngle(startAngle, endAngle) {
768
+ return mathSign(endAngle - startAngle) * Math.min(Math.abs(endAngle - startAngle), 359.999);
769
+ }
770
+ function sectorPathPlain(sector) {
771
+ const {
772
+ cx,
773
+ cy,
774
+ innerRadius,
775
+ outerRadius,
776
+ startAngle,
777
+ endAngle
778
+ } = sector;
779
+ const angle = deltaAngle(startAngle, endAngle);
780
+ const tempEndAngle = startAngle + angle;
781
+ const outerStart = polarToCartesian(cx, cy, outerRadius, startAngle);
782
+ const outerEnd = polarToCartesian(cx, cy, outerRadius, tempEndAngle);
783
+ let d = path`M ${outerStart.x},${outerStart.y}
784
+ A ${outerRadius},${outerRadius},0,
785
+ ${+(Math.abs(angle) > 180)},${+(startAngle > tempEndAngle)},
786
+ ${outerEnd.x},${outerEnd.y}
787
+ `;
788
+ if (innerRadius > 0) {
789
+ const innerStart = polarToCartesian(cx, cy, innerRadius, startAngle);
790
+ const innerEnd = polarToCartesian(cx, cy, innerRadius, tempEndAngle);
791
+ d += path`L ${innerEnd.x},${innerEnd.y}
792
+ A ${innerRadius},${innerRadius},0,
793
+ ${+(Math.abs(angle) > 180)},${+(startAngle <= tempEndAngle)},
794
+ ${innerStart.x},${innerStart.y} Z`;
795
+ } else {
796
+ d += path`L ${cx},${cy} Z`;
797
+ }
798
+ return d;
799
+ }
800
+ function tangentCircle(options) {
801
+ const {
802
+ cx,
803
+ cy,
804
+ radius,
805
+ angle,
806
+ sign,
807
+ isExternal,
808
+ cornerRadius,
809
+ cornerIsExternal
810
+ } = options;
811
+ const centerRadius = cornerRadius * (isExternal ? 1 : -1) + radius;
812
+ const theta = Math.asin(cornerRadius / centerRadius) / RADIAN;
813
+ const centerAngle = cornerIsExternal ? angle : angle + sign * theta;
814
+ const circleTangency = polarToCartesian(cx, cy, radius, centerAngle);
815
+ const lineTangencyAngle = cornerIsExternal ? angle - sign * theta : angle;
816
+ const lineTangency = polarToCartesian(cx, cy, centerRadius * Math.cos(theta * RADIAN), lineTangencyAngle);
817
+ return {
818
+ circleTangency,
819
+ lineTangency,
820
+ theta
821
+ };
822
+ }
823
+ function sectorPathWithCorner(sector) {
824
+ const {
825
+ cx,
826
+ cy,
827
+ innerRadius,
828
+ outerRadius,
829
+ cornerRadius,
830
+ forceCornerRadius,
831
+ cornerIsExternal
832
+ } = sector;
833
+ const {
834
+ startAngle,
835
+ endAngle
836
+ } = sector;
837
+ const sign = mathSign(endAngle - startAngle);
838
+ const common = {
839
+ cx,
840
+ cy,
841
+ cornerRadius,
842
+ cornerIsExternal
843
+ };
844
+ const start = tangentCircle({
845
+ ...common,
846
+ radius: outerRadius,
847
+ angle: startAngle,
848
+ sign
849
+ });
850
+ const end = tangentCircle({
851
+ ...common,
852
+ radius: outerRadius,
853
+ angle: endAngle,
854
+ sign: -sign
855
+ });
856
+ const outerArcAngle = cornerIsExternal ? Math.abs(startAngle - endAngle) : Math.abs(startAngle - endAngle) - start.theta - end.theta;
857
+ if (outerArcAngle < 0) {
858
+ if (forceCornerRadius) {
859
+ return path`M ${start.lineTangency.x},${start.lineTangency.y}
860
+ a${cornerRadius},${cornerRadius},0,0,1,${cornerRadius * 2},0
861
+ a${cornerRadius},${cornerRadius},0,0,1,${-cornerRadius * 2},0
862
+ `;
863
+ }
864
+ return sectorPathPlain(sector);
865
+ }
866
+ const s = +(sign < 0);
867
+ let d = path`M ${start.lineTangency.x},${start.lineTangency.y}
868
+ A${cornerRadius},${cornerRadius},0,0,${s},${start.circleTangency.x},${start.circleTangency.y}
869
+ A${outerRadius},${outerRadius},0,${+(outerArcAngle > 180)},${s},${end.circleTangency.x},${end.circleTangency.y}
870
+ A${cornerRadius},${cornerRadius},0,0,${s},${end.lineTangency.x},${end.lineTangency.y}
871
+ `;
872
+ if (innerRadius > 0) {
873
+ const innerStart = tangentCircle({
874
+ ...common,
875
+ radius: innerRadius,
876
+ angle: startAngle,
877
+ sign,
878
+ isExternal: true
879
+ });
880
+ const innerEnd = tangentCircle({
881
+ ...common,
882
+ radius: innerRadius,
883
+ angle: endAngle,
884
+ sign: -sign,
885
+ isExternal: true
886
+ });
887
+ const innerArcAngle = cornerIsExternal ? Math.abs(startAngle - endAngle) : Math.abs(startAngle - endAngle) - innerStart.theta - innerEnd.theta;
888
+ if (innerArcAngle < 0 && cornerRadius === 0) return `${d}L${cx},${cy}Z`;
889
+ d += path`L${innerEnd.lineTangency.x},${innerEnd.lineTangency.y}
890
+ A${cornerRadius},${cornerRadius},0,0,${s},${innerEnd.circleTangency.x},${innerEnd.circleTangency.y}
891
+ A${innerRadius},${innerRadius},0,${+(innerArcAngle > 180)},${+(sign > 0)},${innerStart.circleTangency.x},${innerStart.circleTangency.y}
892
+ A${cornerRadius},${cornerRadius},0,0,${s},${innerStart.lineTangency.x},${innerStart.lineTangency.y}Z`;
893
+ } else {
894
+ d += path`L${cx},${cy}Z`;
895
+ }
896
+ return d;
897
+ }
898
+
899
+ /**
900
+ * recharts' `Sector` path: a ring segment from `startAngle` to `endAngle`, its corners rounded by
901
+ * `cornerRadius` (a number, or a percentage of the ring's width). Null where recharts draws
902
+ * nothing: an empty angle, or an outer radius inside the inner one.
903
+ */
904
+ function sectorPath(sector) {
905
+ const {
906
+ innerRadius,
907
+ outerRadius,
908
+ startAngle,
909
+ endAngle
910
+ } = sector;
911
+ if (outerRadius < innerRadius || startAngle === endAngle) return null;
912
+ const deltaRadius = outerRadius - innerRadius;
913
+ const cornerRadius = percentValue(sector.cornerRadius ?? 0, deltaRadius, 0, true);
914
+ if (cornerRadius > 0 && Math.abs(startAngle - endAngle) < 360) {
915
+ return sectorPathWithCorner({
916
+ ...sector,
917
+ cornerRadius: Math.min(cornerRadius, deltaRadius / 2),
918
+ forceCornerRadius: sector.forceCornerRadius ?? false,
919
+ cornerIsExternal: sector.cornerIsExternal ?? false
920
+ });
921
+ }
922
+ return sectorPathPlain(sector);
923
+ }
924
+
925
+ // ---------------------------------------------------------------------------------------------
926
+ // Labels
927
+
928
+ const TEXT_DY = {
929
+ start: '0.71em',
930
+ middle: '0.355em',
931
+ end: '0em'
932
+ };
933
+
934
+ /** Where a label sits against a sector (or the ring): recharts' polar positions. */
935
+
936
+ /**
937
+ * recharts' `renderRadialLabel`: the arc a label along a sector (`insideStart`, `insideEnd`,
938
+ * `end`) runs on, as a `<textPath>`'s path.
939
+ */
940
+ function radialLabelPath(viewBox, position, offset) {
941
+ const {
942
+ cx,
943
+ cy,
944
+ innerRadius,
945
+ outerRadius,
946
+ startAngle,
947
+ endAngle
948
+ } = viewBox;
949
+ const clockWise = viewBox.clockWise ?? false;
950
+ const radius = (innerRadius + outerRadius) / 2;
951
+ const delta = mathSign(endAngle - startAngle) * Math.min(Math.abs(endAngle - startAngle), 360);
952
+ const sign = delta >= 0 ? 1 : -1;
953
+ let labelAngle;
954
+ let direction;
955
+ if (position === 'insideStart') {
956
+ labelAngle = startAngle + sign * offset;
957
+ direction = clockWise;
958
+ } else if (position === 'insideEnd') {
959
+ labelAngle = endAngle - sign * offset;
960
+ direction = !clockWise;
961
+ } else {
962
+ labelAngle = endAngle + sign * offset;
963
+ direction = clockWise;
964
+ }
965
+ direction = delta <= 0 ? direction : !direction;
966
+ const start = polarToCartesian(cx, cy, radius, labelAngle);
967
+ const end = polarToCartesian(cx, cy, radius, labelAngle + (direction ? 1 : -1) * 359);
968
+ return `M${start.x},${start.y}
969
+ A${radius},${radius},0,1,${direction ? 0 : 1},
970
+ ${end.x},${end.y}`;
971
+ }
972
+
973
+ /** recharts' `getAttrsOfPolarLabel`: where a label sits against a sector, and its anchors. */
974
+ function polarLabelAttrs(viewBox, offset, position) {
975
+ const {
976
+ cx,
977
+ cy,
978
+ innerRadius,
979
+ outerRadius,
980
+ startAngle,
981
+ endAngle
982
+ } = viewBox;
983
+ const midAngle = (startAngle + endAngle) / 2;
984
+ if (position === 'outside') {
985
+ const {
986
+ x,
987
+ y
988
+ } = polarToCartesian(cx, cy, outerRadius + offset, midAngle);
989
+ return {
990
+ x,
991
+ y,
992
+ textAnchor: x >= cx ? 'start' : 'end',
993
+ dy: TEXT_DY.middle
994
+ };
995
+ }
996
+ if (position === 'center') return {
997
+ x: cx,
998
+ y: cy,
999
+ textAnchor: 'middle',
1000
+ dy: TEXT_DY.middle
1001
+ };
1002
+ if (position === 'centerTop') return {
1003
+ x: cx,
1004
+ y: cy,
1005
+ textAnchor: 'middle',
1006
+ dy: TEXT_DY.start
1007
+ };
1008
+ if (position === 'centerBottom') return {
1009
+ x: cx,
1010
+ y: cy,
1011
+ textAnchor: 'middle',
1012
+ dy: TEXT_DY.end
1013
+ };
1014
+ const r = (innerRadius + outerRadius) / 2;
1015
+ const {
1016
+ x,
1017
+ y
1018
+ } = polarToCartesian(cx, cy, r, midAngle);
1019
+ return {
1020
+ x,
1021
+ y,
1022
+ textAnchor: 'middle',
1023
+ dy: TEXT_DY.middle
1024
+ };
1025
+ }
1026
+
1027
+ // ---------------------------------------------------------------------------------------------
1028
+ // The pointer
1029
+
1030
+ /** recharts' `inRangeOfSector`: the pointer's radius and angle, when it is on the ring. */
1031
+ function inRangeOfSector(point, viewBox) {
1032
+ const radius = Math.sqrt((point.x - viewBox.cx) ** 2 + (point.y - viewBox.cy) ** 2);
1033
+ if (radius < viewBox.innerRadius || radius > viewBox.outerRadius || radius === 0) return null;
1034
+ let radians = Math.acos((point.x - viewBox.cx) / radius);
1035
+ if (point.y > viewBox.cy) radians = 2 * Math.PI - radians;
1036
+ const angle = radians / RADIAN;
1037
+ const min = Math.min(Math.floor(viewBox.startAngle / 360), Math.floor(viewBox.endAngle / 360));
1038
+ const startAngle = viewBox.startAngle - min * 360;
1039
+ const endAngle = viewBox.endAngle - min * 360;
1040
+ let formatted = angle;
1041
+ let inRange;
1042
+ if (startAngle <= endAngle) {
1043
+ while (formatted > endAngle) formatted -= 360;
1044
+ while (formatted < startAngle) formatted += 360;
1045
+ inRange = formatted >= startAngle && formatted <= endAngle;
1046
+ } else {
1047
+ while (formatted > startAngle) formatted -= 360;
1048
+ while (formatted < endAngle) formatted += 360;
1049
+ inRange = formatted >= endAngle && formatted <= startAngle;
1050
+ }
1051
+ return inRange ? {
1052
+ radius,
1053
+ angle: formatted + min * 360
1054
+ } : null;
1055
+ }
1056
+
1057
+ /**
1058
+ * recharts' `calculateActiveTickIndex`: the row whose tick is nearest `coordinate` (an angle
1059
+ * or a radius), going round the circle on a full-circle angle axis. -1 for none.
1060
+ */
1061
+ function activeTickIndex(coordinate, ticks, axisType, axisRange) {
1062
+ const len = ticks.length;
1063
+ if (len <= 1) return 0;
1064
+ const sorted = [...ticks].sort((a, b) => a.coordinate - b.coordinate);
1065
+ if (axisType === 'angleAxis' && Math.abs(Math.abs(axisRange[1] - axisRange[0]) - 360) <= 1e-6) {
1066
+ for (let i = 0; i < len; i++) {
1067
+ const before = (i > 0 ? ticks[i - 1] : ticks[len - 1]).coordinate;
1068
+ const cur = ticks[i].coordinate;
1069
+ const after = (i >= len - 1 ? ticks[0] : ticks[i + 1]).coordinate;
1070
+ if (mathSign(cur - before) !== mathSign(after - cur)) {
1071
+ let same;
1072
+ const diff = [0, 0];
1073
+ if (mathSign(after - cur) === mathSign(axisRange[1] - axisRange[0])) {
1074
+ same = after;
1075
+ const curInRange = cur + axisRange[1] - axisRange[0];
1076
+ diff[0] = Math.min(curInRange, (curInRange + before) / 2);
1077
+ diff[1] = Math.max(curInRange, (curInRange + before) / 2);
1078
+ } else {
1079
+ same = before;
1080
+ const afterInRange = after + axisRange[1] - axisRange[0];
1081
+ diff[0] = Math.min(cur, (afterInRange + cur) / 2);
1082
+ diff[1] = Math.max(cur, (afterInRange + cur) / 2);
1083
+ }
1084
+ const sameInterval = [Math.min(cur, (same + cur) / 2), Math.max(cur, (same + cur) / 2)];
1085
+ if (coordinate > sameInterval[0] && coordinate <= sameInterval[1] || coordinate >= diff[0] && coordinate <= diff[1]) {
1086
+ return ticks[i].index;
1087
+ }
1088
+ } else {
1089
+ const min = Math.min(before, after);
1090
+ const max = Math.max(before, after);
1091
+ if (coordinate > (min + cur) / 2 && coordinate <= (max + cur) / 2) return ticks[i].index;
1092
+ }
1093
+ }
1094
+ return -1;
1095
+ }
1096
+ for (let i = 0; i < len; i++) {
1097
+ const cur = sorted[i];
1098
+ const next = sorted[i + 1];
1099
+ const prev = sorted[i - 1];
1100
+ if (i === 0 && next && coordinate <= (cur.coordinate + next.coordinate) / 2) return cur.index;
1101
+ if (i === len - 1 && prev && coordinate > (cur.coordinate + prev.coordinate) / 2) return cur.index;
1102
+ if (i > 0 && i < len - 1 && prev && next && coordinate > (cur.coordinate + prev.coordinate) / 2 && coordinate <= (cur.coordinate + next.coordinate) / 2) {
1103
+ return cur.index;
1104
+ }
1105
+ }
1106
+ return -1;
1107
+ }
1108
+
1109
+ /** Every part a polar chart reads, besides the tooltip and legend. */
1110
+ /** A part that registers with its chart while it is rendered. */class Part extends Component {
1111
+ constructor(owner, args) {
1112
+ super(owner, args);
1113
+ args.chart.register(this);
1114
+ }
1115
+ willDestroy() {
1116
+ super.willDestroy();
1117
+ this.args.chart.unregister(this);
1118
+ }
1119
+ }
1120
+ // ---------------------------------------------------------------------------------------------
1121
+ // Grid
1122
+
1123
+ /** The grid behind a polar chart: recharts' `PolarGrid`. */class PolarGrid extends Part {
1124
+ kind = 'polar-grid';
1125
+ static {
1126
+ setComponentTemplate(precompileTemplate("", {
1127
+ strictMode: true
1128
+ }), this);
1129
+ }
1130
+ }
1131
+ // ---------------------------------------------------------------------------------------------
1132
+ // Axes
1133
+ /** The arguments both polar axes share with recharts'. */
1134
+
1135
+ /** What an angle axis's custom `@tick` component is handed: where the label goes, and its tick. */
1136
+
1137
+ /** The axis around a polar chart: recharts' `PolarAngleAxis`. */class PolarAngleAxis extends Part {
1138
+ kind = 'angle-axis';
1139
+ static {
1140
+ setComponentTemplate(precompileTemplate("", {
1141
+ strictMode: true
1142
+ }), this);
1143
+ }
1144
+ }
1145
+ /** What a `Label`'s `@content` is handed, as recharts hands its `content` function. */
1146
+
1147
+ /** A label for the radius axis, such as a total in the middle of the chart: recharts' `Label`. */class RadiusAxisLabel extends Component {
1148
+ constructor(owner, args) {
1149
+ super(owner, args);
1150
+ args.axis.registerLabel(this);
1151
+ }
1152
+ willDestroy() {
1153
+ super.willDestroy();
1154
+ this.args.axis.unregisterLabel(this);
1155
+ }
1156
+ static {
1157
+ setComponentTemplate(precompileTemplate("", {
1158
+ strictMode: true
1159
+ }), this);
1160
+ }
1161
+ }
1162
+ /** The axis out from a polar chart's centre: recharts' `PolarRadiusAxis`. */class PolarRadiusAxis extends Part {
1163
+ kind = 'radius-axis';
1164
+ labels = new Registry();
1165
+ registerLabel = label => this.labels.add(label);
1166
+ unregisterLabel = label => this.labels.remove(label);
1167
+ static {
1168
+ setComponentTemplate(precompileTemplate("{{yield (hash Label=(component RadiusAxisLabel axis=this))}}", {
1169
+ strictMode: true,
1170
+ scope: () => ({
1171
+ hash,
1172
+ RadiusAxisLabel
1173
+ })
1174
+ }), this);
1175
+ }
1176
+ }
1177
+ // ---------------------------------------------------------------------------------------------
1178
+ // Series
1179
+ /** A radar's dots: false (default) for none, true, their attributes, or a component. */
1180
+
1181
+ /** The arguments both polar series share. */
1182
+
1183
+ /** A polygon through each row's value: recharts' `Radar`. */class Radar extends Part {
1184
+ kind = 'radar';
1185
+ static {
1186
+ setComponentTemplate(precompileTemplate("", {
1187
+ strictMode: true
1188
+ }), this);
1189
+ }
1190
+ }
1191
+ /** What a radial bar's `@background` takes: true for recharts' track, or its attributes. */
1192
+
1193
+ /** A label on each bar of a radial bar series: recharts' `LabelList` in a polar chart. */class PolarLabelList extends Component {
1194
+ constructor(owner, args) {
1195
+ super(owner, args);
1196
+ args.series.registerLabel(this);
1197
+ }
1198
+ willDestroy() {
1199
+ super.willDestroy();
1200
+ this.args.series.unregisterLabel(this);
1201
+ }
1202
+ static {
1203
+ setComponentTemplate(precompileTemplate("", {
1204
+ strictMode: true
1205
+ }), this);
1206
+ }
1207
+ }
1208
+ /** A bar round the chart for each row: recharts' `RadialBar`. */class RadialBar extends Part {
1209
+ kind = 'radial-bar';
1210
+ labels = new Registry();
1211
+ registerLabel = label => this.labels.add(label);
1212
+ unregisterLabel = label => this.labels.remove(label);
1213
+ static {
1214
+ setComponentTemplate(precompileTemplate("{{yield (hash LabelList=(component PolarLabelList series=this))}}", {
1215
+ strictMode: true,
1216
+ scope: () => ({
1217
+ hash,
1218
+ PolarLabelList
1219
+ })
1220
+ }), this);
1221
+ }
1222
+ }
1223
+
1224
+ const INITIAL_DIMENSION = {
1225
+ width: -1,
1226
+ height: -1
1227
+ };
1228
+ const DEFAULT_MARGIN = {
1229
+ top: 5,
1230
+ right: 5,
1231
+ bottom: 5,
1232
+ left: 5
1233
+ };
1234
+ const EPS = 1e-5;
1235
+ const COS_45 = Math.cos(45 * (Math.PI / 180));
1236
+ let seriesIds = 0;
1237
+ const ids = new WeakMap();
1238
+ function seriesId(part) {
1239
+ let id = ids.get(part);
1240
+ if (!id) ids.set(part, id = `polar-series-${++seriesIds}`);
1241
+ return id;
1242
+ }
1243
+ let labelIds = 0;
1244
+ function keyOf(dataKey) {
1245
+ return isFunction(dataKey) ? '' : String(dataKey ?? '');
1246
+ }
1247
+ function round(value) {
1248
+ return Math.round(value * 1000) / 1000;
1249
+ }
1250
+ function asText(value) {
1251
+ return value === null || value === undefined ? '' : String(value);
1252
+ }
1253
+ /** recharts' `getLegendItemColor`: the stroke, where there is one, else the fill. */
1254
+ function itemColor(stroke, fill) {
1255
+ return stroke && stroke !== 'none' ? stroke : fill;
1256
+ }
1257
+ /** Calls `callback` with an element's layout size now, then on every resize, until removed. */
1258
+ function observeSize(context, element, callback) {
1259
+ callback({
1260
+ width: element.offsetWidth,
1261
+ height: element.offsetHeight
1262
+ });
1263
+ const observer = resizeObserver(context);
1264
+ const onEntry = entry => callback({
1265
+ width: entry.contentRect.width,
1266
+ height: entry.contentRect.height
1267
+ });
1268
+ observer.observe(element, onEntry);
1269
+ return () => observer.unobserve(element, onEntry);
1270
+ }
1271
+ /**
1272
+ * The chart itself, at its size: recharts' wrapper, its `<svg>` with the marks in recharts'
1273
+ * z-index layers, and the legend and tooltip boxes over it.
1274
+ */
1275
+ const Surface = setComponentTemplate(precompileTemplate("<div class=\"recharts-wrapper\" style={{@chart.wrapperStyle}} data-test-jn={{unless @chart.args.inContainer \"chart\"}} data-test-jn-name={{unless @chart.args.inContainer @chart.args.name}} data-test-jn-part=\"wrapper\" data-layout={{@chart.layout}} data-polar-chart={{@chart.chartName}} {{on \"mousemove\" @chart.onMouseMove}} {{on \"mouseleave\" @chart.onMouseLeave}} ...attributes>\n <svg class=\"recharts-surface\" width={{@chart.width}} height={{@chart.height}} viewBox={{@chart.viewBoxAttribute}} style=\"width: 100%; height: 100%; display: block;\" role={{if @chart.accessibilityLayer \"application\"}} tabindex={{if @chart.accessibilityLayer \"0\"}} data-test-jn-part=\"surface\" {{on \"focus\" @chart.onFocus}} {{on \"blur\" @chart.onBlur}} {{on \"keydown\" @chart.onKeyDown}}>\n <title>{{@chart.args.title}}</title>\n <desc>{{@chart.args.desc}}</desc>\n {{!--\n The block registers the chart's parts (and can hold <defs>). Nothing above it may read\n them, in this render or a later one: see ./registry.ts.\n --}}\n {{yield}}\n {{#if @chart.geometry}}\n <g class=\"recharts-zIndex-layer_-100\">\n {{#if @chart.grid}}\n <g class=\"recharts-polar-grid\" data-test-jn-part=\"polar-grid\" data-grid-type={{@chart.grid.gridType}}>\n <g class=\"recharts-polar-grid-concentric\">\n {{#if @chart.grid.background}}\n {{#if @chart.grid.circle}}\n <circle stroke={{@chart.grid.stroke}} fill={{@chart.grid.background.fill}} fill-opacity={{@chart.grid.fillOpacity}} stroke-width={{@chart.grid.strokeWidth}} stroke-dasharray={{@chart.grid.strokeDasharray}} class=\"recharts-polar-grid-concentric-circle {{@chart.grid.class}}\" cx={{@chart.grid.cx}} cy={{@chart.grid.cy}} r={{@chart.grid.background.radius}}></circle>\n {{else}}\n <path stroke={{@chart.grid.stroke}} fill={{@chart.grid.background.fill}} fill-opacity={{@chart.grid.fillOpacity}} stroke-width={{@chart.grid.strokeWidth}} stroke-dasharray={{@chart.grid.strokeDasharray}} class=\"recharts-polar-grid-concentric-polygon {{@chart.grid.class}}\" d={{@chart.grid.background.d}}></path>\n {{/if}}\n {{/if}}\n {{#each @chart.grid.rings as |ring|}}\n {{#if @chart.grid.circle}}\n <circle stroke={{@chart.grid.stroke}} fill=\"none\" stroke-width={{@chart.grid.strokeWidth}} stroke-dasharray={{@chart.grid.strokeDasharray}} class=\"recharts-polar-grid-concentric-circle {{@chart.grid.class}}\" cx={{@chart.grid.cx}} cy={{@chart.grid.cy}} r={{ring.radius}} data-test-jn-part=\"grid-ring\" data-test-jn-value={{ring.radius}}></circle>\n {{else}}\n <path stroke={{@chart.grid.stroke}} fill=\"none\" stroke-width={{@chart.grid.strokeWidth}} stroke-dasharray={{@chart.grid.strokeDasharray}} class=\"recharts-polar-grid-concentric-polygon {{@chart.grid.class}}\" d={{ring.d}} data-test-jn-part=\"grid-ring\" data-test-jn-value={{ring.radius}}></path>\n {{/if}}\n {{/each}}\n </g>\n {{#if @chart.grid.spokes.length}}\n <g class=\"recharts-polar-grid-angle\">\n {{#each @chart.grid.spokes as |spoke|}}\n <line stroke={{@chart.grid.stroke}} stroke-width={{@chart.grid.strokeWidth}} stroke-dasharray={{@chart.grid.strokeDasharray}} fill={{@chart.grid.fill}} class={{@chart.grid.class}} x1={{spoke.x1}} y1={{spoke.y1}} x2={{spoke.x2}} y2={{spoke.y2}} data-test-jn-part=\"grid-spoke\" data-test-jn-value={{spoke.angle}}></line>\n {{/each}}\n </g>\n {{/if}}\n </g>\n {{/if}}\n </g>\n <g class=\"recharts-zIndex-layer_-50\">\n {{#each @chart.radialBars as |bar|}}\n {{#each bar.background as |sector|}}\n <g class=\"recharts-layer recharts-shape\">\n <path fill={{sector.fill}} class=\"recharts-sector recharts-radial-bar-background-sector {{sector.class}}\" d={{sector.d}} data-test-jn-part=\"background-sector\"></path>\n </g>\n {{/each}}\n {{/each}}\n </g>\n <defs>\n <clipPath id={{@chart.clipId}}>\n <rect data-test-jn-part=\"plot\" data-test-jn-categories={{@chart.categoryCoordinates}} data-test-jn-ring={{@chart.ringAttribute}} x={{@chart.geometry.offset.left}} y={{@chart.geometry.offset.top}} height={{@chart.geometry.offset.height}} width={{@chart.geometry.offset.width}}></rect>\n </clipPath>\n </defs>\n <g class=\"recharts-zIndex-layer_100\">\n {{#each @chart.radars as |radar|}}\n <g class=\"recharts-layer recharts-radar {{radar.class}}\" data-test-jn-part=\"series\" data-test-jn-value={{radar.key}} data-series-type=\"radar\" data-test-jn-points={{radar.points}}>\n <g class=\"recharts-layer recharts-radar-polygon\">\n {{#if radar.range}}\n <g class=\"recharts-polygon\">\n <path fill={{radar.fill}} fill-opacity={{radar.fillOpacity}} stroke=\"none\" stroke-width={{radar.strokeWidth}} d={{radar.range.area}}></path>\n {{#if radar.range.outer}}\n <path fill=\"none\" stroke={{radar.stroke}} stroke-width={{radar.strokeWidth}} d={{radar.range.outer}}></path>\n <path fill=\"none\" stroke={{radar.stroke}} stroke-width={{radar.strokeWidth}} d={{radar.range.inner}}></path>\n {{/if}}\n </g>\n {{else if radar.d}}\n <path fill={{radar.fill}} fill-opacity={{radar.fillOpacity}} stroke={{radar.stroke}} stroke-width={{radar.strokeWidth}} class=\"recharts-polygon\" d={{radar.d}}></path>\n {{/if}}\n </g>\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_300\">\n {{#each @chart.radialBars as |bar|}}\n <g class=\"recharts-layer recharts-area {{bar.class}}\" data-test-jn-part=\"series\" data-test-jn-value={{bar.key}} data-series-type=\"radial-bar\" data-test-jn-points={{bar.points}}>\n {{#if bar.hasBackground}}\n <g class=\"recharts-layer recharts-radial-bar-background\"></g>\n {{/if}}\n <g class=\"recharts-layer recharts-radial-bar-sectors\">\n {{#each bar.sectors as |sector|}}\n <g class=\"recharts-layer recharts-shape\">\n {{#if sector.d}}\n <path fill={{sector.fill}} fill-opacity={{sector.fillOpacity}} stroke={{sector.stroke}} stroke-width={{sector.strokeWidth}} class=\"recharts-sector recharts-radial-bar-sector\" d={{sector.d}} data-test-jn-part=\"sector\" data-test-jn-value={{sector.index}}></path>\n {{/if}}\n </g>\n {{/each}}\n </g>\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_500\">\n {{#if @chart.angleAxis}}\n <g class=\"recharts-layer recharts-polar-angle-axis angleAxis {{@chart.angleAxis.class}}\" data-test-jn-part=\"angle-axis\">\n {{#if @chart.angleAxis.line}}\n {{#if @chart.angleAxis.line.circle}}\n <circle class=\"recharts-dot recharts-polar-angle-axis-line\" fill=\"none\" stroke={{@chart.angleAxis.stroke}} cx={{@chart.angleAxis.line.cx}} cy={{@chart.angleAxis.line.cy}} r={{@chart.angleAxis.line.r}}></circle>\n {{else}}\n <path class=\"recharts-polygon recharts-polar-angle-axis-line\" fill=\"none\" stroke={{@chart.angleAxis.stroke}} d={{@chart.angleAxis.line.d}}></path>\n {{/if}}\n {{/if}}\n <g class=\"recharts-layer recharts-polar-angle-axis-ticks\">\n {{#each @chart.angleAxis.ticks as |tick|}}\n <g class=\"recharts-layer recharts-polar-angle-axis-tick\">\n {{#if tick.line}}\n <line class=\"recharts-polar-angle-axis-tick-line\" fill=\"none\" stroke={{@chart.angleAxis.stroke}} x1={{tick.line.x1}} y1={{tick.line.y1}} x2={{tick.line.x2}} y2={{tick.line.y2}}></line>\n {{/if}}\n {{#if @chart.angleAxis.tickComponent}}\n {{#let @chart.angleAxis.tickComponent as |Tick|}}\n <Tick @x={{tick.args.x}} @y={{tick.args.y}} @textAnchor={{tick.args.textAnchor}} @verticalAnchor={{tick.args.verticalAnchor}} @index={{tick.args.index}} @payload={{tick.args.payload}} @value={{tick.args.value}} @fill={{tick.args.fill}} @stroke={{tick.args.stroke}} @cx={{tick.args.cx}} @cy={{tick.args.cy}} @radius={{tick.args.radius}} />\n {{/let}}\n {{else if @chart.angleAxis.showLabels}}\n <text stroke=\"none\" x={{tick.args.x}} y={{tick.args.y}} class=\"recharts-text recharts-polar-angle-axis-tick-value\" text-anchor={{tick.args.textAnchor}} fill={{@chart.angleAxis.labelFill}} data-test-jn-part=\"tick\"><tspan x={{tick.args.x}} dy={{tick.dy}}>{{tick.text}}</tspan></text>\n {{/if}}\n </g>\n {{/each}}\n </g>\n </g>\n {{/if}}\n {{#if @chart.radiusAxis}}\n <g class=\"recharts-layer recharts-polar-radius-axis radiusAxis\n {{@chart.radiusAxis.class}}\" data-test-jn-part=\"radius-axis\">\n {{#if @chart.radiusAxis.line}}\n <line class=\"recharts-polar-radius-axis-line\" stroke={{@chart.radiusAxis.stroke}} fill=\"none\" x1={{@chart.radiusAxis.line.x1}} y1={{@chart.radiusAxis.line.y1}} x2={{@chart.radiusAxis.line.x2}} y2={{@chart.radiusAxis.line.y2}}></line>\n {{/if}}\n {{#if @chart.radiusAxis.ticks.length}}\n <g class=\"recharts-layer recharts-polar-radius-axis-ticks\">\n {{#each @chart.radiusAxis.ticks as |tick|}}\n <g class=\"recharts-layer recharts-polar-radius-axis-tick\">\n <text transform={{tick.transform}} stroke=\"none\" x={{tick.x}} y={{tick.y}} class=\"recharts-text recharts-polar-radius-axis-tick-value\" text-anchor={{@chart.radiusAxis.textAnchor}} fill={{@chart.radiusAxis.stroke}} data-test-jn-part=\"tick\"><tspan x={{tick.x}} dy=\"0em\">{{tick.text}}</tspan></text>\n </g>\n {{/each}}\n </g>\n {{/if}}\n {{#each @chart.radiusAxis.labels as |label|}}\n {{#if label.content}}\n {{#let label.content as |Content|}}\n <Content @viewBox={{label.viewBox}} @value={{label.value}} @offset={{label.offset}} @position={{label.position}} />\n {{/let}}\n {{else if label.arc}}\n <text fill={{label.fill}} font-size={{label.fontSize}} class=\"recharts-radial-bar-label {{label.class}}\" dominant-baseline=\"central\" data-test-jn-part=\"axis-label\"><defs><path id={{label.arc.id}} d={{label.arc.d}}></path></defs><textPath href=\"#{{label.arc.id}}\">{{label.text}}</textPath></text>\n {{else}}\n <text x={{label.x}} y={{label.y}} text-anchor={{label.anchor}} fill={{label.fill}} font-size={{label.fontSize}} class=\"recharts-text recharts-label {{label.class}}\" data-test-jn-part=\"axis-label\"><tspan x={{label.x}} dy={{label.dy}}>{{label.text}}</tspan></text>\n {{/if}}\n {{/each}}\n </g>\n {{/if}}\n </g>\n <g class=\"recharts-zIndex-layer_600\">\n {{#each @chart.radars as |radar|}}\n {{#if radar.dots.length}}\n <g class=\"recharts-layer recharts-radar-dots\" data-test-jn-part=\"dots\" data-test-jn-value={{radar.key}}>\n {{#each radar.dots as |dot|}}\n {{#if dot.component}}\n {{#let dot.component as |Dot|}}\n <Dot @cx={{dot.args.cx}} @cy={{dot.args.cy}} @r={{dot.args.r}} @index={{dot.args.index}} @value={{dot.args.value}} @payload={{dot.args.payload}} @dataKey={{dot.args.dataKey}} @stroke={{dot.args.stroke}} @strokeWidth={{dot.args.strokeWidth}} @fill={{dot.args.fill}} />\n {{/let}}\n {{else}}\n <circle r={{dot.attrs.r}} fill={{dot.attrs.fill}} fill-opacity={{dot.attrs.fillOpacity}} stroke={{dot.attrs.stroke}} stroke-width={{dot.attrs.strokeWidth}} cx={{dot.args.cx}} cy={{dot.args.cy}} class={{dot.attrs.class}}></circle>\n {{/if}}\n {{/each}}\n </g>\n {{/if}}\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_1100\">\n {{#if @chart.cursor}}\n <path class=\"{{@chart.cursor.class}} recharts-tooltip-cursor\" stroke={{@chart.cursor.stroke}} stroke-width={{@chart.cursor.strokeWidth}} fill=\"none\" pointer-events=\"none\" d={{@chart.cursor.d}} data-test-jn-part=\"cursor\"></path>\n {{/if}}\n </g>\n <g class=\"recharts-zIndex-layer_1200\">\n {{#each @chart.activeDots as |dot|}}\n <g class=\"recharts-layer recharts-active-dot\" data-test-jn-part=\"active-dot\">\n {{#if dot.component}}\n {{#let dot.component as |Dot|}}\n <Dot @cx={{dot.args.cx}} @cy={{dot.args.cy}} @r={{dot.args.r}} @index={{dot.args.index}} @value={{dot.args.value}} @payload={{dot.args.payload}} @dataKey={{dot.args.dataKey}} @stroke={{dot.args.stroke}} @strokeWidth={{dot.args.strokeWidth}} @fill={{dot.args.fill}} />\n {{/let}}\n {{else}}\n <circle class={{dot.attrs.class}} cx={{dot.args.cx}} cy={{dot.args.cy}} r={{dot.attrs.r}} fill={{dot.attrs.fill}} fill-opacity={{dot.attrs.fillOpacity}} stroke-width={{dot.attrs.strokeWidth}} stroke={{dot.attrs.stroke}}></circle>\n {{/if}}\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_2000\">\n {{#each @chart.labelLists as |list|}}\n <g class=\"recharts-layer recharts-label-list\" data-test-jn-part=\"labels\" data-test-jn-value={{list.series}}>\n {{#each list.items as |item|}}\n {{#if item.arc}}\n <text fill={{item.fill}} class=\"recharts-radial-bar-label {{list.class}}\" font-size={{list.fontSize}} dominant-baseline=\"central\" data-test-jn-part=\"label\"><defs><path id={{item.arc.id}} d={{item.arc.d}}></path></defs><textPath href=\"#{{item.arc.id}}\">{{item.text}}</textPath></text>\n {{else}}\n <text x={{item.x}} y={{item.y}} text-anchor={{item.anchor}} fill={{item.fill}} font-size={{list.fontSize}} class=\"recharts-text recharts-label {{list.class}}\" data-test-jn-part=\"label\"><tspan x={{item.x}} dy={{item.dy}}>{{item.text}}</tspan></text>\n {{/if}}\n {{/each}}\n </g>\n {{/each}}\n </g>\n {{/if}}\n </svg>\n {{#if @chart.legendPart}}\n <div class=\"recharts-legend-wrapper\" style={{@chart.legendStyle}} {{@chart.measureLegend}}>\n {{#let @chart.legendContent as |Content|}}\n <Content @payload={{@chart.legendPayload}} @verticalAlign={{@chart.legendVerticalAlign}} @config={{@chart.args.config}} />\n {{/let}}\n </div>\n {{/if}}\n {{#if @chart.tooltipPart}}\n <div class=\"recharts-tooltip-wrapper\" tabindex=\"-1\" style={{@chart.tooltipStyle}} {{@chart.measureTooltip @chart.isTooltipActive @chart.tooltipLabel @chart.tooltipPayload.length}}>\n {{#let @chart.tooltipContent as |Content|}}\n <Content @active={{@chart.isTooltipActive}} @payload={{@chart.tooltipPayload}} @label={{@chart.tooltipLabel}} @config={{@chart.args.config}} @coordinate={{@chart.tooltipCoordinate}} @tooltip={{@chart.tooltipProps}} />\n {{/let}}\n </div>\n {{/if}}\n</div>", {
1276
+ strictMode: true,
1277
+ scope: () => ({
1278
+ on
1279
+ })
1280
+ }), templateOnly());
1281
+ class PolarChart extends Component {
1282
+ #parts = new Registry();
1283
+ chartId = idFor(this, 'chart');
1284
+ static {
1285
+ g(this.prototype, "containerSize", [tracked], function () {
1286
+ return null;
1287
+ });
1288
+ }
1289
+ #containerSize_ = (i(this, "containerSize"), void 0);
1290
+ static {
1291
+ g(this.prototype, "legendBox", [tracked], function () {
1292
+ return null;
1293
+ });
1294
+ }
1295
+ #legendBox_ = (i(this, "legendBox"), void 0);
1296
+ static {
1297
+ g(this.prototype, "tooltipBox", [tracked], function () {
1298
+ return null;
1299
+ });
1300
+ }
1301
+ #tooltipBox_ = (i(this, "tooltipBox"), void 0);
1302
+ static {
1303
+ g(this.prototype, "pointer", [tracked], function () {
1304
+ return null;
1305
+ });
1306
+ }
1307
+ #pointer = (i(this, "pointer"), void 0);
1308
+ /** The pointer, in the chart's pixels, while it is over the chart. */
1309
+ static {
1310
+ g(this.prototype, "keyboardIndex", [tracked], function () {
1311
+ return null;
1312
+ });
1313
+ }
1314
+ #keyboardIndex = (i(this, "keyboardIndex"), void 0);
1315
+ static {
1316
+ g(this.prototype, "keyboardActive", [tracked], function () {
1317
+ return false;
1318
+ });
1319
+ }
1320
+ #keyboardActive = (i(this, "keyboardActive"), void 0);
1321
+ register(part) {
1322
+ this.#parts.add(part);
1323
+ }
1324
+ unregister(part) {
1325
+ this.#parts.remove(part);
1326
+ }
1327
+ // ---------------------------------------------------------------------------------------
1328
+ // Size
1329
+ get fixedSize() {
1330
+ return isNumber$1(this.args.width) && isNumber$1(this.args.height);
1331
+ }
1332
+ get size() {
1333
+ if (this.fixedSize) return {
1334
+ width: this.args.width,
1335
+ height: this.args.height
1336
+ };
1337
+ const size = this.containerSize ?? this.args.initialDimension ?? INITIAL_DIMENSION;
1338
+ if (!(size.width > 0) || !(size.height > 0)) return null;
1339
+ return size;
1340
+ }
1341
+ // The measurements below compare with untracked copies: a modifier that read the tracked
1342
+ // value it sets would run again each time it set it.
1343
+ #containerSize = null;
1344
+ #legendBox = null;
1345
+ #tooltipBox = null;
1346
+ measureContainer = modifier(element => observeSize(this, element, ({
1347
+ width,
1348
+ height
1349
+ }) => {
1350
+ const next = {
1351
+ width: Math.round(width),
1352
+ height: Math.round(height)
1353
+ };
1354
+ const current = this.#containerSize;
1355
+ if (!current || current.width !== next.width || current.height !== next.height) {
1356
+ this.#containerSize = next;
1357
+ this.containerSize = next;
1358
+ }
1359
+ }));
1360
+ get width() {
1361
+ return this.size?.width ?? 0;
1362
+ }
1363
+ get height() {
1364
+ return this.size?.height ?? 0;
1365
+ }
1366
+ get viewBoxAttribute() {
1367
+ const size = this.size;
1368
+ return `0 0 ${size.width} ${size.height}`;
1369
+ }
1370
+ get wrapperStyle() {
1371
+ const size = this.size;
1372
+ return htmlSafe(`position: relative; cursor: default; width: ${size.width}px; height: ${size.height}px;`);
1373
+ }
1374
+ get clipId() {
1375
+ return `${this.chartId}-clip`;
1376
+ }
1377
+ get accessibilityLayer() {
1378
+ return this.args.accessibilityLayer ?? true;
1379
+ }
1380
+ // ---------------------------------------------------------------------------------------
1381
+ // Parts
1382
+ get partList() {
1383
+ return this.#parts.items;
1384
+ }
1385
+ get gridPart() {
1386
+ return this.partList.find(part => part instanceof PolarGrid);
1387
+ }
1388
+ get angleAxisPart() {
1389
+ return this.partList.find(part => part instanceof PolarAngleAxis);
1390
+ }
1391
+ get radiusAxisPart() {
1392
+ return this.partList.find(part => part instanceof PolarRadiusAxis);
1393
+ }
1394
+ get radarParts() {
1395
+ return this.partList.filter(part => part instanceof Radar);
1396
+ }
1397
+ get radialBarParts() {
1398
+ return this.partList.filter(part => part instanceof RadialBar);
1399
+ }
1400
+ get seriesParts() {
1401
+ return this.partList.filter(part => part instanceof Radar || part instanceof RadialBar);
1402
+ }
1403
+ get tooltipPart() {
1404
+ return this.partList.find(part => part instanceof ChartTooltip);
1405
+ }
1406
+ get legendPart() {
1407
+ return this.partList.find(part => part instanceof ChartLegend);
1408
+ }
1409
+ get chartName() {
1410
+ return this.args.chartName ?? 'RadarChart';
1411
+ }
1412
+ get layout() {
1413
+ return this.chartName === 'RadarChart' ? 'centric' : 'radial';
1414
+ }
1415
+ get margin() {
1416
+ const margin = this.args.margin;
1417
+ if (!margin) return DEFAULT_MARGIN;
1418
+ return {
1419
+ top: margin.top ?? 0,
1420
+ right: margin.right ?? 0,
1421
+ bottom: margin.bottom ?? 0,
1422
+ left: margin.left ?? 0
1423
+ };
1424
+ }
1425
+ axisSettings(part, axis) {
1426
+ const settings = axis === 'angle' ? defaultAngleAxis() : defaultRadiusAxis();
1427
+ if (!part) return settings;
1428
+ const args = part.args;
1429
+ return {
1430
+ ...settings,
1431
+ dataKey: args.dataKey,
1432
+ type: args.type ?? 'auto',
1433
+ domain: args.domain,
1434
+ allowDecimals: args.allowDecimals ?? settings.allowDecimals,
1435
+ // A PolarAngleAxis has no tick count unless given; a PolarRadiusAxis aims for 5.
1436
+ tickCount: args.tickCount ?? settings.tickCount,
1437
+ ticks: args.ticks,
1438
+ reversed: args.reversed ?? false,
1439
+ scale: args.scale ?? 'auto'
1440
+ };
1441
+ }
1442
+ // ---------------------------------------------------------------------------------------
1443
+ // Layout
1444
+ get geometry() {
1445
+ const size = this.size;
1446
+ if (!size) return null;
1447
+ const radar = this.chartName === 'RadarChart';
1448
+ const legend = this.legendPart;
1449
+ return polarGeometry({
1450
+ chartName: this.chartName,
1451
+ layout: this.layout,
1452
+ width: size.width,
1453
+ height: size.height,
1454
+ margin: this.margin,
1455
+ legend: legend && this.legendBox ? {
1456
+ ...this.legendBox,
1457
+ verticalAlign: legend.args.verticalAlign ?? 'bottom',
1458
+ align: legend.args.align ?? 'center',
1459
+ layout: legend.args.layout ?? 'horizontal'
1460
+ } : undefined,
1461
+ cx: this.args.cx ?? '50%',
1462
+ cy: this.args.cy ?? '50%',
1463
+ innerRadius: this.args.innerRadius ?? 0,
1464
+ outerRadius: this.args.outerRadius ?? '80%',
1465
+ startAngle: this.args.startAngle ?? (radar ? 90 : 0),
1466
+ endAngle: this.args.endAngle ?? (radar ? -270 : 360),
1467
+ data: this.args.data ?? [],
1468
+ angleAxis: this.axisSettings(this.angleAxisPart, 'angle'),
1469
+ radiusAxis: this.axisSettings(this.radiusAxisPart, 'radius'),
1470
+ radars: this.radarParts.map(part => ({
1471
+ id: seriesId(part),
1472
+ dataKey: part.args.dataKey,
1473
+ hide: part.args.hide ?? false
1474
+ })),
1475
+ radialBars: this.radialBarParts.map(part => ({
1476
+ id: seriesId(part),
1477
+ dataKey: part.args.dataKey,
1478
+ stackId: part.args.stackId,
1479
+ hide: part.args.hide ?? false,
1480
+ minPointSize: part.args.minPointSize ?? 0,
1481
+ barSize: part.args.barSize,
1482
+ maxBarSize: part.args.maxBarSize
1483
+ })),
1484
+ stackOffset: this.args.stackOffset ?? 'none',
1485
+ barGap: this.args.barGap ?? 4,
1486
+ barCategoryGap: this.args.barCategoryGap ?? '10%',
1487
+ barSize: this.args.barSize,
1488
+ maxBarSize: this.args.maxBarSize
1489
+ });
1490
+ }
1491
+ static {
1492
+ n(this.prototype, "geometry", [cached]);
1493
+ }
1494
+ get viewBox() {
1495
+ return this.geometry?.viewBox ?? null;
1496
+ }
1497
+ /** Where each row sits on the tooltip's axis (an angle, or a radius), for the harness. */
1498
+ get categoryCoordinates() {
1499
+ return (this.geometry?.tooltipTicks ?? []).map(tick => round(tick.coordinate)).join(' ');
1500
+ }
1501
+ /** The ring, for the harness: `cx cy innerRadius outerRadius startAngle endAngle`. */
1502
+ get ringAttribute() {
1503
+ const box = this.viewBox;
1504
+ if (!box) return '';
1505
+ return [box.cx, box.cy, box.innerRadius, box.outerRadius, box.startAngle, box.endAngle].map(round).join(' ');
1506
+ }
1507
+ // ---------------------------------------------------------------------------------------
1508
+ // Drawing
1509
+ get grid() {
1510
+ const part = this.gridPart;
1511
+ const geometry = this.geometry;
1512
+ if (!part || !geometry) return null;
1513
+ const {
1514
+ cx,
1515
+ cy,
1516
+ innerRadius,
1517
+ outerRadius
1518
+ } = geometry.viewBox;
1519
+ if (outerRadius <= 0) return null;
1520
+ const args = part.args;
1521
+ const angles = args.polarAngles ?? geometry.angleAxis.ticks.map(tick => tick.coordinate);
1522
+ const radii = args.polarRadius ?? geometry.radiusAxis.ticks.map(tick => tick.coordinate);
1523
+ if (!radii.length) return null;
1524
+ const circle = args.gridType === 'circle';
1525
+ const max = Math.max(...radii);
1526
+ return {
1527
+ gridType: circle ? 'circle' : 'polygon',
1528
+ circle,
1529
+ cx,
1530
+ cy,
1531
+ stroke: args.stroke ?? '#ccc',
1532
+ strokeWidth: args.strokeWidth,
1533
+ strokeDasharray: args.strokeDasharray,
1534
+ fill: args.fill,
1535
+ fillOpacity: args.fillOpacity,
1536
+ class: args.class,
1537
+ background: args.fill && args.fill !== 'none' ? {
1538
+ fill: args.fill,
1539
+ radius: max,
1540
+ d: gridPolygonPath(max, cx, cy, angles)
1541
+ } : null,
1542
+ rings: radii.map(radius => ({
1543
+ radius,
1544
+ d: gridPolygonPath(radius, cx, cy, angles)
1545
+ })),
1546
+ spokes: args.radialLines === false ? [] : angles.map(angle => {
1547
+ const start = polarToCartesian(cx, cy, innerRadius, angle);
1548
+ const end = polarToCartesian(cx, cy, outerRadius, angle);
1549
+ return {
1550
+ angle,
1551
+ x1: start.x,
1552
+ y1: start.y,
1553
+ x2: end.x,
1554
+ y2: end.y
1555
+ };
1556
+ })
1557
+ };
1558
+ }
1559
+ get angleAxis() {
1560
+ const part = this.angleAxisPart;
1561
+ const geometry = this.geometry;
1562
+ if (!part || !geometry || part.args.hide || !geometry.angleAxisTicks.length) return null;
1563
+ const args = part.args;
1564
+ const {
1565
+ cx,
1566
+ cy,
1567
+ outerRadius: radius
1568
+ } = geometry.viewBox;
1569
+ const ticks = geometry.angleAxisTicks;
1570
+ const outer = (args.orientation ?? 'outer') === 'outer';
1571
+ const tickSize = args.tickSize || 8;
1572
+ const tick = args.tick ?? true;
1573
+ const tickComponent = tick === true || tick === false ? undefined : tick;
1574
+ const axisLine = args.axisLine ?? true;
1575
+ return {
1576
+ class: args.class,
1577
+ stroke: args.stroke,
1578
+ labelFill: args.stroke ?? '#808080',
1579
+ showLabels: tick !== false,
1580
+ tickComponent,
1581
+ line: axisLine ? args.axisLineType === 'circle' ? {
1582
+ circle: true,
1583
+ cx,
1584
+ cy,
1585
+ r: radius,
1586
+ d: null
1587
+ } : {
1588
+ circle: false,
1589
+ d: polygonPath(ticks.map(entry => polarToCartesian(cx, cy, radius, entry.coordinate)))
1590
+ } : null,
1591
+ ticks: ticks.map((entry, index) => {
1592
+ const start = polarToCartesian(cx, cy, radius, entry.coordinate);
1593
+ const end = polarToCartesian(cx, cy, radius + (outer ? 1 : -1) * tickSize, entry.coordinate);
1594
+ const cos = Math.cos(-entry.coordinate * Math.PI / 180);
1595
+ const sin = Math.sin(-entry.coordinate * Math.PI / 180);
1596
+ const textAnchor = cos > EPS ? outer ? 'start' : 'end' : cos < -EPS ? outer ? 'end' : 'start' : 'middle';
1597
+ const verticalAnchor = Math.abs(cos) <= COS_45 ? sin > 0 ? 'start' : 'end' : 'middle';
1598
+ const text = asText(args.tickFormatter ? args.tickFormatter(entry.value, index) : entry.value);
1599
+ return {
1600
+ line: args.tickLine ?? true ? {
1601
+ x1: start.x,
1602
+ y1: start.y,
1603
+ x2: end.x,
1604
+ y2: end.y
1605
+ } : null,
1606
+ text,
1607
+ dy: TEXT_DY[verticalAnchor],
1608
+ args: {
1609
+ x: end.x,
1610
+ y: end.y,
1611
+ textAnchor,
1612
+ verticalAnchor,
1613
+ index,
1614
+ payload: entry,
1615
+ value: text,
1616
+ fill: args.stroke,
1617
+ stroke: 'none',
1618
+ cx,
1619
+ cy,
1620
+ radius
1621
+ }
1622
+ };
1623
+ })
1624
+ };
1625
+ }
1626
+ get radiusAxis() {
1627
+ const part = this.radiusAxisPart;
1628
+ const geometry = this.geometry;
1629
+ if (!part || !geometry || part.args.hide || !geometry.radiusAxis.ticks.length) return null;
1630
+ const args = part.args;
1631
+ const {
1632
+ cx,
1633
+ cy
1634
+ } = geometry.viewBox;
1635
+ const angle = args.angle ?? 0;
1636
+ const ticks = geometry.radiusAxis.ticks;
1637
+ const stroke = args.stroke ?? '#ccc';
1638
+ const orientation = args.orientation ?? 'right';
1639
+ const coordinates = ticks.map(entry => entry.coordinate);
1640
+ const start = polarToCartesian(cx, cy, Math.min(...coordinates), angle);
1641
+ const end = polarToCartesian(cx, cy, Math.max(...coordinates), angle);
1642
+ // The ring a Label sits in: recharts' radius axis view box.
1643
+ const radii = ticks.map(entry => entry.coordinate || 0);
1644
+ const viewBox = {
1645
+ cx,
1646
+ cy,
1647
+ startAngle: angle,
1648
+ endAngle: angle,
1649
+ innerRadius: Math.min(...radii),
1650
+ outerRadius: Math.max(...radii),
1651
+ clockWise: false
1652
+ };
1653
+ return {
1654
+ class: args.class,
1655
+ stroke,
1656
+ textAnchor: orientation === 'left' ? 'end' : orientation === 'right' ? 'start' : 'middle',
1657
+ line: args.axisLine ?? true ? {
1658
+ x1: start.x,
1659
+ y1: start.y,
1660
+ x2: end.x,
1661
+ y2: end.y
1662
+ } : null,
1663
+ ticks: args.tick === false ? [] : ticks.map((entry, index) => {
1664
+ const point = polarToCartesian(cx, cy, entry.coordinate, angle);
1665
+ const value = args.tickFormatter ? args.tickFormatter(entry.value, index) : entry.value;
1666
+ return {
1667
+ x: point.x,
1668
+ y: point.y,
1669
+ transform: `rotate(${90 - angle}, ${point.x}, ${point.y})`,
1670
+ text: asText(value)
1671
+ };
1672
+ }),
1673
+ labels: part.labels.items.map(label => {
1674
+ const labelArgs = label.args;
1675
+ const position = labelArgs.position ?? 'middle';
1676
+ const offset = labelArgs.offset ?? 5;
1677
+ const common = {
1678
+ viewBox,
1679
+ value: labelArgs.value,
1680
+ offset,
1681
+ position,
1682
+ content: labelArgs.content,
1683
+ text: asText(labelArgs.value),
1684
+ fill: labelArgs.fill ?? '#808080',
1685
+ fontSize: labelArgs.fontSize,
1686
+ class: labelArgs.class
1687
+ };
1688
+ if (position === 'insideStart' || position === 'insideEnd' || position === 'end') {
1689
+ return {
1690
+ ...common,
1691
+ arc: {
1692
+ id: `${this.chartId}-axis-label-${++labelIds}`,
1693
+ d: radialLabelPath(viewBox, position, offset)
1694
+ }
1695
+ };
1696
+ }
1697
+ const attrs = polarLabelAttrs(viewBox, offset, position);
1698
+ return {
1699
+ ...common,
1700
+ arc: null,
1701
+ x: attrs.x,
1702
+ y: attrs.y,
1703
+ anchor: attrs.textAnchor,
1704
+ dy: attrs.dy
1705
+ };
1706
+ })
1707
+ };
1708
+ }
1709
+ dotsFor(option, fallback, base, className, points, dataKey) {
1710
+ const value = option ?? fallback;
1711
+ if (value === false) return [];
1712
+ return points.map(point => {
1713
+ const args = {
1714
+ cx: point.x,
1715
+ cy: point.y,
1716
+ r: base.r ?? 3,
1717
+ index: point.index,
1718
+ value: point.value,
1719
+ payload: point.payload,
1720
+ dataKey,
1721
+ stroke: base.stroke,
1722
+ strokeWidth: base.strokeWidth,
1723
+ fill: base.fill
1724
+ };
1725
+ if (value === true) return {
1726
+ args,
1727
+ attrs: {
1728
+ ...base,
1729
+ class: className
1730
+ }
1731
+ };
1732
+ if (isPlainObject(value)) {
1733
+ const own = value;
1734
+ const attrs = {
1735
+ r: own.r ?? base.r,
1736
+ fill: own.fill ?? base.fill,
1737
+ fillOpacity: own.fillOpacity ?? base.fillOpacity,
1738
+ stroke: own.stroke ?? base.stroke,
1739
+ strokeWidth: own.strokeWidth ?? base.strokeWidth,
1740
+ class: [className, own.class].filter(Boolean).join(' ')
1741
+ };
1742
+ return {
1743
+ args: {
1744
+ ...args,
1745
+ r: attrs.r ?? 3
1746
+ },
1747
+ attrs
1748
+ };
1749
+ }
1750
+ return {
1751
+ component: value,
1752
+ args,
1753
+ attrs: {
1754
+ ...base,
1755
+ class: className
1756
+ }
1757
+ };
1758
+ });
1759
+ }
1760
+ get radars() {
1761
+ const geometry = this.geometry;
1762
+ if (!geometry) return [];
1763
+ return this.radarParts.flatMap((part, i) => {
1764
+ const args = part.args;
1765
+ if (args.hide) return [];
1766
+ const drawn = geometry.radars[i];
1767
+ const points = drawn.points;
1768
+ return [{
1769
+ key: keyOf(args.dataKey),
1770
+ class: args.class ?? '',
1771
+ points: points.map(point => `${round(point.x)},${round(point.y)}`).join(' '),
1772
+ d: drawn.isRange ? null : polygonPath(points, args.connectNulls ?? false),
1773
+ range: drawn.isRange ? {
1774
+ area: rangePolygonPath(points, drawn.baseLinePoints, args.connectNulls ?? false),
1775
+ outer: args.stroke && args.stroke !== 'none' ? polygonPath(points, args.connectNulls ?? false) : null,
1776
+ inner: args.stroke && args.stroke !== 'none' ? polygonPath(drawn.baseLinePoints, args.connectNulls ?? false) : null
1777
+ } : null,
1778
+ fill: args.fill,
1779
+ fillOpacity: args.fillOpacity,
1780
+ stroke: args.stroke,
1781
+ strokeWidth: args.strokeWidth,
1782
+ dots: this.dotsFor(args.dot, false, {
1783
+ r: 3,
1784
+ fill: args.fill,
1785
+ fillOpacity: args.fillOpacity,
1786
+ stroke: args.stroke,
1787
+ strokeWidth: args.strokeWidth
1788
+ }, 'recharts-dot recharts-radar-dot', points, args.dataKey)
1789
+ }];
1790
+ });
1791
+ }
1792
+ static {
1793
+ n(this.prototype, "radars", [cached]);
1794
+ }
1795
+ sectorFill(part, sector) {
1796
+ // recharts spreads the row over the sector, so a row's `fill` wins over the bar's.
1797
+ const own = sector.payload?.['fill'];
1798
+ return isString(own) ? own : part.args.fill;
1799
+ }
1800
+ get radialBars() {
1801
+ const geometry = this.geometry;
1802
+ if (!geometry) return [];
1803
+ return this.radialBarParts.flatMap((part, i) => {
1804
+ const args = part.args;
1805
+ if (args.hide) return [];
1806
+ const drawn = geometry.radialBars[i];
1807
+ const corners = {
1808
+ cornerRadius: args.cornerRadius ?? 0,
1809
+ forceCornerRadius: args.forceCornerRadius ?? false,
1810
+ cornerIsExternal: args.cornerIsExternal ?? false
1811
+ };
1812
+ const background = args.background ?? false;
1813
+ const backgroundOwn = isPlainObject(background) ? background : {};
1814
+ const key = keyOf(args.dataKey);
1815
+ return [{
1816
+ key,
1817
+ class: args.class ?? '',
1818
+ points: drawn.sectors.map(sector => {
1819
+ const point = polarToCartesian(sector.cx, sector.cy, (sector.innerRadius + sector.outerRadius) / 2, (sector.startAngle + sector.endAngle) / 2);
1820
+ return `${round(point.x)},${round(point.y)}`;
1821
+ }).join(' '),
1822
+ hasBackground: background !== false,
1823
+ background: background === false ? [] : drawn.sectors.filter(sector => sector.background).map(sector => ({
1824
+ d: sectorPath({
1825
+ ...sector.background,
1826
+ ...corners
1827
+ }),
1828
+ fill: backgroundOwn.fill ?? '#eee',
1829
+ class: backgroundOwn.class ?? ''
1830
+ })),
1831
+ sectors: drawn.sectors.map(sector => ({
1832
+ d: sectorPath({
1833
+ ...sector,
1834
+ ...corners
1835
+ }),
1836
+ fill: this.sectorFill(part, sector),
1837
+ fillOpacity: args.fillOpacity,
1838
+ stroke: args.stroke,
1839
+ strokeWidth: args.strokeWidth,
1840
+ index: sector.index,
1841
+ value: Array.isArray(sector.value) ? sector.value.join(',') : asText(sector.value)
1842
+ })),
1843
+ labels: part.labels.items.map((label, j) => {
1844
+ const labelArgs = label.args;
1845
+ const position = labelArgs.position ?? 'middle';
1846
+ const offset = labelArgs.offset ?? 5;
1847
+ return {
1848
+ key: `label-${j}`,
1849
+ class: labelArgs.class ?? '',
1850
+ fontSize: labelArgs.fontSize,
1851
+ items: drawn.sectors.map(sector => {
1852
+ const raw = labelArgs.dataKey !== undefined ? valueOf(sector.payload, labelArgs.dataKey) : Array.isArray(sector.value) ? sector.value[sector.value.length - 1] : sector.value;
1853
+ const shown = labelArgs.formatter ? labelArgs.formatter(raw) : raw;
1854
+ const item = {
1855
+ text: asText(shown),
1856
+ fill: labelArgs.fill ?? this.sectorFill(part, sector)
1857
+ };
1858
+ if (position === 'insideStart' || position === 'insideEnd' || position === 'end') {
1859
+ item.arc = {
1860
+ id: `${this.chartId}-radial-line-${++labelIds}`,
1861
+ d: radialLabelPath(sector, position, offset)
1862
+ };
1863
+ } else {
1864
+ const attrs = polarLabelAttrs(sector, offset, position);
1865
+ item.x = attrs.x;
1866
+ item.y = attrs.y;
1867
+ item.anchor = attrs.textAnchor;
1868
+ item.dy = attrs.dy;
1869
+ }
1870
+ return item;
1871
+ })
1872
+ };
1873
+ })
1874
+ }];
1875
+ });
1876
+ }
1877
+ static {
1878
+ n(this.prototype, "radialBars", [cached]);
1879
+ }
1880
+ get labelLists() {
1881
+ return this.radialBars.flatMap(bar => bar.labels.map(list => ({
1882
+ ...list,
1883
+ series: bar.key
1884
+ })));
1885
+ }
1886
+ // ---------------------------------------------------------------------------------------
1887
+ // Tooltip
1888
+ /** The pointer's radius and angle, while it is on the ring. */
1889
+ get pointerOnRing() {
1890
+ const viewBox = this.viewBox;
1891
+ const pointer = this.pointer;
1892
+ if (!viewBox || !pointer) return null;
1893
+ return inRangeOfSector(pointer, viewBox);
1894
+ }
1895
+ get activeIndex() {
1896
+ const geometry = this.geometry;
1897
+ const tooltip = this.tooltipPart;
1898
+ if (!geometry || !tooltip || tooltip.args.active === false) return null;
1899
+ if (this.pointer) {
1900
+ const ring = this.pointerOnRing;
1901
+ if (!ring) return null;
1902
+ const axis = geometry.tooltipAxis;
1903
+ const index = activeTickIndex(this.layout === 'centric' ? ring.angle : ring.radius, geometry.tooltipTicks, axis.axisType, axis.range);
1904
+ return index >= 0 ? index : null;
1905
+ }
1906
+ if (this.keyboardActive && this.keyboardIndex !== null) return this.keyboardIndex;
1907
+ if (isNumber$1(tooltip.args.defaultIndex) && this.keyboardIndex === null) return tooltip.args.defaultIndex;
1908
+ if (tooltip.args.active === true) return this.keyboardIndex ?? 0;
1909
+ return null;
1910
+ }
1911
+ get activeTick() {
1912
+ const index = this.activeIndex;
1913
+ if (index === null) return undefined;
1914
+ return this.geometry?.tooltipTicks.find(tick => tick.index === index);
1915
+ }
1916
+ get isTooltipActive() {
1917
+ return this.activeTick !== undefined && this.activeIndex < (this.args.data?.length ?? 0);
1918
+ }
1919
+ /**
1920
+ * Where the tooltip points: on the active row's spoke (a radar) or ring (a radial bar chart),
1921
+ * at the pointer. Without the pointer (the keyboard, `@defaultIndex`), at the first series'
1922
+ * point on that row, or the middle of its bar.
1923
+ */
1924
+ get activeCoordinate() {
1925
+ const geometry = this.geometry;
1926
+ const tick = this.activeTick;
1927
+ if (!geometry || !tick) return null;
1928
+ const {
1929
+ cx,
1930
+ cy,
1931
+ outerRadius,
1932
+ startAngle
1933
+ } = geometry.viewBox;
1934
+ const ring = this.pointerOnRing;
1935
+ if (this.pointer && ring) {
1936
+ return this.layout === 'centric' ? polarToCartesian(cx, cy, ring.radius, tick.coordinate) : polarToCartesian(cx, cy, tick.coordinate, ring.angle);
1937
+ }
1938
+ const radar = geometry.radars.find((_, i) => !this.radarParts[i]?.args.hide);
1939
+ const point = radar?.points[tick.index];
1940
+ if (point) return {
1941
+ x: point.x,
1942
+ y: point.y
1943
+ };
1944
+ const bar = geometry.radialBars.find((_, i) => !this.radialBarParts[i]?.args.hide);
1945
+ const sector = bar?.sectors.find(entry => entry.index === tick.index);
1946
+ if (sector) {
1947
+ return polarToCartesian(sector.cx, sector.cy, (sector.innerRadius + sector.outerRadius) / 2, (sector.startAngle + sector.endAngle) / 2);
1948
+ }
1949
+ return this.layout === 'centric' ? polarToCartesian(cx, cy, outerRadius, tick.coordinate) : polarToCartesian(cx, cy, tick.coordinate, startAngle);
1950
+ }
1951
+ /** What the tooltip's own arguments pass to its content; see CartesianChart's. */
1952
+ get tooltipProps() {
1953
+ const args = this.tooltipPart?.args;
1954
+ return {
1955
+ labelClassName: args?.labelClassName,
1956
+ labelFormatter: args?.labelFormatter,
1957
+ formatter: args?.formatter
1958
+ };
1959
+ }
1960
+ get tooltipCoordinate() {
1961
+ return this.activeCoordinate ?? undefined;
1962
+ }
1963
+ get tooltipPayload() {
1964
+ const tick = this.activeTick;
1965
+ const tooltip = this.tooltipPart;
1966
+ if (!tick || !tooltip) return [];
1967
+ const row = this.args.data?.[tick.index];
1968
+ if (row === undefined) return [];
1969
+ const filterNull = tooltip.args.filterNull ?? true;
1970
+ const items = [];
1971
+ for (const part of this.seriesParts) {
1972
+ const args = part.args;
1973
+ if (args.hide || args.tooltipType === 'none') continue;
1974
+ const value = valueOf(row, args.dataKey);
1975
+ if (filterNull && (value === null || value === undefined)) continue;
1976
+ items.push({
1977
+ name: args.name ?? keyOf(args.dataKey),
1978
+ value,
1979
+ dataKey: args.dataKey,
1980
+ // A radar's colour is its stroke, else its fill; a radial bar's, its fill.
1981
+ color: part instanceof Radar ? itemColor(args.stroke, args.fill) : args.fill,
1982
+ fill: args.fill,
1983
+ stroke: args.stroke,
1984
+ payload: row,
1985
+ type: args.tooltipType
1986
+ });
1987
+ }
1988
+ // recharts sorts the entries by name.
1989
+ return items.sort((a, b) => String(a.name) < String(b.name) ? -1 : String(a.name) > String(b.name) ? 1 : 0);
1990
+ }
1991
+ get tooltipLabel() {
1992
+ return this.activeTick?.value;
1993
+ }
1994
+ get tooltipContent() {
1995
+ return this.tooltipPart?.args.content ?? ChartTooltipContent;
1996
+ }
1997
+ get tooltipVisible() {
1998
+ return this.isTooltipActive && this.tooltipPayload.length > 0 && !!this.tooltipBox && this.tooltipBox.width > 0 && this.tooltipBox.height > 0;
1999
+ }
2000
+ get tooltipStyle() {
2001
+ const base = 'pointer-events: none; position: absolute; top: 0px; left: 0px;';
2002
+ const coordinate = this.activeCoordinate;
2003
+ const box = this.tooltipBox;
2004
+ const geometry = this.geometry;
2005
+ if (!this.tooltipVisible || !coordinate || !box || !geometry) {
2006
+ return htmlSafe(`visibility: hidden; ${base}`);
2007
+ }
2008
+ const tooltip = this.tooltipPart;
2009
+ const offset = tooltip.args.offset ?? 10;
2010
+ const {
2011
+ offset: plot
2012
+ } = geometry;
2013
+ const x = tooltipTranslate({
2014
+ coordinate: coordinate.x,
2015
+ offset,
2016
+ tooltipSize: box.width,
2017
+ viewBoxStart: plot.left,
2018
+ viewBoxSize: plot.width,
2019
+ allowEscape: false,
2020
+ reverse: false
2021
+ });
2022
+ const y = tooltipTranslate({
2023
+ coordinate: coordinate.y,
2024
+ offset,
2025
+ tooltipSize: box.height,
2026
+ viewBoxStart: plot.top,
2027
+ viewBoxSize: plot.height,
2028
+ allowEscape: false,
2029
+ reverse: false
2030
+ });
2031
+ const transition = tooltipTransition(tooltip.args.isAnimationActive);
2032
+ return htmlSafe(`visibility: visible; ${base}${transition} transform: translate(${x}px, ${y}px);`);
2033
+ }
2034
+ /** Measures the tooltip's box each time what it shows changes (its arguments). */
2035
+ measureTooltip = modifier((element, positional) => {
2036
+ void [...positional];
2037
+ const rect = {
2038
+ width: element.offsetWidth,
2039
+ height: element.offsetHeight
2040
+ };
2041
+ const current = this.#tooltipBox;
2042
+ if (!current || Math.abs(current.width - rect.width) > 1 || Math.abs(current.height - rect.height) > 1) {
2043
+ this.#tooltipBox = rect;
2044
+ this.tooltipBox = rect;
2045
+ }
2046
+ });
2047
+ /**
2048
+ * The cursor: a radar's spoke at the active row, or a radial bar chart's ring through the
2049
+ * active bar, as recharts draws them.
2050
+ */
2051
+ get cursor() {
2052
+ const tooltip = this.tooltipPart;
2053
+ const geometry = this.geometry;
2054
+ const tick = this.activeTick;
2055
+ if (!tooltip || !geometry || !tick || !this.isTooltipActive || tooltip.args.cursor === false) return null;
2056
+ const option = isObject(tooltip.args.cursor) ? tooltip.args.cursor : {};
2057
+ const {
2058
+ cx,
2059
+ cy,
2060
+ innerRadius,
2061
+ outerRadius,
2062
+ startAngle,
2063
+ endAngle
2064
+ } = geometry.viewBox;
2065
+ const stroke = option.stroke ?? '#ccc';
2066
+ if (this.layout === 'centric') {
2067
+ const inner = polarToCartesian(cx, cy, innerRadius, tick.coordinate);
2068
+ const outer = polarToCartesian(cx, cy, outerRadius, tick.coordinate);
2069
+ return {
2070
+ class: 'recharts-curve',
2071
+ d: `M${inner.x},${inner.y}L${outer.x},${outer.y}`,
2072
+ stroke,
2073
+ strokeWidth: option.strokeWidth ?? 1
2074
+ };
2075
+ }
2076
+ return {
2077
+ class: 'recharts-sector',
2078
+ d: sectorPath({
2079
+ cx,
2080
+ cy,
2081
+ innerRadius: tick.coordinate,
2082
+ outerRadius: tick.coordinate,
2083
+ startAngle,
2084
+ endAngle
2085
+ }),
2086
+ stroke,
2087
+ strokeWidth: option.strokeWidth ?? 1
2088
+ };
2089
+ }
2090
+ get activeDots() {
2091
+ const tick = this.activeTick;
2092
+ const geometry = this.geometry;
2093
+ if (!tick || !geometry || !this.isTooltipActive) return [];
2094
+ return this.radarParts.flatMap((part, i) => {
2095
+ const args = part.args;
2096
+ if (args.hide) return [];
2097
+ const point = geometry.radars[i].points[tick.index];
2098
+ if (!point) return [];
2099
+ const color = itemColor(args.stroke, args.fill) ?? 'none';
2100
+ return this.dotsFor(args.activeDot, true, {
2101
+ r: 4,
2102
+ fill: color,
2103
+ stroke: '#fff',
2104
+ strokeWidth: 2
2105
+ }, 'recharts-dot', [point], args.dataKey);
2106
+ });
2107
+ }
2108
+ // ---------------------------------------------------------------------------------------
2109
+ // Legend
2110
+ get legendPayload() {
2111
+ const items = [];
2112
+ for (const part of this.seriesParts) {
2113
+ const args = part.args;
2114
+ if (args.legendType === 'none') continue;
2115
+ if (part instanceof RadialBar) {
2116
+ // A radial bar chart's legend names each row, as recharts' does.
2117
+ for (const row of this.args.data ?? []) {
2118
+ items.push({
2119
+ value: asText(row['name']),
2120
+ dataKey: args.dataKey,
2121
+ color: isString(row['fill']) ? row['fill'] : args.fill,
2122
+ type: args.legendType ?? 'rect',
2123
+ payload: row
2124
+ });
2125
+ }
2126
+ continue;
2127
+ }
2128
+ items.push({
2129
+ value: args.name ?? keyOf(args.dataKey),
2130
+ dataKey: args.dataKey,
2131
+ color: itemColor(args.stroke, args.fill),
2132
+ type: args.legendType ?? 'rect',
2133
+ inactive: args.hide ?? false
2134
+ });
2135
+ }
2136
+ // recharts sorts the legend by value.
2137
+ return items.sort((a, b) => a.value < b.value ? -1 : a.value > b.value ? 1 : 0);
2138
+ }
2139
+ get legendVerticalAlign() {
2140
+ return this.legendPart?.args.verticalAlign ?? 'bottom';
2141
+ }
2142
+ get legendContent() {
2143
+ return this.legendPart?.args.content ?? ChartLegendContent;
2144
+ }
2145
+ get legendStyle() {
2146
+ const size = this.size;
2147
+ const legend = this.legendPart;
2148
+ const margin = this.margin;
2149
+ const layout = legend.args.layout ?? 'horizontal';
2150
+ const align = legend.args.align ?? 'center';
2151
+ const verticalAlign = legend.args.verticalAlign ?? 'bottom';
2152
+ const width = layout === 'horizontal' ? `${size.width - margin.left - margin.right}px` : 'auto';
2153
+ const box = this.legendBox ?? {
2154
+ width: 0,
2155
+ height: 0
2156
+ };
2157
+ const horizontal = align === 'center' && layout === 'vertical' ? `left: ${(size.width - box.width) / 2}px;` : align === 'right' ? `right: ${margin.right}px;` : `left: ${margin.left}px;`;
2158
+ const vertical = verticalAlign === 'middle' ? `top: ${(size.height - box.height) / 2}px;` : verticalAlign === 'bottom' ? `bottom: ${margin.bottom}px;` : `top: ${margin.top}px;`;
2159
+ return htmlSafe(`position: absolute; width: ${width}; height: auto; ${horizontal} ${vertical}`);
2160
+ }
2161
+ measureLegend = modifier(element => observeSize(this, element, ({
2162
+ width,
2163
+ height
2164
+ }) => {
2165
+ const current = this.#legendBox;
2166
+ if (!current || Math.abs(current.width - width) > 1 || Math.abs(current.height - height) > 1) {
2167
+ this.#legendBox = {
2168
+ width,
2169
+ height
2170
+ };
2171
+ this.legendBox = {
2172
+ width,
2173
+ height
2174
+ };
2175
+ }
2176
+ }));
2177
+ // ---------------------------------------------------------------------------------------
2178
+ // Events
2179
+ onMouseMove = event => {
2180
+ if (!this.geometry) return;
2181
+ const element = event.currentTarget;
2182
+ const rect = element.getBoundingClientRect();
2183
+ const scaleX = element.offsetWidth ? rect.width / element.offsetWidth : 1;
2184
+ const scaleY = element.offsetHeight ? rect.height / element.offsetHeight : 1;
2185
+ this.pointer = {
2186
+ x: (event.clientX - rect.left) / scaleX,
2187
+ y: (event.clientY - rect.top) / scaleY
2188
+ };
2189
+ };
2190
+ onMouseLeave = () => {
2191
+ this.pointer = null;
2192
+ };
2193
+ onFocus = () => {
2194
+ if (!this.accessibilityLayer || this.keyboardActive) return;
2195
+ if (this.keyboardIndex === null) this.keyboardIndex = 0;
2196
+ this.keyboardActive = true;
2197
+ };
2198
+ onBlur = () => {
2199
+ if (!this.accessibilityLayer) return;
2200
+ this.keyboardActive = false;
2201
+ };
2202
+ onKeyDown = event => {
2203
+ if (!this.accessibilityLayer) return;
2204
+ const {
2205
+ key
2206
+ } = event;
2207
+ if (key !== 'ArrowRight' && key !== 'ArrowLeft' && key !== 'Enter') return;
2208
+ const current = this.keyboardIndex ?? -1;
2209
+ if (current < 0) return;
2210
+ if (key === 'Enter') {
2211
+ this.keyboardActive = !this.keyboardActive;
2212
+ return;
2213
+ }
2214
+ // ArrowRight moves to the next row and ArrowLeft to the previous one, as recharts 3 does
2215
+ // in a polar chart (its direction there is always left to right).
2216
+ const next = current + (key === 'ArrowRight' ? 1 : -1);
2217
+ const count = this.geometry?.tooltipTicks.length ?? 0;
2218
+ if (next < 0 || next >= count) return;
2219
+ this.pointer = null;
2220
+ this.keyboardIndex = next;
2221
+ this.keyboardActive = true;
2222
+ };
2223
+ static {
2224
+ setComponentTemplate(precompileTemplate("{{#let (hash PolarGrid=(component PolarGrid chart=this) PolarAngleAxis=(component PolarAngleAxis chart=this) PolarRadiusAxis=(component PolarRadiusAxis chart=this) Radar=(component Radar chart=this) RadialBar=(component RadialBar chart=this) ChartTooltip=(component ChartTooltip chart=this) ChartLegend=(component ChartLegend chart=this)) as |parts|}}\n {{#if this.fixedSize}}\n {{#if this.size}}\n <Surface @chart={{this}} ...attributes>{{yield parts}}</Surface>\n {{/if}}\n {{else}}\n <div class=\"recharts-responsive-container\" style=\"width: 100%; height: 100%; min-width: 0px;\" {{this.measureContainer}}>\n <div style=\"width: 0px; height: 0px; overflow: visible;\">\n {{#if this.size}}\n <Surface @chart={{this}} ...attributes>{{yield parts}}</Surface>\n {{/if}}\n </div>\n </div>\n {{/if}}\n{{/let}}", {
2225
+ strictMode: true,
2226
+ scope: () => ({
2227
+ hash,
2228
+ PolarGrid,
2229
+ PolarAngleAxis,
2230
+ PolarRadiusAxis,
2231
+ Radar,
2232
+ RadialBar,
2233
+ ChartTooltip,
2234
+ ChartLegend,
2235
+ Surface
2236
+ })
2237
+ }), this);
2238
+ }
2239
+ }
2240
+
2241
+ export { PolarChart as P };
2242
+ //# sourceMappingURL=polar-chart-GhgOSsH9.js.map