@synertech/ui 0.46.3 → 0.47.1
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/.claude/skills/use-synertech-ui/SKILL.md +102 -3
- package/README.md +50 -0
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/badge/Badge.cjs +1 -1
- package/dist/components/badge/Badge.js +1 -1
- package/dist/components/bar-chart/BarChart.cjs +1 -1
- package/dist/components/bar-chart/BarChart.js +1 -1
- package/dist/components/box-plot/BoxPlot.cjs +1 -1
- package/dist/components/box-plot/BoxPlot.js +1 -1
- package/dist/components/breadcrumb/Breadcrumb.cjs +1 -1
- package/dist/components/breadcrumb/Breadcrumb.js +1 -1
- package/dist/components/bullet-chart/BulletChart.cjs +1 -1
- package/dist/components/bullet-chart/BulletChart.js +1 -1
- package/dist/components/button/Button.cjs +1 -1
- package/dist/components/button/Button.js +1 -1
- package/dist/components/calendar/Calendar.cjs +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
- package/dist/components/chart/ChartBrush.cjs +1 -1
- package/dist/components/chart/ChartBrush.js +1 -1
- package/dist/components/chart/ChartContainer.cjs +1 -1
- package/dist/components/chart/ChartContainer.js +1 -1
- package/dist/components/chart/ChartExportButton.cjs +1 -1
- package/dist/components/chart/ChartExportButton.js +1 -1
- package/dist/components/chart/ChartLegend.cjs +1 -1
- package/dist/components/chart/ChartLegend.js +1 -1
- package/dist/components/chart/ChartPeriodPicker.cjs +1 -1
- package/dist/components/chart/ChartPeriodPicker.js +1 -1
- package/dist/components/checkbox/Checkbox.cjs +1 -1
- package/dist/components/checkbox/Checkbox.js +1 -1
- package/dist/components/checkbox/CheckboxGroup.cjs +1 -1
- package/dist/components/checkbox/CheckboxGroup.js +1 -1
- package/dist/components/chip/Chip.cjs +1 -1
- package/dist/components/chip/Chip.js +1 -1
- package/dist/components/circular-progress/CircularProgress.cjs +1 -1
- package/dist/components/circular-progress/CircularProgress.js +1 -1
- package/dist/components/datagrid/DataGrid.cjs +1 -1
- package/dist/components/datagrid/DataGrid.js +1 -1
- package/dist/components/dropdown/DropdownCheckboxItem.cjs +1 -1
- package/dist/components/dropdown/DropdownCheckboxItem.js +1 -1
- package/dist/components/dropdown/DropdownRadio.cjs +1 -1
- package/dist/components/dropdown/DropdownRadio.js +1 -1
- package/dist/components/dropdown/DropdownTrigger.cjs +1 -1
- package/dist/components/dropdown/DropdownTrigger.js +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
- package/dist/components/file-selector/FileSelector.cjs +1 -1
- package/dist/components/file-selector/FileSelector.js +1 -1
- package/dist/components/footer/FooterLink.cjs +1 -1
- package/dist/components/footer/FooterLink.js +1 -1
- package/dist/components/footer/FooterSocial.cjs +1 -1
- package/dist/components/footer/FooterSocial.js +1 -1
- package/dist/components/form/number-input/NumberInput.cjs +1 -1
- package/dist/components/form/number-input/NumberInput.js +1 -1
- package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
- package/dist/components/funnel-chart/FunnelChart.js +1 -1
- package/dist/components/gantt-chart/GanttChart.cjs +1 -1
- package/dist/components/gantt-chart/GanttChart.js +1 -1
- package/dist/components/header/Header.cjs +1 -1
- package/dist/components/header/Header.js +1 -1
- package/dist/components/heat-map/Heatmap.cjs +1 -1
- package/dist/components/heat-map/Heatmap.js +1 -1
- package/dist/components/help-button/HelpButton.cjs +6 -6
- package/dist/components/help-button/HelpButton.js +7 -7
- package/dist/components/help-button/sanitize-html.cjs +1 -0
- package/dist/components/help-button/sanitize-html.js +1 -0
- package/dist/components/image-uploader/ImageUploader.cjs +1 -1
- package/dist/components/image-uploader/ImageUploader.js +1 -1
- package/dist/components/indicator/Indicator.cjs +1 -1
- package/dist/components/indicator/Indicator.js +1 -1
- package/dist/components/label/Label.cjs +1 -1
- package/dist/components/label/Label.js +1 -1
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/modal/Modal.cjs +1 -1
- package/dist/components/modal/Modal.js +1 -1
- package/dist/components/pagination/Pagination.cjs +1 -1
- package/dist/components/pagination/Pagination.js +1 -1
- package/dist/components/pie-chart/PieChart.cjs +1 -1
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/progress-bar/ProgressBar.cjs +1 -1
- package/dist/components/progress-bar/ProgressBar.js +1 -1
- package/dist/components/radio-button/RadioButton.cjs +1 -1
- package/dist/components/radio-button/RadioButton.js +1 -1
- package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/schema-editor/SchemaEditor.cjs +1 -1
- package/dist/components/schema-editor/SchemaEditor.js +1 -1
- package/dist/components/schema-editor/tables/SchemaTableRenderer.cjs +1 -1
- package/dist/components/schema-editor/tables/SchemaTableRenderer.js +1 -1
- package/dist/components/select/Select.cjs +1 -1
- package/dist/components/select/Select.js +1 -1
- package/dist/components/sidebar/Sidebar.cjs +1 -1
- package/dist/components/sidebar/Sidebar.js +1 -1
- package/dist/components/slider/Slider.cjs +1 -1
- package/dist/components/slider/Slider.js +1 -1
- package/dist/components/tabs/TabsContent.cjs +1 -1
- package/dist/components/tabs/TabsContent.js +1 -1
- package/dist/components/tabs/TabsTrigger.cjs +1 -1
- package/dist/components/tabs/TabsTrigger.js +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
- package/dist/components/wizard/Wizard.cjs +1 -1
- package/dist/components/wizard/Wizard.js +1 -1
- package/dist/components/workflow-editor/edges/WorkflowEdgeRenderer.cjs +1 -1
- package/dist/components/workflow-editor/edges/WorkflowEdgeRenderer.js +1 -1
- package/dist/components/workflow-editor/nodes/WorkflowNodeRenderer.cjs +1 -1
- package/dist/components/workflow-editor/nodes/WorkflowNodeRenderer.js +1 -1
- package/dist/index.d.cts +170 -12
- package/dist/index.d.ts +170 -12
- package/dist/lib/safe-href.cjs +1 -0
- package/dist/lib/safe-href.js +1 -0
- package/dist/styles.css +618 -249
- package/package.json +2 -2
|
@@ -122,6 +122,60 @@ toujours d'accord.
|
|
|
122
122
|
**Anti-pattern** : un bouton qui ne fait qu'ajouter et retirer `dark`. L'état clair n'est
|
|
123
123
|
alors pas déclaré, et les composants redeviennent sombres dès que le système l'est.
|
|
124
124
|
|
|
125
|
+
### 6. Couleur de marque : une rampe de variables
|
|
126
|
+
|
|
127
|
+
Un bouton principal, une case cochée, une ligne sélectionnée, un onglet actif, un anneau
|
|
128
|
+
de focus, un lien : tout ce que les composants peignent dans la couleur de l'application
|
|
129
|
+
lit une seule rampe de variables CSS, de `--color-synertech-primary-50` à `-950`. Par
|
|
130
|
+
défaut, c'est le bleu de Tailwind. Redéfinissez-la et tout le kit suit — sans prop, sans
|
|
131
|
+
composant à envelopper :
|
|
132
|
+
|
|
133
|
+
```css
|
|
134
|
+
:root {
|
|
135
|
+
--color-synertech-primary-50: #f5f3ff;
|
|
136
|
+
--color-synertech-primary-100: #ede9fe;
|
|
137
|
+
--color-synertech-primary-200: #ddd6fe;
|
|
138
|
+
--color-synertech-primary-300: #c4b5fd;
|
|
139
|
+
--color-synertech-primary-400: #a78bfa;
|
|
140
|
+
--color-synertech-primary-500: #8b5cf6;
|
|
141
|
+
--color-synertech-primary-600: #7c3aed; /* l'aplat, et le texte sur une page claire */
|
|
142
|
+
--color-synertech-primary-700: #6d28d9; /* l'aplat sous le pointeur */
|
|
143
|
+
--color-synertech-primary-800: #5b21b6;
|
|
144
|
+
--color-synertech-primary-900: #4c1d95;
|
|
145
|
+
--color-synertech-primary-950: #2e1065;
|
|
146
|
+
|
|
147
|
+
/* Ce qui s'écrit sur les aplats 600 et 700. Blanc par défaut. */
|
|
148
|
+
--color-synertech-on-primary: #fff;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- **Donnez à la rampe la forme de celles de Tailwind**, la plus claire en 50 et la plus
|
|
153
|
+
foncée en 950. Les composants prennent 50 et 100 pour les fonds teintés, 600 pour les
|
|
154
|
+
aplats et le texte sur une page claire, 400 pour le texte sur une page sombre, 500 pour
|
|
155
|
+
les anneaux de focus.
|
|
156
|
+
- **Les teintes 600 et 700 ont deux rôles** : ce sont les aplats sur lesquels s'écrit
|
|
157
|
+
`--color-synertech-on-primary`, et c'est du texte sur une page claire (un lien, le
|
|
158
|
+
libellé d'un onglet actif). Du blanc sur un bleu ou un violet se lit à 4,5:1 dans les
|
|
159
|
+
deux sens. Sur une teinte claire, non (3,6:1 sur l'orange-600 de Tailwind) : placez une
|
|
160
|
+
teinte plus foncée en 600 — l'orange-700 s'y lit à 5,2:1 dans les deux sens. Passer
|
|
161
|
+
`on-primary` en foncé garde lisible un aplat vif, mais laisse le texte de marque d'une
|
|
162
|
+
page claire aussi pâle que cet aplat.
|
|
163
|
+
- **Déclarez-la en CSS simple**, pas dans un bloc `@theme` de Tailwind. Sur `:root`, elle
|
|
164
|
+
repeint tout ; sur un autre élément, ce qu'il contient — mais un `Modal`, un menu ou la
|
|
165
|
+
liste d'un `Select` sont rendus sous `<body>`, hors de sa portée.
|
|
166
|
+
- **Tout ce qui est bleu n'est pas la marque.** Le statut `info` de `Banner`, `Toast` et
|
|
167
|
+
`Tooltip` reste bleu, comme le rouge d'une erreur ; les séries des graphiques ont leur
|
|
168
|
+
propre palette (`--color-chart-1` à `-8`).
|
|
169
|
+
|
|
170
|
+
Les props de couleur (`bgColor`, `checkedColor`, `progressColor`…) l'emportent toujours
|
|
171
|
+
sur la rampe, composant par composant.
|
|
172
|
+
|
|
173
|
+
**Anti-pattern** : passer `bgColor="bg-orange-600"` à chaque `Button` et vivre avec des
|
|
174
|
+
anneaux de focus et des barres de progression bleus partout ailleurs. La rampe repeint
|
|
175
|
+
tout le kit d'un coup. Dans une application qui a son propre jeton Tailwind
|
|
176
|
+
`primary`, ne pas compter sur lui : la librairie ne lit que `--color-synertech-primary-*`,
|
|
177
|
+
justement pour ne pas entrer en collision avec lui.
|
|
178
|
+
|
|
125
179
|
---
|
|
126
180
|
|
|
127
181
|
## Imports
|
|
@@ -348,6 +402,14 @@ import { Breadcrumb } from "@synertech/ui";
|
|
|
348
402
|
/>
|
|
349
403
|
```
|
|
350
404
|
|
|
405
|
+
Une adresse ne fait un lien que si elle est en `http:`, `https:`, `mailto:`,
|
|
406
|
+
`tel:` ou relative : le `href` d'un element de `Breadcrumb`, de `Header` (et
|
|
407
|
+
son `logoHref`), d'un `SidebarItem`, d'un `FooterLink` ou d'un
|
|
408
|
+
`FooterSocialLink`. Toute autre (`javascript:`, `data:`, `sms:`...) laisse le
|
|
409
|
+
texte sans lien, un `SidebarItem` devient un bouton, et la console le signale
|
|
410
|
+
une fois. Un `rel` passe a `FooterLink external` ou a `FooterSocialLink`
|
|
411
|
+
s'ajoute a `noopener noreferrer` au lieu de le remplacer.
|
|
412
|
+
|
|
351
413
|
### Pagination
|
|
352
414
|
|
|
353
415
|
```tsx
|
|
@@ -1232,15 +1294,18 @@ import { Divider } from "@synertech/ui";
|
|
|
1232
1294
|
import { Modal } from "@synertech/ui";
|
|
1233
1295
|
|
|
1234
1296
|
<Modal
|
|
1235
|
-
isOpen={isModalOpen}
|
|
1297
|
+
isOpen={isModalOpen} // ou `open`, le nom que prend `Drawer`
|
|
1236
1298
|
onClose={() => setModalOpen(false)}
|
|
1237
1299
|
title="Confirmer la suppression"
|
|
1238
1300
|
description="Cette action est irreversible."
|
|
1239
1301
|
icon={<TrashIcon />}
|
|
1240
1302
|
size="md" // "sm" | "md" | "lg" | "xl" | "full"
|
|
1241
|
-
|
|
1303
|
+
panelClassName="h-[78vh]" // classes du panneau ; `className` est celle du voile
|
|
1304
|
+
showSubmit={true} // true par defaut : passer false pour un pied maison
|
|
1242
1305
|
submitLabel="Supprimer"
|
|
1243
|
-
onSubmitClick={handleDelete}
|
|
1306
|
+
onSubmitClick={handleDelete} // false ou une erreur : la modale reste ouverte
|
|
1307
|
+
onSubmitError={(error) => setFailure(String(error))}
|
|
1308
|
+
closeOnSubmit={true} // false : l'application ferme elle-meme
|
|
1244
1309
|
showCancel={true}
|
|
1245
1310
|
cancelLabel="Annuler"
|
|
1246
1311
|
buttonsPosition="right" // "left" | "center" | "right"
|
|
@@ -1273,6 +1338,32 @@ dessus.
|
|
|
1273
1338
|
**Ne pas** reimplementer un focus trap local ni ajouter `role="dialog"` sur un
|
|
1274
1339
|
enfant : tout est deja fourni par le composant.
|
|
1275
1340
|
|
|
1341
|
+
**Boutons du pied.** `onSubmitClick` et `onCancelClick` sont appeles puis la
|
|
1342
|
+
modale se ferme. Une promesse est attendue : les deux boutons sont `disabled`
|
|
1343
|
+
entre-temps et celui qui a ete presse porte `aria-busy`. La modale **reste
|
|
1344
|
+
ouverte** si le gestionnaire renvoie (ou resout) `false`, ou s'il leve une
|
|
1345
|
+
erreur ; `onSubmitError` recoit cette erreur, et sans lui elle n'est pas
|
|
1346
|
+
interceptee. Un pied maison (`showSubmit={false}` + ses propres boutons) n'est
|
|
1347
|
+
donc plus necessaire pour valider un formulaire :
|
|
1348
|
+
|
|
1349
|
+
```tsx
|
|
1350
|
+
<Modal
|
|
1351
|
+
open={open}
|
|
1352
|
+
onClose={() => setOpen(false)}
|
|
1353
|
+
title="Nouvelle equipe"
|
|
1354
|
+
showCancel
|
|
1355
|
+
onSubmitClick={async () => {
|
|
1356
|
+
if (!validate()) return false; // la saisie reste a l'ecran
|
|
1357
|
+
await save(); // une erreur ici : la modale reste ouverte
|
|
1358
|
+
}}
|
|
1359
|
+
onSubmitError={(error) => setFailure(messageOf(error))}
|
|
1360
|
+
>
|
|
1361
|
+
```
|
|
1362
|
+
|
|
1363
|
+
Sans `title` ni `aria-label`, la modale affiche un titre de remplacement et un
|
|
1364
|
+
avertissement le signale une fois dans la console. `title=""` (ou pas de
|
|
1365
|
+
`title`) avec un `aria-label` donne un dialogue sans titre visible.
|
|
1366
|
+
|
|
1276
1367
|
### Tooltip
|
|
1277
1368
|
|
|
1278
1369
|
```tsx
|
|
@@ -1351,6 +1442,14 @@ import { HelpButton, WithHelpButton } from "@synertech/ui";
|
|
|
1351
1442
|
</WithHelpButton>
|
|
1352
1443
|
```
|
|
1353
1444
|
|
|
1445
|
+
Sans `markdown`, une chaine est du HTML reduit a sa mise en forme : titres,
|
|
1446
|
+
paragraphes, listes, liens, code, citations, tableaux. `<style>`, formulaires,
|
|
1447
|
+
champs, boutons et images sont retires, comme les attributs `class`, `style`,
|
|
1448
|
+
`id` et `name` ; un lien ne garde qu'une adresse `http:`, `https:`, `mailto:`,
|
|
1449
|
+
`tel:` ou relative. En Markdown non plus, une image (``) n'est pas
|
|
1450
|
+
affichee. Une aide qui a besoin d'autre chose (une image, un composant) se
|
|
1451
|
+
passe en noeud React, rendu tel quel.
|
|
1452
|
+
|
|
1354
1453
|
### Detachable
|
|
1355
1454
|
|
|
1356
1455
|
```tsx
|
package/README.md
CHANGED
|
@@ -117,6 +117,51 @@ stylesheet is included. Without the prop, the edit mode renders an explanatory
|
|
|
117
117
|
message instead of the editor.
|
|
118
118
|
|
|
119
119
|
|
|
120
|
+
### 6. Optional: the colour of your application
|
|
121
|
+
|
|
122
|
+
A primary button, a checked box, a selected row, an active tab, a focus ring, a link:
|
|
123
|
+
everything the components paint in the colour of the application reads one ramp of CSS
|
|
124
|
+
variables, `--color-synertech-primary-50` to `-950`. Out of the box it is Tailwind's
|
|
125
|
+
blue. Redefine it and the whole kit follows — no prop, no component to wrap:
|
|
126
|
+
|
|
127
|
+
```css
|
|
128
|
+
:root {
|
|
129
|
+
--color-synertech-primary-50: #f5f3ff;
|
|
130
|
+
--color-synertech-primary-100: #ede9fe;
|
|
131
|
+
--color-synertech-primary-200: #ddd6fe;
|
|
132
|
+
--color-synertech-primary-300: #c4b5fd;
|
|
133
|
+
--color-synertech-primary-400: #a78bfa;
|
|
134
|
+
--color-synertech-primary-500: #8b5cf6;
|
|
135
|
+
--color-synertech-primary-600: #7c3aed; /* the fill, and text on a light page */
|
|
136
|
+
--color-synertech-primary-700: #6d28d9; /* the fill under the pointer */
|
|
137
|
+
--color-synertech-primary-800: #5b21b6;
|
|
138
|
+
--color-synertech-primary-900: #4c1d95;
|
|
139
|
+
--color-synertech-primary-950: #2e1065;
|
|
140
|
+
|
|
141
|
+
/* What is written on the 600 and 700 fills. White by default. */
|
|
142
|
+
--color-synertech-on-primary: #fff;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- **Shape the ramp like Tailwind's**, lightest at 50 and darkest at 950. The components
|
|
147
|
+
use 50 and 100 for tinted backgrounds, 600 for fills and for text on a light page, 400
|
|
148
|
+
for text on a dark one, 500 for focus rings.
|
|
149
|
+
- **The 600 and 700 stops do two jobs**: they are the fills `--color-synertech-on-primary`
|
|
150
|
+
is written on, and they are text on a light page (a link, the label of an active tab).
|
|
151
|
+
White on a blue or a violet reads at 4.5:1 both ways. On a light hue it does not (3.6:1
|
|
152
|
+
on Tailwind's orange-600): put a darker stop at 600 — orange-700 there reads at 5.2:1
|
|
153
|
+
both ways. Turning `on-primary` dark instead keeps a bright fill readable, and leaves
|
|
154
|
+
the brand-coloured text of a light page as pale as that fill.
|
|
155
|
+
- **Declare it in plain CSS**, not inside a Tailwind `@theme` block. On `:root` it
|
|
156
|
+
repaints everything; on any other element, what is under it — but a `Modal`, a menu or
|
|
157
|
+
the list of a `Select` is rendered under `<body>`, out of that element's reach.
|
|
158
|
+
- **Not everything blue is the brand.** The `info` status of `Banner`, `Toast` and
|
|
159
|
+
`Tooltip` stays blue, like the red of an error; the chart series have their own palette
|
|
160
|
+
(`--color-chart-1` to `-8`).
|
|
161
|
+
|
|
162
|
+
The colour props (`bgColor`, `checkedColor`, `progressColor`…) still win over the ramp,
|
|
163
|
+
one component at a time.
|
|
164
|
+
|
|
120
165
|
## Usage
|
|
121
166
|
|
|
122
167
|
### Button
|
|
@@ -187,6 +232,11 @@ trigger on close, Tab/Shift+Tab contained, Escape to close, inert background and
|
|
|
187
232
|
nested dialog support. The same behaviour is available for custom dialogs
|
|
188
233
|
through the exported `useDialogA11y` hook.
|
|
189
234
|
|
|
235
|
+
A footer handler (`onSubmitClick`, `onCancelClick`) that returns a promise is
|
|
236
|
+
awaited, both buttons disabled meanwhile. The modal then closes — unless the
|
|
237
|
+
handler returns `false` or throws, which keeps it open: a form that does not
|
|
238
|
+
validate does not cost what was typed. `onSubmitError` receives the error.
|
|
239
|
+
|
|
190
240
|
### Translating built-in labels
|
|
191
241
|
|
|
192
242
|
Every string the library writes on its own — visible text, accessible names,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var He=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Je=(h,c)=>{for(var r in c)He(h,r,{get:c[r],enumerable:!0})},Qe=(h,c,r,g)=>{if(c&&typeof c=="object"||typeof c=="function")for(let d of Ze(c))!qe.call(h,d)&&d!==r&&He(h,d,{get:()=>c[d],enumerable:!(g=je(c,d))||g.enumerable});return h};var et=h=>Qe(He({},"__esModule",{value:!0}),h);var lt={};Je(lt,{AreaChart:()=>st});module.exports=et(lt);var s=require("react"),De=require("../../lib/cn.cjs"),$e=require("../../lib/i18n.cjs"),q=require("../chart/ChartAnnotations.cjs"),Ie=require("../chart/ChartAxis.cjs"),ge=require("../chart/ChartBrush.cjs"),Ke=require("../chart/ChartContainer.cjs"),Me=require("../chart/ChartGrid.cjs"),Oe=require("../chart/ChartLegend.cjs"),fe=require("../chart/ChartPatterns.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),pe=require("../chart/ChartTooltip.cjs"),I=require("../chart/palette.cjs"),S=require("../chart/utils/cartesian.cjs"),be=require("../chart/utils/data.cjs"),Ce=require("../chart/utils/decimate.cjs"),N=require("../chart/utils/format.cjs"),ye=require("../chart/utils/keyboard.cjs"),L=require("../chart/utils/path.cjs"),J=require("../chart/utils/scales.cjs"),ve=require("../chart/utils/stack.cjs"),_e=require("../chart/utils/ticks.cjs"),ze=require("../chart/utils/timestamp.cjs"),Ye=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),tt=.12,nt=.9,rt=10,ot=(0,s.memo)(function({bands:c,stacked:r,patterns:g,patternBaseId:d}){return(0,n.jsx)("g",{children:c.map(m=>(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:m.area,fill:(0,fe.patternFill)(g,d,m.slot,m.color),fillOpacity:r?nt:tt,stroke:"none"}),m.gap?(0,n.jsx)("path",{d:m.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,(0,n.jsx)("path",{d:m.edge,fill:"none",stroke:m.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),m.isolated.map(b=>(0,n.jsx)("circle",{cx:b.x,cy:b.y,r:3,fill:m.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${b.x}-${b.y}`))]},m.key))})});function at({width:h,height:c,data:r,resolvedSeries:g,x:d,y:m,grid:b,size:Q,curve:y,stack:A,baseline:B,connectNulls:R,referenceLines:K,annotations:w,annotationsLabel:ke,patterns:ee,patternBaseId:te,overlay:xe,maxPoints:x,brush:ne,onBrush:re,brushLabel:Pe,syncEnabled:M,margin:oe,tooltip:T,onPointClick:V,plotLabel:Le,formatValue:P,formatRaw:O,formatX:W}){let[X,G]=(0,s.useState)(null),i=X!==null&&X<r.length?X:null,[Se,Ae]=(0,s.useState)(null),Be=(0,Xe.useChartSync)(),u=M?Be:null,e=(0,s.useMemo)(()=>{let t=g.filter(E=>!E.hidden),o=t.map(E=>E.key),l=A!=="none",p=(0,ve.stackSeries)(r,o,A),ue=l?(0,ve.stackExtent)(p):(0,_e.extent)([...(0,be.collectAllValues)(r,o),B]),C=(0,S.buildCartesianGeometry)({width:h,height:c,data:r,x:d,y:m,bounds:ue,margin:oe,placement:"point",formatValue:P,formatX:W,defaultIncludeZero:!0}),Ve=C.categoryCenters,ce=C.valueScale,Ue=ce(l?0:B),Fe=t.map((E,Ee)=>{let F=r.map((j,Z)=>{let H=p[Z].segments[Ee];return{x:Ve[Z],y:H.value===null?Number.NaN:ce(H.end),defined:H.value!==null}}),Ne=r.map((j,Z)=>{let H=p[Z].segments[Ee];return{x:Ve[Z],y:H.value===null?Number.NaN:ce(l?H.start:B),defined:H.value!==null}}),he={connectNulls:R},me=x&&x>0&&F.length>x?(0,Ce.decimateIndices)(F,x):null,de=me?me.map(j=>F[j]):F,We=me?me.map(j=>Ne[j]):Ne;return x||(0,Ce.warnPointBudget)("AreaChart",F.length),{key:E.key,color:E.color,slot:E.slot,area:l?(0,L.buildAreaPath)(de,We,y,he):(0,L.buildAreaPath)(de,Ue,y,he),edge:(0,L.buildLinePath)(de,y,he),gap:l&&Ee>0?(0,L.buildLinePath)(We,y,he):"",isolated:(0,L.isolatedPoints)(de,R)}});return{visible:t,locate:(0,S.createCategoryLocator)(C),plot:(0,S.createPlotContext)({geometry:C,width:h,height:c,data:r,series:t,formatValue:P,formatX:W}),rows:p,stacked:l,xValues:C.xValues,positions:Ve,xTicks:C.categoryTicks,yTicks:C.valueTicks,valueScale:ce,innerWidth:C.innerWidth,innerHeight:C.innerHeight,margin:C.margin,bands:Fe}},[r,g,d,m,h,c,oe,y,A,B,R,x,P,W]),_=(0,s.useCallback)(t=>e.visible.map((o,l)=>{let p=(0,be.readNumber)(r[t],o.key),ue=e.rows[t].segments[l],C=p===null?"\u2014":A==="percent"?`${O(p)} (${P(ue.end-ue.start)})`:P(p);return{seriesKey:o.key,seriesLabel:(0,I.getSeriesLabel)(o),color:o.color,value:p,formattedValue:C,datum:r[t]}}),[r,e.visible,e.rows,A,P,O]),ae=u?u.brush:Se,se=(0,s.useCallback)(t=>{Ae(t),u?.setBrush(t),re?.(t)},[u,re]),f=(0,ge.useChartBrush)({enabled:ne,active:ae!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:se}),Re=(0,s.useCallback)(t=>{if(f.onPointerMove(t),T===!1||r.length===0)return;let o=t.currentTarget.getBoundingClientRect(),l=t.clientX-o.left-e.margin.left,p=(0,J.nearestIndex)(e.positions,l);G(p>=0?p:null),u?.setHovered(p>=0?e.xValues[p]:null)},[f,T,r.length,e.margin.left,e.positions,e.xValues,u]),le=(0,s.useCallback)(()=>{G(null),u?.setHovered(null)},[u]),v=(0,s.useCallback)(()=>{if(!V||i===null)return;let[t]=_(i);t&&V({...t,index:i,x:e.xValues[i]})},[V,i,_,e.xValues]),D=(0,s.useCallback)(t=>{if(r.length===0)return;let o=V&&i!==null&&e.visible.length>0;if((0,ye.pressChartMark)(t,o?v:null))return;f.onKeyDown(t,i);let l=(0,ye.chartCursorTarget)(t.key,i,r.length,"x");l!==void 0&&(t.preventDefault(),G(l),u?.setHovered(l===null?null:e.xValues[l]))},[r.length,i,f,u,e.xValues,e.visible.length,V,v]),we=(0,s.useCallback)(()=>{f.consumedClick()||v()},[f,v]),Te=i!==null||!u?.hovered?null:(()=>{let t=(0,J.toKey)(u.hovered),o=e.xValues.findIndex(l=>(0,J.toKey)(l)===t);return o<0?null:o})(),k=i??Te,z=i===null?null:_(i),Y=k===null?[]:e.visible.map((t,o)=>{let l=e.rows[k].segments[o];return l.value===null?null:{key:t.key,color:t.color,y:e.valueScale(l.end)}}).filter(t=>t!==null),U=f.dragging??ae,$=(()=>{if(!U)return null;let t=e.locate(U.from),o=e.locate(U.to);return t===null||o===null?null:{from:t,to:o}})(),ie=(0,S.splitOverlay)(xe),a=i===null||z===null?null:{x:e.xValues[i],xLabel:W(e.xValues[i],i),index:i,points:z};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:c,role:"img","aria-label":Le??[e.visible.map(t=>(0,I.getSeriesLabel)(t)).join(", "),(0,q.describeAnnotations)(w,ke)].filter(Boolean).join(". "),tabIndex:0,className:(0,De.cn)(Ye.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",ne&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:Re,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:le,onKeyDown:D,onBlur:le,onClick:we,children:[ee?(0,n.jsx)(fe.ChartPatternDefs,{id:te,entries:g.map(t=>({slot:t.slot,color:t.color}))}):null,(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Me.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),w?(0,n.jsx)(q.ChartAnnotationLayer,{layer:"under",annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,$?(0,n.jsx)(ge.ChartBrushLayer,{from:$.from,to:$.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:Pe}):null,ie.under?.(e.plot),(0,n.jsx)(ot,{bands:e.bands,stacked:e.stacked,patterns:ee&&e.stacked,patternBaseId:te}),w?(0,n.jsx)(q.ChartAnnotationLayer,{annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,K?.map(t=>{let o=e.valueScale(t.value),l=o<rt?o+12:o-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,n.jsx)("text",{x:e.innerWidth,y:l,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ie.over?.(e.plot),k!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.positions[k],y1:0,x2:e.positions[k],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:i===null?"3 3":void 0}),Y.map(t=>(0,n.jsx)("circle",{cx:e.positions[k],cy:t.y,r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.key))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:d.hidden?null:(0,n.jsx)(Ie.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:Q})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:m?.hidden?null:(0,n.jsx)(Ie.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:m?.label,size:Q})})]}),a&&T!==!1?(0,n.jsx)(pe.ChartTooltip,{x:e.margin.left+e.positions[a.index],y:e.margin.top+(Y.length>0?Math.min(...Y.map(t=>t.y)):e.innerHeight/2),containerWidth:h,children:typeof T=="function"?T(a):(0,n.jsx)(pe.ChartTooltipContent,{title:a.xLabel,points:a.points})}):null]})}function st({data:h,series:c,x:r,y:g,height:d=240,width:m,size:b="md",grid:Q="y",legend:y,tooltip:A=!0,tableView:B=!1,emphasis:R,title:K,description:w,loading:ke=!1,emptyState:ee,error:te=!1,errorState:xe,onRetry:x,actions:ne,onPointClick:re,curve:Pe="monotone",stack:M="none",baseline:oe=0,connectNulls:T=!1,referenceLines:V,annotations:Le,overlay:P,patterns:O=!1,legendToggle:W=!0,maxPoints:X,brush:G=!1,onBrush:i,brushLabel:Se,sync:Ae=!0,margin:Be,locale:u,plotLabel:e,className:_,...ae}){let se=(0,$e.useUILabels)(),[f,Re]=(0,s.useState)(()=>new Set),le=(0,s.useId)(),v=(0,s.useMemo)(()=>c.map((a,t)=>({...a,slot:t,hidden:a.hidden||f.has(a.key),color:(0,I.resolveSeriesColor)(a,t,R)})),[c,f,R]),D=M==="percent",we=(0,s.useMemo)(()=>D?{domain:[0,100],...g}:g,[D,g]),Te=(0,s.useMemo)(()=>g?.format??(D?a=>(0,N.formatPercent)(a,{locale:u,alreadyScaled:!0,maximumFractionDigits:0}):a=>(0,N.formatAuto)(a,u)),[g?.format,D,u]),k=(0,s.useMemo)(()=>a=>(0,N.formatAuto)(a,u),[u]),z=(0,s.useMemo)(()=>r.format??(a=>r.scale==="time"?(0,ze.formatTimeValue)(a,u):(0,N.formatXValue)(a,u)),[r.format,r.scale,u]),Y=(0,s.useCallback)(a=>{Re(t=>{let o=new Set(t);return o.has(a)?o.delete(a):o.add(a),o})},[]),U=y===void 0?c.length>=2:y!==!1,$=typeof y=="string"?y:"bottom",ie=v.filter(a=>!a.hidden).length;return(0,n.jsx)(Ke.ChartContainer,{title:K,description:w,height:d,width:m,size:b,loading:ke,empty:h.length===0||ie===0,emptyState:ee,error:te,errorState:xe,onRetry:x,actions:ne,tableView:B,legendPosition:$,legend:U?(0,n.jsx)(Oe.ChartLegend,{items:(0,I.toLegendItems)(v,R,O&&M!=="none"),position:$,marker:"rect",size:b,onToggle:W?Y:void 0}):void 0,table:B?(0,n.jsx)(Ge.ChartTableView,{data:h,series:v,xKey:r.key,xLabel:r.label??r.key,formatX:z,formatValue:k,caption:typeof K=="string"?K:void 0}):void 0,className:_,...ae,children:({width:a})=>(0,n.jsx)(at,{width:a,height:d,data:h,resolvedSeries:v,x:r,y:we,grid:Q,size:b,curve:Pe,stack:M,baseline:oe,connectNulls:T,referenceLines:V,annotations:Le,annotationsLabel:se.chartAnnotations,patterns:O,patternBaseId:le,overlay:P,maxPoints:X,brush:G,onBrush:i,brushLabel:Se??se.chartBrush,syncEnabled:Ae,margin:Be,tooltip:A,onPointClick:re,plotLabel:e,formatValue:Te,formatRaw:k,formatX:z})})}0&&(module.exports={AreaChart});
|
|
1
|
+
"use strict";"use client";var He=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Je=(h,c)=>{for(var r in c)He(h,r,{get:c[r],enumerable:!0})},Qe=(h,c,r,g)=>{if(c&&typeof c=="object"||typeof c=="function")for(let d of Ze(c))!qe.call(h,d)&&d!==r&&He(h,d,{get:()=>c[d],enumerable:!(g=je(c,d))||g.enumerable});return h};var et=h=>Qe(He({},"__esModule",{value:!0}),h);var lt={};Je(lt,{AreaChart:()=>st});module.exports=et(lt);var s=require("react"),De=require("../../lib/cn.cjs"),$e=require("../../lib/i18n.cjs"),q=require("../chart/ChartAnnotations.cjs"),Ie=require("../chart/ChartAxis.cjs"),ge=require("../chart/ChartBrush.cjs"),Ke=require("../chart/ChartContainer.cjs"),Me=require("../chart/ChartGrid.cjs"),Oe=require("../chart/ChartLegend.cjs"),fe=require("../chart/ChartPatterns.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),pe=require("../chart/ChartTooltip.cjs"),I=require("../chart/palette.cjs"),S=require("../chart/utils/cartesian.cjs"),Ce=require("../chart/utils/data.cjs"),be=require("../chart/utils/decimate.cjs"),N=require("../chart/utils/format.cjs"),ye=require("../chart/utils/keyboard.cjs"),L=require("../chart/utils/path.cjs"),J=require("../chart/utils/scales.cjs"),ve=require("../chart/utils/stack.cjs"),_e=require("../chart/utils/ticks.cjs"),ze=require("../chart/utils/timestamp.cjs"),Ye=require("../chart/utils/touch.cjs"),n=require("react/jsx-runtime"),tt=.12,nt=.9,rt=10,ot=(0,s.memo)(function({bands:c,stacked:r,patterns:g,patternBaseId:d}){return(0,n.jsx)("g",{children:c.map(m=>(0,n.jsxs)("g",{children:[(0,n.jsx)("path",{d:m.area,fill:(0,fe.patternFill)(g,d,m.slot,m.color),fillOpacity:r?nt:tt,stroke:"none"}),m.gap?(0,n.jsx)("path",{d:m.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,(0,n.jsx)("path",{d:m.edge,fill:"none",stroke:m.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),m.isolated.map(C=>(0,n.jsx)("circle",{cx:C.x,cy:C.y,r:3,fill:m.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${C.x}-${C.y}`))]},m.key))})});function at({width:h,height:c,data:r,resolvedSeries:g,x:d,y:m,grid:C,size:Q,curve:y,stack:A,baseline:B,connectNulls:R,referenceLines:K,annotations:w,annotationsLabel:ke,patterns:ee,patternBaseId:te,overlay:xe,maxPoints:x,brush:ne,onBrush:re,brushLabel:Pe,syncEnabled:M,margin:oe,tooltip:T,onPointClick:V,plotLabel:Le,formatValue:P,formatRaw:O,formatX:W}){let[X,G]=(0,s.useState)(null),i=X!==null&&X<r.length?X:null,[Se,Ae]=(0,s.useState)(null),Be=(0,Xe.useChartSync)(),u=M?Be:null,e=(0,s.useMemo)(()=>{let t=g.filter(E=>!E.hidden),o=t.map(E=>E.key),l=A!=="none",p=(0,ve.stackSeries)(r,o,A),ue=l?(0,ve.stackExtent)(p):(0,_e.extent)([...(0,Ce.collectAllValues)(r,o),B]),b=(0,S.buildCartesianGeometry)({width:h,height:c,data:r,x:d,y:m,bounds:ue,margin:oe,placement:"point",formatValue:P,formatX:W,defaultIncludeZero:!0}),Ve=b.categoryCenters,ce=b.valueScale,Ue=ce(l?0:B),Fe=t.map((E,Ee)=>{let F=r.map((j,Z)=>{let H=p[Z].segments[Ee];return{x:Ve[Z],y:H.value===null?Number.NaN:ce(H.end),defined:H.value!==null}}),Ne=r.map((j,Z)=>{let H=p[Z].segments[Ee];return{x:Ve[Z],y:H.value===null?Number.NaN:ce(l?H.start:B),defined:H.value!==null}}),he={connectNulls:R},me=x&&x>0&&F.length>x?(0,be.decimateIndices)(F,x):null,de=me?me.map(j=>F[j]):F,We=me?me.map(j=>Ne[j]):Ne;return x||(0,be.warnPointBudget)("AreaChart",F.length),{key:E.key,color:E.color,slot:E.slot,area:l?(0,L.buildAreaPath)(de,We,y,he):(0,L.buildAreaPath)(de,Ue,y,he),edge:(0,L.buildLinePath)(de,y,he),gap:l&&Ee>0?(0,L.buildLinePath)(We,y,he):"",isolated:(0,L.isolatedPoints)(de,R)}});return{visible:t,locate:(0,S.createCategoryLocator)(b),plot:(0,S.createPlotContext)({geometry:b,width:h,height:c,data:r,series:t,formatValue:P,formatX:W}),rows:p,stacked:l,xValues:b.xValues,positions:Ve,xTicks:b.categoryTicks,yTicks:b.valueTicks,valueScale:ce,innerWidth:b.innerWidth,innerHeight:b.innerHeight,margin:b.margin,bands:Fe}},[r,g,d,m,h,c,oe,y,A,B,R,x,P,W]),_=(0,s.useCallback)(t=>e.visible.map((o,l)=>{let p=(0,Ce.readNumber)(r[t],o.key),ue=e.rows[t].segments[l],b=p===null?"\u2014":A==="percent"?`${O(p)} (${P(ue.end-ue.start)})`:P(p);return{seriesKey:o.key,seriesLabel:(0,I.getSeriesLabel)(o),color:o.color,value:p,formattedValue:b,datum:r[t]}}),[r,e.visible,e.rows,A,P,O]),ae=u?u.brush:Se,se=(0,s.useCallback)(t=>{Ae(t),u?.setBrush(t),re?.(t)},[u,re]),f=(0,ge.useChartBrush)({enabled:ne,active:ae!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:se}),Re=(0,s.useCallback)(t=>{if(f.onPointerMove(t),T===!1||r.length===0)return;let o=t.currentTarget.getBoundingClientRect(),l=t.clientX-o.left-e.margin.left,p=(0,J.nearestIndex)(e.positions,l);G(p>=0?p:null),u?.setHovered(p>=0?e.xValues[p]:null)},[f,T,r.length,e.margin.left,e.positions,e.xValues,u]),le=(0,s.useCallback)(()=>{G(null),u?.setHovered(null)},[u]),v=(0,s.useCallback)(()=>{if(!V||i===null)return;let[t]=_(i);t&&V({...t,index:i,x:e.xValues[i]})},[V,i,_,e.xValues]),D=(0,s.useCallback)(t=>{if(r.length===0)return;let o=V&&i!==null&&e.visible.length>0;if((0,ye.pressChartMark)(t,o?v:null))return;f.onKeyDown(t,i);let l=(0,ye.chartCursorTarget)(t.key,i,r.length,"x");l!==void 0&&(t.preventDefault(),G(l),u?.setHovered(l===null?null:e.xValues[l]))},[r.length,i,f,u,e.xValues,e.visible.length,V,v]),we=(0,s.useCallback)(()=>{f.consumedClick()||v()},[f,v]),Te=i!==null||!u?.hovered?null:(()=>{let t=(0,J.toKey)(u.hovered),o=e.xValues.findIndex(l=>(0,J.toKey)(l)===t);return o<0?null:o})(),k=i??Te,z=i===null?null:_(i),Y=k===null?[]:e.visible.map((t,o)=>{let l=e.rows[k].segments[o];return l.value===null?null:{key:t.key,color:t.color,y:e.valueScale(l.end)}}).filter(t=>t!==null),U=f.dragging??ae,$=(()=>{if(!U)return null;let t=e.locate(U.from),o=e.locate(U.to);return t===null||o===null?null:{from:t,to:o}})(),ie=(0,S.splitOverlay)(xe),a=i===null||z===null?null:{x:e.xValues[i],xLabel:W(e.xValues[i],i),index:i,points:z};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("svg",{width:h,height:c,role:"img","aria-label":Le??[e.visible.map(t=>(0,I.getSeriesLabel)(t)).join(", "),(0,q.describeAnnotations)(w,ke)].filter(Boolean).join(". "),tabIndex:0,className:(0,De.cn)(Ye.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ne&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:Re,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:le,onKeyDown:D,onBlur:le,onClick:we,children:[ee?(0,n.jsx)(fe.ChartPatternDefs,{id:te,entries:g.map(t=>({slot:t.slot,color:t.color}))}):null,(0,n.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,n.jsx)(Me.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:C==="y"||C==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:C==="x"||C==="both"?e.xTicks.map(t=>t.offset):void 0}),w?(0,n.jsx)(q.ChartAnnotationLayer,{layer:"under",annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,$?(0,n.jsx)(ge.ChartBrushLayer,{from:$.from,to:$.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:Pe}):null,ie.under?.(e.plot),(0,n.jsx)(ot,{bands:e.bands,stacked:e.stacked,patterns:ee&&e.stacked,patternBaseId:te}),w?(0,n.jsx)(q.ChartAnnotationLayer,{annotations:w,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,K?.map(t=>{let o=e.valueScale(t.value),l=o<rt?o+12:o-4;return(0,n.jsxs)("g",{children:[(0,n.jsx)("line",{x1:0,y1:o,x2:e.innerWidth,y2:o,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,n.jsx)("text",{x:e.innerWidth,y:l,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),ie.over?.(e.plot),k!==null?(0,n.jsxs)("g",{"aria-hidden":"true",children:[(0,n.jsx)("line",{x1:e.positions[k],y1:0,x2:e.positions[k],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:i===null?"3 3":void 0}),Y.map(t=>(0,n.jsx)("circle",{cx:e.positions[k],cy:t.y,r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.key))]}):null]}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:d.hidden?null:(0,n.jsx)(Ie.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:d.label,size:Q})}),(0,n.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:m?.hidden?null:(0,n.jsx)(Ie.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:m?.label,size:Q})})]}),a&&T!==!1?(0,n.jsx)(pe.ChartTooltip,{x:e.margin.left+e.positions[a.index],y:e.margin.top+(Y.length>0?Math.min(...Y.map(t=>t.y)):e.innerHeight/2),containerWidth:h,children:typeof T=="function"?T(a):(0,n.jsx)(pe.ChartTooltipContent,{title:a.xLabel,points:a.points})}):null]})}function st({data:h,series:c,x:r,y:g,height:d=240,width:m,size:C="md",grid:Q="y",legend:y,tooltip:A=!0,tableView:B=!1,emphasis:R,title:K,description:w,loading:ke=!1,emptyState:ee,error:te=!1,errorState:xe,onRetry:x,actions:ne,onPointClick:re,curve:Pe="monotone",stack:M="none",baseline:oe=0,connectNulls:T=!1,referenceLines:V,annotations:Le,overlay:P,patterns:O=!1,legendToggle:W=!0,maxPoints:X,brush:G=!1,onBrush:i,brushLabel:Se,sync:Ae=!0,margin:Be,locale:u,plotLabel:e,className:_,...ae}){let se=(0,$e.useUILabels)(),[f,Re]=(0,s.useState)(()=>new Set),le=(0,s.useId)(),v=(0,s.useMemo)(()=>c.map((a,t)=>({...a,slot:t,hidden:a.hidden||f.has(a.key),color:(0,I.resolveSeriesColor)(a,t,R)})),[c,f,R]),D=M==="percent",we=(0,s.useMemo)(()=>D?{domain:[0,100],...g}:g,[D,g]),Te=(0,s.useMemo)(()=>g?.format??(D?a=>(0,N.formatPercent)(a,{locale:u,alreadyScaled:!0,maximumFractionDigits:0}):a=>(0,N.formatAuto)(a,u)),[g?.format,D,u]),k=(0,s.useMemo)(()=>a=>(0,N.formatAuto)(a,u),[u]),z=(0,s.useMemo)(()=>r.format??(a=>r.scale==="time"?(0,ze.formatTimeValue)(a,u):(0,N.formatXValue)(a,u)),[r.format,r.scale,u]),Y=(0,s.useCallback)(a=>{Re(t=>{let o=new Set(t);return o.has(a)?o.delete(a):o.add(a),o})},[]),U=y===void 0?c.length>=2:y!==!1,$=typeof y=="string"?y:"bottom",ie=v.filter(a=>!a.hidden).length;return(0,n.jsx)(Ke.ChartContainer,{title:K,description:w,height:d,width:m,size:C,loading:ke,empty:h.length===0||ie===0,emptyState:ee,error:te,errorState:xe,onRetry:x,actions:ne,tableView:B,legendPosition:$,legend:U?(0,n.jsx)(Oe.ChartLegend,{items:(0,I.toLegendItems)(v,R,O&&M!=="none"),position:$,marker:"rect",size:C,onToggle:W?Y:void 0}):void 0,table:B?(0,n.jsx)(Ge.ChartTableView,{data:h,series:v,xKey:r.key,xLabel:r.label??r.key,formatX:z,formatValue:k,caption:typeof K=="string"?K:void 0}):void 0,className:_,...ae,children:({width:a})=>(0,n.jsx)(at,{width:a,height:d,data:h,resolvedSeries:v,x:r,y:we,grid:Q,size:C,curve:Pe,stack:M,baseline:oe,connectNulls:T,referenceLines:V,annotations:Le,annotationsLabel:se.chartAnnotations,patterns:O,patternBaseId:le,overlay:P,maxPoints:X,brush:G,onBrush:i,brushLabel:Se??se.chartBrush,syncEnabled:Ae,margin:Be,tooltip:A,onPointClick:re,plotLabel:e,formatValue:Te,formatRaw:k,formatX:z})})}0&&(module.exports={AreaChart});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as Ie,useCallback as P,useId as Ne,useMemo as N,useState as xe}from"react";import{cn as We}from"../../lib/cn.js";import{useUILabels as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as $e}from"../chart/ChartAnnotations.js";import{ChartAxis as Ae}from"../chart/ChartAxis.js";import{ChartBrushLayer as Ke,useChartBrush as Me}from"../chart/ChartBrush.js";import{ChartContainer as Oe}from"../chart/ChartContainer.js";import{ChartGrid as Xe}from"../chart/ChartGrid.js";import{ChartLegend as Ge}from"../chart/ChartLegend.js";import{ChartPatternDefs as _e,patternFill as ze}from"../chart/ChartPatterns.js";import{useChartSync as Ye}from"../chart/ChartSync.js";import{ChartTableView as Ue}from"../chart/ChartTableView.js";import{ChartTooltip as Fe,ChartTooltipContent as je}from"../chart/ChartTooltip.js";import{getSeriesLabel as Be,resolveSeriesColor as Ze,toLegendItems as qe}from"../chart/palette.js";import{buildCartesianGeometry as Je,createCategoryLocator as Qe,createPlotContext as et,splitOverlay as tt}from"../chart/utils/cartesian.js";import{collectAllValues as nt,readNumber as rt}from"../chart/utils/data.js";import{decimateIndices as ot,warnPointBudget as at}from"../chart/utils/decimate.js";import{formatAuto as Re,formatPercent as st,formatXValue as lt}from"../chart/utils/format.js";import{chartCursorTarget as it,pressChartMark as ut}from"../chart/utils/keyboard.js";import{buildAreaPath as we,buildLinePath as Te,isolatedPoints as ct}from"../chart/utils/path.js";import{nearestIndex as ht,toKey as Ve}from"../chart/utils/scales.js";import{stackExtent as mt,stackSeries as dt}from"../chart/utils/stack.js";import{extent as gt}from"../chart/utils/ticks.js";import{formatTimeValue as ft}from"../chart/utils/timestamp.js";import{CHART_TOUCH as pt}from"../chart/utils/touch.js";import{Fragment as xt,jsx as a,jsxs as W}from"react/jsx-runtime";var bt=.12,Ct=.9,yt=10,vt=Ie(function({bands:p,stacked:r,patterns:g,patternBaseId:C}){return a("g",{children:p.map(u=>W("g",{children:[a("path",{d:u.area,fill:ze(g,C,u.slot,u.color),fillOpacity:r?Ct:bt,stroke:"none"}),u.gap?a("path",{d:u.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a("path",{d:u.edge,fill:"none",stroke:u.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),u.isolated.map(m=>a("circle",{cx:m.x,cy:m.y,r:3,fill:u.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${m.x}-${m.y}`))]},u.key))})});function kt({width:f,height:p,data:r,resolvedSeries:g,x:C,y:u,grid:m,size:j,curve:b,stack:L,baseline:S,connectNulls:A,referenceLines:D,annotations:B,annotationsLabel:ce,patterns:Z,patternBaseId:q,overlay:he,maxPoints:k,brush:J,onBrush:Q,brushLabel:me,syncEnabled:$,margin:ee,tooltip:R,onPointClick:w,plotLabel:de,formatValue:x,formatRaw:K,formatX:E}){let[M,O]=xe(null),l=M!==null&&M<r.length?M:null,[ge,fe]=xe(null),pe=Ye(),i=$?pe:null,e=N(()=>{let t=g.filter(T=>!T.hidden),n=t.map(T=>T.key),s=L!=="none",h=dt(r,n,L),ae=s?mt(h):gt([...nt(r,n),S]),d=Je({width:f,height:p,data:r,x:C,y:u,bounds:ae,margin:ee,placement:"point",formatValue:x,formatX:E,defaultIncludeZero:!0}),ve=d.categoryCenters,se=d.valueScale,Ee=se(s?0:S),He=t.map((T,ke)=>{let Y=r.map((U,F)=>{let V=h[F].segments[ke];return{x:ve[F],y:V.value===null?Number.NaN:se(V.end),defined:V.value!==null}}),Pe=r.map((U,F)=>{let V=h[F].segments[ke];return{x:ve[F],y:V.value===null?Number.NaN:se(s?V.start:S),defined:V.value!==null}}),le={connectNulls:A},ie=k&&k>0&&Y.length>k?ot(Y,k):null,ue=ie?ie.map(U=>Y[U]):Y,Le=ie?ie.map(U=>Pe[U]):Pe;return k||at("AreaChart",Y.length),{key:T.key,color:T.color,slot:T.slot,area:s?we(ue,Le,b,le):we(ue,Ee,b,le),edge:Te(ue,b,le),gap:s&&ke>0?Te(Le,b,le):"",isolated:ct(ue,A)}});return{visible:t,locate:Qe(d),plot:et({geometry:d,width:f,height:p,data:r,series:t,formatValue:x,formatX:E}),rows:h,stacked:s,xValues:d.xValues,positions:ve,xTicks:d.categoryTicks,yTicks:d.valueTicks,valueScale:se,innerWidth:d.innerWidth,innerHeight:d.innerHeight,margin:d.margin,bands:He}},[r,g,C,u,f,p,ee,b,L,S,A,k,x,E]),X=P(t=>e.visible.map((n,s)=>{let h=rt(r[t],n.key),ae=e.rows[t].segments[s],d=h===null?"\u2014":L==="percent"?`${K(h)} (${x(ae.end-ae.start)})`:x(h);return{seriesKey:n.key,seriesLabel:Be(n),color:n.color,value:h,formattedValue:d,datum:r[t]}}),[r,e.visible,e.rows,L,x,K]),te=i?i.brush:ge,ne=P(t=>{fe(t),i?.setBrush(t),Q?.(t)},[i,Q]),c=Me({enabled:J,active:te!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ne}),be=P(t=>{if(c.onPointerMove(t),R===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),s=t.clientX-n.left-e.margin.left,h=ht(e.positions,s);O(h>=0?h:null),i?.setHovered(h>=0?e.xValues[h]:null)},[c,R,r.length,e.margin.left,e.positions,e.xValues,i]),re=P(()=>{O(null),i?.setHovered(null)},[i]),y=P(()=>{if(!w||l===null)return;let[t]=X(l);t&&w({...t,index:l,x:e.xValues[l]})},[w,l,X,e.xValues]),H=P(t=>{if(r.length===0)return;let n=w&&l!==null&&e.visible.length>0;if(ut(t,n?y:null))return;c.onKeyDown(t,l);let s=it(t.key,l,r.length,"x");s!==void 0&&(t.preventDefault(),O(s),i?.setHovered(s===null?null:e.xValues[s]))},[r.length,l,c,i,e.xValues,e.visible.length,w,y]),Ce=P(()=>{c.consumedClick()||y()},[c,y]),ye=l!==null||!i?.hovered?null:(()=>{let t=Ve(i.hovered),n=e.xValues.findIndex(s=>Ve(s)===t);return n<0?null:n})(),v=l??ye,G=l===null?null:X(l),_=v===null?[]:e.visible.map((t,n)=>{let s=e.rows[v].segments[n];return s.value===null?null:{key:t.key,color:t.color,y:e.valueScale(s.end)}}).filter(t=>t!==null),z=c.dragging??te,I=(()=>{if(!z)return null;let t=e.locate(z.from),n=e.locate(z.to);return t===null||n===null?null:{from:t,to:n}})(),oe=tt(he),o=l===null||G===null?null:{x:e.xValues[l],xLabel:E(e.xValues[l],l),index:l,points:G};return W(xt,{children:[W("svg",{width:f,height:p,role:"img","aria-label":de??[e.visible.map(t=>Be(t)).join(", "),$e(B,ce)].filter(Boolean).join(". "),tabIndex:0,className:We(pt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",J&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:be,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:re,onKeyDown:H,onBlur:re,onClick:Ce,children:[Z?a(_e,{id:q,entries:g.map(t=>({slot:t.slot,color:t.color}))}):null,W("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Xe,{width:e.innerWidth,height:e.innerHeight,horizontal:m==="y"||m==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:m==="x"||m==="both"?e.xTicks.map(t=>t.offset):void 0}),B?a(Se,{layer:"under",annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,I?a(Ke,{from:I.from,to:I.to,width:e.innerWidth,height:e.innerHeight,live:c.dragging!==null,label:me}):null,oe.under?.(e.plot),a(vt,{bands:e.bands,stacked:e.stacked,patterns:Z&&e.stacked,patternBaseId:q}),B?a(Se,{annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,D?.map(t=>{let n=e.valueScale(t.value),s=n<yt?n+12:n-4;return W("g",{children:[a("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?a("text",{x:e.innerWidth,y:s,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),oe.over?.(e.plot),v!==null?W("g",{"aria-hidden":"true",children:[a("line",{x1:e.positions[v],y1:0,x2:e.positions[v],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),_.map(t=>a("circle",{cx:e.positions[v],cy:t.y,r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.key))]}):null]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:C.hidden?null:a(Ae,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:C.label,size:j})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:u?.hidden?null:a(Ae,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:u?.label,size:j})})]}),o&&R!==!1?a(Fe,{x:e.margin.left+e.positions[o.index],y:e.margin.top+(_.length>0?Math.min(..._.map(t=>t.y)):e.innerHeight/2),containerWidth:f,children:typeof R=="function"?R(o):a(je,{title:o.xLabel,points:o.points})}):null]})}function Ft({data:f,series:p,x:r,y:g,height:C=240,width:u,size:m="md",grid:j="y",legend:b,tooltip:L=!0,tableView:S=!1,emphasis:A,title:D,description:B,loading:ce=!1,emptyState:Z,error:q=!1,errorState:he,onRetry:k,actions:J,onPointClick:Q,curve:me="monotone",stack:$="none",baseline:ee=0,connectNulls:R=!1,referenceLines:w,annotations:de,overlay:x,patterns:K=!1,legendToggle:E=!0,maxPoints:M,brush:O=!1,onBrush:l,brushLabel:ge,sync:fe=!0,margin:pe,locale:i,plotLabel:e,className:X,...te}){let ne=De(),[c,be]=xe(()=>new Set),re=Ne(),y=N(()=>p.map((o,t)=>({...o,slot:t,hidden:o.hidden||c.has(o.key),color:Ze(o,t,A)})),[p,c,A]),H=$==="percent",Ce=N(()=>H?{domain:[0,100],...g}:g,[H,g]),ye=N(()=>g?.format??(H?o=>st(o,{locale:i,alreadyScaled:!0,maximumFractionDigits:0}):o=>Re(o,i)),[g?.format,H,i]),v=N(()=>o=>Re(o,i),[i]),G=N(()=>r.format??(o=>r.scale==="time"?ft(o,i):lt(o,i)),[r.format,r.scale,i]),_=P(o=>{be(t=>{let n=new Set(t);return n.has(o)?n.delete(o):n.add(o),n})},[]),z=b===void 0?p.length>=2:b!==!1,I=typeof b=="string"?b:"bottom",oe=y.filter(o=>!o.hidden).length;return a(Oe,{title:D,description:B,height:C,width:u,size:m,loading:ce,empty:f.length===0||oe===0,emptyState:Z,error:q,errorState:he,onRetry:k,actions:J,tableView:S,legendPosition:I,legend:z?a(Ge,{items:qe(y,A,K&&$!=="none"),position:I,marker:"rect",size:m,onToggle:E?_:void 0}):void 0,table:S?a(Ue,{data:f,series:y,xKey:r.key,xLabel:r.label??r.key,formatX:G,formatValue:v,caption:typeof D=="string"?D:void 0}):void 0,className:X,...te,children:({width:o})=>a(kt,{width:o,height:C,data:f,resolvedSeries:y,x:r,y:Ce,grid:j,size:m,curve:me,stack:$,baseline:ee,connectNulls:R,referenceLines:w,annotations:de,annotationsLabel:ne.chartAnnotations,patterns:K,patternBaseId:re,overlay:x,maxPoints:M,brush:O,onBrush:l,brushLabel:ge??ne.chartBrush,syncEnabled:fe,margin:pe,tooltip:L,onPointClick:Q,plotLabel:e,formatValue:ye,formatRaw:v,formatX:G})})}export{Ft as AreaChart};
|
|
1
|
+
"use client";import{memo as Ie,useCallback as P,useId as Ne,useMemo as N,useState as xe}from"react";import{cn as We}from"../../lib/cn.js";import{useUILabels as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as $e}from"../chart/ChartAnnotations.js";import{ChartAxis as Ae}from"../chart/ChartAxis.js";import{ChartBrushLayer as Ke,useChartBrush as Me}from"../chart/ChartBrush.js";import{ChartContainer as Oe}from"../chart/ChartContainer.js";import{ChartGrid as Xe}from"../chart/ChartGrid.js";import{ChartLegend as Ge}from"../chart/ChartLegend.js";import{ChartPatternDefs as _e,patternFill as ze}from"../chart/ChartPatterns.js";import{useChartSync as Ye}from"../chart/ChartSync.js";import{ChartTableView as Ue}from"../chart/ChartTableView.js";import{ChartTooltip as Fe,ChartTooltipContent as je}from"../chart/ChartTooltip.js";import{getSeriesLabel as Be,resolveSeriesColor as Ze,toLegendItems as qe}from"../chart/palette.js";import{buildCartesianGeometry as Je,createCategoryLocator as Qe,createPlotContext as et,splitOverlay as tt}from"../chart/utils/cartesian.js";import{collectAllValues as nt,readNumber as rt}from"../chart/utils/data.js";import{decimateIndices as ot,warnPointBudget as at}from"../chart/utils/decimate.js";import{formatAuto as Re,formatPercent as st,formatXValue as lt}from"../chart/utils/format.js";import{chartCursorTarget as it,pressChartMark as ut}from"../chart/utils/keyboard.js";import{buildAreaPath as we,buildLinePath as Te,isolatedPoints as ct}from"../chart/utils/path.js";import{nearestIndex as ht,toKey as Ve}from"../chart/utils/scales.js";import{stackExtent as mt,stackSeries as dt}from"../chart/utils/stack.js";import{extent as gt}from"../chart/utils/ticks.js";import{formatTimeValue as ft}from"../chart/utils/timestamp.js";import{CHART_TOUCH as pt}from"../chart/utils/touch.js";import{Fragment as xt,jsx as a,jsxs as W}from"react/jsx-runtime";var Ct=.12,bt=.9,yt=10,vt=Ie(function({bands:p,stacked:r,patterns:g,patternBaseId:b}){return a("g",{children:p.map(u=>W("g",{children:[a("path",{d:u.area,fill:ze(g,b,u.slot,u.color),fillOpacity:r?bt:Ct,stroke:"none"}),u.gap?a("path",{d:u.gap,fill:"none",strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a("path",{d:u.edge,fill:"none",stroke:u.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),u.isolated.map(m=>a("circle",{cx:m.x,cy:m.y,r:3,fill:u.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${m.x}-${m.y}`))]},u.key))})});function kt({width:f,height:p,data:r,resolvedSeries:g,x:b,y:u,grid:m,size:j,curve:C,stack:L,baseline:S,connectNulls:A,referenceLines:D,annotations:B,annotationsLabel:ce,patterns:Z,patternBaseId:q,overlay:he,maxPoints:k,brush:J,onBrush:Q,brushLabel:me,syncEnabled:$,margin:ee,tooltip:R,onPointClick:w,plotLabel:de,formatValue:x,formatRaw:K,formatX:E}){let[M,O]=xe(null),l=M!==null&&M<r.length?M:null,[ge,fe]=xe(null),pe=Ye(),i=$?pe:null,e=N(()=>{let t=g.filter(T=>!T.hidden),n=t.map(T=>T.key),s=L!=="none",h=dt(r,n,L),ae=s?mt(h):gt([...nt(r,n),S]),d=Je({width:f,height:p,data:r,x:b,y:u,bounds:ae,margin:ee,placement:"point",formatValue:x,formatX:E,defaultIncludeZero:!0}),ve=d.categoryCenters,se=d.valueScale,Ee=se(s?0:S),He=t.map((T,ke)=>{let Y=r.map((U,F)=>{let V=h[F].segments[ke];return{x:ve[F],y:V.value===null?Number.NaN:se(V.end),defined:V.value!==null}}),Pe=r.map((U,F)=>{let V=h[F].segments[ke];return{x:ve[F],y:V.value===null?Number.NaN:se(s?V.start:S),defined:V.value!==null}}),le={connectNulls:A},ie=k&&k>0&&Y.length>k?ot(Y,k):null,ue=ie?ie.map(U=>Y[U]):Y,Le=ie?ie.map(U=>Pe[U]):Pe;return k||at("AreaChart",Y.length),{key:T.key,color:T.color,slot:T.slot,area:s?we(ue,Le,C,le):we(ue,Ee,C,le),edge:Te(ue,C,le),gap:s&&ke>0?Te(Le,C,le):"",isolated:ct(ue,A)}});return{visible:t,locate:Qe(d),plot:et({geometry:d,width:f,height:p,data:r,series:t,formatValue:x,formatX:E}),rows:h,stacked:s,xValues:d.xValues,positions:ve,xTicks:d.categoryTicks,yTicks:d.valueTicks,valueScale:se,innerWidth:d.innerWidth,innerHeight:d.innerHeight,margin:d.margin,bands:He}},[r,g,b,u,f,p,ee,C,L,S,A,k,x,E]),X=P(t=>e.visible.map((n,s)=>{let h=rt(r[t],n.key),ae=e.rows[t].segments[s],d=h===null?"\u2014":L==="percent"?`${K(h)} (${x(ae.end-ae.start)})`:x(h);return{seriesKey:n.key,seriesLabel:Be(n),color:n.color,value:h,formattedValue:d,datum:r[t]}}),[r,e.visible,e.rows,L,x,K]),te=i?i.brush:ge,ne=P(t=>{fe(t),i?.setBrush(t),Q?.(t)},[i,Q]),c=Me({enabled:J,active:te!==null,centers:e.positions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:ne}),Ce=P(t=>{if(c.onPointerMove(t),R===!1||r.length===0)return;let n=t.currentTarget.getBoundingClientRect(),s=t.clientX-n.left-e.margin.left,h=ht(e.positions,s);O(h>=0?h:null),i?.setHovered(h>=0?e.xValues[h]:null)},[c,R,r.length,e.margin.left,e.positions,e.xValues,i]),re=P(()=>{O(null),i?.setHovered(null)},[i]),y=P(()=>{if(!w||l===null)return;let[t]=X(l);t&&w({...t,index:l,x:e.xValues[l]})},[w,l,X,e.xValues]),H=P(t=>{if(r.length===0)return;let n=w&&l!==null&&e.visible.length>0;if(ut(t,n?y:null))return;c.onKeyDown(t,l);let s=it(t.key,l,r.length,"x");s!==void 0&&(t.preventDefault(),O(s),i?.setHovered(s===null?null:e.xValues[s]))},[r.length,l,c,i,e.xValues,e.visible.length,w,y]),be=P(()=>{c.consumedClick()||y()},[c,y]),ye=l!==null||!i?.hovered?null:(()=>{let t=Ve(i.hovered),n=e.xValues.findIndex(s=>Ve(s)===t);return n<0?null:n})(),v=l??ye,G=l===null?null:X(l),_=v===null?[]:e.visible.map((t,n)=>{let s=e.rows[v].segments[n];return s.value===null?null:{key:t.key,color:t.color,y:e.valueScale(s.end)}}).filter(t=>t!==null),z=c.dragging??te,I=(()=>{if(!z)return null;let t=e.locate(z.from),n=e.locate(z.to);return t===null||n===null?null:{from:t,to:n}})(),oe=tt(he),o=l===null||G===null?null:{x:e.xValues[l],xLabel:E(e.xValues[l],l),index:l,points:G};return W(xt,{children:[W("svg",{width:f,height:p,role:"img","aria-label":de??[e.visible.map(t=>Be(t)).join(", "),$e(B,ce)].filter(Boolean).join(". "),tabIndex:0,className:We(pt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",J&&"select-none"),onPointerDown:c.onPointerDown,onPointerMove:Ce,onPointerUp:c.onPointerUp,onPointerCancel:c.onPointerUp,onPointerLeave:re,onKeyDown:H,onBlur:re,onClick:be,children:[Z?a(_e,{id:q,entries:g.map(t=>({slot:t.slot,color:t.color}))}):null,W("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[a(Xe,{width:e.innerWidth,height:e.innerHeight,horizontal:m==="y"||m==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:m==="x"||m==="both"?e.xTicks.map(t=>t.offset):void 0}),B?a(Se,{layer:"under",annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,I?a(Ke,{from:I.from,to:I.to,width:e.innerWidth,height:e.innerHeight,live:c.dragging!==null,label:me}):null,oe.under?.(e.plot),a(vt,{bands:e.bands,stacked:e.stacked,patterns:Z&&e.stacked,patternBaseId:q}),B?a(Se,{annotations:B,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight}):null,D?.map(t=>{let n=e.valueScale(t.value),s=n<yt?n+12:n-4;return W("g",{children:[a("line",{x1:0,y1:n,x2:e.innerWidth,y2:n,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?a("text",{x:e.innerWidth,y:s,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),oe.over?.(e.plot),v!==null?W("g",{"aria-hidden":"true",children:[a("line",{x1:e.positions[v],y1:0,x2:e.positions[v],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),_.map(t=>a("circle",{cx:e.positions[v],cy:t.y,r:4,fill:t.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},t.key))]}):null]}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:b.hidden?null:a(Ae,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:b.label,size:j})}),a("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:u?.hidden?null:a(Ae,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:u?.label,size:j})})]}),o&&R!==!1?a(Fe,{x:e.margin.left+e.positions[o.index],y:e.margin.top+(_.length>0?Math.min(..._.map(t=>t.y)):e.innerHeight/2),containerWidth:f,children:typeof R=="function"?R(o):a(je,{title:o.xLabel,points:o.points})}):null]})}function Ft({data:f,series:p,x:r,y:g,height:b=240,width:u,size:m="md",grid:j="y",legend:C,tooltip:L=!0,tableView:S=!1,emphasis:A,title:D,description:B,loading:ce=!1,emptyState:Z,error:q=!1,errorState:he,onRetry:k,actions:J,onPointClick:Q,curve:me="monotone",stack:$="none",baseline:ee=0,connectNulls:R=!1,referenceLines:w,annotations:de,overlay:x,patterns:K=!1,legendToggle:E=!0,maxPoints:M,brush:O=!1,onBrush:l,brushLabel:ge,sync:fe=!0,margin:pe,locale:i,plotLabel:e,className:X,...te}){let ne=De(),[c,Ce]=xe(()=>new Set),re=Ne(),y=N(()=>p.map((o,t)=>({...o,slot:t,hidden:o.hidden||c.has(o.key),color:Ze(o,t,A)})),[p,c,A]),H=$==="percent",be=N(()=>H?{domain:[0,100],...g}:g,[H,g]),ye=N(()=>g?.format??(H?o=>st(o,{locale:i,alreadyScaled:!0,maximumFractionDigits:0}):o=>Re(o,i)),[g?.format,H,i]),v=N(()=>o=>Re(o,i),[i]),G=N(()=>r.format??(o=>r.scale==="time"?ft(o,i):lt(o,i)),[r.format,r.scale,i]),_=P(o=>{Ce(t=>{let n=new Set(t);return n.has(o)?n.delete(o):n.add(o),n})},[]),z=C===void 0?p.length>=2:C!==!1,I=typeof C=="string"?C:"bottom",oe=y.filter(o=>!o.hidden).length;return a(Oe,{title:D,description:B,height:b,width:u,size:m,loading:ce,empty:f.length===0||oe===0,emptyState:Z,error:q,errorState:he,onRetry:k,actions:J,tableView:S,legendPosition:I,legend:z?a(Ge,{items:qe(y,A,K&&$!=="none"),position:I,marker:"rect",size:m,onToggle:E?_:void 0}):void 0,table:S?a(Ue,{data:f,series:y,xKey:r.key,xLabel:r.label??r.key,formatX:G,formatValue:v,caption:typeof D=="string"?D:void 0}):void 0,className:X,...te,children:({width:o})=>a(kt,{width:o,height:b,data:f,resolvedSeries:y,x:r,y:be,grid:j,size:m,curve:me,stack:$,baseline:ee,connectNulls:R,referenceLines:w,annotations:de,annotationsLabel:ne.chartAnnotations,patterns:K,patternBaseId:re,overlay:x,maxPoints:M,brush:O,onBrush:l,brushLabel:ge??ne.chartBrush,syncEnabled:fe,margin:pe,tooltip:L,onPointClick:Q,plotLabel:e,formatValue:ye,formatRaw:v,formatX:G})})}export{Ft as AreaChart};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var k=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},u=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of x(e))!c.call(r,d)&&d!==t&&l(r,d,{get:()=>e[d],enumerable:!(o=y(e,d))||o.enumerable});return r};var m=r=>u(l({},"__esModule",{value:!0}),r);var C={};k(C,{Badge:()=>i});module.exports=m(C);var g=require("../../lib/cn.cjs"),a=require("react/jsx-runtime"),h={default:{solid:"bg-gray-500 text-white",soft:"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300",outlined:"border border-gray-300 text-gray-600 dark:border-gray-600 dark:text-gray-400",subtle:"bg-gray-50 text-gray-600 dark:bg-gray-800 dark:text-gray-400"},primary:{solid:"bg-synertech-primary-600 text-synertech-on-primary",soft:"bg-synertech-primary-100 text-synertech-primary-700 dark:bg-synertech-primary-900/50 dark:text-synertech-primary-300",outlined:"border border-synertech-primary-500 text-synertech-primary-600 dark:border-synertech-primary-400 dark:text-synertech-primary-400",subtle:"bg-synertech-primary-50 text-synertech-primary-600 dark:bg-synertech-primary-900/30 dark:text-synertech-primary-400"},success:{solid:"bg-green-700 text-white",soft:"bg-green-100 text-green-800 dark:bg-green-900/50 dark:text-green-300",outlined:"border border-green-500 text-green-700 dark:border-green-400 dark:text-green-400",subtle:"bg-green-50 text-green-700 dark:bg-green-900/30 dark:text-green-400"},warning:{solid:"bg-yellow-500 text-gray-900",soft:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/50 dark:text-yellow-300",outlined:"border border-yellow-400 text-yellow-700 dark:border-yellow-400 dark:text-yellow-400",subtle:"bg-yellow-50 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"},error:{solid:"bg-red-600 text-white",soft:"bg-red-100 text-red-700 dark:bg-red-900/50 dark:text-red-300",outlined:"border border-red-500 text-red-600 dark:border-red-400 dark:text-red-400",subtle:"bg-red-50 text-red-700 dark:bg-red-900/30 dark:text-red-400"},info:{solid:"bg-cyan-700 text-white",soft:"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300",outlined:"border border-cyan-500 text-cyan-700 dark:border-cyan-400 dark:text-cyan-400",subtle:"bg-cyan-50 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-400"},purple:{solid:"bg-purple-600 text-white",soft:"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300",outlined:"border border-purple-500 text-purple-600 dark:border-purple-400 dark:text-purple-400",subtle:"bg-purple-50 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400"},indigo:{solid:"bg-indigo-600 text-white",soft:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/50 dark:text-indigo-300",outlined:"border border-indigo-500 text-indigo-600 dark:border-indigo-400 dark:text-indigo-400",subtle:"bg-indigo-50 text-indigo-600 dark:bg-indigo-900/30 dark:text-indigo-300"},teal:{solid:"bg-teal-700 text-white",soft:"bg-teal-100 text-teal-700 dark:bg-teal-900/50 dark:text-teal-300",outlined:"border border-teal-500 text-teal-700 dark:border-teal-400 dark:text-teal-400",subtle:"bg-teal-50 text-teal-700 dark:bg-teal-900/30 dark:text-teal-400"}},w={default:"bg-gray-500",primary:"bg-synertech-primary-500",success:"bg-green-500",warning:"bg-yellow-400",error:"bg-red-500",info:"bg-cyan-500",purple:"bg-purple-500",indigo:"bg-indigo-500",teal:"bg-teal-500"},f={sm:"text-[10px] px-1.5 py-0.5 gap-1",md:"text-xs px-2 py-0.5 gap-1",lg:"text-sm px-2.5 py-1 gap-1.5"},B={sm:"w-1.5 h-1.5",md:"w-1.5 h-1.5",lg:"w-2 h-2"},R={sm:"w-2.5 h-2.5",md:"w-3 h-3",lg:"w-3.5 h-3.5"};function i({children:r,color:e="default",size:t="md",variant:o="soft",dot:d=!1,icon:n,pill:s=!0,className:b,...p}){return(0,a.jsxs)("span",{className:(0,g.cn)("inline-flex items-center font-medium",f[t],s?"rounded-full":"rounded",h[e][o],b),...p,children:[d&&(0,a.jsx)("span",{className:(0,g.cn)("shrink-0 rounded-full",B[t],w[e]),"aria-hidden":"true"}),n&&!d&&(0,a.jsx)("span",{className:(0,g.cn)("shrink-0",R[t]),"aria-hidden":"true",children:n}),r]})}i.displayName="Badge";0&&(module.exports={Badge});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cn as
|
|
1
|
+
import{cn as r}from"../../lib/cn.js";import{jsx as o,jsxs as u}from"react/jsx-runtime";var b={default:{solid:"bg-gray-500 text-white",soft:"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300",outlined:"border border-gray-300 text-gray-600 dark:border-gray-600 dark:text-gray-400",subtle:"bg-gray-50 text-gray-600 dark:bg-gray-800 dark:text-gray-400"},primary:{solid:"bg-synertech-primary-600 text-synertech-on-primary",soft:"bg-synertech-primary-100 text-synertech-primary-700 dark:bg-synertech-primary-900/50 dark:text-synertech-primary-300",outlined:"border border-synertech-primary-500 text-synertech-primary-600 dark:border-synertech-primary-400 dark:text-synertech-primary-400",subtle:"bg-synertech-primary-50 text-synertech-primary-600 dark:bg-synertech-primary-900/30 dark:text-synertech-primary-400"},success:{solid:"bg-green-700 text-white",soft:"bg-green-100 text-green-800 dark:bg-green-900/50 dark:text-green-300",outlined:"border border-green-500 text-green-700 dark:border-green-400 dark:text-green-400",subtle:"bg-green-50 text-green-700 dark:bg-green-900/30 dark:text-green-400"},warning:{solid:"bg-yellow-500 text-gray-900",soft:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/50 dark:text-yellow-300",outlined:"border border-yellow-400 text-yellow-700 dark:border-yellow-400 dark:text-yellow-400",subtle:"bg-yellow-50 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"},error:{solid:"bg-red-600 text-white",soft:"bg-red-100 text-red-700 dark:bg-red-900/50 dark:text-red-300",outlined:"border border-red-500 text-red-600 dark:border-red-400 dark:text-red-400",subtle:"bg-red-50 text-red-700 dark:bg-red-900/30 dark:text-red-400"},info:{solid:"bg-cyan-700 text-white",soft:"bg-cyan-100 text-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-300",outlined:"border border-cyan-500 text-cyan-700 dark:border-cyan-400 dark:text-cyan-400",subtle:"bg-cyan-50 text-cyan-700 dark:bg-cyan-900/30 dark:text-cyan-400"},purple:{solid:"bg-purple-600 text-white",soft:"bg-purple-100 text-purple-700 dark:bg-purple-900/50 dark:text-purple-300",outlined:"border border-purple-500 text-purple-600 dark:border-purple-400 dark:text-purple-400",subtle:"bg-purple-50 text-purple-600 dark:bg-purple-900/30 dark:text-purple-400"},indigo:{solid:"bg-indigo-600 text-white",soft:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/50 dark:text-indigo-300",outlined:"border border-indigo-500 text-indigo-600 dark:border-indigo-400 dark:text-indigo-400",subtle:"bg-indigo-50 text-indigo-600 dark:bg-indigo-900/30 dark:text-indigo-300"},teal:{solid:"bg-teal-700 text-white",soft:"bg-teal-100 text-teal-700 dark:bg-teal-900/50 dark:text-teal-300",outlined:"border border-teal-500 text-teal-700 dark:border-teal-400 dark:text-teal-400",subtle:"bg-teal-50 text-teal-700 dark:bg-teal-900/30 dark:text-teal-400"}},p={default:"bg-gray-500",primary:"bg-synertech-primary-500",success:"bg-green-500",warning:"bg-yellow-400",error:"bg-red-500",info:"bg-cyan-500",purple:"bg-purple-500",indigo:"bg-indigo-500",teal:"bg-teal-500"},y={sm:"text-[10px] px-1.5 py-0.5 gap-1",md:"text-xs px-2 py-0.5 gap-1",lg:"text-sm px-2.5 py-1 gap-1.5"},x={sm:"w-1.5 h-1.5",md:"w-1.5 h-1.5",lg:"w-2 h-2"},c={sm:"w-2.5 h-2.5",md:"w-3 h-3",lg:"w-3.5 h-3.5"};function k({children:g,color:t="default",size:e="md",variant:l="soft",dot:d=!1,icon:a,pill:n=!0,className:i,...s}){return u("span",{className:r("inline-flex items-center font-medium",y[e],n?"rounded-full":"rounded",b[t][l],i),...s,children:[d&&o("span",{className:r("shrink-0 rounded-full",x[e],p[t]),"aria-hidden":"true"}),a&&!d&&o("span",{className:r("shrink-0",c[e]),"aria-hidden":"true",children:a}),g]})}k.displayName="Badge";export{k as Badge};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var nt=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Wt=(f,c)=>{for(var n in c)nt(f,n,{get:c[n],enumerable:!0})},Nt=(f,c,n,m)=>{if(c&&typeof c=="object"||typeof c=="function")for(let h of Dt(c))!Ht.call(f,h)&&h!==n&&nt(f,h,{get:()=>c[h],enumerable:!(m=It(c,h))||m.enumerable});return f};var Ot=f=>Nt(nt({},"__esModule",{value:!0}),f);var Yt={};Wt(Yt,{BarChart:()=>Ft,resetBarChartWarnings:()=>Xt});module.exports=Ot(Yt);var i=require("react"),gt=require("../../lib/cn.cjs"),pt=require("../../lib/i18n.cjs"),Be=require("../chart/ChartAnnotations.cjs"),rt=require("../chart/ChartAxis.cjs"),_e=require("../chart/ChartBrush.cjs"),bt=require("../chart/ChartContainer.cjs"),yt=require("../chart/ChartGrid.cjs"),Ct=require("../chart/ChartLegend.cjs"),$e=require("../chart/ChartPatterns.cjs"),vt=require("../chart/ChartScaleLegend.cjs"),xt=require("../chart/ChartSync.cjs"),kt=require("../chart/ChartTableView.cjs"),Ke=require("../chart/ChartTooltip.cjs"),w=require("../chart/palette.cjs"),G=require("../chart/utils/cartesian.cjs"),M=require("../chart/utils/data.cjs"),he=require("../chart/utils/format.cjs"),Xe=require("../chart/utils/keyboard.cjs"),St=require("../chart/utils/bins.cjs"),Ge=require("../chart/utils/path.cjs"),Pe=require("../chart/utils/scales.cjs"),de=require("../chart/utils/stack.cjs"),Bt=require("../chart/utils/text.cjs"),we=require("../chart/utils/ticks.cjs"),Ue=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),_t=24,ne=2,$t=4,ue=6,Kt=10,ot=!1,at=!1;function Xt(){ot=!1,at=!1}var Gt=(0,i.memo)(function({bars:c,patterns:n,patternBaseId:m}){return(0,r.jsx)("g",{children:c.map((h,T)=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:h.d,fill:(0,$e.patternFill)(n,m,h.slot,h.color)}),h.label?(0,r.jsx)("text",{x:h.label.x,y:h.label.y,textAnchor:h.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:h.label.text}):null]},`${h.key}-${T}`))})}),Ut=(0,i.memo)(function({lines:c}){return(0,r.jsx)("g",{children:c.map(n=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(m=>(0,r.jsx)("circle",{cx:m.x,cy:m.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${m.x}-${m.y}`))]},n.key))})});function zt({width:f,height:c,data:n,resolvedSeries:m,x:h,y:T,grid:I,size:Le,orientation:E,stack:N,center:V,centerKey:D,valueColors:U,binned:re,curve:Re,barSize:Ae,showValues:Te,referenceLines:ze,annotations:z,annotationsLabel:Fe,patterns:Ee,patternBaseId:oe,overlay:Ve,brush:L,onBrush:F,brushLabel:Ye,syncEnabled:Ze,margin:ae,tooltip:Y,onPointClick:Z,plotLabel:Me,formatValue:O,formatRaw:j,formatX:le}){let[me,fe]=(0,i.useState)(null),d=me!==null&&me<n.length?me:null,[je,qe]=(0,i.useState)(null),H=(0,xt.useChartSync)(),v=Ze?H:null,e=(0,i.useMemo)(()=>{let t=E==="vertical",o=m.filter(g=>!g.hidden),a=o.filter(g=>g.type!=="line"),b=o.filter(g=>g.type==="line"),R=a.map(g=>g.key),y=D!==null||N!=="none",s=D!==null?(0,de.stackDiverging)(n,R,{centerKey:D,percent:N==="percent"}):(0,de.stackSeries)(n,R,N),l=y?(0,de.stackExtent)(s):(0,we.extent)((0,M.collectAllValues)(n,R)),u=(0,we.extent)((0,M.collectAllValues)(n,b.map(g=>g.key))),p=l===null?u:u===null?l:[Math.min(l[0],u[0]),Math.max(l[1],u[1])],A=(0,G.buildCartesianGeometry)({width:f,height:c,data:n,x:h,y:T,bounds:p===null?null:[Math.min(p[0],V),Math.max(p[1],V)],margin:ae,orientation:E,placement:"band",bandPaddingInner:re?0:void 0,formatValue:O,formatX:le,defaultIncludeZero:V===0}),{valueScale:ve,bandwidth:xe,categoryPositions:lt,innerWidth:it,innerHeight:st}=A,Pt=ve(V),He=Math.max(1,a.length),wt=y?xe:xe/He,X=Math.min(Ae??(re?Number.POSITIVE_INFINITY:_t),Math.max(1,wt-(y&&!re?0:ne))),Lt=y?X:He*X+(He-1)*ne,ct=(xe-Lt)/2,ut=[],ht=g=>y?g.end>=g.start:g.end>=V;s.forEach((g,We)=>{let Q=-1,Ne=-1;g.segments.forEach((P,se)=>{P.value!==null&&P.outer!==!1&&(ht(P)?Q=se:Ne=se)});let ie=0,ke=0;g.segments.forEach((P,se)=>{if(P.value===null)return;let Qe=a[se],x=ht(P),dt=ve(y?P.start:V),mt=ve(P.end),ee=Math.min(dt,mt),ce=Math.abs(mt-dt),At=P.base??(x?ie===0:ke===0),Tt=t?!x:x;y&&!At&&ce>ne&&(ce-=ne,Tt&&(ee+=ne)),x?ie+=1:ke+=1;let Oe=lt[We]+(y?ct:ct+se*(X+ne)),Et=se===(x?Q:Ne)?t?x?"top":"bottom":x?"right":"left":"none",Vt=t?{x:Oe,y:ee,width:X,height:ce}:{x:ee,y:Oe,width:ce,height:X},et=null;if(Te&&!y){let tt=j(P.value),ft=(0,Bt.estimateTextWidth)(tt,10);if(t){let te=x?ee:ee+ce,Se=x?te-ue:te+ue,Mt=He>1?X+ne:xe;ft<=Mt&&(x?Se>8:Se<st-4)&&(et={x:Oe+X/2,y:Se,anchor:"middle",text:tt})}else{let te=x?ee+ce:ee,Se=x?it-te-ue:te-ue;ft<=Se&&(et={x:x?te+ue:te-ue,y:Oe+X/2,anchor:x?"start":"end",text:tt})}}ut.push({key:Qe.key,slot:Qe.slot,color:U&&P.value!==null?U(P.value):Qe.color,d:(0,Ge.buildBarPath)({...Vt,radius:$t,round:Et}),label:et})})});let Rt=b.map(g=>{let We=A.categoryCenters.map((Q,Ne)=>{let ie=(0,M.readNumber)(n[Ne],g.key),ke=ie===null?Number.NaN:ve(ie);return{x:t?Q:ke,y:t?ke:Q,defined:ie!==null}});return{key:g.key,color:g.color,dashed:g.dashed,d:(0,Ge.buildLinePath)(We,Re),markers:We.filter(Q=>Q.defined!==!1)}});return{vertical:t,visible:o,locate:(0,G.createCategoryLocator)(A),barSeries:a,rows:s,stacked:y,plot:(0,G.createPlotContext)({geometry:A,width:f,height:c,data:n,series:o,formatValue:O,formatX:le}),xValues:A.xValues,categoryPositions:lt,categoryCenters:A.categoryCenters,bandwidth:xe,categoryTicks:A.categoryTicks,valueTicks:A.valueTicks,valueScale:ve,baseline:Pt,innerWidth:it,innerHeight:st,margin:A.margin,bars:ut,lines:Rt}},[n,m,h,T,f,c,ae,E,N,V,D,U,re,Re,Ae,Te,O,j,le]),ge=(0,i.useCallback)(t=>e.visible.map(o=>{let a=(0,M.readNumber)(n[t],o.key),b=e.barSeries.indexOf(o),R=b===-1?null:e.rows[t].segments[b],y=a===null?"\u2014":N==="percent"&&R!==null?`${j(a)} (${O(R.end-R.start)})`:O(a);return{seriesKey:o.key,seriesLabel:(0,w.getSeriesLabel)(o),color:o.color,value:a,formattedValue:y,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,N,O,j]),pe=v?v.brush:je,Ie=(0,i.useCallback)(t=>{qe(t),v?.setBrush(t),F?.(t)},[v,F]),k=(0,_e.useChartBrush)({enabled:L,active:pe!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:E,onCommit:Ie}),Je=(0,i.useCallback)(t=>{if(k.onPointerMove(t),Y===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),a=e.vertical?t.clientX-o.left-e.margin.left:t.clientY-o.top-e.margin.top,b=(0,Pe.nearestIndex)(e.categoryCenters,a);fe(b>=0?b:null),v?.setHovered(b>=0?e.xValues[b]:null)},[k,Y,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,v]),S=(0,i.useCallback)(()=>{fe(null),v?.setHovered(null)},[v]),C=(0,i.useCallback)(()=>{if(!Z||d===null)return;let[t]=ge(d);t&&Z({...t,index:d,x:e.xValues[d]})},[Z,d,ge,e.xValues]),q=(0,i.useCallback)(t=>{if(n.length===0)return;let o=Z&&d!==null&&e.visible.length>0;if((0,Xe.pressChartMark)(t,o?C:null))return;k.onKeyDown(t,d);let a=(0,Xe.chartCursorTarget)(t.key,d,n.length,e.vertical?"x":"y");a!==void 0&&(t.preventDefault(),fe(a),v?.setHovered(a===null?null:e.xValues[a]))},[n.length,d,e.vertical,k,v,e.xValues,e.visible.length,Z,C]),_=(0,i.useCallback)(()=>{k.consumedClick()||C()},[k,C]),$=d!==null||!v?.hovered?null:(()=>{let t=(0,Pe.toKey)(v.hovered),o=e.xValues.findIndex(a=>(0,Pe.toKey)(a)===t);return o<0?null:o})(),B=d??$,W=k.dragging??pe,K=(()=>{if(!W)return null;let t=e.locate(W.from),o=e.locate(W.to);if(t===null||o===null)return null;let a=e.bandwidth/2;return{from:Math.min(t,o)-a,to:Math.max(t,o)+a}})(),De=(0,G.splitOverlay)(Ve),be=d===null?null:ge(d),J=d===null||be===null?null:{x:e.xValues[d],xLabel:le(e.xValues[d],d),index:d,points:be},ye=t=>{let o=e.rows[t].segments.filter(a=>a.value!==null).map(a=>e.valueScale(a.end));for(let a of e.lines){let b=(0,M.readNumber)(n[t],a.key);b!==null&&o.push(e.valueScale(b))}return o},Ce=d===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[d],y:e.margin.top+Math.min(...ye(d),e.baseline)}:{x:e.margin.left+Math.max(...ye(d),e.baseline),y:e.margin.top+e.categoryCenters[d]};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:f,height:c,role:"img","aria-label":Me??[e.visible.map(t=>(0,w.getSeriesLabel)(t)).join(", "),(0,Be.describeAnnotations)(z,Fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,gt.cn)(L&&!e.vertical?Ue.CHART_TOUCH_VERTICAL_DRAG:Ue.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",L&&"select-none"),onPointerDown:k.onPointerDown,onPointerMove:Je,onPointerUp:k.onPointerUp,onPointerCancel:k.onPointerUp,onPointerLeave:S,onKeyDown:q,onBlur:S,onClick:_,children:[Ee?(0,r.jsx)($e.ChartPatternDefs,{id:oe,entries:m.map(t=>({slot:t.slot,color:t.color}))}):null,(0,r.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,r.jsx)(yt.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(t=>t.offset):void 0}),z?(0,r.jsx)(Be.ChartAnnotationLayer,{layer:"under",annotations:z,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,K?(0,r.jsx)(_e.ChartBrushLayer,{from:K.from,to:K.to,width:e.innerWidth,height:e.innerHeight,orientation:E,live:k.dragging!==null,label:Ye}):null,B!==null?(0,r.jsx)("rect",{x:e.vertical?e.categoryPositions[B]:0,y:e.vertical?0:e.categoryPositions[B],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,De.under?.(e.plot),(0,r.jsx)(Gt,{bars:e.bars,patterns:Ee,patternBaseId:oe}),e.lines.length>0?(0,r.jsx)(Ut,{lines:e.lines}):null,(0,r.jsx)("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),z?(0,r.jsx)(Be.ChartAnnotationLayer,{annotations:z,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,De.over?.(e.plot),ze?.map(t=>{let o=e.valueScale(t.value),a=o<Kt?o+12:o-4;return(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:e.vertical?0:o,y1:e.vertical?o:0,x2:e.vertical?e.innerWidth:o,y2:e.vertical?o:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,r.jsx)("text",{x:e.vertical?e.innerWidth:o+4,y:e.vertical?a:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?h.hidden:T?.hidden)?null:(0,r.jsx)(rt.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?h.label:T?.label,size:Le})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?T?.hidden:h.hidden)?null:(0,r.jsx)(rt.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?T?.label:h.label,size:Le})})]}),J&&Ce&&Y!==!1?(0,r.jsx)(Ke.ChartTooltip,{x:Ce.x,y:Ce.y,containerWidth:f,children:typeof Y=="function"?Y(J):(0,r.jsx)(Ke.ChartTooltipContent,{title:J.xLabel,points:J.points})}):null]})}function Ft({data:f,series:c,x:n,y:m,height:h=260,width:T,size:I="md",grid:Le="y",legend:E,tooltip:N=!0,tableView:V=!1,emphasis:D,title:U,description:re,loading:Re=!1,emptyState:Ae,error:Te=!1,errorState:ze,onRetry:z,actions:Fe,onPointClick:Ee,orientation:oe="vertical",stack:Ve="none",diverging:L,bins:F,curve:Ye="linear",barSize:Ze,sort:ae="none",showValues:Y=!1,referenceLines:Z,annotations:Me,overlay:O,patterns:j=!1,legendToggle:le=!0,brush:me=!1,onBrush:fe,brushLabel:d,sync:je=!0,margin:qe,locale:H,plotLabel:v,className:e,...ge}){let pe=(0,pt.useUILabels)(),[Ie,k]=(0,i.useState)(()=>new Set),Je=(0,i.useId)(),S=F!==void 0&&F!==!1,C=S||typeof L!="string"?null:L,q=!S&&typeof L=="number"?L:0,_=(0,i.useMemo)(()=>{let s=C===null?null:(0,w.createDivergingScale)([0,Math.max(1,c.length-1)],{center:Math.max(0,c.findIndex(l=>l.key===C)),symmetric:!1});return c.map((l,u)=>({...l,slot:u,hidden:l.hidden||Ie.has(l.key),color:s&&!l.color&&!D?l.key===C?w.CHART_MUTED_COLOR:s(u):(0,w.resolveSeriesColor)(l,u,D)}))},[c,Ie,D,C]),$=(0,i.useMemo)(()=>s=>(0,he.formatAuto)(s,H),[H]),B=(0,i.useMemo)(()=>{if(!S)return null;c.length>1&&!ot&&(ot=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let s=c[0]?.key??"count",l=n.format?p=>n.format(p,0):p=>$(p),u=(0,St.binValues)(f.map(p=>(0,M.readNumber)(p,n.key)),F);return{rows:u.map(p=>({[n.key]:p.from,[s]:p.count})),labels:u.map(p=>`${l(p.from)}\u2013${l(p.to)}`)}},[S,F,f,n.key,n.format,c,$]),W=(0,i.useMemo)(()=>{if(B)return B.rows;if(ae==="none")return f;let s=_.filter(u=>!u.hidden).map(u=>u.key),l=u=>s.reduce((p,A)=>p+((0,M.readNumber)(u,A)??0),0);return[...f].sort((u,p)=>ae==="asc"?l(u)-l(p):l(p)-l(u))},[B,f,ae,_]),K=!S&&Ve==="percent",De=(0,i.useMemo)(()=>K?{domain:C===null?[0,100]:[-100,100],...m}:m,[K,C,m]),be=(0,i.useMemo)(()=>{let s=m?.format??(K?l=>(0,he.formatPercent)(l,{locale:H,alreadyScaled:!0,maximumFractionDigits:0}):$);return C===null?s:l=>s(Math.abs(l))},[m?.format,K,H,$,C]),J=(0,i.useMemo)(()=>B?(s,l)=>B.labels[l]??"":n.format??(s=>(0,he.formatXValue)(s,H)),[B,n.format,H]),ye=(0,i.useMemo)(()=>B?{...n,scale:"category"}:n,[B,n]),Ce=(0,i.useCallback)(s=>{k(l=>{let u=new Set(l);return u.has(s)?u.delete(s):u.add(s),u})},[]),t=oe==="vertical"?Me:void 0;Me&&oe!=="vertical"&&!at&&(at=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let o=E===void 0?c.length>=2:E!==!1,a=typeof E=="string"?E:"bottom",b=_.filter(s=>!s.hidden),R=b.length,y=(0,i.useMemo)(()=>{if(S||L===void 0||L===!1||C!==null||R!==1)return null;let s=(0,M.collectAllValues)(W,b.map(u=>u.key)),l=(0,we.resolveDomain)([...s,q],{domain:m?.domain,includeZero:m?.includeZero??q===0,ticks:m?.ticks??5});return(0,w.createDivergingScale)(l,{center:q})},[S,L,C,R,b,W,q,m]);return(0,r.jsx)(bt.ChartContainer,{title:U,description:re,height:h,width:T,size:I,loading:Re,empty:W.length===0||R===0,emptyState:Ae,error:Te,errorState:ze,onRetry:z,actions:Fe,tableView:V,legendPosition:a,legend:y?(0,r.jsx)(vt.ChartScaleLegend,{scale:y,label:m?.label,format:be,size:I,locale:H}):o?(0,r.jsx)(Ct.ChartLegend,{items:(0,w.toLegendItems)(_,D,j),position:a,marker:"rect",size:I,onToggle:le?Ce:void 0}):void 0,table:V?(0,r.jsx)(kt.ChartTableView,{data:W,series:_,xKey:ye.key,xLabel:n.label??n.key,formatX:J,formatValue:$,caption:typeof U=="string"?U:void 0}):void 0,className:e,...ge,children:({width:s})=>(0,r.jsx)(zt,{width:s,height:h,data:W,resolvedSeries:_,x:ye,y:De,grid:Le,size:I,orientation:oe,stack:S?"none":Ve,center:q,centerKey:C,valueColors:y,binned:S,curve:Ye,barSize:Ze,showValues:Y,referenceLines:Z,annotations:t,annotationsLabel:pe.chartAnnotations,patterns:j&&y===null,patternBaseId:Je,overlay:O,brush:me,onBrush:fe,brushLabel:d??pe.chartBrush,syncEnabled:je,margin:qe,tooltip:N,onPointClick:Ee,plotLabel:v,formatValue:be,formatRaw:$,formatX:J})})}0&&(module.exports={BarChart,resetBarChartWarnings});
|
|
1
|
+
"use strict";"use client";var nt=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Wt=(f,c)=>{for(var n in c)nt(f,n,{get:c[n],enumerable:!0})},Nt=(f,c,n,m)=>{if(c&&typeof c=="object"||typeof c=="function")for(let h of Dt(c))!Ht.call(f,h)&&h!==n&&nt(f,h,{get:()=>c[h],enumerable:!(m=It(c,h))||m.enumerable});return f};var Ot=f=>Nt(nt({},"__esModule",{value:!0}),f);var Yt={};Wt(Yt,{BarChart:()=>Ft,resetBarChartWarnings:()=>Xt});module.exports=Ot(Yt);var i=require("react"),gt=require("../../lib/cn.cjs"),pt=require("../../lib/i18n.cjs"),Be=require("../chart/ChartAnnotations.cjs"),rt=require("../chart/ChartAxis.cjs"),_e=require("../chart/ChartBrush.cjs"),bt=require("../chart/ChartContainer.cjs"),yt=require("../chart/ChartGrid.cjs"),Ct=require("../chart/ChartLegend.cjs"),$e=require("../chart/ChartPatterns.cjs"),vt=require("../chart/ChartScaleLegend.cjs"),xt=require("../chart/ChartSync.cjs"),kt=require("../chart/ChartTableView.cjs"),Ke=require("../chart/ChartTooltip.cjs"),w=require("../chart/palette.cjs"),G=require("../chart/utils/cartesian.cjs"),M=require("../chart/utils/data.cjs"),he=require("../chart/utils/format.cjs"),Xe=require("../chart/utils/keyboard.cjs"),St=require("../chart/utils/bins.cjs"),Ge=require("../chart/utils/path.cjs"),Pe=require("../chart/utils/scales.cjs"),de=require("../chart/utils/stack.cjs"),Bt=require("../chart/utils/text.cjs"),we=require("../chart/utils/ticks.cjs"),Ue=require("../chart/utils/touch.cjs"),r=require("react/jsx-runtime"),_t=24,ne=2,$t=4,ue=6,Kt=10,ot=!1,at=!1;function Xt(){ot=!1,at=!1}var Gt=(0,i.memo)(function({bars:c,patterns:n,patternBaseId:m}){return(0,r.jsx)("g",{children:c.map((h,T)=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:h.d,fill:(0,$e.patternFill)(n,m,h.slot,h.color)}),h.label?(0,r.jsx)("text",{x:h.label.x,y:h.label.y,textAnchor:h.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:h.label.text}):null]},`${h.key}-${T}`))})}),Ut=(0,i.memo)(function({lines:c}){return(0,r.jsx)("g",{children:c.map(n=>(0,r.jsxs)("g",{children:[(0,r.jsx)("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(m=>(0,r.jsx)("circle",{cx:m.x,cy:m.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${m.x}-${m.y}`))]},n.key))})});function zt({width:f,height:c,data:n,resolvedSeries:m,x:h,y:T,grid:I,size:Le,orientation:E,stack:N,center:V,centerKey:D,valueColors:U,binned:re,curve:Re,barSize:Ae,showValues:Te,referenceLines:ze,annotations:z,annotationsLabel:Fe,patterns:Ee,patternBaseId:oe,overlay:Ve,brush:L,onBrush:F,brushLabel:Ye,syncEnabled:Ze,margin:ae,tooltip:Y,onPointClick:Z,plotLabel:Me,formatValue:O,formatRaw:j,formatX:le}){let[me,fe]=(0,i.useState)(null),d=me!==null&&me<n.length?me:null,[je,qe]=(0,i.useState)(null),H=(0,xt.useChartSync)(),v=Ze?H:null,e=(0,i.useMemo)(()=>{let t=E==="vertical",o=m.filter(g=>!g.hidden),a=o.filter(g=>g.type!=="line"),b=o.filter(g=>g.type==="line"),R=a.map(g=>g.key),y=D!==null||N!=="none",s=D!==null?(0,de.stackDiverging)(n,R,{centerKey:D,percent:N==="percent"}):(0,de.stackSeries)(n,R,N),l=y?(0,de.stackExtent)(s):(0,we.extent)((0,M.collectAllValues)(n,R)),u=(0,we.extent)((0,M.collectAllValues)(n,b.map(g=>g.key))),p=l===null?u:u===null?l:[Math.min(l[0],u[0]),Math.max(l[1],u[1])],A=(0,G.buildCartesianGeometry)({width:f,height:c,data:n,x:h,y:T,bounds:p===null?null:[Math.min(p[0],V),Math.max(p[1],V)],margin:ae,orientation:E,placement:"band",bandPaddingInner:re?0:void 0,formatValue:O,formatX:le,defaultIncludeZero:V===0}),{valueScale:ve,bandwidth:xe,categoryPositions:lt,innerWidth:it,innerHeight:st}=A,Pt=ve(V),He=Math.max(1,a.length),wt=y?xe:xe/He,X=Math.min(Ae??(re?Number.POSITIVE_INFINITY:_t),Math.max(1,wt-(y&&!re?0:ne))),Lt=y?X:He*X+(He-1)*ne,ct=(xe-Lt)/2,ut=[],ht=g=>y?g.end>=g.start:g.end>=V;s.forEach((g,We)=>{let Q=-1,Ne=-1;g.segments.forEach((P,se)=>{P.value!==null&&P.outer!==!1&&(ht(P)?Q=se:Ne=se)});let ie=0,ke=0;g.segments.forEach((P,se)=>{if(P.value===null)return;let Qe=a[se],x=ht(P),dt=ve(y?P.start:V),mt=ve(P.end),ee=Math.min(dt,mt),ce=Math.abs(mt-dt),At=P.base??(x?ie===0:ke===0),Tt=t?!x:x;y&&!At&&ce>ne&&(ce-=ne,Tt&&(ee+=ne)),x?ie+=1:ke+=1;let Oe=lt[We]+(y?ct:ct+se*(X+ne)),Et=se===(x?Q:Ne)?t?x?"top":"bottom":x?"right":"left":"none",Vt=t?{x:Oe,y:ee,width:X,height:ce}:{x:ee,y:Oe,width:ce,height:X},et=null;if(Te&&!y){let tt=j(P.value),ft=(0,Bt.estimateTextWidth)(tt,10);if(t){let te=x?ee:ee+ce,Se=x?te-ue:te+ue,Mt=He>1?X+ne:xe;ft<=Mt&&(x?Se>8:Se<st-4)&&(et={x:Oe+X/2,y:Se,anchor:"middle",text:tt})}else{let te=x?ee+ce:ee,Se=x?it-te-ue:te-ue;ft<=Se&&(et={x:x?te+ue:te-ue,y:Oe+X/2,anchor:x?"start":"end",text:tt})}}ut.push({key:Qe.key,slot:Qe.slot,color:U&&P.value!==null?U(P.value):Qe.color,d:(0,Ge.buildBarPath)({...Vt,radius:$t,round:Et}),label:et})})});let Rt=b.map(g=>{let We=A.categoryCenters.map((Q,Ne)=>{let ie=(0,M.readNumber)(n[Ne],g.key),ke=ie===null?Number.NaN:ve(ie);return{x:t?Q:ke,y:t?ke:Q,defined:ie!==null}});return{key:g.key,color:g.color,dashed:g.dashed,d:(0,Ge.buildLinePath)(We,Re),markers:We.filter(Q=>Q.defined!==!1)}});return{vertical:t,visible:o,locate:(0,G.createCategoryLocator)(A),barSeries:a,rows:s,stacked:y,plot:(0,G.createPlotContext)({geometry:A,width:f,height:c,data:n,series:o,formatValue:O,formatX:le}),xValues:A.xValues,categoryPositions:lt,categoryCenters:A.categoryCenters,bandwidth:xe,categoryTicks:A.categoryTicks,valueTicks:A.valueTicks,valueScale:ve,baseline:Pt,innerWidth:it,innerHeight:st,margin:A.margin,bars:ut,lines:Rt}},[n,m,h,T,f,c,ae,E,N,V,D,U,re,Re,Ae,Te,O,j,le]),ge=(0,i.useCallback)(t=>e.visible.map(o=>{let a=(0,M.readNumber)(n[t],o.key),b=e.barSeries.indexOf(o),R=b===-1?null:e.rows[t].segments[b],y=a===null?"\u2014":N==="percent"&&R!==null?`${j(a)} (${O(R.end-R.start)})`:O(a);return{seriesKey:o.key,seriesLabel:(0,w.getSeriesLabel)(o),color:o.color,value:a,formattedValue:y,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,N,O,j]),pe=v?v.brush:je,Ie=(0,i.useCallback)(t=>{qe(t),v?.setBrush(t),F?.(t)},[v,F]),k=(0,_e.useChartBrush)({enabled:L,active:pe!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:E,onCommit:Ie}),Je=(0,i.useCallback)(t=>{if(k.onPointerMove(t),Y===!1||n.length===0)return;let o=t.currentTarget.getBoundingClientRect(),a=e.vertical?t.clientX-o.left-e.margin.left:t.clientY-o.top-e.margin.top,b=(0,Pe.nearestIndex)(e.categoryCenters,a);fe(b>=0?b:null),v?.setHovered(b>=0?e.xValues[b]:null)},[k,Y,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,v]),S=(0,i.useCallback)(()=>{fe(null),v?.setHovered(null)},[v]),C=(0,i.useCallback)(()=>{if(!Z||d===null)return;let[t]=ge(d);t&&Z({...t,index:d,x:e.xValues[d]})},[Z,d,ge,e.xValues]),q=(0,i.useCallback)(t=>{if(n.length===0)return;let o=Z&&d!==null&&e.visible.length>0;if((0,Xe.pressChartMark)(t,o?C:null))return;k.onKeyDown(t,d);let a=(0,Xe.chartCursorTarget)(t.key,d,n.length,e.vertical?"x":"y");a!==void 0&&(t.preventDefault(),fe(a),v?.setHovered(a===null?null:e.xValues[a]))},[n.length,d,e.vertical,k,v,e.xValues,e.visible.length,Z,C]),_=(0,i.useCallback)(()=>{k.consumedClick()||C()},[k,C]),$=d!==null||!v?.hovered?null:(()=>{let t=(0,Pe.toKey)(v.hovered),o=e.xValues.findIndex(a=>(0,Pe.toKey)(a)===t);return o<0?null:o})(),B=d??$,W=k.dragging??pe,K=(()=>{if(!W)return null;let t=e.locate(W.from),o=e.locate(W.to);if(t===null||o===null)return null;let a=e.bandwidth/2;return{from:Math.min(t,o)-a,to:Math.max(t,o)+a}})(),De=(0,G.splitOverlay)(Ve),be=d===null?null:ge(d),J=d===null||be===null?null:{x:e.xValues[d],xLabel:le(e.xValues[d],d),index:d,points:be},ye=t=>{let o=e.rows[t].segments.filter(a=>a.value!==null).map(a=>e.valueScale(a.end));for(let a of e.lines){let b=(0,M.readNumber)(n[t],a.key);b!==null&&o.push(e.valueScale(b))}return o},Ce=d===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[d],y:e.margin.top+Math.min(...ye(d),e.baseline)}:{x:e.margin.left+Math.max(...ye(d),e.baseline),y:e.margin.top+e.categoryCenters[d]};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("svg",{width:f,height:c,role:"img","aria-label":Me??[e.visible.map(t=>(0,w.getSeriesLabel)(t)).join(", "),(0,Be.describeAnnotations)(z,Fe)].filter(Boolean).join(". "),tabIndex:0,className:(0,gt.cn)(L&&!e.vertical?Ue.CHART_TOUCH_VERTICAL_DRAG:Ue.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",L&&"select-none"),onPointerDown:k.onPointerDown,onPointerMove:Je,onPointerUp:k.onPointerUp,onPointerCancel:k.onPointerUp,onPointerLeave:S,onKeyDown:q,onBlur:S,onClick:_,children:[Ee?(0,r.jsx)($e.ChartPatternDefs,{id:oe,entries:m.map(t=>({slot:t.slot,color:t.color}))}):null,(0,r.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,r.jsx)(yt.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(I==="y"||I==="both")?e.valueTicks.map(t=>t.offset):void 0}),z?(0,r.jsx)(Be.ChartAnnotationLayer,{layer:"under",annotations:z,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,K?(0,r.jsx)(_e.ChartBrushLayer,{from:K.from,to:K.to,width:e.innerWidth,height:e.innerHeight,orientation:E,live:k.dragging!==null,label:Ye}):null,B!==null?(0,r.jsx)("rect",{x:e.vertical?e.categoryPositions[B]:0,y:e.vertical?0:e.categoryPositions[B],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,De.under?.(e.plot),(0,r.jsx)(Gt,{bars:e.bars,patterns:Ee,patternBaseId:oe}),e.lines.length>0?(0,r.jsx)(Ut,{lines:e.lines}):null,(0,r.jsx)("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),z?(0,r.jsx)(Be.ChartAnnotationLayer,{annotations:z,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,De.over?.(e.plot),ze?.map(t=>{let o=e.valueScale(t.value),a=o<Kt?o+12:o-4;return(0,r.jsxs)("g",{children:[(0,r.jsx)("line",{x1:e.vertical?0:o,y1:e.vertical?o:0,x2:e.vertical?e.innerWidth:o,y2:e.vertical?o:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,r.jsx)("text",{x:e.vertical?e.innerWidth:o+4,y:e.vertical?a:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?h.hidden:T?.hidden)?null:(0,r.jsx)(rt.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?h.label:T?.label,size:Le})}),(0,r.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?T?.hidden:h.hidden)?null:(0,r.jsx)(rt.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?T?.label:h.label,size:Le})})]}),J&&Ce&&Y!==!1?(0,r.jsx)(Ke.ChartTooltip,{x:Ce.x,y:Ce.y,containerWidth:f,children:typeof Y=="function"?Y(J):(0,r.jsx)(Ke.ChartTooltipContent,{title:J.xLabel,points:J.points})}):null]})}function Ft({data:f,series:c,x:n,y:m,height:h=260,width:T,size:I="md",grid:Le="y",legend:E,tooltip:N=!0,tableView:V=!1,emphasis:D,title:U,description:re,loading:Re=!1,emptyState:Ae,error:Te=!1,errorState:ze,onRetry:z,actions:Fe,onPointClick:Ee,orientation:oe="vertical",stack:Ve="none",diverging:L,bins:F,curve:Ye="linear",barSize:Ze,sort:ae="none",showValues:Y=!1,referenceLines:Z,annotations:Me,overlay:O,patterns:j=!1,legendToggle:le=!0,brush:me=!1,onBrush:fe,brushLabel:d,sync:je=!0,margin:qe,locale:H,plotLabel:v,className:e,...ge}){let pe=(0,pt.useUILabels)(),[Ie,k]=(0,i.useState)(()=>new Set),Je=(0,i.useId)(),S=F!==void 0&&F!==!1,C=S||typeof L!="string"?null:L,q=!S&&typeof L=="number"?L:0,_=(0,i.useMemo)(()=>{let s=C===null?null:(0,w.createDivergingScale)([0,Math.max(1,c.length-1)],{center:Math.max(0,c.findIndex(l=>l.key===C)),symmetric:!1});return c.map((l,u)=>({...l,slot:u,hidden:l.hidden||Ie.has(l.key),color:s&&!l.color&&!D?l.key===C?w.CHART_MUTED_COLOR:s(u):(0,w.resolveSeriesColor)(l,u,D)}))},[c,Ie,D,C]),$=(0,i.useMemo)(()=>s=>(0,he.formatAuto)(s,H),[H]),B=(0,i.useMemo)(()=>{if(!S)return null;c.length>1&&!ot&&(ot=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let s=c[0]?.key??"count",l=n.format?p=>n.format(p,0):p=>$(p),u=(0,St.binValues)(f.map(p=>(0,M.readNumber)(p,n.key)),F);return{rows:u.map(p=>({[n.key]:p.from,[s]:p.count})),labels:u.map(p=>`${l(p.from)}\u2013${l(p.to)}`)}},[S,F,f,n.key,n.format,c,$]),W=(0,i.useMemo)(()=>{if(B)return B.rows;if(ae==="none")return f;let s=_.filter(u=>!u.hidden).map(u=>u.key),l=u=>s.reduce((p,A)=>p+((0,M.readNumber)(u,A)??0),0);return[...f].sort((u,p)=>ae==="asc"?l(u)-l(p):l(p)-l(u))},[B,f,ae,_]),K=!S&&Ve==="percent",De=(0,i.useMemo)(()=>K?{domain:C===null?[0,100]:[-100,100],...m}:m,[K,C,m]),be=(0,i.useMemo)(()=>{let s=m?.format??(K?l=>(0,he.formatPercent)(l,{locale:H,alreadyScaled:!0,maximumFractionDigits:0}):$);return C===null?s:l=>s(Math.abs(l))},[m?.format,K,H,$,C]),J=(0,i.useMemo)(()=>B?(s,l)=>B.labels[l]??"":n.format??(s=>(0,he.formatXValue)(s,H)),[B,n.format,H]),ye=(0,i.useMemo)(()=>B?{...n,scale:"category"}:n,[B,n]),Ce=(0,i.useCallback)(s=>{k(l=>{let u=new Set(l);return u.has(s)?u.delete(s):u.add(s),u})},[]),t=oe==="vertical"?Me:void 0;Me&&oe!=="vertical"&&!at&&(at=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let o=E===void 0?c.length>=2:E!==!1,a=typeof E=="string"?E:"bottom",b=_.filter(s=>!s.hidden),R=b.length,y=(0,i.useMemo)(()=>{if(S||L===void 0||L===!1||C!==null||R!==1)return null;let s=(0,M.collectAllValues)(W,b.map(u=>u.key)),l=(0,we.resolveDomain)([...s,q],{domain:m?.domain,includeZero:m?.includeZero??q===0,ticks:m?.ticks??5});return(0,w.createDivergingScale)(l,{center:q})},[S,L,C,R,b,W,q,m]);return(0,r.jsx)(bt.ChartContainer,{title:U,description:re,height:h,width:T,size:I,loading:Re,empty:W.length===0||R===0,emptyState:Ae,error:Te,errorState:ze,onRetry:z,actions:Fe,tableView:V,legendPosition:a,legend:y?(0,r.jsx)(vt.ChartScaleLegend,{scale:y,label:m?.label,format:be,size:I,locale:H}):o?(0,r.jsx)(Ct.ChartLegend,{items:(0,w.toLegendItems)(_,D,j),position:a,marker:"rect",size:I,onToggle:le?Ce:void 0}):void 0,table:V?(0,r.jsx)(kt.ChartTableView,{data:W,series:_,xKey:ye.key,xLabel:n.label??n.key,formatX:J,formatValue:$,caption:typeof U=="string"?U:void 0}):void 0,className:e,...ge,children:({width:s})=>(0,r.jsx)(zt,{width:s,height:h,data:W,resolvedSeries:_,x:ye,y:De,grid:Le,size:I,orientation:oe,stack:S?"none":Ve,center:q,centerKey:C,valueColors:y,binned:S,curve:Ye,barSize:Ze,showValues:Y,referenceLines:Z,annotations:t,annotationsLabel:pe.chartAnnotations,patterns:j&&y===null,patternBaseId:Je,overlay:O,brush:me,onBrush:fe,brushLabel:d??pe.chartBrush,syncEnabled:je,margin:qe,tooltip:N,onPointClick:Ee,plotLabel:v,formatValue:be,formatRaw:$,formatX:J})})}0&&(module.exports={BarChart,resetBarChartWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as ut,useCallback as K,useId as vt,useMemo as E,useState as Ue}from"react";import{cn as xt}from"../../lib/cn.js";import{useUILabels as kt}from"../../lib/i18n.js";import{ChartAnnotationLayer as ot,describeAnnotations as St}from"../chart/ChartAnnotations.js";import{ChartAxis as at}from"../chart/ChartAxis.js";import{ChartBrushLayer as Bt,useChartBrush as Pt}from"../chart/ChartBrush.js";import{ChartContainer as wt}from"../chart/ChartContainer.js";import{ChartGrid as Lt}from"../chart/ChartGrid.js";import{ChartLegend as Rt}from"../chart/ChartLegend.js";import{ChartPatternDefs as At,patternFill as Tt}from"../chart/ChartPatterns.js";import{ChartScaleLegend as Et}from"../chart/ChartScaleLegend.js";import{useChartSync as Vt}from"../chart/ChartSync.js";import{ChartTableView as Mt}from"../chart/ChartTableView.js";import{ChartTooltip as It,ChartTooltipContent as Dt}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as Ht,createDivergingScale as lt,getSeriesLabel as it,resolveSeriesColor as Wt,toLegendItems as Nt}from"../chart/palette.js";import{buildCartesianGeometry as Ot,createCategoryLocator as _t,createPlotContext as $t,splitOverlay as Kt}from"../chart/utils/cartesian.js";import{collectAllValues as ze,readNumber as xe}from"../chart/utils/data.js";import{formatAuto as Xt,formatPercent as Gt,formatXValue as Ut}from"../chart/utils/format.js";import{chartCursorTarget as zt,pressChartMark as Ft}from"../chart/utils/keyboard.js";import{binValues as Yt}from"../chart/utils/bins.js";import{buildBarPath as Zt,buildLinePath as jt}from"../chart/utils/path.js";import{nearestIndex as qt,toKey as st}from"../chart/utils/scales.js";import{stackDiverging as Jt,stackExtent as Qt,stackSeries as en}from"../chart/utils/stack.js";import{estimateTextWidth as tn}from"../chart/utils/text.js";import{extent as ct,resolveDomain as nn}from"../chart/utils/ticks.js";import{CHART_TOUCH as rn,CHART_TOUCH_VERTICAL_DRAG as on}from"../chart/utils/touch.js";import{Fragment as dn,jsx as i,jsxs as ce}from"react/jsx-runtime";var an=24,ee=2,ln=4,se=6,sn=10,Fe=!1,Ye=!1;function $n(){Fe=!1,Ye=!1}var cn=ut(function({bars:f,patterns:n,patternBaseId:u}){return i("g",{children:f.map((m,R)=>ce("g",{children:[i("path",{d:m.d,fill:Tt(n,u,m.slot,m.color)}),m.label?i("text",{x:m.label.x,y:m.label.y,textAnchor:m.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:m.label.text}):null]},`${m.key}-${R}`))})}),un=ut(function({lines:f}){return i("g",{children:f.map(n=>ce("g",{children:[i("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(u=>i("circle",{cx:u.x,cy:u.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${u.x}-${u.y}`))]},n.key))})});function hn({width:v,height:f,data:n,resolvedSeries:u,x:m,y:R,grid:V,size:ke,orientation:A,stack:H,center:T,centerKey:M,valueColors:X,binned:te,curve:Se,barSize:Be,showValues:Pe,referenceLines:De,annotations:G,annotationsLabel:He,patterns:we,patternBaseId:ne,overlay:Le,brush:P,onBrush:U,brushLabel:We,syncEnabled:Ne,margin:re,tooltip:z,onPointClick:F,plotLabel:Re,formatValue:W,formatRaw:Y,formatX:oe}){let[ue,he]=Ue(null),c=ue!==null&&ue<n.length?ue:null,[Oe,_e]=Ue(null),I=Vt(),y=Ne?I:null,e=E(()=>{let t=A==="vertical",r=u.filter(h=>!h.hidden),o=r.filter(h=>h.type!=="line"),g=r.filter(h=>h.type==="line"),w=o.map(h=>h.key),p=M!==null||H!=="none",l=M!==null?Jt(n,w,{centerKey:M,percent:H==="percent"}):en(n,w,H),a=p?Qt(l):ct(ze(n,w)),s=ct(ze(n,g.map(h=>h.key))),d=a===null?s:s===null?a:[Math.min(a[0],s[0]),Math.max(a[1],s[1])],L=Ot({width:v,height:f,data:n,x:m,y:R,bounds:d===null?null:[Math.min(d[0],T),Math.max(d[1],T)],margin:re,orientation:A,placement:"band",bandPaddingInner:te?0:void 0,formatValue:W,formatX:oe,defaultIncludeZero:T===0}),{valueScale:be,bandwidth:ye,categoryPositions:Ze,innerWidth:je,innerHeight:qe}=L,ht=be(T),Ee=Math.max(1,o.length),dt=p?ye:ye/Ee,$=Math.min(Be??(te?Number.POSITIVE_INFINITY:an),Math.max(1,dt-(p&&!te?0:ee))),mt=p?$:Ee*$+(Ee-1)*ee,Je=(ye-mt)/2,Qe=[],et=h=>p?h.end>=h.start:h.end>=T;l.forEach((h,Ve)=>{let q=-1,Me=-1;h.segments.forEach((B,le)=>{B.value!==null&&B.outer!==!1&&(et(B)?q=le:Me=le)});let ae=0,Ce=0;h.segments.forEach((B,le)=>{if(B.value===null)return;let Ke=o[le],C=et(B),tt=be(p?B.start:T),nt=be(B.end),J=Math.min(tt,nt),ie=Math.abs(nt-tt),gt=B.base??(C?ae===0:Ce===0),pt=t?!C:C;p&&!gt&&ie>ee&&(ie-=ee,pt&&(J+=ee)),C?ae+=1:Ce+=1;let Ie=Ze[Ve]+(p?Je:Je+le*($+ee)),bt=le===(C?q:Me)?t?C?"top":"bottom":C?"right":"left":"none",yt=t?{x:Ie,y:J,width:$,height:ie}:{x:J,y:Ie,width:ie,height:$},Xe=null;if(Pe&&!p){let Ge=Y(B.value),rt=tn(Ge,10);if(t){let Q=C?J:J+ie,ve=C?Q-se:Q+se,Ct=Ee>1?$+ee:ye;rt<=Ct&&(C?ve>8:ve<qe-4)&&(Xe={x:Ie+$/2,y:ve,anchor:"middle",text:Ge})}else{let Q=C?J+ie:J,ve=C?je-Q-se:Q-se;rt<=ve&&(Xe={x:C?Q+se:Q-se,y:Ie+$/2,anchor:C?"start":"end",text:Ge})}}Qe.push({key:Ke.key,slot:Ke.slot,color:X&&B.value!==null?X(B.value):Ke.color,d:Zt({...yt,radius:ln,round:bt}),label:Xe})})});let ft=g.map(h=>{let Ve=L.categoryCenters.map((q,Me)=>{let ae=xe(n[Me],h.key),Ce=ae===null?Number.NaN:be(ae);return{x:t?q:Ce,y:t?Ce:q,defined:ae!==null}});return{key:h.key,color:h.color,dashed:h.dashed,d:jt(Ve,Se),markers:Ve.filter(q=>q.defined!==!1)}});return{vertical:t,visible:r,locate:_t(L),barSeries:o,rows:l,stacked:p,plot:$t({geometry:L,width:v,height:f,data:n,series:r,formatValue:W,formatX:oe}),xValues:L.xValues,categoryPositions:Ze,categoryCenters:L.categoryCenters,bandwidth:ye,categoryTicks:L.categoryTicks,valueTicks:L.valueTicks,valueScale:be,baseline:ht,innerWidth:je,innerHeight:qe,margin:L.margin,bars:Qe,lines:ft}},[n,u,m,R,v,f,re,A,H,T,M,X,te,Se,Be,Pe,W,Y,oe]),de=K(t=>e.visible.map(r=>{let o=xe(n[t],r.key),g=e.barSeries.indexOf(r),w=g===-1?null:e.rows[t].segments[g],p=o===null?"\u2014":H==="percent"&&w!==null?`${Y(o)} (${W(w.end-w.start)})`:W(o);return{seriesKey:r.key,seriesLabel:it(r),color:r.color,value:o,formattedValue:p,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,H,W,Y]),me=y?y.brush:Oe,Ae=K(t=>{_e(t),y?.setBrush(t),U?.(t)},[y,U]),x=Pt({enabled:P,active:me!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:A,onCommit:Ae}),$e=K(t=>{if(x.onPointerMove(t),z===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),o=e.vertical?t.clientX-r.left-e.margin.left:t.clientY-r.top-e.margin.top,g=qt(e.categoryCenters,o);he(g>=0?g:null),y?.setHovered(g>=0?e.xValues[g]:null)},[x,z,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,y]),k=K(()=>{he(null),y?.setHovered(null)},[y]),b=K(()=>{if(!F||c===null)return;let[t]=de(c);t&&F({...t,index:c,x:e.xValues[c]})},[F,c,de,e.xValues]),Z=K(t=>{if(n.length===0)return;let r=F&&c!==null&&e.visible.length>0;if(Ft(t,r?b:null))return;x.onKeyDown(t,c);let o=zt(t.key,c,n.length,e.vertical?"x":"y");o!==void 0&&(t.preventDefault(),he(o),y?.setHovered(o===null?null:e.xValues[o]))},[n.length,c,e.vertical,x,y,e.xValues,e.visible.length,F,b]),N=K(()=>{x.consumedClick()||b()},[x,b]),O=c!==null||!y?.hovered?null:(()=>{let t=st(y.hovered),r=e.xValues.findIndex(o=>st(o)===t);return r<0?null:r})(),S=c??O,D=x.dragging??me,_=(()=>{if(!D)return null;let t=e.locate(D.from),r=e.locate(D.to);if(t===null||r===null)return null;let o=e.bandwidth/2;return{from:Math.min(t,r)-o,to:Math.max(t,r)+o}})(),Te=Kt(Le),fe=c===null?null:de(c),j=c===null||fe===null?null:{x:e.xValues[c],xLabel:oe(e.xValues[c],c),index:c,points:fe},ge=t=>{let r=e.rows[t].segments.filter(o=>o.value!==null).map(o=>e.valueScale(o.end));for(let o of e.lines){let g=xe(n[t],o.key);g!==null&&r.push(e.valueScale(g))}return r},pe=c===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[c],y:e.margin.top+Math.min(...ge(c),e.baseline)}:{x:e.margin.left+Math.max(...ge(c),e.baseline),y:e.margin.top+e.categoryCenters[c]};return ce(dn,{children:[ce("svg",{width:v,height:f,role:"img","aria-label":Re??[e.visible.map(t=>it(t)).join(", "),St(G,He)].filter(Boolean).join(". "),tabIndex:0,className:xt(P&&!e.vertical?on:rn,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500",P&&"select-none"),onPointerDown:x.onPointerDown,onPointerMove:$e,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerUp,onPointerLeave:k,onKeyDown:Z,onBlur:k,onClick:N,children:[we?i(At,{id:ne,entries:u.map(t=>({slot:t.slot,color:t.color}))}):null,ce("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[i(Lt,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(V==="y"||V==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(V==="y"||V==="both")?e.valueTicks.map(t=>t.offset):void 0}),G?i(ot,{layer:"under",annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,_?i(Bt,{from:_.from,to:_.to,width:e.innerWidth,height:e.innerHeight,orientation:A,live:x.dragging!==null,label:We}):null,S!==null?i("rect",{x:e.vertical?e.categoryPositions[S]:0,y:e.vertical?0:e.categoryPositions[S],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,Te.under?.(e.plot),i(cn,{bars:e.bars,patterns:we,patternBaseId:ne}),e.lines.length>0?i(un,{lines:e.lines}):null,i("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),G?i(ot,{annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,Te.over?.(e.plot),De?.map(t=>{let r=e.valueScale(t.value),o=r<sn?r+12:r-4;return ce("g",{children:[i("line",{x1:e.vertical?0:r,y1:e.vertical?r:0,x2:e.vertical?e.innerWidth:r,y2:e.vertical?r:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?i("text",{x:e.vertical?e.innerWidth:r+4,y:e.vertical?o:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?m.hidden:R?.hidden)?null:i(at,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?m.label:R?.label,size:ke})}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?R?.hidden:m.hidden)?null:i(at,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?R?.label:m.label,size:ke})})]}),j&&pe&&z!==!1?i(It,{x:pe.x,y:pe.y,containerWidth:v,children:typeof z=="function"?z(j):i(Dt,{title:j.xLabel,points:j.points})}):null]})}function Kn({data:v,series:f,x:n,y:u,height:m=260,width:R,size:V="md",grid:ke="y",legend:A,tooltip:H=!0,tableView:T=!1,emphasis:M,title:X,description:te,loading:Se=!1,emptyState:Be,error:Pe=!1,errorState:De,onRetry:G,actions:He,onPointClick:we,orientation:ne="vertical",stack:Le="none",diverging:P,bins:U,curve:We="linear",barSize:Ne,sort:re="none",showValues:z=!1,referenceLines:F,annotations:Re,overlay:W,patterns:Y=!1,legendToggle:oe=!0,brush:ue=!1,onBrush:he,brushLabel:c,sync:Oe=!0,margin:_e,locale:I,plotLabel:y,className:e,...de}){let me=kt(),[Ae,x]=Ue(()=>new Set),$e=vt(),k=U!==void 0&&U!==!1,b=k||typeof P!="string"?null:P,Z=!k&&typeof P=="number"?P:0,N=E(()=>{let l=b===null?null:lt([0,Math.max(1,f.length-1)],{center:Math.max(0,f.findIndex(a=>a.key===b)),symmetric:!1});return f.map((a,s)=>({...a,slot:s,hidden:a.hidden||Ae.has(a.key),color:l&&!a.color&&!M?a.key===b?Ht:l(s):Wt(a,s,M)}))},[f,Ae,M,b]),O=E(()=>l=>Xt(l,I),[I]),S=E(()=>{if(!k)return null;f.length>1&&!Fe&&(Fe=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let l=f[0]?.key??"count",a=n.format?d=>n.format(d,0):d=>O(d),s=Yt(v.map(d=>xe(d,n.key)),U);return{rows:s.map(d=>({[n.key]:d.from,[l]:d.count})),labels:s.map(d=>`${a(d.from)}\u2013${a(d.to)}`)}},[k,U,v,n.key,n.format,f,O]),D=E(()=>{if(S)return S.rows;if(re==="none")return v;let l=N.filter(s=>!s.hidden).map(s=>s.key),a=s=>l.reduce((d,L)=>d+(xe(s,L)??0),0);return[...v].sort((s,d)=>re==="asc"?a(s)-a(d):a(d)-a(s))},[S,v,re,N]),_=!k&&Le==="percent",Te=E(()=>_?{domain:b===null?[0,100]:[-100,100],...u}:u,[_,b,u]),fe=E(()=>{let l=u?.format??(_?a=>Gt(a,{locale:I,alreadyScaled:!0,maximumFractionDigits:0}):O);return b===null?l:a=>l(Math.abs(a))},[u?.format,_,I,O,b]),j=E(()=>S?(l,a)=>S.labels[a]??"":n.format??(l=>Ut(l,I)),[S,n.format,I]),ge=E(()=>S?{...n,scale:"category"}:n,[S,n]),pe=K(l=>{x(a=>{let s=new Set(a);return s.has(l)?s.delete(l):s.add(l),s})},[]),t=ne==="vertical"?Re:void 0;Re&&ne!=="vertical"&&!Ye&&(Ye=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let r=A===void 0?f.length>=2:A!==!1,o=typeof A=="string"?A:"bottom",g=N.filter(l=>!l.hidden),w=g.length,p=E(()=>{if(k||P===void 0||P===!1||b!==null||w!==1)return null;let l=ze(D,g.map(s=>s.key)),a=nn([...l,Z],{domain:u?.domain,includeZero:u?.includeZero??Z===0,ticks:u?.ticks??5});return lt(a,{center:Z})},[k,P,b,w,g,D,Z,u]);return i(wt,{title:X,description:te,height:m,width:R,size:V,loading:Se,empty:D.length===0||w===0,emptyState:Be,error:Pe,errorState:De,onRetry:G,actions:He,tableView:T,legendPosition:o,legend:p?i(Et,{scale:p,label:u?.label,format:fe,size:V,locale:I}):r?i(Rt,{items:Nt(N,M,Y),position:o,marker:"rect",size:V,onToggle:oe?pe:void 0}):void 0,table:T?i(Mt,{data:D,series:N,xKey:ge.key,xLabel:n.label??n.key,formatX:j,formatValue:O,caption:typeof X=="string"?X:void 0}):void 0,className:e,...de,children:({width:l})=>i(hn,{width:l,height:m,data:D,resolvedSeries:N,x:ge,y:Te,grid:ke,size:V,orientation:ne,stack:k?"none":Le,center:Z,centerKey:b,valueColors:p,binned:k,curve:We,barSize:Ne,showValues:z,referenceLines:F,annotations:t,annotationsLabel:me.chartAnnotations,patterns:Y&&p===null,patternBaseId:$e,overlay:W,brush:ue,onBrush:he,brushLabel:c??me.chartBrush,syncEnabled:Oe,margin:_e,tooltip:H,onPointClick:we,plotLabel:y,formatValue:fe,formatRaw:O,formatX:j})})}export{Kn as BarChart,$n as resetBarChartWarnings};
|
|
1
|
+
"use client";import{memo as ut,useCallback as K,useId as vt,useMemo as E,useState as Ue}from"react";import{cn as xt}from"../../lib/cn.js";import{useUILabels as kt}from"../../lib/i18n.js";import{ChartAnnotationLayer as ot,describeAnnotations as St}from"../chart/ChartAnnotations.js";import{ChartAxis as at}from"../chart/ChartAxis.js";import{ChartBrushLayer as Bt,useChartBrush as Pt}from"../chart/ChartBrush.js";import{ChartContainer as wt}from"../chart/ChartContainer.js";import{ChartGrid as Lt}from"../chart/ChartGrid.js";import{ChartLegend as Rt}from"../chart/ChartLegend.js";import{ChartPatternDefs as At,patternFill as Tt}from"../chart/ChartPatterns.js";import{ChartScaleLegend as Et}from"../chart/ChartScaleLegend.js";import{useChartSync as Vt}from"../chart/ChartSync.js";import{ChartTableView as Mt}from"../chart/ChartTableView.js";import{ChartTooltip as It,ChartTooltipContent as Dt}from"../chart/ChartTooltip.js";import{CHART_MUTED_COLOR as Ht,createDivergingScale as lt,getSeriesLabel as it,resolveSeriesColor as Wt,toLegendItems as Nt}from"../chart/palette.js";import{buildCartesianGeometry as Ot,createCategoryLocator as _t,createPlotContext as $t,splitOverlay as Kt}from"../chart/utils/cartesian.js";import{collectAllValues as ze,readNumber as xe}from"../chart/utils/data.js";import{formatAuto as Xt,formatPercent as Gt,formatXValue as Ut}from"../chart/utils/format.js";import{chartCursorTarget as zt,pressChartMark as Ft}from"../chart/utils/keyboard.js";import{binValues as Yt}from"../chart/utils/bins.js";import{buildBarPath as Zt,buildLinePath as jt}from"../chart/utils/path.js";import{nearestIndex as qt,toKey as st}from"../chart/utils/scales.js";import{stackDiverging as Jt,stackExtent as Qt,stackSeries as en}from"../chart/utils/stack.js";import{estimateTextWidth as tn}from"../chart/utils/text.js";import{extent as ct,resolveDomain as nn}from"../chart/utils/ticks.js";import{CHART_TOUCH as rn,CHART_TOUCH_VERTICAL_DRAG as on}from"../chart/utils/touch.js";import{Fragment as dn,jsx as i,jsxs as ce}from"react/jsx-runtime";var an=24,ee=2,ln=4,se=6,sn=10,Fe=!1,Ye=!1;function $n(){Fe=!1,Ye=!1}var cn=ut(function({bars:f,patterns:n,patternBaseId:u}){return i("g",{children:f.map((m,R)=>ce("g",{children:[i("path",{d:m.d,fill:Tt(n,u,m.slot,m.color)}),m.label?i("text",{x:m.label.x,y:m.label.y,textAnchor:m.label.anchor,dominantBaseline:"middle",className:"fill-gray-600 text-[10px] [font-variant-numeric:tabular-nums] dark:fill-gray-300",children:m.label.text}):null]},`${m.key}-${R}`))})}),un=ut(function({lines:f}){return i("g",{children:f.map(n=>ce("g",{children:[i("path",{d:n.d,fill:"none",stroke:n.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:n.dashed?"5 4":void 0}),n.markers.map(u=>i("circle",{cx:u.x,cy:u.y,r:3,fill:n.color,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"},`${u.x}-${u.y}`))]},n.key))})});function hn({width:v,height:f,data:n,resolvedSeries:u,x:m,y:R,grid:V,size:ke,orientation:A,stack:H,center:T,centerKey:M,valueColors:X,binned:te,curve:Se,barSize:Be,showValues:Pe,referenceLines:De,annotations:G,annotationsLabel:He,patterns:we,patternBaseId:ne,overlay:Le,brush:P,onBrush:U,brushLabel:We,syncEnabled:Ne,margin:re,tooltip:z,onPointClick:F,plotLabel:Re,formatValue:W,formatRaw:Y,formatX:oe}){let[ue,he]=Ue(null),c=ue!==null&&ue<n.length?ue:null,[Oe,_e]=Ue(null),I=Vt(),y=Ne?I:null,e=E(()=>{let t=A==="vertical",r=u.filter(h=>!h.hidden),o=r.filter(h=>h.type!=="line"),g=r.filter(h=>h.type==="line"),w=o.map(h=>h.key),p=M!==null||H!=="none",l=M!==null?Jt(n,w,{centerKey:M,percent:H==="percent"}):en(n,w,H),a=p?Qt(l):ct(ze(n,w)),s=ct(ze(n,g.map(h=>h.key))),d=a===null?s:s===null?a:[Math.min(a[0],s[0]),Math.max(a[1],s[1])],L=Ot({width:v,height:f,data:n,x:m,y:R,bounds:d===null?null:[Math.min(d[0],T),Math.max(d[1],T)],margin:re,orientation:A,placement:"band",bandPaddingInner:te?0:void 0,formatValue:W,formatX:oe,defaultIncludeZero:T===0}),{valueScale:be,bandwidth:ye,categoryPositions:Ze,innerWidth:je,innerHeight:qe}=L,ht=be(T),Ee=Math.max(1,o.length),dt=p?ye:ye/Ee,$=Math.min(Be??(te?Number.POSITIVE_INFINITY:an),Math.max(1,dt-(p&&!te?0:ee))),mt=p?$:Ee*$+(Ee-1)*ee,Je=(ye-mt)/2,Qe=[],et=h=>p?h.end>=h.start:h.end>=T;l.forEach((h,Ve)=>{let q=-1,Me=-1;h.segments.forEach((B,le)=>{B.value!==null&&B.outer!==!1&&(et(B)?q=le:Me=le)});let ae=0,Ce=0;h.segments.forEach((B,le)=>{if(B.value===null)return;let Ke=o[le],C=et(B),tt=be(p?B.start:T),nt=be(B.end),J=Math.min(tt,nt),ie=Math.abs(nt-tt),gt=B.base??(C?ae===0:Ce===0),pt=t?!C:C;p&&!gt&&ie>ee&&(ie-=ee,pt&&(J+=ee)),C?ae+=1:Ce+=1;let Ie=Ze[Ve]+(p?Je:Je+le*($+ee)),bt=le===(C?q:Me)?t?C?"top":"bottom":C?"right":"left":"none",yt=t?{x:Ie,y:J,width:$,height:ie}:{x:J,y:Ie,width:ie,height:$},Xe=null;if(Pe&&!p){let Ge=Y(B.value),rt=tn(Ge,10);if(t){let Q=C?J:J+ie,ve=C?Q-se:Q+se,Ct=Ee>1?$+ee:ye;rt<=Ct&&(C?ve>8:ve<qe-4)&&(Xe={x:Ie+$/2,y:ve,anchor:"middle",text:Ge})}else{let Q=C?J+ie:J,ve=C?je-Q-se:Q-se;rt<=ve&&(Xe={x:C?Q+se:Q-se,y:Ie+$/2,anchor:C?"start":"end",text:Ge})}}Qe.push({key:Ke.key,slot:Ke.slot,color:X&&B.value!==null?X(B.value):Ke.color,d:Zt({...yt,radius:ln,round:bt}),label:Xe})})});let ft=g.map(h=>{let Ve=L.categoryCenters.map((q,Me)=>{let ae=xe(n[Me],h.key),Ce=ae===null?Number.NaN:be(ae);return{x:t?q:Ce,y:t?Ce:q,defined:ae!==null}});return{key:h.key,color:h.color,dashed:h.dashed,d:jt(Ve,Se),markers:Ve.filter(q=>q.defined!==!1)}});return{vertical:t,visible:r,locate:_t(L),barSeries:o,rows:l,stacked:p,plot:$t({geometry:L,width:v,height:f,data:n,series:r,formatValue:W,formatX:oe}),xValues:L.xValues,categoryPositions:Ze,categoryCenters:L.categoryCenters,bandwidth:ye,categoryTicks:L.categoryTicks,valueTicks:L.valueTicks,valueScale:be,baseline:ht,innerWidth:je,innerHeight:qe,margin:L.margin,bars:Qe,lines:ft}},[n,u,m,R,v,f,re,A,H,T,M,X,te,Se,Be,Pe,W,Y,oe]),de=K(t=>e.visible.map(r=>{let o=xe(n[t],r.key),g=e.barSeries.indexOf(r),w=g===-1?null:e.rows[t].segments[g],p=o===null?"\u2014":H==="percent"&&w!==null?`${Y(o)} (${W(w.end-w.start)})`:W(o);return{seriesKey:r.key,seriesLabel:it(r),color:r.color,value:o,formattedValue:p,datum:n[t]}}),[n,e.visible,e.barSeries,e.rows,H,W,Y]),me=y?y.brush:Oe,Ae=K(t=>{_e(t),y?.setBrush(t),U?.(t)},[y,U]),x=Pt({enabled:P,active:me!==null,centers:e.categoryCenters,xValues:e.xValues,offset:e.vertical?e.margin.left:e.margin.top,orientation:A,onCommit:Ae}),$e=K(t=>{if(x.onPointerMove(t),z===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),o=e.vertical?t.clientX-r.left-e.margin.left:t.clientY-r.top-e.margin.top,g=qt(e.categoryCenters,o);he(g>=0?g:null),y?.setHovered(g>=0?e.xValues[g]:null)},[x,z,n.length,e.vertical,e.margin,e.categoryCenters,e.xValues,y]),k=K(()=>{he(null),y?.setHovered(null)},[y]),b=K(()=>{if(!F||c===null)return;let[t]=de(c);t&&F({...t,index:c,x:e.xValues[c]})},[F,c,de,e.xValues]),Z=K(t=>{if(n.length===0)return;let r=F&&c!==null&&e.visible.length>0;if(Ft(t,r?b:null))return;x.onKeyDown(t,c);let o=zt(t.key,c,n.length,e.vertical?"x":"y");o!==void 0&&(t.preventDefault(),he(o),y?.setHovered(o===null?null:e.xValues[o]))},[n.length,c,e.vertical,x,y,e.xValues,e.visible.length,F,b]),N=K(()=>{x.consumedClick()||b()},[x,b]),O=c!==null||!y?.hovered?null:(()=>{let t=st(y.hovered),r=e.xValues.findIndex(o=>st(o)===t);return r<0?null:r})(),S=c??O,D=x.dragging??me,_=(()=>{if(!D)return null;let t=e.locate(D.from),r=e.locate(D.to);if(t===null||r===null)return null;let o=e.bandwidth/2;return{from:Math.min(t,r)-o,to:Math.max(t,r)+o}})(),Te=Kt(Le),fe=c===null?null:de(c),j=c===null||fe===null?null:{x:e.xValues[c],xLabel:oe(e.xValues[c],c),index:c,points:fe},ge=t=>{let r=e.rows[t].segments.filter(o=>o.value!==null).map(o=>e.valueScale(o.end));for(let o of e.lines){let g=xe(n[t],o.key);g!==null&&r.push(e.valueScale(g))}return r},pe=c===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[c],y:e.margin.top+Math.min(...ge(c),e.baseline)}:{x:e.margin.left+Math.max(...ge(c),e.baseline),y:e.margin.top+e.categoryCenters[c]};return ce(dn,{children:[ce("svg",{width:v,height:f,role:"img","aria-label":Re??[e.visible.map(t=>it(t)).join(", "),St(G,He)].filter(Boolean).join(". "),tabIndex:0,className:xt(P&&!e.vertical?on:rn,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",P&&"select-none"),onPointerDown:x.onPointerDown,onPointerMove:$e,onPointerUp:x.onPointerUp,onPointerCancel:x.onPointerUp,onPointerLeave:k,onKeyDown:Z,onBlur:k,onClick:N,children:[we?i(At,{id:ne,entries:u.map(t=>({slot:t.slot,color:t.color}))}):null,ce("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[i(Lt,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&(V==="y"||V==="both")?e.valueTicks.map(t=>t.offset):void 0,vertical:!e.vertical&&(V==="y"||V==="both")?e.valueTicks.map(t=>t.offset):void 0}),G?i(ot,{layer:"under",annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,_?i(Bt,{from:_.from,to:_.to,width:e.innerWidth,height:e.innerHeight,orientation:A,live:x.dragging!==null,label:We}):null,S!==null?i("rect",{x:e.vertical?e.categoryPositions[S]:0,y:e.vertical?0:e.categoryPositions[S],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,Te.under?.(e.plot),i(cn,{bars:e.bars,patterns:we,patternBaseId:ne}),e.lines.length>0?i(un,{lines:e.lines}):null,i("line",{x1:e.vertical?0:e.baseline,y1:e.vertical?e.baseline:0,x2:e.vertical?e.innerWidth:e.baseline,y2:e.vertical?e.baseline:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,shapeRendering:"crispEdges"}),G?i(ot,{annotations:G,xAt:e.locate,yAt:e.valueScale,width:e.innerWidth,height:e.innerHeight,bandwidth:e.bandwidth}):null,Te.over?.(e.plot),De?.map(t=>{let r=e.valueScale(t.value),o=r<sn?r+12:r-4;return ce("g",{children:[i("line",{x1:e.vertical?0:r,y1:e.vertical?r:0,x2:e.vertical?e.innerWidth:r,y2:e.vertical?r:e.innerHeight,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?i("text",{x:e.vertical?e.innerWidth:r+4,y:e.vertical?o:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)})]}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?m.hidden:R?.hidden)?null:i(at,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?m.label:R?.label,size:ke})}),i("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?R?.hidden:m.hidden)?null:i(at,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?R?.label:m.label,size:ke})})]}),j&&pe&&z!==!1?i(It,{x:pe.x,y:pe.y,containerWidth:v,children:typeof z=="function"?z(j):i(Dt,{title:j.xLabel,points:j.points})}):null]})}function Kn({data:v,series:f,x:n,y:u,height:m=260,width:R,size:V="md",grid:ke="y",legend:A,tooltip:H=!0,tableView:T=!1,emphasis:M,title:X,description:te,loading:Se=!1,emptyState:Be,error:Pe=!1,errorState:De,onRetry:G,actions:He,onPointClick:we,orientation:ne="vertical",stack:Le="none",diverging:P,bins:U,curve:We="linear",barSize:Ne,sort:re="none",showValues:z=!1,referenceLines:F,annotations:Re,overlay:W,patterns:Y=!1,legendToggle:oe=!0,brush:ue=!1,onBrush:he,brushLabel:c,sync:Oe=!0,margin:_e,locale:I,plotLabel:y,className:e,...de}){let me=kt(),[Ae,x]=Ue(()=>new Set),$e=vt(),k=U!==void 0&&U!==!1,b=k||typeof P!="string"?null:P,Z=!k&&typeof P=="number"?P:0,N=E(()=>{let l=b===null?null:lt([0,Math.max(1,f.length-1)],{center:Math.max(0,f.findIndex(a=>a.key===b)),symmetric:!1});return f.map((a,s)=>({...a,slot:s,hidden:a.hidden||Ae.has(a.key),color:l&&!a.color&&!M?a.key===b?Ht:l(s):Wt(a,s,M)}))},[f,Ae,M,b]),O=E(()=>l=>Xt(l,I),[I]),S=E(()=>{if(!k)return null;f.length>1&&!Fe&&(Fe=!0,console.warn("[@synertech/ui] BarChart was given `bins` and more than one series. A histogram counts a single field \u2014 the extra series are ignored. Facet the chart, or draw the distributions side by side."));let l=f[0]?.key??"count",a=n.format?d=>n.format(d,0):d=>O(d),s=Yt(v.map(d=>xe(d,n.key)),U);return{rows:s.map(d=>({[n.key]:d.from,[l]:d.count})),labels:s.map(d=>`${a(d.from)}\u2013${a(d.to)}`)}},[k,U,v,n.key,n.format,f,O]),D=E(()=>{if(S)return S.rows;if(re==="none")return v;let l=N.filter(s=>!s.hidden).map(s=>s.key),a=s=>l.reduce((d,L)=>d+(xe(s,L)??0),0);return[...v].sort((s,d)=>re==="asc"?a(s)-a(d):a(d)-a(s))},[S,v,re,N]),_=!k&&Le==="percent",Te=E(()=>_?{domain:b===null?[0,100]:[-100,100],...u}:u,[_,b,u]),fe=E(()=>{let l=u?.format??(_?a=>Gt(a,{locale:I,alreadyScaled:!0,maximumFractionDigits:0}):O);return b===null?l:a=>l(Math.abs(a))},[u?.format,_,I,O,b]),j=E(()=>S?(l,a)=>S.labels[a]??"":n.format??(l=>Ut(l,I)),[S,n.format,I]),ge=E(()=>S?{...n,scale:"category"}:n,[S,n]),pe=K(l=>{x(a=>{let s=new Set(a);return s.has(l)?s.delete(l):s.add(l),s})},[]),t=ne==="vertical"?Re:void 0;Re&&ne!=="vertical"&&!Ye&&(Ye=!0,console.warn("[@synertech/ui] BarChart was given `annotations` and a horizontal orientation. Annotations are read on the category axis, which runs up the side there: they are ignored. Use `referenceLines` for a threshold on the value axis."));let r=A===void 0?f.length>=2:A!==!1,o=typeof A=="string"?A:"bottom",g=N.filter(l=>!l.hidden),w=g.length,p=E(()=>{if(k||P===void 0||P===!1||b!==null||w!==1)return null;let l=ze(D,g.map(s=>s.key)),a=nn([...l,Z],{domain:u?.domain,includeZero:u?.includeZero??Z===0,ticks:u?.ticks??5});return lt(a,{center:Z})},[k,P,b,w,g,D,Z,u]);return i(wt,{title:X,description:te,height:m,width:R,size:V,loading:Se,empty:D.length===0||w===0,emptyState:Be,error:Pe,errorState:De,onRetry:G,actions:He,tableView:T,legendPosition:o,legend:p?i(Et,{scale:p,label:u?.label,format:fe,size:V,locale:I}):r?i(Rt,{items:Nt(N,M,Y),position:o,marker:"rect",size:V,onToggle:oe?pe:void 0}):void 0,table:T?i(Mt,{data:D,series:N,xKey:ge.key,xLabel:n.label??n.key,formatX:j,formatValue:O,caption:typeof X=="string"?X:void 0}):void 0,className:e,...de,children:({width:l})=>i(hn,{width:l,height:m,data:D,resolvedSeries:N,x:ge,y:Te,grid:ke,size:V,orientation:ne,stack:k?"none":Le,center:Z,centerKey:b,valueColors:p,binned:k,curve:We,barSize:Ne,showValues:z,referenceLines:F,annotations:t,annotationsLabel:me.chartAnnotations,patterns:Y&&p===null,patternBaseId:$e,overlay:W,brush:ue,onBrush:he,brushLabel:c??me.chartBrush,syncEnabled:Oe,margin:_e,tooltip:H,onPointClick:we,plotLabel:y,formatValue:fe,formatRaw:O,formatX:j})})}export{Kn as BarChart,$n as resetBarChartWarnings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ke=(s,o)=>{for(var d in o)se(s,d,{get:o[d],enumerable:!0})},qe=(s,o,d,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of De(o))!Ge.call(s,n)&&n!==d&&se(s,n,{get:()=>o[n],enumerable:!(a=ze(o,n))||a.enumerable});return s};var Oe=s=>qe(se({},"__esModule",{value:!0}),s);var Ze={};Ke(Ze,{BoxPlot:()=>je});module.exports=Oe(Ze);var f=require("react"),ue=require("../../lib/i18n.cjs"),me=require("../chart/ChartAxis.cjs"),Ce=require("../chart/ChartContainer.cjs"),ve=require("../chart/ChartGrid.cjs"),ke=require("../chart/ChartTooltip.cjs"),Pe=require("../chart/palette.cjs"),Ne=require("../chart/utils/cartesian.cjs"),B=require("../chart/utils/data.cjs"),ee=require("../chart/utils/format.cjs"),Te=require("../chart/utils/keyboard.cjs"),Be=require("../chart/utils/path.cjs"),we=require("../chart/utils/quantile.cjs"),Se=require("../chart/utils/scales.cjs"),Re=require("../chart/utils/touch.cjs"),Le=require("../table/Table.cjs"),Me=require("../table/TableBody.cjs"),O=require("../table/TableCell.cjs"),$e=require("../table/TableHeader.cjs"),P=require("../table/TableHeaderCell.cjs"),He=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),_e=40,Qe=3,J=4,ce="text-right [font-variant-numeric:tabular-nums]",Ue=(0,f.memo)(function({boxes:o,color:d}){return(0,t.jsx)("g",{children:o.map(a=>(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{stroke:d,strokeWidth:1.5,strokeLinecap:"round",children:a.whiskers.map(n=>(0,t.jsx)("line",{x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2},n.key))}),a.body?(0,t.jsx)("path",{d:a.body,fill:d}):null,a.median?(0,t.jsx)("line",{x1:a.median.x1,y1:a.median.y1,x2:a.median.x2,y2:a.median.y2,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a.mean?(0,t.jsx)("path",{d:`M${a.mean.cx},${a.mean.cy-J} L${a.mean.cx+J},${a.mean.cy} L${a.mean.cx},${a.mean.cy+J} L${a.mean.cx-J},${a.mean.cy} Z`,strokeWidth:1.5,stroke:d,className:"fill-white dark:fill-gray-800"}):null,a.outliers.map(n=>(0,t.jsx)("circle",{cx:n.cx,cy:n.cy,r:Qe,fill:d,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},n.key))]},a.key))})});function Ye({width:s,height:o,data:d,boxes:a,x:n,y:x,grid:$,size:_,orientation:w,boxSize:Q,showOutliers:U,showMean:I,color:Y,referenceLines:te,margin:z,tooltip:S,plotLabel:ae,formatValue:H,formatX:A,onBoxClick:R}){let[D,E]=(0,f.useState)(null),g=D!==null&&D<a.length?D:null,W=(0,ue.useUILabels)(),e=(0,f.useMemo)(()=>{let l=w==="vertical",c=a.flatMap(m=>m.stats===null?[]:[m.stats.min,m.stats.max,...I&&m.mean!==null?[m.mean]:[]]),b=(0,Ne.buildCartesianGeometry)({width:s,height:o,data:d,x:n,y:x,bounds:c.length===0?null:[Math.min(...c),Math.max(...c)],margin:z,orientation:w,placement:"band",formatValue:H,formatX:A,defaultIncludeZero:!1}),{valueScale:y,bandwidth:C,categoryPositions:N,innerWidth:K,innerHeight:ne}=b,r=Math.min(Q??_e,C),v=r*.5,k=(m,p)=>l?{x:m,y:p}:{x:p,y:m},L=a.map((m,p)=>{let i=N[p]+(C-r)/2,u=i+r/2;if(m.stats===null)return{key:`${p}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:N[p],height:C};let{q1:T,q3:q,median:j,lower:Ae,upper:Ee,outliers:We}=m.stats,de=y(T),he=y(q),ge=Math.min(de,he),ye=Math.abs(he-de),Xe=(0,Be.buildBarPath)({...l?{x:i,y:ge,width:r,height:Math.max(1,ye)}:{x:ge,y:i,width:Math.max(1,ye),height:r},radius:2,round:"none"}),Z=y(j),Ve=l?{x1:i,y1:Z,x2:i+r,y2:Z}:{x1:Z,y1:i,x2:Z,y2:i+r},le=[];for(let[M,oe,F]of[["lower",Ae,T],["upper",Ee,q]]){let ie=y(oe),Ie=y(F),fe=k(u,ie),pe=k(u,Ie);le.push({key:`${M}-stem`,x1:pe.x,y1:pe.y,x2:fe.x,y2:fe.y});let xe=k(u-v/2,ie),be=k(u+v/2,ie);le.push({key:`${M}-cap`,x1:xe.x,y1:xe.y,x2:be.x,y2:be.y})}return{key:`${p}`,body:Xe,median:Ve,whiskers:le,outliers:U?We.map((M,oe)=>{let F=k(u,y(M));return{key:`${oe}`,cx:F.x,cy:F.y}}):[],mean:I&&m.mean!==null?(()=>{let M=k(u,y(m.mean));return{cx:M.x,cy:M.y}})():null,top:N[p],height:C}});return{vertical:l,rendered:L,categoryPositions:N,categoryCenters:b.categoryCenters,bandwidth:C,categoryTicks:b.categoryTicks,valueTicks:b.valueTicks,valueScale:y,innerWidth:K,innerHeight:ne,margin:b.margin}},[a,d,n,x,s,o,z,w,Q,U,I,H,A]),re=(0,f.useCallback)(l=>{if(S===!1||a.length===0)return;let c=l.currentTarget.getBoundingClientRect(),b=e.vertical?l.clientX-c.left-e.margin.left:l.clientY-c.top-e.margin.top;E((0,Se.nearestIndex)(e.categoryCenters,b))},[S,a.length,e.vertical,e.margin,e.categoryCenters]),G=(0,f.useCallback)(()=>{!R||g===null||R(a[g])},[R,g,a]),X=(0,f.useCallback)(l=>(0,Te.handleChartKeyDown)(l,{count:a.length,current:g,axis:e.vertical?"x":"y",onMove:E,pick:R?G:null}),[a.length,g,e.vertical,R,G]),h=g===null?null:a[g],V=g===null||h===null||h.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[g],y:e.margin.top+e.valueScale(h.stats.q3)}:{x:e.margin.left+e.valueScale(h.stats.q3),y:e.margin.top+e.categoryCenters[g]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:s,height:o,role:"img","aria-label":ae??a.map(l=>l.label).join(", "),tabIndex:0,className:`${Re.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500`,onPointerMove:re,onPointerLeave:()=>E(null),onKeyDown:X,onBlur:()=>E(null),onClick:G,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(ve.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&($==="y"||$==="both")?e.valueTicks.map(l=>l.offset):void 0,vertical:!e.vertical&&($==="y"||$==="both")?e.valueTicks.map(l=>l.offset):void 0}),g!==null?(0,t.jsx)("rect",{x:e.vertical?e.categoryPositions[g]:0,y:e.vertical?0:e.categoryPositions[g],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,te?.map(l=>{let c=e.valueScale(l.value);return(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:e.vertical?0:c,y1:e.vertical?c:0,x2:e.vertical?e.innerWidth:c,y2:e.vertical?c:e.innerHeight,stroke:l.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:l.dashed===!1?void 0:"4 4"}),l.label?(0,t.jsx)("text",{x:e.vertical?e.innerWidth:c+4,y:e.vertical?c-4:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:l.label}):null]},`${l.value}-${l.label??""}`)}),(0,t.jsx)(Ue,{boxes:e.rendered,color:Y})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?n.hidden:x?.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?n.label:x?.label,size:_})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?x?.hidden:n.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?x?.label:n.label,size:_})})]}),h&&h.stats&&V&&S!==!1?(0,t.jsx)(ke.ChartTooltip,{x:V.x,y:V.y,containerWidth:s,children:typeof S=="function"?S(h):(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:h.label}),(0,t.jsxs)("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[[W.chartMax,h.stats.max],["Q3",h.stats.q3],[W.chartMedian,h.stats.median],["Q1",h.stats.q1],[W.chartMin,h.stats.min]].map(([l,c])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:l}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:H(c)})]},l)),(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:W.chartCount}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:h.stats.count})]})]})]})}):null]})}function je({data:s,x:o,y:d,values:a,quantiles:n,whisker:x=1.5,orientation:$="vertical",boxSize:_,showOutliers:w=!0,showMean:Q=!1,color:U,referenceLines:I,height:Y=280,width:te,size:z="md",grid:S="y",tooltip:ae=!0,tableView:H=!1,title:A,description:R,loading:D=!1,emptyState:E,error:g=!1,errorState:W,onRetry:e,actions:re,margin:G,locale:X,plotLabel:h,format:V,onBoxClick:l,className:c,...b}){let y=(0,ue.useUILabels)(),C=(0,f.useMemo)(()=>d?.format??V??(r=>(0,ee.formatAuto)(r,X)),[d?.format,V,X]),N=(0,f.useMemo)(()=>o.format??(r=>(0,ee.formatXValue)(r,X)),[o.format,X]),K=(0,f.useMemo)(()=>s.map((r,v)=>{let k=(0,B.readXValue)(r,o.key,v),L=a?(()=>{let i=r[a];return Array.isArray(i)?i.map(u=>typeof u=="number"?u:Number(u)).filter(u=>Number.isFinite(u)):null})():null,m=null,p=null;if(L!==null)m=(0,we.boxStats)(L,x),p=L.length===0?null:L.reduce((i,u)=>i+u,0)/L.length;else if(n){let i=(0,B.readNumber)(r,n.q1),u=(0,B.readNumber)(r,n.median),T=(0,B.readNumber)(r,n.q3);if(i!==null&&u!==null&&T!==null){let q=n.min?(0,B.readNumber)(r,n.min)??i:i,j=n.max?(0,B.readNumber)(r,n.max)??T:T;m={count:0,min:q,max:j,q1:i,median:u,q3:T,iqr:T-i,lower:q,upper:j,outliers:[]}}}return{index:v,x:k,label:N(k,v),stats:m,mean:p,datum:r}}),[s,o.key,a,n,x,N]),ne=K.filter(r=>r.stats!==null);return(0,t.jsx)(Ce.ChartContainer,{title:A,description:R,height:Y,width:te,size:z,loading:D,empty:ne.length===0,emptyState:E,error:g,errorState:W,onRetry:e,actions:re,tableView:H,table:H?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Le.Table,{children:[typeof A=="string"?(0,t.jsx)("caption",{className:"sr-only",children:A}):null,(0,t.jsxs)($e.TableHeader,{children:[(0,t.jsx)(P.TableHeaderCell,{children:o.label??o.key}),a?(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartCount}):null,(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMin}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:"Q1"}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMedian}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:"Q3"}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMax}),a&&w?(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartOutliers}):null]}),(0,t.jsx)(Me.TableBody,{children:K.map(r=>(0,t.jsxs)(He.TableRow,{clickable:!1,children:[(0,t.jsx)(O.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:r.label}),a?(0,t.jsx)(O.TableCell,{className:ce,children:r.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(v=>(0,t.jsx)(O.TableCell,{className:ce,children:r.stats===null?"\u2014":C(r.stats[v])},v)),a&&w?(0,t.jsx)(O.TableCell,{className:ce,children:r.stats===null||r.stats.outliers.length===0?"\u2014":r.stats.outliers.map(C).join(", ")}):null]},r.index))})]})}):void 0,className:c,...b,children:({width:r})=>(0,t.jsx)(Ye,{width:r,height:Y,data:s,boxes:K,x:o,y:d,grid:S,size:z,orientation:$,boxSize:_,showOutliers:w,showMean:Q,color:U??(0,Pe.getSeriesColor)(0),referenceLines:I,margin:G,tooltip:ae,plotLabel:h,formatValue:C,formatX:N,onBoxClick:l})})}0&&(module.exports={BoxPlot});
|
|
1
|
+
"use strict";"use client";var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ke=(s,o)=>{for(var d in o)se(s,d,{get:o[d],enumerable:!0})},qe=(s,o,d,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of De(o))!Ge.call(s,n)&&n!==d&&se(s,n,{get:()=>o[n],enumerable:!(a=ze(o,n))||a.enumerable});return s};var Oe=s=>qe(se({},"__esModule",{value:!0}),s);var Ze={};Ke(Ze,{BoxPlot:()=>je});module.exports=Oe(Ze);var f=require("react"),ue=require("../../lib/i18n.cjs"),me=require("../chart/ChartAxis.cjs"),Ce=require("../chart/ChartContainer.cjs"),ve=require("../chart/ChartGrid.cjs"),ke=require("../chart/ChartTooltip.cjs"),Pe=require("../chart/palette.cjs"),Ne=require("../chart/utils/cartesian.cjs"),B=require("../chart/utils/data.cjs"),ee=require("../chart/utils/format.cjs"),Te=require("../chart/utils/keyboard.cjs"),Be=require("../chart/utils/path.cjs"),we=require("../chart/utils/quantile.cjs"),Se=require("../chart/utils/scales.cjs"),Re=require("../chart/utils/touch.cjs"),Le=require("../table/Table.cjs"),Me=require("../table/TableBody.cjs"),O=require("../table/TableCell.cjs"),$e=require("../table/TableHeader.cjs"),P=require("../table/TableHeaderCell.cjs"),He=require("../table/TableRow.cjs"),t=require("react/jsx-runtime"),_e=40,Qe=3,J=4,ce="text-right [font-variant-numeric:tabular-nums]",Ue=(0,f.memo)(function({boxes:o,color:d}){return(0,t.jsx)("g",{children:o.map(a=>(0,t.jsxs)("g",{children:[(0,t.jsx)("g",{stroke:d,strokeWidth:1.5,strokeLinecap:"round",children:a.whiskers.map(n=>(0,t.jsx)("line",{x1:n.x1,y1:n.y1,x2:n.x2,y2:n.y2},n.key))}),a.body?(0,t.jsx)("path",{d:a.body,fill:d}):null,a.median?(0,t.jsx)("line",{x1:a.median.x1,y1:a.median.y1,x2:a.median.x2,y2:a.median.y2,strokeWidth:2,className:"stroke-white dark:stroke-gray-800"}):null,a.mean?(0,t.jsx)("path",{d:`M${a.mean.cx},${a.mean.cy-J} L${a.mean.cx+J},${a.mean.cy} L${a.mean.cx},${a.mean.cy+J} L${a.mean.cx-J},${a.mean.cy} Z`,strokeWidth:1.5,stroke:d,className:"fill-white dark:fill-gray-800"}):null,a.outliers.map(n=>(0,t.jsx)("circle",{cx:n.cx,cy:n.cy,r:Qe,fill:d,strokeWidth:1.5,className:"stroke-white dark:stroke-gray-800"},n.key))]},a.key))})});function Ye({width:s,height:o,data:d,boxes:a,x:n,y:x,grid:$,size:_,orientation:w,boxSize:Q,showOutliers:U,showMean:I,color:Y,referenceLines:te,margin:z,tooltip:S,plotLabel:ae,formatValue:H,formatX:A,onBoxClick:R}){let[D,E]=(0,f.useState)(null),g=D!==null&&D<a.length?D:null,W=(0,ue.useUILabels)(),e=(0,f.useMemo)(()=>{let l=w==="vertical",c=a.flatMap(m=>m.stats===null?[]:[m.stats.min,m.stats.max,...I&&m.mean!==null?[m.mean]:[]]),b=(0,Ne.buildCartesianGeometry)({width:s,height:o,data:d,x:n,y:x,bounds:c.length===0?null:[Math.min(...c),Math.max(...c)],margin:z,orientation:w,placement:"band",formatValue:H,formatX:A,defaultIncludeZero:!1}),{valueScale:y,bandwidth:C,categoryPositions:N,innerWidth:K,innerHeight:ne}=b,r=Math.min(Q??_e,C),v=r*.5,k=(m,p)=>l?{x:m,y:p}:{x:p,y:m},L=a.map((m,p)=>{let i=N[p]+(C-r)/2,u=i+r/2;if(m.stats===null)return{key:`${p}`,body:"",median:null,whiskers:[],outliers:[],mean:null,top:N[p],height:C};let{q1:T,q3:q,median:j,lower:Ae,upper:Ee,outliers:We}=m.stats,de=y(T),he=y(q),ge=Math.min(de,he),ye=Math.abs(he-de),Xe=(0,Be.buildBarPath)({...l?{x:i,y:ge,width:r,height:Math.max(1,ye)}:{x:ge,y:i,width:Math.max(1,ye),height:r},radius:2,round:"none"}),Z=y(j),Ve=l?{x1:i,y1:Z,x2:i+r,y2:Z}:{x1:Z,y1:i,x2:Z,y2:i+r},le=[];for(let[M,oe,F]of[["lower",Ae,T],["upper",Ee,q]]){let ie=y(oe),Ie=y(F),fe=k(u,ie),pe=k(u,Ie);le.push({key:`${M}-stem`,x1:pe.x,y1:pe.y,x2:fe.x,y2:fe.y});let xe=k(u-v/2,ie),be=k(u+v/2,ie);le.push({key:`${M}-cap`,x1:xe.x,y1:xe.y,x2:be.x,y2:be.y})}return{key:`${p}`,body:Xe,median:Ve,whiskers:le,outliers:U?We.map((M,oe)=>{let F=k(u,y(M));return{key:`${oe}`,cx:F.x,cy:F.y}}):[],mean:I&&m.mean!==null?(()=>{let M=k(u,y(m.mean));return{cx:M.x,cy:M.y}})():null,top:N[p],height:C}});return{vertical:l,rendered:L,categoryPositions:N,categoryCenters:b.categoryCenters,bandwidth:C,categoryTicks:b.categoryTicks,valueTicks:b.valueTicks,valueScale:y,innerWidth:K,innerHeight:ne,margin:b.margin}},[a,d,n,x,s,o,z,w,Q,U,I,H,A]),re=(0,f.useCallback)(l=>{if(S===!1||a.length===0)return;let c=l.currentTarget.getBoundingClientRect(),b=e.vertical?l.clientX-c.left-e.margin.left:l.clientY-c.top-e.margin.top;E((0,Se.nearestIndex)(e.categoryCenters,b))},[S,a.length,e.vertical,e.margin,e.categoryCenters]),G=(0,f.useCallback)(()=>{!R||g===null||R(a[g])},[R,g,a]),X=(0,f.useCallback)(l=>(0,Te.handleChartKeyDown)(l,{count:a.length,current:g,axis:e.vertical?"x":"y",onMove:E,pick:R?G:null}),[a.length,g,e.vertical,R,G]),h=g===null?null:a[g],V=g===null||h===null||h.stats===null?null:e.vertical?{x:e.margin.left+e.categoryCenters[g],y:e.margin.top+e.valueScale(h.stats.q3)}:{x:e.margin.left+e.valueScale(h.stats.q3),y:e.margin.top+e.categoryCenters[g]};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("svg",{width:s,height:o,role:"img","aria-label":ae??a.map(l=>l.label).join(", "),tabIndex:0,className:`${Re.CHART_TOUCH} focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500`,onPointerMove:re,onPointerLeave:()=>E(null),onKeyDown:X,onBlur:()=>E(null),onClick:G,children:[(0,t.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,t.jsx)(ve.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:e.vertical&&($==="y"||$==="both")?e.valueTicks.map(l=>l.offset):void 0,vertical:!e.vertical&&($==="y"||$==="both")?e.valueTicks.map(l=>l.offset):void 0}),g!==null?(0,t.jsx)("rect",{x:e.vertical?e.categoryPositions[g]:0,y:e.vertical?0:e.categoryPositions[g],width:e.vertical?e.bandwidth:e.innerWidth,height:e.vertical?e.innerHeight:e.bandwidth,className:"fill-gray-400 dark:fill-gray-500",opacity:.12,"aria-hidden":"true"}):null,te?.map(l=>{let c=e.valueScale(l.value);return(0,t.jsxs)("g",{children:[(0,t.jsx)("line",{x1:e.vertical?0:c,y1:e.vertical?c:0,x2:e.vertical?e.innerWidth:c,y2:e.vertical?c:e.innerHeight,stroke:l.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:l.dashed===!1?void 0:"4 4"}),l.label?(0,t.jsx)("text",{x:e.vertical?e.innerWidth:c+4,y:e.vertical?c-4:8,textAnchor:e.vertical?"end":"start",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:l.label}):null]},`${l.value}-${l.label??""}`)}),(0,t.jsx)(Ue,{boxes:e.rendered,color:Y})]}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:(e.vertical?n.hidden:x?.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"bottom",ticks:e.vertical?e.categoryTicks:e.valueTicks,length:e.innerWidth,label:e.vertical?n.label:x?.label,size:_})}),(0,t.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:(e.vertical?x?.hidden:n.hidden)?null:(0,t.jsx)(me.ChartAxis,{orientation:"left",ticks:e.vertical?e.valueTicks:e.categoryTicks,length:e.innerHeight,showLine:!1,label:e.vertical?x?.label:n.label,size:_})})]}),h&&h.stats&&V&&S!==!1?(0,t.jsx)(ke.ChartTooltip,{x:V.x,y:V.y,containerWidth:s,children:typeof S=="function"?S(h):(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsx)("div",{className:"font-medium text-gray-900 dark:text-gray-100",children:h.label}),(0,t.jsxs)("dl",{className:"grid grid-cols-[auto_auto] gap-x-3 gap-y-0.5",children:[[[W.chartMax,h.stats.max],["Q3",h.stats.q3],[W.chartMedian,h.stats.median],["Q1",h.stats.q1],[W.chartMin,h.stats.min]].map(([l,c])=>(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:l}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:H(c)})]},l)),(0,t.jsxs)("div",{className:"contents",children:[(0,t.jsx)("dt",{className:"text-gray-500 dark:text-gray-400",children:W.chartCount}),(0,t.jsx)("dd",{className:"justify-self-end font-medium text-gray-900 [font-variant-numeric:tabular-nums] dark:text-gray-100",children:h.stats.count})]})]})]})}):null]})}function je({data:s,x:o,y:d,values:a,quantiles:n,whisker:x=1.5,orientation:$="vertical",boxSize:_,showOutliers:w=!0,showMean:Q=!1,color:U,referenceLines:I,height:Y=280,width:te,size:z="md",grid:S="y",tooltip:ae=!0,tableView:H=!1,title:A,description:R,loading:D=!1,emptyState:E,error:g=!1,errorState:W,onRetry:e,actions:re,margin:G,locale:X,plotLabel:h,format:V,onBoxClick:l,className:c,...b}){let y=(0,ue.useUILabels)(),C=(0,f.useMemo)(()=>d?.format??V??(r=>(0,ee.formatAuto)(r,X)),[d?.format,V,X]),N=(0,f.useMemo)(()=>o.format??(r=>(0,ee.formatXValue)(r,X)),[o.format,X]),K=(0,f.useMemo)(()=>s.map((r,v)=>{let k=(0,B.readXValue)(r,o.key,v),L=a?(()=>{let i=r[a];return Array.isArray(i)?i.map(u=>typeof u=="number"?u:Number(u)).filter(u=>Number.isFinite(u)):null})():null,m=null,p=null;if(L!==null)m=(0,we.boxStats)(L,x),p=L.length===0?null:L.reduce((i,u)=>i+u,0)/L.length;else if(n){let i=(0,B.readNumber)(r,n.q1),u=(0,B.readNumber)(r,n.median),T=(0,B.readNumber)(r,n.q3);if(i!==null&&u!==null&&T!==null){let q=n.min?(0,B.readNumber)(r,n.min)??i:i,j=n.max?(0,B.readNumber)(r,n.max)??T:T;m={count:0,min:q,max:j,q1:i,median:u,q3:T,iqr:T-i,lower:q,upper:j,outliers:[]}}}return{index:v,x:k,label:N(k,v),stats:m,mean:p,datum:r}}),[s,o.key,a,n,x,N]),ne=K.filter(r=>r.stats!==null);return(0,t.jsx)(Ce.ChartContainer,{title:A,description:R,height:Y,width:te,size:z,loading:D,empty:ne.length===0,emptyState:E,error:g,errorState:W,onRetry:e,actions:re,tableView:H,table:H?(0,t.jsx)("div",{className:"w-full overflow-x-auto",children:(0,t.jsxs)(Le.Table,{children:[typeof A=="string"?(0,t.jsx)("caption",{className:"sr-only",children:A}):null,(0,t.jsxs)($e.TableHeader,{children:[(0,t.jsx)(P.TableHeaderCell,{children:o.label??o.key}),a?(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartCount}):null,(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMin}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:"Q1"}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMedian}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:"Q3"}),(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartMax}),a&&w?(0,t.jsx)(P.TableHeaderCell,{className:"text-right",children:y.chartOutliers}):null]}),(0,t.jsx)(Me.TableBody,{children:K.map(r=>(0,t.jsxs)(He.TableRow,{clickable:!1,children:[(0,t.jsx)(O.TableCell,{className:"font-medium text-gray-900 dark:text-gray-100",children:r.label}),a?(0,t.jsx)(O.TableCell,{className:ce,children:r.stats?.count??"\u2014"}):null,["min","q1","median","q3","max"].map(v=>(0,t.jsx)(O.TableCell,{className:ce,children:r.stats===null?"\u2014":C(r.stats[v])},v)),a&&w?(0,t.jsx)(O.TableCell,{className:ce,children:r.stats===null||r.stats.outliers.length===0?"\u2014":r.stats.outliers.map(C).join(", ")}):null]},r.index))})]})}):void 0,className:c,...b,children:({width:r})=>(0,t.jsx)(Ye,{width:r,height:Y,data:s,boxes:K,x:o,y:d,grid:S,size:z,orientation:$,boxSize:_,showOutliers:w,showMean:Q,color:U??(0,Pe.getSeriesColor)(0),referenceLines:I,margin:G,tooltip:ae,plotLabel:h,formatValue:C,formatX:N,onBoxClick:l})})}0&&(module.exports={BoxPlot});
|