@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,39 @@
|
|
|
1
|
+
/** How many colours a theme gives before a chart has to say "the rest". */
|
|
2
|
+
export declare const CHART_COLORS = 5;
|
|
3
|
+
/**
|
|
4
|
+
* The ink a change is written in. A rise is the success colour deepened towards the text
|
|
5
|
+
* colour, so it is a dark green on a light surface and a clear green on a dark one; the ramp's
|
|
6
|
+
* own dark steps turn pale mint in dark mode and stop reading as green.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHANGE_INK: {
|
|
9
|
+
readonly up: "text-[color-mix(in_oklab,var(--color-success-500)_62%,var(--color-neutral-950))]";
|
|
10
|
+
readonly down: "text-[color-mix(in_oklab,var(--color-error-500)_80%,var(--color-neutral-950))]";
|
|
11
|
+
readonly neutral: "text-neutral-600";
|
|
12
|
+
};
|
|
13
|
+
export type ChartColor =
|
|
14
|
+
/** Independent series, by position. */
|
|
15
|
+
'series-1' | 'series-2' | 'series-3' | 'series-4' | 'series-5'
|
|
16
|
+
/** Steps in order: a funnel, shades of one measure. */
|
|
17
|
+
| 'chart-1' | 'chart-2' | 'chart-3' | 'chart-4' | 'chart-5'
|
|
18
|
+
/** A tone, where the measure itself is good or bad. */
|
|
19
|
+
| 'success' | 'warning' | 'error' | 'neutral'
|
|
20
|
+
/** Anything else is taken as a CSS colour and used as given. */
|
|
21
|
+
| (string & {});
|
|
22
|
+
/** A name turned into the token it stands for; anything else passes through as CSS. */
|
|
23
|
+
export declare const chartColor: (color?: ChartColor) => string;
|
|
24
|
+
/**
|
|
25
|
+
* The colour of series `index`. A theme gives five that a reader can tell apart, so a
|
|
26
|
+
* sixth series is drawn grey rather than starting the set again: two series in one
|
|
27
|
+
* colour is worse than one series without one.
|
|
28
|
+
*/
|
|
29
|
+
export declare const seriesColor: (index: number) => string;
|
|
30
|
+
/**
|
|
31
|
+
* The colour of step `index` of something read in order, such as a funnel. Past the five
|
|
32
|
+
* the set walks again from the second, so two steps beside each other never match.
|
|
33
|
+
*/
|
|
34
|
+
export declare const stepColor: (index: number) => string;
|
|
35
|
+
export declare const shadeColor: (color: ChartColor, index: number) => string;
|
|
36
|
+
/** `level` 0 is no value at all; 1 to 4 climb. */
|
|
37
|
+
export declare const intensityColor: (level: number) => string;
|
|
38
|
+
/** Which of the four levels a value sits at, measured against the busiest. */
|
|
39
|
+
export declare const intensityLevel: (value: number, max: number) => 0 | 1 | 3 | 2 | 4;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A chart holds no colour of its own: it names one, and the name is a token the theme
|
|
3
|
+
* sets. That is what makes every chart follow the theme builder, light and dark, with
|
|
4
|
+
* nothing read from script and no hex anywhere in the kit.
|
|
5
|
+
*/
|
|
6
|
+
/** How many colours a theme gives before a chart has to say "the rest". */
|
|
7
|
+
export const CHART_COLORS = 5;
|
|
8
|
+
/**
|
|
9
|
+
* The ink a change is written in. A rise is the success colour deepened towards the text
|
|
10
|
+
* colour, so it is a dark green on a light surface and a clear green on a dark one; the ramp's
|
|
11
|
+
* own dark steps turn pale mint in dark mode and stop reading as green.
|
|
12
|
+
*/
|
|
13
|
+
export const CHANGE_INK = {
|
|
14
|
+
up: 'text-[color-mix(in_oklab,var(--color-success-500)_62%,var(--color-neutral-950))]',
|
|
15
|
+
down: 'text-[color-mix(in_oklab,var(--color-error-500)_80%,var(--color-neutral-950))]',
|
|
16
|
+
neutral: 'text-neutral-600',
|
|
17
|
+
};
|
|
18
|
+
const tones = {
|
|
19
|
+
success: 'var(--color-success-500)',
|
|
20
|
+
warning: 'var(--color-warning-500)',
|
|
21
|
+
error: 'var(--color-error-500)',
|
|
22
|
+
neutral: 'var(--color-neutral-400)',
|
|
23
|
+
};
|
|
24
|
+
/** A name turned into the token it stands for; anything else passes through as CSS. */
|
|
25
|
+
export const chartColor = (color = 'series-1') => {
|
|
26
|
+
if (color in tones)
|
|
27
|
+
return tones[color];
|
|
28
|
+
if (/^series-[1-5]$/.test(color))
|
|
29
|
+
return `var(--color-chart-${color})`;
|
|
30
|
+
if (/^chart-[1-5]$/.test(color))
|
|
31
|
+
return `var(--color-${color})`;
|
|
32
|
+
return color;
|
|
33
|
+
};
|
|
34
|
+
let warned = false;
|
|
35
|
+
/**
|
|
36
|
+
* The colour of series `index`. A theme gives five that a reader can tell apart, so a
|
|
37
|
+
* sixth series is drawn grey rather than starting the set again: two series in one
|
|
38
|
+
* colour is worse than one series without one.
|
|
39
|
+
*/
|
|
40
|
+
export const seriesColor = (index) => {
|
|
41
|
+
if (index < CHART_COLORS)
|
|
42
|
+
return chartColor(`series-${index + 1}`);
|
|
43
|
+
if (!warned) {
|
|
44
|
+
warned = true;
|
|
45
|
+
console.warn(`Continuum charts: a theme has ${CHART_COLORS} series colours and this chart has more series than that. The rest are drawn grey. Group the small ones into "Other", or show them as several charts.`);
|
|
46
|
+
}
|
|
47
|
+
return chartColor('neutral');
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The colour of step `index` of something read in order, such as a funnel. Past the five
|
|
51
|
+
* the set walks again from the second, so two steps beside each other never match.
|
|
52
|
+
*/
|
|
53
|
+
export const stepColor = (index) => chartColor(`chart-${(index < CHART_COLORS ? index : 1 + (index % (CHART_COLORS - 1))) + 1}`);
|
|
54
|
+
/** Shades of one colour, for parts of a single measure: a share, a device, a plan. */
|
|
55
|
+
const SHADES = [100, 80, 60, 45, 33];
|
|
56
|
+
export const shadeColor = (color, index) => {
|
|
57
|
+
const share = SHADES[index] ?? SHADES.at(-1) ?? 33;
|
|
58
|
+
const base = chartColor(color);
|
|
59
|
+
return share === 100 ? base : `color-mix(in oklab, ${base} ${share}%, transparent)`;
|
|
60
|
+
};
|
|
61
|
+
/** How loud a cell of a heatmap is: nothing, then four steps of the first chart colour. */
|
|
62
|
+
const LEVELS = [20, 40, 70, 100];
|
|
63
|
+
/** `level` 0 is no value at all; 1 to 4 climb. */
|
|
64
|
+
export const intensityColor = (level) => {
|
|
65
|
+
if (level <= 0)
|
|
66
|
+
return 'var(--color-neutral-200)';
|
|
67
|
+
const share = LEVELS[Math.min(level, LEVELS.length) - 1] ?? 100;
|
|
68
|
+
const base = chartColor('chart-1');
|
|
69
|
+
return share === 100 ? base : `color-mix(in oklab, ${base} ${share}%, transparent)`;
|
|
70
|
+
};
|
|
71
|
+
/** Which of the four levels a value sits at, measured against the busiest. */
|
|
72
|
+
export const intensityLevel = (value, max) => {
|
|
73
|
+
if (!(value > 0) || !(max > 0))
|
|
74
|
+
return 0;
|
|
75
|
+
const share = value / max;
|
|
76
|
+
if (share > 0.75)
|
|
77
|
+
return 4;
|
|
78
|
+
if (share > 0.5)
|
|
79
|
+
return 3;
|
|
80
|
+
if (share > 0.25)
|
|
81
|
+
return 2;
|
|
82
|
+
return 1;
|
|
83
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Axis labels: short enough to sit in a gutter. 1,250 is 1.3K, 0.5 stays 0.5. */
|
|
2
|
+
export declare const formatCompact: (value: number) => string;
|
|
3
|
+
/** A tooltip has room for the figure itself, so it reads 5,100 rather than 5.1K. */
|
|
4
|
+
export declare const formatNumber: (value: number) => string;
|
|
5
|
+
export declare const formatPercent: (share: number, digits?: number) => string;
|
|
6
|
+
/** An x label under a plot: "19 Oct". */
|
|
7
|
+
export declare const formatDate: (date: Date) => string;
|
|
8
|
+
/** A tooltip's title, where the weekday is worth the room: "Mon 19 Oct". */
|
|
9
|
+
export declare const formatDateLong: (date: Date) => string;
|
|
10
|
+
/** Whatever a row holds in its x field, as something to print. */
|
|
11
|
+
export declare const formatX: (value: unknown, long?: boolean) => string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How a chart writes a number or a date when it is not told how. Every formatter is
|
|
3
|
+
* fixed to en-GB: the runtime's own locale would let a server write "1,234" and the
|
|
4
|
+
* browser hydrate "1.234".
|
|
5
|
+
*/
|
|
6
|
+
const compact = new Intl.NumberFormat('en-GB', {
|
|
7
|
+
notation: 'compact',
|
|
8
|
+
maximumFractionDigits: 1,
|
|
9
|
+
});
|
|
10
|
+
const full = new Intl.NumberFormat('en-GB', { maximumFractionDigits: 2 });
|
|
11
|
+
/** Axis labels: short enough to sit in a gutter. 1,250 is 1.3K, 0.5 stays 0.5. */
|
|
12
|
+
export const formatCompact = (value) => Math.abs(value) >= 1000 ? compact.format(value) : full.format(value);
|
|
13
|
+
/** A tooltip has room for the figure itself, so it reads 5,100 rather than 5.1K. */
|
|
14
|
+
export const formatNumber = (value) => full.format(value);
|
|
15
|
+
export const formatPercent = (share, digits = 0) => `${full.format(Number((share * 100).toFixed(digits)))}%`;
|
|
16
|
+
const shortDate = new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short' });
|
|
17
|
+
const longDate = new Intl.DateTimeFormat('en-GB', {
|
|
18
|
+
weekday: 'short',
|
|
19
|
+
day: 'numeric',
|
|
20
|
+
month: 'short',
|
|
21
|
+
});
|
|
22
|
+
/** An x label under a plot: "19 Oct". */
|
|
23
|
+
export const formatDate = (date) => shortDate.format(date);
|
|
24
|
+
/** A tooltip's title, where the weekday is worth the room: "Mon 19 Oct". */
|
|
25
|
+
export const formatDateLong = (date) => longDate.format(date).replace(',', '');
|
|
26
|
+
/** Whatever a row holds in its x field, as something to print. */
|
|
27
|
+
export const formatX = (value, long = false) => {
|
|
28
|
+
if (value instanceof Date)
|
|
29
|
+
return long ? formatDateLong(value) : formatDate(value);
|
|
30
|
+
if (typeof value === 'number')
|
|
31
|
+
return formatNumber(value);
|
|
32
|
+
return String(value ?? '');
|
|
33
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame every chart's plot stands in: a hairline a shade quieter than a card's, on the
|
|
3
|
+
* item corner, so the plot reads as a place of its own inside its card instead of melting
|
|
4
|
+
* into it. Axis text stands outside it; only the marks and their grid are within.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PLOT_FRAME = "pointer-events-none absolute rounded-item border border-neutral-950/8";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The frame every chart's plot stands in: a hairline a shade quieter than a card's, on the
|
|
3
|
+
* item corner, so the plot reads as a place of its own inside its card instead of melting
|
|
4
|
+
* into it. Axis text stands outside it; only the marks and their grid are within.
|
|
5
|
+
*/
|
|
6
|
+
export const PLOT_FRAME = 'pointer-events-none absolute rounded-item border border-neutral-950/8';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Rect = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The rectangles for a set of values, in the order the values were given. The largest are
|
|
9
|
+
* laid first, from the top left, so the order on the page is the order of size.
|
|
10
|
+
*/
|
|
11
|
+
export declare const squarify: (values: readonly number[], room: Rect) => Rect[];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Laying out a treemap: each share becomes a rectangle whose area is that share of the
|
|
3
|
+
* whole, as close to square as the shares allow (Bruls, Huizing and van Wijk's squarified
|
|
4
|
+
* layout). A square is read for its size at a glance; a sliver is not read at all.
|
|
5
|
+
*/
|
|
6
|
+
const total = (values) => values.reduce((sum, value) => sum + value, 0);
|
|
7
|
+
/** How far from square the worst rectangle of a row would be, laid along a side this long. */
|
|
8
|
+
const worst = (row, side) => {
|
|
9
|
+
const sum = total(row);
|
|
10
|
+
const largest = Math.max(...row);
|
|
11
|
+
const smallest = Math.min(...row);
|
|
12
|
+
return Math.max((side * side * largest) / (sum * sum), (sum * sum) / (side * side * smallest));
|
|
13
|
+
};
|
|
14
|
+
/** Lays a finished row along the shorter side of what is left, and returns what is left after it. */
|
|
15
|
+
const place = (row, room, out) => {
|
|
16
|
+
const sum = total(row);
|
|
17
|
+
if (room.width >= room.height) {
|
|
18
|
+
const width = sum / room.height;
|
|
19
|
+
let y = room.y;
|
|
20
|
+
for (const area of row) {
|
|
21
|
+
const height = area / width;
|
|
22
|
+
out.push({ x: room.x, y, width, height });
|
|
23
|
+
y += height;
|
|
24
|
+
}
|
|
25
|
+
return { x: room.x + width, y: room.y, width: room.width - width, height: room.height };
|
|
26
|
+
}
|
|
27
|
+
const height = sum / room.width;
|
|
28
|
+
let x = room.x;
|
|
29
|
+
for (const area of row) {
|
|
30
|
+
const width = area / height;
|
|
31
|
+
out.push({ x, y: room.y, width, height });
|
|
32
|
+
x += width;
|
|
33
|
+
}
|
|
34
|
+
return { x: room.x, y: room.y + height, width: room.width, height: room.height - height };
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The rectangles for a set of values, in the order the values were given. The largest are
|
|
38
|
+
* laid first, from the top left, so the order on the page is the order of size.
|
|
39
|
+
*/
|
|
40
|
+
export const squarify = (values, room) => {
|
|
41
|
+
const whole = total(values);
|
|
42
|
+
if (whole <= 0 || room.width <= 0 || room.height <= 0)
|
|
43
|
+
return values.map(() => ({ ...room, width: 0, height: 0 }));
|
|
44
|
+
const scale = (room.width * room.height) / whole;
|
|
45
|
+
const order = values
|
|
46
|
+
.map((value, index) => ({ index, area: Math.max(0, value) * scale }))
|
|
47
|
+
.sort((a, b) => b.area - a.area);
|
|
48
|
+
const laid = [];
|
|
49
|
+
let left = { ...room };
|
|
50
|
+
let row = [];
|
|
51
|
+
const queue = order.map(item => item.area);
|
|
52
|
+
while (queue.length) {
|
|
53
|
+
const next = queue[0];
|
|
54
|
+
const side = Math.min(left.width, left.height);
|
|
55
|
+
if (row.length === 0 || worst([...row, next], side) <= worst(row, side)) {
|
|
56
|
+
row.push(next);
|
|
57
|
+
queue.shift();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
left = place(row, left, laid);
|
|
61
|
+
row = [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (row.length)
|
|
65
|
+
place(row, left, laid);
|
|
66
|
+
const out = new Array(values.length);
|
|
67
|
+
order.forEach((item, i) => {
|
|
68
|
+
out[item.index] = laid[i];
|
|
69
|
+
});
|
|
70
|
+
return out;
|
|
71
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
/** A monotone curve through every point; nothing for fewer than two. */
|
|
6
|
+
export declare const curvePath: (points: readonly Point[]) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Straight segments through every point. Where the points are closer together than the curve
|
|
9
|
+
* is wide there is nothing for a curve to say: the eye cannot tell the two apart, and this is
|
|
10
|
+
* a third of the path data and none of the slope maths.
|
|
11
|
+
*/
|
|
12
|
+
export declare const linePath: (points: readonly Point[]) => string;
|
|
13
|
+
/**
|
|
14
|
+
* The value held across its own period, then stepped to the next. For a measure that is only
|
|
15
|
+
* true of the period it was taken over — a price in force, a plan's seats, a daily count — a
|
|
16
|
+
* curve between two readings invents values that were never measured; this draws none.
|
|
17
|
+
*/
|
|
18
|
+
export declare const stepPath: (points: readonly Point[]) => string;
|
|
19
|
+
/** The stepped line, closed down to the baseline. */
|
|
20
|
+
export declare const stepAreaPath: (points: readonly Point[], baseline: number) => string;
|
|
21
|
+
/** The same straight line, closed down to the baseline. */
|
|
22
|
+
export declare const lineAreaPath: (points: readonly Point[], baseline: number) => string;
|
|
23
|
+
/** The same curve, closed down to the baseline: the fill under a line. */
|
|
24
|
+
export declare const areaPath: (points: readonly Point[], baseline: number) => string;
|
|
25
|
+
/**
|
|
26
|
+
* One shape between a high edge and a low edge: out along the highs and back along the lows.
|
|
27
|
+
* It draws the spread a set of averages was taken from, so the line is read as the middle of
|
|
28
|
+
* something rather than as the whole of it.
|
|
29
|
+
*/
|
|
30
|
+
export declare const bandPath: (high: readonly Point[], low: readonly Point[]) => string;
|
|
31
|
+
/**
|
|
32
|
+
* A slice of a ring, from `start` to `end` in radians clockwise from twelve o'clock, with
|
|
33
|
+
* its four corners rounded. A donut's slices and a gauge's arc are both this shape.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ringSegmentPath: (cx: number, cy: number, outer: number, inner: number, start: number, end: number, corner?: number) => string;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The shapes a chart draws: a curve through its points, the area under it, and a
|
|
3
|
+
* segment of a ring. Written out because a chart needs this much and no more.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The slope to leave each point at, for a curve that never overshoots its neighbours
|
|
7
|
+
* (Fritsch and Carlson's rule): where a point is a peak the curve is flat there, and
|
|
8
|
+
* between two points it stays between their values. A peak stays the peak it was.
|
|
9
|
+
*/
|
|
10
|
+
const sign = (value) => (value < 0 ? -1 : 1);
|
|
11
|
+
const slopes = (points) => {
|
|
12
|
+
const n = points.length;
|
|
13
|
+
const runs = [];
|
|
14
|
+
const deltas = [];
|
|
15
|
+
for (let i = 0; i < n - 1; i++) {
|
|
16
|
+
const a = points[i];
|
|
17
|
+
const b = points[i + 1];
|
|
18
|
+
const run = b.x - a.x;
|
|
19
|
+
runs.push(run);
|
|
20
|
+
deltas.push(run === 0 ? 0 : (b.y - a.y) / run);
|
|
21
|
+
}
|
|
22
|
+
/*
|
|
23
|
+
* The slope to leave a point at, weighted towards the gentler of its two sides. Taking the
|
|
24
|
+
* plain average instead and pulling it back into range, as the first draft did, flattens
|
|
25
|
+
* the curve at every turn, and a line of many readings comes out as a run of flat tops
|
|
26
|
+
* joined by ramps — the corners that made it look cut rather than drawn.
|
|
27
|
+
*/
|
|
28
|
+
const between = (before, after, runBefore, runAfter) => {
|
|
29
|
+
if (before * after <= 0)
|
|
30
|
+
return 0;
|
|
31
|
+
const weighted = (before * runAfter + after * runBefore) / (runBefore + runAfter);
|
|
32
|
+
return ((sign(before) + sign(after)) *
|
|
33
|
+
Math.min(Math.abs(before), Math.abs(after), 0.5 * Math.abs(weighted)));
|
|
34
|
+
};
|
|
35
|
+
const m = new Array(n).fill(0);
|
|
36
|
+
for (let i = 1; i < n - 1; i++) {
|
|
37
|
+
m[i] = between(deltas[i - 1] ?? 0, deltas[i] ?? 0, runs[i - 1] ?? 1, runs[i] ?? 1);
|
|
38
|
+
}
|
|
39
|
+
// The ends have one side only, so they take it, held to what the first span can carry.
|
|
40
|
+
const end = (delta, inner) => 1.5 * delta - 0.5 * inner;
|
|
41
|
+
m[0] = n > 2 ? end(deltas[0] ?? 0, m[1] ?? 0) : (deltas[0] ?? 0);
|
|
42
|
+
m[n - 1] = n > 2 ? end(deltas[n - 2] ?? 0, m[n - 2] ?? 0) : (deltas[n - 2] ?? 0);
|
|
43
|
+
for (let i = 0; i < n - 1; i++) {
|
|
44
|
+
const delta = deltas[i] ?? 0;
|
|
45
|
+
if (delta === 0) {
|
|
46
|
+
m[i] = 0;
|
|
47
|
+
m[i + 1] = 0;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const a = (m[i] ?? 0) / delta;
|
|
51
|
+
const b = (m[i + 1] ?? 0) / delta;
|
|
52
|
+
const reach = a * a + b * b;
|
|
53
|
+
// Past this the curve would bulge outside the two points, so both slopes are pulled in.
|
|
54
|
+
if (reach > 9) {
|
|
55
|
+
const scale = 3 / Math.sqrt(reach);
|
|
56
|
+
m[i] = scale * a * delta;
|
|
57
|
+
m[i + 1] = scale * b * delta;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return m;
|
|
61
|
+
};
|
|
62
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
63
|
+
/** The curve's cubic segments, without the opening move. */
|
|
64
|
+
const segments = (points) => {
|
|
65
|
+
const m = slopes(points);
|
|
66
|
+
let d = '';
|
|
67
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
68
|
+
const a = points[i];
|
|
69
|
+
const b = points[i + 1];
|
|
70
|
+
const third = (b.x - a.x) / 3;
|
|
71
|
+
d += ` C${round(a.x + third)},${round(a.y + (m[i] ?? 0) * third)} ${round(b.x - third)},${round(b.y - (m[i + 1] ?? 0) * third)} ${round(b.x)},${round(b.y)}`;
|
|
72
|
+
}
|
|
73
|
+
return d;
|
|
74
|
+
};
|
|
75
|
+
/** A monotone curve through every point; nothing for fewer than two. */
|
|
76
|
+
export const curvePath = (points) => {
|
|
77
|
+
const first = points[0];
|
|
78
|
+
if (!first || points.length < 2)
|
|
79
|
+
return '';
|
|
80
|
+
return `M${round(first.x)},${round(first.y)}${segments(points)}`;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Straight segments through every point. Where the points are closer together than the curve
|
|
84
|
+
* is wide there is nothing for a curve to say: the eye cannot tell the two apart, and this is
|
|
85
|
+
* a third of the path data and none of the slope maths.
|
|
86
|
+
*/
|
|
87
|
+
export const linePath = (points) => {
|
|
88
|
+
const first = points[0];
|
|
89
|
+
if (!first || points.length < 2)
|
|
90
|
+
return '';
|
|
91
|
+
return `M${round(first.x)},${round(first.y)}${points
|
|
92
|
+
.slice(1)
|
|
93
|
+
.map(point => ` L${round(point.x)},${round(point.y)}`)
|
|
94
|
+
.join('')}`;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The value held across its own period, then stepped to the next. For a measure that is only
|
|
98
|
+
* true of the period it was taken over — a price in force, a plan's seats, a daily count — a
|
|
99
|
+
* curve between two readings invents values that were never measured; this draws none.
|
|
100
|
+
*/
|
|
101
|
+
export const stepPath = (points) => {
|
|
102
|
+
const first = points[0];
|
|
103
|
+
if (!first || points.length < 2)
|
|
104
|
+
return '';
|
|
105
|
+
let d = `M${round(first.x)},${round(first.y)}`;
|
|
106
|
+
for (let i = 1; i < points.length; i++) {
|
|
107
|
+
const point = points[i];
|
|
108
|
+
const middle = ((points[i - 1].x + point.x) / 2) | 0;
|
|
109
|
+
d += ` L${middle},${round(points[i - 1].y)} L${middle},${round(point.y)} L${round(point.x)},${round(point.y)}`;
|
|
110
|
+
}
|
|
111
|
+
return d;
|
|
112
|
+
};
|
|
113
|
+
/** The stepped line, closed down to the baseline. */
|
|
114
|
+
export const stepAreaPath = (points, baseline) => {
|
|
115
|
+
const first = points[0];
|
|
116
|
+
const last = points.at(-1);
|
|
117
|
+
if (!first || !last || points.length < 2)
|
|
118
|
+
return '';
|
|
119
|
+
return `${stepPath(points)} L${round(last.x)},${round(baseline)} L${round(first.x)},${round(baseline)} Z`;
|
|
120
|
+
};
|
|
121
|
+
/** The same straight line, closed down to the baseline. */
|
|
122
|
+
export const lineAreaPath = (points, baseline) => {
|
|
123
|
+
const first = points[0];
|
|
124
|
+
const last = points.at(-1);
|
|
125
|
+
if (!first || !last || points.length < 2)
|
|
126
|
+
return '';
|
|
127
|
+
return `${linePath(points)} L${round(last.x)},${round(baseline)} L${round(first.x)},${round(baseline)} Z`;
|
|
128
|
+
};
|
|
129
|
+
/** The same curve, closed down to the baseline: the fill under a line. */
|
|
130
|
+
export const areaPath = (points, baseline) => {
|
|
131
|
+
const first = points[0];
|
|
132
|
+
const last = points.at(-1);
|
|
133
|
+
if (!first || !last || points.length < 2)
|
|
134
|
+
return '';
|
|
135
|
+
return `M${round(first.x)},${round(baseline)} L${round(first.x)},${round(first.y)}${segments(points)} L${round(last.x)},${round(baseline)} Z`;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* One shape between a high edge and a low edge: out along the highs and back along the lows.
|
|
139
|
+
* It draws the spread a set of averages was taken from, so the line is read as the middle of
|
|
140
|
+
* something rather than as the whole of it.
|
|
141
|
+
*/
|
|
142
|
+
export const bandPath = (high, low) => {
|
|
143
|
+
if (high.length < 2 || low.length !== high.length)
|
|
144
|
+
return '';
|
|
145
|
+
const back = [...low].reverse();
|
|
146
|
+
return `${linePath(high)}${back.map(point => ` L${round(point.x)},${round(point.y)}`).join('')} Z`;
|
|
147
|
+
};
|
|
148
|
+
const polar = (cx, cy, radius, angle) => ({
|
|
149
|
+
x: cx + radius * Math.sin(angle),
|
|
150
|
+
y: cy - radius * Math.cos(angle),
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* A slice of a ring, from `start` to `end` in radians clockwise from twelve o'clock, with
|
|
154
|
+
* its four corners rounded. A donut's slices and a gauge's arc are both this shape.
|
|
155
|
+
*/
|
|
156
|
+
export const ringSegmentPath = (cx, cy, outer, inner, start, end, corner = 0) => {
|
|
157
|
+
const sweep = end - start;
|
|
158
|
+
if (sweep <= 0 || outer <= 0)
|
|
159
|
+
return '';
|
|
160
|
+
// A full ring has no ends to draw, so it is two half arcs out and two back.
|
|
161
|
+
if (sweep >= Math.PI * 2 - 1e-6) {
|
|
162
|
+
const top = polar(cx, cy, outer, 0);
|
|
163
|
+
const bottom = polar(cx, cy, outer, Math.PI);
|
|
164
|
+
const innerTop = polar(cx, cy, inner, 0);
|
|
165
|
+
const innerBottom = polar(cx, cy, inner, Math.PI);
|
|
166
|
+
return [
|
|
167
|
+
`M${round(top.x)},${round(top.y)}`,
|
|
168
|
+
`A${outer},${outer} 0 0 1 ${round(bottom.x)},${round(bottom.y)}`,
|
|
169
|
+
`A${outer},${outer} 0 0 1 ${round(top.x)},${round(top.y)}`,
|
|
170
|
+
`M${round(innerTop.x)},${round(innerTop.y)}`,
|
|
171
|
+
`A${inner},${inner} 0 0 0 ${round(innerBottom.x)},${round(innerBottom.y)}`,
|
|
172
|
+
`A${inner},${inner} 0 0 0 ${round(innerTop.x)},${round(innerTop.y)}`,
|
|
173
|
+
'Z',
|
|
174
|
+
].join(' ');
|
|
175
|
+
}
|
|
176
|
+
// A corner can never take more than the slice has to give, on either radius.
|
|
177
|
+
const band = Math.max(0, outer - inner);
|
|
178
|
+
const r = Math.max(0, Math.min(corner, band / 2, (outer * sweep) / 2));
|
|
179
|
+
const outerTurn = outer > r ? r / outer : 0;
|
|
180
|
+
const innerTurn = inner > r ? r / inner : 0;
|
|
181
|
+
const long = sweep > Math.PI ? 1 : 0;
|
|
182
|
+
const a = polar(cx, cy, outer, start + outerTurn);
|
|
183
|
+
const b = polar(cx, cy, outer, end - outerTurn);
|
|
184
|
+
const c = polar(cx, cy, inner || 0.01, end - innerTurn);
|
|
185
|
+
const d = polar(cx, cy, inner || 0.01, start + innerTurn);
|
|
186
|
+
const startEdgeOuter = polar(cx, cy, outer - r, start);
|
|
187
|
+
const endEdgeOuter = polar(cx, cy, outer - r, end);
|
|
188
|
+
const startEdgeInner = polar(cx, cy, inner + r, start);
|
|
189
|
+
const endEdgeInner = polar(cx, cy, inner + r, end);
|
|
190
|
+
return [
|
|
191
|
+
`M${round(startEdgeOuter.x)},${round(startEdgeOuter.y)}`,
|
|
192
|
+
r > 0 ? `A${r},${r} 0 0 1 ${round(a.x)},${round(a.y)}` : '',
|
|
193
|
+
`A${outer},${outer} 0 ${long} 1 ${round(b.x)},${round(b.y)}`,
|
|
194
|
+
r > 0 ? `A${r},${r} 0 0 1 ${round(endEdgeOuter.x)},${round(endEdgeOuter.y)}` : '',
|
|
195
|
+
`L${round(endEdgeInner.x)},${round(endEdgeInner.y)}`,
|
|
196
|
+
r > 0 ? `A${r},${r} 0 0 1 ${round(c.x)},${round(c.y)}` : '',
|
|
197
|
+
inner > 0 ? `A${inner},${inner} 0 ${long} 0 ${round(d.x)},${round(d.y)}` : '',
|
|
198
|
+
r > 0 ? `A${r},${r} 0 0 1 ${round(startEdgeInner.x)},${round(startEdgeInner.y)}` : '',
|
|
199
|
+
'Z',
|
|
200
|
+
]
|
|
201
|
+
.filter(Boolean)
|
|
202
|
+
.join(' ');
|
|
203
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** The smallest step of that family at or above `rough`. */
|
|
2
|
+
export declare const niceStep: (rough: number) => number;
|
|
3
|
+
export type Ticks = {
|
|
4
|
+
/** Every rule the plot draws and labels, lowest first. */
|
|
5
|
+
values: number[];
|
|
6
|
+
/** The domain the plot draws, which the data fills. */
|
|
7
|
+
min: number;
|
|
8
|
+
max: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The domain a measure is drawn in, and the round numbers ruled across it.
|
|
12
|
+
*
|
|
13
|
+
* The data sets the domain — the top is the largest value and a little air — and the rules
|
|
14
|
+
* land on round numbers inside it. Letting the ticks set the domain instead is what leaves
|
|
15
|
+
* a chart of 6,300 counting up to 8,000 with a quarter of its height empty; here the top
|
|
16
|
+
* rule is 6,000 and the peak sits just above it, where the eye can still read it off.
|
|
17
|
+
*
|
|
18
|
+
* `cap` is a ceiling the measure cannot pass, such as 100 for a rate: then it is the top,
|
|
19
|
+
* air and all, because headroom above a full bar would be a lie.
|
|
20
|
+
*/
|
|
21
|
+
export declare const niceTicks: (dataMin: number, dataMax: number, count?: number, cap?: number) => Ticks;
|
|
22
|
+
/** Where a value sits across a plot's height: the domain's top at the top of the plot. */
|
|
23
|
+
export declare const scaleY: (value: number, { min, max }: Pick<Ticks, "min" | "max">, height: number) => number;
|
|
24
|
+
/**
|
|
25
|
+
* Where point `index` of `count` sits across a plot's width. A line reaches both edges,
|
|
26
|
+
* so its first and last points sit on them; with one point it sits in the middle.
|
|
27
|
+
*/
|
|
28
|
+
export declare const scalePoint: (index: number, count: number, width: number) => number;
|
|
29
|
+
/**
|
|
30
|
+
* A slot per row, each the same width, with the row's marks drawn inside it. Bars count in
|
|
31
|
+
* slots rather than points, so the first and last bar keep half a slot of air at the edges.
|
|
32
|
+
*/
|
|
33
|
+
export declare const slotScale: (count: number, width: number) => {
|
|
34
|
+
slot: number;
|
|
35
|
+
center: (index: number) => number;
|
|
36
|
+
};
|
|
37
|
+
/** The smallest and largest of the numbers, ignoring the gaps. */
|
|
38
|
+
export declare const extent: (values: readonly (number | null | undefined)[]) => {
|
|
39
|
+
min: number;
|
|
40
|
+
max: number;
|
|
41
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Where a value sits in a plot, and the round numbers an axis counts in. This is
|
|
3
|
+
* the whole of the maths a cartesian chart needs: no d3, no scale objects, just
|
|
4
|
+
* the two functions a chart calls and the ticks it labels.
|
|
5
|
+
*/
|
|
6
|
+
/** The steps an axis may count in: 1, 2, 2.5 and 5 at every power of ten. */
|
|
7
|
+
const STEPS = [1, 2, 2.5, 5, 10];
|
|
8
|
+
/** The smallest step of that family at or above `rough`. */
|
|
9
|
+
export const niceStep = (rough) => {
|
|
10
|
+
if (!(rough > 0) || !Number.isFinite(rough))
|
|
11
|
+
return 1;
|
|
12
|
+
const power = 10 ** Math.floor(Math.log10(rough));
|
|
13
|
+
// The float that comes out of a log is never exact, so a step lands on its own value.
|
|
14
|
+
const factor = STEPS.find(step => step * power >= rough - 1e-9) ?? 10;
|
|
15
|
+
return factor * power;
|
|
16
|
+
};
|
|
17
|
+
/** A peak is given this much air above it, so the line never grazes the chart's top edge. */
|
|
18
|
+
const HEADROOM = 0.08;
|
|
19
|
+
/**
|
|
20
|
+
* The domain a measure is drawn in, and the round numbers ruled across it.
|
|
21
|
+
*
|
|
22
|
+
* The data sets the domain — the top is the largest value and a little air — and the rules
|
|
23
|
+
* land on round numbers inside it. Letting the ticks set the domain instead is what leaves
|
|
24
|
+
* a chart of 6,300 counting up to 8,000 with a quarter of its height empty; here the top
|
|
25
|
+
* rule is 6,000 and the peak sits just above it, where the eye can still read it off.
|
|
26
|
+
*
|
|
27
|
+
* `cap` is a ceiling the measure cannot pass, such as 100 for a rate: then it is the top,
|
|
28
|
+
* air and all, because headroom above a full bar would be a lie.
|
|
29
|
+
*/
|
|
30
|
+
export const niceTicks = (dataMin, dataMax, count = 4, cap) => {
|
|
31
|
+
// A measure is read against zero unless it goes below it.
|
|
32
|
+
const low = Math.min(0, dataMin);
|
|
33
|
+
let high = Math.max(0, dataMax);
|
|
34
|
+
// Nothing to tell apart (every value zero, or one value): count in ones from zero.
|
|
35
|
+
if (high - low < 1e-12)
|
|
36
|
+
high = low + count;
|
|
37
|
+
else
|
|
38
|
+
high = high + (high - low) * HEADROOM;
|
|
39
|
+
if (cap !== undefined && Number.isFinite(cap))
|
|
40
|
+
high = Math.min(high, cap);
|
|
41
|
+
const step = niceStep((high - low) / count);
|
|
42
|
+
const first = Math.ceil(low / step) * step;
|
|
43
|
+
const values = [];
|
|
44
|
+
// Counting by multiples of the step, rather than adding it, keeps 0.1 + 0.2 out of the labels.
|
|
45
|
+
for (let i = 0; first + i * step <= high + step * 1e-9; i++)
|
|
46
|
+
values.push(first + i * step);
|
|
47
|
+
// A domain too shallow for a single rule still gets its floor, so the plot is not bare.
|
|
48
|
+
if (!values.length)
|
|
49
|
+
values.push(low);
|
|
50
|
+
return { values, min: low, max: high };
|
|
51
|
+
};
|
|
52
|
+
/** Where a value sits across a plot's height: the domain's top at the top of the plot. */
|
|
53
|
+
export const scaleY = (value, { min, max }, height) => max === min ? height : height - ((value - min) / (max - min)) * height;
|
|
54
|
+
/**
|
|
55
|
+
* Where point `index` of `count` sits across a plot's width. A line reaches both edges,
|
|
56
|
+
* so its first and last points sit on them; with one point it sits in the middle.
|
|
57
|
+
*/
|
|
58
|
+
export const scalePoint = (index, count, width) => count > 1 ? (index / (count - 1)) * width : width / 2;
|
|
59
|
+
/**
|
|
60
|
+
* A slot per row, each the same width, with the row's marks drawn inside it. Bars count in
|
|
61
|
+
* slots rather than points, so the first and last bar keep half a slot of air at the edges.
|
|
62
|
+
*/
|
|
63
|
+
export const slotScale = (count, width) => {
|
|
64
|
+
const slot = count > 0 ? width / count : width;
|
|
65
|
+
return { slot, center: (index) => slot * (index + 0.5) };
|
|
66
|
+
};
|
|
67
|
+
/** The smallest and largest of the numbers, ignoring the gaps. */
|
|
68
|
+
export const extent = (values) => {
|
|
69
|
+
let min = Number.POSITIVE_INFINITY;
|
|
70
|
+
let max = Number.NEGATIVE_INFINITY;
|
|
71
|
+
for (const value of values) {
|
|
72
|
+
if (value == null || !Number.isFinite(value))
|
|
73
|
+
continue;
|
|
74
|
+
if (value < min)
|
|
75
|
+
min = value;
|
|
76
|
+
if (value > max)
|
|
77
|
+
max = value;
|
|
78
|
+
}
|
|
79
|
+
return Number.isFinite(min) ? { min, max } : { min: 0, max: 0 };
|
|
80
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type KeyboardEvent, type PointerEvent } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Which row a chart is reading out: the one nearest the pointer, or the one the arrow
|
|
4
|
+
* keys walked to. The reader aims at a date, never at a two-pixel line, so the pointer's
|
|
5
|
+
* x is snapped to the nearest row rather than used as it is.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useActive: (count: number, xOf: (index: number) => number) => {
|
|
8
|
+
active: number | null;
|
|
9
|
+
setActive: import("react").Dispatch<import("react").SetStateAction<number | null>>;
|
|
10
|
+
/** On the layer over the plot, which is one tab stop. */
|
|
11
|
+
handlers: {
|
|
12
|
+
onPointerMove: (event: PointerEvent<HTMLElement>) => void;
|
|
13
|
+
onPointerLeave: () => void;
|
|
14
|
+
onPointerCancel: () => void;
|
|
15
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
|
|
16
|
+
onBlur: () => void;
|
|
17
|
+
};
|
|
18
|
+
};
|