neba 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2ui/adapter-catalog.json +1 -1
- package/dist/a2ui/catalog.json +2 -2
- package/dist/components/accordion/Accordion.js +1 -1
- package/dist/components/agent-steps/AgentSteps.js +1 -1
- package/dist/components/alert/Alert.js +1 -1
- package/dist/components/anchor/Anchor.js +1 -1
- package/dist/components/animate-counter/AnimateCounter.js +1 -1
- package/dist/components/animate-headline/AnimateHeadline.js +1 -1
- package/dist/components/animate-lighting/AnimateLighting.js +1 -1
- package/dist/components/animate-marquee/AnimateMarquee.js +1 -1
- package/dist/components/animate-scramble/AnimateScramble.js +1 -1
- package/dist/components/animate-typing/AnimateTyping.js +1 -1
- package/dist/components/app-logo/AppLogo.js +1 -1
- package/dist/components/approval/Approval.js +1 -1
- package/dist/components/aspect-ratio/AspectRatio.js +1 -1
- package/dist/components/avatar/Avatar.js +1 -1
- package/dist/components/badge/Badge.js +1 -1
- package/dist/components/bar-chart/BarChart.js +1 -1
- package/dist/components/blockquote/Blockquote.js +1 -1
- package/dist/components/bottom-navigation/BottomNavigation.js +1 -1
- package/dist/components/breadcrumb/Breadcrumb.js +1 -1
- package/dist/components/button/Button.js +1 -1
- package/dist/components/button-group/ButtonGroup.js +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/carousel/Carousel.js +1 -1
- package/dist/components/chat-bubble/ChatBubble.js +1 -1
- package/dist/components/checkbox/Checkbox.js +1 -1
- package/dist/components/checkbox/index.d.ts +1 -1
- package/dist/components/checkbox-group/index.d.ts +1 -1
- package/dist/components/chip/Chip.d.ts +32 -3
- package/dist/components/chip/Chip.js +1 -1
- package/dist/components/code-block/CodeBlock.js +1 -1
- package/dist/components/collapsible/Collapsible.js +1 -1
- package/dist/components/color-picker/ColorPicker.js +1 -1
- package/dist/components/combobox/Combobox.d.ts +11 -0
- package/dist/components/combobox/Combobox.js +1 -1
- package/dist/components/combobox/index.d.ts +1 -1
- package/dist/components/command-palette/CommandPalette.d.ts +21 -5
- package/dist/components/command-palette/CommandPalette.js +1 -1
- package/dist/components/command-palette/CommandPaletteSheet.d.ts +27 -0
- package/dist/components/command-palette/CommandPaletteSheet.js +1 -0
- package/dist/components/command-palette/index.d.ts +1 -1
- package/dist/components/confirm/Confirm.d.ts +7 -5
- package/dist/components/confirm/Confirm.js +1 -1
- package/dist/components/data-list/DataList.js +1 -1
- package/dist/components/data-table/DataTable.js +1 -1
- package/dist/components/data-table/RowsPerPage.d.ts +43 -0
- package/dist/components/data-table/RowsPerPage.js +1 -0
- package/dist/components/date-picker/DatePicker.js +1 -1
- package/dist/components/date-range-picker/DateRangePicker.js +1 -1
- package/dist/components/date-time-picker/DateTimePicker.js +1 -1
- package/dist/components/dialog/Dialog.js +1 -1
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/drawer/Drawer.d.ts +1 -1
- package/dist/components/drawer/Drawer.js +1 -1
- package/dist/components/empty/Empty.js +1 -1
- package/dist/components/file-picker/FilePicker.js +1 -1
- package/dist/components/floating-action-button/FloatingActionButton.js +1 -1
- package/dist/components/floating-action-button/index.d.ts +1 -0
- package/dist/components/floating-bottom-navigation/FloatingBottomNavigation.js +1 -1
- package/dist/components/footer/Footer.js +1 -1
- package/dist/components/gallery/Gallery.js +1 -1
- package/dist/components/gauge-chart/GaugeChart.js +1 -1
- package/dist/components/header/Header.js +1 -1
- package/dist/components/heatmap-chart/HeatmapChart.js +1 -1
- package/dist/components/highlight/Highlight.js +1 -1
- package/dist/components/hover-card/HoverCard.js +1 -1
- package/dist/components/how-to-steps/HowToSteps.d.ts +3 -0
- package/dist/components/how-to-steps/HowToSteps.js +1 -1
- package/dist/components/image/Image.js +1 -1
- package/dist/components/inline-citation/InlineCitation.d.ts +24 -0
- package/dist/components/inline-citation/InlineCitation.js +1 -1
- package/dist/components/list/List.js +1 -1
- package/dist/components/menu/Menu.js +1 -1
- package/dist/components/menubar/Menubar.js +1 -1
- package/dist/components/meter/Meter.js +1 -1
- package/dist/components/mockup/Mockup.js +1 -1
- package/dist/components/navigation-menu/NavigationMenu.d.ts +2 -1
- package/dist/components/navigation-menu/NavigationMenu.js +1 -1
- package/dist/components/number-field/NumberField.js +1 -1
- package/dist/components/number-field/index.d.ts +1 -1
- package/dist/components/overlay/Overlay.js +1 -1
- package/dist/components/page-layout/PageLayout.js +1 -1
- package/dist/components/pagination/Pagination.js +1 -1
- package/dist/components/panes/Panes.js +1 -1
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/pill/Pill.js +1 -1
- package/dist/components/popover/Popover.js +1 -1
- package/dist/components/progress-box/ProgressBox.js +1 -1
- package/dist/components/progress-circular/ProgressCircular.js +1 -1
- package/dist/components/progress-linear/ProgressLinear.js +1 -1
- package/dist/components/prompt-input/PromptInput.js +1 -1
- package/dist/components/provider/NebaProvider.js +1 -1
- package/dist/components/radio-group/RadioGroup.js +1 -1
- package/dist/components/radio-group/index.d.ts +1 -1
- package/dist/components/rating/Rating.js +1 -1
- package/dist/components/reasoning/Reasoning.js +1 -1
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/scroll-area/ScrollArea.js +1 -1
- package/dist/components/scroll-zone/ScrollZone.js +1 -1
- package/dist/components/segmented-button/SegmentedButton.js +1 -1
- package/dist/components/select/Select.d.ts +12 -0
- package/dist/components/select/Select.js +1 -1
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/shortcut/Shortcut.js +1 -1
- package/dist/components/sidebar/Sidebar.js +1 -1
- package/dist/components/sidebar/SidebarTrigger.js +1 -1
- package/dist/components/skeleton/Skeleton.js +1 -1
- package/dist/components/slider/Slider.js +1 -1
- package/dist/components/slider/index.d.ts +1 -1
- package/dist/components/sources/Sources.js +1 -1
- package/dist/components/sparkline/Sparkline.d.ts +7 -0
- package/dist/components/sparkline/Sparkline.js +1 -1
- package/dist/components/spoiler/Spoiler.js +1 -1
- package/dist/components/statistic/Statistic.js +1 -1
- package/dist/components/streaming-text/StreamingText.d.ts +10 -6
- package/dist/components/streaming-text/StreamingText.js +1 -1
- package/dist/components/switch/Switch.js +1 -1
- package/dist/components/switch/index.d.ts +1 -1
- package/dist/components/table/Table.js +1 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/tabs/Tabs.js +1 -1
- package/dist/components/text-field/TextField.js +1 -1
- package/dist/components/text-field/index.d.ts +1 -1
- package/dist/components/text-link/TextLink.js +1 -1
- package/dist/components/time-picker/TimePicker.js +1 -1
- package/dist/components/timeline-chart/TimelineChart.js +1 -1
- package/dist/components/toast/Toast.d.ts +38 -5
- package/dist/components/toast/Toast.js +1 -1
- package/dist/components/toast/index.d.ts +2 -2
- package/dist/components/toast/index.js +1 -1
- package/dist/components/toggle/Toggle.js +1 -1
- package/dist/components/toggle-group/ToggleGroup.js +1 -1
- package/dist/components/tool-call/ToolCall.js +1 -1
- package/dist/components/toolbar/Toolbar.js +1 -1
- package/dist/components/tooltip/Tooltip.js +1 -1
- package/dist/components/tour/Tour.js +1 -1
- package/dist/components/tour/index.d.ts +1 -1
- package/dist/components/transfer/Transfer.d.ts +7 -0
- package/dist/components/transfer/Transfer.js +1 -1
- package/dist/components/tree-select/TreeSelect.js +1 -1
- package/dist/components/tree-view/TreeView.js +1 -1
- package/dist/components/window-pane/WindowPane.js +1 -1
- package/dist/internal/animate.d.ts +34 -2
- package/dist/internal/animate.js +1 -1
- package/dist/internal/cache.d.ts +7 -1
- package/dist/internal/cache.js +1 -1
- package/dist/internal/calendar.d.ts +40 -1
- package/dist/internal/calendar.js +1 -1
- package/dist/internal/chart-frame.d.ts +86 -8
- package/dist/internal/chart-frame.js +1 -1
- package/dist/internal/chart-line.js +1 -1
- package/dist/internal/chart.d.ts +13 -0
- package/dist/internal/chart.js +1 -1
- package/dist/internal/data-table.d.ts +7 -1
- package/dist/internal/data-table.js +1 -1
- package/dist/internal/date.d.ts +10 -0
- package/dist/internal/date.js +1 -1
- package/dist/internal/idle.d.ts +10 -0
- package/dist/internal/idle.js +1 -0
- package/dist/internal/link.d.ts +4 -3
- package/dist/internal/media.js +1 -1
- package/dist/internal/observe.d.ts +4 -0
- package/dist/internal/observe.js +1 -1
- package/dist/internal/page-layout.d.ts +30 -2
- package/dist/internal/page-layout.js +1 -1
- package/dist/internal/picker.js +1 -1
- package/dist/internal/progress.d.ts +17 -0
- package/dist/internal/progress.js +1 -1
- package/dist/internal/refs.d.ts +18 -0
- package/dist/internal/refs.js +1 -0
- package/dist/internal/run.d.ts +34 -19
- package/dist/internal/run.js +1 -1
- package/dist/internal/sizer.d.ts +9 -4
- package/dist/internal/sizer.js +1 -1
- package/dist/internal/styles.d.ts +14 -0
- package/dist/internal/styles.js +1 -1
- package/dist/internal/tile.d.ts +34 -0
- package/dist/internal/tile.js +1 -0
- package/dist/internal/wheel.d.ts +24 -1
- package/dist/internal/wheel.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/tailwind.css +366 -61
- package/dist/types.d.ts +4 -2
- package/package.json +1 -1
|
@@ -15,8 +15,28 @@ import type { NebaChartAxis, NebaChartBrush, NebaChartCategory, NebaChartLegend,
|
|
|
15
15
|
* it on a server-rendered page is a box of the right height with nothing in it,
|
|
16
16
|
* which is why the height is a prop and not something measured too: a reserve
|
|
17
17
|
* that is dropped when the content arrives is the same jump twice.
|
|
18
|
+
*
|
|
19
|
+
* `enabled: false` measures nothing and watches nothing, for a chart that was
|
|
20
|
+
* handed its width as a number: a Sparkline given `width={120}` was observed
|
|
21
|
+
* all the same, and drew itself again each time its box was resized for a
|
|
22
|
+
* width it never read.
|
|
23
|
+
*
|
|
24
|
+
* `initial` is a chart's `initialWidth`: the width it is drawn at on the
|
|
25
|
+
* server and while it hydrates, so the server's HTML holds the drawing rather
|
|
26
|
+
* than an empty box. It is a guess the caller makes, and the measurement
|
|
27
|
+
* replaces it.
|
|
18
28
|
*/
|
|
19
|
-
declare function useMeasuredWidth(ref: React.RefObject<HTMLElement | null
|
|
29
|
+
declare function useMeasuredWidth(ref: React.RefObject<HTMLElement | null>, { enabled, initial }?: {
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
initial?: number;
|
|
32
|
+
}): number;
|
|
33
|
+
/**
|
|
34
|
+
* The `initialWidth` a chart can draw at before it is measured: a positive
|
|
35
|
+
* number, and only for a chart whose height is known without measuring too.
|
|
36
|
+
* A height given as a CSS length is read off the box as well, so on the server
|
|
37
|
+
* there is no height to draw into and the guess would be a drawing with none.
|
|
38
|
+
*/
|
|
39
|
+
declare function initialWidthFor(initialWidth: number | undefined, height: number | string | undefined): number | undefined;
|
|
20
40
|
/**
|
|
21
41
|
* The host's height, for a chart whose `height` is a CSS length rather than a
|
|
22
42
|
* number. A drawing is laid out in pixels, so `height="16rem"` has to be read
|
|
@@ -74,6 +94,21 @@ declare function chartHeight(height: number | string | undefined, size: NebaSize
|
|
|
74
94
|
* each showed both answers at once.
|
|
75
95
|
*/
|
|
76
96
|
export declare const markTransitionClasses = "[transition:opacity_var(--neba-duration)_var(--neba-ease),r_var(--neba-duration)_var(--neba-ease),scale_var(--neba-duration)_var(--neba-ease)]";
|
|
97
|
+
/**
|
|
98
|
+
* The same transition, and the box a mark grows about, given to every `<path>`
|
|
99
|
+
* inside the element that carries it — for a chart with thousands of marks,
|
|
100
|
+
* where saying it on each one was most of the markup.
|
|
101
|
+
*
|
|
102
|
+
* Every scatter mark carried `markTransitionClasses`, a `style` with three
|
|
103
|
+
* properties and its stroke: about 390 bytes a mark, 390 kB of server HTML for
|
|
104
|
+
* a thousand points, and a style resolved per element in the browser. Said once
|
|
105
|
+
* on the group, a mark is its `d` and whatever is its own.
|
|
106
|
+
*
|
|
107
|
+
* The origin is `--n-origin` against the mark's own bounding box, which is the
|
|
108
|
+
* same fraction for every mark of one shape — see `markOrigin` — so it is set
|
|
109
|
+
* per series rather than per mark; the middle of the box when unset.
|
|
110
|
+
*/
|
|
111
|
+
export declare const markGroupClasses: string;
|
|
77
112
|
export interface ChartBaseProps extends Omit<BoxProps, 'children' | 'title'> {
|
|
78
113
|
/**
|
|
79
114
|
* How tall the drawing is. A number is pixels; a string is any CSS length.
|
|
@@ -83,6 +118,21 @@ export interface ChartBaseProps extends Omit<BoxProps, 'children' | 'title'> {
|
|
|
83
118
|
* the chart is a card the chart fits in.
|
|
84
119
|
*/
|
|
85
120
|
height?: number | string;
|
|
121
|
+
/**
|
|
122
|
+
* The width, in pixels, to draw at before the chart has measured its box:
|
|
123
|
+
* on the server and while the page hydrates.
|
|
124
|
+
*
|
|
125
|
+
* A chart is laid out in pixels and a server has no box to measure, so a
|
|
126
|
+
* server-rendered chart is an empty box of the right height until the page
|
|
127
|
+
* runs — and the drawing is not in the HTML a crawler reads or the first
|
|
128
|
+
* paint shows. Given this, the server draws it at that width, and the
|
|
129
|
+
* measured width replaces it once the page has hydrated. Pass the width the
|
|
130
|
+
* chart is most often shown at; the closer it is, the less the drawing
|
|
131
|
+
* moves when it is replaced.
|
|
132
|
+
*
|
|
133
|
+
* Ignored when `height` is a CSS length, which has to be measured too.
|
|
134
|
+
*/
|
|
135
|
+
initialWidth?: number;
|
|
86
136
|
/**
|
|
87
137
|
* How the numbers are written, everywhere they appear — the axis, the
|
|
88
138
|
* tooltip, the labels on the marks. `Intl.NumberFormat` options, the same
|
|
@@ -227,6 +277,11 @@ interface LegendProps {
|
|
|
227
277
|
visibility: Visibility;
|
|
228
278
|
size: NebaSize;
|
|
229
279
|
values?: readonly (string | undefined)[];
|
|
280
|
+
/**
|
|
281
|
+
* Per series, the widest numbers `values` can hold. Given, every row keeps
|
|
282
|
+
* room for its number whether or not one is showing — see `legendReserve`.
|
|
283
|
+
*/
|
|
284
|
+
reserve?: readonly (readonly string[])[];
|
|
230
285
|
swatch?: (index: number, color: string) => React.ReactNode;
|
|
231
286
|
}
|
|
232
287
|
/**
|
|
@@ -260,7 +315,7 @@ interface LegendProps {
|
|
|
260
315
|
* out of it. It listens only while something is being read.
|
|
261
316
|
*/
|
|
262
317
|
declare function useReleaseOutside(ref: React.RefObject<HTMLElement | null>, active: boolean, release: () => void): void;
|
|
263
|
-
declare function ChartLegendBar({ series, colors, options, visibility, size, values, swatch }: LegendProps): React.JSX.Element;
|
|
318
|
+
declare function ChartLegendBar({ series, colors, options, visibility, size, values, reserve, swatch }: LegendProps): React.JSX.Element;
|
|
264
319
|
interface ScaleLegendProps {
|
|
265
320
|
/** The steps, palest first, as the `var()`s that resolve them. */
|
|
266
321
|
steps: readonly string[];
|
|
@@ -406,6 +461,10 @@ export declare const chartTableClasses = "absolute size-px overflow-hidden white
|
|
|
406
461
|
* take a screen reader's place in it away — and only rows that are new to it
|
|
407
462
|
* are deferred. A change in the row count, or the table unmounting, cancels the
|
|
408
463
|
* slice that was waiting.
|
|
464
|
+
*
|
|
465
|
+
* `run` is how many rows one slice adds, which is also how many rows a table
|
|
466
|
+
* draws in each of its `tableRuns`: a slice then adds one run, and the runs
|
|
467
|
+
* already written are left alone.
|
|
409
468
|
*/
|
|
410
469
|
declare function useDeferredRows({ rows, points, columns }: {
|
|
411
470
|
/** How many rows the body has. */
|
|
@@ -414,7 +473,18 @@ declare function useDeferredRows({ rows, points, columns }: {
|
|
|
414
473
|
points: number;
|
|
415
474
|
/** How many cells each row has, which sizes a slice. */
|
|
416
475
|
columns: number;
|
|
417
|
-
}):
|
|
476
|
+
}): {
|
|
477
|
+
shown: number;
|
|
478
|
+
run: number;
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* A table's body rows, as runs of `run` rows each.
|
|
482
|
+
*
|
|
483
|
+
* The runs start at fixed multiples of `run` rather than wherever the last
|
|
484
|
+
* slice stopped, so a run keeps its key and its rows from one slice to the
|
|
485
|
+
* next. The DOM is exactly the flat list of rows it replaces.
|
|
486
|
+
*/
|
|
487
|
+
declare function tableRuns(shown: number, run: number, draw: (from: number, to: number) => React.ReactNode): React.ReactNode[];
|
|
418
488
|
interface DataTableProps {
|
|
419
489
|
id: string;
|
|
420
490
|
caption?: string;
|
|
@@ -575,6 +645,18 @@ export interface CartesianLayout {
|
|
|
575
645
|
/** And a given series' own, which differs once there are two scales. */
|
|
576
646
|
zeroPxOf: (series?: number) => number;
|
|
577
647
|
categories: readonly NebaChartCategory[];
|
|
648
|
+
size: NebaSize;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* The layout, plus how a number is written and everything the pointer decides.
|
|
652
|
+
*
|
|
653
|
+
* The two formatters are not part of the layout, because the marks are built
|
|
654
|
+
* from the layout and nothing a mark is placed by depends on them. A chart
|
|
655
|
+
* hydrated with no `locale` changes its formatter straight after the
|
|
656
|
+
* hydration, to write in the reader's language, and with the formatters in
|
|
657
|
+
* the layout that one render laid out and drew every mark on the plot again.
|
|
658
|
+
*/
|
|
659
|
+
export interface CartesianContext extends CartesianLayout {
|
|
578
660
|
format: (value: number) => string;
|
|
579
661
|
/**
|
|
580
662
|
* How a given series' numbers are written: through `secondaryAxis.tickFormat`
|
|
@@ -583,10 +665,6 @@ export interface CartesianLayout {
|
|
|
583
665
|
* printed in the first axis' currency.
|
|
584
666
|
*/
|
|
585
667
|
formatFor: (series: number) => (value: number) => string;
|
|
586
|
-
size: NebaSize;
|
|
587
|
-
}
|
|
588
|
-
/** The layout, plus everything the pointer decides. */
|
|
589
|
-
export interface CartesianContext extends CartesianLayout {
|
|
590
668
|
/** The series the legend is being hovered over, if any. */
|
|
591
669
|
hovered: number | null;
|
|
592
670
|
/** The category under the pointer, if any. */
|
|
@@ -706,5 +784,5 @@ interface CartesianProps extends CartesianChartProps {
|
|
|
706
784
|
* component never has to know which way round the axes are.
|
|
707
785
|
*/
|
|
708
786
|
export declare function CartesianChart(rawProps: CartesianProps): React.JSX.Element;
|
|
709
|
-
export { ChartDataTable, ChartExport, ChartLegendBar, ChartScaleLegend, ChartStatus, ChartSummary, ChartSurface, ChartTooltipPanel, summarise, chartHeight, useDeferredRows, useMeasuredHeight, useMeasuredWidth, useReleaseOutside, useVisibility };
|
|
787
|
+
export { ChartDataTable, ChartExport, ChartLegendBar, ChartScaleLegend, ChartStatus, ChartSummary, ChartSurface, ChartTooltipPanel, summarise, chartHeight, initialWidthFor, tableRuns, useDeferredRows, useMeasuredHeight, useMeasuredWidth, useReleaseOutside, useVisibility };
|
|
710
788
|
export type { Visibility };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,Fragment as t,jsxs as n}from"react/jsx-runtime";import{useStyleDefaults as a}from"./defaults.js";import*as l from"react";import{useLayoutEffectOnClient as r}from"./layout-effect.js";import{Box as i}from"../components/box/Box.js";import{alignedScale as o,bandScale as s,categoryAt as c,categoryCount as u,categoryExtent as d,chartFontSizes as h,compactNumber as m,extentOf as f,fitsLast as x,formatCategory as g,markerRadii as p,plotHeights as v,resolveColor as b,seriesColor as y,showsTick as k,textWidth as M,tickStride as w,toFullShares as C,toValues as S,truncate as N,turnedAxis as z,valueScale as P,warnPaletteOverflow as A}from"./chart.js";import{numberFormatter as T}from"./format.js";import{useHydrated as B,useIntlLocale as j}from"./media.js";import{observeResize as $}from"./observe.js";import{chartMessages as I,emptyMessages as E,fillMessage as R,useMessages as W}from"./i18n.js";import{cx as _,hasContent as F,metaTextClasses as L,srOnlyClasses as D,transitionClasses as H}from"./styles.js";const O=[];function V(e){const[t,n]=l.useState(0);return r(()=>{const t=e.current;if(!t)return;const a=()=>n(t.clientWidth);return a(),$(t,a)},[e]),t}function Z(e,t){const[n,a]=l.useState(0);return r(()=>{const n=e.current;if(!t||!n)return;const l=()=>a(n.clientHeight);return l(),$(n,l)},[e,t]),n}function q(e,t,n){return"number"==typeof e?e:void 0===e?v[t]:n}export const markTransitionClasses="[transition:opacity_var(--neba-duration)_var(--neba-ease),r_var(--neba-duration)_var(--neba-ease),scale_var(--neba-duration)_var(--neba-ease)]";function X(e){const[t,n]=l.useState(()=>new Map),[a,r]=l.useState(null),i=l.useMemo(()=>function(e){const t=new Map;return e.map((e,n)=>{if(void 0===e.name)return`index:${n}`;const a=t.get(e.name)??0;return t.set(e.name,a+1),`name:${a}:${e.name}`})}(e),[e]),o=l.useMemo(()=>e.map((e,n)=>t.get(i[n])??!e.hidden),[e,i,t]),s=l.useRef({series:e,keys:i});l.useEffect(()=>{s.current={series:e,keys:i}});return{visible:o,hovered:a,toggle:l.useCallback(e=>{const{series:t,keys:a}=s.current,l=a[e];void 0!==l&&n(n=>{const a=new Map(n);return a.set(l,!(n.get(l)??!t[e]?.hidden)),a})},[]),setHovered:r}}const Y={top:"flex-col-reverse",bottom:"flex-col",left:"flex-row-reverse",right:"flex-row"},J={start:"justify-start",center:"justify-center",end:"justify-end"};function K(e,t,n){const a=l.useRef(n);l.useEffect(()=>{a.current=n}),l.useEffect(()=>{if(!t)return;const n=t=>{const n=e.current;n&&t.target instanceof Node&&!n.contains(t.target)&&a.current()};return document.addEventListener("pointerdown",n,!0),()=>document.removeEventListener("pointerdown",n,!0)},[e,t])}function ChartLegendBar({series:a,colors:l,options:r,visibility:i,size:o,values:s,swatch:c}){const u=!1!==r.interactive,d="left"===r.side||"right"===r.side;return e("ul",{className:_("flex list-none flex-wrap items-center gap-x-3 gap-y-1 p-0",d?"min-w-0 flex-col items-start":"",J[r.align??"center"],L[o]),children:a.map((a,r)=>{const o=i.visible[r],d=null!==i.hovered&&i.hovered!==r,h=a.name??`${r+1}`,m=l[r],f=n(t,{children:[e("span",c?{"aria-hidden":"true",className:"flex size-2.5 shrink-0 items-center justify-center",children:c(r,m)}:{"aria-hidden":"true",className:`size-2.5 shrink-0 rounded-[0.1875rem] ${H}`,style:{backgroundColor:m}}),e("span",{className:"min-w-0 truncate",children:h}),s?.[r]?e("span",{className:"shrink-0 tabular-nums text-(--neba-muted-fg)",children:s[r]}):null]});return e("li",{className:"min-w-0",children:u?e("button",{type:"button","aria-pressed":o,onClick:()=>i.toggle(r),onPointerEnter:()=>i.setHovered(r),onPointerLeave:()=>i.setHovered(null),onFocus:()=>i.setHovered(r),onBlur:()=>i.setHovered(null),className:_("flex min-w-0 cursor-pointer items-center gap-1.5 rounded-(--neba-radius-xs)","px-1 py-0.5 text-(--neba-fg)","[transition-property:background-color,color,opacity]","[transition-duration:var(--neba-duration)]","[transition-timing-function:var(--neba-ease)]","hover:bg-(--n-soft)","focus-visible:[outline:2px_solid_var(--n-ring)] focus-visible:outline-offset-1",o?d?"opacity-55":"":"opacity-40"),children:f}):e("span",{className:_("flex min-w-0 items-center gap-1.5 px-1 py-0.5 text-(--neba-fg)",o?"":"opacity-40"),children:f})},a.name??r)})})}function ChartScaleLegend({steps:a,from:l,to:r,middle:i,align:o,vertical:s,size:c}){return e("div",{className:_("flex",s?"":J[o]),children:n("div",{className:_("grid grid-cols-[auto_auto_auto] items-center gap-x-2",L[c]),children:[e("span",{className:"shrink-0 tabular-nums text-(--neba-muted-fg)",children:l}),e("span",{"aria-hidden":"true",className:_("flex h-2.5 overflow-hidden rounded-[0.1875rem]",s?"w-20":"w-24"),children:a.map(t=>e("span",{className:"h-full flex-1",style:{backgroundColor:t}},t))}),e("span",{className:"shrink-0 tabular-nums text-(--neba-muted-fg)",children:r}),i?n(t,{children:[e("span",{}),e("span",{className:"text-center tabular-nums text-(--neba-muted-fg)",children:i}),e("span",{})]}):null]})})}function ChartTooltipPanel({heading:t,items:a,x:l,y:r,flip:i,size:o}){return n("div",{"data-neba-tooltip":"",className:_("pointer-events-none absolute z-10 max-w-56 min-w-24","rounded-(--neba-radius-sm) border p-2","[background-image:var(--neba-grain),var(--neba-sheen)]","[background-blend-mode:overlay,normal] [backdrop-filter:var(--neba-blur)]","bg-(--neba-panel-press) [border-color:var(--n-line)]","[box-shadow:var(--neba-shadow-2),var(--neba-plate-glass)]",L[o]),style:i?{right:`calc(100% - ${l}px + 10px)`,top:r}:{left:l+10,top:r},children:[e("div",{className:"mb-1 font-medium text-(--neba-fg)",children:t}),e("ul",{className:"flex list-none flex-col gap-0.5 p-0",children:a.map(t=>n("li",{className:"flex items-center gap-1.5",children:[e("span",{"aria-hidden":"true",className:"size-2 shrink-0 rounded-[0.125rem]",style:{backgroundColor:t.color}}),t.name?e("span",{className:"min-w-0 flex-1 truncate text-(--neba-muted-fg)",children:t.name}):null,e("span",{className:"ms-auto shrink-0 font-medium tabular-nums text-(--neba-fg)",children:t.label??t.formatted})]},t.seriesIndex))})]})}function ChartSummary({id:e,template:t,count:a,min:l,max:r,second:i,locale:o}){const s=T(o,{});return n("span",{id:e,hidden:!0,children:[R(t,{count:s.format(a),min:l,max:r}),i&&i.count>0?` ${R(i.template,{count:s.format(i.count),min:i.min,max:i.max})}`:null]})}function U(e,t){let n=0,a=1/0,l=-1/0;for(const t of e)for(const e of t)null===e.value||Number.isNaN(e.value)||(n+=1,a=Math.min(a,e.value),l=Math.max(l,e.value));return 0===n?{count:n,min:"",max:""}:{count:n,min:t(a),max:t(l)}}function ChartStatus({heading:a,items:r}){return e("span",{role:"status","aria-live":"polite",className:D,children:0===r.length?null:n(t,{children:[F(a)?n(t,{children:[a,", "]}):null,r.map((e,t)=>n(l.Fragment,{children:[t>0?", ":null,e.name?`${e.name}: `:null,e.label??e.formatted]},e.seriesIndex))]})})}export const deferredTablePoints=500;export const chartTableClasses=`${D} table-fixed [contain:content]`;function G({rows:e,points:t,columns:n}){const a=t>500,[r,i]=l.useState(()=>a?0:e),o=a?Math.min(r,e):e;o!==r&&i(o);const s=Math.max(1,Math.floor(1e3/Math.max(1,n)));return l.useEffect(()=>{if(!(r>=e))return function(e){if("function"==typeof requestIdleCallback&&"function"==typeof cancelIdleCallback){const t=requestIdleCallback(e,{timeout:500});return()=>cancelIdleCallback(t)}const t=setTimeout(e,16);return()=>clearTimeout(t)}(()=>i(Math.min(e,r+s)))},[r,e,s]),o}const Q=/*@__PURE__*/l.memo(function ChartDataTable({id:t,caption:a,corner:l,categories:r,series:i,values:o,format:s,formatFor:c,locale:u}){const d=G({rows:r.length,points:o.reduce((e,t)=>e+t.length,0),columns:i.length+1});return n("table",{id:t,className:chartTableClasses,"aria-busy":d<r.length||void 0,children:[a?e("caption",{children:a}):null,e("thead",{children:n("tr",{children:[e("th",{scope:"col",children:l??""}),i.map((t,n)=>e("th",{scope:"col",children:t.name??n+1},t.name??n))]})}),e("tbody",{children:r.slice(0,d).map((t,a)=>n("tr",{children:[e("th",{scope:"row",children:g(t,u)}),i.map((t,n)=>{const l=o[n]?.[a];return e("td",void 0!==l?.label?{children:l.label}:{children:null==l?.value?"":(c?.(n)??s)(l.value)},t.name??n)})]},a))})]})}),ee=l.lazy(()=>import("./chart-brush.js").then(e=>({default:e.ChartBrush})));function ChartExport({rows:t,fileName:n,onExport:a,label:l}){return e("button",{type:"button","aria-label":l,title:l,onClick:async()=>{const{toCsv:e,downloadText:l}=await(import("./csv.js")),r=e(t());a?a(r):l(r,n,"text/csv;charset=utf-8")},className:_("absolute end-0 top-0 z-10 inline-flex size-6 cursor-pointer items-center justify-center","rounded-(--neba-radius-xs) text-(--neba-muted-fg)","hover:bg-(--n-soft) hover:text-(--neba-fg)","focus-visible:[outline:2px_solid_var(--n-ring)] focus-visible:outline-offset-1",H),children:e("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:"size-3.5",children:e("path",{d:"M12 3v12m0 0 4-4m-4 4-4-4M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})})})}function ChartSurface({legend:t,legendSide:a,children:l,table:r,className:o,...s}){return n(i,{...s,className:_("relative flex gap-3",Y[a],o??void 0),children:[e("div",{className:"relative min-w-0 flex-1",children:l}),t,r]})}function ChartReferences({references:t,plot:a,horizontal:l,valuePx:r,categoryPx:i,categoryScale:o,categoryValuePx:s,categoryBounds:c,categoryOffset:u,fontSize:d}){const[h,m]=c;return e("g",{children:t.map((t,c)=>{const f="value"===(t.axis??"value"),x=e=>f?e:Math.min(m,Math.max(h,e));if(!f&&Math.max(t.value,t.to??t.value)<h)return null;if(!f&&Math.min(t.value,t.to??t.value)>m)return null;const g=e=>f?r(e):o?s(e):(l?a.top:a.left)+i(e-u),p=f?!l:l,v=g(x(t.value)),y=void 0===t.to?null:g(x(t.to)),k=(void 0===t.to?[t.value]:[t.value,t.to]).filter(e=>f||e>=h&&e<=m).map(g),M=null===y?v:Math.min(v,y),w=null===y?v:Math.max(v,y),C=t.color?b(t.color):"var(--neba-muted-fg)",S=t.solid?void 0:"4 4",N=t.label?e("text",{x:p?a.left+a.width-4:M+4,y:p?M-5:a.top+d,textAnchor:p?"end":"start",fontSize:d,fontWeight:500,fill:C,children:t.label}):null;return n("g",{children:[null===y?null:e("rect",{x:p?a.left:M,y:p?M:a.top,width:p?a.width:Math.max(0,w-M),height:p?Math.max(0,w-M):a.height,fill:`color-mix(in oklab, ${C} 12%, transparent)`}),k.map((t,n)=>e("line",{x1:p?a.left:t,x2:p?a.left+a.width:t,y1:p?t:a.top,y2:p?t:a.top+a.height,stroke:C,strokeWidth:1,strokeDasharray:S},n)),N]},c)})})}export function CartesianChart(r){const{series:i,categories:x,xAxis:v,yAxis:b,secondaryAxis:k,brush:w,references:$,horizontal:R=!1,stacked:F=!1,stackedFull:H=!1,includeZero:Y=!0,bandRatio:J=1,inset:G=!1,headroom:ne=0,markInset:ae=0,xScale:le="band",marks:re,markRadius:ie=24,table:oe,exportRows:se,summary:ce,swatch:ue,scale:de,markTooltip:he,height:me,format:fe,locale:xe,label:ge,legend:pe,tooltip:ve,empty:be,exportable:ye=!1,exportFileName:ke="chart.csv",onExport:Me,size:we="md",variant:Ce="text",padded:Se=!1,className:Ne,children:ze,...Pe}=a(r,["size","variant","locale"]),Ae=l.useRef(null),Te=V(Ae),Be=W(E,xe),je=W(I,xe),$e=j(xe),Ie=B(),Ee=l.useId(),Re=l.useId(),We=X(i);l.useEffect(()=>{A(i.length)},[i.length]);const _e=u(i),Fe=!0===w?{}:!1===w||void 0===w?null:w,[Le,De]=l.useState(null),He=Fe?Fe.range??Le??Fe.defaultRange??[0,Math.max(0,_e-1)]:[0,Math.max(0,_e-1)],Oe=Math.min(Math.max(0,Math.round(He[0])),Math.max(0,_e-1)),Ve=Math.min(Math.max(Oe,Math.round(He[1])),Math.max(0,_e-1)),Ze=null!==Fe&&(Oe>0||Ve<_e-1),qe=l.useMemo(()=>Ze?i.map(e=>({...e,data:e.data.slice(Oe,Ve+1)})):i,[i,Ze,Oe,Ve]),Xe=l.useMemo(()=>Ze&&x?x.slice(Oe,Ve+1):x,[x,Ze,Oe,Ve]),[Ye,Je]=l.useState(null),[Ke,Ue]=l.useState(null),[Ge,Qe]=l.useState(null),et=fe?JSON.stringify(fe):"",tt=l.useCallback(e=>fe?T($e,fe).format(e):m(e,$e),[et,$e]),nt=l.useMemo(()=>S(qe),[qe]),at=We.visible,lt=l.useMemo(()=>H?C(nt,at,tt):nt,[nt,H,at,tt]),rt=l.useMemo(()=>qe.map((e,t)=>y(e,t)),[qe]),it=u(qe),ot=l.useMemo(()=>Array.from({length:it},(e,t)=>c(t,Xe,lt)),[it,Xe,lt]),st=Ze||H,ct=l.useMemo(()=>st?S(i):null,[st,i]),ut=ct??lt,dt=l.useMemo(()=>Ze&&ct?Array.from({length:_e},(e,t)=>c(t,x,ct)):null,[Ze,_e,x,ct])??ot,ht=Math.max(0,We.visible.indexOf(!0)),mt=null!==Fe,ft=l.useMemo(()=>mt?(ut[ht]??[]).map(e=>e.value):[],[mt,ut,ht]),xt=Boolean(k)&&!F&&!H,gt=i.map(e=>"secondary"===e.axis?"1":"0").join(""),pt=l.useCallback(e=>xt&&"1"===gt[e],[xt,gt]),vt=l.useMemo(()=>{const e=f(lt.filter((e,t)=>at[t]&&!pt(t)),F),t=($??[]).filter(e=>"value"===(e.axis??"value"));if(0===t.length)return e;const n=t.flatMap(e=>void 0===e.to?[e.value]:[e.value,e.to]);return{min:Math.min(e?.min??1/0,...n),max:Math.max(e?.max??-1/0,...n)}},[lt,at,pt,F,$]),bt=l.useMemo(()=>xt?f(lt.filter((e,t)=>at[t]&&pt(t)),!1):null,[xt,lt,at,pt]),yt=k?.tickFormat,kt=l.useMemo(()=>ce??U(lt.filter((e,t)=>at[t]&&!pt(t)),tt),[ce,lt,at,pt,tt]),Mt=l.useMemo(()=>void 0===ce&&xt?U(lt.filter((e,t)=>at[t]&&pt(t)),yt?e=>String(yt(e,0)):tt):null,[ce,xt,lt,at,pt,yt,tt]),wt=Z(Ae,"string"==typeof me),Ct=q(me,we,wt),St=h[we],Nt=b,zt=v,Pt=Nt?.min,At=Nt?.max,Tt=Nt?.tickCount,Bt=l.useMemo(()=>de??P(vt,{min:Pt,max:At,tickCount:Tt,includeZero:Y}),[de,vt,Pt,At,Tt,Y]),jt=k?.min,$t=k?.max,It=k?.tickCount,Et=Bt.ticks.length-1,Rt=l.useMemo(()=>null===bt?null:void 0===It?o(bt,Et,{min:jt,max:$t,includeZero:Y}):P(bt,{min:jt,max:$t,tickCount:It,includeZero:Y}),[bt,Et,jt,$t,It,Y]),Wt=l.useMemo(()=>"value"===le?d(lt.filter((e,t)=>at[t]),Xe):null,[le,lt,at,Xe]),_t=zt?.min,Ft=zt?.max,Lt=zt?.tickCount,Dt=l.useMemo(()=>"value"===le?P(Wt,{min:_t,max:Ft,tickCount:Lt,includeZero:!1}):null,[le,Wt,_t,Ft,Lt]),Ht=Nt?.tickFormat,Ot=l.useMemo(()=>Bt.ticks.map((e,t)=>Ht?String(Ht(e,t)):tt(e)),[Bt,Ht,tt]),Vt=zt?.tickFormat,Zt=l.useMemo(()=>Dt?Dt.ticks.map((e,t)=>Vt?String(Vt(e,t)):m(e,$e)):ot.map((e,t)=>Vt?String(Vt(e,t)):g(e,$e)),[Dt,ot,Vt,$e]),qt=Ot.reduce((e,t)=>Math.max(e,M(t,St)),0),Xt=l.useMemo(()=>(Rt?.ticks??[]).map((e,t)=>yt?String(yt(e,t)):tt(e)),[Rt,yt,tt]),Yt=Xt.reduce((e,t)=>Math.max(e,M(t,St)),0),Jt=St+6,Kt=Rt&&!k?.hidden?k?.thickness??(R?St+12:Yt+10):0,Ut=R?zt:Nt,Gt=Boolean(Ut?.label)&&!Ut?.hidden,Qt=Boolean(Rt&&k?.label&&!k.hidden),en=R||zt?.hidden?0:zt?.tickAngle,tn=l.useMemo(()=>z(en,St),[en,St]),nn=0!==tn.angle,an=Nt?.hidden?0:qt+10,ln=(Te-(R?0:an)-16)/Math.max(1,it),rn=Math.min(140,.4*Ct),on=!Dt&&(R||nn||ln-6>=2.4*St),sn=R?150:nn?tn.cut(rn):ln-6,cn=l.useMemo(()=>on?Zt.map(e=>N(e,sn,St)):Zt,[Zt,on,sn,St]),un=l.useMemo(()=>cn.reduce((e,t)=>Math.max(e,M(t,St)),0),[cn,St]),dn=R?zt?.hidden?0:un+10:an,hn=tn.depth(un),mn=Fe?(Fe.height??32)+10:0,fn=R?Nt?.hidden?0:St+12+(Nt?.label?Jt:0):zt?.hidden?0:hn+12+(zt?.label?Jt:0),xn=(R?zt:Nt)?.thickness??dn,gn=((R?Nt:zt)?.thickness??fn)+mn,pn=(R||Dt?12:nn?tn.angle>0?tn.overhang(un)+8:8:Math.max(8,cn.length?tn.overhang(un):8))+ae+(R?0:Kt),vn=p[we]+4+ne+ae+(Gt||Qt?Jt+2:0)+(ye?20:0)+(R?Kt:0),bn=Ct,yn=xn+ae,kn=Math.max(0,Te-xn-ae-pn),Mn=Math.max(0,bn-vn-gn-ae),wn=l.useMemo(()=>({left:yn,top:vn,width:kn,height:Mn}),[yn,vn,kn,Mn]),Cn=R?wn.height:wn.width,Sn=G?Math.max(1,it-1):it,Nn=l.useMemo(()=>s(Sn,Cn,J),[Sn,Cn,J]),zn=l.useCallback(e=>G?it<=1?Cn/2:Cn*e/(it-1):Nn.centre(e),[G,it,Cn,Nn]),Pn=l.useCallback((e,t)=>{return n=void 0!==t&&pt(t)&&Rt?Rt:Bt,R?wn.left+n.fraction(e)*wn.width:wn.top+(1-n.fraction(e))*wn.height;var n},[R,wn.left,wn.top,wn.width,wn.height,Bt,Rt,pt]),An=l.useCallback((e,t,n)=>R?{x:Pn(t,n),y:wn.top+zn(e)}:{x:wn.left+zn(e),y:Pn(t,n)},[R,Pn,zn,wn.left,wn.top]),Tn=l.useCallback(e=>R?wn.top+(1-(Dt?.fraction(e)??0))*wn.height:wn.left+(Dt?.fraction(e)??0)*wn.width,[R,wn.left,wn.top,wn.width,wn.height,Dt]),Bn=l.useCallback(e=>{const t=void 0!==e&&pt(e)&&Rt?Rt:Bt;return Pn(Math.min(Math.max(0,t.min),t.max),e)},[Pn,Bt,Rt,pt]),jn=Bn(),$n=k?.tickFormat,In=l.useCallback(e=>pt(e)&&$n?e=>String($n(e,0)):tt,[pt,$n,tt]),En=l.useMemo(()=>({plot:wn,values:lt,visible:at,colors:rt,scale:Bt,secondScale:Rt,onSecond:pt,band:Nn,horizontal:R,valuePx:Pn,categoryPx:zn,point:An,categoryScale:Dt,categoryValuePx:Tn,zeroPx:jn,zeroPxOf:Bn,categories:ot,format:tt,formatFor:In,size:we}),[wn,lt,at,rt,Bt,Rt,pt,Nn,R,Pn,zn,An,Dt,Tn,jn,Bn,ot,tt,In,we]),Rn=l.useMemo(()=>re?re(En):O,[re,En]),Wn=($??[]).filter(e=>Boolean(e.label)),_n=e=>{const t=t=>"value"===(e.axis??"value")?tt(t):g(Dt?t:dt[t]??t,$e);return void 0===e.to?t(e.value):`${t(e.value)}–${t(e.to)}`},Fn=!1===ve?{mode:"none"}:!0===ve||void 0===ve?{}:ve,Ln=Fn.mode??(re?"item":"index"),Dn=null===Ke?null:Rn[Ke]??null,Hn=re?Dn?Dn.index:null:Ye,On=re?Rn.length:it,Vn=()=>{Je(null),Ue(null),Qe(null)};K(Ae,null!==Hn,Vn);const Zn=e=>{if("none"!==Ln){if(re){const t=((e,t)=>{const n=Ae.current;if(!n||0===Rn.length)return null;const a=n.getBoundingClientRect(),l=e-a.left,r=t-a.top;let i=null,o=1/0,s=1/0;return Rn.forEach((e,t)=>{const n=e.x-l,a=e.y-r,c=Math.sqrt(n*n+a*a);let u;if(void 0===e.rx)u=Math.max(0,c-e.r);else{const t=Math.max(0,Math.abs(n)-e.rx),l=Math.max(0,Math.abs(a)-(e.ry??e.rx));u=Math.sqrt(t*t+l*l)}u<=ie&&(u<o||u===o&&c<s)&&(o=u,s=c,i=t)}),i})(e.clientX,e.clientY);t!==Ke&&Ue(t)}else{const t=((e,t)=>{const n=Ae.current;if(!n||0===it)return null;const a=n.getBoundingClientRect(),l=R?t-a.top-wn.top:e-a.left-wn.left;if(l<-Nn.step||l>Cn+Nn.step)return null;const r=G?it<=1?0:Math.round(l/Cn*(it-1)):Math.floor(l/Nn.step);return Math.min(it-1,Math.max(0,r))})(e.clientX,e.clientY);t!==Ye&&Je(t)}"item"!==Ln||re||Qe(((e,t)=>{const n=Ae.current;if(!n)return null;const a=n.getBoundingClientRect();return R?e-a.left:t-a.top})(e.clientX,e.clientY))}},qn=e=>{const t=null===e?null:Math.min(On-1,Math.max(0,e));re?Ue(t):Je(t)},Xn=e=>{Qe(null);qn(((re?Ke:Ye)??(e>0?-1:On))+e)},Yn=null===Hn?[]:qe.flatMap((e,t)=>{if(!We.visible[t]||Dn&&Dn.series!==t)return[];const n=lt[t]?.[Hn];return n&&null!==n.value?[{seriesIndex:t,name:e.name,color:n.color??rt[t],value:n.value,formatted:In(t)(n.value),label:n.label}]:[]}),Jn=Dn&&he?he(Dn):null,Kn=new Map;let Un=0,Gn=0;for(const e of Yn){const t=e.value??0,n=F?t<0?Gn:Un:t,a=F?n+t:t;F&&t<0?Gn=a:F&&(Un=a),Kn.set(e.seriesIndex,[Pn(n,e.seriesIndex),Pn(a,e.seriesIndex)])}const Qn=(e,t)=>{const[n,a]=Kn.get(e.seriesIndex)??[t,t];return Math.max(0,Math.min(n,a)-t,t-Math.max(n,a))},ea=Jn?Jn.items:"item"===Ln&&Yn.length>1&&null!==Ge?[Yn.reduce((e,t)=>Qn(t,Ge)<Qn(e,Ge)?t:e)]:Yn,ta=Dn?lt[Dn.series]?.[Dn.index]?.x??Xe?.[Dn.index]??Dn.index:void 0,na=e=>"number"==typeof e&&Dt?T($e,{}).format(e):g(e,$e),aa=Dn?Dn.x:R?Kn.get(ea[0]?.seriesIndex??-1)?.[1]??Pn(ea[0]?.value??0,ea[0]?.seriesIndex):wn.left+zn(Hn??0),la=Dn?Dn.y:R?wn.top+zn(Hn??0):wn.top,ra=Dn?(Dn.x-wn.left)/Math.max(1,wn.width)>.6:(R?(aa-wn.left)/Math.max(1,wn.width):zn(Hn??0)/Math.max(1,Cn))>.6,ia=!1===pe?{interactive:!1}:!0===pe||void 0===pe?{}:pe,oa=!0===pe||!1!==pe&&qe.length>1,sa=ia.side??"bottom",ca={...En,hovered:We.hovered,activeIndex:Hn,marks:Rn,activeMark:Dn},ua=0===it||null===vt||"value"===le&&null===Wt,da=Ze&&ua&&ut.some((e,t)=>We.visible[t]&&e.some(e=>null!==e.value)),ha=ua&&!da;return n(ChartSurface,{...Pe,size:we,variant:Ce,padded:Se,className:Ne,legendSide:sa,legend:oa?e(ChartLegendBar,{series:qe,colors:rt,options:ia,visibility:We,size:we,swatch:ue,values:ia.showValue&&null!==Hn?qe.map((e,t)=>{const n=lt[t]?.[Hn]?.value;return null==n?void 0:In(t)(n)}):void 0}):null,table:ha?null:n(t,{children:[oe?.(Ee,tt)??e(Q,{id:Ee,caption:ge,corner:zt?.label,categories:dt,series:i,values:ut,format:tt,formatFor:xt?In:void 0,locale:$e}),Wn.length>0?e("ul",{className:D,children:Wn.map((e,t)=>n("li",{children:[e.label,": ",_n(e)]},t))}):null]}),children:[ye&&!ha?e(ChartExport,{rows:se??(()=>[["string"==typeof zt?.label?zt.label:"",...qe.map((e,t)=>e.name??`${t+1}`)],...dt.map((e,t)=>[e,...ut.map(e=>e[t]?.value??null)])]),fileName:ke,onExport:Me,label:je.exportCsv}):null,n("div",{ref:Ae,role:"img",tabIndex:ua?void 0:0,"aria-label":ge??je.label,"aria-describedby":ua?void 0:Re,onPointerMove:Zn,onPointerDown:e=>{"touch"===e.pointerType&&Zn(e)},onPointerLeave:e=>{"touch"!==e.pointerType&&Vn()},onKeyDown:"none"===Ln?void 0:e=>{const t=R?"ArrowDown":"ArrowRight",n=R?"ArrowUp":"ArrowLeft";if(e.key===t)Xn(1);else if(e.key===n)Xn(-1);else if("Home"===e.key)qn(0);else if("End"===e.key)qn(On-1);else{if("Escape"!==e.key)return;Vn()}e.preventDefault()},onBlur:Vn,className:_("relative w-full","rounded-(--neba-radius-xs)","focus-visible:[outline:2px_solid_var(--n-ring)] focus-visible:outline-offset-2"),style:{height:"string"==typeof me?me:Ct},children:[ua?e("div",{className:_("flex h-full items-center justify-center text-(--neba-muted-fg)",L[we]),style:da?{paddingBottom:mn}:void 0,children:be??Be.title}):Te>0?n("svg",{width:Te,height:bn||"100%",viewBox:`0 0 ${Te} ${bn}`,"aria-hidden":"true",className:"block overflow-visible",children:[e(te,{plot:wn,scale:Bt,band:Nn,horizontal:R,inset:G,categoryPx:zn,valuePx:Pn,tickTexts:Ot,widestTick:qt,categoryTexts:cn,widestCategory:un,categoryScale:Dt,categoryValuePx:Tn,valueAxis:Nt,categoryAxis:zt,secondScale:Rt,secondTickTexts:Xt,secondaryAxis:k,fontSize:St,turn:tn,labelDepth:hn,zeroPx:jn}),$&&$.length>0?e(ChartReferences,{references:$,plot:wn,horizontal:R,valuePx:Pn,categoryPx:zn,categoryScale:Dt,categoryValuePx:Tn,categoryBounds:Dt?[Dt.min,Dt.max]:G?[Oe,Oe+it-1]:[Oe-.5,Oe+it-.5],categoryOffset:Oe,fontSize:St}):null,null===Hn||re||"index"!==Ln||!1===Fn.crosshair?null:(()=>{const t=zn(Hn);return e("line",R?{x1:wn.left,x2:wn.left+wn.width,y1:wn.top+t,y2:wn.top+t,stroke:"var(--neba-chart-baseline)",strokeWidth:1}:{x1:wn.left+t,x2:wn.left+t,y1:wn.top,y2:wn.top+wn.height,stroke:"var(--neba-chart-baseline)",strokeWidth:1})})(),ze(ca)]}):null,null!==Hn&&ea.length>0&&"none"!==Ln?Fn.render?e("div",{className:"pointer-events-none absolute z-10",style:ra?{right:`calc(100% - ${aa}px + 10px)`,top:la}:{left:aa+10,top:la},children:Fn.render({index:Hn,category:ta??ot[Hn],items:ea})}):e(ChartTooltipPanel,{heading:Jn?Jn.heading:na(ta??ot[Hn]),items:ea,x:aa,y:la,flip:ra,size:we}):null]}),Fe&&!ha&&Ie?e(l.Suspense,{fallback:null,children:e(ee,{outline:ft,count:_e,range:[Oe,Ve],onRange:e=>{De(e),Fe.onRangeChange?.(e)},color:rt[Math.max(0,We.visible.indexOf(!0))]??rt[0],height:Fe.height??32,words:{start:je.start,end:je.end},label:ge??je.label,categories:dt,locale:$e,width:Te})}):null,ua?null:e(ChartSummary,{id:Re,template:je.summary,locale:$e,...kt,second:Mt?{template:je.summarySecondary,...Mt}:null}),"none"===Ln?null:e(ChartStatus,{heading:null===Hn?void 0:Jn?.heading??na(ta??ot[Hn]),items:ea})]})}const te=/*@__PURE__*/l.memo(function ChartAxes({plot:a,scale:l,horizontal:r,categoryPx:i,valuePx:o,tickTexts:s,widestTick:c,categoryTexts:u,widestCategory:d,categoryScale:h,categoryValuePx:m,valueAxis:f,categoryAxis:g,secondScale:p,secondTickTexts:v,secondaryAxis:b,fontSize:y,turn:C,labelDepth:S,zeroPx:N}){const z=!1!==f?.grid&&!f?.hidden,P=r?g:f,A=r?f:g,T=!g?.hidden&&(g?.grid??null!==h),B=e=>h?m(h.ticks[e]):(r?a.top:a.left)+i(e),j=0!==C.angle,$=C.room(d),I=w(u.length,r?a.height:a.width,r?1.8*y:$),E=w(l.ticks.length,r?a.width:a.height,r?Math.max(c,1)+16:2*y),R=u.length>1?Math.abs(B(1)-B(0)):a.width,W=l.ticks.length>1?Math.abs(o(l.ticks[1])-o(l.ticks[0])):a.height,_=x(u.length,I,R,r?1.8*y:j?$:M(u[u.length-1]??"",y)),F=a.top+a.height+C.offset,L=x(l.ticks.length,E,W,r?M(s[s.length-1]??"",y):1.6*y);return n("g",{children:[l.ticks.map((t,i)=>{const c=o(t),u=Math.abs(t)<1e-9;return n("g",{children:[z?e("line",r?{x1:c,x2:c,y1:a.top,y2:a.top+a.height,stroke:u?"var(--neba-chart-baseline)":"var(--neba-chart-grid)",strokeWidth:1}:{x1:a.left,x2:a.left+a.width,y1:c,y2:c,stroke:u?"var(--neba-chart-baseline)":"var(--neba-chart-grid)",strokeWidth:1}):null,f?.hidden||!k(i,l.ticks.length,E,L)?null:e("text",r?{x:c,y:a.top+a.height+y+6,textAnchor:0===i?"start":i===l.ticks.length-1?"end":"middle",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:s[i]}:{x:a.left-8,y:c,textAnchor:"end",dominantBaseline:"central",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:s[i]})]},t)}),g?.hidden?null:n(t,{children:[e("line",r?{x1:N,x2:N,y1:a.top,y2:a.top+a.height,stroke:"var(--neba-chart-axis)",strokeWidth:1}:{x1:a.left,x2:a.left+a.width,y1:N,y2:N,stroke:"var(--neba-chart-axis)",strokeWidth:1}),u.map((t,l)=>{const i=k(l,u.length,I,_);if(!i&&(r||!T))return null;const o=B(l);return r?e("text",{x:a.left-8,y:o,textAnchor:"end",dominantBaseline:"central",fontSize:y,fill:"var(--neba-muted-fg)",className:h?"tabular-nums":void 0,children:t},l):n("g",{children:[T?e("line",{x1:o,x2:o,y1:a.top,y2:a.top+a.height,stroke:"var(--neba-chart-grid)",strokeWidth:1}):null,i?e("text",{x:o,y:F,textAnchor:j?C.anchor:h?0===l?"start":l===u.length-1?"end":"middle":"middle",transform:j?`rotate(${C.angle} ${o} ${F})`:void 0,dominantBaseline:j?"central":void 0,fontSize:y,fill:"var(--neba-muted-fg)",className:h?"tabular-nums":void 0,children:t}):null]},l)})]}),p&&!b?.hidden?p.ticks.map((t,n)=>{const l=r?a.left+p.fraction(t)*a.width:a.top+(1-p.fraction(t))*a.height;return k(n,p.ticks.length,E,L)?e("text",r?{x:l,y:a.top-8,textAnchor:0===n?"start":n===p.ticks.length-1?"end":"middle",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:v[n]}:{x:a.left+a.width+8,y:l,textAnchor:"start",dominantBaseline:"central",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:v[n]},t):null}):null,p&&b?.label&&!b.hidden?e("text",{x:a.left+a.width,y:y+2,textAnchor:"end",fontSize:y,fill:"var(--neba-muted-fg)",fontWeight:500,children:b.label}):null,P?.label&&!P.hidden?e("text",{x:a.left,y:y+2,textAnchor:"start",fontSize:y,fill:"var(--neba-muted-fg)",fontWeight:500,children:P.label}):null,A?.label&&!A.hidden?e("text",{x:a.left+a.width,y:a.top+a.height+S+y+12,textAnchor:"end",fontSize:y,fill:"var(--neba-muted-fg)",fontWeight:500,children:A.label}):null]})});export{Q as ChartDataTable,ChartExport,ChartLegendBar,ChartScaleLegend,ChartStatus,ChartSummary,ChartSurface,ChartTooltipPanel,U as summarise,q as chartHeight,G as useDeferredRows,Z as useMeasuredHeight,V as useMeasuredWidth,K as useReleaseOutside,X as useVisibility};
|
|
1
|
+
"use client";import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{useStyleDefaults as a}from"./defaults.js";import*as l from"react";import{useLayoutEffectOnClient as r}from"./layout-effect.js";import{Box as i}from"../components/box/Box.js";import{alignedScale as o,bandScale as s,categoryAt as c,categoryCount as u,categoryExtent as d,chartFontSizes as h,compactNumber as m,extentOf as f,fitsLast as x,formatCategory as p,markerRadii as g,plotHeights as v,resolveColor as b,seriesColor as y,showsTick as k,textWidth as M,tickStride as w,toFullShares as C,toValues as N,truncate as S,turnedAxis as z,valueScale as P,warnPaletteOverflow as A}from"./chart.js";import{numberFormatter as j}from"./format.js";import{useHydrated as B,useIntlLocale as T}from"./media.js";import{observeResize as _}from"./observe.js";import{WidthSizer as $,widestSamples as E}from"./sizer.js";import{chartMessages as I,emptyMessages as R,fillMessage as W,useMessages as F}from"./i18n.js";import{whenIdle as L}from"./idle.js";import{cx as D,hasContent as H,metaTextClasses as V,srOnlyClasses as O,transitionClasses as Z}from"./styles.js";const X=[];function Y(e,t,n,a){const i=B(),[o]=l.useState(i),[s,c]=l.useState(()=>i?0:a??0);return r(()=>{const a=e.current;if(!n||!a)return;const r=()=>{const e=t(a);l.startTransition(()=>c(e))};return o?c(t(a)):r(),_(a,r)},[e,t,n,o]),s}const q=e=>e.clientWidth,G=e=>e.clientHeight;function J(e,{enabled:t=!0,initial:n}={}){return Y(e,q,t,n)}function K(e,t){return"string"==typeof t||void 0===e||!Number.isFinite(e)||e<=0?void 0:e}function U(e,t){return Y(e,G,t)}function Q(e,t,n){return"number"==typeof e?e:void 0===e?v[t]:n}export const markTransitionClasses="[transition:opacity_var(--neba-duration)_var(--neba-ease),r_var(--neba-duration)_var(--neba-ease),scale_var(--neba-duration)_var(--neba-ease)]";export const markGroupClasses="[&_path]:[transition:opacity_var(--neba-duration)_var(--neba-ease),r_var(--neba-duration)_var(--neba-ease),scale_var(--neba-duration)_var(--neba-ease)] [&_path]:[transform-box:fill-box] [&_path]:[transform-origin:var(--n-origin,50%_50%)]";function ee(e){const[t,n]=l.useState(()=>new Map),[a,r]=l.useState(null),i=l.useMemo(()=>function(e){const t=new Map;return e.map((e,n)=>{if(void 0===e.name)return`index:${n}`;const a=t.get(e.name)??0;return t.set(e.name,a+1),`name:${a}:${e.name}`})}(e),[e]),o=l.useMemo(()=>e.map((e,n)=>t.get(i[n])??!e.hidden),[e,i,t]),s=l.useRef({series:e,keys:i});l.useEffect(()=>{s.current={series:e,keys:i}});return{visible:o,hovered:a,toggle:l.useCallback(e=>{const{series:t,keys:a}=s.current,l=a[e];void 0!==l&&n(n=>{const a=new Map(n);return a.set(l,!(n.get(l)??!t[e]?.hidden)),a})},[]),setHovered:r}}const te={top:"flex-col-reverse",bottom:"flex-col",left:"flex-row-reverse",right:"flex-row"},ne={start:"justify-start",center:"justify-center",end:"justify-end"};function ae(e,t,n){const a=l.useRef(n);l.useEffect(()=>{a.current=n}),l.useEffect(()=>{if(!t)return;const n=t=>{const n=e.current;n&&t.target instanceof Node&&!n.contains(t.target)&&a.current()};return document.addEventListener("pointerdown",n,!0),()=>document.removeEventListener("pointerdown",n,!0)},[e,t])}function ChartLegendBar({series:a,colors:l,options:r,visibility:i,size:o,values:s,reserve:c,swatch:u}){const d=!1!==r.interactive,h="left"===r.side||"right"===r.side;return e("ul",{className:D("flex list-none flex-wrap items-center gap-x-3 gap-y-1 p-0",h?"min-w-0 flex-col items-start":"",ne[r.align??"center"],V[o]),children:a.map((a,r)=>{const o=i.visible[r],h=null!==i.hovered&&i.hovered!==r,m=a.name??`${r+1}`,f=l[r],x=t(n,{children:[e("span",u?{"aria-hidden":"true",className:"flex size-2.5 shrink-0 items-center justify-center",children:u(r,f)}:{"aria-hidden":"true",className:`size-2.5 shrink-0 rounded-[0.1875rem] ${Z}`,style:{backgroundColor:f}}),e("span",{className:"min-w-0 truncate",children:m}),c?t("span",{className:"flex shrink-0 flex-col tabular-nums text-(--neba-muted-fg)",children:[e("span",{className:s?.[r]?void 0:"invisible",children:s?.[r]??""}),e($,{samples:c[r]??[]})]}):s?.[r]?e("span",{className:"shrink-0 tabular-nums text-(--neba-muted-fg)",children:s[r]}):null]});return e("li",{className:"min-w-0",children:d?e("button",{type:"button","aria-pressed":o,onClick:()=>i.toggle(r),onPointerEnter:()=>i.setHovered(r),onPointerLeave:()=>i.setHovered(null),onFocus:()=>i.setHovered(r),onBlur:()=>i.setHovered(null),className:D("flex min-w-0 cursor-pointer items-center gap-1.5 rounded-(--neba-radius-xs)","px-1 py-0.5 text-(--neba-fg)","[transition-property:background-color,color,opacity]","[transition-duration:var(--neba-duration)]","[transition-timing-function:var(--neba-ease)]","hover:bg-(--n-soft)","focus-visible:[outline:2px_solid_var(--n-ring)] focus-visible:outline-offset-1",o?h?"opacity-55":"":"opacity-40"),children:x}):e("span",{className:D("flex min-w-0 items-center gap-1.5 px-1 py-0.5 text-(--neba-fg)",o?"":"opacity-40"),children:x})},a.name??r)})})}function ChartScaleLegend({steps:a,from:l,to:r,middle:i,align:o,vertical:s,size:c}){return e("div",{className:D("flex",s?"":ne[o]),children:t("div",{className:D("grid grid-cols-[auto_auto_auto] items-center gap-x-2",V[c]),children:[e("span",{className:"shrink-0 tabular-nums text-(--neba-muted-fg)",children:l}),e("span",{"aria-hidden":"true",className:D("flex h-2.5 overflow-hidden rounded-[0.1875rem]",s?"w-20":"w-24"),children:a.map(t=>e("span",{className:"h-full flex-1",style:{backgroundColor:t}},t))}),e("span",{className:"shrink-0 tabular-nums text-(--neba-muted-fg)",children:r}),i?t(n,{children:[e("span",{}),e("span",{className:"text-center tabular-nums text-(--neba-muted-fg)",children:i}),e("span",{})]}):null]})})}function ChartTooltipPanel({heading:n,items:a,x:l,y:r,flip:i,size:o}){return t("div",{"data-neba-tooltip":"",className:D("pointer-events-none absolute z-10 max-w-56 min-w-24","rounded-(--neba-radius-sm) border p-2","[background-image:var(--neba-grain),var(--neba-sheen)]","[background-blend-mode:overlay,normal] [backdrop-filter:var(--neba-blur)]","bg-(--neba-panel-press) [border-color:var(--n-line)]","[box-shadow:var(--neba-shadow-2),var(--neba-plate-glass)]",V[o]),style:i?{right:`calc(100% - ${l}px + 10px)`,top:r}:{left:l+10,top:r},children:[e("div",{className:"mb-1 font-medium text-(--neba-fg)",children:n}),e("ul",{className:"flex list-none flex-col gap-0.5 p-0",children:a.map(n=>t("li",{className:"flex items-center gap-1.5",children:[e("span",{"aria-hidden":"true",className:"size-2 shrink-0 rounded-[0.125rem]",style:{backgroundColor:n.color}}),n.name?e("span",{className:"min-w-0 flex-1 truncate text-(--neba-muted-fg)",children:n.name}):null,e("span",{className:"ms-auto shrink-0 font-medium tabular-nums text-(--neba-fg)",children:n.label??n.formatted})]},n.seriesIndex))})]})}function ChartSummary({id:e,template:n,count:a,min:l,max:r,second:i,locale:o}){const s=j(o,{});return t("span",{id:e,hidden:!0,children:[W(n,{count:s.format(a),min:l,max:r}),i&&i.count>0?` ${W(i.template,{count:s.format(i.count),min:i.min,max:i.max})}`:null]})}function le(e,t){let n=0,a=1/0,l=-1/0;for(const t of e)for(const e of t)null===e.value||Number.isNaN(e.value)||(n+=1,a=Math.min(a,e.value),l=Math.max(l,e.value));return 0===n?{count:n,min:"",max:""}:{count:n,min:t(a),max:t(l)}}function ChartStatus({heading:a,items:r}){return e("span",{role:"status","aria-live":"polite",className:O,children:0===r.length?null:t(n,{children:[H(a)?t(n,{children:[a,", "]}):null,r.map((e,n)=>t(l.Fragment,{children:[n>0?", ":null,e.name?`${e.name}: `:null,e.label??e.formatted]},e.seriesIndex))]})})}export const deferredTablePoints=500;export const chartTableClasses=`${O} table-fixed [contain:content]`;function re({rows:e,points:t,columns:n}){const a=t>500,[r,i]=l.useState(()=>a?0:e),o=a?Math.min(r,e):e;o!==r&&i(o);const s=Math.max(1,Math.floor(1e3/Math.max(1,n)));return l.useEffect(()=>{if(!(r>=e))return L(()=>i(Math.min(e,r+s)),500)},[r,e,s]),{shown:o,run:s}}const ie=/*@__PURE__*/l.memo(function TableRun({from:t,to:a,draw:l}){return e(n,{children:l(t,a)})});function oe(t,n,a){const l=[];for(let r=0;r<t;r+=n)l.push(e(ie,{from:r,to:Math.min(t,r+n),draw:a},r));return l}const se=/*@__PURE__*/l.memo(function ChartDataTable({id:n,caption:a,corner:r,categories:i,series:o,values:s,format:c,formatFor:u,locale:d}){const{shown:h,run:m}=re({rows:i.length,points:s.reduce((e,t)=>e+t.length,0),columns:o.length+1}),f=l.useCallback((n,a)=>i.slice(n,a).map((a,l)=>{const r=n+l;return t("tr",{children:[e("th",{scope:"row",children:p(a,d)}),o.map((t,n)=>{const a=s[n]?.[r];return e("td",void 0!==a?.label?{children:a.label}:{children:null==a?.value?"":(u?.(n)??c)(a.value)},t.name??n)})]},r)}),[i,o,s,c,u,d]);return t("table",{id:n,className:chartTableClasses,"aria-busy":h<i.length||void 0,children:[a?e("caption",{children:a}):null,e("thead",{children:t("tr",{children:[e("th",{scope:"col",children:r??""}),o.map((t,n)=>e("th",{scope:"col",children:t.name??n+1},t.name??n))]})}),e("tbody",{children:oe(h,m,f)})]})}),ce=l.lazy(()=>import("./chart-brush.js").then(e=>({default:e.ChartBrush})));function ChartExport({rows:t,fileName:n,onExport:a,label:l}){return e("button",{type:"button","aria-label":l,title:l,onClick:async()=>{const{toCsv:e,downloadText:l}=await(import("./csv.js")),r=e(t());a?a(r):l(r,n,"text/csv;charset=utf-8")},className:D("absolute end-0 top-0 z-10 inline-flex size-6 cursor-pointer items-center justify-center","rounded-(--neba-radius-xs) text-(--neba-muted-fg)","hover:bg-(--n-soft) hover:text-(--neba-fg)","focus-visible:[outline:2px_solid_var(--n-ring)] focus-visible:outline-offset-1",Z),children:e("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",className:"size-3.5",children:e("path",{d:"M12 3v12m0 0 4-4m-4 4-4-4M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})})})}function ChartSurface({legend:n,legendSide:a,children:l,table:r,className:o,...s}){return t(i,{...s,className:D("relative flex gap-3",te[a],o??void 0),children:[e("div",{className:"relative min-w-0 flex-1",children:l}),n,r]})}function ChartReferences({references:n,plot:a,horizontal:l,valuePx:r,categoryPx:i,categoryScale:o,categoryValuePx:s,categoryBounds:c,categoryOffset:u,fontSize:d}){const[h,m]=c;return e("g",{children:n.map((n,c)=>{const f="value"===(n.axis??"value"),x=e=>f?e:Math.min(m,Math.max(h,e));if(!f&&Math.max(n.value,n.to??n.value)<h)return null;if(!f&&Math.min(n.value,n.to??n.value)>m)return null;const p=e=>f?r(e):o?s(e):(l?a.top:a.left)+i(e-u),g=f?!l:l,v=p(x(n.value)),y=void 0===n.to?null:p(x(n.to)),k=(void 0===n.to?[n.value]:[n.value,n.to]).filter(e=>f||e>=h&&e<=m).map(p),M=null===y?v:Math.min(v,y),w=null===y?v:Math.max(v,y),C=n.color?b(n.color):"var(--neba-muted-fg)",N=n.solid?void 0:"4 4",S=n.label?e("text",{x:g?a.left+a.width-4:M+4,y:g?M-5:a.top+d,textAnchor:g?"end":"start",fontSize:d,fontWeight:500,fill:C,children:n.label}):null;return t("g",{children:[null===y?null:e("rect",{x:g?a.left:M,y:g?M:a.top,width:g?a.width:Math.max(0,w-M),height:g?Math.max(0,w-M):a.height,fill:`color-mix(in oklab, ${C} 12%, transparent)`}),k.map((t,n)=>e("line",{x1:g?a.left:t,x2:g?a.left+a.width:t,y1:g?t:a.top,y2:g?t:a.top+a.height,stroke:C,strokeWidth:1,strokeDasharray:N},n)),S]},c)})})}export function CartesianChart(r){const{series:i,categories:x,xAxis:v,yAxis:b,secondaryAxis:k,brush:w,references:_,horizontal:$=!1,stacked:W=!1,stackedFull:L=!1,includeZero:H=!0,bandRatio:Z=1,inset:Y=!1,headroom:q=0,markInset:G=0,xScale:te="band",marks:ne,markRadius:re=24,table:ie,exportRows:oe,summary:de,swatch:he,scale:me,markTooltip:fe,height:xe,initialWidth:pe,format:ge,locale:ve,label:be,legend:ye,tooltip:ke,empty:Me,exportable:we=!1,exportFileName:Ce="chart.csv",onExport:Ne,size:Se="md",variant:ze="text",padded:Pe=!1,className:Ae,children:je,...Be}=a(r,["size","variant","locale"]),Te=l.useRef(null),_e=J(Te,{initial:K(pe,xe)}),$e=F(R,ve),Ee=F(I,ve),Ie=T(ve),Re=B(),We=l.useId(),Fe=l.useId(),Le=ee(i);l.useEffect(()=>{A(i.length)},[i.length]);const De=u(i),He=!0===w?{}:!1===w||void 0===w?null:w,[Ve,Oe]=l.useState(null),Ze=He?He.range??Ve??He.defaultRange??[0,Math.max(0,De-1)]:[0,Math.max(0,De-1)],Xe=Math.min(Math.max(0,Math.round(Ze[0])),Math.max(0,De-1)),Ye=Math.min(Math.max(Xe,Math.round(Ze[1])),Math.max(0,De-1)),qe=null!==He&&(Xe>0||Ye<De-1),Ge=l.useMemo(()=>qe?i.map(e=>({...e,data:e.data.slice(Xe,Ye+1)})):i,[i,qe,Xe,Ye]),Je=l.useMemo(()=>qe&&x?x.slice(Xe,Ye+1):x,[x,qe,Xe,Ye]),[Ke,Ue]=l.useState(null),[Qe,et]=l.useState(null),[tt,nt]=l.useState(null),at=ge?JSON.stringify(ge):"",lt=l.useCallback(e=>ge?j(Ie,ge).format(e):m(e,Ie),[at,Ie]),rt=l.useMemo(()=>N(Ge),[Ge]),it=Le.visible,ot=l.useMemo(()=>L?C(rt,it,lt):rt,[rt,L,it,lt]),st=l.useMemo(()=>Ge.map((e,t)=>y(e,t)),[Ge]),ct=u(Ge),ut=l.useMemo(()=>Array.from({length:ct},(e,t)=>c(t,Je,ot)),[ct,Je,ot]),dt=qe||L,ht=l.useMemo(()=>dt?N(i):null,[dt,i]),mt=ht??ot,ft=l.useMemo(()=>qe&&ht?Array.from({length:De},(e,t)=>c(t,x,ht)):null,[qe,De,x,ht])??ut,xt=Math.max(0,Le.visible.indexOf(!0)),pt=null!==He,gt=l.useMemo(()=>pt?(mt[xt]??[]).map(e=>e.value):[],[pt,mt,xt]),vt=Boolean(k)&&!W&&!L,bt=i.map(e=>"secondary"===e.axis?"1":"0").join(""),yt=l.useCallback(e=>vt&&"1"===bt[e],[vt,bt]),kt=l.useMemo(()=>{const e=f(ot.filter((e,t)=>it[t]&&!yt(t)),W),t=(_??[]).filter(e=>"value"===(e.axis??"value"));if(0===t.length)return e;const n=t.flatMap(e=>void 0===e.to?[e.value]:[e.value,e.to]);return{min:Math.min(e?.min??1/0,...n),max:Math.max(e?.max??-1/0,...n)}},[ot,it,yt,W,_]),Mt=l.useMemo(()=>vt?f(ot.filter((e,t)=>it[t]&&yt(t)),!1):null,[vt,ot,it,yt]),wt=k?.tickFormat,Ct=l.useMemo(()=>de??le(ot.filter((e,t)=>it[t]&&!yt(t)),lt),[de,ot,it,yt,lt]),Nt=l.useMemo(()=>void 0===de&&vt?le(ot.filter((e,t)=>it[t]&&yt(t)),wt?e=>String(wt(e,0)):lt):null,[de,vt,ot,it,yt,wt,lt]),St=U(Te,"string"==typeof xe),zt=Q(xe,Se,St),Pt=h[Se],At=b,jt=v,Bt=At?.min,Tt=At?.max,_t=At?.tickCount,$t=l.useMemo(()=>me??P(kt,{min:Bt,max:Tt,tickCount:_t,includeZero:H}),[me,kt,Bt,Tt,_t,H]),Et=k?.min,It=k?.max,Rt=k?.tickCount,Wt=$t.ticks.length-1,Ft=l.useMemo(()=>null===Mt?null:void 0===Rt?o(Mt,Wt,{min:Et,max:It,includeZero:H}):P(Mt,{min:Et,max:It,tickCount:Rt,includeZero:H}),[Mt,Wt,Et,It,Rt,H]),Lt=l.useMemo(()=>"value"===te?d(ot.filter((e,t)=>it[t]),Je):null,[te,ot,it,Je]),Dt=jt?.min,Ht=jt?.max,Vt=jt?.tickCount,Ot=l.useMemo(()=>"value"===te?P(Lt,{min:Dt,max:Ht,tickCount:Vt,includeZero:!1}):null,[te,Lt,Dt,Ht,Vt]),Zt=At?.tickFormat,Xt=l.useMemo(()=>$t.ticks.map((e,t)=>Zt?String(Zt(e,t)):lt(e)),[$t,Zt,lt]),Yt=jt?.tickFormat,qt=l.useMemo(()=>Ot?Ot.ticks.map((e,t)=>Yt?String(Yt(e,t)):m(e,Ie)):ut.map((e,t)=>Yt?String(Yt(e,t)):p(e,Ie)),[Ot,ut,Yt,Ie]),Gt=Xt.reduce((e,t)=>Math.max(e,M(t,Pt)),0),Jt=l.useMemo(()=>(Ft?.ticks??[]).map((e,t)=>wt?String(wt(e,t)):lt(e)),[Ft,wt,lt]),Kt=Jt.reduce((e,t)=>Math.max(e,M(t,Pt)),0),Ut=Pt+6,Qt=Ft&&!k?.hidden?k?.thickness??($?Pt+12:Kt+10):0,en=$?jt:At,tn=Boolean(en?.label)&&!en?.hidden,nn=Boolean(Ft&&k?.label&&!k.hidden),an=$||jt?.hidden?0:jt?.tickAngle,ln=l.useMemo(()=>z(an,Pt),[an,Pt]),rn=0!==ln.angle,on=At?.hidden?0:Gt+10,sn=(_e-($?0:on)-16)/Math.max(1,ct),cn=Math.min(140,.4*zt),un=!Ot&&($||rn||sn-6>=2.4*Pt),dn=$?150:rn?ln.cut(cn):sn-6,hn=l.useMemo(()=>un?qt.map(e=>S(e,dn,Pt)):qt,[qt,un,dn,Pt]),mn=l.useMemo(()=>hn.reduce((e,t)=>Math.max(e,M(t,Pt)),0),[hn,Pt]),fn=$?jt?.hidden?0:mn+10:on,xn=ln.depth(mn),pn=He?(He.height??32)+10:0,gn=$?At?.hidden?0:Pt+12+(At?.label?Ut:0):jt?.hidden?0:xn+12+(jt?.label?Ut:0),vn=($?jt:At)?.thickness??fn,bn=(($?At:jt)?.thickness??gn)+pn,yn=($||Ot?12:rn?ln.angle>0?ln.overhang(mn)+8:8:Math.max(8,hn.length?ln.overhang(mn):8))+G+($?0:Qt),kn=g[Se]+4+q+G+(tn||nn?Ut+2:0)+(we?20:0)+($?Qt:0),Mn=zt,wn=vn+G,Cn=Math.max(0,_e-vn-G-yn),Nn=Math.max(0,Mn-kn-bn-G),Sn=l.useMemo(()=>({left:wn,top:kn,width:Cn,height:Nn}),[wn,kn,Cn,Nn]),zn=$?Sn.height:Sn.width,Pn=Y?Math.max(1,ct-1):ct,An=l.useMemo(()=>s(Pn,zn,Z),[Pn,zn,Z]),jn=l.useCallback(e=>Y?ct<=1?zn/2:zn*e/(ct-1):An.centre(e),[Y,ct,zn,An]),Bn=l.useCallback((e,t)=>{return n=void 0!==t&&yt(t)&&Ft?Ft:$t,$?Sn.left+n.fraction(e)*Sn.width:Sn.top+(1-n.fraction(e))*Sn.height;var n},[$,Sn.left,Sn.top,Sn.width,Sn.height,$t,Ft,yt]),Tn=l.useCallback((e,t,n)=>$?{x:Bn(t,n),y:Sn.top+jn(e)}:{x:Sn.left+jn(e),y:Bn(t,n)},[$,Bn,jn,Sn.left,Sn.top]),_n=l.useCallback(e=>$?Sn.top+(1-(Ot?.fraction(e)??0))*Sn.height:Sn.left+(Ot?.fraction(e)??0)*Sn.width,[$,Sn.left,Sn.top,Sn.width,Sn.height,Ot]),$n=l.useCallback(e=>{const t=void 0!==e&&yt(e)&&Ft?Ft:$t;return Bn(Math.min(Math.max(0,t.min),t.max),e)},[Bn,$t,Ft,yt]),En=$n(),In=k?.tickFormat,Rn=l.useCallback(e=>yt(e)&&In?e=>String(In(e,0)):lt,[yt,In,lt]),Wn="object"==typeof ye&&Boolean(ye.showValue),Fn=l.useMemo(()=>Wn?ot.map((e,t)=>function(e,t){const n=new Set;for(const a of e)null===a.value||Number.isNaN(a.value)||n.add(t(a.value).replace(/[0-9]/g,"0"));return E([...n])}(e,Rn(t))):void 0,[Wn,ot,Rn]),Ln=l.useMemo(()=>({plot:Sn,values:ot,visible:it,colors:st,scale:$t,secondScale:Ft,onSecond:yt,band:An,horizontal:$,valuePx:Bn,categoryPx:jn,point:Tn,categoryScale:Ot,categoryValuePx:_n,zeroPx:En,zeroPxOf:$n,categories:ut,size:Se}),[Sn,ot,it,st,$t,Ft,yt,An,$,Bn,jn,Tn,Ot,_n,En,$n,ut,Se]),Dn=_e>0,Hn=l.useMemo(()=>ne&&Dn?ne(Ln):X,[ne,Dn,Ln]),Vn=(_??[]).filter(e=>Boolean(e.label)),On=e=>{const t=t=>"value"===(e.axis??"value")?lt(t):p(Ot?t:ft[t]??t,Ie);return void 0===e.to?t(e.value):`${t(e.value)}–${t(e.to)}`},Zn=!1===ke?{mode:"none"}:!0===ke||void 0===ke?{}:ke,Xn=Zn.mode??(ne?"item":"index"),Yn=e=>{const t=new Map;let n=0,a=0;for(const l of e){const e=l.value??0,r=W?e<0?a:n:e,i=W?r+e:e;W&&e<0?a=i:W&&(n=i),t.set(l.seriesIndex,[Bn(r,l.seriesIndex),Bn(i,l.seriesIndex)])}return t},qn=null===Qe?null:Hn[Qe]??null,Gn=ne?qn?qn.index:null:Ke,Jn=ne?Hn.length:ct,Kn=()=>{Ue(null),et(null),nt(null)};ae(Te,null!==Gn,Kn);const Un=e=>{if("none"===Xn)return;if(ne){const t=((e,t)=>{const n=Te.current;if(!n||0===Hn.length)return null;const a=n.getBoundingClientRect(),l=e-a.left,r=t-a.top;let i=null,o=1/0,s=1/0;return Hn.forEach((e,t)=>{const n=e.x-l,a=e.y-r,c=Math.sqrt(n*n+a*a);let u;if(void 0===e.rx)u=Math.max(0,c-e.r);else{const t=Math.max(0,Math.abs(n)-e.rx),l=Math.max(0,Math.abs(a)-(e.ry??e.rx));u=Math.sqrt(t*t+l*l)}u<=re&&(u<o||u===o&&c<s)&&(o=u,s=c,i=t)}),i})(e.clientX,e.clientY);return void(t!==Qe&&et(t))}const t=((e,t)=>{const n=Te.current;if(!n||0===ct)return null;const a=n.getBoundingClientRect(),l=$?t-a.top-Sn.top:e-a.left-Sn.left;if(l<-An.step||l>zn+An.step)return null;const r=Y?ct<=1?0:Math.round(l/zn*(ct-1)):Math.floor(l/An.step);return Math.min(ct-1,Math.max(0,r))})(e.clientX,e.clientY);if(t!==Ke&&Ue(t),"item"===Xn){const n=((e,t)=>{const n=Te.current;if(!n)return null;const a=n.getBoundingClientRect();return $?e-a.left:t-a.top})(e.clientX,e.clientY),a=null===t||null===n?null:((e,t)=>{const n=Ge.flatMap((t,n)=>{const a=ot[n]?.[e]?.value;return Le.visible[n]&&null!=a?[{seriesIndex:n,value:a}]:[]}),a=Yn(n);let l=null,r=1/0;for(const{seriesIndex:e}of n){const[n,i]=a.get(e)??[t,t],o=Math.max(0,Math.min(n,i)-t,t-Math.max(n,i));o<r&&(r=o,l=e)}return l})(t,n);a!==tt&&nt(a)}},Qn=e=>{const t=null===e?null:Math.min(Jn-1,Math.max(0,e));ne?et(t):Ue(t)},ea=e=>{nt(null);Qn(((ne?Qe:Ke)??(e>0?-1:Jn))+e)},ta=null===Gn?[]:Ge.flatMap((e,t)=>{if(!Le.visible[t]||qn&&qn.series!==t)return[];const n=ot[t]?.[Gn];return n&&null!==n.value?[{seriesIndex:t,name:e.name,color:n.color??st[t],value:n.value,formatted:Rn(t)(n.value),label:n.label}]:[]}),na=qn&&fe?fe(qn):null,aa=Yn(ta),la="item"===Xn&&ta.length>1&&null!==tt?ta.find(e=>e.seriesIndex===tt):void 0,ra=na?na.items:la?[la]:ta,ia=qn?ot[qn.series]?.[qn.index]?.x??Je?.[qn.index]??qn.index:void 0,oa=e=>"number"==typeof e&&Ot?j(Ie,{}).format(e):p(e,Ie),sa=qn?qn.x:$?aa.get(ra[0]?.seriesIndex??-1)?.[1]??Bn(ra[0]?.value??0,ra[0]?.seriesIndex):Sn.left+jn(Gn??0),ca=qn?qn.y:$?Sn.top+jn(Gn??0):Sn.top,ua=qn?(qn.x-Sn.left)/Math.max(1,Sn.width)>.6:($?(sa-Sn.left)/Math.max(1,Sn.width):jn(Gn??0)/Math.max(1,zn))>.6,da=!1===ye?{interactive:!1}:!0===ye||void 0===ye?{}:ye,ha=!0===ye||!1!==ye&&Ge.length>1,ma=da.side??"bottom",fa={...Ln,format:lt,formatFor:Rn,hovered:Le.hovered,activeIndex:Gn,marks:Hn,activeMark:qn},xa=0===ct||null===kt||"value"===te&&null===Lt,pa=qe&&xa&&mt.some((e,t)=>Le.visible[t]&&e.some(e=>null!==e.value)),ga=xa&&!pa;return t(ChartSurface,{...Be,size:Se,variant:ze,padded:Pe,className:Ae,legendSide:ma,legend:ha?e(ChartLegendBar,{series:Ge,colors:st,options:da,visibility:Le,size:Se,swatch:he,reserve:Fn,values:da.showValue&&null!==Gn?Ge.map((e,t)=>{const n=ot[t]?.[Gn]?.value;return null==n?void 0:Rn(t)(n)}):void 0}):null,table:ga?null:t(n,{children:[ie?.(We,lt)??e(se,{id:We,caption:be,corner:jt?.label,categories:ft,series:i,values:mt,format:lt,formatFor:vt?Rn:void 0,locale:Ie}),Vn.length>0?e("ul",{className:O,children:Vn.map((e,n)=>t("li",{children:[e.label,": ",On(e)]},n))}):null]}),children:[we&&!ga?e(ChartExport,{rows:oe??(()=>[["string"==typeof jt?.label?jt.label:"",...Ge.map((e,t)=>e.name??`${t+1}`)],...ft.map((e,t)=>[e,...mt.map(e=>e[t]?.value??null)])]),fileName:Ce,onExport:Ne,label:Ee.exportCsv}):null,t("div",{ref:Te,role:"img",tabIndex:xa?void 0:0,"aria-label":be??Ee.label,"aria-describedby":xa?void 0:Fe,onPointerMove:Un,onPointerDown:e=>{"touch"===e.pointerType&&Un(e)},onPointerLeave:e=>{"touch"!==e.pointerType&&Kn()},onKeyDown:"none"===Xn?void 0:e=>{const t=$?"ArrowDown":"ArrowRight",n=$?"ArrowUp":"ArrowLeft";if(e.key===t)ea(1);else if(e.key===n)ea(-1);else if("Home"===e.key)Qn(0);else if("End"===e.key)Qn(Jn-1);else{if("Escape"!==e.key)return;Kn()}e.preventDefault()},onBlur:Kn,className:D("relative w-full","rounded-(--neba-radius-xs)","focus-visible:[outline:2px_solid_var(--n-ring)] focus-visible:outline-offset-2"),style:{height:"string"==typeof xe?xe:zt},children:[xa?e("div",{className:D("flex h-full items-center justify-center text-(--neba-muted-fg)",V[Se]),style:pa?{paddingBottom:pn}:void 0,children:Me??$e.title}):_e>0?t("svg",{width:_e,height:Mn||"100%",viewBox:`0 0 ${_e} ${Mn}`,"aria-hidden":"true",className:"block overflow-visible",children:[e(ue,{plot:Sn,scale:$t,band:An,horizontal:$,inset:Y,categoryPx:jn,valuePx:Bn,tickTexts:Xt,widestTick:Gt,categoryTexts:hn,widestCategory:mn,categoryScale:Ot,categoryValuePx:_n,valueAxis:At,categoryAxis:jt,secondScale:Ft,secondTickTexts:Jt,secondaryAxis:k,fontSize:Pt,turn:ln,labelDepth:xn,zeroPx:En}),_&&_.length>0?e(ChartReferences,{references:_,plot:Sn,horizontal:$,valuePx:Bn,categoryPx:jn,categoryScale:Ot,categoryValuePx:_n,categoryBounds:Ot?[Ot.min,Ot.max]:Y?[Xe,Xe+ct-1]:[Xe-.5,Xe+ct-.5],categoryOffset:Xe,fontSize:Pt}):null,null===Gn||ne||"index"!==Xn||!1===Zn.crosshair?null:(()=>{const t=jn(Gn);return e("line",$?{x1:Sn.left,x2:Sn.left+Sn.width,y1:Sn.top+t,y2:Sn.top+t,stroke:"var(--neba-chart-baseline)",strokeWidth:1}:{x1:Sn.left+t,x2:Sn.left+t,y1:Sn.top,y2:Sn.top+Sn.height,stroke:"var(--neba-chart-baseline)",strokeWidth:1})})(),je(fa)]}):null,null!==Gn&&ra.length>0&&"none"!==Xn?Zn.render?e("div",{className:"pointer-events-none absolute z-10",style:ua?{right:`calc(100% - ${sa}px + 10px)`,top:ca}:{left:sa+10,top:ca},children:Zn.render({index:Gn,category:ia??ut[Gn],items:ra})}):e(ChartTooltipPanel,{heading:na?na.heading:oa(ia??ut[Gn]),items:ra,x:sa,y:ca,flip:ua,size:Se}):null]}),He&&!ga&&Re?e(l.Suspense,{fallback:null,children:e(ce,{outline:gt,count:De,range:[Xe,Ye],onRange:e=>{Oe(e),He.onRangeChange?.(e)},color:st[Math.max(0,Le.visible.indexOf(!0))]??st[0],height:He.height??32,words:{start:Ee.start,end:Ee.end},label:be??Ee.label,categories:ft,locale:Ie,width:_e})}):null,xa?null:e(ChartSummary,{id:Fe,template:Ee.summary,locale:Ie,...Ct,second:Nt?{template:Ee.summarySecondary,...Nt}:null}),"none"===Xn?null:e(ChartStatus,{heading:null===Gn?void 0:na?.heading??oa(ia??ut[Gn]),items:ra})]})}const ue=/*@__PURE__*/l.memo(function ChartAxes({plot:a,scale:l,horizontal:r,categoryPx:i,valuePx:o,tickTexts:s,widestTick:c,categoryTexts:u,widestCategory:d,categoryScale:h,categoryValuePx:m,valueAxis:f,categoryAxis:p,secondScale:g,secondTickTexts:v,secondaryAxis:b,fontSize:y,turn:C,labelDepth:N,zeroPx:S}){const z=!1!==f?.grid&&!f?.hidden,P=r?p:f,A=r?f:p,j=!p?.hidden&&(p?.grid??null!==h),B=e=>h?m(h.ticks[e]):(r?a.top:a.left)+i(e),T=0!==C.angle,_=C.room(d),$=w(u.length,r?a.height:a.width,r?1.8*y:_),E=w(l.ticks.length,r?a.width:a.height,r?Math.max(c,1)+16:2*y),I=u.length>1?Math.abs(B(1)-B(0)):a.width,R=l.ticks.length>1?Math.abs(o(l.ticks[1])-o(l.ticks[0])):a.height,W=x(u.length,$,I,r?1.8*y:T?_:M(u[u.length-1]??"",y)),F=a.top+a.height+C.offset,L=x(l.ticks.length,E,R,r?M(s[s.length-1]??"",y):1.6*y);return t("g",{children:[l.ticks.map((n,i)=>{const c=o(n),u=Math.abs(n)<1e-9;return t("g",{children:[z?e("line",r?{x1:c,x2:c,y1:a.top,y2:a.top+a.height,stroke:u?"var(--neba-chart-baseline)":"var(--neba-chart-grid)",strokeWidth:1}:{x1:a.left,x2:a.left+a.width,y1:c,y2:c,stroke:u?"var(--neba-chart-baseline)":"var(--neba-chart-grid)",strokeWidth:1}):null,f?.hidden||!k(i,l.ticks.length,E,L)?null:e("text",r?{x:c,y:a.top+a.height+y+6,textAnchor:0===i?"start":i===l.ticks.length-1?"end":"middle",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:s[i]}:{x:a.left-8,y:c,textAnchor:"end",dominantBaseline:"central",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:s[i]})]},n)}),p?.hidden?null:t(n,{children:[e("line",r?{x1:S,x2:S,y1:a.top,y2:a.top+a.height,stroke:"var(--neba-chart-axis)",strokeWidth:1}:{x1:a.left,x2:a.left+a.width,y1:S,y2:S,stroke:"var(--neba-chart-axis)",strokeWidth:1}),u.map((n,l)=>{const i=k(l,u.length,$,W);if(!i&&(r||!j))return null;const o=B(l);return r?e("text",{x:a.left-8,y:o,textAnchor:"end",dominantBaseline:"central",fontSize:y,fill:"var(--neba-muted-fg)",className:h?"tabular-nums":void 0,children:n},l):t("g",{children:[j?e("line",{x1:o,x2:o,y1:a.top,y2:a.top+a.height,stroke:"var(--neba-chart-grid)",strokeWidth:1}):null,i?e("text",{x:o,y:F,textAnchor:T?C.anchor:h?0===l?"start":l===u.length-1?"end":"middle":"middle",transform:T?`rotate(${C.angle} ${o} ${F})`:void 0,dominantBaseline:T?"central":void 0,fontSize:y,fill:"var(--neba-muted-fg)",className:h?"tabular-nums":void 0,children:n}):null]},l)})]}),g&&!b?.hidden?g.ticks.map((t,n)=>{const l=r?a.left+g.fraction(t)*a.width:a.top+(1-g.fraction(t))*a.height;return k(n,g.ticks.length,E,L)?e("text",r?{x:l,y:a.top-8,textAnchor:0===n?"start":n===g.ticks.length-1?"end":"middle",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:v[n]}:{x:a.left+a.width+8,y:l,textAnchor:"start",dominantBaseline:"central",fontSize:y,fill:"var(--neba-muted-fg)",className:"tabular-nums",children:v[n]},t):null}):null,g&&b?.label&&!b.hidden?e("text",{x:a.left+a.width,y:y+2,textAnchor:"end",fontSize:y,fill:"var(--neba-muted-fg)",fontWeight:500,children:b.label}):null,P?.label&&!P.hidden?e("text",{x:a.left,y:y+2,textAnchor:"start",fontSize:y,fill:"var(--neba-muted-fg)",fontWeight:500,children:P.label}):null,A?.label&&!A.hidden?e("text",{x:a.left+a.width,y:a.top+a.height+N+y+12,textAnchor:"end",fontSize:y,fill:"var(--neba-muted-fg)",fontWeight:500,children:A.label}):null]})});export{se as ChartDataTable,ChartExport,ChartLegendBar,ChartScaleLegend,ChartStatus,ChartSummary,ChartSurface,ChartTooltipPanel,le as summarise,Q as chartHeight,K as initialWidthFor,oe as tableRuns,re as useDeferredRows,U as useMeasuredHeight,J as useMeasuredWidth,ae as useReleaseOutside,ee as useVisibility};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as l,jsxs as e}from"react/jsx-runtime";import*as
|
|
1
|
+
import{jsx as l,jsxs as e,Fragment as r}from"react/jsx-runtime";import*as t from"react";import{areaPath as o,chartFontSizes as n,labelInk as a,labelledPoints as s,linePath as i,lineWidths as u,markerRadii as c,markGap as f}from"./chart.js";import{markTransitionClasses as p}from"./chart-frame.js";const d=l=>l.filter(Boolean);export function LineSeries({context:r,curve:n,filled:a,stacked:m,markers:b,valueLabels:$,connectNulls:g,gradient:y,idPrefix:j}){const{values:z,visible:L,colors:C,hovered:F,activeIndex:N,plot:W,point:M,zeroPxOf:O,size:S,formatFor:w}=r,E=u[S],G=c[S],P=t.useMemo(()=>{const l=L.indexOf(!0),e=[],r=[],t=[];return z.forEach((l,o)=>{const n=l.map((l,e)=>(l.value??0)<0?t[e]??0:r[e]??0);e.push(n),m&&L[o]&&l.forEach((l,e)=>{const o=l.value??0;o<0?t[e]=(t[e]??0)+o:r[e]=(r[e]??0)+o})}),z.map((r,t)=>{if(!L[t])return null;const u=r.map((l,r)=>{if(null===l.value)return null;const o=m?e[t][r]+l.value:l.value;return M(r,o,t)}),c=g?d(u):u,f=O(t),p=r.map((l,r)=>null===l.value?null:m?M(r,e[t][r],t):{x:M(r,l.value,t).x,y:f}),h=g?d(p):p,x=a&&m;return{tops:u,area:a?o(c,h,n):null,gap:x&&t!==l?i(h,n):null,line:x?null:i(c,n),labelled:s(r,$)}})},[z,L,m,a,g,n,M,O,$]);return e("g",{children:[e("defs",{children:[y?C.map((r,t)=>e("linearGradient",{id:`${j}-stroke-${t}`,gradientUnits:"userSpaceOnUse",x1:W.left,y1:0,x2:W.left+W.width,y2:0,children:[l("stop",{offset:"0%",stopColor:`color-mix(in oklab, ${r} 45%, transparent)`}),l("stop",{offset:"100%",stopColor:r})]},`stroke-${t}`)):null,a&&!m?C.map((r,t)=>e("linearGradient",{id:`${j}-fill-${t}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[l("stop",{offset:"0%",stopColor:`color-mix(in oklab, ${r} 28%, transparent)`}),l("stop",{offset:"100%",stopColor:`color-mix(in oklab, ${r} 2%, transparent)`})]},`fill-${t}`)):null]}),z.map((r,t)=>{const o=P[t];if(!o)return null;const{tops:n,labelled:a}=o,s=C[t],i=null!==F&&F!==t,u="all"===b||"auto"===b&&r.length<=14;return e("g",{opacity:i?.28:1,className:p,children:[null===o.area?null:l("path",{d:o.area,fill:m?`color-mix(in oklab, ${s} 70%, transparent)`:`url(#${j}-fill-${t})`,stroke:"none"}),null===o.gap?null:l("path",{d:o.gap,fill:"none",stroke:"var(--neba-chart-gap)",strokeWidth:f}),null===o.line?null:l("path",{d:o.line,fill:"none",stroke:y?`url(#${j}-stroke-${t})`:s,strokeWidth:E,strokeLinecap:"round",strokeLinejoin:"round"}),u?h(n.length).map(([e,t])=>l(v,{tops:n,values:r,from:e,to:t,color:s,radius:G,active:null!==N&&N>=e&&N<t?N:null},e)):null===N?null:x(n,r,N,s,G,N),"none"===$?null:l(k,{tops:n,values:r,labelled:a,color:s,plot:W,radius:G,size:S,series:t,formatFor:w})]},t)})]})}const m=64;function h(l){const e=[];for(let r=0;r<l;r+=m)e.push([r,Math.min(l,r+m)]);return e}function x(e,r,t,o,n,a){const s=e[t];return s?l("circle",{cx:s.x,cy:s.y,r:t===a?n+1:n,fill:r[t].color??o,stroke:"var(--neba-chart-gap)",strokeWidth:f,className:p},t):null}const v=/*@__PURE__*/t.memo(function MarkerRun({tops:e,values:t,from:o,to:n,color:a,radius:s,active:i}){const u=[];for(let l=o;l<n;l++)u.push(x(e,t,l,a,s,i));return l(r,{children:u})}),k=/*@__PURE__*/t.memo(function ValueLabels({tops:e,values:t,labelled:o,color:s,plot:i,radius:u,size:c,series:f,formatFor:p}){const d=p(f);return l(r,{children:e.map((e,r)=>{const f=t[r].value;return e&&null!==f&&o(r)?l("text",{x:e.x,y:e.y-u-5,textAnchor:e.x>i.left+i.width-24?"end":e.x<i.left+24?"start":"middle",fontSize:n[c],fontWeight:500,fill:a(t[r].color??s),className:"tabular-nums",children:t[r].label??d(f)},`label-${r}`):null})})});
|
package/dist/internal/chart.d.ts
CHANGED
|
@@ -519,6 +519,19 @@ export declare const markShapes: readonly MarkShape[];
|
|
|
519
519
|
* the hover treatment are then unarguably the same on all five.
|
|
520
520
|
*/
|
|
521
521
|
export declare function markPath(shape: MarkShape, cx: number, cy: number, r: number): string;
|
|
522
|
+
/**
|
|
523
|
+
* Where `markPath`'s `cx`/`cy` falls inside the shape's own bounding box, as a
|
|
524
|
+
* `transform-origin` against `transform-box: fill-box`.
|
|
525
|
+
*
|
|
526
|
+
* A fraction of the box is the same for every mark of one shape, whatever its
|
|
527
|
+
* size and wherever it sits, so a whole plot of them can be grown about their
|
|
528
|
+
* own points by one rule rather than by an origin written on each mark. Four of
|
|
529
|
+
* the shapes are symmetric about their point and are the middle of their box,
|
|
530
|
+
* which is what `undefined` stands for. The triangle is the exception, since it
|
|
531
|
+
* sits on its circumcircle: its apex is `size` above the point and its base
|
|
532
|
+
* `size / 2` below it, so the point is two thirds of the way down.
|
|
533
|
+
*/
|
|
534
|
+
export declare function markOrigin(shape: MarkShape): string | undefined;
|
|
522
535
|
/**
|
|
523
536
|
* The centre line of that slice, as an *open* path.
|
|
524
537
|
*
|
package/dist/internal/chart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseColor as t,readableInk as e}from"./color.js";import{dateFormatter as n,numberFormatter as r}from"./format.js";export const plotHeights={xs:120,sm:160,md:220,lg:280,xl:360};export const sparklineHeights={xs:16,sm:20,md:28,lg:40,xl:56};export const lineWidths={xs:1.5,sm:1.75,md:2,lg:2.25,xl:2.5};export const markerRadii={xs:3,sm:3.5,md:4,lg:4.5,xl:5};export const chartFontSizes={xs:10,sm:11,md:12,lg:13,xl:14};export const barMaxThickness={xs:14,sm:18,md:24,lg:30,xl:36};export const barBandRatio={default:.62,compact:.82};export const markGap=2;export const barRadius=4;export const chartPalette=["var(--neba-chart-1)","var(--neba-chart-2)","var(--neba-chart-3)","var(--neba-chart-4)","var(--neba-chart-5)","var(--neba-chart-6)","var(--neba-chart-7)","var(--neba-chart-8)"];export function inkOn(n,r){if(!n)return`var(--neba-chart-on-${r%chartPalette.length+1})`;const a=o.has(n)?null:t(n);return a?e(a.hsv):"var(--neba-surface)"}export function labelInk(t){return`color-mix(in oklab, ${t} 85%, var(--neba-fg))`}const o=new Set(["primary","secondary","success","warning","danger","info"]);export function resolveColor(t){return o.has(t)?`var(--neba-${t}-accent)`:t}export function seriesColor(t,e,n=chartPalette){return resolveColor(t?.color?t.color:n[e%n.length]??chartPalette[0])}const a=new Set;export function warnPaletteOverflow(t){"production"===process.env.NODE_ENV||t<=chartPalette.length||a.has(t)||(a.add(t),console.warn(`Neba: a chart was given ${t} series and its palette has ${chartPalette.length} colours, so the colours repeat from the ninth series. Fold the smallest into an "Other" series, or draw a second chart.`))}export function toFullShares(t,e,n){const r=[];return t.forEach((t,n)=>{!1!==e[n]&&t.forEach((t,e)=>{r[e]=(r[e]??0)+Math.abs(t.value??0)})}),t.map(t=>t.map((t,e)=>{if(null===t.value)return t;const o=r[e]??0;return{...t,value:0===o?0:t.value/o*100,label:t.label??n(t.value)}}))}export function toValue(t){return null==t?{value:null}:"number"==typeof t?{value:Number.isFinite(t)?t:null}:(t=>"object"==typeof t&&null!==t)(t)?{value:null!==t.y&&Number.isFinite(t.y)?t.y:null,x:t.x,z:t.z,color:t.color?resolveColor(t.color):void 0,label:t.label}:{value:null}}export function toValues(t){return t.map(t=>t.data.map(toValue))}export function zeroGaps(t){return t.map(t=>({...t,data:t.data.map(t=>null==t?0:"number"==typeof t?Number.isFinite(t)?t:0:null!==t.y&&Number.isFinite(t.y)?t:{...t,y:0})}))}export function toNumber(t){return t instanceof Date?Number.isFinite(t.getTime())?t.getTime():null:"number"==typeof t&&Number.isFinite(t)?t:null}export function pointX(t,e,n){return toNumber(t.x??n?.[e]??e)}export function categoryExtent(t,e){let n=1/0,r=-1/0,o=!1;return t.forEach(t=>{t.forEach((t,a)=>{if(null===t.value)return;const i=pointX(t,a,e);null!==i&&(o=!0,n=Math.min(n,i),r=Math.max(r,i))})}),o?{min:n,max:r}:null}export function bubbleRadius(t,e,n,r){return e>0&&Number.isFinite(t)&&!(t<=0)?Math.max(r,Math.sqrt(Math.min(t,e)/e)*n):0===t?0:r}export function categoryCount(t){return t.reduce((t,e)=>Math.max(t,e.data.length),0)}export function categoryAt(t,e,n){if(e&&t<e.length)return e[t];for(const e of n){const n=e[t]?.x;if(void 0!==n)return n}return t}export function extentOf(t,e){let n=1/0,r=-1/0,o=!1;if(e){const e=t.reduce((t,e)=>Math.max(t,e.length),0);for(let a=0;a<e;a++){let e=0,i=0;for(const n of t){const t=n[a]?.value;null!=t&&(o=!0,t>=0?e+=t:i+=t)}n=Math.min(n,i),r=Math.max(r,e)}}else for(const e of t)for(const{value:t}of e)null!==t&&(o=!0,n=Math.min(n,t),r=Math.max(r,t));return o?{min:n,max:r}:null}function i(t){const e=10**Math.floor(Math.log10(t)),n=t/e;return n<=1?e:n<=2?2*e:n<=5?5*e:10*e}export function valueScale(t,e={}){const{tickCount:n=5}=e,{low:r,high:o}=u(t,e),a=void 0!==e.min&&void 0!==e.max?function(t,e){const n=10**Math.floor(Math.log10(t/Math.max(1,e)));let r=i(t/Math.max(1,e)),o=1/0;for(const a of[.1,1,10])for(const i of[1,2,2.5,5]){const u=i*a*n,s=t/u,c=Math.round(s);if(c<1||Math.abs(s-c)>1e-9)continue;const l=Math.abs(c-e);l<o&&(o=l,r=u)}return r}(o-r,n):i((o-r)/Math.max(1,n)),s=void 0!==e.min?r:Number((Math.floor(r/a+1e-9)*a).toFixed(12)),c=void 0!==e.max?o:Number((Math.ceil(o/a-1e-9)*a).toFixed(12)),l=c-s||1,h=[];for(let t=s;t<=c+1e-9*a;t+=a)h.push(Number(t.toFixed(12)));return{min:s,max:c,ticks:h,fraction:t=>(t-s)/l}}export function alignedScale(t,e,n={}){const r=Math.max(1,Math.round(e)),{low:o,high:a}=u(t,n);let s,c=i((a-o)/r);if(void 0!==n.min&&void 0!==n.max)c=(a-o)/r,s=o;else if(void 0!==n.max)s=a-r*c;else if(void 0!==n.min)s=o;else for(s=Math.floor(o/c+1e-9)*c;s+r*c<a-1e-9*c;)c=i(1.000001*c),s=Math.floor(o/c+1e-9)*c;const l=Array.from({length:r+1},(t,e)=>Number((s+e*c).toFixed(12))),h=l[0],m=l[r]-h||1;return{min:h,max:l[r],ticks:l,fraction:t=>(t-h)/m}}function u(t,e){const{includeZero:n=!0}=e;let r=e.min??(t?t.min:0),o=e.max??(t?t.max:1);n&&void 0===e.min&&(r=Math.min(r,0)),n&&void 0===e.max&&(o=Math.max(o,0));const a=void 0!==e.min&&void 0===e.max,i=void 0!==e.max&&void 0===e.min;if(o<=r&&(a||i)){const t=a?r:o,e=Math.abs(t)>0?Math.abs(t):2;a?o=r+e:r=o-e}else if(o===r){const t=Math.abs(o)>0?.5*Math.abs(o):1;r-=t,o+=t}return{low:r,high:o}}const s=1e3,c=6e4,l=36e5,h=24*l,m=[{unit:"second",count:1,size:s},{unit:"second",count:5,size:5e3},{unit:"second",count:15,size:15e3},{unit:"second",count:30,size:3e4},{unit:"minute",count:1,size:c},{unit:"minute",count:5,size:3e5},{unit:"minute",count:15,size:9e5},{unit:"minute",count:30,size:18e5},{unit:"hour",count:1,size:l},{unit:"hour",count:3,size:3*l},{unit:"hour",count:6,size:6*l},{unit:"hour",count:12,size:12*l},{unit:"day",count:1,size:h},{unit:"day",count:2,size:2*h},{unit:"week",count:1,size:7*h},{unit:"week",count:2,size:14*h},{unit:"month",count:1,size:30*h},{unit:"quarter",count:1,size:91*h},{unit:"month",count:6,size:182*h},{unit:"year",count:1,size:365*h}];function f(t,e,n){const r=new Date(t);if("year"===e)r.setFullYear(r.getFullYear()+n);else if("quarter"===e)r.setMonth(r.getMonth()+3*n);else if("month"===e)r.setMonth(r.getMonth()+n);else if("week"===e)r.setDate(r.getDate()+7*n);else if("day"===e)r.setDate(r.getDate()+n);else{if("hour"!==e)return t+n*("minute"===e?c:s);r.setHours(r.getHours()+n)}return r.getTime()}const $={second:"minute",minute:"hour",hour:"day",day:"month",week:"week",month:"year",quarter:"year",year:"year"};function x(t,e,n){let r=function(t,e){const n=new Date(t);if("year"===e)return new Date(n.getFullYear(),0,1).getTime();if("quarter"===e)return new Date(n.getFullYear(),3*Math.floor(n.getMonth()/3),1).getTime();if("month"===e)return new Date(n.getFullYear(),n.getMonth(),1).getTime();if("week"===e){const t=new Date(n.getFullYear(),n.getMonth(),n.getDate());return t.setDate(t.getDate()-t.getDay()),t.getTime()}return"day"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime():"hour"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()).getTime():"minute"===e?Math.floor(t/c)*c:Math.floor(t/s)*s}(t,$[e]);if("year"===e&&n>1){const t=new Date(r).getFullYear();r=new Date(t-(t%n+n)%n,0,1).getTime()}for(let o=0;o<500;o++){const o=f(r,e,n);if(o>t)return r;r=o}return r}export function timeScale(t,e={}){const{tickCount:n=6}=e;let r=e.min??t?.min??Date.parse("2000-01-01T00:00:00"),o=e.max??t?.max??r+h;o<=r&&(r-=h/2,o+=h/2);const a=o-r;let u=m[0],s=1/0;for(const t of m){const e=Math.abs(a/t.size-n);e<s&&(s=e,u=t)}const c=u.unit,l="year"===c?Math.max(1,Math.round(i(a/n/(365*h)))):u.count,$=e.min??x(r,c,l),M=[];let p=x(r,c,l);for(let t=0;t<500&&(M.push(p),!(p>o));t++)p=f(p,c,l);const d=e.max??M[M.length-1],g=d-$||1;return{min:$,max:d,ticks:M.filter(t=>t>=$&&t<=d),unit:c,step:l,fraction:t=>(t-$)/g}}function M(t,e){if("second"===t)return{hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"};if("minute"===t||"hour"===t)return{hour:"2-digit",minute:"2-digit",hourCycle:"h23"};if("year"===t)return{year:"numeric"};const n="month"===t||"quarter"===t?{month:"short"}:{month:"short",day:"numeric"};return e?{...n,year:"numeric"}:n}export function formatTimeValue(t,e,r,o=!1){const a=M(e,!0);return n(r,o&&void 0===a.hour?{...a,hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:a).format(new Date(t))}export function formatTimeTicks(t,e,r){const o=new Set(t.map(t=>new Date(t).getFullYear())).size>1;return t.map((t,a)=>n(r,M(e,o||0===a)).format(new Date(t)))}export function tickStride(t,e,n){if(t<=1||e<=0)return 1;const r=Math.max(1,Math.floor(e/Math.max(1,n)));return Math.max(1,Math.ceil(t/r))}export function showsTick(t,e,n,r){return t%n===0||r&&t===e-1}export function fitsLast(t,e,n,r){const o=(t-1)%e;return o>0&&o*n>=r+8}export function textWidth(t,e){let n=0;for(const e of t)n+=/[ᄀ-ᇿ⺀-가-豈-︰-﹏]/.test(e)?1:.6;return n*e}export function turnedAxis(t,e){const n=Math.max(-90,Math.min(90,t??0)),r=Math.abs(n)*(Math.PI/180),o=Math.sin(r),a=Math.cos(r);return 0===n?{angle:0,depth:()=>e,room:t=>Math.max(t,1)+12,cut:t=>t,offset:e+6,overhang:t=>t/2,anchor:"middle"}:{angle:n,depth:t=>t*o+e*a,room:()=>e/Math.max(.2,o)+4,cut:t=>Math.max(0,(t-e*a)/Math.max(.05,o)),offset:8+e/2*a,overhang:t=>t*a,anchor:n<0?"end":"start"}}export function truncate(t,e,n){if(e<=0||textWidth(t,n)<=e)return t;const r=e-textWidth("…",n);let o="",a=0;for(const e of t){const t=a+textWidth(e,n);if(t>r)break;a=t,o+=e}return o.length>0?`${o.trimEnd()}…`:"…"}export function bandScale(t,e,n){const r=t>0?e/t:e;return{step:r,band:r*n,centre:t=>r*(t+.5)}}export function linePath(t,e){const n=[];let r=[];const o=()=>{if(0!==r.length){if(1===r.length)n.push(`M${r[0].x} ${r[0].y}h0`);else if("step"===e){n.push(`M${r[0].x} ${r[0].y}`);for(let t=1;t<r.length;t++){const e=(r[t-1].x+r[t].x)/2;n.push(`H${e}V${r[t].y}H${r[t].x}`)}}else if("smooth"===e)n.push(`M${r[0].x} ${r[0].y}`),n.push(function(t){const e=t.length,n=[];for(let r=0;r<e-1;r++){const e=t[r+1].x-t[r].x;n.push(0===e?0:(t[r+1].y-t[r].y)/e)}const r=[n[0]??0];for(let t=1;t<e-1;t++){const e=n[t-1],o=n[t];r.push(e*o<=0?0:2*e*o/(e+o))}r.push(n[e-2]??0);const o=[];for(let n=0;n<e-1;n++){const e=(t[n+1].x-t[n].x)/3;o.push(`C${t[n].x+e} ${t[n].y+r[n]*e} ${t[n+1].x-e} ${t[n+1].y-r[n+1]*e} ${t[n+1].x} ${t[n+1].y}`)}return o.join("")}(r));else{n.push(`M${r[0].x} ${r[0].y}`);for(let t=1;t<r.length;t++)n.push(`L${r[t].x} ${r[t].y}`)}r=[]}};for(const e of t)null===e?o():r.push(e);return o(),n.join("")}export function areaPath(t,e,n){const r=[];let o=0;const a=a=>{const i=t.slice(o,a).filter(Boolean);if(0===i.length)return;const u="number"==typeof e?i.map(t=>({x:t.x,y:e})).reverse():e.slice(o,a).filter(Boolean).reverse();if(0===u.length)return;const s=linePath(i,n),c=linePath(u,n).replace(/^M/,"L");r.push(`${s}${c}Z`)};for(let e=0;e<t.length;e++)null===t[e]&&(a(e),o=e+1);return a(t.length),r.join("")}export function barPath(t,e,n,r,o,a){const i=Math.max(0,Math.min(o,n/2,r/2));if(0===i||n<=0||r<=0)return`M${t} ${e}h${n}v${r}h${-n}Z`;const u=(t,e)=>`a${i} ${i} 0 0 1 ${t} ${e}`;return"up"===a?`M${t} ${e+r}V${e+i}${u(i,-i)}H${t+n-i}${u(i,i)}V${e+r}Z`:"down"===a?`M${t} ${e}H${t+n}V${e+r-i}${u(-i,i)}H${t+i}${u(-i,-i)}Z`:"right"===a?`M${t} ${e}H${t+n-i}${u(i,i)}V${e+r-i}${u(-i,i)}H${t}Z`:`M${t+n} ${e+r}H${t+i}${u(-i,-i)}V${e+i}${u(i,-i)}H${t+n}Z`}export const markShapes=["circle","square","triangle","diamond","cross"];const p={circle:1,square:.8862,triangle:1.5551,diamond:1.2533,cross:1.189};export function markPath(t,e,n,r){const o=Math.max(0,r)*p[t];if(0===o)return"";if("circle"===t)return`M${e-o} ${n}a${o} ${o} 0 1 0 ${2*o} 0a${o} ${o} 0 1 0 ${2*-o} 0Z`;if("square"===t)return`M${e-o} ${n-o}h${2*o}v${2*o}h${2*-o}Z`;if("diamond"===t)return`M${e} ${n-o}L${e+o} ${n}L${e} ${n+o}L${e-o} ${n}Z`;if("triangle"===t){return`M${[0,120,240].map(t=>{const r=(t-90)*Math.PI/180;return`${e+o*Math.cos(r)} ${n+o*Math.sin(r)}`}).join("L")}Z`}const a=o/3;return`M${e-a} ${n-o}h${2*a}v${o-a}h${o-a}v${2*a}h${-(o-a)}v${o-a}h${2*-a}v${-(o-a)}h${-(o-a)}v${2*-a}h${o-a}Z`}export function ringPath(t,e,n,r,o){const a=r=>{const o=(r-90)*Math.PI/180;return`${t+n*Math.cos(o)} ${e+n*Math.sin(o)}`};if(Math.abs(o-r)>=360){const t=r+180;return`M${a(r)}A${n} ${n} 0 1 1 ${a(t)}A${n} ${n} 0 1 1 ${a(r)}`}const i=Math.abs(o-r)>180?1:0;return`M${a(r)}A${n} ${n} 0 ${i} 1 ${a(o)}`}export function arcPath(t,e,n,r,o,a){const i=(n,r)=>{const o=(r-90)*Math.PI/180;return`${t+n*Math.cos(o)} ${e+n*Math.sin(o)}`};if(Math.abs(a-o)>=360){const t=o+180;return r>0?`M${i(n,o)}A${n} ${n} 0 1 1 ${i(n,t)}A${n} ${n} 0 1 1 ${i(n,o)}ZM${i(r,o)}A${r} ${r} 0 1 0 ${i(r,t)}A${r} ${r} 0 1 0 ${i(r,o)}Z`:`M${i(n,o)}A${n} ${n} 0 1 1 ${i(n,t)}A${n} ${n} 0 1 1 ${i(n,o)}Z`}const u=Math.abs(a-o)>180?1:0;return r<=0?`M${t} ${e}L${i(n,o)}A${n} ${n} 0 ${u} 1 ${i(n,a)}Z`:`M${i(n,o)}A${n} ${n} 0 ${u} 1 ${i(n,a)}L${i(r,a)}A${r} ${r} 0 ${u} 0 ${i(r,o)}Z`}export const rampSteps=5;export function rampStep(t,e,n,r,o=0){if("diverging"===r){const r=Math.max(Math.abs(n-o),Math.abs(o-e));if(!(r>0))return 2;const a=(t-o)/r;return Math.min(4,Math.max(0,2+Math.round(2*a)))}const a=n-e;return a>0?Math.min(4,Math.max(0,Math.floor((t-e)/a*5))):t>0?4:0}export function rampFill(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-${t+1})`}export function rampInk(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-on-${t+1})`}export function squarify(t,e,n){const r=t.reduce((t,e)=>t+Math.max(0,e),0);if(!(r>0)||e<=0||n<=0)return[];const o=e*n/r,a=t.map((t,e)=>({index:e,area:Math.max(0,t)*o})).filter(t=>t.area>0).sort((t,e)=>e.area-t.area),i=[];let u=0,s=0,c=e,l=n,h=[];const m=t=>{const e=Math.min(c,l),n=t.reduce((t,e)=>t+e.area,0);if(!(n>0&&e>0))return 1/0;const r=t[0].area,o=t[t.length-1].area;return Math.max(e*e*r/(n*n),n*n/(e*e*o))},f=()=>{const t=h.reduce((t,e)=>t+e.area,0),e=Math.min(c,l),n=e>0?t/e:0,r=c>=l;let o=0;for(const t of h){const e=n>0?t.area/n:0;i.push(r?{index:t.index,x:u,y:s+o,width:n,height:e}:{index:t.index,x:u+o,y:s,width:e,height:n}),o+=e}r?(u+=n,c-=n):(s+=n,l-=n),h=[]};for(const t of a)0===h.length||m([...h,t])<=m(h)||f(),h.push(t);return h.length>0&&f(),i}const d={month:"short",day:"numeric"},g={notation:"compact",maximumFractionDigits:1},v={maximumFractionDigits:2};export function labelledPoints(t,e){if("all"===e)return()=>!0;if("last"===e){let e=-1;for(let n=t.length-1;n>=0;n--)if(null!==t[n].value){e=n;break}return t=>t===e}let n=1/0,r=-1/0;for(const e of t)null!==e.value&&(n=Math.min(n,e.value),r=Math.max(r,e.value));return e=>{const o=t[e].value;return null!==o&&(o===n||o===r)}}export function formatCategory(t,e){return t instanceof Date?n(e,d).format(t):String(t)}export function compactNumber(t,e){return Math.abs(t)>=1e4?r(e,g).format(t):r(e,v).format(t)}
|
|
1
|
+
import{parseColor as t,readableInk as e}from"./color.js";import{dateFormatter as n,numberFormatter as r}from"./format.js";export const plotHeights={xs:120,sm:160,md:220,lg:280,xl:360};export const sparklineHeights={xs:16,sm:20,md:28,lg:40,xl:56};export const lineWidths={xs:1.5,sm:1.75,md:2,lg:2.25,xl:2.5};export const markerRadii={xs:3,sm:3.5,md:4,lg:4.5,xl:5};export const chartFontSizes={xs:10,sm:11,md:12,lg:13,xl:14};export const barMaxThickness={xs:14,sm:18,md:24,lg:30,xl:36};export const barBandRatio={default:.62,compact:.82};export const markGap=2;export const barRadius=4;export const chartPalette=["var(--neba-chart-1)","var(--neba-chart-2)","var(--neba-chart-3)","var(--neba-chart-4)","var(--neba-chart-5)","var(--neba-chart-6)","var(--neba-chart-7)","var(--neba-chart-8)"];export function inkOn(n,r){if(!n)return`var(--neba-chart-on-${r%chartPalette.length+1})`;const a=o.has(n)?null:t(n);return a?e(a.hsv):"var(--neba-surface)"}export function labelInk(t){return`color-mix(in oklab, ${t} 85%, var(--neba-fg))`}const o=new Set(["primary","secondary","success","warning","danger","info"]);export function resolveColor(t){return o.has(t)?`var(--neba-${t}-accent)`:t}export function seriesColor(t,e,n=chartPalette){return resolveColor(t?.color?t.color:n[e%n.length]??chartPalette[0])}const a=new Set;export function warnPaletteOverflow(t){"production"===process.env.NODE_ENV||t<=chartPalette.length||a.has(t)||(a.add(t),console.warn(`Neba: a chart was given ${t} series and its palette has ${chartPalette.length} colours, so the colours repeat from the ninth series. Fold the smallest into an "Other" series, or draw a second chart.`))}export function toFullShares(t,e,n){const r=[];return t.forEach((t,n)=>{!1!==e[n]&&t.forEach((t,e)=>{r[e]=(r[e]??0)+Math.abs(t.value??0)})}),t.map(t=>t.map((t,e)=>{if(null===t.value)return t;const o=r[e]??0;return{...t,value:0===o?0:t.value/o*100,label:t.label??n(t.value)}}))}export function toValue(t){return null==t?{value:null}:"number"==typeof t?{value:Number.isFinite(t)?t:null}:(t=>"object"==typeof t&&null!==t)(t)?{value:null!==t.y&&Number.isFinite(t.y)?t.y:null,x:t.x,z:t.z,color:t.color?resolveColor(t.color):void 0,label:t.label}:{value:null}}export function toValues(t){return t.map(t=>t.data.map(toValue))}export function zeroGaps(t){return t.map(t=>({...t,data:t.data.map(t=>null==t?0:"number"==typeof t?Number.isFinite(t)?t:0:null!==t.y&&Number.isFinite(t.y)?t:{...t,y:0})}))}export function toNumber(t){return t instanceof Date?Number.isFinite(t.getTime())?t.getTime():null:"number"==typeof t&&Number.isFinite(t)?t:null}export function pointX(t,e,n){return toNumber(t.x??n?.[e]??e)}export function categoryExtent(t,e){let n=1/0,r=-1/0,o=!1;return t.forEach(t=>{t.forEach((t,a)=>{if(null===t.value)return;const i=pointX(t,a,e);null!==i&&(o=!0,n=Math.min(n,i),r=Math.max(r,i))})}),o?{min:n,max:r}:null}export function bubbleRadius(t,e,n,r){return e>0&&Number.isFinite(t)&&!(t<=0)?Math.max(r,Math.sqrt(Math.min(t,e)/e)*n):0===t?0:r}export function categoryCount(t){return t.reduce((t,e)=>Math.max(t,e.data.length),0)}export function categoryAt(t,e,n){if(e&&t<e.length)return e[t];for(const e of n){const n=e[t]?.x;if(void 0!==n)return n}return t}export function extentOf(t,e){let n=1/0,r=-1/0,o=!1;if(e){const e=t.reduce((t,e)=>Math.max(t,e.length),0);for(let a=0;a<e;a++){let e=0,i=0;for(const n of t){const t=n[a]?.value;null!=t&&(o=!0,t>=0?e+=t:i+=t)}n=Math.min(n,i),r=Math.max(r,e)}}else for(const e of t)for(const{value:t}of e)null!==t&&(o=!0,n=Math.min(n,t),r=Math.max(r,t));return o?{min:n,max:r}:null}function i(t){const e=10**Math.floor(Math.log10(t)),n=t/e;return n<=1?e:n<=2?2*e:n<=5?5*e:10*e}export function valueScale(t,e={}){const{tickCount:n=5}=e,{low:r,high:o}=u(t,e),a=void 0!==e.min&&void 0!==e.max?function(t,e){const n=10**Math.floor(Math.log10(t/Math.max(1,e)));let r=i(t/Math.max(1,e)),o=1/0;for(const a of[.1,1,10])for(const i of[1,2,2.5,5]){const u=i*a*n,s=t/u,c=Math.round(s);if(c<1||Math.abs(s-c)>1e-9)continue;const l=Math.abs(c-e);l<o&&(o=l,r=u)}return r}(o-r,n):i((o-r)/Math.max(1,n)),s=void 0!==e.min?r:Number((Math.floor(r/a+1e-9)*a).toFixed(12)),c=void 0!==e.max?o:Number((Math.ceil(o/a-1e-9)*a).toFixed(12)),l=c-s||1,h=[];for(let t=s;t<=c+1e-9*a;t+=a)h.push(Number(t.toFixed(12)));return{min:s,max:c,ticks:h,fraction:t=>(t-s)/l}}export function alignedScale(t,e,n={}){const r=Math.max(1,Math.round(e)),{low:o,high:a}=u(t,n);let s,c=i((a-o)/r);if(void 0!==n.min&&void 0!==n.max)c=(a-o)/r,s=o;else if(void 0!==n.max)s=a-r*c;else if(void 0!==n.min)s=o;else for(s=Math.floor(o/c+1e-9)*c;s+r*c<a-1e-9*c;)c=i(1.000001*c),s=Math.floor(o/c+1e-9)*c;const l=Array.from({length:r+1},(t,e)=>Number((s+e*c).toFixed(12))),h=l[0],m=l[r]-h||1;return{min:h,max:l[r],ticks:l,fraction:t=>(t-h)/m}}function u(t,e){const{includeZero:n=!0}=e;let r=e.min??(t?t.min:0),o=e.max??(t?t.max:1);n&&void 0===e.min&&(r=Math.min(r,0)),n&&void 0===e.max&&(o=Math.max(o,0));const a=void 0!==e.min&&void 0===e.max,i=void 0!==e.max&&void 0===e.min;if(o<=r&&(a||i)){const t=a?r:o,e=Math.abs(t)>0?Math.abs(t):2;a?o=r+e:r=o-e}else if(o===r){const t=Math.abs(o)>0?.5*Math.abs(o):1;r-=t,o+=t}return{low:r,high:o}}const s=1e3,c=6e4,l=36e5,h=24*l,m=[{unit:"second",count:1,size:s},{unit:"second",count:5,size:5e3},{unit:"second",count:15,size:15e3},{unit:"second",count:30,size:3e4},{unit:"minute",count:1,size:c},{unit:"minute",count:5,size:3e5},{unit:"minute",count:15,size:9e5},{unit:"minute",count:30,size:18e5},{unit:"hour",count:1,size:l},{unit:"hour",count:3,size:3*l},{unit:"hour",count:6,size:6*l},{unit:"hour",count:12,size:12*l},{unit:"day",count:1,size:h},{unit:"day",count:2,size:2*h},{unit:"week",count:1,size:7*h},{unit:"week",count:2,size:14*h},{unit:"month",count:1,size:30*h},{unit:"quarter",count:1,size:91*h},{unit:"month",count:6,size:182*h},{unit:"year",count:1,size:365*h}];function f(t,e,n){const r=new Date(t);if("year"===e)r.setFullYear(r.getFullYear()+n);else if("quarter"===e)r.setMonth(r.getMonth()+3*n);else if("month"===e)r.setMonth(r.getMonth()+n);else if("week"===e)r.setDate(r.getDate()+7*n);else if("day"===e)r.setDate(r.getDate()+n);else{if("hour"!==e)return t+n*("minute"===e?c:s);r.setHours(r.getHours()+n)}return r.getTime()}const $={second:"minute",minute:"hour",hour:"day",day:"month",week:"week",month:"year",quarter:"year",year:"year"};function x(t,e,n){let r=function(t,e){const n=new Date(t);if("year"===e)return new Date(n.getFullYear(),0,1).getTime();if("quarter"===e)return new Date(n.getFullYear(),3*Math.floor(n.getMonth()/3),1).getTime();if("month"===e)return new Date(n.getFullYear(),n.getMonth(),1).getTime();if("week"===e){const t=new Date(n.getFullYear(),n.getMonth(),n.getDate());return t.setDate(t.getDate()-t.getDay()),t.getTime()}return"day"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime():"hour"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()).getTime():"minute"===e?Math.floor(t/c)*c:Math.floor(t/s)*s}(t,$[e]);if("year"===e&&n>1){const t=new Date(r).getFullYear();r=new Date(t-(t%n+n)%n,0,1).getTime()}for(let o=0;o<500;o++){const o=f(r,e,n);if(o>t)return r;r=o}return r}export function timeScale(t,e={}){const{tickCount:n=6}=e;let r=e.min??t?.min??Date.parse("2000-01-01T00:00:00"),o=e.max??t?.max??r+h;o<=r&&(r-=h/2,o+=h/2);const a=o-r;let u=m[0],s=1/0;for(const t of m){const e=Math.abs(a/t.size-n);e<s&&(s=e,u=t)}const c=u.unit,l="year"===c?Math.max(1,Math.round(i(a/n/(365*h)))):u.count,$=e.min??x(r,c,l),M=[];let p=x(r,c,l);for(let t=0;t<500&&(M.push(p),!(p>o));t++)p=f(p,c,l);const d=e.max??M[M.length-1],g=d-$||1;return{min:$,max:d,ticks:M.filter(t=>t>=$&&t<=d),unit:c,step:l,fraction:t=>(t-$)/g}}function M(t,e){if("second"===t)return{hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"};if("minute"===t||"hour"===t)return{hour:"2-digit",minute:"2-digit",hourCycle:"h23"};if("year"===t)return{year:"numeric"};const n="month"===t||"quarter"===t?{month:"short"}:{month:"short",day:"numeric"};return e?{...n,year:"numeric"}:n}export function formatTimeValue(t,e,r,o=!1){const a=M(e,!0);return n(r,o&&void 0===a.hour?{...a,hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:a).format(new Date(t))}export function formatTimeTicks(t,e,r){const o=new Set(t.map(t=>new Date(t).getFullYear())).size>1;return t.map((t,a)=>n(r,M(e,o||0===a)).format(new Date(t)))}export function tickStride(t,e,n){if(t<=1||e<=0)return 1;const r=Math.max(1,Math.floor(e/Math.max(1,n)));return Math.max(1,Math.ceil(t/r))}export function showsTick(t,e,n,r){return t%n===0||r&&t===e-1}export function fitsLast(t,e,n,r){const o=(t-1)%e;return o>0&&o*n>=r+8}export function textWidth(t,e){let n=0;for(const e of t)n+=/[ᄀ-ᇿ⺀-가-豈-︰-﹏]/.test(e)?1:.6;return n*e}export function turnedAxis(t,e){const n=Math.max(-90,Math.min(90,t??0)),r=Math.abs(n)*(Math.PI/180),o=Math.sin(r),a=Math.cos(r);return 0===n?{angle:0,depth:()=>e,room:t=>Math.max(t,1)+12,cut:t=>t,offset:e+6,overhang:t=>t/2,anchor:"middle"}:{angle:n,depth:t=>t*o+e*a,room:()=>e/Math.max(.2,o)+4,cut:t=>Math.max(0,(t-e*a)/Math.max(.05,o)),offset:8+e/2*a,overhang:t=>t*a,anchor:n<0?"end":"start"}}export function truncate(t,e,n){if(e<=0||textWidth(t,n)<=e)return t;const r=e-textWidth("…",n);let o="",a=0;for(const e of t){const t=a+textWidth(e,n);if(t>r)break;a=t,o+=e}return o.length>0?`${o.trimEnd()}…`:"…"}export function bandScale(t,e,n){const r=t>0?e/t:e;return{step:r,band:r*n,centre:t=>r*(t+.5)}}function p(t){return Math.round(100*t)/100}export function linePath(t,e){const n=[];let r=[];const o=()=>{if(0!==r.length){if(1===r.length)n.push(`M${p(r[0].x)} ${p(r[0].y)}h0`);else if("step"===e){n.push(`M${p(r[0].x)} ${p(r[0].y)}`);for(let t=1;t<r.length;t++){const e=(r[t-1].x+r[t].x)/2;n.push(`H${p(e)}V${p(r[t].y)}H${p(r[t].x)}`)}}else if("smooth"===e)n.push(`M${p(r[0].x)} ${p(r[0].y)}`),n.push(function(t){const e=t.length,n=[];for(let r=0;r<e-1;r++){const e=t[r+1].x-t[r].x;n.push(0===e?0:(t[r+1].y-t[r].y)/e)}const r=[n[0]??0];for(let t=1;t<e-1;t++){const e=n[t-1],o=n[t];r.push(e*o<=0?0:2*e*o/(e+o))}r.push(n[e-2]??0);const o=[];for(let n=0;n<e-1;n++){const e=(t[n+1].x-t[n].x)/3;o.push(`C${p(t[n].x+e)} ${p(t[n].y+r[n]*e)} ${p(t[n+1].x-e)} ${p(t[n+1].y-r[n+1]*e)} ${p(t[n+1].x)} ${p(t[n+1].y)}`)}return o.join("")}(r));else{n.push(`M${p(r[0].x)} ${p(r[0].y)}`);for(let t=1;t<r.length;t++)n.push(`L${p(r[t].x)} ${p(r[t].y)}`)}r=[]}};for(const e of t)null===e?o():r.push(e);return o(),n.join("")}export function areaPath(t,e,n){const r=[];let o=0;const a=a=>{const i=t.slice(o,a).filter(Boolean);if(0===i.length)return;const u="number"==typeof e?i.map(t=>({x:t.x,y:e})).reverse():e.slice(o,a).filter(Boolean).reverse();if(0===u.length)return;const s=linePath(i,n),c=linePath(u,n).replace(/^M/,"L");r.push(`${s}${c}Z`)};for(let e=0;e<t.length;e++)null===t[e]&&(a(e),o=e+1);return a(t.length),r.join("")}export function barPath(t,e,n,r,o,a){const i=p(Math.max(0,Math.min(o,n/2,r/2)));if(0===i||n<=0||r<=0)return`M${p(t)} ${p(e)}h${p(n)}v${p(r)}h${p(-n)}Z`;const u=(t,e)=>`a${i} ${i} 0 0 1 ${t} ${e}`,s=p(t),c=p(e),l=p(t+n),h=p(e+r);return"up"===a?`M${s} ${h}V${p(e+i)}${u(i,-i)}H${p(t+n-i)}${u(i,i)}V${h}Z`:"down"===a?`M${s} ${c}H${l}V${p(e+r-i)}${u(-i,i)}H${p(t+i)}${u(-i,-i)}Z`:"right"===a?`M${s} ${c}H${p(t+n-i)}${u(i,i)}V${p(e+r-i)}${u(-i,i)}H${s}Z`:`M${l} ${h}H${p(t+i)}${u(-i,-i)}V${p(e+i)}${u(i,-i)}H${l}Z`}export const markShapes=["circle","square","triangle","diamond","cross"];const d={circle:1,square:.8862,triangle:1.5551,diamond:1.2533,cross:1.189};export function markPath(t,e,n,r){const o=p(Math.max(0,r)*d[t]);if(0===o)return"";const a=p(e),i=p(n);if("circle"===t)return`M${p(e-o)} ${i}a${o} ${o} 0 1 0 ${p(2*o)} 0a${o} ${o} 0 1 0 ${p(2*-o)} 0Z`;if("square"===t)return`M${p(e-o)} ${p(n-o)}h${p(2*o)}v${p(2*o)}h${p(2*-o)}Z`;if("diamond"===t)return`M${a} ${p(n-o)}L${p(e+o)} ${i}L${a} ${p(n+o)}L${p(e-o)} ${i}Z`;if("triangle"===t){return`M${[0,120,240].map(t=>{const r=(t-90)*Math.PI/180;return`${p(e+o*Math.cos(r))} ${p(n+o*Math.sin(r))}`}).join("L")}Z`}const u=p(o/3),s=p(o-u),c=p(2*u);return`M${p(e-u)} ${p(n-o)}h${c}v${s}h${s}v${c}h${-s}v${s}h${-c}v${-s}h${-s}v${-c}h${s}Z`}export function markOrigin(t){return"triangle"===t?"50% 66.6667%":void 0}export function ringPath(t,e,n,r,o){const a=r=>{const o=(r-90)*Math.PI/180;return`${p(t+n*Math.cos(o))} ${p(e+n*Math.sin(o))}`},i=p(n);if(Math.abs(o-r)>=360){const t=r+180;return`M${a(r)}A${i} ${i} 0 1 1 ${a(t)}A${i} ${i} 0 1 1 ${a(r)}`}const u=Math.abs(o-r)>180?1:0;return`M${a(r)}A${i} ${i} 0 ${u} 1 ${a(o)}`}export function arcPath(t,e,n,r,o,a){const i=(n,r)=>{const o=(r-90)*Math.PI/180;return`${p(t+n*Math.cos(o))} ${p(e+n*Math.sin(o))}`},u=p(n),s=p(r);if(Math.abs(a-o)>=360){const t=o+180;return r>0?`M${i(n,o)}A${u} ${u} 0 1 1 ${i(n,t)}A${u} ${u} 0 1 1 ${i(n,o)}ZM${i(r,o)}A${s} ${s} 0 1 0 ${i(r,t)}A${s} ${s} 0 1 0 ${i(r,o)}Z`:`M${i(n,o)}A${u} ${u} 0 1 1 ${i(n,t)}A${u} ${u} 0 1 1 ${i(n,o)}Z`}const c=Math.abs(a-o)>180?1:0;return r<=0?`M${p(t)} ${p(e)}L${i(n,o)}A${u} ${u} 0 ${c} 1 ${i(n,a)}Z`:`M${i(n,o)}A${u} ${u} 0 ${c} 1 ${i(n,a)}L${i(r,a)}A${s} ${s} 0 ${c} 0 ${i(r,o)}Z`}export const rampSteps=5;export function rampStep(t,e,n,r,o=0){if("diverging"===r){const r=Math.max(Math.abs(n-o),Math.abs(o-e));if(!(r>0))return 2;const a=(t-o)/r;return Math.min(4,Math.max(0,2+Math.round(2*a)))}const a=n-e;return a>0?Math.min(4,Math.max(0,Math.floor((t-e)/a*5))):t>0?4:0}export function rampFill(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-${t+1})`}export function rampInk(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-on-${t+1})`}export function squarify(t,e,n){const r=t.reduce((t,e)=>t+Math.max(0,e),0);if(!(r>0)||e<=0||n<=0)return[];const o=e*n/r,a=t.map((t,e)=>({index:e,area:Math.max(0,t)*o})).filter(t=>t.area>0).sort((t,e)=>e.area-t.area),i=[];let u=0,s=0,c=e,l=n,h=[];const m=t=>{const e=Math.min(c,l),n=t.reduce((t,e)=>t+e.area,0);if(!(n>0&&e>0))return 1/0;const r=t[0].area,o=t[t.length-1].area;return Math.max(e*e*r/(n*n),n*n/(e*e*o))},f=()=>{const t=h.reduce((t,e)=>t+e.area,0),e=Math.min(c,l),n=e>0?t/e:0,r=c>=l;let o=0;for(const t of h){const e=n>0?t.area/n:0;i.push(r?{index:t.index,x:u,y:s+o,width:n,height:e}:{index:t.index,x:u+o,y:s,width:e,height:n}),o+=e}r?(u+=n,c-=n):(s+=n,l-=n),h=[]};for(const t of a)0===h.length||m([...h,t])<=m(h)||f(),h.push(t);return h.length>0&&f(),i}const g={month:"short",day:"numeric"},v={notation:"compact",maximumFractionDigits:1},b={maximumFractionDigits:2};export function labelledPoints(t,e){if("all"===e)return()=>!0;if("last"===e){let e=-1;for(let n=t.length-1;n>=0;n--)if(null!==t[n].value){e=n;break}return t=>t===e}let n=1/0,r=-1/0;for(const e of t)null!==e.value&&(n=Math.min(n,e.value),r=Math.max(r,e.value));return e=>{const o=t[e].value;return null!==o&&(o===n||o===r)}}export function formatCategory(t,e){return t instanceof Date?n(e,g).format(t):String(t)}export function compactNumber(t,e){return Math.abs(t)>=1e4?r(e,v).format(t):r(e,b).format(t)}
|
|
@@ -170,5 +170,11 @@ export declare function virtualWindow(scrollTop: number, viewport: number, rowHe
|
|
|
170
170
|
* A key that is no longer in the list (a row the current filter hides) yields
|
|
171
171
|
* an empty range rather than a range from one end, which is what an index of
|
|
172
172
|
* `-1` would silently produce.
|
|
173
|
+
*
|
|
174
|
+
* `positions` is where each key sits in `order`, for a caller that already
|
|
175
|
+
* holds it. A drag asks this once for every row it reaches, and finding the two
|
|
176
|
+
* ends by walking the list was two passes over every key in the table per row:
|
|
177
|
+
* on a hundred thousand rows, most of the frame went on finding where the run
|
|
178
|
+
* starts rather than on the run.
|
|
173
179
|
*/
|
|
174
|
-
export declare function keysBetween(order: readonly string[], from: string, to: string): string[];
|
|
180
|
+
export declare function keysBetween(order: readonly string[], from: string, to: string, positions?: ReadonlyMap<string, number>): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const dataRowHeights={default:{xs:24,sm:28,md:32,lg:38,xl:44},compact:{xs:20,sm:24,md:28,lg:32,xl:38}};export const dataHeaderHeights={default:{xs:28,sm:32,md:36,lg:42,xl:48},compact:{xs:24,sm:28,md:32,lg:36,xl:42}};export const dataTickWidths={xs:30,sm:34,md:38,lg:42,xl:50};export const defaultColumnWidth=160;export const minColumnWidth=48;export function compareValues(t,e,n){const o=isEmptyValue(t),r=isEmptyValue(e);return o||r?o&&r?0:o?1:-1:"number"==typeof t&&"number"==typeof e?t-e:"boolean"==typeof t&&"boolean"==typeof e?Number(t)-Number(e):t instanceof Date&&e instanceof Date?t.getTime()-e.getTime():n.compare(String(t),String(e))}export function isEmptyValue(t){return null==t||""===t||"number"==typeof t&&Number.isNaN(t)}export function sortRows(t,e,n){if(0===e.length)return t;const o=e.map(t=>{const e=n(t.key);if(!e)return null;const o="desc"===t.direction?-1:1;return"function"==typeof e?{compare:e,isEmpty:null,sign:o}:{compare:e.compare,isEmpty:e.isEmpty,sign:o}}).filter(t=>null!==t);return 0===o.length?t:[...t].sort((t,e)=>{for(const n of o){if(n.isEmpty){const o=n.isEmpty(t);if(o!==n.isEmpty(e))return o?1:-1;if(o)continue}const o=n.compare(t,e);if(0!==o)return o*n.sign}return 0})}export function nextSort(t,e,n){const o=t.find(t=>t.key===e),r=void 0===o?"asc":"asc"===o.direction?"desc":null;return n?null===r?t.filter(t=>t.key!==e):void 0===o?[...t,{key:e,direction:r}]:t.map(t=>t.key===e?{key:e,direction:r}:t):null===r?[]:[{key:e,direction:r}]}export function pageBounds(t,e,n){const o=Math.max(1,Math.floor(n)),r=Math.max(1,Math.ceil(t/o)),i=Math.min(Math.max(Math.floor(e),1),r),a=(i-1)*o;return{pages:r,page:i,start:a,end:Math.min(a+o,t)}}export function virtualWindow(t,e,n,o,r){const i=e>0?Math.ceil(e/n):3*r,a=Math.min(Math.floor(t/n),Math.max(0,o-i)),s=Math.max(0,a-r),m=Math.min(o,s+i+2*r);return{start:s,end:m,before:s*n,after:Math.max(0,(o-m)*n)}}export function keysBetween(t,e,n){const o
|
|
1
|
+
export const dataRowHeights={default:{xs:24,sm:28,md:32,lg:38,xl:44},compact:{xs:20,sm:24,md:28,lg:32,xl:38}};export const dataHeaderHeights={default:{xs:28,sm:32,md:36,lg:42,xl:48},compact:{xs:24,sm:28,md:32,lg:36,xl:42}};export const dataTickWidths={xs:30,sm:34,md:38,lg:42,xl:50};export const defaultColumnWidth=160;export const minColumnWidth=48;export function compareValues(t,e,n){const o=isEmptyValue(t),r=isEmptyValue(e);return o||r?o&&r?0:o?1:-1:"number"==typeof t&&"number"==typeof e?t-e:"boolean"==typeof t&&"boolean"==typeof e?Number(t)-Number(e):t instanceof Date&&e instanceof Date?t.getTime()-e.getTime():n.compare(String(t),String(e))}export function isEmptyValue(t){return null==t||""===t||"number"==typeof t&&Number.isNaN(t)}export function sortRows(t,e,n){if(0===e.length)return t;const o=e.map(t=>{const e=n(t.key);if(!e)return null;const o="desc"===t.direction?-1:1;return"function"==typeof e?{compare:e,isEmpty:null,sign:o}:{compare:e.compare,isEmpty:e.isEmpty,sign:o}}).filter(t=>null!==t);return 0===o.length?t:[...t].sort((t,e)=>{for(const n of o){if(n.isEmpty){const o=n.isEmpty(t);if(o!==n.isEmpty(e))return o?1:-1;if(o)continue}const o=n.compare(t,e);if(0!==o)return o*n.sign}return 0})}export function nextSort(t,e,n){const o=t.find(t=>t.key===e),r=void 0===o?"asc":"asc"===o.direction?"desc":null;return n?null===r?t.filter(t=>t.key!==e):void 0===o?[...t,{key:e,direction:r}]:t.map(t=>t.key===e?{key:e,direction:r}:t):null===r?[]:[{key:e,direction:r}]}export function pageBounds(t,e,n){const o=Math.max(1,Math.floor(n)),r=Math.max(1,Math.ceil(t/o)),i=Math.min(Math.max(Math.floor(e),1),r),a=(i-1)*o;return{pages:r,page:i,start:a,end:Math.min(a+o,t)}}export function virtualWindow(t,e,n,o,r){const i=e>0?Math.ceil(e/n):3*r,a=Math.min(Math.floor(t/n),Math.max(0,o-i)),s=Math.max(0,a-r),m=Math.min(o,s+i+2*r);return{start:s,end:m,before:s*n,after:Math.max(0,(o-m)*n)}}export function keysBetween(t,e,n,o){const r=o?o.get(e)??-1:t.indexOf(e),i=o?o.get(n)??-1:t.indexOf(n);return-1===r||-1===i?[]:t.slice(Math.min(r,i),Math.max(r,i)+1)}
|
package/dist/internal/date.d.ts
CHANGED
|
@@ -72,6 +72,16 @@ export declare function addYears(date: Date, amount: number): Date;
|
|
|
72
72
|
export declare function compareDay(a: Date, b: Date): number;
|
|
73
73
|
export declare function isSameDay(a: Date | null | undefined, b: Date | null | undefined): boolean;
|
|
74
74
|
export declare function isSameMonth(a: Date | null | undefined, b: Date | null | undefined): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* A state updater that moves a held month to the one `date` is in, and keeps
|
|
77
|
+
* the object it already holds when that is the same month.
|
|
78
|
+
*
|
|
79
|
+
* Every picker puts its calendar back on the chosen month when the popup
|
|
80
|
+
* opens, from an effect on `open`. Handed a fresh `Date` there, React saw a
|
|
81
|
+
* new state on every open and drew the trigger, its sizer and the field
|
|
82
|
+
* around it a second time to arrive at the month it was already holding.
|
|
83
|
+
*/
|
|
84
|
+
export declare function toMonthOf(date: Date): (current: Date) => Date;
|
|
75
85
|
/** Holds a date inside `[min, max]`, at whatever precision the bounds carry. */
|
|
76
86
|
export declare function clampDate(date: Date, min?: Date | null, max?: Date | null): Date;
|
|
77
87
|
/**
|
package/dist/internal/date.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memoise as t}from"./cache.js";import{dateFormatter as e}from"./format.js";export const YEAR_PAGE_SIZE=12;export function makeDate(t,e,
|
|
1
|
+
import{memoise as t}from"./cache.js";import{dateFormatter as e}from"./format.js";export const YEAR_PAGE_SIZE=12;export function makeDate(t,e,n){const r=new Date(0);return r.setFullYear(t,e,n),r.setHours(0,0,0,0),r}export function isValidDate(t){return t instanceof Date&&!Number.isNaN(t.getTime())}export function startOfDay(t){const e=new Date(t.getTime());return e.setHours(0,0,0,0),e}export function startOfMonth(t){return makeDate(t.getFullYear(),t.getMonth(),1)}export function startOfYear(t){return makeDate(t.getFullYear(),0,1)}export function startOfUnit(t,e){return"year"===e?startOfYear(t):"month"===e?startOfMonth(t):startOfDay(t)}export function endOfUnit(t,e){const n=t.getFullYear();return"year"===e?makeDate(n,11,31):"month"===e?makeDate(n,t.getMonth(),daysInMonth(n,t.getMonth())):startOfDay(t)}export function daysInMonth(t,e){return makeDate(t,e+1,0).getDate()}export function today(){return startOfDay(new Date)}export function addDays(t,e){const n=new Date(t.getTime());return n.setDate(n.getDate()+e),n}export function addMonths(t,e){const n=t.getFullYear(),r=t.getMonth()+e,o=new Date(t.getTime()),a=makeDate(n,r,1);return o.setFullYear(a.getFullYear(),a.getMonth(),Math.min(t.getDate(),daysInMonth(a.getFullYear(),a.getMonth()))),o}export function addYears(t,e){return addMonths(t,12*e)}export function compareDay(t,e){return startOfDay(t).getTime()-startOfDay(e).getTime()}export function isSameDay(t,e){return isValidDate(t)&&isValidDate(e)&&0===compareDay(t,e)}export function isSameMonth(t,e){return isValidDate(t)&&isValidDate(e)&&t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()}export function toMonthOf(t){return e=>isSameMonth(e,t)?e:startOfMonth(t)}export function clampDate(t,e,n){return isValidDate(e)&&t.getTime()<e.getTime()?new Date(e.getTime()):isValidDate(n)&&t.getTime()>n.getTime()?new Date(n.getTime()):t}export function isDayOutside(t,e,n){return!!(isValidDate(e)&&compareDay(t,e)<0)||isValidDate(n)&&compareDay(t,n)>0}export function isUnitOutside(t,e,n,r){return!!(isValidDate(n)&&compareDay(endOfUnit(t,e),n)<0)||isValidDate(r)&&compareDay(startOfUnit(t,e),r)>0}export function secondsOfDay(t){return 3600*t.getHours()+60*t.getMinutes()+t.getSeconds()}export function timeUnitSpan(t,e){const n=secondsOfDay(e);if("hour"===t){const t=3600*Math.floor(n/3600);return[t,t+3599]}if("minute"===t){const t=60*Math.floor(n/60);return[t,t+59]}if("second"===t)return[n,n];const r=e.getHours()<12?0:43200;return[r,r+43200-1]}export function timeUnitRange(t,e){const[n,r]=timeUnitSpan(t,e),o=t=>withTime(e,{hours:Math.floor(t/3600),minutes:Math.floor(t%3600/60),seconds:t%60});return[o(n),o(r)]}export function withTime(t,e){const n=new Date(t.getTime());return n.setHours(e.hours??n.getHours(),e.minutes??n.getMinutes(),e.seconds??n.getSeconds(),0),n}export function mergeDateAndTime(t,e){return withTime(startOfDay(t),{hours:e.getHours(),minutes:e.getMinutes(),seconds:e.getSeconds()})}export function calendarWeeks(t,e){const n=startOfMonth(t),r=(n.getDay()-e+7)%7,o=addDays(n,-r);return Array.from({length:6},(t,e)=>Array.from({length:7},(t,n)=>addDays(o,7*e+n)))}export function yearPageStart(t){return t-(t%12+12)%12}export function formatDate(t,n,r){return isValidDate(t)?e(n,r).format(t):""}const n=Array.from({length:24},(t,e)=>new Date(2027,e%12,21+e%7,e,58,58)),r=Array.from({length:84},(t,e)=>{const n=Math.floor(e/7),r=new Date(2027,n,21).getDay();return new Date(2027,n,21+(e-r+7)%7,e%24,58,58)}),o=new WeakMap;export function displaySamples(t,a){const i=e(t,a),u=o.get(i);if(u)return u;const s=i.formatToParts(n[0]).some(t=>"weekday"===t.type),c=[...new Set((s?r:n).map(t=>i.format(t)))];return o.set(i,c),c}export function withPlaceholder(t,e){return"string"==typeof e&&""!==e?[...t,e]:t}export function toISODate(t){const e=t=>String(t).padStart(2,"0");return`${String(t.getFullYear()).padStart(4,"0")}-${e(t.getMonth()+1)}-${e(t.getDate())}`}export function toISOMonth(t){return`${String(t.getFullYear()).padStart(4,"0")}-${String(t.getMonth()+1).padStart(2,"0")}`}export function toISOYear(t){return String(t.getFullYear()).padStart(4,"0")}export function toISOTime(t,e=!1){const n=t=>String(t).padStart(2,"0"),r=`${n(t.getHours())}:${n(t.getMinutes())}`;return e?`${r}:${n(t.getSeconds())}`:r}export function toISODateTime(t,e=!1){return`${toISODate(t)}T${toISOTime(t,e)}`}const a=makeDate(2021,7,1);export function weekdayLabels(t,n,r="short"){const o=e(t,{weekday:r});return Array.from({length:7},(t,e)=>o.format(addDays(a,(n+e)%7)))}export function monthLabels(t,n="short"){const r=e(t,{month:n});return Array.from({length:12},(t,e)=>r.format(makeDate(2021,e,1)))}export function isMonthBeforeYear(t){const n=e(t,{year:"numeric",month:"long"}).formatToParts(a);return n.findIndex(t=>"month"===t.type)<n.findIndex(t=>"year"===t.type)}export function isHour12(t){const n=e(t,{hour:"numeric"}).resolvedOptions();return n.hourCycle?"h11"===n.hourCycle||"h12"===n.hourCycle:!0===n.hour12}export function meridiemLabels(t){const n=e(t,{hour:"numeric",hour12:!0}),r=t=>{const e=n.formatToParts(withTime(a,{hours:t})).find(t=>"dayPeriod"===t.type);return e?.value??(t<12?"AM":"PM")};return[r(9),r(21)]}const i=new Map;export function localeWeekStart(e){return t(i,e??"",()=>function(t){try{const e=t??(new Intl.DateTimeFormat).resolvedOptions().locale,n=new Intl.Locale(e),r="function"==typeof n.getWeekInfo?n.getWeekInfo():n.weekInfo;if("number"==typeof r?.firstDay)return r.firstDay%7}catch{}return 0}(e))}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs `task` when the browser next has nothing else to do, and returns what
|
|
3
|
+
* cancels it.
|
|
4
|
+
*
|
|
5
|
+
* `timeout` is how long a page that is never idle may hold the task back, and
|
|
6
|
+
* it is the caller's: a chart's hidden table wants its next slice within half a
|
|
7
|
+
* second, a palette fetching its sheet can wait two. Where there is no idle
|
|
8
|
+
* callback, which is Safari, a timer of `fallbackDelay` stands in.
|
|
9
|
+
*/
|
|
10
|
+
export declare function whenIdle(task: (deadline?: IdleDeadline) => void, timeout: number, fallbackDelay?: number): () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function whenIdle(e,t,l=16){if("function"==typeof requestIdleCallback&&"function"==typeof cancelIdleCallback){const l=requestIdleCallback(e,{timeout:t});return()=>cancelIdleCallback(l)}const c=setTimeout(e,l);return()=>clearTimeout(c)}
|
package/dist/internal/link.d.ts
CHANGED
|
@@ -32,9 +32,10 @@ export declare function opensElsewhere(target: string | undefined): boolean;
|
|
|
32
32
|
* and neither is implied for a named target. So the two tokens are added
|
|
33
33
|
* wherever a component lets a caller choose where a link opens — TextLink, a
|
|
34
34
|
* Menu row, a NavigationMenu link, a ChatBubble's link, an AppLogo, a
|
|
35
|
-
* BottomNavigation destination, a Breadcrumb item, a Sources row
|
|
36
|
-
* InlineCitation — and they are added the same way in all of them,
|
|
37
|
-
* library where only some are safe is a library whose users cannot
|
|
35
|
+
* BottomNavigation destination, a Breadcrumb item, a Sources row, an
|
|
36
|
+
* InlineCitation and a Chip — and they are added the same way in all of them,
|
|
37
|
+
* because a library where only some are safe is a library whose users cannot
|
|
38
|
+
* tell which.
|
|
38
39
|
*
|
|
39
40
|
* It is a *merge* and not an override, and that is the whole reason this is a
|
|
40
41
|
* function rather than a string. The common reason to write a `rel` by hand is
|
package/dist/internal/media.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import*as e from"react";import{memoise as t}from"./cache.js";const
|
|
1
|
+
"use client";import*as e from"react";import{memoise as t}from"./cache.js";const n=new Map;function r(e){return t(n,e,()=>"undefined"!=typeof window&&window.matchMedia?window.matchMedia(e):null)}export function subscribeToQuery(e,t){const n=r(e);return n?(n.addEventListener("change",t),()=>n.removeEventListener("change",t)):()=>{}}export function queryMatches(e){return r(e)?.matches??!1}export function noMatchOnServer(){return!1}export const breakpointWidths={xs:"0rem",sm:"40rem",md:"48rem",lg:"64rem",xl:"80rem"};let o=null;function u(){if(o)return o;if("undefined"==typeof window||!window.getComputedStyle)return breakpointWidths;const e=getComputedStyle(document.documentElement),t={...breakpointWidths};let n=!1;for(const r of["sm","md","lg","xl"]){const o=e.getPropertyValue(`--neba-breakpoint-${r}`).trim();o&&(t[r]=o,n=!0)}return n&&(o=t),t}export function widthBelow(e){return"xs"===e?null:`(width < ${u()[e]})`}export function widthAtLeast(e){return`(width >= ${u()[e]})`}export function useMediaQuery(t){const n=e.useCallback(e=>t?subscribeToQuery(t,e):()=>{},[t]),r=e.useCallback(()=>!!t&&queryMatches(t),[t]);return e.useSyncExternalStore(n,r,noMatchOnServer)}export const reducedMotionQuery="(prefers-reduced-motion: reduce)";const c=e=>subscribeToQuery(reducedMotionQuery,e),i=()=>queryMatches(reducedMotionQuery),s=()=>()=>{},d=()=>!0,a=()=>!1;export function useHydrated(){return e.useSyncExternalStore(s,d,a)}export const HYDRATION_LOCALE="en-US";export function useIntlLocale(t){const n=e.useSyncExternalStore(s,d,void 0===t?a:d);return t??(n?void 0:"en-US")}export function usePrefersReducedMotion(){return e.useSyncExternalStore(c,i,noMatchOnServer)}
|
|
@@ -32,6 +32,10 @@ type VisibilityCallback = (visible: boolean) => void;
|
|
|
32
32
|
/**
|
|
33
33
|
* Watches whether one element is on screen. Returns the function that stops.
|
|
34
34
|
*
|
|
35
|
+
* On screen means at least `threshold` of it is showing; `0` is any of it. A
|
|
36
|
+
* watcher is told when that answer changes, and one that arrives after the
|
|
37
|
+
* element was first reported is told the answer as it stands.
|
|
38
|
+
*
|
|
35
39
|
* `rootMargin` grows the screen it is measured against, for work that should
|
|
36
40
|
* start before the element arrives rather than as it does.
|
|
37
41
|
*
|
package/dist/internal/observe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new Map;let t=null;export function observeResize(r,n){const s="undefined"==typeof ResizeObserver?null:(t??=new ResizeObserver(t=>{for(const r of t){const t=e.get(r.target);if(t)for(const e of[...t])e(r)}}),t);if(!s)return()=>{};let o=e.get(r);return o||(o=new Set,e.set(r,o),s.observe(r)),o.add(n),()=>{const t=e.get(r);t&&(t.delete(n),0===t.size&&(e.delete(r),s.unobserve(r)))}}const r=new Map;export function observeVisibility(e,t,n,s="0px"){const o=Number.isNaN(t)?0:Math.min(1,Math.max(0,t)),c=function(e,t){if("undefined"==typeof IntersectionObserver)return null;const n=`${e} ${t}`;let s=r.get(n);if(!s){const o=new Map;s={watchers:o,observer:new IntersectionObserver(e=>{for(const t of e){const e=o.get(t.target);if(e)for(const r of[...e])r(t.isIntersecting)}},{threshold:e,rootMargin:t})},r.set(n,s)}return s}(o,s);if(!c)return null;let i=c.watchers.get(e);return i
|
|
1
|
+
const e=new Map;let t=null;export function observeResize(r,n){const s="undefined"==typeof ResizeObserver?null:(t??=new ResizeObserver(t=>{for(const r of t){const t=e.get(r.target);if(t)for(const e of[...t])e(r)}}),t);if(!s)return()=>{};let o=e.get(r);return o||(o=new Set,e.set(r,o),s.observe(r)),o.add(n),()=>{const t=e.get(r);t&&(t.delete(n),0===t.size&&(e.delete(r),s.unobserve(r)))}}const r=new Map;export function observeVisibility(e,t,n,s="0px"){const o=Number.isNaN(t)?0:Math.min(1,Math.max(0,t)),c=function(e,t){if("undefined"==typeof IntersectionObserver)return null;const n=`${e} ${t}`;let s=r.get(n);if(!s){const o=new Map,c=new Map;s={watchers:o,last:c,observer:new IntersectionObserver(e=>{for(const t of e){const e=o.get(t.target);if(e){c.set(t.target,t.isIntersecting);for(const r of[...e])r(t.isIntersecting)}}},{threshold:e,rootMargin:t})},r.set(n,s)}return s}(o,s);if(!c)return null;let i=c.watchers.get(e);return i?c.last.has(e)&&queueMicrotask(()=>{const t=c.last.get(e);void 0!==t&&c.watchers.get(e)?.has(n)&&n(t)}):(i=new Set,c.watchers.set(e,i),c.observer.observe(e)),i.add(n),()=>{const t=c.watchers.get(e);t&&(t.delete(n),0===t.size&&(c.watchers.delete(e),c.last.delete(e),c.observer.unobserve(e),0===c.watchers.size&&(c.observer.disconnect(),r.delete(`${o} ${s}`))))}}export function attachedRef(e){let t=null;return{get current(){return t},set current(r){t=r,e(r)}}}
|