@contui/ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +30 -0
- package/README.md +150 -2
- package/cli/contui.mjs +250 -0
- package/dist/charts/area-chart.d.ts +8 -0
- package/dist/charts/area-chart.js +9 -0
- package/dist/charts/bar-chart.d.ts +9 -0
- package/dist/charts/bar-chart.js +10 -0
- package/dist/charts/bubble-chart.d.ts +60 -0
- package/dist/charts/bubble-chart.js +392 -0
- package/dist/charts/bullet-chart.d.ts +53 -0
- package/dist/charts/bullet-chart.js +123 -0
- package/dist/charts/candlestick-chart.d.ts +77 -0
- package/dist/charts/candlestick-chart.js +558 -0
- package/dist/charts/cartesian.d.ts +121 -0
- package/dist/charts/cartesian.js +625 -0
- package/dist/charts/chart-card.d.ts +80 -0
- package/dist/charts/chart-card.js +114 -0
- package/dist/charts/donut-chart.d.ts +40 -0
- package/dist/charts/donut-chart.js +88 -0
- package/dist/charts/funnel-chart.d.ts +16 -0
- package/dist/charts/funnel-chart.js +164 -0
- package/dist/charts/horizontal-bar-chart.d.ts +67 -0
- package/dist/charts/horizontal-bar-chart.js +481 -0
- package/dist/charts/index.d.ts +21 -0
- package/dist/charts/index.js +32 -0
- package/dist/charts/legend.d.ts +23 -0
- package/dist/charts/legend.js +22 -0
- package/dist/charts/lib/candlestick-window.d.ts +15 -0
- package/dist/charts/lib/candlestick-window.js +23 -0
- package/dist/charts/lib/color.d.ts +39 -0
- package/dist/charts/lib/color.js +83 -0
- package/dist/charts/lib/format.d.ts +11 -0
- package/dist/charts/lib/format.js +33 -0
- package/dist/charts/lib/frame.d.ts +6 -0
- package/dist/charts/lib/frame.js +6 -0
- package/dist/charts/lib/layout.d.ts +11 -0
- package/dist/charts/lib/layout.js +71 -0
- package/dist/charts/lib/path.d.ts +35 -0
- package/dist/charts/lib/path.js +203 -0
- package/dist/charts/lib/scale.d.ts +41 -0
- package/dist/charts/lib/scale.js +80 -0
- package/dist/charts/lib/use-active.d.ts +18 -0
- package/dist/charts/lib/use-active.js +71 -0
- package/dist/charts/lib/use-size.d.ts +9 -0
- package/dist/charts/lib/use-size.js +40 -0
- package/dist/charts/line-chart.d.ts +7 -0
- package/dist/charts/line-chart.js +8 -0
- package/dist/charts/radar-chart.d.ts +27 -0
- package/dist/charts/radar-chart.js +165 -0
- package/dist/charts/rose-chart.d.ts +35 -0
- package/dist/charts/rose-chart.js +242 -0
- package/dist/charts/sparkline.d.ts +35 -0
- package/dist/charts/sparkline.js +110 -0
- package/dist/charts/tooltip.d.ts +35 -0
- package/dist/charts/tooltip.js +22 -0
- package/dist/charts/treemap.d.ts +28 -0
- package/dist/charts/treemap.js +103 -0
- package/dist/charts/uptime-strip.d.ts +40 -0
- package/dist/charts/uptime-strip.js +178 -0
- package/dist/components/accordion.d.ts +31 -0
- package/dist/components/accordion.js +34 -0
- package/dist/components/activity-item.d.ts +12 -0
- package/dist/components/activity-item.js +6 -0
- package/dist/components/alert.d.ts +21 -0
- package/dist/components/alert.js +58 -0
- package/dist/components/assistant-answer.d.ts +52 -0
- package/dist/components/assistant-answer.js +40 -0
- package/dist/components/assistant-prompt.d.ts +63 -0
- package/dist/components/assistant-prompt.js +122 -0
- package/dist/components/avatar.d.ts +28 -0
- package/dist/components/avatar.js +75 -0
- package/dist/components/badge.d.ts +16 -0
- package/dist/components/badge.js +33 -0
- package/dist/components/bar-list.d.ts +65 -0
- package/dist/components/bar-list.js +119 -0
- package/dist/components/block-slider.d.ts +43 -0
- package/dist/components/block-slider.js +63 -0
- package/dist/components/branch-graph.d.ts +87 -0
- package/dist/components/branch-graph.js +231 -0
- package/dist/components/breadcrumb.d.ts +41 -0
- package/dist/components/breadcrumb.js +53 -0
- package/dist/components/button.d.ts +23 -0
- package/dist/components/button.js +108 -0
- package/dist/components/calendar.d.ts +5 -0
- package/dist/components/calendar.js +90 -0
- package/dist/components/card.d.ts +65 -0
- package/dist/components/card.js +104 -0
- package/dist/components/chat-attachment.d.ts +47 -0
- package/dist/components/chat-attachment.js +63 -0
- package/dist/components/chat-event.d.ts +7 -0
- package/dist/components/chat-event.js +7 -0
- package/dist/components/chat-message.d.ts +59 -0
- package/dist/components/chat-message.js +91 -0
- package/dist/components/chat-reference.d.ts +20 -0
- package/dist/components/chat-reference.js +41 -0
- package/dist/components/chat-shared.d.ts +21 -0
- package/dist/components/chat-shared.js +23 -0
- package/dist/components/chat-suggestions.d.ts +59 -0
- package/dist/components/chat-suggestions.js +88 -0
- package/dist/components/chat-thread.d.ts +39 -0
- package/dist/components/chat-thread.js +172 -0
- package/dist/components/chat-typing.d.ts +35 -0
- package/dist/components/chat-typing.js +66 -0
- package/dist/components/checkbox.d.ts +18 -0
- package/dist/components/checkbox.js +33 -0
- package/dist/components/checklist.d.ts +26 -0
- package/dist/components/checklist.js +18 -0
- package/dist/components/chip.d.ts +29 -0
- package/dist/components/chip.js +61 -0
- package/dist/components/code-input.d.ts +40 -0
- package/dist/components/code-input.js +285 -0
- package/dist/components/color-picker.d.ts +38 -0
- package/dist/components/color-picker.js +855 -0
- package/dist/components/combobox.d.ts +75 -0
- package/dist/components/combobox.js +112 -0
- package/dist/components/command-menu.d.ts +58 -0
- package/dist/components/command-menu.js +166 -0
- package/dist/components/copy-button.d.ts +16 -0
- package/dist/components/copy-button.js +31 -0
- package/dist/components/data-grid.d.ts +50 -0
- package/dist/components/data-grid.js +599 -0
- package/dist/components/date-picker.d.ts +109 -0
- package/dist/components/date-picker.js +268 -0
- package/dist/components/description-list.d.ts +12 -0
- package/dist/components/description-list.js +10 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +140 -0
- package/dist/components/dock.d.ts +45 -0
- package/dist/components/dock.js +79 -0
- package/dist/components/drop-zone.d.ts +46 -0
- package/dist/components/drop-zone.js +101 -0
- package/dist/components/dropdown-menu.d.ts +50 -0
- package/dist/components/dropdown-menu.js +78 -0
- package/dist/components/editable-cell.d.ts +34 -0
- package/dist/components/editable-cell.js +89 -0
- package/dist/components/empty-state.d.ts +17 -0
- package/dist/components/empty-state.js +9 -0
- package/dist/components/field.d.ts +43 -0
- package/dist/components/field.js +75 -0
- package/dist/components/filter-condition.d.ts +188 -0
- package/dist/components/filter-condition.js +113 -0
- package/dist/components/filter-menu.d.ts +57 -0
- package/dist/components/filter-menu.js +46 -0
- package/dist/components/header-bar.d.ts +84 -0
- package/dist/components/header-bar.js +94 -0
- package/dist/components/hold-button.d.ts +15 -0
- package/dist/components/hold-button.js +88 -0
- package/dist/components/icon-tile.d.ts +12 -0
- package/dist/components/icon-tile.js +29 -0
- package/dist/components/info-tip.d.ts +13 -0
- package/dist/components/info-tip.js +26 -0
- package/dist/components/input.d.ts +17 -0
- package/dist/components/input.js +83 -0
- package/dist/components/kbd.d.ts +6 -0
- package/dist/components/kbd.js +7 -0
- package/dist/components/menu-item.d.ts +56 -0
- package/dist/components/menu-item.js +94 -0
- package/dist/components/message-composer.d.ts +75 -0
- package/dist/components/message-composer.js +199 -0
- package/dist/components/nav-rail.d.ts +31 -0
- package/dist/components/nav-rail.js +85 -0
- package/dist/components/notice.d.ts +45 -0
- package/dist/components/notice.js +66 -0
- package/dist/components/optimistic-undo.d.ts +28 -0
- package/dist/components/optimistic-undo.js +43 -0
- package/dist/components/option-row.d.ts +15 -0
- package/dist/components/option-row.js +14 -0
- package/dist/components/page-content.d.ts +11 -0
- package/dist/components/page-content.js +31 -0
- package/dist/components/pagination.d.ts +34 -0
- package/dist/components/pagination.js +41 -0
- package/dist/components/popover.d.ts +27 -0
- package/dist/components/popover.js +25 -0
- package/dist/components/progress.d.ts +33 -0
- package/dist/components/progress.js +75 -0
- package/dist/components/radio-group.d.ts +7 -0
- package/dist/components/radio-group.js +33 -0
- package/dist/components/readonly-field.d.ts +33 -0
- package/dist/components/readonly-field.js +80 -0
- package/dist/components/segmented-control.d.ts +21 -0
- package/dist/components/segmented-control.js +108 -0
- package/dist/components/select.d.ts +42 -0
- package/dist/components/select.js +86 -0
- package/dist/components/separator.d.ts +10 -0
- package/dist/components/separator.js +7 -0
- package/dist/components/setting-row.d.ts +53 -0
- package/dist/components/setting-row.js +93 -0
- package/dist/components/sidebar-switcher.d.ts +47 -0
- package/dist/components/sidebar-switcher.js +20 -0
- package/dist/components/sidebar.d.ts +220 -0
- package/dist/components/sidebar.js +327 -0
- package/dist/components/skeleton.d.ts +18 -0
- package/dist/components/skeleton.js +23 -0
- package/dist/components/slider.d.ts +15 -0
- package/dist/components/slider.js +28 -0
- package/dist/components/spinner.d.ts +14 -0
- package/dist/components/spinner.js +19 -0
- package/dist/components/status-dot.d.ts +24 -0
- package/dist/components/status-dot.js +35 -0
- package/dist/components/stepper.d.ts +60 -0
- package/dist/components/stepper.js +197 -0
- package/dist/components/switch.d.ts +9 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table-cell.d.ts +38 -0
- package/dist/components/table-cell.js +107 -0
- package/dist/components/table-context.d.ts +48 -0
- package/dist/components/table-context.js +69 -0
- package/dist/components/table-head.d.ts +42 -0
- package/dist/components/table-head.js +188 -0
- package/dist/components/table-tree.d.ts +96 -0
- package/dist/components/table-tree.js +137 -0
- package/dist/components/table.d.ts +78 -0
- package/dist/components/table.js +119 -0
- package/dist/components/tabs.d.ts +27 -0
- package/dist/components/tabs.js +79 -0
- package/dist/components/textarea.d.ts +3 -0
- package/dist/components/textarea.js +20 -0
- package/dist/components/theme.d.ts +41 -0
- package/dist/components/theme.js +60 -0
- package/dist/components/thinking.d.ts +68 -0
- package/dist/components/thinking.js +94 -0
- package/dist/components/toast.d.ts +39 -0
- package/dist/components/toast.js +110 -0
- package/dist/components/toolbar.d.ts +25 -0
- package/dist/components/toolbar.js +92 -0
- package/dist/components/tooltip.d.ts +23 -0
- package/dist/components/tooltip.js +27 -0
- package/dist/components/top-nav.d.ts +129 -0
- package/dist/components/top-nav.js +211 -0
- package/dist/components/truncate.d.ts +29 -0
- package/dist/components/truncate.js +138 -0
- package/dist/deprecated.d.ts +43 -0
- package/dist/deprecated.js +47 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +93 -0
- package/dist/lib/cn.d.ts +5 -0
- package/dist/lib/cn.js +14 -0
- package/dist/lib/color.d.ts +136 -0
- package/dist/lib/color.js +307 -0
- package/dist/lib/contrast.d.ts +53 -0
- package/dist/lib/contrast.js +169 -0
- package/dist/lib/create-theme.d.ts +240 -0
- package/dist/lib/create-theme.js +461 -0
- package/dist/lib/harmony.d.ts +102 -0
- package/dist/lib/harmony.js +426 -0
- package/dist/lib/import-theme.d.ts +22 -0
- package/dist/lib/import-theme.js +221 -0
- package/dist/lib/overflow-scroll.d.ts +25 -0
- package/dist/lib/overflow-scroll.js +66 -0
- package/dist/lib/radio-toggle-render.d.ts +3 -0
- package/dist/lib/radio-toggle-render.js +9 -0
- package/dist/lib/reorder.d.ts +38 -0
- package/dist/lib/reorder.js +193 -0
- package/dist/lib/spacing.d.ts +101 -0
- package/dist/lib/spacing.js +118 -0
- package/dist/lib/tailwind-palette.d.ts +5 -0
- package/dist/lib/tailwind-palette.js +351 -0
- package/dist/lib/truncate.d.ts +18 -0
- package/dist/lib/truncate.js +69 -0
- package/dist/lib/use-single-value.d.ts +5 -0
- package/dist/lib/use-single-value.js +17 -0
- package/dist/styles.css +7988 -0
- package/mcp/server.mjs +87590 -0
- package/package.json +58 -5
- package/skills/continuum-fix-padding/SKILL.md +69 -0
- package/skills/continuum-fix-padding/scripts/compute.ts +155 -0
- package/skills/continuum-fix-padding/scripts/spacing.ts +189 -0
- package/skills/continuum-taste/SKILL.md +186 -0
- package/skills/continuum-taste/assets/tokens.css +647 -0
- package/skills/continuum-taste/references/charts.md +375 -0
- package/skills/continuum-taste/references/components.md +1369 -0
- package/skills/continuum-taste/references/foundations.md +539 -0
- package/skills/continuum-taste/references/media/canvas.md +75 -0
- package/skills/continuum-taste/references/media/css.md +61 -0
- package/skills/continuum-taste/references/media/react.md +161 -0
- package/skills/continuum-taste/references/method.md +87 -0
- package/skills/continuum-taste/references/pages.md +391 -0
- package/skills/continuum-taste/references/patterns.md +77 -0
- package/skills/continuum-taste/references/screens/agent.tsx +450 -0
- package/skills/continuum-taste/references/screens/analytics-overview.tsx +377 -0
- package/skills/continuum-taste/references/screens/checkout-funnel.tsx +193 -0
- package/skills/continuum-taste/references/screens/customer.tsx +475 -0
- package/skills/continuum-taste/references/screens/customers.tsx +608 -0
- package/skills/continuum-taste/references/screens/index.tsx +72 -0
- package/skills/continuum-taste/references/screens/invoice-editor.tsx +558 -0
- package/skills/continuum-taste/references/screens/new-customer.tsx +205 -0
- package/skills/continuum-taste/references/screens/overview.tsx +196 -0
- package/skills/continuum-taste/references/screens/report-generator.tsx +329 -0
- package/skills/continuum-taste/references/screens/risk-report.tsx +577 -0
- package/skills/continuum-taste/references/screens/sequence-editor.tsx +455 -0
- package/skills/continuum-taste/references/screens/settings.tsx +288 -0
- package/skills/continuum-taste/references/screens/shared.tsx +204 -0
- package/skills/continuum-taste/references/screens/sign-in.tsx +104 -0
- package/skills/continuum-taste/references/screens/workspace.tsx +596 -0
- package/skills/continuum-taste/references/theming.md +95 -0
- package/src/charts/area-chart.tsx +17 -0
- package/src/charts/bar-chart.tsx +15 -0
- package/src/charts/bubble-chart.tsx +913 -0
- package/src/charts/bullet-chart.tsx +419 -0
- package/src/charts/candlestick-chart.tsx +1242 -0
- package/src/charts/cartesian.tsx +1437 -0
- package/src/charts/chart-card.tsx +394 -0
- package/src/charts/donut-chart.tsx +299 -0
- package/src/charts/funnel-chart.tsx +373 -0
- package/src/charts/horizontal-bar-chart.tsx +991 -0
- package/src/charts/index.ts +76 -0
- package/src/charts/legend.tsx +59 -0
- package/src/charts/lib/candlestick-window.ts +42 -0
- package/src/charts/lib/color.ts +110 -0
- package/src/charts/lib/format.ts +42 -0
- package/src/charts/lib/frame.ts +6 -0
- package/src/charts/lib/layout.ts +78 -0
- package/src/charts/lib/path.ts +225 -0
- package/src/charts/lib/scale.ts +91 -0
- package/src/charts/lib/use-active.ts +87 -0
- package/src/charts/lib/use-size.ts +45 -0
- package/src/charts/line-chart.tsx +16 -0
- package/src/charts/radar-chart.tsx +485 -0
- package/src/charts/rose-chart.tsx +553 -0
- package/src/charts/sparkline.tsx +293 -0
- package/src/charts/tooltip.tsx +105 -0
- package/src/charts/treemap.tsx +271 -0
- package/src/charts/uptime-strip.tsx +469 -0
- package/src/components/accordion.tsx +136 -0
- package/src/components/activity-item.tsx +43 -0
- package/src/components/alert.tsx +135 -0
- package/src/components/assistant-answer.tsx +185 -0
- package/src/components/assistant-prompt.tsx +352 -0
- package/src/components/avatar.tsx +157 -0
- package/src/components/badge.tsx +55 -0
- package/src/components/bar-list.tsx +350 -0
- package/src/components/block-slider.tsx +189 -0
- package/src/components/branch-graph.tsx +580 -0
- package/src/components/breadcrumb.tsx +173 -0
- package/src/components/button.tsx +157 -0
- package/src/components/calendar.tsx +154 -0
- package/src/components/card.tsx +296 -0
- package/src/components/chat-attachment.tsx +255 -0
- package/src/components/chat-event.tsx +34 -0
- package/src/components/chat-message.tsx +332 -0
- package/src/components/chat-reference.tsx +100 -0
- package/src/components/chat-shared.ts +41 -0
- package/src/components/chat-suggestions.tsx +188 -0
- package/src/components/chat-thread.tsx +348 -0
- package/src/components/chat-typing.tsx +155 -0
- package/src/components/checkbox.tsx +83 -0
- package/src/components/checklist.tsx +146 -0
- package/src/components/chip.tsx +152 -0
- package/src/components/code-input.tsx +406 -0
- package/src/components/color-picker.tsx +1385 -0
- package/src/components/combobox.tsx +420 -0
- package/src/components/command-menu.tsx +405 -0
- package/src/components/copy-button.tsx +87 -0
- package/src/components/data-grid.tsx +965 -0
- package/src/components/date-picker.tsx +652 -0
- package/src/components/description-list.tsx +39 -0
- package/src/components/dialog.tsx +367 -0
- package/src/components/dock.tsx +192 -0
- package/src/components/drop-zone.tsx +283 -0
- package/src/components/dropdown-menu.tsx +323 -0
- package/src/components/editable-cell.tsx +219 -0
- package/src/components/empty-state.tsx +50 -0
- package/src/components/field.tsx +148 -0
- package/src/components/filter-condition.tsx +463 -0
- package/src/components/filter-menu.tsx +196 -0
- package/src/components/header-bar.tsx +220 -0
- package/src/components/hold-button.tsx +146 -0
- package/src/components/icon-tile.tsx +43 -0
- package/src/components/info-tip.tsx +87 -0
- package/src/components/input.tsx +136 -0
- package/src/components/kbd.tsx +17 -0
- package/src/components/menu-item.tsx +216 -0
- package/src/components/message-composer.tsx +458 -0
- package/src/components/nav-rail.tsx +235 -0
- package/src/components/notice.tsx +133 -0
- package/src/components/optimistic-undo.ts +68 -0
- package/src/components/option-row.tsx +54 -0
- package/src/components/page-content.tsx +44 -0
- package/src/components/pagination.tsx +182 -0
- package/src/components/popover.tsx +113 -0
- package/src/components/progress.tsx +222 -0
- package/src/components/radio-group.tsx +80 -0
- package/src/components/readonly-field.tsx +251 -0
- package/src/components/segmented-control.tsx +205 -0
- package/src/components/select.tsx +259 -0
- package/src/components/separator.tsx +30 -0
- package/src/components/setting-row.tsx +277 -0
- package/src/components/sidebar-switcher.tsx +134 -0
- package/src/components/sidebar.tsx +804 -0
- package/src/components/skeleton.tsx +57 -0
- package/src/components/slider.tsx +106 -0
- package/src/components/spinner.tsx +43 -0
- package/src/components/status-dot.tsx +100 -0
- package/src/components/stepper.tsx +459 -0
- package/src/components/switch.tsx +54 -0
- package/src/components/table-cell.tsx +239 -0
- package/src/components/table-context.ts +135 -0
- package/src/components/table-head.tsx +393 -0
- package/src/components/table-tree.tsx +357 -0
- package/src/components/table.tsx +295 -0
- package/src/components/tabs.tsx +191 -0
- package/src/components/textarea.tsx +44 -0
- package/src/components/theme.tsx +120 -0
- package/src/components/thinking.tsx +295 -0
- package/src/components/toast.tsx +308 -0
- package/src/components/toolbar.tsx +166 -0
- package/src/components/tooltip.tsx +84 -0
- package/src/components/top-nav.tsx +660 -0
- package/src/components/truncate.tsx +234 -0
- package/src/deprecated.ts +61 -0
- package/src/index.ts +184 -0
- package/src/lib/cn.ts +22 -0
- package/src/lib/color.ts +469 -0
- package/src/lib/contrast.ts +220 -0
- package/src/lib/create-theme.ts +659 -0
- package/src/lib/harmony.ts +609 -0
- package/src/lib/import-theme.ts +272 -0
- package/src/lib/overflow-scroll.tsx +108 -0
- package/src/lib/radio-toggle-render.tsx +15 -0
- package/src/lib/reorder.ts +222 -0
- package/src/lib/spacing.ts +189 -0
- package/src/lib/tailwind-palette.ts +355 -0
- package/src/lib/truncate.ts +79 -0
- package/src/lib/use-single-value.ts +23 -0
- package/src/styles/continuum.css +3 -0
- package/src/styles/theme.css +524 -0
- package/src/styles/tokens.css +647 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ReactNode, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { type ChartColor, chartColor } from './lib/color';
|
|
6
|
+
import { areaPath, curvePath, type Point } from './lib/path';
|
|
7
|
+
import { extent, scalePoint, slotScale } from './lib/scale';
|
|
8
|
+
import { useWidth } from './lib/use-size';
|
|
9
|
+
|
|
10
|
+
export type SparklineLabel = {
|
|
11
|
+
/** The reading the label stands under: its index in `data`. */
|
|
12
|
+
at: number;
|
|
13
|
+
label: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type SparklineProps = {
|
|
17
|
+
/** The readings, oldest first. */
|
|
18
|
+
data: readonly number[];
|
|
19
|
+
/** `area`, a line over its wash; `line`, the line alone; `bar`, a bar a reading. */
|
|
20
|
+
kind?: 'area' | 'line' | 'bar';
|
|
21
|
+
/**
|
|
22
|
+
* The reading that is now. A line ends its solid stroke there and marks it with a dot;
|
|
23
|
+
* bars before it are quieter and it stands at full strength. What comes after is a
|
|
24
|
+
* forecast: a dashed line, or bars in a faint tint.
|
|
25
|
+
*/
|
|
26
|
+
current?: number;
|
|
27
|
+
/** The series' colour, `series-1` unless given. */
|
|
28
|
+
color?: ChartColor;
|
|
29
|
+
/** The marks' height in px, the labels under them not counted. */
|
|
30
|
+
height?: number;
|
|
31
|
+
/** A few places named under the marks, 11 in the quiet ink: the start, now, the end. */
|
|
32
|
+
labels?: readonly SparklineLabel[];
|
|
33
|
+
/** What the line shows, for a screen reader: "Net revenue, May 2026 to June 2027". */
|
|
34
|
+
'aria-label': string;
|
|
35
|
+
className?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Bars take this share of their slot, and never more than this wide. */
|
|
39
|
+
const BAR_SHARE = 0.62;
|
|
40
|
+
const BAR_MAX = 12;
|
|
41
|
+
/** Room kept clear over the highest reading, so a dot on it is not cut. */
|
|
42
|
+
const HEADROOM = 4;
|
|
43
|
+
/** The least room between two labels under the marks. */
|
|
44
|
+
const LABEL_GAP = 8;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Where a line's reading sits across: held in from both edges by the dot's reach, since the
|
|
48
|
+
* reveal clips the marks to their box and a dot on the edge would lose its half.
|
|
49
|
+
*/
|
|
50
|
+
const lineX = (index: number, count: number, width: number) =>
|
|
51
|
+
HEADROOM + scalePoint(index, count, width - HEADROOM * 2);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A measure's recent shape in a few dozen pixels, for a stat card: no axes, no grid, no frame,
|
|
55
|
+
* since the card's figure says how much and the line only says which way it went. A few places
|
|
56
|
+
* named under it give the stretch it covers. It reads at a glance or not at all, so it takes
|
|
57
|
+
* no pointer: the readings are in the card's figures and in the chart it opens to.
|
|
58
|
+
*/
|
|
59
|
+
export const Sparkline = ({
|
|
60
|
+
data,
|
|
61
|
+
kind = 'area',
|
|
62
|
+
current,
|
|
63
|
+
color = 'series-1',
|
|
64
|
+
height = 40,
|
|
65
|
+
labels,
|
|
66
|
+
'aria-label': label,
|
|
67
|
+
className,
|
|
68
|
+
}: SparklineProps) => {
|
|
69
|
+
const [ref, width] = useWidth<HTMLDivElement>();
|
|
70
|
+
const id = useId();
|
|
71
|
+
const ink = chartColor(color);
|
|
72
|
+
const now = current ?? data.length - 1;
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<figure
|
|
76
|
+
aria-label={label}
|
|
77
|
+
className={cn('m-0 flex min-w-0 flex-col', className)}
|
|
78
|
+
role="img"
|
|
79
|
+
>
|
|
80
|
+
<div className="relative w-full" ref={ref} style={{ height }}>
|
|
81
|
+
{width > 0 && data.length > 0 && (
|
|
82
|
+
<svg
|
|
83
|
+
aria-hidden="true"
|
|
84
|
+
className="absolute inset-0 overflow-visible motion-safe:animate-reveal"
|
|
85
|
+
height={height}
|
|
86
|
+
width={width}
|
|
87
|
+
>
|
|
88
|
+
{kind === 'bar' ? (
|
|
89
|
+
<Bars data={data} height={height} ink={ink} now={now} width={width} />
|
|
90
|
+
) : (
|
|
91
|
+
<Line
|
|
92
|
+
data={data}
|
|
93
|
+
height={height}
|
|
94
|
+
id={id}
|
|
95
|
+
ink={ink}
|
|
96
|
+
now={now}
|
|
97
|
+
wash={kind === 'area'}
|
|
98
|
+
width={width}
|
|
99
|
+
/>
|
|
100
|
+
)}
|
|
101
|
+
</svg>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
{labels && labels.length > 0 && (
|
|
105
|
+
<SparklineLabels count={data.length} kind={kind} labels={labels} width={width} />
|
|
106
|
+
)}
|
|
107
|
+
</figure>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type MarksProps = {
|
|
112
|
+
data: readonly number[];
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
ink: string;
|
|
116
|
+
now: number;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const Line = ({
|
|
120
|
+
data,
|
|
121
|
+
width,
|
|
122
|
+
height,
|
|
123
|
+
ink,
|
|
124
|
+
now,
|
|
125
|
+
wash,
|
|
126
|
+
id,
|
|
127
|
+
}: MarksProps & { wash: boolean; id: string }) => {
|
|
128
|
+
const { min, max } = extent(data);
|
|
129
|
+
/*
|
|
130
|
+
* A line stands on its own range, not on zero: the shape is what it is for. But never on less
|
|
131
|
+
* than a fifth of its level, so a measure that held steady reads as steady rather than as a
|
|
132
|
+
* swing of a few seconds blown up to the full height.
|
|
133
|
+
*/
|
|
134
|
+
const middle = (min + max) / 2;
|
|
135
|
+
const span = Math.max(max - min, Math.abs(middle) * 0.2) || 1;
|
|
136
|
+
const low = middle - span / 2;
|
|
137
|
+
const points: Point[] = data.map((value, i) => ({
|
|
138
|
+
x: lineX(i, data.length, width),
|
|
139
|
+
y: HEADROOM + (1 - (value - low) / span) * (height - HEADROOM * 2),
|
|
140
|
+
}));
|
|
141
|
+
const done = points.slice(0, now + 1);
|
|
142
|
+
const ahead = points.slice(now);
|
|
143
|
+
const dot = points[now];
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<>
|
|
147
|
+
{wash && done.length > 1 && (
|
|
148
|
+
<>
|
|
149
|
+
<defs>
|
|
150
|
+
<linearGradient id={`${id}-wash`} x1="0" x2="0" y1="0" y2="1">
|
|
151
|
+
<stop offset="0" stopColor={ink} stopOpacity={0.2} />
|
|
152
|
+
<stop offset="1" stopColor={ink} stopOpacity={0.04} />
|
|
153
|
+
</linearGradient>
|
|
154
|
+
</defs>
|
|
155
|
+
<path d={areaPath(done, height)} fill={`url(#${id}-wash)`} />
|
|
156
|
+
</>
|
|
157
|
+
)}
|
|
158
|
+
{ahead.length > 1 && (
|
|
159
|
+
<path
|
|
160
|
+
d={curvePath(ahead)}
|
|
161
|
+
fill="none"
|
|
162
|
+
stroke={ink}
|
|
163
|
+
strokeDasharray="6 4"
|
|
164
|
+
strokeOpacity={0.5}
|
|
165
|
+
strokeWidth={1.5}
|
|
166
|
+
/>
|
|
167
|
+
)}
|
|
168
|
+
{done.length > 1 && (
|
|
169
|
+
<path
|
|
170
|
+
d={curvePath(done)}
|
|
171
|
+
fill="none"
|
|
172
|
+
stroke={ink}
|
|
173
|
+
strokeLinecap="round"
|
|
174
|
+
strokeLinejoin="round"
|
|
175
|
+
strokeWidth={2}
|
|
176
|
+
/>
|
|
177
|
+
)}
|
|
178
|
+
{dot && (
|
|
179
|
+
<circle
|
|
180
|
+
cx={dot.x}
|
|
181
|
+
cy={dot.y}
|
|
182
|
+
fill={ink}
|
|
183
|
+
r={3}
|
|
184
|
+
stroke="var(--color-neutral-50)"
|
|
185
|
+
strokeWidth={2}
|
|
186
|
+
/>
|
|
187
|
+
)}
|
|
188
|
+
</>
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const Bars = ({ data, width, height, ink, now }: MarksProps) => {
|
|
193
|
+
const { max } = extent([0, ...data]);
|
|
194
|
+
const { slot, center } = slotScale(data.length, width);
|
|
195
|
+
const bar = Math.max(2, Math.min(slot * BAR_SHARE, BAR_MAX));
|
|
196
|
+
const radius = Math.min(3, bar / 2);
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<>
|
|
200
|
+
{data.map((value, i) => {
|
|
201
|
+
const size = Math.max(2, (value / (max || 1)) * height);
|
|
202
|
+
// Before now quieter, now itself full, after it a forecast in a faint tint.
|
|
203
|
+
const opacity = i === now ? 1 : i < now ? 0.45 : 0.18;
|
|
204
|
+
return (
|
|
205
|
+
<path
|
|
206
|
+
d={barPath(center(i) - bar / 2, height - size, bar, size, radius)}
|
|
207
|
+
fill={ink}
|
|
208
|
+
fillOpacity={opacity}
|
|
209
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a reading's place is its key
|
|
210
|
+
key={i}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
213
|
+
})}
|
|
214
|
+
</>
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/** A bar flat on the baseline, rounded at its head. */
|
|
219
|
+
const barPath = (x: number, y: number, w: number, h: number, r: number) => {
|
|
220
|
+
const radius = Math.min(r, h);
|
|
221
|
+
return `M${x},${y + h} L${x},${y + radius} Q${x},${y} ${x + radius},${y} L${x + w - radius},${y} Q${x + w},${y} ${x + w},${y + radius} L${x + w},${y + h} Z`;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The named places, each under its reading: the first held to the left edge, the last to the
|
|
226
|
+
* right, one between centred on its reading. One that would run into a neighbour is left out,
|
|
227
|
+
* the ends kept first.
|
|
228
|
+
*/
|
|
229
|
+
const SparklineLabels = ({
|
|
230
|
+
labels,
|
|
231
|
+
count,
|
|
232
|
+
width,
|
|
233
|
+
kind,
|
|
234
|
+
}: {
|
|
235
|
+
labels: readonly SparklineLabel[];
|
|
236
|
+
count: number;
|
|
237
|
+
width: number;
|
|
238
|
+
kind: SparklineProps['kind'];
|
|
239
|
+
}) => {
|
|
240
|
+
const xOf = (at: number) =>
|
|
241
|
+
kind === 'bar' ? slotScale(count, width).center(at) : lineX(at, count, width);
|
|
242
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
243
|
+
// Each label's width as set, measured: the theme's font decides it, not a guess.
|
|
244
|
+
const [sizes, setSizes] = useState<readonly number[]>([]);
|
|
245
|
+
|
|
246
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: new labels are new widths to measure
|
|
247
|
+
useLayoutEffect(() => {
|
|
248
|
+
const node = ref.current;
|
|
249
|
+
if (!node || width === 0) return;
|
|
250
|
+
setSizes(Array.from(node.children, child => (child as HTMLElement).offsetWidth));
|
|
251
|
+
}, [width, labels]);
|
|
252
|
+
|
|
253
|
+
const lastIndex = labels.length > 1 ? labels.length - 1 : -1;
|
|
254
|
+
const shown = new Set<number>([0, lastIndex]);
|
|
255
|
+
if (sizes.length === labels.length) {
|
|
256
|
+
// The ends stand first; each label between is kept when it clears both its neighbours.
|
|
257
|
+
const end = lastIndex > 0 ? width - (sizes[lastIndex] ?? 0) - LABEL_GAP : width;
|
|
258
|
+
let reach = (sizes[0] ?? 0) + LABEL_GAP;
|
|
259
|
+
for (let i = 1; i < lastIndex; i++) {
|
|
260
|
+
const half = (sizes[i] ?? 0) / 2;
|
|
261
|
+
const x = xOf(labels[i]?.at ?? 0);
|
|
262
|
+
if (x - half >= reach && x + half <= end) {
|
|
263
|
+
shown.add(i);
|
|
264
|
+
reach = x + half + LABEL_GAP;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
className="relative mt-2 h-3.5 text-[11px] text-neutral-600 tabular-nums leading-3.5"
|
|
272
|
+
ref={ref}
|
|
273
|
+
>
|
|
274
|
+
{labels.map(({ at, label }, i) => (
|
|
275
|
+
<span
|
|
276
|
+
className="absolute top-0 whitespace-nowrap"
|
|
277
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the labels are given in order
|
|
278
|
+
key={i}
|
|
279
|
+
style={{
|
|
280
|
+
...(i === 0
|
|
281
|
+
? { left: 0 }
|
|
282
|
+
: i === lastIndex
|
|
283
|
+
? { right: 0 }
|
|
284
|
+
: { left: xOf(at), transform: 'translateX(-50%)' }),
|
|
285
|
+
visibility: shown.has(i) ? undefined : 'hidden',
|
|
286
|
+
}}
|
|
287
|
+
>
|
|
288
|
+
{label}
|
|
289
|
+
</span>
|
|
290
|
+
))}
|
|
291
|
+
</div>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { type ChartColor, chartColor } from './lib/color';
|
|
6
|
+
|
|
7
|
+
export type ChartTooltipRow = {
|
|
8
|
+
name: ReactNode;
|
|
9
|
+
value: ReactNode;
|
|
10
|
+
/** Left out on a total, which keys nothing. */
|
|
11
|
+
color?: ChartColor;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type ChartTooltipProps = {
|
|
15
|
+
/** The x the rows are read at: a date, or the category. */
|
|
16
|
+
title?: ReactNode;
|
|
17
|
+
rows?: readonly ChartTooltipRow[];
|
|
18
|
+
/** Appended under the rows, divided from them: a stacked chart's total. */
|
|
19
|
+
footer?: ReactNode;
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Which side the rule it speaks from is on. That bottom corner is left square, so the
|
|
23
|
+
* readout reads as a bubble said from the rule. Only where there is a rule to speak from:
|
|
24
|
+
* beside a bar, or on its own, all four corners are round.
|
|
25
|
+
*/
|
|
26
|
+
tail?: 'left' | 'right' | 'none';
|
|
27
|
+
className?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The readout beside the point a chart is hovered at. Also exported on its own, so a
|
|
32
|
+
* custom readout is written in the same surface as every other chart's.
|
|
33
|
+
*
|
|
34
|
+
* Beside a line's rule it is a bubble: three round corners and one square, the bottom one
|
|
35
|
+
* on the rule's side. Each series is keyed by a short upright stroke of its colour.
|
|
36
|
+
* The value leads and the name follows, the legend's order inverted: here the reader
|
|
37
|
+
* already knows which series they are on and wants the figure.
|
|
38
|
+
*/
|
|
39
|
+
export const ChartTooltip = ({
|
|
40
|
+
title,
|
|
41
|
+
rows,
|
|
42
|
+
footer,
|
|
43
|
+
children,
|
|
44
|
+
tail = 'none',
|
|
45
|
+
className,
|
|
46
|
+
}: ChartTooltipProps) => (
|
|
47
|
+
<div
|
|
48
|
+
className={cn(
|
|
49
|
+
'min-w-35 overflow-hidden rounded-item border border-neutral-200 bg-neutral-50 shadow-float',
|
|
50
|
+
tail === 'left' && 'rounded-bl-none',
|
|
51
|
+
tail === 'right' && 'rounded-br-none',
|
|
52
|
+
className,
|
|
53
|
+
)}
|
|
54
|
+
data-slot="chart-tooltip"
|
|
55
|
+
>
|
|
56
|
+
<div className="p-3">
|
|
57
|
+
{title != null && (
|
|
58
|
+
<p
|
|
59
|
+
className="mb-2 font-medium text-neutral-950 text-xs"
|
|
60
|
+
data-slot="chart-tooltip-title"
|
|
61
|
+
>
|
|
62
|
+
{title}
|
|
63
|
+
</p>
|
|
64
|
+
)}
|
|
65
|
+
{rows && rows.length > 0 && (
|
|
66
|
+
<ul className="flex flex-col gap-1.5" data-slot="chart-tooltip-rows">
|
|
67
|
+
{rows.map((row, index) => (
|
|
68
|
+
<ChartTooltipRow
|
|
69
|
+
// A row is its series; two series may share a name, so the place is the key.
|
|
70
|
+
key={`${index}-${String(row.name)}`}
|
|
71
|
+
{...row}
|
|
72
|
+
/>
|
|
73
|
+
))}
|
|
74
|
+
</ul>
|
|
75
|
+
)}
|
|
76
|
+
{children}
|
|
77
|
+
</div>
|
|
78
|
+
{footer != null && (
|
|
79
|
+
// The rule runs edge to edge: a divider that stops short of the sides is a box in a box.
|
|
80
|
+
<div className="border-neutral-200 border-t px-3 py-2" data-slot="chart-tooltip-footer">
|
|
81
|
+
{footer}
|
|
82
|
+
</div>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/** One series at the read x: its dot and name, then its value. */
|
|
88
|
+
export const ChartTooltipRow = ({ name, value, color }: ChartTooltipRow) => (
|
|
89
|
+
<li className="flex items-center justify-between gap-4" data-slot="chart-tooltip-row">
|
|
90
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
91
|
+
{color ? (
|
|
92
|
+
<span
|
|
93
|
+
aria-hidden
|
|
94
|
+
className="h-3 w-0.75 shrink-0 rounded-full"
|
|
95
|
+
style={{ background: chartColor(color) }}
|
|
96
|
+
/>
|
|
97
|
+
) : (
|
|
98
|
+
// A total keeps the rows' text aligned without claiming a colour of its own.
|
|
99
|
+
<span aria-hidden className="h-3 w-0.75 shrink-0" />
|
|
100
|
+
)}
|
|
101
|
+
<span className="truncate text-neutral-600 text-xs">{name}</span>
|
|
102
|
+
</span>
|
|
103
|
+
<span className="shrink-0 font-medium text-neutral-950 text-xs tabular-nums">{value}</span>
|
|
104
|
+
</li>
|
|
105
|
+
);
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type ReactNode, useState } from 'react';
|
|
4
|
+
import { Badge } from '../components/badge';
|
|
5
|
+
import { cn } from '../lib/cn';
|
|
6
|
+
import { type ChartColor, chartColor, seriesColor } from './lib/color';
|
|
7
|
+
import { formatNumber, formatPercent } from './lib/format';
|
|
8
|
+
import { PLOT_FRAME } from './lib/frame';
|
|
9
|
+
import { squarify } from './lib/layout';
|
|
10
|
+
import { useWidth } from './lib/use-size';
|
|
11
|
+
import { ChartTooltip } from './tooltip';
|
|
12
|
+
|
|
13
|
+
export type TreemapItem = {
|
|
14
|
+
name: string;
|
|
15
|
+
value: number;
|
|
16
|
+
/** The change on the period before, as it should read: "+2.6%". */
|
|
17
|
+
delta?: string;
|
|
18
|
+
/** A 14px icon before the name. */
|
|
19
|
+
icon?: ReactNode;
|
|
20
|
+
color?: ChartColor;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type TreemapProps = {
|
|
24
|
+
/** Says what the chart shows; it names the chart for a screen reader. */
|
|
25
|
+
'aria-label': string;
|
|
26
|
+
data: readonly TreemapItem[];
|
|
27
|
+
height?: number;
|
|
28
|
+
/** Writes a tile's figure; its share of the whole unless given. */
|
|
29
|
+
formatValue?: (value: number, share: number) => string;
|
|
30
|
+
/** While the data loads: the chart's own shape stands in, in the skeleton wash, at the size it will have. */
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The stand-in's shares: one part that takes most, a few middling and a small one, as spending
|
|
37
|
+
* or traffic tends to split, so the tiles read as data waiting and not as a grid.
|
|
38
|
+
*/
|
|
39
|
+
const SKELETON_SHARES = [44, 18, 13, 11, 8, 6];
|
|
40
|
+
|
|
41
|
+
/** The widths of the stand-in's names, in the tiles large enough to write one. */
|
|
42
|
+
const SKELETON_NAMES = [72, 88, 64, 80, 56, 68];
|
|
43
|
+
|
|
44
|
+
/** A bar on a stand-in tile, a step stronger than the tile's own wash so it reads over it. */
|
|
45
|
+
const SKELETON_BAR = 'color-mix(in oklab, var(--color-neutral-950) 7%, transparent)';
|
|
46
|
+
|
|
47
|
+
const GAP = 4;
|
|
48
|
+
/**
|
|
49
|
+
* The tiles stand inside their frame's hairline with the same room as between them; the frame's
|
|
50
|
+
* corner is the tiles' corner grown by that inset, so the two stay concentric.
|
|
51
|
+
*/
|
|
52
|
+
const INSET = 1 + GAP;
|
|
53
|
+
/**
|
|
54
|
+
* Parts of a whole as tiles, each as large as its share and as square as the shares allow.
|
|
55
|
+
* A tile is a tint of its colour, keyed by the same upright stroke the readout uses, and it
|
|
56
|
+
* says as much as it has room for: its name, then its figure, then its change.
|
|
57
|
+
*/
|
|
58
|
+
export const Treemap = ({
|
|
59
|
+
'aria-label': label,
|
|
60
|
+
data,
|
|
61
|
+
height = 280,
|
|
62
|
+
formatValue,
|
|
63
|
+
loading = false,
|
|
64
|
+
className,
|
|
65
|
+
}: TreemapProps) => {
|
|
66
|
+
const [ref, width] = useWidth<HTMLDivElement>();
|
|
67
|
+
const [active, setActive] = useState<number | null>(null);
|
|
68
|
+
const total = data.reduce((sum, item) => sum + Math.max(0, item.value), 0);
|
|
69
|
+
// While it loads, the stand-in's shares are tiled as the data will be, by the same layout.
|
|
70
|
+
const tiles = squarify(loading ? SKELETON_SHARES : data.map(item => item.value), {
|
|
71
|
+
x: INSET,
|
|
72
|
+
y: INSET,
|
|
73
|
+
width: Math.max(0, width - INSET * 2) + GAP,
|
|
74
|
+
height: Math.max(0, height - INSET * 2) + GAP,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<figure
|
|
79
|
+
aria-busy={loading || undefined}
|
|
80
|
+
aria-label={label}
|
|
81
|
+
className={cn('relative m-0 min-w-0', className)}
|
|
82
|
+
data-slot="treemap"
|
|
83
|
+
>
|
|
84
|
+
<div className="relative" ref={ref} style={{ height }}>
|
|
85
|
+
{/* The tiles are held to the frame's rect and corner, never past its hairline. */}
|
|
86
|
+
<div
|
|
87
|
+
className="absolute inset-0 overflow-hidden"
|
|
88
|
+
style={{ borderRadius: `calc(var(--radius-item) + ${INSET}px)` }}
|
|
89
|
+
>
|
|
90
|
+
{width > 0 && loading && (
|
|
91
|
+
<div aria-hidden className="absolute inset-0" data-slot="chart-skeleton">
|
|
92
|
+
{tiles.map((tile, index) => {
|
|
93
|
+
if (tile.width <= GAP || tile.height <= GAP) return null;
|
|
94
|
+
const w = tile.width - GAP;
|
|
95
|
+
const h = tile.height - GAP;
|
|
96
|
+
return (
|
|
97
|
+
<div
|
|
98
|
+
className="skeleton absolute flex flex-col justify-between overflow-hidden rounded-item p-5"
|
|
99
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the stand-in never reorders
|
|
100
|
+
key={index}
|
|
101
|
+
style={{ height: h, left: tile.x, top: tile.y, width: w }}
|
|
102
|
+
>
|
|
103
|
+
{/*
|
|
104
|
+
* Where a tile would write its name and figure, a bar
|
|
105
|
+
* holds each line at its height, a step firmer than
|
|
106
|
+
* the tile it sits on.
|
|
107
|
+
*/}
|
|
108
|
+
{w >= 96 && h >= 56 && (
|
|
109
|
+
<span className="flex min-w-0 items-center text-xs">
|
|
110
|
+
<span className="invisible w-0">0</span>
|
|
111
|
+
<span
|
|
112
|
+
className="skeleton h-2.5 min-w-0 rounded-chip"
|
|
113
|
+
style={{
|
|
114
|
+
backgroundColor: SKELETON_BAR,
|
|
115
|
+
width: SKELETON_NAMES[index] ?? 64,
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
</span>
|
|
119
|
+
)}
|
|
120
|
+
{h >= 84 && w >= 80 && (
|
|
121
|
+
<span className="flex min-w-0 items-center text-lg">
|
|
122
|
+
<span className="invisible w-0">0</span>
|
|
123
|
+
<span
|
|
124
|
+
className="skeleton h-[0.75em] w-12 min-w-0 rounded-chip"
|
|
125
|
+
style={{ backgroundColor: SKELETON_BAR }}
|
|
126
|
+
/>
|
|
127
|
+
</span>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
})}
|
|
132
|
+
</div>
|
|
133
|
+
)}
|
|
134
|
+
{width > 0 &&
|
|
135
|
+
!loading &&
|
|
136
|
+
data.map((item, index) => {
|
|
137
|
+
const tile = tiles[index];
|
|
138
|
+
if (!tile || tile.width <= GAP || tile.height <= GAP) return null;
|
|
139
|
+
const w = tile.width - GAP;
|
|
140
|
+
const h = tile.height - GAP;
|
|
141
|
+
const color = chartColor(item.color ?? seriesColor(index));
|
|
142
|
+
const share = total ? item.value / total : 0;
|
|
143
|
+
const named = w >= 96 && h >= 56;
|
|
144
|
+
const figured = h >= 84 && w >= 80;
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div
|
|
148
|
+
className="absolute flex flex-col justify-between overflow-hidden rounded-item p-5 transition-colors duration-150 motion-reduce:transition-none"
|
|
149
|
+
key={item.name}
|
|
150
|
+
onPointerEnter={() => setActive(index)}
|
|
151
|
+
onPointerLeave={() => setActive(null)}
|
|
152
|
+
style={{
|
|
153
|
+
background: `color-mix(in oklab, ${color} ${active === index ? 26 : 16}%, transparent)`,
|
|
154
|
+
height: h,
|
|
155
|
+
left: tile.x,
|
|
156
|
+
top: tile.y,
|
|
157
|
+
width: w,
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
{named && (
|
|
161
|
+
<span className="flex min-w-0 items-center gap-2 font-medium text-neutral-950 text-xs">
|
|
162
|
+
{!item.icon && (
|
|
163
|
+
<span
|
|
164
|
+
aria-hidden
|
|
165
|
+
className="h-3 w-0.75 shrink-0 rounded-full"
|
|
166
|
+
style={{ background: color }}
|
|
167
|
+
/>
|
|
168
|
+
)}
|
|
169
|
+
{item.icon && (
|
|
170
|
+
<span
|
|
171
|
+
aria-hidden
|
|
172
|
+
className="flex shrink-0 [&_svg]:size-3.5"
|
|
173
|
+
style={{ color }}
|
|
174
|
+
>
|
|
175
|
+
{item.icon}
|
|
176
|
+
</span>
|
|
177
|
+
)}
|
|
178
|
+
<span className="truncate">{item.name}</span>
|
|
179
|
+
</span>
|
|
180
|
+
)}
|
|
181
|
+
{figured && (
|
|
182
|
+
<span className="flex min-w-0 items-end justify-between gap-2">
|
|
183
|
+
{/*
|
|
184
|
+
* One size on every tile, a step under the card's own
|
|
185
|
+
* figure: the tile's area already says how large it is.
|
|
186
|
+
*/}
|
|
187
|
+
<span className="font-medium text-lg text-neutral-950 tabular-nums">
|
|
188
|
+
{formatValue
|
|
189
|
+
? formatValue(item.value, share)
|
|
190
|
+
: formatPercent(share)}
|
|
191
|
+
</span>
|
|
192
|
+
{/*
|
|
193
|
+
* The change is a deeper tint of the tile's own colour,
|
|
194
|
+
* so the tile keeps one hue; its sign says which way.
|
|
195
|
+
*/}
|
|
196
|
+
{item.delta && w >= 120 && (
|
|
197
|
+
<Badge
|
|
198
|
+
className="self-center text-neutral-950 tabular-nums"
|
|
199
|
+
style={{
|
|
200
|
+
background: `color-mix(in oklab, ${color} 24%, transparent)`,
|
|
201
|
+
}}
|
|
202
|
+
variant="pill"
|
|
203
|
+
>
|
|
204
|
+
{item.delta}
|
|
205
|
+
</Badge>
|
|
206
|
+
)}
|
|
207
|
+
</span>
|
|
208
|
+
)}
|
|
209
|
+
</div>
|
|
210
|
+
);
|
|
211
|
+
})}
|
|
212
|
+
</div>
|
|
213
|
+
{(() => {
|
|
214
|
+
// A tile too small to write its own name and figure is read out beside it, in
|
|
215
|
+
// the readout every chart uses.
|
|
216
|
+
const tile = active !== null && !loading ? tiles[active] : undefined;
|
|
217
|
+
const item = active !== null ? data[active] : undefined;
|
|
218
|
+
if (!tile || !item) return null;
|
|
219
|
+
const w = tile.width - GAP;
|
|
220
|
+
const h = tile.height - GAP;
|
|
221
|
+
if (w >= 80 && h >= 84) return null;
|
|
222
|
+
const share = total ? item.value / total : 0;
|
|
223
|
+
const left = tile.x + w / 2 < width / 2;
|
|
224
|
+
return (
|
|
225
|
+
<div
|
|
226
|
+
className="pointer-events-none absolute z-10"
|
|
227
|
+
style={{
|
|
228
|
+
left: left ? tile.x + w + 8 : undefined,
|
|
229
|
+
right: left ? undefined : width - tile.x + 8,
|
|
230
|
+
top: Math.max(0, Math.min(height - 64, tile.y)),
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
<ChartTooltip
|
|
234
|
+
rows={[
|
|
235
|
+
{
|
|
236
|
+
color:
|
|
237
|
+
item.color ??
|
|
238
|
+
(`series-${Math.min((active ?? 0) + 1, 5)}` as ChartColor),
|
|
239
|
+
name: item.name,
|
|
240
|
+
value: formatValue
|
|
241
|
+
? formatValue(item.value, share)
|
|
242
|
+
: formatPercent(share),
|
|
243
|
+
},
|
|
244
|
+
]}
|
|
245
|
+
/>
|
|
246
|
+
</div>
|
|
247
|
+
);
|
|
248
|
+
})()}
|
|
249
|
+
<div
|
|
250
|
+
aria-hidden
|
|
251
|
+
className={cn(PLOT_FRAME, 'inset-0')}
|
|
252
|
+
style={{ borderRadius: `calc(var(--radius-item) + ${INSET}px)` }}
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
<div className={cn('sr-only', loading && 'hidden')}>
|
|
256
|
+
<table>
|
|
257
|
+
<caption>{label}</caption>
|
|
258
|
+
<tbody>
|
|
259
|
+
{data.map(item => (
|
|
260
|
+
<tr key={item.name}>
|
|
261
|
+
<th scope="row">{item.name}</th>
|
|
262
|
+
<td>{formatNumber(item.value)}</td>
|
|
263
|
+
<td>{formatPercent(total ? item.value / total : 0)}</td>
|
|
264
|
+
</tr>
|
|
265
|
+
))}
|
|
266
|
+
</tbody>
|
|
267
|
+
</table>
|
|
268
|
+
</div>
|
|
269
|
+
</figure>
|
|
270
|
+
);
|
|
271
|
+
};
|