@adecore/charts 0.41.1 → 0.43.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.
- package/dist/Root.d.ts +3 -1
- package/dist/Root.js +410 -339
- package/dist/annotations.js +210 -85
- package/dist/axes.d.ts +3 -2
- package/dist/axes.js +541 -74
- package/dist/band.d.ts +2 -0
- package/dist/band.js +10 -0
- package/dist/context.d.ts +3 -0
- package/dist/cursor.d.ts +1 -1
- package/dist/cursor.js +5 -4
- package/dist/locales/en.d.ts +1 -0
- package/dist/locales/en.js +1 -0
- package/dist/locales/nl.d.ts +1 -0
- package/dist/locales/nl.js +1 -0
- package/dist/overlays.js +204 -132
- package/dist/series.d.ts +4 -4
- package/dist/series.js +329 -195
- package/dist/store.d.ts +2 -0
- package/dist/store.js +2 -1
- package/package.json +3 -3
- package/src/Root.tsx +137 -44
- package/src/annotations.tsx +31 -4
- package/src/axes.tsx +182 -6
- package/src/band.ts +13 -0
- package/src/context.ts +9 -0
- package/src/cursor.ts +12 -4
- package/src/locales/en.ts +1 -0
- package/src/locales/nl.ts +1 -0
- package/src/overlays.tsx +51 -1
- package/src/series.tsx +144 -28
- package/src/store.ts +5 -1
package/dist/axes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import { useEffect, useId, useRef, useSyncExternalStore } from 'react';
|
|
2
|
+
import { useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
@@ -24,6 +24,10 @@ const X_TITLE_ROOM = 21;
|
|
|
24
24
|
/* The baseline of a y axis title from the top of the chart, and the room above the plot it needs. */
|
|
25
25
|
const Y_TITLE_BASELINE = 15;
|
|
26
26
|
const Y_TITLE_ROOM = 28;
|
|
27
|
+
/* The names of the rows of a horizontal chart: their widest and the share of the chart they may take, and their line. */
|
|
28
|
+
const ROW_LABEL_LIMIT = 240;
|
|
29
|
+
const ROW_LABEL_SHARE = 0.4;
|
|
30
|
+
const ROW_LABEL_LINE = 16;
|
|
27
31
|
/* The height a row of labels takes under the plot, more for a slanted one. */
|
|
28
32
|
const roomOf = (widest, angle) => Math.ceil(angle === 0 ? X_LABEL_LINE : widest * Math.sin(SLANT) + X_LABEL_LINE * Math.cos(SLANT));
|
|
29
33
|
const textWidth = node => typeof node.getComputedTextLength === 'function' ? node.getComputedTextLength() : (node.textContent?.length ?? 0) * 7;
|
|
@@ -48,7 +52,7 @@ const apart = (labels, spacing) => {
|
|
|
48
52
|
};
|
|
49
53
|
/* Gridlines on the ticks, a heavier one on the ground. */
|
|
50
54
|
export function ChartGrid(t0) {
|
|
51
|
-
const $ = _c(
|
|
55
|
+
const $ = _c(78);
|
|
52
56
|
const {
|
|
53
57
|
axis: t1,
|
|
54
58
|
dashed: t2,
|
|
@@ -67,31 +71,150 @@ export function ChartGrid(t0) {
|
|
|
67
71
|
band
|
|
68
72
|
} = chart;
|
|
69
73
|
const ground = y.domain[0] <= 0 && y.domain[1] >= 0 ? 0 : y.domain[0];
|
|
74
|
+
if (chart.horizontal) {
|
|
75
|
+
let t4;
|
|
76
|
+
if ($[0] !== axis || $[1] !== ground || $[2] !== lines || $[3] !== y.ticks) {
|
|
77
|
+
t4 = lines === "ground" ? [ground] : axis === "x" ? [] : y.ticks;
|
|
78
|
+
$[0] = axis;
|
|
79
|
+
$[1] = ground;
|
|
80
|
+
$[2] = lines;
|
|
81
|
+
$[3] = y.ticks;
|
|
82
|
+
$[4] = t4;
|
|
83
|
+
} else {
|
|
84
|
+
t4 = $[4];
|
|
85
|
+
}
|
|
86
|
+
const ticks = t4;
|
|
87
|
+
let t5;
|
|
88
|
+
let t6;
|
|
89
|
+
let t7;
|
|
90
|
+
let t8;
|
|
91
|
+
let t9;
|
|
92
|
+
if ($[5] !== axis || $[6] !== chart || $[7] !== className || $[8] !== dashed || $[9] !== ground || $[10] !== lines || $[11] !== plot || $[12] !== ref || $[13] !== ticks || $[14] !== y) {
|
|
93
|
+
const rows = lines === "ground" || axis === "y" ? [] : chart.xs.map((_, index) => chart.centerOf(index));
|
|
94
|
+
t5 = ref;
|
|
95
|
+
if ($[20] !== className) {
|
|
96
|
+
t6 = clsx("pointer-events-none", className);
|
|
97
|
+
$[20] = className;
|
|
98
|
+
$[21] = t6;
|
|
99
|
+
} else {
|
|
100
|
+
t6 = $[21];
|
|
101
|
+
}
|
|
102
|
+
t7 = true;
|
|
103
|
+
if ($[22] !== dashed || $[23] !== ground || $[24] !== plot || $[25] !== ticks || $[26] !== y) {
|
|
104
|
+
let t10;
|
|
105
|
+
if ($[28] !== dashed || $[29] !== ground || $[30] !== plot || $[31] !== y) {
|
|
106
|
+
t10 = tick => {
|
|
107
|
+
const pixel = y.at(tick);
|
|
108
|
+
return pixel === null ? null : /*#__PURE__*/_jsx("line", {
|
|
109
|
+
x1: crisp(pixel),
|
|
110
|
+
x2: crisp(pixel),
|
|
111
|
+
y1: plot.top,
|
|
112
|
+
y2: plot.bottom,
|
|
113
|
+
strokeDasharray: dashed && tick !== ground ? DASH : undefined,
|
|
114
|
+
className: dashed ? "stroke-border" : tick === ground ? "stroke-border-strong" : "stroke-border-soft"
|
|
115
|
+
}, tick);
|
|
116
|
+
};
|
|
117
|
+
$[28] = dashed;
|
|
118
|
+
$[29] = ground;
|
|
119
|
+
$[30] = plot;
|
|
120
|
+
$[31] = y;
|
|
121
|
+
$[32] = t10;
|
|
122
|
+
} else {
|
|
123
|
+
t10 = $[32];
|
|
124
|
+
}
|
|
125
|
+
t8 = ticks.map(t10);
|
|
126
|
+
$[22] = dashed;
|
|
127
|
+
$[23] = ground;
|
|
128
|
+
$[24] = plot;
|
|
129
|
+
$[25] = ticks;
|
|
130
|
+
$[26] = y;
|
|
131
|
+
$[27] = t8;
|
|
132
|
+
} else {
|
|
133
|
+
t8 = $[27];
|
|
134
|
+
}
|
|
135
|
+
let t10;
|
|
136
|
+
if ($[33] !== dashed || $[34] !== plot) {
|
|
137
|
+
t10 = pixel_0 => /*#__PURE__*/_jsx("line", {
|
|
138
|
+
x1: plot.left,
|
|
139
|
+
x2: plot.right,
|
|
140
|
+
y1: crisp(pixel_0),
|
|
141
|
+
y2: crisp(pixel_0),
|
|
142
|
+
strokeDasharray: dashed ? DASH : undefined,
|
|
143
|
+
className: dashed ? "stroke-border" : "stroke-border-soft"
|
|
144
|
+
}, pixel_0);
|
|
145
|
+
$[33] = dashed;
|
|
146
|
+
$[34] = plot;
|
|
147
|
+
$[35] = t10;
|
|
148
|
+
} else {
|
|
149
|
+
t10 = $[35];
|
|
150
|
+
}
|
|
151
|
+
t9 = rows.map(t10);
|
|
152
|
+
$[5] = axis;
|
|
153
|
+
$[6] = chart;
|
|
154
|
+
$[7] = className;
|
|
155
|
+
$[8] = dashed;
|
|
156
|
+
$[9] = ground;
|
|
157
|
+
$[10] = lines;
|
|
158
|
+
$[11] = plot;
|
|
159
|
+
$[12] = ref;
|
|
160
|
+
$[13] = ticks;
|
|
161
|
+
$[14] = y;
|
|
162
|
+
$[15] = t5;
|
|
163
|
+
$[16] = t6;
|
|
164
|
+
$[17] = t7;
|
|
165
|
+
$[18] = t8;
|
|
166
|
+
$[19] = t9;
|
|
167
|
+
} else {
|
|
168
|
+
t5 = $[15];
|
|
169
|
+
t6 = $[16];
|
|
170
|
+
t7 = $[17];
|
|
171
|
+
t8 = $[18];
|
|
172
|
+
t9 = $[19];
|
|
173
|
+
}
|
|
174
|
+
let t10;
|
|
175
|
+
if ($[36] !== t5 || $[37] !== t6 || $[38] !== t7 || $[39] !== t8 || $[40] !== t9) {
|
|
176
|
+
t10 = /*#__PURE__*/_jsxs("g", {
|
|
177
|
+
ref: t5,
|
|
178
|
+
className: t6,
|
|
179
|
+
"aria-hidden": t7,
|
|
180
|
+
children: [t8, t9]
|
|
181
|
+
});
|
|
182
|
+
$[36] = t5;
|
|
183
|
+
$[37] = t6;
|
|
184
|
+
$[38] = t7;
|
|
185
|
+
$[39] = t8;
|
|
186
|
+
$[40] = t9;
|
|
187
|
+
$[41] = t10;
|
|
188
|
+
} else {
|
|
189
|
+
t10 = $[41];
|
|
190
|
+
}
|
|
191
|
+
return t10;
|
|
192
|
+
}
|
|
70
193
|
if (lines === "ground") {
|
|
71
194
|
let t4;
|
|
72
|
-
if ($[
|
|
73
|
-
const
|
|
74
|
-
t4 =
|
|
195
|
+
if ($[42] !== className || $[43] !== dashed || $[44] !== ground || $[45] !== plot || $[46] !== ref || $[47] !== y) {
|
|
196
|
+
const pixel_1 = y.at(ground);
|
|
197
|
+
t4 = pixel_1 === null ? null : /*#__PURE__*/_jsx("g", {
|
|
75
198
|
ref: ref,
|
|
76
199
|
className: clsx("pointer-events-none", className),
|
|
77
200
|
"aria-hidden": true,
|
|
78
201
|
children: /*#__PURE__*/_jsx("line", {
|
|
79
202
|
x1: plot.left,
|
|
80
203
|
x2: plot.right,
|
|
81
|
-
y1: crisp(
|
|
82
|
-
y2: crisp(
|
|
204
|
+
y1: crisp(pixel_1),
|
|
205
|
+
y2: crisp(pixel_1),
|
|
83
206
|
className: dashed ? "stroke-border" : "stroke-border-strong"
|
|
84
207
|
})
|
|
85
208
|
});
|
|
86
|
-
$[
|
|
87
|
-
$[
|
|
88
|
-
$[
|
|
89
|
-
$[
|
|
90
|
-
$[
|
|
91
|
-
$[
|
|
92
|
-
$[
|
|
209
|
+
$[42] = className;
|
|
210
|
+
$[43] = dashed;
|
|
211
|
+
$[44] = ground;
|
|
212
|
+
$[45] = plot;
|
|
213
|
+
$[46] = ref;
|
|
214
|
+
$[47] = y;
|
|
215
|
+
$[48] = t4;
|
|
93
216
|
} else {
|
|
94
|
-
t4 = $[
|
|
217
|
+
t4 = $[48];
|
|
95
218
|
}
|
|
96
219
|
return t4;
|
|
97
220
|
}
|
|
@@ -100,89 +223,249 @@ export function ChartGrid(t0) {
|
|
|
100
223
|
let t6;
|
|
101
224
|
let t7;
|
|
102
225
|
let t8;
|
|
103
|
-
if ($[
|
|
104
|
-
const columns = continuous !== null ? continuous.ticks(tickCount(plot.width, X_TICK_SPACING)).map(
|
|
226
|
+
if ($[49] !== axis || $[50] !== band || $[51] !== chart || $[52] !== className || $[53] !== continuous || $[54] !== dashed || $[55] !== ground || $[56] !== plot || $[57] !== ref || $[58] !== y) {
|
|
227
|
+
const columns = continuous !== null ? continuous.ticks(tickCount(plot.width, X_TICK_SPACING)).map(tick_0 => continuous.at(tick_0)) : chart.xs.map((__0, index_0) => chart.centerOf(index_0));
|
|
105
228
|
t4 = ref;
|
|
106
|
-
if ($[
|
|
229
|
+
if ($[64] !== className) {
|
|
107
230
|
t5 = clsx("pointer-events-none", className);
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
231
|
+
$[64] = className;
|
|
232
|
+
$[65] = t5;
|
|
110
233
|
} else {
|
|
111
|
-
t5 = $[
|
|
234
|
+
t5 = $[65];
|
|
112
235
|
}
|
|
113
236
|
t6 = true;
|
|
114
|
-
if ($[
|
|
115
|
-
t7 = axis !== "x" && y.ticks.map(
|
|
116
|
-
const
|
|
117
|
-
return
|
|
237
|
+
if ($[66] !== axis || $[67] !== dashed || $[68] !== ground || $[69] !== plot || $[70] !== y) {
|
|
238
|
+
t7 = axis !== "x" && y.ticks.map(tick_1 => {
|
|
239
|
+
const pixel_2 = y.at(tick_1);
|
|
240
|
+
return pixel_2 === null ? null : /*#__PURE__*/_jsx("line", {
|
|
118
241
|
x1: plot.left,
|
|
119
242
|
x2: plot.right,
|
|
120
|
-
y1: crisp(
|
|
121
|
-
y2: crisp(
|
|
122
|
-
strokeDasharray: dashed &&
|
|
123
|
-
className: dashed ? "stroke-border" :
|
|
124
|
-
},
|
|
243
|
+
y1: crisp(pixel_2),
|
|
244
|
+
y2: crisp(pixel_2),
|
|
245
|
+
strokeDasharray: dashed && tick_1 !== ground ? DASH : undefined,
|
|
246
|
+
className: dashed ? "stroke-border" : tick_1 === ground ? "stroke-border-strong" : "stroke-border-soft"
|
|
247
|
+
}, tick_1);
|
|
125
248
|
});
|
|
126
|
-
$[
|
|
127
|
-
$[
|
|
128
|
-
$[
|
|
129
|
-
$[
|
|
130
|
-
$[
|
|
131
|
-
$[
|
|
249
|
+
$[66] = axis;
|
|
250
|
+
$[67] = dashed;
|
|
251
|
+
$[68] = ground;
|
|
252
|
+
$[69] = plot;
|
|
253
|
+
$[70] = y;
|
|
254
|
+
$[71] = t7;
|
|
132
255
|
} else {
|
|
133
|
-
t7 = $[
|
|
256
|
+
t7 = $[71];
|
|
134
257
|
}
|
|
135
|
-
t8 = axis !== "y" && (band === null || chart.xs.length > 0) && columns.map(
|
|
136
|
-
x1: crisp(
|
|
137
|
-
x2: crisp(
|
|
258
|
+
t8 = axis !== "y" && (band === null || chart.xs.length > 0) && columns.map(pixel_3 => /*#__PURE__*/_jsx("line", {
|
|
259
|
+
x1: crisp(pixel_3),
|
|
260
|
+
x2: crisp(pixel_3),
|
|
138
261
|
y1: plot.top,
|
|
139
262
|
y2: plot.bottom,
|
|
140
263
|
strokeDasharray: dashed ? DASH : undefined,
|
|
141
264
|
className: dashed ? "stroke-border" : "stroke-border-soft"
|
|
142
|
-
},
|
|
143
|
-
$[
|
|
144
|
-
$[
|
|
145
|
-
$[
|
|
146
|
-
$[
|
|
147
|
-
$[
|
|
148
|
-
$[
|
|
149
|
-
$[
|
|
150
|
-
$[
|
|
151
|
-
$[
|
|
152
|
-
$[
|
|
153
|
-
$[
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
265
|
+
}, pixel_3));
|
|
266
|
+
$[49] = axis;
|
|
267
|
+
$[50] = band;
|
|
268
|
+
$[51] = chart;
|
|
269
|
+
$[52] = className;
|
|
270
|
+
$[53] = continuous;
|
|
271
|
+
$[54] = dashed;
|
|
272
|
+
$[55] = ground;
|
|
273
|
+
$[56] = plot;
|
|
274
|
+
$[57] = ref;
|
|
275
|
+
$[58] = y;
|
|
276
|
+
$[59] = t4;
|
|
277
|
+
$[60] = t5;
|
|
278
|
+
$[61] = t6;
|
|
279
|
+
$[62] = t7;
|
|
280
|
+
$[63] = t8;
|
|
158
281
|
} else {
|
|
159
|
-
t4 = $[
|
|
160
|
-
t5 = $[
|
|
161
|
-
t6 = $[
|
|
162
|
-
t7 = $[
|
|
163
|
-
t8 = $[
|
|
282
|
+
t4 = $[59];
|
|
283
|
+
t5 = $[60];
|
|
284
|
+
t6 = $[61];
|
|
285
|
+
t7 = $[62];
|
|
286
|
+
t8 = $[63];
|
|
164
287
|
}
|
|
165
288
|
let t9;
|
|
166
|
-
if ($[
|
|
289
|
+
if ($[72] !== t4 || $[73] !== t5 || $[74] !== t6 || $[75] !== t7 || $[76] !== t8) {
|
|
167
290
|
t9 = /*#__PURE__*/_jsxs("g", {
|
|
168
291
|
ref: t4,
|
|
169
292
|
className: t5,
|
|
170
293
|
"aria-hidden": t6,
|
|
171
294
|
children: [t7, t8]
|
|
172
295
|
});
|
|
173
|
-
$[
|
|
174
|
-
$[
|
|
175
|
-
$[
|
|
176
|
-
$[
|
|
177
|
-
$[
|
|
178
|
-
$[
|
|
296
|
+
$[72] = t4;
|
|
297
|
+
$[73] = t5;
|
|
298
|
+
$[74] = t6;
|
|
299
|
+
$[75] = t7;
|
|
300
|
+
$[76] = t8;
|
|
301
|
+
$[77] = t9;
|
|
302
|
+
} else {
|
|
303
|
+
t9 = $[77];
|
|
304
|
+
}
|
|
305
|
+
return t9;
|
|
306
|
+
}
|
|
307
|
+
/*
|
|
308
|
+
* The labels under the plot: one per bucket on a band scale as far as they fit, round ticks on a continuous one. In a
|
|
309
|
+
* horizontal chart, the name of every row left of the plot.
|
|
310
|
+
*/
|
|
311
|
+
export function ChartXAxis(props) {
|
|
312
|
+
const $ = _c(3);
|
|
313
|
+
const chart = useChartContext("Chart.XAxis");
|
|
314
|
+
let t0;
|
|
315
|
+
if ($[0] !== chart.horizontal || $[1] !== props) {
|
|
316
|
+
t0 = chart.horizontal ? /*#__PURE__*/_jsx(RowAxis, {
|
|
317
|
+
...props
|
|
318
|
+
}) : /*#__PURE__*/_jsx(ColumnAxis, {
|
|
319
|
+
...props
|
|
320
|
+
});
|
|
321
|
+
$[0] = chart.horizontal;
|
|
322
|
+
$[1] = props;
|
|
323
|
+
$[2] = t0;
|
|
324
|
+
} else {
|
|
325
|
+
t0 = $[2];
|
|
326
|
+
}
|
|
327
|
+
return t0;
|
|
328
|
+
}
|
|
329
|
+
/* The names of the rows of a horizontal chart, never left out: the column takes the widest, up to its limit, and cuts the rest short. */
|
|
330
|
+
function RowAxis(t0) {
|
|
331
|
+
const $ = _c(26);
|
|
332
|
+
const {
|
|
333
|
+
format,
|
|
334
|
+
title,
|
|
335
|
+
label: spoken,
|
|
336
|
+
maxWidth: t1,
|
|
337
|
+
onThinnedChange,
|
|
338
|
+
className,
|
|
339
|
+
ref
|
|
340
|
+
} = t0;
|
|
341
|
+
const maxWidth = t1 === undefined ? ROW_LABEL_LIMIT : t1;
|
|
342
|
+
const chart = useChartContext("Chart.XAxis");
|
|
343
|
+
const {
|
|
344
|
+
store,
|
|
345
|
+
xs
|
|
346
|
+
} = chart;
|
|
347
|
+
useAxisTitle(spoken ?? title);
|
|
348
|
+
const candidates = useRef(null);
|
|
349
|
+
const write = format ?? chart.formatX;
|
|
350
|
+
const limit = chart.box > 0 ? Math.min(maxWidth, Math.floor(chart.box * ROW_LABEL_SHARE)) : maxWidth;
|
|
351
|
+
const target = chart.elements.rows;
|
|
352
|
+
let t2;
|
|
353
|
+
if ($[0] !== limit || $[1] !== store) {
|
|
354
|
+
t2 = () => {
|
|
355
|
+
store.setAxis("start", Math.min(limit, Math.ceil(widestIn(candidates.current)) + 1) + LABEL_GAP);
|
|
356
|
+
};
|
|
357
|
+
$[0] = limit;
|
|
358
|
+
$[1] = store;
|
|
359
|
+
$[2] = t2;
|
|
360
|
+
} else {
|
|
361
|
+
t2 = $[2];
|
|
362
|
+
}
|
|
363
|
+
useBeforePaint(t2);
|
|
364
|
+
let t3;
|
|
365
|
+
let t4;
|
|
366
|
+
if ($[3] !== store) {
|
|
367
|
+
t3 = () => () => store.setAxis("start", null);
|
|
368
|
+
t4 = [store];
|
|
369
|
+
$[3] = store;
|
|
370
|
+
$[4] = t3;
|
|
371
|
+
$[5] = t4;
|
|
372
|
+
} else {
|
|
373
|
+
t3 = $[4];
|
|
374
|
+
t4 = $[5];
|
|
375
|
+
}
|
|
376
|
+
useBeforePaint(t3, t4);
|
|
377
|
+
const reported = useRef(false);
|
|
378
|
+
let t5;
|
|
379
|
+
if ($[6] !== onThinnedChange) {
|
|
380
|
+
t5 = () => {
|
|
381
|
+
if (!reported.current) {
|
|
382
|
+
reported.current = true;
|
|
383
|
+
onThinnedChange?.(false);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
$[6] = onThinnedChange;
|
|
387
|
+
$[7] = t5;
|
|
388
|
+
} else {
|
|
389
|
+
t5 = $[7];
|
|
390
|
+
}
|
|
391
|
+
useEffect(t5);
|
|
392
|
+
const column = Math.max(0, chart.leftAxis - LABEL_GAP);
|
|
393
|
+
let t6;
|
|
394
|
+
if ($[8] !== write || $[9] !== xs) {
|
|
395
|
+
let t7;
|
|
396
|
+
if ($[11] !== write) {
|
|
397
|
+
t7 = key => /*#__PURE__*/_jsx("text", {
|
|
398
|
+
className: "text-xs",
|
|
399
|
+
children: write(key)
|
|
400
|
+
}, String(key));
|
|
401
|
+
$[11] = write;
|
|
402
|
+
$[12] = t7;
|
|
403
|
+
} else {
|
|
404
|
+
t7 = $[12];
|
|
405
|
+
}
|
|
406
|
+
t6 = xs.map(t7);
|
|
407
|
+
$[8] = write;
|
|
408
|
+
$[9] = xs;
|
|
409
|
+
$[10] = t6;
|
|
410
|
+
} else {
|
|
411
|
+
t6 = $[10];
|
|
412
|
+
}
|
|
413
|
+
let t7;
|
|
414
|
+
if ($[13] !== t6) {
|
|
415
|
+
t7 = /*#__PURE__*/_jsx("g", {
|
|
416
|
+
ref: candidates,
|
|
417
|
+
visibility: "hidden",
|
|
418
|
+
children: t6
|
|
419
|
+
});
|
|
420
|
+
$[13] = t6;
|
|
421
|
+
$[14] = t7;
|
|
422
|
+
} else {
|
|
423
|
+
t7 = $[14];
|
|
424
|
+
}
|
|
425
|
+
let t8;
|
|
426
|
+
if ($[15] !== chart || $[16] !== className || $[17] !== column || $[18] !== target || $[19] !== write || $[20] !== xs) {
|
|
427
|
+
t8 = target !== null && createPortal(/*#__PURE__*/_jsx("div", {
|
|
428
|
+
className: clsx("pointer-events-none", className),
|
|
429
|
+
children: xs.map((key_0, index) => {
|
|
430
|
+
const focus = chart.labelFocus[index] ?? null;
|
|
431
|
+
return /*#__PURE__*/_jsx("div", {
|
|
432
|
+
className: clsx("absolute left-0 truncate text-right text-xs/4", focus === "strong" ? "text-text" : "text-text-muted"),
|
|
433
|
+
style: {
|
|
434
|
+
top: Math.round(chart.centerOf(index)) - ROW_LABEL_LINE / 2,
|
|
435
|
+
width: column,
|
|
436
|
+
opacity: focus === "dim" ? chart.labelDim : undefined
|
|
437
|
+
},
|
|
438
|
+
children: write(key_0)
|
|
439
|
+
}, String(key_0));
|
|
440
|
+
})
|
|
441
|
+
}), target);
|
|
442
|
+
$[15] = chart;
|
|
443
|
+
$[16] = className;
|
|
444
|
+
$[17] = column;
|
|
445
|
+
$[18] = target;
|
|
446
|
+
$[19] = write;
|
|
447
|
+
$[20] = xs;
|
|
448
|
+
$[21] = t8;
|
|
449
|
+
} else {
|
|
450
|
+
t8 = $[21];
|
|
451
|
+
}
|
|
452
|
+
let t9;
|
|
453
|
+
if ($[22] !== ref || $[23] !== t7 || $[24] !== t8) {
|
|
454
|
+
t9 = /*#__PURE__*/_jsxs("g", {
|
|
455
|
+
ref: ref,
|
|
456
|
+
"aria-hidden": true,
|
|
457
|
+
children: [t7, t8]
|
|
458
|
+
});
|
|
459
|
+
$[22] = ref;
|
|
460
|
+
$[23] = t7;
|
|
461
|
+
$[24] = t8;
|
|
462
|
+
$[25] = t9;
|
|
179
463
|
} else {
|
|
180
|
-
t9 = $[
|
|
464
|
+
t9 = $[25];
|
|
181
465
|
}
|
|
182
466
|
return t9;
|
|
183
467
|
}
|
|
184
|
-
|
|
185
|
-
export function ChartXAxis(t0) {
|
|
468
|
+
function ColumnAxis(t0) {
|
|
186
469
|
const $ = _c(42);
|
|
187
470
|
const {
|
|
188
471
|
format,
|
|
@@ -498,8 +781,192 @@ function useAxisTitle(title) {
|
|
|
498
781
|
}
|
|
499
782
|
useBeforePaint(t1, t2);
|
|
500
783
|
}
|
|
501
|
-
/* The value labels beside the plot. It measures its widest label and gives the plot the rest. */
|
|
502
|
-
export function ChartYAxis(
|
|
784
|
+
/* The value labels beside the plot. It measures its widest label and gives the plot the rest. In a horizontal chart they stand under it. */
|
|
785
|
+
export function ChartYAxis(props) {
|
|
786
|
+
const $ = _c(3);
|
|
787
|
+
const chart = useChartContext("Chart.YAxis");
|
|
788
|
+
let t0;
|
|
789
|
+
if ($[0] !== chart.horizontal || $[1] !== props) {
|
|
790
|
+
t0 = chart.horizontal ? /*#__PURE__*/_jsx(BottomAxis, {
|
|
791
|
+
...props
|
|
792
|
+
}) : /*#__PURE__*/_jsx(SideAxis, {
|
|
793
|
+
...props
|
|
794
|
+
});
|
|
795
|
+
$[0] = chart.horizontal;
|
|
796
|
+
$[1] = props;
|
|
797
|
+
$[2] = t0;
|
|
798
|
+
} else {
|
|
799
|
+
t0 = $[2];
|
|
800
|
+
}
|
|
801
|
+
return t0;
|
|
802
|
+
}
|
|
803
|
+
/* The values under the rows of a horizontal chart, with its title above the plot where the values start. */
|
|
804
|
+
function BottomAxis(t0) {
|
|
805
|
+
const $ = _c(44);
|
|
806
|
+
const {
|
|
807
|
+
format,
|
|
808
|
+
ticks,
|
|
809
|
+
side: t1,
|
|
810
|
+
title,
|
|
811
|
+
className,
|
|
812
|
+
ref
|
|
813
|
+
} = t0;
|
|
814
|
+
const side = t1 === undefined ? "left" : t1;
|
|
815
|
+
const chart = useChartContext("Chart.YAxis");
|
|
816
|
+
const {
|
|
817
|
+
store,
|
|
818
|
+
y,
|
|
819
|
+
yStep,
|
|
820
|
+
plot
|
|
821
|
+
} = chart;
|
|
822
|
+
const labels = useRef(null);
|
|
823
|
+
const [widest, setWidest] = useState(0);
|
|
824
|
+
let t2;
|
|
825
|
+
if ($[0] !== format || $[1] !== side || $[2] !== store || $[3] !== ticks || $[4] !== title || $[5] !== widest) {
|
|
826
|
+
t2 = () => {
|
|
827
|
+
store.setYAxis(side, {
|
|
828
|
+
width: 0,
|
|
829
|
+
ticks: ticks ?? null,
|
|
830
|
+
top: title === undefined ? null : Y_TITLE_ROOM,
|
|
831
|
+
format
|
|
832
|
+
});
|
|
833
|
+
const measured = Math.ceil(widestIn(labels.current));
|
|
834
|
+
if (measured !== widest) {
|
|
835
|
+
setWidest(measured);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
$[0] = format;
|
|
839
|
+
$[1] = side;
|
|
840
|
+
$[2] = store;
|
|
841
|
+
$[3] = ticks;
|
|
842
|
+
$[4] = title;
|
|
843
|
+
$[5] = widest;
|
|
844
|
+
$[6] = t2;
|
|
845
|
+
} else {
|
|
846
|
+
t2 = $[6];
|
|
847
|
+
}
|
|
848
|
+
useBeforePaint(t2);
|
|
849
|
+
let t3;
|
|
850
|
+
let t4;
|
|
851
|
+
if ($[7] !== side || $[8] !== store) {
|
|
852
|
+
t3 = () => () => store.setYAxis(side, null);
|
|
853
|
+
t4 = [store, side];
|
|
854
|
+
$[7] = side;
|
|
855
|
+
$[8] = store;
|
|
856
|
+
$[9] = t3;
|
|
857
|
+
$[10] = t4;
|
|
858
|
+
} else {
|
|
859
|
+
t3 = $[9];
|
|
860
|
+
t4 = $[10];
|
|
861
|
+
}
|
|
862
|
+
useBeforePaint(t3, t4);
|
|
863
|
+
let t5;
|
|
864
|
+
let t6;
|
|
865
|
+
let t7;
|
|
866
|
+
let t8;
|
|
867
|
+
let t9;
|
|
868
|
+
if ($[11] !== chart.leftAxis || $[12] !== chart.valueFormat || $[13] !== chart.width || $[14] !== className || $[15] !== format || $[16] !== plot || $[17] !== ref || $[18] !== widest || $[19] !== y || $[20] !== yStep) {
|
|
869
|
+
const decimals = decimalsOf(yStep);
|
|
870
|
+
let t10;
|
|
871
|
+
if ($[26] !== chart.leftAxis || $[27] !== chart.width || $[28] !== widest) {
|
|
872
|
+
t10 = x => Math.min(Math.max(x, widest / 2 - chart.leftAxis), chart.width - widest / 2);
|
|
873
|
+
$[26] = chart.leftAxis;
|
|
874
|
+
$[27] = chart.width;
|
|
875
|
+
$[28] = widest;
|
|
876
|
+
$[29] = t10;
|
|
877
|
+
} else {
|
|
878
|
+
t10 = $[29];
|
|
879
|
+
}
|
|
880
|
+
const inward = t10;
|
|
881
|
+
t7 = ref;
|
|
882
|
+
if ($[30] !== className) {
|
|
883
|
+
t8 = clsx("pointer-events-none", className);
|
|
884
|
+
$[30] = className;
|
|
885
|
+
$[31] = t8;
|
|
886
|
+
} else {
|
|
887
|
+
t8 = $[31];
|
|
888
|
+
}
|
|
889
|
+
t9 = true;
|
|
890
|
+
t5 = labels;
|
|
891
|
+
t6 = y.ticks.map(tick => {
|
|
892
|
+
const pixel = y.at(tick);
|
|
893
|
+
return pixel === null ? null : /*#__PURE__*/_jsx("text", {
|
|
894
|
+
x: Math.round(inward(pixel)),
|
|
895
|
+
y: plot.bottom + LABEL_GAP,
|
|
896
|
+
dy: "0.8em",
|
|
897
|
+
textAnchor: "middle",
|
|
898
|
+
className: "fill-text-faint text-xs tabular-nums",
|
|
899
|
+
children: (format ?? chart.valueFormat)?.(tick) ?? formatRounded(tick, decimals)
|
|
900
|
+
}, tick);
|
|
901
|
+
});
|
|
902
|
+
$[11] = chart.leftAxis;
|
|
903
|
+
$[12] = chart.valueFormat;
|
|
904
|
+
$[13] = chart.width;
|
|
905
|
+
$[14] = className;
|
|
906
|
+
$[15] = format;
|
|
907
|
+
$[16] = plot;
|
|
908
|
+
$[17] = ref;
|
|
909
|
+
$[18] = widest;
|
|
910
|
+
$[19] = y;
|
|
911
|
+
$[20] = yStep;
|
|
912
|
+
$[21] = t5;
|
|
913
|
+
$[22] = t6;
|
|
914
|
+
$[23] = t7;
|
|
915
|
+
$[24] = t8;
|
|
916
|
+
$[25] = t9;
|
|
917
|
+
} else {
|
|
918
|
+
t5 = $[21];
|
|
919
|
+
t6 = $[22];
|
|
920
|
+
t7 = $[23];
|
|
921
|
+
t8 = $[24];
|
|
922
|
+
t9 = $[25];
|
|
923
|
+
}
|
|
924
|
+
let t10;
|
|
925
|
+
if ($[32] !== t5 || $[33] !== t6) {
|
|
926
|
+
t10 = /*#__PURE__*/_jsx("g", {
|
|
927
|
+
ref: t5,
|
|
928
|
+
children: t6
|
|
929
|
+
});
|
|
930
|
+
$[32] = t5;
|
|
931
|
+
$[33] = t6;
|
|
932
|
+
$[34] = t10;
|
|
933
|
+
} else {
|
|
934
|
+
t10 = $[34];
|
|
935
|
+
}
|
|
936
|
+
let t11;
|
|
937
|
+
if ($[35] !== plot || $[36] !== title) {
|
|
938
|
+
t11 = title !== undefined && /*#__PURE__*/_jsx("text", {
|
|
939
|
+
x: Math.round(plot.left),
|
|
940
|
+
y: Y_TITLE_BASELINE,
|
|
941
|
+
className: "fill-text-muted text-xs",
|
|
942
|
+
children: title
|
|
943
|
+
});
|
|
944
|
+
$[35] = plot;
|
|
945
|
+
$[36] = title;
|
|
946
|
+
$[37] = t11;
|
|
947
|
+
} else {
|
|
948
|
+
t11 = $[37];
|
|
949
|
+
}
|
|
950
|
+
let t12;
|
|
951
|
+
if ($[38] !== t10 || $[39] !== t11 || $[40] !== t7 || $[41] !== t8 || $[42] !== t9) {
|
|
952
|
+
t12 = /*#__PURE__*/_jsxs("g", {
|
|
953
|
+
ref: t7,
|
|
954
|
+
className: t8,
|
|
955
|
+
"aria-hidden": t9,
|
|
956
|
+
children: [t10, t11]
|
|
957
|
+
});
|
|
958
|
+
$[38] = t10;
|
|
959
|
+
$[39] = t11;
|
|
960
|
+
$[40] = t7;
|
|
961
|
+
$[41] = t8;
|
|
962
|
+
$[42] = t9;
|
|
963
|
+
$[43] = t12;
|
|
964
|
+
} else {
|
|
965
|
+
t12 = $[43];
|
|
966
|
+
}
|
|
967
|
+
return t12;
|
|
968
|
+
}
|
|
969
|
+
function SideAxis(t0) {
|
|
503
970
|
const $ = _c(41);
|
|
504
971
|
const {
|
|
505
972
|
format,
|
|
@@ -664,7 +1131,7 @@ export function ChartGroupAxis(t0) {
|
|
|
664
1131
|
} = t0;
|
|
665
1132
|
const chart = useChartContext("Chart.GroupAxis");
|
|
666
1133
|
const target = chart.elements.groups;
|
|
667
|
-
if (target === null || chart.band === null) {
|
|
1134
|
+
if (target === null || chart.band === null || chart.horizontal) {
|
|
668
1135
|
return null;
|
|
669
1136
|
}
|
|
670
1137
|
const rows = chart.data;
|
package/dist/band.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ export declare function segmentOf(topPixel: number, basePixel: number, onGround:
|
|
|
29
29
|
height: number;
|
|
30
30
|
};
|
|
31
31
|
export declare function endRoundedColumn(x: number, y: number, width: number, height: number, radius: number, upward: boolean): string;
|
|
32
|
+
export declare function endRoundedBar(x: number, y: number, width: number, height: number, radius: number, rightward: boolean): string;
|
|
32
33
|
export declare const LABEL_LIFT = 10;
|
|
34
|
+
export declare const LABEL_INSET = 6;
|
|
33
35
|
declare const LABEL_SIZES: {
|
|
34
36
|
readonly '2xs': {
|
|
35
37
|
readonly row: 16;
|