@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,913 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { type CSSProperties, Fragment, 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 { PLOT_FRAME } from './lib/frame';
|
|
9
|
+
import { niceTicks, type Ticks } from './lib/scale';
|
|
10
|
+
import { useWidth } from './lib/use-size';
|
|
11
|
+
import { ChartTooltip, type ChartTooltipRow } from './tooltip';
|
|
12
|
+
|
|
13
|
+
export type BubbleChartProps<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 bubble. */
|
|
17
|
+
data: readonly Row[];
|
|
18
|
+
/** The field naming each bubble: "Northwind". */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The field read across. */
|
|
21
|
+
x: string;
|
|
22
|
+
/** The field read up. */
|
|
23
|
+
y: string;
|
|
24
|
+
/** The field each bubble's area shows. */
|
|
25
|
+
size: string;
|
|
26
|
+
/** The field a bubble's group is read from; its colour follows the group. */
|
|
27
|
+
group?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The groups in their order, with their names and colours: `series-1` to `series-5` by
|
|
30
|
+
* place unless given. Each `key` is a value of the `group` field. The groups found in the
|
|
31
|
+
* data are used, in the order met, when this is left out.
|
|
32
|
+
*/
|
|
33
|
+
groups?: readonly ChartSeries[];
|
|
34
|
+
/** What each measure is called in the readout and on its axis: "Seats". */
|
|
35
|
+
xLabel?: string;
|
|
36
|
+
yLabel?: string;
|
|
37
|
+
sizeLabel?: string;
|
|
38
|
+
formatX?: (value: number) => string;
|
|
39
|
+
formatY?: (value: number) => string;
|
|
40
|
+
formatSize?: (value: number) => string;
|
|
41
|
+
/**
|
|
42
|
+
* `log` for a measure that runs over several powers of ten, so the small ones are not
|
|
43
|
+
* all pressed into a corner; each step of the axis is then ten times the one before.
|
|
44
|
+
*/
|
|
45
|
+
xScale?: 'linear' | 'log';
|
|
46
|
+
yScale?: 'linear' | 'log';
|
|
47
|
+
/** How many of the largest bubbles have their names written beside them, where they fit. */
|
|
48
|
+
labels?: number;
|
|
49
|
+
/** A key of two or three circles, under the plot, saying what a bubble's size stands for. */
|
|
50
|
+
sizeKey?: boolean;
|
|
51
|
+
height?: number;
|
|
52
|
+
/** `tint`, the kit's look, a tint of each colour with a solid edge; `solid` fills each bubble. */
|
|
53
|
+
fill?: 'tint' | 'solid';
|
|
54
|
+
/** While the data loads: the chart's own shape stands in, in the skeleton wash, at the size it will have. */
|
|
55
|
+
loading?: boolean;
|
|
56
|
+
/** What the chart says when there is nothing to draw. */
|
|
57
|
+
emptyLabel?: string;
|
|
58
|
+
className?: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** The room under the plot for the x axis's values, and over it for the y axis's name. */
|
|
62
|
+
const BOTTOM = 20;
|
|
63
|
+
/** Nothing stands over the plot: the y axis is named in the plot's own corner. */
|
|
64
|
+
const TOP = 0;
|
|
65
|
+
/** The room between the plot's frame and its rules: none, the frame holds the data tight. */
|
|
66
|
+
const PAD = 0;
|
|
67
|
+
const EDGE = 1.5;
|
|
68
|
+
/** The smallest a bubble is drawn, however small its value, so it can still be pointed at. */
|
|
69
|
+
const LEAST = 3;
|
|
70
|
+
const LABEL_HEIGHT = 14;
|
|
71
|
+
/** The width of one character of an 11px label, near enough to keep two names apart. */
|
|
72
|
+
const CHAR = 6.2;
|
|
73
|
+
|
|
74
|
+
type Scale = Ticks & { log: boolean };
|
|
75
|
+
|
|
76
|
+
/** The round numbers of a measure read in powers of ten: 1, 2 and 5 of each. */
|
|
77
|
+
const ROUND = [1, 2, 5] as const;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The domain of a measure read in powers of ten, from the round number under its least to the
|
|
81
|
+
* one over its most, and the rules across it: 1, 2 and 5 of each power while there is room
|
|
82
|
+
* for them, the powers alone when there is not.
|
|
83
|
+
*/
|
|
84
|
+
const logTicks = (low: number, high: number, most: number): Scale => {
|
|
85
|
+
const rounds = (from: number, to: number) => {
|
|
86
|
+
const out: number[] = [];
|
|
87
|
+
for (
|
|
88
|
+
let power = Math.floor(Math.log10(from)) - 1;
|
|
89
|
+
power <= Math.ceil(Math.log10(to)) + 1;
|
|
90
|
+
power++
|
|
91
|
+
) {
|
|
92
|
+
for (const step of ROUND) out.push(step * 10 ** power);
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
};
|
|
96
|
+
const all = rounds(low, high);
|
|
97
|
+
const min = [...all].reverse().find(value => value <= low * 1.0001) ?? low;
|
|
98
|
+
const max = all.find(value => value >= high / 1.0001) ?? high;
|
|
99
|
+
const inside = all.filter(value => value >= min / 1.0001 && value <= max * 1.0001);
|
|
100
|
+
const powers = inside.filter(
|
|
101
|
+
value => Math.abs(Math.log10(value) - Math.round(Math.log10(value))) < 1e-9,
|
|
102
|
+
);
|
|
103
|
+
return {
|
|
104
|
+
values: inside.length <= most ? inside : powers,
|
|
105
|
+
min,
|
|
106
|
+
max: max > min ? max : min * 10,
|
|
107
|
+
log: true,
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const scaleOf = (values: readonly number[], log: boolean, most: number): Scale => {
|
|
112
|
+
const positive = values.filter(value => value > 0);
|
|
113
|
+
if (log && positive.length) return logTicks(Math.min(...positive), Math.max(...positive), most);
|
|
114
|
+
return { ...niceTicks(0, Math.max(0, ...values), 4), log: false };
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Where a value sits along `length`, the scale's floor at 0. */
|
|
118
|
+
const place = (value: number, scale: Scale, length: number) => {
|
|
119
|
+
if (scale.log) {
|
|
120
|
+
const span = Math.log10(scale.max / scale.min) || 1;
|
|
121
|
+
return (Math.log10(Math.max(value, scale.min) / scale.min) / span) * length;
|
|
122
|
+
}
|
|
123
|
+
return scale.max > scale.min ? ((value - scale.min) / (scale.max - scale.min)) * length : 0;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
type Box = { left: number; top: number; right: number; bottom: number };
|
|
127
|
+
|
|
128
|
+
const overlaps = (a: Box, b: Box) =>
|
|
129
|
+
a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Things that have three measures, as bubbles: one measure across, one up, and the third in
|
|
133
|
+
* each bubble's area, which grows as the value so a bubble twice the value is twice the ink.
|
|
134
|
+
* A fourth, a group, may colour them.
|
|
135
|
+
*
|
|
136
|
+
* The largest bubbles are drawn first, so a small one is never hidden under a large one, and
|
|
137
|
+
* the few largest have their names written beside them wherever a name fits clear of the
|
|
138
|
+
* others. The largest bubble's radius is taken from the room the plot has, so a phone draws
|
|
139
|
+
* smaller bubbles rather than a heap. Pointing at a bubble reads all of it out while the rest
|
|
140
|
+
* step back.
|
|
141
|
+
*/
|
|
142
|
+
export const BubbleChart = <Row extends ChartRow>({
|
|
143
|
+
'aria-label': label,
|
|
144
|
+
data: given,
|
|
145
|
+
name: nameKey,
|
|
146
|
+
x: xKey,
|
|
147
|
+
y: yKey,
|
|
148
|
+
size: sizeKey,
|
|
149
|
+
group: groupKey,
|
|
150
|
+
groups: givenGroups,
|
|
151
|
+
xLabel = xKey,
|
|
152
|
+
yLabel = yKey,
|
|
153
|
+
sizeLabel = sizeKey,
|
|
154
|
+
formatX = formatNumber,
|
|
155
|
+
formatY = formatNumber,
|
|
156
|
+
formatSize = formatNumber,
|
|
157
|
+
xScale = 'linear',
|
|
158
|
+
yScale = 'linear',
|
|
159
|
+
labels = 3,
|
|
160
|
+
sizeKey: showSizeKey = true,
|
|
161
|
+
height = 340,
|
|
162
|
+
fill = 'tint',
|
|
163
|
+
loading = false,
|
|
164
|
+
emptyLabel = 'Nothing to show yet',
|
|
165
|
+
className,
|
|
166
|
+
}: BubbleChartProps<Row>) => {
|
|
167
|
+
const id = useId().replace(/[^a-zA-Z0-9_-]/g, '');
|
|
168
|
+
const [ref, width] = useWidth<HTMLDivElement>();
|
|
169
|
+
const [active, setActive] = useState<number | null>(null);
|
|
170
|
+
|
|
171
|
+
// While it loads the chart draws its stand-in, and nothing of the old answer.
|
|
172
|
+
const data: readonly Row[] = loading ? [] : given;
|
|
173
|
+
const points = data
|
|
174
|
+
.map((row, index) => ({
|
|
175
|
+
index,
|
|
176
|
+
name: String(row[nameKey] ?? ''),
|
|
177
|
+
x: Number(row[xKey]) || 0,
|
|
178
|
+
y: Number(row[yKey]) || 0,
|
|
179
|
+
size: Math.max(0, Number(row[sizeKey]) || 0),
|
|
180
|
+
group: groupKey ? String(row[groupKey] ?? '') : '',
|
|
181
|
+
}))
|
|
182
|
+
.filter(point => Number.isFinite(point.x) && Number.isFinite(point.y));
|
|
183
|
+
|
|
184
|
+
const groups: ChartSeries[] = givenGroups
|
|
185
|
+
? [...givenGroups]
|
|
186
|
+
: [...new Set(points.map(point => point.group))].map(key => ({ key }));
|
|
187
|
+
const colorOf = (group: string) => {
|
|
188
|
+
const index = groups.findIndex(item => item.key === group);
|
|
189
|
+
const item = groups[index];
|
|
190
|
+
return item?.color ?? (groupKey && index >= 0 ? seriesColor(index) : seriesColor(0));
|
|
191
|
+
};
|
|
192
|
+
const groupName = (group: string) => groups.find(item => item.key === group)?.name ?? group;
|
|
193
|
+
|
|
194
|
+
const xTick = formatX === formatNumber ? formatCompact : formatX;
|
|
195
|
+
const yTick = formatY === formatNumber ? formatCompact : formatY;
|
|
196
|
+
const plotHeight = Math.max(0, height - BOTTOM - TOP - PAD * 2);
|
|
197
|
+
// Where the plot starts, inside its frame.
|
|
198
|
+
const plotTop = TOP + PAD;
|
|
199
|
+
// A rule every 36px up at the closest, and every 72px across, where the values are wider.
|
|
200
|
+
const ys = scaleOf(
|
|
201
|
+
points.map(point => point.y),
|
|
202
|
+
yScale === 'log',
|
|
203
|
+
Math.max(2, Math.floor(plotHeight / 36)),
|
|
204
|
+
);
|
|
205
|
+
// The y values' gutter, as wide as the widest of them; while loading, as wide as a short figure.
|
|
206
|
+
const gutter = loading
|
|
207
|
+
? SKELETON_GUTTER
|
|
208
|
+
: Math.ceil(Math.max(1, ...ys.values.map(tick => yTick(tick).length)) * CHAR) + 8 + PAD;
|
|
209
|
+
const plotWidth = Math.max(0, width - gutter - PAD);
|
|
210
|
+
const xs = scaleOf(
|
|
211
|
+
points.map(point => point.x),
|
|
212
|
+
xScale === 'log',
|
|
213
|
+
Math.max(2, Math.floor(plotWidth / 72)),
|
|
214
|
+
);
|
|
215
|
+
const biggest = Math.max(0, ...points.map(point => point.size));
|
|
216
|
+
const empty = points.length === 0;
|
|
217
|
+
|
|
218
|
+
// The largest bubble takes a share of the plot's shorter side, within reason.
|
|
219
|
+
const most = Math.max(8, Math.min(36, Math.min(plotWidth, plotHeight) * 0.1));
|
|
220
|
+
const radiusOf = (value: number) =>
|
|
221
|
+
biggest > 0 ? Math.max(LEAST, Math.sqrt(value / biggest) * most) : LEAST;
|
|
222
|
+
// The plot keeps the largest bubble's radius clear at its top and right, and a small one's at
|
|
223
|
+
// its foot and left, and the frame's hairline clear of both, so a bubble at either end of a
|
|
224
|
+
// measure stays whole inside the frame rather than being cut by it.
|
|
225
|
+
const low = LEAST + 8;
|
|
226
|
+
const high = most + 8;
|
|
227
|
+
const xOf = (value: number) =>
|
|
228
|
+
gutter + low + place(value, xs, Math.max(0, plotWidth - low - high));
|
|
229
|
+
const yOf = (value: number) =>
|
|
230
|
+
plotTop + plotHeight - low - place(value, ys, Math.max(0, plotHeight - low - high));
|
|
231
|
+
|
|
232
|
+
const drawn = points
|
|
233
|
+
.map(point => ({ ...point, cx: xOf(point.x), cy: yOf(point.y), r: radiusOf(point.size) }))
|
|
234
|
+
// The largest first, so the small ones lie on top and stay in reach.
|
|
235
|
+
.sort((a, b) => b.r - a.r);
|
|
236
|
+
|
|
237
|
+
// Names beside the few largest, on whichever side has room clear of the names already placed.
|
|
238
|
+
const named: { index: number; x: number; y: number; anchor: 'start' | 'end' | 'middle' }[] = [];
|
|
239
|
+
const taken: Box[] = [];
|
|
240
|
+
for (const point of drawn.slice(0, Math.max(0, labels))) {
|
|
241
|
+
const w = point.name.length * CHAR;
|
|
242
|
+
const h = LABEL_HEIGHT;
|
|
243
|
+
// Beside it first, then over and under it, then off its four shoulders.
|
|
244
|
+
const side = point.r + 4;
|
|
245
|
+
const shoulder = point.r * 0.72 + 3;
|
|
246
|
+
const tries = [
|
|
247
|
+
{ x: point.cx + side, y: point.cy, anchor: 'start' as const, left: point.cx + side },
|
|
248
|
+
{ x: point.cx - side, y: point.cy, anchor: 'end' as const, left: point.cx - side - w },
|
|
249
|
+
{
|
|
250
|
+
x: point.cx,
|
|
251
|
+
y: point.cy - point.r - 9,
|
|
252
|
+
anchor: 'middle' as const,
|
|
253
|
+
left: point.cx - w / 2,
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
x: point.cx,
|
|
257
|
+
y: point.cy + point.r + 9,
|
|
258
|
+
anchor: 'middle' as const,
|
|
259
|
+
left: point.cx - w / 2,
|
|
260
|
+
},
|
|
261
|
+
...[-1, 1].flatMap(up => [
|
|
262
|
+
{
|
|
263
|
+
x: point.cx + shoulder,
|
|
264
|
+
y: point.cy + up * (shoulder + 5),
|
|
265
|
+
anchor: 'start' as const,
|
|
266
|
+
left: point.cx + shoulder,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
x: point.cx - shoulder,
|
|
270
|
+
y: point.cy + up * (shoulder + 5),
|
|
271
|
+
anchor: 'end' as const,
|
|
272
|
+
left: point.cx - shoulder - w,
|
|
273
|
+
},
|
|
274
|
+
]),
|
|
275
|
+
];
|
|
276
|
+
for (const attempt of tries) {
|
|
277
|
+
const box = {
|
|
278
|
+
left: attempt.left,
|
|
279
|
+
top: attempt.y - h / 2,
|
|
280
|
+
right: attempt.left + w,
|
|
281
|
+
bottom: attempt.y + h / 2,
|
|
282
|
+
};
|
|
283
|
+
const inside =
|
|
284
|
+
// A name stays inside the frame, clear of its line.
|
|
285
|
+
box.left >= gutter - PAD + 4 &&
|
|
286
|
+
box.right <= gutter + plotWidth + PAD - 4 &&
|
|
287
|
+
box.top >= TOP + 4 &&
|
|
288
|
+
box.bottom <= plotTop + plotHeight + PAD - 4;
|
|
289
|
+
// Clear of the other bubbles too, but for a sliver of their edge.
|
|
290
|
+
const onBubble = drawn.some(
|
|
291
|
+
other =>
|
|
292
|
+
other !== point &&
|
|
293
|
+
Math.hypot(
|
|
294
|
+
other.cx - Math.max(box.left, Math.min(other.cx, box.right)),
|
|
295
|
+
other.cy - Math.max(box.top, Math.min(other.cy, box.bottom)),
|
|
296
|
+
) <
|
|
297
|
+
other.r - 1,
|
|
298
|
+
);
|
|
299
|
+
if (inside && !onBubble && !taken.some(other => overlaps(box, other))) {
|
|
300
|
+
taken.push(box);
|
|
301
|
+
named.push({
|
|
302
|
+
index: point.index,
|
|
303
|
+
x: attempt.x,
|
|
304
|
+
y: attempt.y,
|
|
305
|
+
anchor: attempt.anchor,
|
|
306
|
+
});
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// The bubble under the pointer: the smallest one it is inside, else the nearest within reach.
|
|
313
|
+
const onPointerMove = (event: PointerEvent<SVGSVGElement>) => {
|
|
314
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
315
|
+
const px = event.clientX - box.left;
|
|
316
|
+
const py = event.clientY - box.top;
|
|
317
|
+
let found: number | null = null;
|
|
318
|
+
let best = Number.POSITIVE_INFINITY;
|
|
319
|
+
for (const point of drawn) {
|
|
320
|
+
const distance = Math.hypot(point.cx - px, point.cy - py);
|
|
321
|
+
const reach = point.r + 6;
|
|
322
|
+
// Inside a bubble, a smaller one wins; outside every bubble, the nearest edge does.
|
|
323
|
+
const score = distance <= point.r ? point.r - 1000 : distance - point.r;
|
|
324
|
+
if (distance <= reach && score < best) {
|
|
325
|
+
best = score;
|
|
326
|
+
found = point.index;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
setActive(found);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const shown = active !== null ? drawn.find(point => point.index === active) : undefined;
|
|
333
|
+
const right = shown ? shown.cx < gutter + plotWidth / 2 : true;
|
|
334
|
+
|
|
335
|
+
// The key's circles: the round number under the largest value, then a tenth and a hundredth
|
|
336
|
+
// of it, for as long as the circle is still larger than the least a bubble is drawn.
|
|
337
|
+
const top = biggest > 0 ? 10 ** Math.floor(Math.log10(biggest)) : 0;
|
|
338
|
+
const keyTop =
|
|
339
|
+
top > 0 ? ([5, 2, 1].map(step => step * top).find(value => value <= biggest) ?? top) : 0;
|
|
340
|
+
const keyValues = [keyTop / 100, keyTop / 10, keyTop].filter(
|
|
341
|
+
value => value > 0 && radiusOf(value) > LEAST + 1,
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
// The size key stands inside the plot, in the first corner no bubble reaches; a plot with
|
|
345
|
+
// none free has it underneath instead.
|
|
346
|
+
const keyRadii = keyValues
|
|
347
|
+
.slice(-2)
|
|
348
|
+
.map(value => ({ r: radiusOf(value), text: formatSize(value) }));
|
|
349
|
+
const keyBox = sizeKeyBox(keyRadii);
|
|
350
|
+
const withKey = showSizeKey && !empty && keyRadii.length > 0 && width > 0;
|
|
351
|
+
const keyRight = gutter + plotWidth - 12 - keyBox.width;
|
|
352
|
+
const keyFoot = plotTop + plotHeight - 12 - keyBox.height;
|
|
353
|
+
const keyAt = [
|
|
354
|
+
{ x: keyRight, y: keyFoot },
|
|
355
|
+
{ x: gutter + 12, y: plotTop + 12 },
|
|
356
|
+
{ x: gutter + 12, y: keyFoot },
|
|
357
|
+
{ x: keyRight, y: plotTop + 12 },
|
|
358
|
+
].find(
|
|
359
|
+
corner =>
|
|
360
|
+
keyBox.width < plotWidth / 2 &&
|
|
361
|
+
keyBox.height < plotHeight / 2 &&
|
|
362
|
+
drawn.every(point => {
|
|
363
|
+
const dx =
|
|
364
|
+
point.cx - Math.max(corner.x, Math.min(point.cx, corner.x + keyBox.width));
|
|
365
|
+
const dy =
|
|
366
|
+
point.cy - Math.max(corner.y, Math.min(point.cy, corner.y + keyBox.height));
|
|
367
|
+
return Math.hypot(dx, dy) > point.r + 8;
|
|
368
|
+
}),
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
const rows = (point: (typeof drawn)[number]): ChartTooltipRow[] => [
|
|
372
|
+
...(groupKey
|
|
373
|
+
? [{ name: groupName(point.group), value: '', color: colorOf(point.group) }]
|
|
374
|
+
: []),
|
|
375
|
+
{ name: xLabel, value: formatX(point.x) },
|
|
376
|
+
{ name: yLabel, value: formatY(point.y) },
|
|
377
|
+
{ name: sizeLabel, value: formatSize(point.size) },
|
|
378
|
+
];
|
|
379
|
+
|
|
380
|
+
return (
|
|
381
|
+
<figure
|
|
382
|
+
aria-busy={loading || undefined}
|
|
383
|
+
aria-label={label}
|
|
384
|
+
className={cn('relative m-0 min-w-0', className)}
|
|
385
|
+
data-slot="bubble-chart"
|
|
386
|
+
>
|
|
387
|
+
<div className="relative" ref={ref} style={{ height }}>
|
|
388
|
+
{width > 0 && empty && !loading && (
|
|
389
|
+
<p className="absolute inset-0 flex items-center justify-center rounded-item border border-neutral-200 border-dashed text-neutral-600 text-xs">
|
|
390
|
+
{emptyLabel}
|
|
391
|
+
</p>
|
|
392
|
+
)}
|
|
393
|
+
{width > 0 && (!empty || loading) && (
|
|
394
|
+
// The plot's own place in the card: the bubbles and rules inside, the labels out.
|
|
395
|
+
<div
|
|
396
|
+
aria-hidden
|
|
397
|
+
className={PLOT_FRAME}
|
|
398
|
+
data-slot="bubble-chart-plot"
|
|
399
|
+
style={{
|
|
400
|
+
height: plotHeight + PAD * 2,
|
|
401
|
+
left: gutter - PAD,
|
|
402
|
+
top: TOP,
|
|
403
|
+
width: plotWidth + PAD * 2,
|
|
404
|
+
}}
|
|
405
|
+
/>
|
|
406
|
+
)}
|
|
407
|
+
{width > 0 && loading && (
|
|
408
|
+
<BubbleSkeleton
|
|
409
|
+
gutter={gutter}
|
|
410
|
+
height={plotHeight}
|
|
411
|
+
most={most}
|
|
412
|
+
names={Math.min(3, Math.max(0, labels))}
|
|
413
|
+
top={plotTop}
|
|
414
|
+
width={plotWidth}
|
|
415
|
+
yLabel={yLabel}
|
|
416
|
+
/>
|
|
417
|
+
)}
|
|
418
|
+
{width > 0 && !empty && (
|
|
419
|
+
<svg
|
|
420
|
+
aria-hidden="true"
|
|
421
|
+
className="block overflow-visible"
|
|
422
|
+
height={height}
|
|
423
|
+
onPointerLeave={() => setActive(null)}
|
|
424
|
+
onPointerMove={onPointerMove}
|
|
425
|
+
width={width}
|
|
426
|
+
>
|
|
427
|
+
{/* The y axis's name in the plot's top corner, the x axis's at the end of its own. */}
|
|
428
|
+
<text
|
|
429
|
+
className="text-xxs"
|
|
430
|
+
dominantBaseline="middle"
|
|
431
|
+
fill="var(--color-chart-label)"
|
|
432
|
+
x={gutter + 10}
|
|
433
|
+
y={plotTop + 14}
|
|
434
|
+
>
|
|
435
|
+
{yLabel}
|
|
436
|
+
</text>
|
|
437
|
+
|
|
438
|
+
{ys.values.map(tick => (
|
|
439
|
+
<text
|
|
440
|
+
className="text-xxs tabular-nums"
|
|
441
|
+
dominantBaseline="middle"
|
|
442
|
+
fill="var(--color-chart-label)"
|
|
443
|
+
key={`y-${tick}`}
|
|
444
|
+
textAnchor="end"
|
|
445
|
+
x={gutter - PAD - 8}
|
|
446
|
+
y={yOf(tick)}
|
|
447
|
+
>
|
|
448
|
+
{yTick(tick)}
|
|
449
|
+
</text>
|
|
450
|
+
))}
|
|
451
|
+
{xs.values.map((tick, i) => {
|
|
452
|
+
const last = i === xs.values.length - 1;
|
|
453
|
+
return (
|
|
454
|
+
<text
|
|
455
|
+
className="text-xxs tabular-nums"
|
|
456
|
+
fill="var(--color-chart-label)"
|
|
457
|
+
key={`x-${tick}`}
|
|
458
|
+
textAnchor={last ? 'end' : i === 0 ? 'start' : 'middle'}
|
|
459
|
+
x={xOf(tick)}
|
|
460
|
+
y={plotTop + plotHeight + PAD + 16}
|
|
461
|
+
>
|
|
462
|
+
{last ? `${xTick(tick)} ${xLabel.toLowerCase()}` : xTick(tick)}
|
|
463
|
+
</text>
|
|
464
|
+
);
|
|
465
|
+
})}
|
|
466
|
+
|
|
467
|
+
{/*
|
|
468
|
+
* The frame's own rect and corner: the rules, the bubbles and their
|
|
469
|
+
* names are held inside it, so nothing runs past its hairline.
|
|
470
|
+
*/}
|
|
471
|
+
<defs>
|
|
472
|
+
<clipPath id={`${id}-plot`}>
|
|
473
|
+
<rect
|
|
474
|
+
height={plotHeight + PAD * 2}
|
|
475
|
+
style={{ rx: 'var(--radius-item)', ry: 'var(--radius-item)' }}
|
|
476
|
+
width={plotWidth + PAD * 2}
|
|
477
|
+
x={gutter - PAD}
|
|
478
|
+
y={TOP}
|
|
479
|
+
/>
|
|
480
|
+
</clipPath>
|
|
481
|
+
</defs>
|
|
482
|
+
<g clipPath={`url(#${id}-plot)`}>
|
|
483
|
+
{ys.values
|
|
484
|
+
// A rule on the frame's own edge would only thicken it.
|
|
485
|
+
.filter(
|
|
486
|
+
tick =>
|
|
487
|
+
Math.abs(yOf(tick) - plotTop) > 4 &&
|
|
488
|
+
Math.abs(yOf(tick) - plotTop - plotHeight) > 4,
|
|
489
|
+
)
|
|
490
|
+
.map(tick => (
|
|
491
|
+
<line
|
|
492
|
+
key={`y-${tick}`}
|
|
493
|
+
stroke="var(--color-chart-grid)"
|
|
494
|
+
x1={gutter}
|
|
495
|
+
x2={gutter + plotWidth}
|
|
496
|
+
y1={yOf(tick)}
|
|
497
|
+
y2={yOf(tick)}
|
|
498
|
+
/>
|
|
499
|
+
))}
|
|
500
|
+
{xs.values
|
|
501
|
+
.filter(
|
|
502
|
+
tick =>
|
|
503
|
+
Math.abs(xOf(tick) - gutter) > 4 &&
|
|
504
|
+
Math.abs(xOf(tick) - gutter - plotWidth) > 4,
|
|
505
|
+
)
|
|
506
|
+
.map(tick => (
|
|
507
|
+
<line
|
|
508
|
+
key={`x-${tick}`}
|
|
509
|
+
stroke="var(--color-chart-grid)"
|
|
510
|
+
x1={xOf(tick)}
|
|
511
|
+
x2={xOf(tick)}
|
|
512
|
+
y1={plotTop}
|
|
513
|
+
y2={plotTop + plotHeight}
|
|
514
|
+
/>
|
|
515
|
+
))}
|
|
516
|
+
|
|
517
|
+
{shown && (
|
|
518
|
+
// Two quiet rules from the bubble back to its axes, to read it off them.
|
|
519
|
+
<g stroke="var(--color-neutral-400)" strokeDasharray="2 3">
|
|
520
|
+
<line
|
|
521
|
+
x1={gutter}
|
|
522
|
+
x2={shown.cx - shown.r}
|
|
523
|
+
y1={shown.cy}
|
|
524
|
+
y2={shown.cy}
|
|
525
|
+
/>
|
|
526
|
+
<line
|
|
527
|
+
x1={shown.cx}
|
|
528
|
+
x2={shown.cx}
|
|
529
|
+
y1={shown.cy + shown.r}
|
|
530
|
+
y2={plotTop + plotHeight}
|
|
531
|
+
/>
|
|
532
|
+
</g>
|
|
533
|
+
)}
|
|
534
|
+
|
|
535
|
+
{drawn.map(point => {
|
|
536
|
+
const color = chartColor(colorOf(point.group));
|
|
537
|
+
return (
|
|
538
|
+
<circle
|
|
539
|
+
className="transition-opacity duration-150 motion-reduce:transition-none"
|
|
540
|
+
cx={point.cx}
|
|
541
|
+
cy={point.cy}
|
|
542
|
+
fill={
|
|
543
|
+
fill === 'solid'
|
|
544
|
+
? color
|
|
545
|
+
: `color-mix(in oklab, ${color} 20%, var(--color-chart-background))`
|
|
546
|
+
}
|
|
547
|
+
key={point.index}
|
|
548
|
+
opacity={
|
|
549
|
+
active === null || active === point.index ? 1 : 0.35
|
|
550
|
+
}
|
|
551
|
+
r={Math.max(0.5, point.r - EDGE / 2)}
|
|
552
|
+
stroke={
|
|
553
|
+
fill === 'solid'
|
|
554
|
+
? 'var(--color-chart-background)'
|
|
555
|
+
: color
|
|
556
|
+
}
|
|
557
|
+
strokeWidth={fill === 'solid' ? 1 : EDGE}
|
|
558
|
+
/>
|
|
559
|
+
);
|
|
560
|
+
})}
|
|
561
|
+
{shown && (
|
|
562
|
+
// The one pointed at, again on top, so a bubble over it cannot hide it.
|
|
563
|
+
<circle
|
|
564
|
+
cx={shown.cx}
|
|
565
|
+
cy={shown.cy}
|
|
566
|
+
fill={
|
|
567
|
+
fill === 'solid'
|
|
568
|
+
? chartColor(colorOf(shown.group))
|
|
569
|
+
: `color-mix(in oklab, ${chartColor(colorOf(shown.group))} 20%, var(--color-chart-background))`
|
|
570
|
+
}
|
|
571
|
+
r={Math.max(0.5, shown.r - EDGE / 2)}
|
|
572
|
+
stroke={chartColor(colorOf(shown.group))}
|
|
573
|
+
strokeWidth={2}
|
|
574
|
+
/>
|
|
575
|
+
)}
|
|
576
|
+
|
|
577
|
+
{named.map(item => (
|
|
578
|
+
<text
|
|
579
|
+
className="text-xxs transition-opacity duration-150 motion-reduce:transition-none"
|
|
580
|
+
dominantBaseline="middle"
|
|
581
|
+
fill="var(--color-neutral-600)"
|
|
582
|
+
key={item.index}
|
|
583
|
+
opacity={active === null || active === item.index ? 1 : 0.35}
|
|
584
|
+
textAnchor={item.anchor}
|
|
585
|
+
x={item.x}
|
|
586
|
+
y={item.y}
|
|
587
|
+
>
|
|
588
|
+
{drawn.find(point => point.index === item.index)?.name}
|
|
589
|
+
</text>
|
|
590
|
+
))}
|
|
591
|
+
</g>
|
|
592
|
+
</svg>
|
|
593
|
+
)}
|
|
594
|
+
|
|
595
|
+
{withKey && keyAt && (
|
|
596
|
+
<SizeKey
|
|
597
|
+
label={sizeLabel}
|
|
598
|
+
radii={keyRadii}
|
|
599
|
+
style={{ left: keyAt.x, position: 'absolute', top: keyAt.y }}
|
|
600
|
+
/>
|
|
601
|
+
)}
|
|
602
|
+
|
|
603
|
+
{shown && (
|
|
604
|
+
<div
|
|
605
|
+
className="pointer-events-none absolute z-10"
|
|
606
|
+
style={{
|
|
607
|
+
left: right ? shown.cx + shown.r + 10 : undefined,
|
|
608
|
+
right: right ? undefined : width - shown.cx + shown.r + 10,
|
|
609
|
+
top: Math.max(0, Math.min(height - 132, shown.cy - 40)),
|
|
610
|
+
}}
|
|
611
|
+
>
|
|
612
|
+
<ChartTooltip rows={rows(shown)} title={shown.name} />
|
|
613
|
+
</div>
|
|
614
|
+
)}
|
|
615
|
+
</div>
|
|
616
|
+
|
|
617
|
+
{withKey && !keyAt && <SizeKey label={sizeLabel} radii={keyRadii} />}
|
|
618
|
+
|
|
619
|
+
<div className="sr-only">
|
|
620
|
+
<table>
|
|
621
|
+
<caption>{label}</caption>
|
|
622
|
+
<thead>
|
|
623
|
+
<tr>
|
|
624
|
+
<th scope="col">{nameKey}</th>
|
|
625
|
+
{groupKey && <th scope="col">{groupKey}</th>}
|
|
626
|
+
<th scope="col">{xLabel}</th>
|
|
627
|
+
<th scope="col">{yLabel}</th>
|
|
628
|
+
<th scope="col">{sizeLabel}</th>
|
|
629
|
+
</tr>
|
|
630
|
+
</thead>
|
|
631
|
+
<tbody>
|
|
632
|
+
{points.map(point => (
|
|
633
|
+
<tr key={point.index}>
|
|
634
|
+
<th scope="row">{point.name}</th>
|
|
635
|
+
{groupKey && <td>{groupName(point.group)}</td>}
|
|
636
|
+
<td>{formatX(point.x)}</td>
|
|
637
|
+
<td>{formatY(point.y)}</td>
|
|
638
|
+
<td>{formatSize(point.size)}</td>
|
|
639
|
+
</tr>
|
|
640
|
+
))}
|
|
641
|
+
</tbody>
|
|
642
|
+
</table>
|
|
643
|
+
</div>
|
|
644
|
+
</figure>
|
|
645
|
+
);
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
/** The stand-in's y gutter: room for a figure of six characters, "10,000", as most axes need. */
|
|
649
|
+
const SKELETON_GUTTER = Math.ceil(6 * CHAR) + 8 + PAD;
|
|
650
|
+
|
|
651
|
+
/** Where the stand-in's rules sit up the plot, as shares of its height: three, as a loaded one has. */
|
|
652
|
+
const SKELETON_RULES = [0.25, 0.5, 0.75];
|
|
653
|
+
|
|
654
|
+
/** The room between the stand-in's rules across, near what the loaded axis keeps between its values. */
|
|
655
|
+
const SKELETON_STEP = 96;
|
|
656
|
+
|
|
657
|
+
/** The stand-in's values, as widths: figures up the side, and shorter counts along the foot. */
|
|
658
|
+
const SKELETON_FIGURES = [24, 32, 36];
|
|
659
|
+
const SKELETON_COUNTS = [12, 16, 20, 16];
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* The stand-in's bubbles, largest first, as shares of the plot (`x` across, `y` up) and of the
|
|
663
|
+
* largest radius: a loose climb from small at the foot to large at the top, as three measures of
|
|
664
|
+
* one thing tend to run together. The largest carry a name's width and the side it stands on.
|
|
665
|
+
*/
|
|
666
|
+
const SKELETON_BUBBLES: {
|
|
667
|
+
x: number;
|
|
668
|
+
y: number;
|
|
669
|
+
size: number;
|
|
670
|
+
name?: { width: number; side: 'start' | 'end' };
|
|
671
|
+
}[] = [
|
|
672
|
+
{ x: 0.9, y: 0.86, size: 1, name: { width: 52, side: 'end' } },
|
|
673
|
+
{ x: 0.66, y: 0.6, size: 0.8, name: { width: 40, side: 'start' } },
|
|
674
|
+
{ x: 0.44, y: 0.5, size: 0.6, name: { width: 44, side: 'end' } },
|
|
675
|
+
{ x: 0.58, y: 0.26, size: 0.44 },
|
|
676
|
+
{ x: 0.26, y: 0.36, size: 0.38 },
|
|
677
|
+
{ x: 0.14, y: 0.12, size: 0.28 },
|
|
678
|
+
{ x: 0.34, y: 0.1, size: 0.22 },
|
|
679
|
+
];
|
|
680
|
+
|
|
681
|
+
/** The stand-in's edges, a step stronger than its wash, as a bubble's edge is over its tint. */
|
|
682
|
+
const SKELETON_EDGE = 'color-mix(in oklab, var(--color-neutral-950) 14%, transparent)';
|
|
683
|
+
|
|
684
|
+
/** A circle's 1.5px edge alone, as a mask: the bubble's own edge over its tint. */
|
|
685
|
+
const SKELETON_RING =
|
|
686
|
+
'radial-gradient(closest-side, transparent calc(100% - 2px), black calc(100% - 1.25px))';
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* A bubble chart that is loading, with the depth of a loaded one: its frame and grid stay, its
|
|
690
|
+
* axis keeps its name, and bubbles of several sizes stand in the skeleton wash, each with its
|
|
691
|
+
* edge, spread as data spreads. Short bars stand where the axes' values and the largest names
|
|
692
|
+
* will. It takes the plot's room, so nothing moves when the data lands.
|
|
693
|
+
*/
|
|
694
|
+
const BubbleSkeleton = ({
|
|
695
|
+
gutter,
|
|
696
|
+
top,
|
|
697
|
+
width,
|
|
698
|
+
height,
|
|
699
|
+
most,
|
|
700
|
+
names,
|
|
701
|
+
yLabel,
|
|
702
|
+
}: {
|
|
703
|
+
gutter: number;
|
|
704
|
+
top: number;
|
|
705
|
+
width: number;
|
|
706
|
+
height: number;
|
|
707
|
+
most: number;
|
|
708
|
+
names: number;
|
|
709
|
+
yLabel: string;
|
|
710
|
+
}) => {
|
|
711
|
+
if (width <= 0 || height <= 0) return null;
|
|
712
|
+
// The same room at the plot's ends as the loaded chart keeps, so the bubbles stay whole.
|
|
713
|
+
const low = LEAST + 8;
|
|
714
|
+
const high = most + 8;
|
|
715
|
+
const bubbles = SKELETON_BUBBLES.map(item => ({
|
|
716
|
+
...item,
|
|
717
|
+
cx: gutter + low + item.x * Math.max(0, width - low - high),
|
|
718
|
+
cy: top + height - low - item.y * Math.max(0, height - low - high),
|
|
719
|
+
r: Math.max(LEAST, item.size * most),
|
|
720
|
+
}));
|
|
721
|
+
const across = Math.max(3, Math.round(width / SKELETON_STEP));
|
|
722
|
+
const columns = Array.from({ length: across }, (_, i) => (i + 1) / (across + 1));
|
|
723
|
+
|
|
724
|
+
return (
|
|
725
|
+
<div aria-hidden className="absolute inset-0" data-slot="chart-skeleton">
|
|
726
|
+
<svg
|
|
727
|
+
aria-hidden="true"
|
|
728
|
+
className="absolute top-0 left-0 overflow-visible"
|
|
729
|
+
height={top + height}
|
|
730
|
+
width={gutter + width}
|
|
731
|
+
>
|
|
732
|
+
<text
|
|
733
|
+
className="text-xxs"
|
|
734
|
+
dominantBaseline="middle"
|
|
735
|
+
fill="var(--color-chart-label)"
|
|
736
|
+
x={gutter + 10}
|
|
737
|
+
y={top + 14}
|
|
738
|
+
>
|
|
739
|
+
{yLabel}
|
|
740
|
+
</text>
|
|
741
|
+
<g stroke="var(--color-chart-grid)">
|
|
742
|
+
{SKELETON_RULES.map(share => (
|
|
743
|
+
<line
|
|
744
|
+
key={`y-${share}`}
|
|
745
|
+
x1={gutter}
|
|
746
|
+
x2={gutter + width}
|
|
747
|
+
y1={Math.round(top + height * (1 - share)) + 0.5}
|
|
748
|
+
y2={Math.round(top + height * (1 - share)) + 0.5}
|
|
749
|
+
/>
|
|
750
|
+
))}
|
|
751
|
+
{columns.map(share => (
|
|
752
|
+
<line
|
|
753
|
+
key={`x-${share}`}
|
|
754
|
+
x1={Math.round(gutter + width * share) + 0.5}
|
|
755
|
+
x2={Math.round(gutter + width * share) + 0.5}
|
|
756
|
+
y1={top}
|
|
757
|
+
y2={top + height}
|
|
758
|
+
/>
|
|
759
|
+
))}
|
|
760
|
+
</g>
|
|
761
|
+
</svg>
|
|
762
|
+
{SKELETON_RULES.map((share, i) => {
|
|
763
|
+
const wide = SKELETON_FIGURES[i] ?? 24;
|
|
764
|
+
return (
|
|
765
|
+
<div
|
|
766
|
+
className="skeleton absolute h-2 rounded-chip"
|
|
767
|
+
key={share}
|
|
768
|
+
style={{
|
|
769
|
+
left: gutter - 8 - wide,
|
|
770
|
+
top: top + height * (1 - share) - 4,
|
|
771
|
+
width: wide,
|
|
772
|
+
}}
|
|
773
|
+
/>
|
|
774
|
+
);
|
|
775
|
+
})}
|
|
776
|
+
{columns.map((share, i) => {
|
|
777
|
+
const wide = SKELETON_COUNTS[i % SKELETON_COUNTS.length] ?? 12;
|
|
778
|
+
return (
|
|
779
|
+
<div
|
|
780
|
+
className="skeleton absolute h-2 rounded-chip"
|
|
781
|
+
key={share}
|
|
782
|
+
style={{
|
|
783
|
+
left: gutter + width * share - wide / 2,
|
|
784
|
+
top: top + height + 8,
|
|
785
|
+
width: wide,
|
|
786
|
+
}}
|
|
787
|
+
/>
|
|
788
|
+
);
|
|
789
|
+
})}
|
|
790
|
+
{bubbles.map(bubble => {
|
|
791
|
+
const place = {
|
|
792
|
+
height: bubble.r * 2,
|
|
793
|
+
left: bubble.cx - bubble.r,
|
|
794
|
+
top: bubble.cy - bubble.r,
|
|
795
|
+
width: bubble.r * 2,
|
|
796
|
+
};
|
|
797
|
+
return (
|
|
798
|
+
<Fragment key={`${bubble.x}-${bubble.y}`}>
|
|
799
|
+
{/* The chart's ground under the wash, so the rules stop at a bubble as they do at a loaded one. */}
|
|
800
|
+
<div
|
|
801
|
+
className="absolute rounded-full"
|
|
802
|
+
style={{ ...place, backgroundColor: 'var(--color-chart-background)' }}
|
|
803
|
+
/>
|
|
804
|
+
<div className="skeleton absolute rounded-full" style={place} />
|
|
805
|
+
<div
|
|
806
|
+
className="skeleton absolute rounded-full"
|
|
807
|
+
style={{
|
|
808
|
+
...place,
|
|
809
|
+
backgroundColor: SKELETON_EDGE,
|
|
810
|
+
maskImage: SKELETON_RING,
|
|
811
|
+
}}
|
|
812
|
+
/>
|
|
813
|
+
</Fragment>
|
|
814
|
+
);
|
|
815
|
+
})}
|
|
816
|
+
{bubbles.slice(0, names).map(bubble =>
|
|
817
|
+
bubble.name ? (
|
|
818
|
+
<div
|
|
819
|
+
className="skeleton absolute h-2 rounded-chip"
|
|
820
|
+
key={`${bubble.x}-${bubble.y}`}
|
|
821
|
+
style={{
|
|
822
|
+
left:
|
|
823
|
+
bubble.name.side === 'start'
|
|
824
|
+
? bubble.cx + bubble.r + 4
|
|
825
|
+
: bubble.cx - bubble.r - 4 - bubble.name.width,
|
|
826
|
+
top: bubble.cy - 4,
|
|
827
|
+
width: bubble.name.width,
|
|
828
|
+
}}
|
|
829
|
+
/>
|
|
830
|
+
) : null,
|
|
831
|
+
)}
|
|
832
|
+
</div>
|
|
833
|
+
);
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
const KEY_LABEL = 16;
|
|
837
|
+
const KEY_TEXT = 56;
|
|
838
|
+
|
|
839
|
+
/** The room the size key takes: its title, the circles on one foot, and their values beside. */
|
|
840
|
+
const sizeKeyBox = (radii: { r: number }[]) => {
|
|
841
|
+
const largest = Math.max(0, ...radii.map(item => item.r));
|
|
842
|
+
return { width: largest * 2 + 12 + KEY_TEXT, height: KEY_LABEL + largest * 2 + 2 };
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* What a bubble's size reads as: the reference circles nested on one foot, as bubbles of
|
|
847
|
+
* those sizes would sit, each with a short leader from its top to its value, under the name
|
|
848
|
+
* of what the size measures. A note on the plot, so it stands in it.
|
|
849
|
+
*/
|
|
850
|
+
const SizeKey = ({
|
|
851
|
+
label,
|
|
852
|
+
radii,
|
|
853
|
+
style,
|
|
854
|
+
}: {
|
|
855
|
+
label: string;
|
|
856
|
+
radii: { r: number; text: string }[];
|
|
857
|
+
style?: CSSProperties;
|
|
858
|
+
}) => {
|
|
859
|
+
const largest = Math.max(...radii.map(item => item.r));
|
|
860
|
+
const box = sizeKeyBox(radii);
|
|
861
|
+
const foot = box.height - KEY_LABEL - 1;
|
|
862
|
+
const labelAt = largest * 2 + 12;
|
|
863
|
+
return (
|
|
864
|
+
<div
|
|
865
|
+
className={cn(
|
|
866
|
+
'pointer-events-none flex flex-col text-neutral-600 text-xxs',
|
|
867
|
+
!style && 'mt-3 items-end',
|
|
868
|
+
)}
|
|
869
|
+
data-slot="bubble-chart-size-key"
|
|
870
|
+
style={style}
|
|
871
|
+
>
|
|
872
|
+
<span className="h-4 leading-4">{label}</span>
|
|
873
|
+
<svg
|
|
874
|
+
aria-hidden="true"
|
|
875
|
+
className="overflow-visible"
|
|
876
|
+
height={box.height - KEY_LABEL}
|
|
877
|
+
width={box.width}
|
|
878
|
+
>
|
|
879
|
+
{radii.map(item => {
|
|
880
|
+
const top = foot - item.r * 2;
|
|
881
|
+
return (
|
|
882
|
+
<g key={item.text}>
|
|
883
|
+
<circle
|
|
884
|
+
cx={largest + 0.5}
|
|
885
|
+
cy={foot - item.r}
|
|
886
|
+
fill="none"
|
|
887
|
+
r={Math.max(0.5, item.r - 0.5)}
|
|
888
|
+
stroke="var(--color-neutral-400)"
|
|
889
|
+
/>
|
|
890
|
+
<line
|
|
891
|
+
stroke="var(--color-neutral-400)"
|
|
892
|
+
strokeDasharray="2 2"
|
|
893
|
+
x1={largest + 0.5}
|
|
894
|
+
x2={labelAt - 4}
|
|
895
|
+
y1={top + 0.5}
|
|
896
|
+
y2={top + 0.5}
|
|
897
|
+
/>
|
|
898
|
+
<text
|
|
899
|
+
className="text-xxs tabular-nums"
|
|
900
|
+
dominantBaseline="middle"
|
|
901
|
+
fill="var(--color-chart-label)"
|
|
902
|
+
x={labelAt}
|
|
903
|
+
y={top + 1}
|
|
904
|
+
>
|
|
905
|
+
{item.text}
|
|
906
|
+
</text>
|
|
907
|
+
</g>
|
|
908
|
+
);
|
|
909
|
+
})}
|
|
910
|
+
</svg>
|
|
911
|
+
</div>
|
|
912
|
+
);
|
|
913
|
+
};
|