@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,553 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type PointerEvent, useId, useState } from 'react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import type { ChartRow, ChartSeries } from './cartesian';
|
|
6
|
+
import { chartColor, seriesColor } from './lib/color';
|
|
7
|
+
import { formatCompact, formatNumber } from './lib/format';
|
|
8
|
+
import { ringSegmentPath } from './lib/path';
|
|
9
|
+
import { niceTicks } from './lib/scale';
|
|
10
|
+
import { useWidth } from './lib/use-size';
|
|
11
|
+
import { ChartTooltip } from './tooltip';
|
|
12
|
+
|
|
13
|
+
export type RoseChartProps<Row extends ChartRow> = {
|
|
14
|
+
/** Says what the chart shows; it names the chart for a screen reader. */
|
|
15
|
+
'aria-label': string;
|
|
16
|
+
/** One row per wedge, in the order they go round: hours, months, weekdays. */
|
|
17
|
+
data: readonly Row[];
|
|
18
|
+
/** The field naming each wedge: "09", "Mar", "Tue". */
|
|
19
|
+
x: string;
|
|
20
|
+
/**
|
|
21
|
+
* What each wedge measures. More than one is stacked outward, each series a ring of the
|
|
22
|
+
* wedge over the one before it, so the whole wedge is the total.
|
|
23
|
+
*/
|
|
24
|
+
series: readonly ChartSeries[];
|
|
25
|
+
/** The chart's height; it is drawn as a circle in the smaller of this and its width. */
|
|
26
|
+
height?: number;
|
|
27
|
+
formatValue?: (value: number) => string;
|
|
28
|
+
/** `tint`, the kit's look, a tint of each colour with a solid edge; `solid` fills each wedge. */
|
|
29
|
+
fill?: 'tint' | 'solid';
|
|
30
|
+
/** What the chart says when there is nothing to draw. */
|
|
31
|
+
emptyLabel?: string;
|
|
32
|
+
/** While the data loads: the chart's own shape stands in, in the skeleton wash, at the size it will have. */
|
|
33
|
+
loading?: boolean;
|
|
34
|
+
className?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The circle fills its frame: only the hairline lies between the outer ring and its edge. */
|
|
38
|
+
const PAD = 1;
|
|
39
|
+
/** The room between the frame and a category's name outside it. */
|
|
40
|
+
const LABEL_GAP = 8;
|
|
41
|
+
/** A name's line, above or under the frame. */
|
|
42
|
+
const LABEL_LINE = 12;
|
|
43
|
+
/** What a name beside the frame is allowed, at most, before the frame gives way to it. */
|
|
44
|
+
const LABEL_SIDE = 40;
|
|
45
|
+
/** The empty middle every wedge starts from, as a share of the radius. */
|
|
46
|
+
const HOLE = 0.1;
|
|
47
|
+
/** The gap between two wedges, and between two stacked rings, in px: the same all the way in. */
|
|
48
|
+
const GAP = 2;
|
|
49
|
+
const EDGE = 2;
|
|
50
|
+
const CORNER = 2.5;
|
|
51
|
+
/** The fewest pixels between two category names round the outside before some are left out. */
|
|
52
|
+
const LABEL_SPACING = 56;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Where a category's name stands: round the circle, a little way past its edge, set from the
|
|
56
|
+
* side it is on so it never runs back over the shape.
|
|
57
|
+
*/
|
|
58
|
+
const outsideFrame = (cx: number, cy: number, half: number, dx: number, dy: number) => ({
|
|
59
|
+
anchor:
|
|
60
|
+
Math.abs(dx) < 0.25 ? ('middle' as const) : dx > 0 ? ('start' as const) : ('end' as const),
|
|
61
|
+
x: cx + dx * (half + LABEL_GAP),
|
|
62
|
+
y: cy + dy * (half + LABEL_GAP + (Math.abs(dx) < 0.25 ? LABEL_LINE / 2 - 2 : 0)),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* How many categories go by between two names: every second, third or fourth when the circle is
|
|
67
|
+
* crowded, counting in a step that goes into the whole, so 24 hours read 00, 03, 06 and never
|
|
68
|
+
* 00, 05, 10.
|
|
69
|
+
*/
|
|
70
|
+
const labelStep = (count: number, half: number) => {
|
|
71
|
+
const room = ((half + LABEL_GAP) * Math.PI * 2) / Math.max(1, count);
|
|
72
|
+
return (
|
|
73
|
+
[1, 2, 3, 4, 6, 8, 12].find(n => count % n === 0 && room * n >= LABEL_SPACING) ??
|
|
74
|
+
Math.ceil(LABEL_SPACING / Math.max(1, room))
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The wedge whose spoke lies between the two quietest neighbours, where the rings' values go. */
|
|
79
|
+
const quietestSpoke = (totals: readonly number[]) => {
|
|
80
|
+
const count = totals.length;
|
|
81
|
+
let quiet = 0;
|
|
82
|
+
let quietest = Number.POSITIVE_INFINITY;
|
|
83
|
+
for (let i = 0; i < count; i++) {
|
|
84
|
+
const loud = Math.max(totals[i] ?? 0, totals[(i - 1 + count) % count] ?? 0);
|
|
85
|
+
if (loud < quietest - 1e-9) {
|
|
86
|
+
quietest = loud;
|
|
87
|
+
quiet = i;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return quiet;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Amounts by a category that goes round, such as the hours of a day or the months of a year:
|
|
95
|
+
* each category a wedge at its own place on the clock, reaching out as far as its value.
|
|
96
|
+
*
|
|
97
|
+
* The radius grows with the square root of the value, so a wedge's area is what is read: a
|
|
98
|
+
* wedge twice the value is twice the ink, never four times. The wedges start from a small
|
|
99
|
+
* hole, and the root is taken of the band between the hole and the edge, so the areas stay
|
|
100
|
+
* true there too. Faint rings mark round values, written once along the quietest spoke, and
|
|
101
|
+
* pointing at a wedge reads it out while the rest step back.
|
|
102
|
+
*/
|
|
103
|
+
export const RoseChart = <Row extends ChartRow>({
|
|
104
|
+
'aria-label': label,
|
|
105
|
+
data,
|
|
106
|
+
x: xKey,
|
|
107
|
+
series,
|
|
108
|
+
height = 320,
|
|
109
|
+
formatValue = formatNumber,
|
|
110
|
+
fill = 'tint',
|
|
111
|
+
emptyLabel = 'Nothing to show yet',
|
|
112
|
+
loading = false,
|
|
113
|
+
className,
|
|
114
|
+
}: RoseChartProps<Row>) => {
|
|
115
|
+
const id = useId().replace(/[^a-zA-Z0-9_-]/g, '');
|
|
116
|
+
const [ref, width] = useWidth<HTMLDivElement>();
|
|
117
|
+
const [active, setActive] = useState<number | null>(null);
|
|
118
|
+
|
|
119
|
+
const count = data.length;
|
|
120
|
+
const values = series.map(line => data.map(row => Math.max(0, Number(row[line.key]) || 0)));
|
|
121
|
+
const totals = data.map((_, i) => values.reduce((sum, column) => sum + (column[i] ?? 0), 0));
|
|
122
|
+
const peak = Math.max(0, ...totals);
|
|
123
|
+
// While it loads the chart draws its stand-in and nothing else, never the last rows.
|
|
124
|
+
const empty = !loading && (count === 0 || peak <= 0);
|
|
125
|
+
const drawn = !loading && !empty;
|
|
126
|
+
const ticks = niceTicks(0, peak, 3);
|
|
127
|
+
|
|
128
|
+
const cx = width / 2;
|
|
129
|
+
const cy = height / 2;
|
|
130
|
+
// The plot is a square frame round the circle; the names stand outside it.
|
|
131
|
+
const half = Math.max(
|
|
132
|
+
0,
|
|
133
|
+
Math.min(width / 2 - LABEL_SIDE, height / 2 - LABEL_GAP - LABEL_LINE) - 1,
|
|
134
|
+
);
|
|
135
|
+
const outer = Math.max(0, half - PAD);
|
|
136
|
+
const hole = outer * HOLE;
|
|
137
|
+
// The area between the hole and a ring grows as the value, so the radius as its root.
|
|
138
|
+
const radiusOf = (value: number) =>
|
|
139
|
+
ticks.max > 0
|
|
140
|
+
? Math.sqrt(
|
|
141
|
+
hole ** 2 + (Math.min(value, ticks.max) / ticks.max) * (outer ** 2 - hole ** 2),
|
|
142
|
+
)
|
|
143
|
+
: hole;
|
|
144
|
+
const step = (Math.PI * 2) / Math.max(1, count);
|
|
145
|
+
// Each wedge is centred on its own angle, so the first stands upright at twelve o'clock.
|
|
146
|
+
const startOf = (i: number) => (i - 0.5) * step;
|
|
147
|
+
const point = (radius: number, angle: number) => ({
|
|
148
|
+
x: cx + radius * Math.sin(angle),
|
|
149
|
+
y: cy - radius * Math.cos(angle),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const every = labelStep(count, half);
|
|
153
|
+
// The ring values go along the spoke between the two quietest neighbours, clear of the wedges.
|
|
154
|
+
const spoke = startOf(quietestSpoke(totals));
|
|
155
|
+
|
|
156
|
+
const onPointerMove = (event: PointerEvent<SVGSVGElement>) => {
|
|
157
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
158
|
+
const dx = event.clientX - box.left - cx;
|
|
159
|
+
const dy = event.clientY - box.top - cy;
|
|
160
|
+
if (Math.hypot(dx, dy) > outer + 8) {
|
|
161
|
+
setActive(null);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const angle = (Math.atan2(dx, -dy) + Math.PI * 2) % (Math.PI * 2);
|
|
165
|
+
setActive((Math.round(angle / step) + count) % count);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// The readout stands off the wedge's outer edge and grows away from the middle, both across
|
|
169
|
+
// and up or down, so it never lies over the wedge it reads.
|
|
170
|
+
const shown = active;
|
|
171
|
+
const tipAngle = shown !== null ? shown * step : 0;
|
|
172
|
+
const tip = shown !== null ? point(radiusOf(totals[shown] ?? 0) + 10, tipAngle) : null;
|
|
173
|
+
const right = Math.sin(tipAngle) >= -1e-6;
|
|
174
|
+
const above = Math.cos(tipAngle) > 0;
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<figure
|
|
178
|
+
aria-busy={loading || undefined}
|
|
179
|
+
aria-label={label}
|
|
180
|
+
className={cn('relative m-0 min-w-0', className)}
|
|
181
|
+
data-slot="rose-chart"
|
|
182
|
+
>
|
|
183
|
+
<div className="relative" ref={ref} style={{ height }}>
|
|
184
|
+
{width > 0 && empty && (
|
|
185
|
+
<p className="absolute inset-0 flex items-center justify-center rounded-item border border-neutral-200 border-dashed text-neutral-600 text-xs">
|
|
186
|
+
{emptyLabel}
|
|
187
|
+
</p>
|
|
188
|
+
)}
|
|
189
|
+
{width > 0 && loading && (
|
|
190
|
+
<RoseSkeleton fill={fill} half={half} height={height} width={width} />
|
|
191
|
+
)}
|
|
192
|
+
{width > 0 && drawn && (
|
|
193
|
+
<svg
|
|
194
|
+
aria-hidden="true"
|
|
195
|
+
className="block overflow-visible"
|
|
196
|
+
height={height}
|
|
197
|
+
onPointerLeave={() => setActive(null)}
|
|
198
|
+
onPointerMove={onPointerMove}
|
|
199
|
+
width={width}
|
|
200
|
+
>
|
|
201
|
+
{/* The frame's own rect and corner: the rings and wedges stay inside it. */}
|
|
202
|
+
<defs>
|
|
203
|
+
<clipPath id={`${id}-plot`}>
|
|
204
|
+
<rect
|
|
205
|
+
height={half * 2}
|
|
206
|
+
style={{ rx: 'var(--radius-item)', ry: 'var(--radius-item)' }}
|
|
207
|
+
width={half * 2}
|
|
208
|
+
x={cx - half}
|
|
209
|
+
y={cy - half}
|
|
210
|
+
/>
|
|
211
|
+
</clipPath>
|
|
212
|
+
</defs>
|
|
213
|
+
<g clipPath={`url(#${id}-plot)`}>
|
|
214
|
+
{ticks.values.slice(1).map(tick => (
|
|
215
|
+
<circle
|
|
216
|
+
cx={cx}
|
|
217
|
+
cy={cy}
|
|
218
|
+
fill="none"
|
|
219
|
+
key={tick}
|
|
220
|
+
r={radiusOf(tick)}
|
|
221
|
+
stroke="var(--color-chart-grid)"
|
|
222
|
+
/>
|
|
223
|
+
))}
|
|
224
|
+
|
|
225
|
+
{data.map((row, i) => {
|
|
226
|
+
const from = startOf(i);
|
|
227
|
+
const to = startOf(i) + step;
|
|
228
|
+
let reached = 0;
|
|
229
|
+
return (
|
|
230
|
+
<g
|
|
231
|
+
className="transition-opacity duration-150 motion-reduce:transition-none"
|
|
232
|
+
key={String(row[xKey])}
|
|
233
|
+
opacity={active === null || active === i ? 1 : 0.35}
|
|
234
|
+
>
|
|
235
|
+
{series.map((line, index) => {
|
|
236
|
+
const value = values[index]?.[i] ?? 0;
|
|
237
|
+
const inner = radiusOf(reached);
|
|
238
|
+
reached += value;
|
|
239
|
+
const outerEdge = radiusOf(reached);
|
|
240
|
+
if (value <= 0 || outerEdge - inner < 0.5) return null;
|
|
241
|
+
const color = chartColor(
|
|
242
|
+
line.color ?? seriesColor(index),
|
|
243
|
+
);
|
|
244
|
+
const edge = outerEdge - EDGE / 2;
|
|
245
|
+
// The edge stops short of the rounded corners, as the donut's does.
|
|
246
|
+
const inset = Math.min(
|
|
247
|
+
(CORNER + GAP / 2 + EDGE / 2) / edge,
|
|
248
|
+
(to - from) / 3,
|
|
249
|
+
);
|
|
250
|
+
const a = point(edge, from + inset);
|
|
251
|
+
const b = point(edge, to - inset);
|
|
252
|
+
return (
|
|
253
|
+
<g key={line.key}>
|
|
254
|
+
<path
|
|
255
|
+
d={ringSegmentPath(
|
|
256
|
+
cx,
|
|
257
|
+
cy,
|
|
258
|
+
outerEdge,
|
|
259
|
+
inner,
|
|
260
|
+
from,
|
|
261
|
+
to,
|
|
262
|
+
CORNER,
|
|
263
|
+
)}
|
|
264
|
+
fill={color}
|
|
265
|
+
fillOpacity={fill === 'solid' ? 1 : 0.2}
|
|
266
|
+
// The gap is the page drawn over the seam, so it keeps its
|
|
267
|
+
// width down to the middle, where an angle would close.
|
|
268
|
+
stroke="var(--color-chart-background)"
|
|
269
|
+
strokeWidth={GAP}
|
|
270
|
+
/>
|
|
271
|
+
{fill === 'tint' && outerEdge - inner >= 3 && (
|
|
272
|
+
<path
|
|
273
|
+
d={`M${a.x.toFixed(2)},${a.y.toFixed(2)} A${edge},${edge} 0 0 1 ${b.x.toFixed(2)},${b.y.toFixed(2)}`}
|
|
274
|
+
fill="none"
|
|
275
|
+
stroke={color}
|
|
276
|
+
strokeLinecap="round"
|
|
277
|
+
strokeWidth={EDGE}
|
|
278
|
+
/>
|
|
279
|
+
)}
|
|
280
|
+
</g>
|
|
281
|
+
);
|
|
282
|
+
})}
|
|
283
|
+
</g>
|
|
284
|
+
);
|
|
285
|
+
})}
|
|
286
|
+
</g>
|
|
287
|
+
|
|
288
|
+
{data.map((row, i) => {
|
|
289
|
+
if (i % every !== 0 && active !== i) return null;
|
|
290
|
+
const angle = i * step;
|
|
291
|
+
const place = outsideFrame(
|
|
292
|
+
cx,
|
|
293
|
+
cy,
|
|
294
|
+
half,
|
|
295
|
+
Math.sin(angle),
|
|
296
|
+
-Math.cos(angle),
|
|
297
|
+
);
|
|
298
|
+
return (
|
|
299
|
+
<text
|
|
300
|
+
className="text-xxs"
|
|
301
|
+
dominantBaseline="middle"
|
|
302
|
+
fill={
|
|
303
|
+
active === i
|
|
304
|
+
? 'var(--color-neutral-950)'
|
|
305
|
+
: 'var(--color-chart-label)'
|
|
306
|
+
}
|
|
307
|
+
key={String(row[xKey])}
|
|
308
|
+
textAnchor={place.anchor}
|
|
309
|
+
x={place.x}
|
|
310
|
+
y={place.y}
|
|
311
|
+
>
|
|
312
|
+
{String(row[xKey])}
|
|
313
|
+
</text>
|
|
314
|
+
);
|
|
315
|
+
})}
|
|
316
|
+
</svg>
|
|
317
|
+
)}
|
|
318
|
+
|
|
319
|
+
{/* The rings' values, once, along the quietest spoke. */}
|
|
320
|
+
{width > 0 &&
|
|
321
|
+
drawn &&
|
|
322
|
+
ticks.values.slice(1).map(tick => {
|
|
323
|
+
const at = point(radiusOf(tick), spoke);
|
|
324
|
+
return (
|
|
325
|
+
<span
|
|
326
|
+
className="pointer-events-none absolute -translate-x-1/2 -translate-y-1/2 rounded-full border border-neutral-200 bg-neutral-50 px-1.5 text-neutral-600 text-xxs tabular-nums leading-4"
|
|
327
|
+
key={tick}
|
|
328
|
+
style={{ left: at.x, top: at.y }}
|
|
329
|
+
>
|
|
330
|
+
{formatCompact(tick)}
|
|
331
|
+
</span>
|
|
332
|
+
);
|
|
333
|
+
})}
|
|
334
|
+
|
|
335
|
+
{drawn && shown !== null && tip && (
|
|
336
|
+
<div
|
|
337
|
+
className="pointer-events-none absolute z-10"
|
|
338
|
+
style={{
|
|
339
|
+
left: right ? tip.x : undefined,
|
|
340
|
+
right: right ? undefined : width - tip.x,
|
|
341
|
+
top: above ? undefined : tip.y,
|
|
342
|
+
bottom: above ? height - tip.y : undefined,
|
|
343
|
+
}}
|
|
344
|
+
>
|
|
345
|
+
<ChartTooltip
|
|
346
|
+
footer={
|
|
347
|
+
series.length > 1 ? (
|
|
348
|
+
<span className="flex justify-between gap-4 text-xs">
|
|
349
|
+
<span className="text-neutral-600">Total</span>
|
|
350
|
+
<span className="font-medium text-neutral-950 tabular-nums">
|
|
351
|
+
{formatValue(totals[shown] ?? 0)}
|
|
352
|
+
</span>
|
|
353
|
+
</span>
|
|
354
|
+
) : undefined
|
|
355
|
+
}
|
|
356
|
+
rows={series.map((line, index) => ({
|
|
357
|
+
color: line.color ?? seriesColor(index),
|
|
358
|
+
name: line.name ?? line.key,
|
|
359
|
+
value: formatValue(values[index]?.[shown] ?? 0),
|
|
360
|
+
}))}
|
|
361
|
+
title={String(data[shown]?.[xKey] ?? '')}
|
|
362
|
+
/>
|
|
363
|
+
</div>
|
|
364
|
+
)}
|
|
365
|
+
</div>
|
|
366
|
+
{!loading && (
|
|
367
|
+
<div className="sr-only">
|
|
368
|
+
<table>
|
|
369
|
+
<caption>{label}</caption>
|
|
370
|
+
<thead>
|
|
371
|
+
<tr>
|
|
372
|
+
<th scope="col">{xKey}</th>
|
|
373
|
+
{series.map(line => (
|
|
374
|
+
<th key={line.key} scope="col">
|
|
375
|
+
{line.name ?? line.key}
|
|
376
|
+
</th>
|
|
377
|
+
))}
|
|
378
|
+
</tr>
|
|
379
|
+
</thead>
|
|
380
|
+
<tbody>
|
|
381
|
+
{data.map((row, i) => (
|
|
382
|
+
<tr key={String(row[xKey])}>
|
|
383
|
+
<th scope="row">{String(row[xKey])}</th>
|
|
384
|
+
{series.map((line, index) => (
|
|
385
|
+
<td key={line.key}>
|
|
386
|
+
{formatValue(values[index]?.[i] ?? 0)}
|
|
387
|
+
</td>
|
|
388
|
+
))}
|
|
389
|
+
</tr>
|
|
390
|
+
))}
|
|
391
|
+
</tbody>
|
|
392
|
+
</table>
|
|
393
|
+
</div>
|
|
394
|
+
)}
|
|
395
|
+
</figure>
|
|
396
|
+
);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* The stand-in's wedges, as shares of the outer edge's value, round from twelve o'clock: a
|
|
401
|
+
* day's shape, quiet at night and long through the working hours, so a few reach far and a few
|
|
402
|
+
* stay near the middle.
|
|
403
|
+
*/
|
|
404
|
+
const SKELETON_REACH = [0.3, 0.16, 0.1, 0.14, 0.38, 0.7, 0.92, 0.8, 0.58, 0.66, 0.48, 0.42];
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* The stand-in's rings, as shares of the outer edge's value: two round values under the
|
|
408
|
+
* headroom, as a loaded chart draws them, with the longest wedge reaching past the last.
|
|
409
|
+
*/
|
|
410
|
+
const SKELETON_RINGS = [0.4, 0.8];
|
|
411
|
+
|
|
412
|
+
/** The stand-in's edge, a step stronger than its wash, as a wedge's line is over its tint. */
|
|
413
|
+
const SKELETON_EDGE = 'color-mix(in oklab, var(--color-neutral-950) 14%, transparent)';
|
|
414
|
+
|
|
415
|
+
/** A name's stand-in: a short bar at the 11px names' height. */
|
|
416
|
+
const SKELETON_NAME = { width: 14, height: 8 };
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* A wedge from the hole out to its reach, with its sides drawn in by half the gap, so the gap
|
|
420
|
+
* between two wedges keeps its width down to the middle as the loaded chart's does. A clip
|
|
421
|
+
* cannot be stroked, so the gap is drawn into the shape instead.
|
|
422
|
+
*/
|
|
423
|
+
const wedgePath = (
|
|
424
|
+
cx: number,
|
|
425
|
+
cy: number,
|
|
426
|
+
outer: number,
|
|
427
|
+
inner: number,
|
|
428
|
+
from: number,
|
|
429
|
+
to: number,
|
|
430
|
+
) => {
|
|
431
|
+
const at = (radius: number, angle: number) =>
|
|
432
|
+
`${(cx + radius * Math.sin(angle)).toFixed(2)},${(cy - radius * Math.cos(angle)).toFixed(2)}`;
|
|
433
|
+
const side = (radius: number) => Math.asin(Math.min(1, GAP / 2 / radius));
|
|
434
|
+
if (to - side(inner) <= from + side(inner)) return '';
|
|
435
|
+
return `M${at(outer, from + side(outer))} A${outer},${outer} 0 0 1 ${at(outer, to - side(outer))} L${at(inner, to - side(inner))} A${inner},${inner} 0 0 0 ${at(inner, from + side(inner))} Z`;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* A rose that is loading, with the depth of a loaded one: its rings stay, its wedges stand in
|
|
440
|
+
* the skeleton wash at a day's varied reach with their edges, the rings' values and the names
|
|
441
|
+
* round the outside are short bars where they will be, and the light crosses all of it. It is
|
|
442
|
+
* drawn in the circle the loaded chart takes, so nothing moves when the data lands.
|
|
443
|
+
*/
|
|
444
|
+
const RoseSkeleton = ({
|
|
445
|
+
width,
|
|
446
|
+
height,
|
|
447
|
+
half,
|
|
448
|
+
fill,
|
|
449
|
+
}: {
|
|
450
|
+
width: number;
|
|
451
|
+
height: number;
|
|
452
|
+
half: number;
|
|
453
|
+
fill: 'tint' | 'solid';
|
|
454
|
+
}) => {
|
|
455
|
+
const outer = Math.max(0, half - PAD);
|
|
456
|
+
if (outer <= 0) return null;
|
|
457
|
+
const cx = width / 2;
|
|
458
|
+
const cy = height / 2;
|
|
459
|
+
const hole = outer * HOLE;
|
|
460
|
+
const radiusOf = (share: number) => Math.sqrt(hole ** 2 + share * (outer ** 2 - hole ** 2));
|
|
461
|
+
const count = SKELETON_REACH.length;
|
|
462
|
+
const step = (Math.PI * 2) / count;
|
|
463
|
+
const startOf = (i: number) => (i - 0.5) * step;
|
|
464
|
+
const point = (radius: number, angle: number) => ({
|
|
465
|
+
x: cx + radius * Math.sin(angle),
|
|
466
|
+
y: cy - radius * Math.cos(angle),
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
const wash = SKELETON_REACH.map((share, i) =>
|
|
470
|
+
wedgePath(cx, cy, radiusOf(share), hole + GAP / 2, startOf(i), startOf(i) + step),
|
|
471
|
+
).join(' ');
|
|
472
|
+
// The edge as the loaded one is drawn: a band along the outside with round ends, short of the corners.
|
|
473
|
+
const edge = SKELETON_REACH.map((share, i) => {
|
|
474
|
+
const reach = radiusOf(share);
|
|
475
|
+
const inset = (CORNER + GAP / 2) / reach;
|
|
476
|
+
return ringSegmentPath(
|
|
477
|
+
cx,
|
|
478
|
+
cy,
|
|
479
|
+
reach,
|
|
480
|
+
reach - EDGE,
|
|
481
|
+
startOf(i) + inset,
|
|
482
|
+
startOf(i) + step - inset,
|
|
483
|
+
EDGE / 2,
|
|
484
|
+
);
|
|
485
|
+
}).join(' ');
|
|
486
|
+
const every = labelStep(count, half);
|
|
487
|
+
const spoke = startOf(quietestSpoke(SKELETON_REACH));
|
|
488
|
+
|
|
489
|
+
return (
|
|
490
|
+
<div aria-hidden className="absolute inset-0" data-slot="chart-skeleton">
|
|
491
|
+
<svg
|
|
492
|
+
aria-hidden="true"
|
|
493
|
+
className="absolute inset-0 block"
|
|
494
|
+
height={height}
|
|
495
|
+
width={width}
|
|
496
|
+
>
|
|
497
|
+
{SKELETON_RINGS.map(share => (
|
|
498
|
+
<circle
|
|
499
|
+
cx={cx}
|
|
500
|
+
cy={cy}
|
|
501
|
+
fill="none"
|
|
502
|
+
key={share}
|
|
503
|
+
r={radiusOf(share)}
|
|
504
|
+
stroke="var(--color-chart-grid)"
|
|
505
|
+
/>
|
|
506
|
+
))}
|
|
507
|
+
</svg>
|
|
508
|
+
<div className="skeleton absolute inset-0" style={{ clipPath: `path('${wash}')` }} />
|
|
509
|
+
{fill === 'tint' && (
|
|
510
|
+
<div
|
|
511
|
+
className="skeleton absolute inset-0"
|
|
512
|
+
style={{ backgroundColor: SKELETON_EDGE, clipPath: `path('${edge}')` }}
|
|
513
|
+
/>
|
|
514
|
+
)}
|
|
515
|
+
{SKELETON_REACH.map((_, i) => {
|
|
516
|
+
if (i % every !== 0) return null;
|
|
517
|
+
const angle = i * step;
|
|
518
|
+
const place = outsideFrame(cx, cy, half, Math.sin(angle), -Math.cos(angle));
|
|
519
|
+
const left =
|
|
520
|
+
place.anchor === 'middle'
|
|
521
|
+
? place.x - SKELETON_NAME.width / 2
|
|
522
|
+
: place.anchor === 'end'
|
|
523
|
+
? place.x - SKELETON_NAME.width
|
|
524
|
+
: place.x;
|
|
525
|
+
return (
|
|
526
|
+
<div
|
|
527
|
+
className="skeleton absolute rounded-chip"
|
|
528
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: the stand-in never reorders
|
|
529
|
+
key={i}
|
|
530
|
+
style={{
|
|
531
|
+
...SKELETON_NAME,
|
|
532
|
+
left,
|
|
533
|
+
top: place.y - SKELETON_NAME.height / 2,
|
|
534
|
+
}}
|
|
535
|
+
/>
|
|
536
|
+
);
|
|
537
|
+
})}
|
|
538
|
+
{/* The rings' values: the pill's own size, on the page's colour so the ring stops at it. */}
|
|
539
|
+
{SKELETON_RINGS.map(share => {
|
|
540
|
+
const at = point(radiusOf(share), spoke);
|
|
541
|
+
return (
|
|
542
|
+
<span
|
|
543
|
+
className="absolute -translate-x-1/2 -translate-y-1/2 rounded-full bg-neutral-50"
|
|
544
|
+
key={share}
|
|
545
|
+
style={{ left: at.x, top: at.y }}
|
|
546
|
+
>
|
|
547
|
+
<span className="skeleton block h-4.5 w-7 rounded-full" />
|
|
548
|
+
</span>
|
|
549
|
+
);
|
|
550
|
+
})}
|
|
551
|
+
</div>
|
|
552
|
+
);
|
|
553
|
+
};
|