@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,1123 @@
1
+ /*!
2
+ * @ember-joinery/chart ports recharts 3.8.0 (https://github.com/recharts/recharts): its tick
3
+ * selection, nice tick values, text measurement, cartesian, pie and polar layout, tooltip
4
+ * placement, and rectangle, sector and polygon paths.
5
+ *
6
+ * The MIT License (MIT). Copyright (c) 2015-present recharts
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9
+ * and associated documentation files (the "Software"), to deal in the Software without
10
+ * restriction, including without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
12
+ * Software is furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all copies or
15
+ * substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ import { isUndefined, isNumber, isObject, isString, isFunction } from '@sindresorhus/is';
24
+ import Component from '@glimmer/component';
25
+ import { tracked, cached } from '@glimmer/tracking';
26
+ import { hash } from '@ember/helper';
27
+ import { registerDestructor } from '@ember/destroyable';
28
+ import { on } from '@ember/modifier';
29
+ import { htmlSafe } from '@ember/template';
30
+ import { modifier } from 'ember-modifier';
31
+ import { idFor } from '@ember-joinery/primitives/id';
32
+ import { resizeObserver } from '@ember-joinery/primitives/resize-observer';
33
+ import { R as Registry, X as XAxis, Y as YAxis, b as CartesianGrid, C as ChartTooltip, a as ChartLegend, A as Area, B as Bar, L as Line, d as dotFor } from './parts-BWLhFFjB.js';
34
+ import { c as cartesianGeometry, v as valueOf, a as activeIndexAt, b as clearStringSizeCache, d as defaultAxis, t as tooltipTranslate, e as tooltipTransition } from './cartesian-D9hWDamz.js';
35
+ import { R as Rectangle, l as linePath, a as areaPath, r as rectanglePath } from './rectangle-Cl7tbXuZ.js';
36
+ import ChartTooltipContent from './components/chart-tooltip-content.js';
37
+ import ChartLegendContent from './components/chart-legend-content.js';
38
+ import { precompileTemplate } from '@ember/template-compilation';
39
+ import { setComponentTemplate } from '@ember/component';
40
+ import templateOnly from '@ember/component/template-only';
41
+ import { g, i, n } from 'decorator-transforms/runtime';
42
+
43
+ const INITIAL_DIMENSION = {
44
+ width: -1,
45
+ height: -1
46
+ };
47
+ const DEFAULT_MARGIN = {
48
+ top: 5,
49
+ right: 5,
50
+ bottom: 5,
51
+ left: 5
52
+ };
53
+ let seriesIds = 0;
54
+ const ids = new WeakMap();
55
+ function seriesId(part) {
56
+ let id = ids.get(part);
57
+ if (!id) ids.set(part, id = `series-${++seriesIds}`);
58
+ return id;
59
+ }
60
+ function num(value, fallback) {
61
+ return isNumber(value) && Number.isFinite(value) ? value : fallback;
62
+ }
63
+ function keyOf(dataKey) {
64
+ return isFunction(dataKey) ? '' : String(dataKey ?? '');
65
+ }
66
+ function round(value) {
67
+ return Math.round(value * 1000) / 1000;
68
+ }
69
+ /** A row's own `fill` (or its Cell's), where it has one. */
70
+ function entryFill(payload) {
71
+ const fill = payload?.['fill'];
72
+ return isString(fill) ? fill : undefined;
73
+ }
74
+ /** recharts' `getLegendItemColor`: the stroke, where there is one, else the fill. */
75
+ function itemColor(stroke, fill) {
76
+ return stroke && stroke !== 'none' ? stroke : fill;
77
+ }
78
+ /** Where a label sits against its point (a zero-size box) or bar, as recharts' Label places it. */
79
+ function labelPlacement(box, position, offset) {
80
+ const {
81
+ x,
82
+ y,
83
+ width,
84
+ height
85
+ } = box;
86
+ const vertical = height >= 0 ? 1 : -1;
87
+ const horizontal = width >= 0 ? 1 : -1;
88
+ const DY = {
89
+ start: '0.71em',
90
+ middle: '0.355em',
91
+ end: '0em'
92
+ };
93
+ switch (position) {
94
+ case 'top':
95
+ return {
96
+ x: x + width / 2,
97
+ y: y - vertical * offset,
98
+ anchor: 'middle',
99
+ dy: DY[vertical > 0 ? 'end' : 'start']
100
+ };
101
+ case 'bottom':
102
+ return {
103
+ x: x + width / 2,
104
+ y: y + height + vertical * offset,
105
+ anchor: 'middle',
106
+ dy: DY[vertical > 0 ? 'start' : 'end']
107
+ };
108
+ case 'left':
109
+ return {
110
+ x: x - horizontal * offset,
111
+ y: y + height / 2,
112
+ anchor: horizontal > 0 ? 'end' : 'start',
113
+ dy: DY.middle
114
+ };
115
+ case 'right':
116
+ return {
117
+ x: x + width + horizontal * offset,
118
+ y: y + height / 2,
119
+ anchor: horizontal > 0 ? 'start' : 'end',
120
+ dy: DY.middle
121
+ };
122
+ case 'insideLeft':
123
+ return {
124
+ x: x + horizontal * offset,
125
+ y: y + height / 2,
126
+ anchor: horizontal > 0 ? 'start' : 'end',
127
+ dy: DY.middle
128
+ };
129
+ case 'insideRight':
130
+ return {
131
+ x: x + width - horizontal * offset,
132
+ y: y + height / 2,
133
+ anchor: horizontal > 0 ? 'end' : 'start',
134
+ dy: DY.middle
135
+ };
136
+ case 'insideTop':
137
+ return {
138
+ x: x + width / 2,
139
+ y: y + vertical * offset,
140
+ anchor: 'middle',
141
+ dy: DY[vertical > 0 ? 'start' : 'end']
142
+ };
143
+ case 'insideBottom':
144
+ return {
145
+ x: x + width / 2,
146
+ y: y + height - vertical * offset,
147
+ anchor: 'middle',
148
+ dy: DY[vertical > 0 ? 'end' : 'start']
149
+ };
150
+ default:
151
+ return {
152
+ x: x + width / 2,
153
+ y: y + height / 2,
154
+ anchor: 'middle',
155
+ dy: DY.middle
156
+ };
157
+ }
158
+ }
159
+ /**
160
+ * Calls `callback` with an element's size now, then on every resize, until it is removed. The
161
+ * size is the element's layout size (`offsetWidth`, as a ResizeObserver reports it), not its
162
+ * box on screen, which a CSS transform scales.
163
+ */
164
+ function observeSize(context, element, callback) {
165
+ callback({
166
+ width: element.offsetWidth,
167
+ height: element.offsetHeight
168
+ });
169
+ const observer = resizeObserver(context);
170
+ const onEntry = entry => callback({
171
+ width: entry.contentRect.width,
172
+ height: entry.contentRect.height
173
+ });
174
+ observer.observe(element, onEntry);
175
+ return () => observer.unobserve(element, onEntry);
176
+ }
177
+ /**
178
+ * Where recharts' tooltip box goes: beside the point it shows (`coordinate`), kept inside the
179
+ * plot area, and hidden until it has been measured.
180
+ */
181
+ function tooltipStyleFor(options) {
182
+ const {
183
+ visible,
184
+ coordinate,
185
+ box,
186
+ plot,
187
+ tooltip
188
+ } = options;
189
+ const base = 'pointer-events: none; position: absolute; top: 0px; left: 0px;';
190
+ if (!visible || !coordinate || !box || !plot || !tooltip) {
191
+ return htmlSafe(`visibility: hidden; ${base}`);
192
+ }
193
+ const offset = num(tooltip.args.offset, 10);
194
+ const x = tooltipTranslate({
195
+ coordinate: coordinate.x,
196
+ offset,
197
+ tooltipSize: box.width,
198
+ viewBoxStart: plot.left,
199
+ viewBoxSize: plot.width,
200
+ allowEscape: false,
201
+ reverse: false
202
+ });
203
+ const y = tooltipTranslate({
204
+ coordinate: coordinate.y,
205
+ offset,
206
+ tooltipSize: box.height,
207
+ viewBoxStart: plot.top,
208
+ viewBoxSize: plot.height,
209
+ allowEscape: false,
210
+ reverse: false
211
+ });
212
+ const transition = tooltipTransition(tooltip.args.isAnimationActive);
213
+ return htmlSafe(`visibility: visible; ${base}${transition} transform: translate(${x}px, ${y}px);`);
214
+ }
215
+ /** Where recharts' legend box goes: across the chart's foot (or wherever its arguments put it). */
216
+ function legendStyleFor(size, margin, legend, measured) {
217
+ const layout = legend.args.layout ?? 'horizontal';
218
+ const align = legend.args.align ?? 'center';
219
+ const verticalAlign = legend.args.verticalAlign ?? 'bottom';
220
+ const width = layout === 'horizontal' ? `${size.width - margin.left - margin.right}px` : 'auto';
221
+ const box = measured ?? {
222
+ width: 0,
223
+ height: 0
224
+ };
225
+ const horizontal = align === 'center' && layout === 'vertical' ? `left: ${(size.width - box.width) / 2}px;` : align === 'right' ? `right: ${margin.right}px;` : `left: ${margin.left}px;`;
226
+ const vertical = verticalAlign === 'middle' ? `top: ${(size.height - box.height) / 2}px;` : verticalAlign === 'bottom' ? `bottom: ${margin.bottom}px;` : `top: ${margin.top}px;`;
227
+ return htmlSafe(`position: absolute; width: ${width}; height: auto; ${horizontal} ${vertical}`);
228
+ }
229
+ /**
230
+ * The chart itself, at its size: recharts' wrapper, its `<svg>` with the marks in recharts'
231
+ * z-index layers, and the legend and tooltip boxes over it.
232
+ */
233
+ 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}} {{on \"mousemove\" @chart.onMouseMove}} {{on \"mouseleave\" @chart.onMouseLeave}} ...attributes>\n <svg class=\"recharts-surface\" width={{@chart.width}} height={{@chart.height}} viewBox={{@chart.viewBox}} 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: a part the block adds (inside an if, say) writes\n the registry, and Glimmer forbids writing tracked state the same render has read. So\n everything that reads them, the categories attribute included, comes after it.\n --}}\n {{yield}}\n {{#if @chart.geometry}}\n <g class=\"recharts-zIndex-layer_-100\">\n {{#if @chart.grid}}\n <g class=\"recharts-cartesian-grid\" data-test-jn-part=\"grid\">\n {{#if @chart.grid.horizontal.length}}\n <g class=\"recharts-cartesian-grid-horizontal\">\n {{#each @chart.grid.horizontal as |gridLine|}}\n <line stroke={{gridLine.stroke}} fill=\"none\" stroke-dasharray={{gridLine.dash}} x1={{gridLine.x1}} y1={{gridLine.y1}} x2={{gridLine.x2}} y2={{gridLine.y2}} data-test-jn-part=\"grid-line\" data-test-jn-value=\"horizontal\"></line>\n {{/each}}\n </g>\n {{/if}}\n {{#if @chart.grid.vertical.length}}\n <g class=\"recharts-cartesian-grid-vertical\">\n {{#each @chart.grid.vertical as |gridLine|}}\n <line stroke={{gridLine.stroke}} fill=\"none\" stroke-dasharray={{gridLine.dash}} x1={{gridLine.x1}} y1={{gridLine.y1}} x2={{gridLine.x2}} y2={{gridLine.y2}} data-test-jn-part=\"grid-line\" data-test-jn-value=\"vertical\"></line>\n {{/each}}\n </g>\n {{/if}}\n </g>\n {{/if}}\n </g>\n <defs>\n <clipPath id={{@chart.clipId}}>\n <rect data-test-jn-part=\"plot\" data-test-jn-categories={{@chart.categoryCoordinates}} 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.areas as |area|}}\n <g class=\"recharts-layer recharts-area\" data-test-jn-part=\"series\" data-test-jn-value={{area.key}} data-series-type=\"area\" data-test-jn-points={{area.points}}>\n <g class=\"recharts-layer\">\n {{#if area.areaPath}}\n <path class=\"recharts-curve recharts-area-area\" stroke-width={{area.strokeWidth}} fill={{area.fill}} fill-opacity={{area.fillOpacity}} stroke=\"none\" d={{area.areaPath}}></path>\n {{/if}}\n {{#if area.curvePath}}\n <path class=\"recharts-curve recharts-area-curve\" stroke-width={{area.strokeWidth}} fill=\"none\" stroke={{area.stroke}} stroke-dasharray={{area.strokeDasharray}} d={{area.curvePath}}></path>\n {{/if}}\n </g>\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_200\">\n {{#if @chart.cursor.isRectangle}}\n <path class=\"recharts-rectangle recharts-tooltip-cursor\" stroke=\"none\" fill={{@chart.cursor.fill}} pointer-events=\"none\" d={{@chart.cursor.d}} data-test-jn-part=\"cursor\"></path>\n {{/if}}\n </g>\n <g class=\"recharts-zIndex-layer_300\">\n {{#each @chart.bars as |bar|}}\n <g class=\"recharts-layer recharts-bar\" data-test-jn-part=\"series\" data-test-jn-value={{bar.key}} data-series-type=\"bar\" data-test-jn-points={{bar.points}}>\n <g class=\"recharts-layer recharts-bar-rectangles\">\n <g class=\"recharts-layer\">\n {{#each bar.bars as |rectangle|}}\n <g class=\"recharts-layer recharts-bar-rectangle\">\n <g class=\"recharts-layer recharts-inactive-bar\">\n {{#if bar.shape}}\n {{#let bar.shape as |Shape|}}\n <Shape @props={{rectangle}} @index={{rectangle.index}} />\n {{/let}}\n {{else}}\n <Rectangle @props={{rectangle}} />\n {{/if}}\n </g>\n </g>\n {{/each}}\n </g>\n </g>\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_400\">\n {{#each @chart.lines as |lineSeries|}}\n <g class=\"recharts-layer recharts-line\" data-test-jn-part=\"series\" data-test-jn-value={{lineSeries.key}} data-series-type=\"line\" data-test-jn-points={{lineSeries.points}}>\n <g class=\"recharts-layer recharts-shape\">\n {{#if lineSeries.curvePath}}\n <path class=\"recharts-curve recharts-line-curve\" stroke={{lineSeries.stroke}} stroke-width={{lineSeries.strokeWidth}} stroke-dasharray={{lineSeries.strokeDasharray}} fill=\"none\" d={{lineSeries.curvePath}}></path>\n {{/if}}\n </g>\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_500\">\n {{#each @chart.axes as |axis|}}\n <g class=\"recharts-layer recharts-cartesian-axis recharts-{{axis.kind}} {{axis.kind}}\" data-test-jn-part={{axis.kind}}>\n {{#if axis.line}}\n <line class=\"recharts-cartesian-axis-line\" stroke={{axis.line.stroke}} fill=\"none\" x1={{axis.line.x1}} y1={{axis.line.y1}} x2={{axis.line.x2}} y2={{axis.line.y2}}></line>\n {{/if}}\n <g class=\"recharts-cartesian-axis-ticks recharts-{{axis.kind}}-ticks\">\n <g class=\"recharts-cartesian-axis-tick-lines recharts-{{axis.kind}}-tick-lines\">\n {{#each axis.ticks as |tick|}}\n <g class=\"recharts-layer recharts-cartesian-axis-tick\">\n {{#if tick.tickLine}}\n <line class=\"recharts-cartesian-axis-tick-line\" stroke={{tick.tickLine.stroke}} fill=\"none\" x1={{tick.tickLine.x1}} y1={{tick.tickLine.y1}} x2={{tick.tickLine.x2}} y2={{tick.tickLine.y2}}></line>\n {{/if}}\n </g>\n {{/each}}\n </g>\n </g>\n </g>\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_600\">\n {{#each @chart.series as |series|}}\n {{#if series.dots.length}}\n <g class=\"recharts-layer recharts-{{series.type}}-dots\" data-test-jn-part=\"dots\" data-test-jn-value={{series.key}}>\n {{#each series.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 class=\"recharts-dot recharts-{{series.type}}-dot {{dot.attrs.class}}\" r={{dot.attrs.r}} stroke={{dot.attrs.stroke}} stroke-width={{dot.attrs.strokeWidth}} fill={{dot.attrs.fill}} cx={{dot.args.cx}} cy={{dot.args.cy}}></circle>\n {{/if}}\n {{/each}}\n </g>\n {{/if}}\n {{/each}}\n </g>\n <g class=\"recharts-zIndex-layer_1100\">\n {{#if @chart.cursor.isCurve}}\n <path class=\"recharts-curve 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=\"recharts-dot {{dot.attrs.class}}\" cx={{dot.args.cx}} cy={{dot.args.cy}} r={{dot.attrs.r}} fill={{dot.attrs.fill}} 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.axes as |axis|}}\n {{#if axis.showLabels}}\n <g class=\"recharts-cartesian-axis-tick-labels recharts-{{axis.kind}}-tick-labels\" data-test-jn-part=\"{{axis.kind}}-labels\" {{@chart.measureTicks axis.axisKey axis.ticks.length}}>\n {{#each axis.ticks as |tick|}}\n <g class=\"recharts-layer recharts-cartesian-axis-tick-label\">\n <text class=\"recharts-text recharts-cartesian-axis-tick-value\" stroke=\"none\" x={{tick.label.x}} y={{tick.label.y}} text-anchor={{axis.textAnchor}} fill={{axis.fill}} data-test-jn-part=\"tick\"><tspan x={{tick.label.x}} dy={{axis.dy}}>{{tick.text}}</tspan></text>\n </g>\n {{/each}}\n </g>\n {{/if}}\n {{/each}}\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 <text class={{list.class}} x={{item.x}} y={{item.y}} text-anchor={{item.anchor}} fill={{item.fill}} fill-opacity={{list.fillOpacity}} stroke={{list.stroke}} font-size={{list.fontSize}} data-test-jn-part=\"label\"><tspan x={{item.x}} dy={{item.dy}}>{{item.text}}</tspan></text>\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 {{!-- The legend's @class goes to its content only when given, so it can't override a\n class curried into the content. --}}\n {{#if @chart.legendPart.args.class}}\n <Content @payload={{@chart.legendPayload}} @verticalAlign={{@chart.legendVerticalAlign}} @config={{@chart.args.config}} @class={{@chart.legendPart.args.class}} />\n {{else}}\n <Content @payload={{@chart.legendPayload}} @verticalAlign={{@chart.legendVerticalAlign}} @config={{@chart.args.config}} />\n {{/if}}\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>", {
234
+ strictMode: true,
235
+ scope: () => ({
236
+ on,
237
+ Rectangle
238
+ })
239
+ }), templateOnly());
240
+ class CartesianChart extends Component {
241
+ #parts = new Registry();
242
+ chartId = idFor(this, 'chart');
243
+ static {
244
+ g(this.prototype, "containerSize", [tracked], function () {
245
+ return null;
246
+ });
247
+ }
248
+ #containerSize_ = (i(this, "containerSize"), void 0);
249
+ static {
250
+ g(this.prototype, "tickStyles", [tracked], function () {
251
+ return {
252
+ x: {},
253
+ y: {}
254
+ };
255
+ });
256
+ }
257
+ #tickStyles_ = (i(this, "tickStyles"), void 0);
258
+ static {
259
+ g(this.prototype, "legendBox", [tracked], function () {
260
+ return null;
261
+ });
262
+ }
263
+ #legendBox_ = (i(this, "legendBox"), void 0);
264
+ static {
265
+ g(this.prototype, "tooltipBox", [tracked], function () {
266
+ return null;
267
+ });
268
+ }
269
+ #tooltipBox_ = (i(this, "tooltipBox"), void 0);
270
+ static {
271
+ g(this.prototype, "pointer", [tracked], function () {
272
+ return null;
273
+ });
274
+ }
275
+ #pointer = (i(this, "pointer"), void 0);
276
+ /** The pointer, in the chart's pixels, while it is over the plot area. */
277
+ static {
278
+ g(this.prototype, "keyboardIndex", [tracked], function () {
279
+ return null;
280
+ });
281
+ }
282
+ #keyboardIndex = (i(this, "keyboardIndex"), void 0);
283
+ static {
284
+ g(this.prototype, "keyboardActive", [tracked], function () {
285
+ return false;
286
+ });
287
+ }
288
+ #keyboardActive = (i(this, "keyboardActive"), void 0);
289
+ static {
290
+ g(this.prototype, "fontRevision", [tracked], function () {
291
+ return 0;
292
+ });
293
+ }
294
+ #fontRevision = (i(this, "fontRevision"), void 0);
295
+ /** Bumped when the page's fonts finish loading, which changes how wide tick labels are. */
296
+ constructor(owner, args) {
297
+ super(owner, args);
298
+ // Tick labels are measured to drop those that would overlap, and a web font that loads
299
+ // after the first render changes their size: measure again once it has.
300
+ const fonts = !isUndefined(globalThis.document) ? document.fonts : undefined;
301
+ if (fonts?.addEventListener) {
302
+ const onFontsLoaded = () => {
303
+ clearStringSizeCache();
304
+ this.fontRevision += 1;
305
+ };
306
+ fonts.addEventListener('loadingdone', onFontsLoaded);
307
+ registerDestructor(this, () => fonts.removeEventListener('loadingdone', onFontsLoaded));
308
+ }
309
+ }
310
+ register(part) {
311
+ this.#parts.add(part);
312
+ }
313
+ unregister(part) {
314
+ this.#parts.remove(part);
315
+ }
316
+ // ---------------------------------------------------------------------------------------
317
+ // Size
318
+ get fixedSize() {
319
+ return isNumber(this.args.width) && isNumber(this.args.height);
320
+ }
321
+ get size() {
322
+ if (this.fixedSize) return {
323
+ width: this.args.width,
324
+ height: this.args.height
325
+ };
326
+ const measured = this.containerSize;
327
+ const size = measured ?? this.args.initialDimension ?? INITIAL_DIMENSION;
328
+ if (!(size.width > 0) || !(size.height > 0)) return null;
329
+ return size;
330
+ }
331
+ // The measurements below compare with untracked copies: a modifier that read the tracked
332
+ // value it sets would run again each time it set it.
333
+ #containerSize = null;
334
+ #legendBox = null;
335
+ #tooltipBox = null;
336
+ #tickStyles = {
337
+ x: {},
338
+ y: {}
339
+ };
340
+ measureContainer = modifier(element => observeSize(this, element, ({
341
+ width,
342
+ height
343
+ }) => {
344
+ const next = {
345
+ width: Math.round(width),
346
+ height: Math.round(height)
347
+ };
348
+ const current = this.#containerSize;
349
+ if (!current || current.width !== next.width || current.height !== next.height) {
350
+ this.#containerSize = next;
351
+ this.containerSize = next;
352
+ }
353
+ }));
354
+ // ---------------------------------------------------------------------------------------
355
+ // Parts
356
+ get partList() {
357
+ return this.#parts.items;
358
+ }
359
+ get xAxisPart() {
360
+ return this.partList.find(part => part instanceof XAxis);
361
+ }
362
+ get yAxisPart() {
363
+ return this.partList.find(part => part instanceof YAxis);
364
+ }
365
+ get gridPart() {
366
+ return this.partList.find(part => part instanceof CartesianGrid);
367
+ }
368
+ get tooltipPart() {
369
+ return this.partList.find(part => part instanceof ChartTooltip);
370
+ }
371
+ get legendPart() {
372
+ return this.partList.find(part => part instanceof ChartLegend);
373
+ }
374
+ get seriesParts() {
375
+ return this.partList.filter(part => part instanceof Area || part instanceof Bar || part instanceof Line);
376
+ }
377
+ get layout() {
378
+ return this.args.layout ?? 'horizontal';
379
+ }
380
+ get chartName() {
381
+ return this.args.chartName ?? 'ComposedChart';
382
+ }
383
+ get margin() {
384
+ const margin = this.args.margin;
385
+ if (!margin) return DEFAULT_MARGIN;
386
+ return {
387
+ top: margin.top ?? 0,
388
+ right: margin.right ?? 0,
389
+ bottom: margin.bottom ?? 0,
390
+ left: margin.left ?? 0
391
+ };
392
+ }
393
+ axisSettings(part, axis) {
394
+ const settings = defaultAxis(axis, !part);
395
+ if (!part) {
396
+ // recharts' implicit axes: a hidden category x-axis and a hidden number y-axis, swapped in
397
+ // a vertical chart.
398
+ if (this.layout === 'vertical') settings.type = axis === 'x' ? 'number' : 'category';
399
+ return settings;
400
+ }
401
+ const args = part.args;
402
+ const padding = args.padding;
403
+ return {
404
+ ...settings,
405
+ dataKey: args.dataKey,
406
+ type: args.type ?? (this.layout === 'vertical' ? axis === 'x' ? 'number' : 'category' : settings.type),
407
+ hide: args.hide ?? false,
408
+ height: num(args.height, settings.height),
409
+ width: num(args.width, settings.width),
410
+ orientation: args.orientation ?? settings.orientation,
411
+ mirror: args.mirror ?? false,
412
+ reversed: args.reversed ?? false,
413
+ padding: axis === 'x' ? {
414
+ start: padding?.left ?? 0,
415
+ end: padding?.right ?? 0
416
+ } : {
417
+ start: padding?.top ?? 0,
418
+ end: padding?.bottom ?? 0
419
+ },
420
+ domain: args.domain,
421
+ allowDataOverflow: args.allowDataOverflow ?? false,
422
+ allowDecimals: args.allowDecimals ?? true,
423
+ tickCount: num(args.tickCount, settings.tickCount),
424
+ ticks: args.ticks,
425
+ tick: args.tick ?? true,
426
+ tickLine: args.tickLine ?? true,
427
+ axisLine: args.axisLine ?? true,
428
+ tickSize: num(args.tickSize, settings.tickSize),
429
+ tickMargin: num(args.tickMargin, settings.tickMargin),
430
+ minTickGap: num(args.minTickGap, settings.minTickGap),
431
+ interval: args.interval ?? settings.interval,
432
+ tickFormatter: args.tickFormatter,
433
+ unit: args.unit,
434
+ angle: num(args.angle, 0),
435
+ stroke: args.stroke ?? settings.stroke,
436
+ scale: args.scale ?? 'auto'
437
+ };
438
+ }
439
+ seriesSettings(part) {
440
+ const args = part.args;
441
+ return {
442
+ id: seriesId(part),
443
+ type: part.kind,
444
+ dataKey: args.dataKey,
445
+ name: args.name,
446
+ stackId: args.stackId,
447
+ hide: args.hide ?? false,
448
+ baseValue: part instanceof Area ? part.args.baseValue : undefined,
449
+ barSize: part instanceof Bar ? part.args.barSize : undefined,
450
+ maxBarSize: part instanceof Bar ? part.args.maxBarSize : undefined,
451
+ hasCustomShape: part instanceof Bar && part.args.shape !== undefined
452
+ };
453
+ }
454
+ // ---------------------------------------------------------------------------------------
455
+ // Layout
456
+ get geometry() {
457
+ void this.fontRevision;
458
+ const size = this.size;
459
+ if (!size) return null;
460
+ const legend = this.legendPart;
461
+ return cartesianGeometry({
462
+ chartName: this.chartName,
463
+ layout: this.layout,
464
+ width: size.width,
465
+ height: size.height,
466
+ margin: this.margin,
467
+ data: this.args.data ?? [],
468
+ xAxis: this.axisSettings(this.xAxisPart, 'x'),
469
+ yAxis: this.axisSettings(this.yAxisPart, 'y'),
470
+ series: this.seriesParts.map(part => this.seriesSettings(part)),
471
+ stackOffset: this.args.stackOffset ?? 'none',
472
+ barCategoryGap: this.args.barCategoryGap ?? '10%',
473
+ barGap: this.args.barGap ?? 4,
474
+ barSize: this.args.barSize,
475
+ maxBarSize: this.args.maxBarSize,
476
+ legend: legend && this.legendBox ? {
477
+ ...this.legendBox,
478
+ verticalAlign: legend.args.verticalAlign ?? 'bottom',
479
+ align: legend.args.align ?? 'center',
480
+ layout: legend.args.layout ?? 'horizontal'
481
+ } : undefined,
482
+ tickStyle: this.tickStyles,
483
+ measure: !isUndefined(globalThis.document)
484
+ });
485
+ }
486
+ /** Where each row sits along the category axis, for the harness to point at. */
487
+ static {
488
+ n(this.prototype, "geometry", [cached]);
489
+ }
490
+ get categoryCoordinates() {
491
+ return (this.geometry?.categoryTicks ?? []).map(tick => round(tick.coordinate)).join(' ');
492
+ }
493
+ get width() {
494
+ return this.size?.width ?? 0;
495
+ }
496
+ get height() {
497
+ return this.size?.height ?? 0;
498
+ }
499
+ get viewBox() {
500
+ const size = this.size;
501
+ return `0 0 ${size.width} ${size.height}`;
502
+ }
503
+ get wrapperStyle() {
504
+ const size = this.size;
505
+ return htmlSafe(`position: relative; cursor: default; width: ${size.width}px; height: ${size.height}px;`);
506
+ }
507
+ get clipId() {
508
+ return `${this.chartId}-clip`;
509
+ }
510
+ get accessibilityLayer() {
511
+ return this.args.accessibilityLayer ?? true;
512
+ }
513
+ // ---------------------------------------------------------------------------------------
514
+ // Drawing
515
+ get grid() {
516
+ const part = this.gridPart;
517
+ const geometry = this.geometry;
518
+ if (!part || !geometry) return null;
519
+ const {
520
+ offset
521
+ } = geometry;
522
+ const args = part.args;
523
+ const common = {
524
+ stroke: args.stroke ?? '#ccc',
525
+ dash: args.strokeDasharray
526
+ };
527
+ return {
528
+ horizontal: args.horizontal === false ? [] : geometry.grid.horizontal.map(y => ({
529
+ ...common,
530
+ x1: offset.left,
531
+ y1: y,
532
+ x2: offset.left + offset.width,
533
+ y2: y
534
+ })),
535
+ vertical: args.vertical === false ? [] : geometry.grid.vertical.map(x => ({
536
+ ...common,
537
+ x1: x,
538
+ y1: offset.top,
539
+ x2: x,
540
+ y2: offset.top + offset.height
541
+ }))
542
+ };
543
+ }
544
+ drawAxis(axis, kind) {
545
+ const settings = axis.settings;
546
+ if (settings.hide) return null;
547
+ return {
548
+ kind,
549
+ axisKey: kind === 'xAxis' ? 'x' : 'y',
550
+ settings,
551
+ line: settings.axisLine ? {
552
+ ...axis.line,
553
+ stroke: settings.stroke,
554
+ fill: 'none'
555
+ } : null,
556
+ ticks: axis.ticks.map(tick => ({
557
+ ...tick,
558
+ tickLine: settings.tickLine ? {
559
+ ...tick.line,
560
+ stroke: settings.stroke,
561
+ fill: 'none'
562
+ } : null
563
+ })),
564
+ showLabels: settings.tick,
565
+ textAnchor: axis.textAnchor,
566
+ dy: axis.dy,
567
+ fill: settings.stroke
568
+ };
569
+ }
570
+ get axes() {
571
+ const geometry = this.geometry;
572
+ if (!geometry) return [];
573
+ return [this.drawAxis(geometry.xAxis, 'xAxis'), this.drawAxis(geometry.yAxis, 'yAxis')].filter(axis => axis !== null);
574
+ }
575
+ drawLabels(part, geometry, bars) {
576
+ return part.labels.items.map((label, i) => {
577
+ const args = label.args;
578
+ const offset = num(args.offset, 5);
579
+ const position = args.position ?? (part instanceof Bar ? 'center' : 'top');
580
+ // A bar's label takes the bar's own fill (its row's or its Cell's), as recharts' does; a
581
+ // point's has none. Without one, recharts' Text is grey.
582
+ const boxes = part instanceof Bar ? geometry.bars.map((bar, index) => ({
583
+ box: bar,
584
+ payload: bar.payload,
585
+ value: bar.value,
586
+ fill: entryFill(bars[index]?.payload)
587
+ })) : geometry.points.filter(point => point.x !== null && point.y !== null).map(point => ({
588
+ box: {
589
+ x: point.x,
590
+ y: point.y,
591
+ width: 0,
592
+ height: 0
593
+ },
594
+ payload: point.payload,
595
+ value: point.value,
596
+ fill: undefined
597
+ }));
598
+ return {
599
+ key: `label-${i}`,
600
+ // recharts' Label is `recharts-label` unless given a class, which replaces it.
601
+ class: `recharts-text ${args.class ?? 'recharts-label'}`,
602
+ fillOpacity: args.fillOpacity,
603
+ stroke: args.stroke,
604
+ fontSize: args.fontSize,
605
+ items: boxes.map(({
606
+ box,
607
+ payload,
608
+ value,
609
+ fill
610
+ }) => {
611
+ const raw = args.dataKey !== undefined ? valueOf(payload, args.dataKey) : value;
612
+ const shown = args.formatter ? args.formatter(raw) : raw;
613
+ return {
614
+ ...labelPlacement(box, position, offset),
615
+ text: String(shown ?? ''),
616
+ fill: args.fill ?? fill ?? '#808080'
617
+ };
618
+ })
619
+ };
620
+ });
621
+ }
622
+ get series() {
623
+ const geometry = this.geometry;
624
+ if (!geometry) return [];
625
+ return this.seriesParts.map((part, i) => {
626
+ const drawn = geometry.series[i];
627
+ const settings = drawn.settings;
628
+ const key = keyOf(settings.dataKey);
629
+ const base = {
630
+ id: settings.id,
631
+ type: part.kind,
632
+ key,
633
+ name: settings.name ?? key,
634
+ points: drawn.points.filter(point => point.x !== null && point.y !== null).map(point => `${round(point.x)},${round(point.y)}`).join(' '),
635
+ bars: [],
636
+ dots: [],
637
+ labels: []
638
+ };
639
+ if (settings.hide) return base;
640
+ if (part instanceof Bar) {
641
+ const args = part.args;
642
+ const cells = part.cells.items;
643
+ // Each bar is the bar's attributes, then its row's (a `fill` in the data) and its
644
+ // Cell's over them, as recharts spreads the row and the cell over the bar's props.
645
+ const bars = drawn.bars.map(bar => {
646
+ const payload = {
647
+ ...bar.payload,
648
+ ...cells[bar.index]?.attributes
649
+ };
650
+ return {
651
+ x: bar.x,
652
+ y: bar.y,
653
+ width: bar.width,
654
+ height: bar.height,
655
+ radius: args.radius ?? 0,
656
+ fill: entryFill(payload) ?? args.fill,
657
+ fillOpacity: payload['fillOpacity'] ?? args.fillOpacity,
658
+ stroke: payload['stroke'] ?? args.stroke,
659
+ strokeWidth: payload['strokeWidth'] ?? args.strokeWidth,
660
+ index: bar.index,
661
+ value: bar.value,
662
+ payload,
663
+ dataKey: settings.dataKey,
664
+ // Without recharts' `activeBar`, which Joinery doesn't have, a bar is never active.
665
+ isActive: false
666
+ };
667
+ });
668
+ return {
669
+ ...base,
670
+ points: drawn.bars.map(bar => `${round(bar.x)},${round(bar.y)}`).join(' '),
671
+ fill: args.fill,
672
+ bars,
673
+ shape: args.shape,
674
+ labels: this.drawLabels(part, drawn, bars)
675
+ };
676
+ }
677
+ base.labels = this.drawLabels(part, drawn, []);
678
+ const curveType = part.args.type ?? 'linear';
679
+ const connectNulls = part.args.connectNulls ?? false;
680
+ const curvePath = linePath(drawn.points, curveType, this.layout, connectNulls);
681
+ if (part instanceof Area) {
682
+ const args = part.args;
683
+ const fill = args.fill ?? '#3182bd';
684
+ const stroke = args.stroke ?? '#3182bd';
685
+ const strokeWidth = args.strokeWidth ?? 1;
686
+ return {
687
+ ...base,
688
+ areaPath: areaPath(drawn.points, drawn.base, curveType, this.layout, connectNulls),
689
+ curvePath,
690
+ fill,
691
+ fillOpacity: args.fillOpacity ?? 0.6,
692
+ stroke,
693
+ strokeWidth,
694
+ strokeDasharray: args.strokeDasharray,
695
+ dots: this.dots(args.dot, false, drawn, {
696
+ r: 3,
697
+ fill: '#fff',
698
+ stroke,
699
+ strokeWidth: String(strokeWidth)
700
+ })
701
+ };
702
+ }
703
+ const args = part.args;
704
+ const stroke = args.stroke ?? '#3182bd';
705
+ const strokeWidth = args.strokeWidth ?? 1;
706
+ return {
707
+ ...base,
708
+ curvePath,
709
+ stroke,
710
+ strokeWidth,
711
+ strokeDasharray: args.strokeDasharray,
712
+ fill: args.fill ?? '#fff',
713
+ dots: this.dots(args.dot, true, drawn, {
714
+ r: 3,
715
+ fill: args.fill ?? '#fff',
716
+ stroke,
717
+ strokeWidth: String(strokeWidth)
718
+ })
719
+ };
720
+ });
721
+ }
722
+ static {
723
+ n(this.prototype, "series", [cached]);
724
+ }
725
+ dots(option, fallback, drawn, defaults) {
726
+ const result = [];
727
+ for (const point of drawn.points) {
728
+ if (point.x === null || point.y === null) continue;
729
+ const dot = dotFor(option, fallback, defaults, {
730
+ cx: point.x,
731
+ cy: point.y,
732
+ r: defaults.r,
733
+ index: point.index,
734
+ value: point.value,
735
+ payload: point.payload,
736
+ dataKey: drawn.settings.dataKey,
737
+ stroke: defaults.stroke,
738
+ strokeWidth: defaults.strokeWidth,
739
+ fill: defaults.fill
740
+ });
741
+ if (dot) result.push(dot);
742
+ }
743
+ return result;
744
+ }
745
+ get areas() {
746
+ return this.series.filter(series => series.type === 'area');
747
+ }
748
+ get bars() {
749
+ return this.series.filter(series => series.type === 'bar');
750
+ }
751
+ get lines() {
752
+ return this.series.filter(series => series.type === 'line');
753
+ }
754
+ get labelLists() {
755
+ return this.series.flatMap(series => series.labels.map(list => ({
756
+ ...list,
757
+ series: series.key
758
+ })));
759
+ }
760
+ // ---------------------------------------------------------------------------------------
761
+ // Tooltip
762
+ get activeIndex() {
763
+ const geometry = this.geometry;
764
+ const tooltip = this.tooltipPart;
765
+ if (!geometry || !tooltip || tooltip.args.active === false) return null;
766
+ const pointer = this.pointer;
767
+ if (pointer) {
768
+ return activeIndexAt(geometry.categoryTicks, this.layout === 'horizontal' ? pointer.x : pointer.y);
769
+ }
770
+ if (this.keyboardActive && this.keyboardIndex !== null) return this.keyboardIndex;
771
+ if (isNumber(tooltip.args.defaultIndex) && this.keyboardIndex === null) return tooltip.args.defaultIndex;
772
+ if (tooltip.args.active === true) return this.keyboardIndex ?? 0;
773
+ return null;
774
+ }
775
+ get isTooltipActive() {
776
+ return this.activeIndex !== null && this.activeIndex < (this.args.data?.length ?? 0);
777
+ }
778
+ /**
779
+ * Where the tooltip points: the active row's tick, at the pointer. Without one (the keyboard,
780
+ * `@defaultIndex`), at the first series' point, as recharts' `getPosition` gives it; a bar has
781
+ * none (recharts' is a no-op), so then the tick at the plot's middle, as recharts falls back.
782
+ */
783
+ get activeCoordinate() {
784
+ const geometry = this.geometry;
785
+ const index = this.activeIndex;
786
+ if (!geometry || index === null) return null;
787
+ const tick = geometry.categoryTicks.find(entry => entry.index === index);
788
+ if (!tick) return null;
789
+ const pointer = this.pointer;
790
+ if (pointer) {
791
+ return this.layout === 'horizontal' ? {
792
+ x: tick.coordinate,
793
+ y: pointer.y
794
+ } : {
795
+ x: pointer.x,
796
+ y: tick.coordinate
797
+ };
798
+ }
799
+ const first = geometry.series.find(series => !series.settings.hide);
800
+ const point = first?.points[index];
801
+ if (point && point.x !== null && point.y !== null) return {
802
+ x: point.x,
803
+ y: point.y
804
+ };
805
+ const size = this.size;
806
+ return this.layout === 'horizontal' ? {
807
+ x: tick.coordinate,
808
+ y: (geometry.offset.top + size.height) / 2
809
+ } : {
810
+ x: (geometry.offset.left + size.width) / 2,
811
+ y: tick.coordinate
812
+ };
813
+ }
814
+ /**
815
+ * What the tooltip's own arguments pass to its content. They go in one object: passed one by
816
+ * one, an argument the tooltip leaves out would reach the content as `undefined` and override
817
+ * the one curried into it (recharts passes only the props given).
818
+ */
819
+ get tooltipProps() {
820
+ const args = this.tooltipPart?.args;
821
+ return {
822
+ labelClassName: args?.labelClassName,
823
+ labelFormatter: args?.labelFormatter,
824
+ formatter: args?.formatter
825
+ };
826
+ }
827
+ get tooltipCoordinate() {
828
+ return this.activeCoordinate ?? undefined;
829
+ }
830
+ get tooltipPayload() {
831
+ const index = this.activeIndex;
832
+ const tooltip = this.tooltipPart;
833
+ if (index === null || !tooltip) return [];
834
+ const datum = this.args.data?.[index];
835
+ if (datum === undefined) return [];
836
+ const filterNull = tooltip.args.filterNull ?? true;
837
+ const items = [];
838
+ for (const part of this.seriesParts) {
839
+ const args = part.args;
840
+ if (args.hide || args.tooltipType === 'none') continue;
841
+ const value = valueOf(datum, args.dataKey);
842
+ if (filterNull && (value === null || value === undefined)) continue;
843
+ const fill = 'fill' in args ? args.fill : undefined;
844
+ const stroke = 'stroke' in args ? args.stroke : undefined;
845
+ const color = part instanceof Bar ? fill : part instanceof Line ? stroke ?? '#3182bd' : itemColor(stroke ?? '#3182bd', fill);
846
+ items.push({
847
+ name: args.name ?? keyOf(args.dataKey),
848
+ value,
849
+ dataKey: args.dataKey,
850
+ color,
851
+ fill: part instanceof Line ? fill ?? '#fff' : fill,
852
+ stroke,
853
+ payload: datum,
854
+ type: args.tooltipType,
855
+ unit: args.unit
856
+ });
857
+ }
858
+ // recharts sorts the entries by name.
859
+ return items.sort((a, b) => String(a.name) < String(b.name) ? -1 : String(a.name) > String(b.name) ? 1 : 0);
860
+ }
861
+ get tooltipLabel() {
862
+ const index = this.activeIndex;
863
+ const geometry = this.geometry;
864
+ if (index === null || !geometry) return undefined;
865
+ return geometry.categoryTicks.find(tick => tick.index === index)?.value;
866
+ }
867
+ get tooltipContent() {
868
+ return this.tooltipPart?.args.content ?? ChartTooltipContent;
869
+ }
870
+ get tooltipVisible() {
871
+ return this.isTooltipActive && this.tooltipPayload.length > 0 && !!this.tooltipBox && this.tooltipBox.width > 0 && this.tooltipBox.height > 0;
872
+ }
873
+ get tooltipStyle() {
874
+ return tooltipStyleFor({
875
+ visible: this.tooltipVisible,
876
+ coordinate: this.activeCoordinate,
877
+ box: this.tooltipBox,
878
+ plot: this.geometry?.offset,
879
+ tooltip: this.tooltipPart
880
+ });
881
+ }
882
+ /** Measures the tooltip's box each time what it shows changes (its arguments). */
883
+ measureTooltip = modifier((element, positional) => {
884
+ // Read the arguments, so the modifier runs again when they change.
885
+ void [...positional];
886
+ const rect = {
887
+ width: element.offsetWidth,
888
+ height: element.offsetHeight
889
+ };
890
+ const current = this.#tooltipBox;
891
+ if (!current || Math.abs(current.width - rect.width) > 1 || Math.abs(current.height - rect.height) > 1) {
892
+ this.#tooltipBox = rect;
893
+ this.tooltipBox = rect;
894
+ }
895
+ });
896
+ get cursor() {
897
+ const tooltip = this.tooltipPart;
898
+ const geometry = this.geometry;
899
+ const coordinate = this.activeCoordinate;
900
+ if (!tooltip || !geometry || !coordinate || !this.isTooltipActive || tooltip.args.cursor === false) return null;
901
+ const option = isObject(tooltip.args.cursor) ? tooltip.args.cursor : {};
902
+ const {
903
+ offset
904
+ } = geometry;
905
+ if (this.chartName === 'BarChart') {
906
+ const half = geometry.bandSize / 2;
907
+ const rect = this.layout === 'horizontal' ? {
908
+ x: coordinate.x - half,
909
+ y: offset.top + 0.5,
910
+ width: geometry.bandSize,
911
+ height: offset.height - 1
912
+ } : {
913
+ x: offset.left + 0.5,
914
+ y: coordinate.y - half,
915
+ width: offset.width - 1,
916
+ height: geometry.bandSize
917
+ };
918
+ return {
919
+ isRectangle: true,
920
+ isCurve: false,
921
+ d: rectanglePath(rect.x, rect.y, rect.width, rect.height, 0),
922
+ fill: option.fill ?? '#ccc',
923
+ stroke: 'none',
924
+ strokeWidth: undefined
925
+ };
926
+ }
927
+ const points = this.layout === 'horizontal' ? [{
928
+ x: coordinate.x,
929
+ y: offset.top
930
+ }, {
931
+ x: coordinate.x,
932
+ y: offset.top + offset.height
933
+ }] : [{
934
+ x: offset.left,
935
+ y: coordinate.y
936
+ }, {
937
+ x: offset.left + offset.width,
938
+ y: coordinate.y
939
+ }];
940
+ return {
941
+ isRectangle: false,
942
+ isCurve: true,
943
+ d: linePath(points, 'linear', this.layout) ?? '',
944
+ stroke: option.stroke ?? '#ccc',
945
+ strokeWidth: option.strokeWidth ?? 1,
946
+ fill: 'none'
947
+ };
948
+ }
949
+ get activeDots() {
950
+ const index = this.activeIndex;
951
+ const geometry = this.geometry;
952
+ if (index === null || !geometry || !this.isTooltipActive) return [];
953
+ const result = [];
954
+ this.seriesParts.forEach((part, i) => {
955
+ if (part instanceof Bar || part.args.hide) return;
956
+ const point = geometry.series[i].points[index];
957
+ if (!point || point.x === null || point.y === null) return;
958
+ const args = part.args;
959
+ const stroke = args.stroke ?? '#3182bd';
960
+ const fill = part instanceof Area ? itemColor(stroke, args.fill ?? '#3182bd') : stroke;
961
+ const dot = dotFor(args.activeDot, true, {
962
+ r: 4,
963
+ fill: fill ?? 'none',
964
+ stroke: '#fff',
965
+ strokeWidth: '2'
966
+ }, {
967
+ cx: point.x,
968
+ cy: point.y,
969
+ r: 4,
970
+ index,
971
+ value: point.value,
972
+ payload: point.payload,
973
+ dataKey: args.dataKey,
974
+ fill,
975
+ stroke: '#fff',
976
+ strokeWidth: 2
977
+ });
978
+ if (dot) result.push(dot);
979
+ });
980
+ return result;
981
+ }
982
+ // ---------------------------------------------------------------------------------------
983
+ // Legend
984
+ get legendPayload() {
985
+ const items = [];
986
+ for (const part of this.seriesParts) {
987
+ const args = part.args;
988
+ if (args.legendType === 'none') continue;
989
+ const fill = 'fill' in args ? args.fill : undefined;
990
+ const stroke = 'stroke' in args ? args.stroke : undefined;
991
+ items.push({
992
+ value: args.name ?? keyOf(args.dataKey),
993
+ dataKey: args.dataKey,
994
+ color: part instanceof Bar ? fill : part instanceof Line ? stroke ?? '#3182bd' : itemColor(stroke ?? '#3182bd', fill ?? '#3182bd'),
995
+ type: args.legendType ?? (part instanceof Bar ? 'rect' : 'line'),
996
+ inactive: args.hide ?? false
997
+ });
998
+ }
999
+ // recharts sorts the legend by value.
1000
+ return items.sort((a, b) => a.value < b.value ? -1 : a.value > b.value ? 1 : 0);
1001
+ }
1002
+ get legendVerticalAlign() {
1003
+ return this.legendPart?.args.verticalAlign ?? 'bottom';
1004
+ }
1005
+ get legendContent() {
1006
+ return this.legendPart?.args.content ?? ChartLegendContent;
1007
+ }
1008
+ get legendStyle() {
1009
+ return legendStyleFor(this.size, this.margin, this.legendPart, this.legendBox);
1010
+ }
1011
+ measureLegend = modifier(element => observeSize(this, element, ({
1012
+ width,
1013
+ height
1014
+ }) => {
1015
+ const current = this.#legendBox;
1016
+ if (!current || Math.abs(current.width - width) > 1 || Math.abs(current.height - height) > 1) {
1017
+ this.#legendBox = {
1018
+ width,
1019
+ height
1020
+ };
1021
+ this.legendBox = {
1022
+ width,
1023
+ height
1024
+ };
1025
+ }
1026
+ }));
1027
+ /** Reads the font the tick labels are drawn in, which the axes measure them with. */
1028
+ measureTicks = modifier((element, [axis, count]) => {
1029
+ const text = element.querySelector('.recharts-cartesian-axis-tick-value');
1030
+ if (!text) return;
1031
+ const style = getComputedStyle(text);
1032
+ const current = this.#tickStyles[axis];
1033
+ if (current.fontSize !== style.fontSize || current.letterSpacing !== style.letterSpacing) {
1034
+ this.#tickStyles = {
1035
+ ...this.#tickStyles,
1036
+ [axis]: {
1037
+ fontSize: style.fontSize,
1038
+ letterSpacing: style.letterSpacing
1039
+ }
1040
+ };
1041
+ this.tickStyles = this.#tickStyles;
1042
+ }
1043
+ });
1044
+ // ---------------------------------------------------------------------------------------
1045
+ // Events
1046
+ onMouseMove = event => {
1047
+ const geometry = this.geometry;
1048
+ if (!geometry) return;
1049
+ const element = event.currentTarget;
1050
+ const rect = element.getBoundingClientRect();
1051
+ const scaleX = element.offsetWidth ? rect.width / element.offsetWidth : 1;
1052
+ const scaleY = element.offsetHeight ? rect.height / element.offsetHeight : 1;
1053
+ const x = (event.clientX - rect.left) / scaleX;
1054
+ const y = (event.clientY - rect.top) / scaleY;
1055
+ const {
1056
+ offset
1057
+ } = geometry;
1058
+ const inside = x >= offset.left && x <= offset.left + offset.width && y >= offset.top && y <= offset.top + offset.height;
1059
+ this.pointer = inside ? {
1060
+ x,
1061
+ y
1062
+ } : null;
1063
+ };
1064
+ onMouseLeave = () => {
1065
+ this.pointer = null;
1066
+ };
1067
+ onFocus = () => {
1068
+ if (!this.accessibilityLayer || this.keyboardActive) return;
1069
+ if (this.keyboardIndex === null) this.keyboardIndex = 0;
1070
+ this.keyboardActive = true;
1071
+ };
1072
+ onBlur = () => {
1073
+ if (!this.accessibilityLayer) return;
1074
+ this.keyboardActive = false;
1075
+ };
1076
+ onKeyDown = event => {
1077
+ if (!this.accessibilityLayer) return;
1078
+ const {
1079
+ key
1080
+ } = event;
1081
+ if (key !== 'ArrowRight' && key !== 'ArrowLeft' && key !== 'Enter') return;
1082
+ const current = this.keyboardIndex ?? -1;
1083
+ if (current < 0) return;
1084
+ if (key === 'Enter') {
1085
+ this.keyboardActive = !this.keyboardActive;
1086
+ return;
1087
+ }
1088
+ const geometry = this.geometry;
1089
+ const categoryAxis = this.layout === 'horizontal' ? geometry?.xAxis.settings : geometry?.yAxis.settings;
1090
+ // ArrowRight moves to the next row and ArrowLeft to the previous one, the other way on a
1091
+ // reversed category axis, as recharts 3 does in a horizontal chart. In a vertical chart
1092
+ // recharts' keyboardEventsMiddleware flips every move (its direction there is never
1093
+ // 'left-to-right'), so its ArrowRight goes up to the previous row; Joinery's goes down to
1094
+ // the next, as in a horizontal chart. The guide's Keyboard interactions section says so.
1095
+ const direction = categoryAxis?.reversed ? -1 : 1;
1096
+ const next = current + (key === 'ArrowRight' ? 1 : -1) * direction;
1097
+ const count = geometry?.categoryTicks.length ?? 0;
1098
+ if (next < 0 || next >= count) return;
1099
+ this.pointer = null;
1100
+ this.keyboardIndex = next;
1101
+ this.keyboardActive = true;
1102
+ };
1103
+ static {
1104
+ setComponentTemplate(precompileTemplate("{{#let (hash XAxis=(component XAxis chart=this) YAxis=(component YAxis chart=this) CartesianGrid=(component CartesianGrid chart=this) Area=(component Area chart=this) Bar=(component Bar chart=this) Line=(component Line chart=this) ChartTooltip=(component ChartTooltip chart=this) ChartLegend=(component ChartLegend chart=this)) as |parts|}}\n {{#if this.fixedSize}}\n {{!-- A fixed size: recharts draws the wrapper alone. --}}\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}}", {
1105
+ strictMode: true,
1106
+ scope: () => ({
1107
+ hash,
1108
+ XAxis,
1109
+ YAxis,
1110
+ CartesianGrid,
1111
+ Area,
1112
+ Bar,
1113
+ Line,
1114
+ ChartTooltip,
1115
+ ChartLegend,
1116
+ Surface
1117
+ })
1118
+ }), this);
1119
+ }
1120
+ }
1121
+
1122
+ export { CartesianChart as C, legendStyleFor as l, observeSize as o, tooltipStyleFor as t };
1123
+ //# sourceMappingURL=cartesian-chart-BLj6Q_OB.js.map