@link-foundation/ui-components 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/CONFIGURATIONS.md +74 -0
- package/ICONS.md +76 -0
- package/LICENSE +24 -0
- package/README.md +1499 -2
- package/bin/lino-network.mjs +71 -0
- package/dist/icons/ATTRIBUTION.md +602 -0
- package/dist/icons/NOTICE.lino +1261 -0
- package/dist/icons/brand.js +31 -0
- package/dist/icons/brand.svg +3 -0
- package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
- package/dist/icons/licenses/brand/LICENSE.md +30 -0
- package/dist/icons/licenses/lucide/LICENSE +43 -0
- package/dist/icons/licenses/material-symbols/LICENSE +202 -0
- package/dist/icons/licenses/material-symbols/NOTICE +12 -0
- package/dist/icons/licenses/tabler/LICENSE +21 -0
- package/dist/icons/lucide.js +681 -0
- package/dist/icons/lucide.svg +34 -0
- package/dist/icons/material-symbols.js +681 -0
- package/dist/icons/material-symbols.svg +34 -0
- package/dist/icons/own.js +521 -0
- package/dist/icons/own.svg +34 -0
- package/dist/icons/tabler.js +681 -0
- package/dist/icons/tabler.svg +34 -0
- package/dist/network-layout-NOTICE.md +6 -0
- package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
- package/dist/network-layout-d3-force-LICENSE.txt +13 -0
- package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
- package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
- package/dist/network-layout-dagre-LICENSE.txt +19 -0
- package/dist/network-layout.worker.mjs +2 -0
- package/package.json +246 -4
- package/src/a11y/announce.js +88 -0
- package/src/a11y/bind-machine.js +181 -0
- package/src/a11y/focus.js +169 -0
- package/src/a11y/index.d.ts +89 -0
- package/src/a11y/index.js +19 -0
- package/src/a11y/keys.js +182 -0
- package/src/a11y/roving.js +167 -0
- package/src/a11y/typeahead.js +82 -0
- package/src/behavior/actions.js +235 -0
- package/src/behavior/diagnostics.js +73 -0
- package/src/behavior/dom.d.ts +38 -0
- package/src/behavior/dom.js +420 -0
- package/src/behavior/index.d.ts +211 -0
- package/src/behavior/index.js +29 -0
- package/src/behavior/interpret.js +454 -0
- package/src/behavior/machines/disclosure.lino +46 -0
- package/src/behavior/machines/index.js +91 -0
- package/src/behavior/machines/toggle.lino +25 -0
- package/src/behavior/parse-machine.js +367 -0
- package/src/charts/README.md +78 -0
- package/src/charts/activity-layout.js +350 -0
- package/src/charts/activity-model.js +130 -0
- package/src/charts/activity-validation.js +31 -0
- package/src/charts/chart-model.js +667 -0
- package/src/charts/chart.js +518 -0
- package/src/charts/echarts-adapter.d.ts +23 -0
- package/src/charts/echarts-adapter.js +240 -0
- package/src/charts/element.js +330 -0
- package/src/charts/errors.js +62 -0
- package/src/charts/gauge.js +27 -0
- package/src/charts/index.d.ts +344 -0
- package/src/charts/index.js +59 -0
- package/src/charts/layout.js +542 -0
- package/src/charts/lino.js +158 -0
- package/src/charts/mark-options.js +78 -0
- package/src/charts/read.js +101 -0
- package/src/charts/renderer-features.js +8 -0
- package/src/charts/scales.js +223 -0
- package/src/charts/small-model.js +223 -0
- package/src/charts/small-svg.js +269 -0
- package/src/charts/sparkline.js +27 -0
- package/src/charts/stat-tile.js +37 -0
- package/src/charts/summary.js +193 -0
- package/src/charts/svg-renderer.js +226 -0
- package/src/charts/svg.js +69 -0
- package/src/charts/tag-cloud.js +129 -0
- package/src/charts/tokens.js +171 -0
- package/src/charts/tooltip.js +47 -0
- package/src/charts/values.js +146 -0
- package/src/chat/README.md +142 -0
- package/src/chat/actions.js +75 -0
- package/src/chat/chat-contract.js +95 -0
- package/src/chat/chat-list.js +42 -0
- package/src/chat/chat-model.js +125 -0
- package/src/chat/chat.css +228 -0
- package/src/chat/composer.js +131 -0
- package/src/chat/day-separator.js +12 -0
- package/src/chat/dom.js +33 -0
- package/src/chat/follow.js +49 -0
- package/src/chat/index.d.ts +142 -0
- package/src/chat/index.js +13 -0
- package/src/chat/message-bubble.js +191 -0
- package/src/chat/message-stream.js +331 -0
- package/src/chat/reasoning-trace.js +70 -0
- package/src/chat/selection.js +39 -0
- package/src/chat/skins/bubbles.lino +2 -0
- package/src/chat/skins/cards.lino +4 -0
- package/src/chat/skins/compact.lino +4 -0
- package/src/chat/skins/signal.lino +25 -0
- package/src/chat/skins/t3.lino +25 -0
- package/src/chat/skins/telegram.lino +31 -0
- package/src/chat/skins/whatsapp.lino +25 -0
- package/src/chat/stream-keys.js +57 -0
- package/src/chat/stream-window.js +159 -0
- package/src/chat/vocabulary.js +19 -0
- package/src/controls/accordion.js +160 -0
- package/src/controls/avatar.js +80 -0
- package/src/controls/badge.js +48 -0
- package/src/controls/button-template.js +32 -0
- package/src/controls/button.js +97 -0
- package/src/controls/catalog.lino +84 -0
- package/src/controls/checkbox.js +112 -0
- package/src/controls/chip.js +140 -0
- package/src/controls/choices.js +45 -0
- package/src/controls/color-field.js +217 -0
- package/src/controls/color-popover.js +135 -0
- package/src/controls/color-rgb.js +80 -0
- package/src/controls/color.js +67 -0
- package/src/controls/combobox.js +192 -0
- package/src/controls/dom.js +261 -0
- package/src/controls/icon-button.js +33 -0
- package/src/controls/index.d.ts +163 -0
- package/src/controls/index.js +182 -0
- package/src/controls/kinds-text.js +358 -0
- package/src/controls/kinds.lino +350 -0
- package/src/controls/label.js +52 -0
- package/src/controls/link.js +101 -0
- package/src/controls/listbox.js +144 -0
- package/src/controls/machines/button.lino +20 -0
- package/src/controls/machines/checkbox.lino +17 -0
- package/src/controls/machines/chip.lino +20 -0
- package/src/controls/machines/color-field.lino +23 -0
- package/src/controls/machines/combobox.lino +82 -0
- package/src/controls/machines/icon-button.lino +20 -0
- package/src/controls/machines/index.js +586 -0
- package/src/controls/machines/number-field.lino +71 -0
- package/src/controls/machines/radio-group.lino +17 -0
- package/src/controls/machines/select.lino +122 -0
- package/src/controls/machines/slider.lino +99 -0
- package/src/controls/machines/switch.lino +19 -0
- package/src/controls/machines/text-area.lino +26 -0
- package/src/controls/machines/text-field.lino +26 -0
- package/src/controls/number-field.js +239 -0
- package/src/controls/numeric-keys.js +125 -0
- package/src/controls/option.js +54 -0
- package/src/controls/progress.js +76 -0
- package/src/controls/radio-group.js +234 -0
- package/src/controls/select.js +229 -0
- package/src/controls/slider.js +234 -0
- package/src/controls/stories.js +172 -0
- package/src/controls/styles.css +1060 -0
- package/src/controls/switch.js +95 -0
- package/src/controls/text-area.js +39 -0
- package/src/controls/text-field.js +131 -0
- package/src/controls/vocabulary.js +164 -0
- package/src/data/data.css +95 -0
- package/src/data/index.d.ts +83 -0
- package/src/data/index.js +10 -0
- package/src/data/keyboard.js +189 -0
- package/src/data/list.js +215 -0
- package/src/data/render-data.js +116 -0
- package/src/data/selection-dom.js +39 -0
- package/src/data/selection-model.js +43 -0
- package/src/data/sort-model.js +42 -0
- package/src/data/source.js +45 -0
- package/src/data/table.js +160 -0
- package/src/data/tree-model.js +41 -0
- package/src/data/tree.js +55 -0
- package/src/data/viewport.js +216 -0
- package/src/data/virtual-range.js +92 -0
- package/src/data/vocabulary.js +67 -0
- package/src/diagrams/diagram-model.js +511 -0
- package/src/diagrams/diagram.js +204 -0
- package/src/diagrams/index.d.ts +225 -0
- package/src/diagrams/index.js +48 -0
- package/src/diagrams/layout-dagre.js +164 -0
- package/src/diagrams/layout-plugins.js +131 -0
- package/src/diagrams/mermaid-export.js +232 -0
- package/src/diagrams/mermaid-view.js +229 -0
- package/src/diagrams/svg-diagram.js +215 -0
- package/src/editor/code-editor.js +206 -0
- package/src/editor/documents-model.js +170 -0
- package/src/editor/documents-persistence.js +85 -0
- package/src/editor/editor-engine.js +22 -0
- package/src/editor/editor-ui.js +203 -0
- package/src/editor/editor.css +106 -0
- package/src/editor/engines/codemirror.js +227 -0
- package/src/editor/engines/monaco.js +219 -0
- package/src/editor/index.d.ts +111 -0
- package/src/editor/index.js +14 -0
- package/src/editor/lino-highlight.js +106 -0
- package/src/editor/lino-structure.js +85 -0
- package/src/editor/validate-lino.js +43 -0
- package/src/embed/README.md +161 -0
- package/src/embed/controller.js +223 -0
- package/src/embed/element.js +141 -0
- package/src/embed/index.d.ts +75 -0
- package/src/embed/index.js +9 -0
- package/src/embed/providers/telegram.d.ts +3 -0
- package/src/embed/providers/telegram.js +38 -0
- package/src/embed/providers/vk.d.ts +3 -0
- package/src/embed/providers/vk.js +42 -0
- package/src/embed/providers/x.d.ts +3 -0
- package/src/embed/providers/x.js +31 -0
- package/src/embed/registry.js +35 -0
- package/src/embed/script.js +73 -0
- package/src/embed/view.js +122 -0
- package/src/icons/adapters/lucide.d.ts +15 -0
- package/src/icons/adapters/lucide.js +142 -0
- package/src/icons/adapters/material-symbols.d.ts +13 -0
- package/src/icons/adapters/material-symbols.js +113 -0
- package/src/icons/adapters/shared.d.ts +38 -0
- package/src/icons/adapters/shared.js +157 -0
- package/src/icons/adapters/simple-icons.d.ts +9 -0
- package/src/icons/adapters/simple-icons.js +38 -0
- package/src/icons/adapters/tabler.d.ts +9 -0
- package/src/icons/adapters/tabler.js +86 -0
- package/src/icons/icon-registry.js +215 -0
- package/src/icons/icon.js +356 -0
- package/src/icons/index.d.ts +123 -0
- package/src/icons/index.js +30 -0
- package/src/icons/names.js +51 -0
- package/src/icons/own-icons.js +521 -0
- package/src/icons/presentation.js +55 -0
- package/src/icons/svg.js +136 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +40 -0
- package/src/layout/README.md +102 -0
- package/src/layout/app-shell.js +150 -0
- package/src/layout/catalog.lino +27 -0
- package/src/layout/dock-model.js +576 -0
- package/src/layout/dock-view.js +312 -0
- package/src/layout/dock.js +352 -0
- package/src/layout/dom.js +312 -0
- package/src/layout/grid.js +192 -0
- package/src/layout/index.d.ts +267 -0
- package/src/layout/index.js +60 -0
- package/src/layout/layer-manager.js +120 -0
- package/src/layout/layout.css +760 -0
- package/src/layout/menu.js +141 -0
- package/src/layout/nav-strip.js +174 -0
- package/src/layout/page-links.js +166 -0
- package/src/layout/panel.js +26 -0
- package/src/layout/pref-switches.js +209 -0
- package/src/layout/split-model.js +270 -0
- package/src/layout/split.js +430 -0
- package/src/layout/stack.js +86 -0
- package/src/layout/surfaces.js +119 -0
- package/src/layout/tab-group.js +151 -0
- package/src/layout/tab-strip.js +277 -0
- package/src/layout/vocabulary.js +229 -0
- package/src/layout/window-frame.js +222 -0
- package/src/layout/window.js +146 -0
- package/src/links-view/animator.js +144 -0
- package/src/links-view/configuration-classes.js +150 -0
- package/src/links-view/configuration-model.js +191 -0
- package/src/links-view/configuration-notations.js +230 -0
- package/src/links-view/configurations.d.ts +73 -0
- package/src/links-view/configurations.js +33 -0
- package/src/links-view/create-layout-runner.js +79 -0
- package/src/links-view/doublet-curves.js +239 -0
- package/src/links-view/doublet-layout.js +148 -0
- package/src/links-view/doublet-markers.js +109 -0
- package/src/links-view/doublet-options.js +369 -0
- package/src/links-view/doublet-svg.js +156 -0
- package/src/links-view/doublet.js +230 -0
- package/src/links-view/export.js +146 -0
- package/src/links-view/geometry.js +409 -0
- package/src/links-view/index.d.ts +1029 -0
- package/src/links-view/index.js +140 -0
- package/src/links-view/labels.js +28 -0
- package/src/links-view/layout-worker-entry.mjs +2 -0
- package/src/links-view/layout-worker.js +28 -0
- package/src/links-view/layouts/circle.js +7 -0
- package/src/links-view/layouts/force.js +76 -0
- package/src/links-view/layouts/grid.js +7 -0
- package/src/links-view/layouts/hex.js +8 -0
- package/src/links-view/layouts/index.js +15 -0
- package/src/links-view/layouts/layered.js +29 -0
- package/src/links-view/layouts/regular.js +27 -0
- package/src/links-view/layouts/spiral.js +10 -0
- package/src/links-view/link-view.js +494 -0
- package/src/links-view/links-gallery.js +306 -0
- package/src/links-view/links-network.js +496 -0
- package/src/links-view/lino-network-source.js +122 -0
- package/src/links-view/lino-network.js +233 -0
- package/src/links-view/lino-to-network.js +252 -0
- package/src/links-view/markers.js +192 -0
- package/src/links-view/model.js +233 -0
- package/src/links-view/network-editor/dom.js +36 -0
- package/src/links-view/network-editor/editor.js +202 -0
- package/src/links-view/network-editor/model.js +163 -0
- package/src/links-view/network-editor/options.js +265 -0
- package/src/links-view/network-editor/panels.js +423 -0
- package/src/links-view/network-editor/presets.js +76 -0
- package/src/links-view/network-editor/provider.js +93 -0
- package/src/links-view/network-editor/remap.js +45 -0
- package/src/links-view/network-editor/schema.js +224 -0
- package/src/links-view/network-editor/share.js +232 -0
- package/src/links-view/network-editor/styles.js +19 -0
- package/src/links-view/network-editor/url-sync.js +131 -0
- package/src/links-view/network-interaction.js +228 -0
- package/src/links-view/network-model.js +85 -0
- package/src/links-view/network-renderer.js +259 -0
- package/src/links-view/network-scene.js +245 -0
- package/src/links-view/network-source.js +82 -0
- package/src/links-view/network-vocabulary.js +18 -0
- package/src/links-view/presentation.js +199 -0
- package/src/links-view/render-canvas.js +102 -0
- package/src/links-view/render-svg.js +118 -0
- package/src/links-view/scene.js +233 -0
- package/src/links-view/solver-job.js +106 -0
- package/src/links-view/tokens.js +114 -0
- package/src/links-view/zoom-pan.js +203 -0
- package/src/overlays/catalog.lino +89 -0
- package/src/overlays/context-menu.js +110 -0
- package/src/overlays/dialog.js +117 -0
- package/src/overlays/dom.js +168 -0
- package/src/overlays/drawer.js +8 -0
- package/src/overlays/index.d.ts +80 -0
- package/src/overlays/index.js +25 -0
- package/src/overlays/kinds.lino +137 -0
- package/src/overlays/list-popover.js +129 -0
- package/src/overlays/machines/index.js +71 -0
- package/src/overlays/machines/surface.lino +11 -0
- package/src/overlays/machines/tabs.lino +7 -0
- package/src/overlays/machines/toast.lino +16 -0
- package/src/overlays/machines/tooltip.lino +29 -0
- package/src/overlays/menu.js +240 -0
- package/src/overlays/popover.js +194 -0
- package/src/overlays/position.js +84 -0
- package/src/overlays/radial-geometry.js +38 -0
- package/src/overlays/radial-menu.js +50 -0
- package/src/overlays/styles.css +155 -0
- package/src/overlays/tabs.js +125 -0
- package/src/overlays/toast-queue.js +105 -0
- package/src/overlays/toast.js +163 -0
- package/src/overlays/tooltip.js +110 -0
- package/src/overlays/vocabulary.js +3 -0
- package/src/settings/conditions.js +44 -0
- package/src/settings/control-for.js +62 -0
- package/src/settings/field-control.js +201 -0
- package/src/settings/index.d.ts +201 -0
- package/src/settings/index.js +3 -0
- package/src/settings/messages.js +112 -0
- package/src/settings/miniature.js +26 -0
- package/src/settings/panel-actions.js +234 -0
- package/src/settings/panel-model.js +49 -0
- package/src/settings/panel-refresh.js +56 -0
- package/src/settings/panel-rows.js +200 -0
- package/src/settings/preset-cards.js +43 -0
- package/src/settings/saved-looks.js +227 -0
- package/src/settings/section-layout.js +95 -0
- package/src/settings/section-tabs.js +175 -0
- package/src/settings/settings-panel.js +192 -0
- package/src/settings/settings.css +178 -0
- package/stories/accordion.lino +14 -0
- package/stories/alert-dialog.lino +4 -0
- package/stories/app-bar.lino +10 -0
- package/stories/avatar.lino +7 -0
- package/stories/badge.lino +12 -0
- package/stories/button.lino +17 -0
- package/stories/card.lino +10 -0
- package/stories/checkbox.lino +14 -0
- package/stories/chip.lino +19 -0
- package/stories/color-field.lino +9 -0
- package/stories/combobox.lino +10 -0
- package/stories/container.lino +11 -0
- package/stories/context-menu.lino +15 -0
- package/stories/dialog.lino +16 -0
- package/stories/drawer.lino +12 -0
- package/stories/icon-button.lino +13 -0
- package/stories/label.lino +7 -0
- package/stories/link-cards.lino +9 -0
- package/stories/link.lino +9 -0
- package/stories/menu-item.lino +6 -0
- package/stories/menu-separator.lino +7 -0
- package/stories/menu.lino +30 -0
- package/stories/nav-strip.lino +11 -0
- package/stories/number-field.lino +16 -0
- package/stories/option.lino +10 -0
- package/stories/paper.lino +11 -0
- package/stories/popover.lino +4 -0
- package/stories/pref-switches.lino +4 -0
- package/stories/progress.lino +14 -0
- package/stories/radial-menu.lino +19 -0
- package/stories/radio-group.lino +22 -0
- package/stories/radio.lino +10 -0
- package/stories/section-nav.lino +9 -0
- package/stories/select.lino +16 -0
- package/stories/slider.lino +14 -0
- package/stories/switch.lino +10 -0
- package/stories/tab-panel.lino +7 -0
- package/stories/tab.lino +7 -0
- package/stories/tabs.lino +25 -0
- package/stories/text-area.lino +12 -0
- package/stories/text-field.lino +23 -0
- package/stories/titled-section.lino +7 -0
- package/stories/toast.lino +3 -0
- package/stories/toaster.lino +2 -0
- package/stories/tooltip.lino +3 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `renderChartSvg(spec, { width, height, tokens })`: a chart spec as a
|
|
3
|
+
* standalone SVG string. Deterministic: the same spec and options give the
|
|
4
|
+
* same bytes on every run and machine (no ids, no clock, no randomness,
|
|
5
|
+
* numbers rounded to hundredths).
|
|
6
|
+
*
|
|
7
|
+
* Colours are `var(--color-chart-N, #light)` so a page theme (and dark
|
|
8
|
+
* mode) restyles the chart; pass `tokens` (token path to colour) to write
|
|
9
|
+
* literal colours instead, for an SVG used outside a page.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { patternShapes } from './activity-layout.js';
|
|
13
|
+
import { tagCloudSvg } from './tag-cloud.js';
|
|
14
|
+
import { layoutChart } from './layout.js';
|
|
15
|
+
import { renderSmallChartSvg } from './small-svg.js';
|
|
16
|
+
import { el, escapeXml, paint, svgRoot, text } from './svg.js';
|
|
17
|
+
import { tokenColor } from './tokens.js';
|
|
18
|
+
|
|
19
|
+
const MARK_ATTRS = {
|
|
20
|
+
fill: 'fill',
|
|
21
|
+
stroke: 'stroke',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** A mark shape with its colours as styles. */
|
|
25
|
+
function shapeSvg(shape, series) {
|
|
26
|
+
const attrs = {};
|
|
27
|
+
const styles = [];
|
|
28
|
+
for (const [name, value] of Object.entries(shape.attrs)) {
|
|
29
|
+
if (MARK_ATTRS[name] && value !== 'none') {
|
|
30
|
+
styles.push(paint(name, value));
|
|
31
|
+
} else {
|
|
32
|
+
attrs[name] = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return el(
|
|
36
|
+
shape.tag,
|
|
37
|
+
{
|
|
38
|
+
...attrs,
|
|
39
|
+
style: styles.join(';') || null,
|
|
40
|
+
'data-series': series,
|
|
41
|
+
'data-row': shape.row,
|
|
42
|
+
'data-pattern': shape.pattern,
|
|
43
|
+
},
|
|
44
|
+
[
|
|
45
|
+
shape.title ? el('title', {}, escapeXml(shape.title)) : '',
|
|
46
|
+
shape.content ? escapeXml(shape.content) : '',
|
|
47
|
+
]
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function axisSvg(axis, plot, colors) {
|
|
52
|
+
const bottom = axis.orient === 'bottom';
|
|
53
|
+
const ticks = axis.ticks.map((tick) => {
|
|
54
|
+
const line = bottom
|
|
55
|
+
? {
|
|
56
|
+
x1: tick.position,
|
|
57
|
+
x2: tick.position,
|
|
58
|
+
y1: plot.height,
|
|
59
|
+
y2: plot.height + 5,
|
|
60
|
+
}
|
|
61
|
+
: { x1: -5, x2: 0, y1: tick.position, y2: tick.position };
|
|
62
|
+
const label = bottom
|
|
63
|
+
? { x: tick.position, y: plot.height + 18, 'text-anchor': 'middle' }
|
|
64
|
+
: { x: -8, y: tick.position + 4, 'text-anchor': 'end' };
|
|
65
|
+
const grid = axis.grid
|
|
66
|
+
? el('line', {
|
|
67
|
+
...(bottom
|
|
68
|
+
? { x1: tick.position, x2: tick.position, y1: 0, y2: plot.height }
|
|
69
|
+
: { x1: 0, x2: plot.width, y1: tick.position, y2: tick.position }),
|
|
70
|
+
style: paint('stroke', colors.grid),
|
|
71
|
+
})
|
|
72
|
+
: '';
|
|
73
|
+
return [
|
|
74
|
+
grid,
|
|
75
|
+
el('line', { ...line, style: paint('stroke', colors.axis) }),
|
|
76
|
+
text(
|
|
77
|
+
{ ...label, 'font-size': 11, style: paint('fill', colors.muted) },
|
|
78
|
+
tick.label
|
|
79
|
+
),
|
|
80
|
+
].join('');
|
|
81
|
+
});
|
|
82
|
+
const domain = bottom
|
|
83
|
+
? { x1: 0, x2: plot.width, y1: plot.height, y2: plot.height }
|
|
84
|
+
: { x1: 0, x2: 0, y1: 0, y2: plot.height };
|
|
85
|
+
const title = bottom
|
|
86
|
+
? { x: plot.width / 2, y: plot.height + 36, 'text-anchor': 'middle' }
|
|
87
|
+
: {
|
|
88
|
+
x: 0,
|
|
89
|
+
y: 0,
|
|
90
|
+
transform: `translate(${-plot.x + 14},${plot.height / 2}) rotate(-90)`,
|
|
91
|
+
'text-anchor': 'middle',
|
|
92
|
+
};
|
|
93
|
+
return el(
|
|
94
|
+
'g',
|
|
95
|
+
{
|
|
96
|
+
class: `ui-chart-axis ui-chart-axis-${bottom ? 'x' : 'y'}`,
|
|
97
|
+
'aria-hidden': 'true',
|
|
98
|
+
},
|
|
99
|
+
[
|
|
100
|
+
...ticks,
|
|
101
|
+
el('line', { ...domain, style: paint('stroke', colors.axis) }),
|
|
102
|
+
text(
|
|
103
|
+
{ ...title, 'font-size': 12, style: paint('fill', colors.text) },
|
|
104
|
+
axis.title
|
|
105
|
+
),
|
|
106
|
+
]
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function legendSvg(legend, colors) {
|
|
111
|
+
if (legend.length === 0) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
const items = legend.map((entry) =>
|
|
115
|
+
el('g', { transform: `translate(${entry.x},${entry.y})` }, [
|
|
116
|
+
el('rect', {
|
|
117
|
+
x: 0,
|
|
118
|
+
y: -9,
|
|
119
|
+
width: 14,
|
|
120
|
+
height: 14,
|
|
121
|
+
rx: 2,
|
|
122
|
+
style: paint('fill', entry.color),
|
|
123
|
+
}),
|
|
124
|
+
...patternShapes(
|
|
125
|
+
{ x: 0, y: -9, width: 14, height: 14 },
|
|
126
|
+
entry.pattern
|
|
127
|
+
).map((shape) => shapeSvg(shape, null)),
|
|
128
|
+
text(
|
|
129
|
+
{ x: 20, y: 3, 'font-size': 12, style: paint('fill', colors.text) },
|
|
130
|
+
entry.label
|
|
131
|
+
),
|
|
132
|
+
])
|
|
133
|
+
);
|
|
134
|
+
return el('g', { class: 'ui-chart-legend', 'aria-hidden': 'true' }, items);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The chart colours of the text, axes and grid. */
|
|
138
|
+
export const chromeColors = (tokens) => ({
|
|
139
|
+
text: tokenColor('color.chart.text', tokens),
|
|
140
|
+
muted: tokenColor('color.chart.muted', tokens),
|
|
141
|
+
axis: tokenColor('color.chart.axis', tokens),
|
|
142
|
+
grid: tokenColor('color.chart.grid', tokens),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Write a laid out chart as SVG.
|
|
147
|
+
* @param {import('./layout.js').ChartLayout} layout
|
|
148
|
+
* @param {object} [options]
|
|
149
|
+
* @param {Record<string, string>|Map<string, string>|null} [options.tokens]
|
|
150
|
+
*/
|
|
151
|
+
export function layoutToSvg(layout, options = {}) {
|
|
152
|
+
const colors = chromeColors(options.tokens ?? null);
|
|
153
|
+
const { plot } = layout;
|
|
154
|
+
const children = [];
|
|
155
|
+
if (layout.title) {
|
|
156
|
+
children.push(
|
|
157
|
+
text(
|
|
158
|
+
{
|
|
159
|
+
class: 'ui-chart-title',
|
|
160
|
+
x: 20,
|
|
161
|
+
y: 20,
|
|
162
|
+
'font-size': 15,
|
|
163
|
+
'font-weight': 600,
|
|
164
|
+
style: paint('fill', colors.text),
|
|
165
|
+
},
|
|
166
|
+
layout.title
|
|
167
|
+
)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
children.push(legendSvg(layout.legend, colors));
|
|
171
|
+
const marks = layout.series.map((series, s) =>
|
|
172
|
+
el(
|
|
173
|
+
'g',
|
|
174
|
+
{ class: 'ui-chart-series', 'data-series': s, 'data-key': series.key },
|
|
175
|
+
series.shapes.map((shape) => shapeSvg(shape, s))
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
children.push(
|
|
179
|
+
el(
|
|
180
|
+
'g',
|
|
181
|
+
{ class: 'ui-chart-plot', transform: `translate(${plot.x},${plot.y})` },
|
|
182
|
+
[
|
|
183
|
+
...layout.axes.map((axis) => axisSvg(axis, plot, colors)),
|
|
184
|
+
el(
|
|
185
|
+
'g',
|
|
186
|
+
{
|
|
187
|
+
class: 'ui-chart-marks',
|
|
188
|
+
'aria-hidden': layout.accessibleMarks ? null : 'true',
|
|
189
|
+
},
|
|
190
|
+
marks
|
|
191
|
+
),
|
|
192
|
+
]
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
return svgRoot(
|
|
196
|
+
{
|
|
197
|
+
width: layout.width,
|
|
198
|
+
height: layout.height,
|
|
199
|
+
label: layout.label,
|
|
200
|
+
title: layout.title,
|
|
201
|
+
className: 'ui-chart-svg',
|
|
202
|
+
role: layout.accessibleMarks ? 'group' : 'img',
|
|
203
|
+
},
|
|
204
|
+
children
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A chart spec (any kind) as an SVG string.
|
|
210
|
+
* @param {import('./chart-model.js').ChartSpec|import('./small-model.js').SmallChartSpec} spec
|
|
211
|
+
* @param {object} [options]
|
|
212
|
+
* @param {number} [options.width]
|
|
213
|
+
* @param {number} [options.height]
|
|
214
|
+
* @param {Record<string, string>|Map<string, string>|null} [options.tokens]
|
|
215
|
+
* token path (`color.chart.1`) to colour; default: CSS custom properties
|
|
216
|
+
* @returns {string}
|
|
217
|
+
*/
|
|
218
|
+
export function renderChartSvg(spec, options = {}) {
|
|
219
|
+
if (spec.kind === 'tag-cloud') {
|
|
220
|
+
return tagCloudSvg(spec);
|
|
221
|
+
}
|
|
222
|
+
if (spec.kind !== undefined && spec.kind !== 'chart') {
|
|
223
|
+
return renderSmallChartSvg(spec, options);
|
|
224
|
+
}
|
|
225
|
+
return layoutToSvg(layoutChart(spec, options), options);
|
|
226
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tiny deterministic SVG writer: elements as strings, attributes in the
|
|
3
|
+
* order given, numbers rounded to hundredths, text escaped.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const ESCAPES = {
|
|
7
|
+
'&': '&',
|
|
8
|
+
'<': '<',
|
|
9
|
+
'>': '>',
|
|
10
|
+
'"': '"',
|
|
11
|
+
"'": ''',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Text escaped for XML content and attribute values. */
|
|
15
|
+
export const escapeXml = (text) =>
|
|
16
|
+
String(text).replace(/[&<>"']/gu, (c) => ESCAPES[c]);
|
|
17
|
+
|
|
18
|
+
/** An attribute value: numbers rounded to hundredths. */
|
|
19
|
+
const attrValue = (value) =>
|
|
20
|
+
typeof value === 'number'
|
|
21
|
+
? String(Math.round(value * 100) / 100)
|
|
22
|
+
: escapeXml(value);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* One element.
|
|
26
|
+
* @param {string} tag
|
|
27
|
+
* @param {Record<string, string|number|boolean|null|undefined>} [attrs]
|
|
28
|
+
* `null`, `undefined` and `false` are left out
|
|
29
|
+
* @param {string|string[]} [children] already written SVG
|
|
30
|
+
*/
|
|
31
|
+
export function el(tag, attrs = {}, children = []) {
|
|
32
|
+
const parts = Object.entries(attrs)
|
|
33
|
+
.filter(
|
|
34
|
+
([, value]) => value !== null && value !== undefined && value !== false
|
|
35
|
+
)
|
|
36
|
+
.map(([name, value]) => ` ${name}="${attrValue(value)}"`)
|
|
37
|
+
.join('');
|
|
38
|
+
const content = Array.isArray(children) ? children.join('') : children;
|
|
39
|
+
return content === ''
|
|
40
|
+
? `<${tag}${parts}/>`
|
|
41
|
+
: `<${tag}${parts}>${content}</${tag}>`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A text element. */
|
|
45
|
+
export const text = (attrs, content) => el('text', attrs, escapeXml(content));
|
|
46
|
+
|
|
47
|
+
/** A fill or stroke as a style, so CSS custom properties apply. */
|
|
48
|
+
export const paint = (name, color) => `${name}:${color}`;
|
|
49
|
+
|
|
50
|
+
/** The root `<svg>` with its accessible name and description. */
|
|
51
|
+
export function svgRoot(
|
|
52
|
+
{ width, height, label, title, className, role = 'img' },
|
|
53
|
+
children
|
|
54
|
+
) {
|
|
55
|
+
return el(
|
|
56
|
+
'svg',
|
|
57
|
+
{
|
|
58
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
59
|
+
class: className,
|
|
60
|
+
width,
|
|
61
|
+
height,
|
|
62
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
63
|
+
role,
|
|
64
|
+
'aria-label': label,
|
|
65
|
+
'font-family': 'system-ui, sans-serif',
|
|
66
|
+
},
|
|
67
|
+
[el('title', {}, escapeXml(title ?? label)), ...children]
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** A semantic tag cloud; its configuration and items round-trip through LiNo. */
|
|
2
|
+
import { fail } from './errors.js';
|
|
3
|
+
import { headName, isAtom, prop } from './lino.js';
|
|
4
|
+
import { booleanOf, optionalNumber, optionalText, properties } from './read.js';
|
|
5
|
+
import { escapeXml } from './svg.js';
|
|
6
|
+
|
|
7
|
+
export function readTagCloud(node, path) {
|
|
8
|
+
const props = properties(node, path, 1, [
|
|
9
|
+
'label',
|
|
10
|
+
'description',
|
|
11
|
+
'min-size',
|
|
12
|
+
'max-size',
|
|
13
|
+
'items',
|
|
14
|
+
]);
|
|
15
|
+
const minSize = optionalNumber(props, 'min-size', 12);
|
|
16
|
+
const maxSize = optionalNumber(props, 'max-size', 36);
|
|
17
|
+
if (minSize <= 0 || maxSize < minSize) {
|
|
18
|
+
fail(
|
|
19
|
+
'invalid-value',
|
|
20
|
+
'tag sizes require 0 < min-size <= max-size',
|
|
21
|
+
node,
|
|
22
|
+
path
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const itemsEntry = props.get('items')?.[0];
|
|
26
|
+
if (!itemsEntry) {
|
|
27
|
+
fail('missing-field', 'tag-cloud requires items', node, path);
|
|
28
|
+
}
|
|
29
|
+
const items = itemsEntry.node.values.slice(1).map((item, i) => {
|
|
30
|
+
const at = [...itemsEntry.path, i + 1];
|
|
31
|
+
if (headName(item) !== 'item' || !isAtom(item.values[1])) {
|
|
32
|
+
fail('invalid-value', 'expected item NAME', item, at);
|
|
33
|
+
}
|
|
34
|
+
const fields = properties(item, at, 2, ['count', 'color', 'emphasis']);
|
|
35
|
+
const count = optionalNumber(fields, 'count');
|
|
36
|
+
if (count !== null && count < 0) {
|
|
37
|
+
fail('invalid-value', 'count must be nonnegative', item, at);
|
|
38
|
+
}
|
|
39
|
+
const emphasis = fields.get('emphasis')?.[0];
|
|
40
|
+
return {
|
|
41
|
+
name: item.values[1].id,
|
|
42
|
+
count,
|
|
43
|
+
color: optionalText(fields, 'color'),
|
|
44
|
+
emphasis: emphasis
|
|
45
|
+
? booleanOf(emphasis.node, emphasis.path, 'emphasis')
|
|
46
|
+
: false,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
kind: 'tag-cloud',
|
|
51
|
+
id: node.id,
|
|
52
|
+
label: optionalText(props, 'label'),
|
|
53
|
+
description: optionalText(props, 'description'),
|
|
54
|
+
minSize,
|
|
55
|
+
maxSize,
|
|
56
|
+
items,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function tagCloudNode(spec) {
|
|
61
|
+
return {
|
|
62
|
+
id: spec.id ?? null,
|
|
63
|
+
values: [
|
|
64
|
+
{ id: 'tag-cloud', values: [] },
|
|
65
|
+
...['label', 'description'].flatMap((name) =>
|
|
66
|
+
spec[name] === null || spec[name] === undefined
|
|
67
|
+
? []
|
|
68
|
+
: [prop(name, spec[name])]
|
|
69
|
+
),
|
|
70
|
+
prop('min-size', String(spec.minSize ?? 12)),
|
|
71
|
+
prop('max-size', String(spec.maxSize ?? 36)),
|
|
72
|
+
prop(
|
|
73
|
+
'items',
|
|
74
|
+
...spec.items.map((item) =>
|
|
75
|
+
prop(
|
|
76
|
+
'item',
|
|
77
|
+
item.name,
|
|
78
|
+
...(item.count === null || item.count === undefined
|
|
79
|
+
? []
|
|
80
|
+
: [prop('count', String(item.count))]),
|
|
81
|
+
...(item.color ? [prop('color', item.color)] : []),
|
|
82
|
+
...(item.emphasis ? [prop('emphasis', 'true')] : [])
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
),
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function tagSizes(spec) {
|
|
91
|
+
const max = Math.max(1, ...spec.items.map((item) => item.count ?? 0));
|
|
92
|
+
return spec.items.map(
|
|
93
|
+
(item) =>
|
|
94
|
+
(spec.minSize ?? 12) +
|
|
95
|
+
(((spec.maxSize ?? 36) - (spec.minSize ?? 12)) *
|
|
96
|
+
Math.log1p(item.count ?? 0)) /
|
|
97
|
+
Math.log1p(max)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function drawTagCloud(document, spec) {
|
|
102
|
+
const list = document.createElement('ul');
|
|
103
|
+
list.className = 'ui-tag-cloud';
|
|
104
|
+
list.setAttribute('aria-label', spec.description ?? spec.label ?? 'Tags');
|
|
105
|
+
const sizes = tagSizes(spec);
|
|
106
|
+
spec.items.forEach((item, i) => {
|
|
107
|
+
const li = document.createElement('li');
|
|
108
|
+
li.textContent = `${item.emphasis ? '★ ' : ''}${item.name}`;
|
|
109
|
+
li.setAttribute(
|
|
110
|
+
'aria-label',
|
|
111
|
+
`${item.name}, ${item.count ?? 0}${item.emphasis ? ', emphasized' : ''}`
|
|
112
|
+
);
|
|
113
|
+
li.style.fontSize = `${sizes[i]}px`;
|
|
114
|
+
if (item.color) {
|
|
115
|
+
li.style.color = item.color;
|
|
116
|
+
}
|
|
117
|
+
if (item.emphasis) {
|
|
118
|
+
li.style.fontWeight = 'bold';
|
|
119
|
+
}
|
|
120
|
+
list.append(li);
|
|
121
|
+
});
|
|
122
|
+
return list;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** SVG export keeps the counts in each item's title. DOM rendering is a list. */
|
|
126
|
+
export function tagCloudSvg(spec) {
|
|
127
|
+
const sizes = tagSizes(spec);
|
|
128
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" role="img" aria-label="${escapeXml(spec.description ?? spec.label ?? 'Tags')}" width="640" height="${Math.max(40, spec.items.length * 44)}">${spec.items.map((item, i) => `<text x="8" y="${(i + 1) * 44 - 8}" font-size="${sizes[i]}" fill="${escapeXml(item.color ?? 'currentColor')}"><title>${escapeXml(item.name)}, ${item.count ?? 0}</title>${item.emphasis ? '★ ' : ''}${escapeXml(item.name)}</text>`).join('')}</svg>`;
|
|
129
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colour tokens of the charts: the categorical series `color.chart.1`
|
|
3
|
+
* ... `color.chart.8` and the chart text, axis, grid and background, in a
|
|
4
|
+
* light and a dark mode. Each series colour has at least 3:1 contrast with
|
|
5
|
+
* the background of its mode (WCAG 2.2 non-text contrast, 1.4.11) and the
|
|
6
|
+
* text colours at least 4.5:1 (1.4.3); the tests check both.
|
|
7
|
+
*
|
|
8
|
+
* The renderers write `var(--color-chart-1, #1f6fb2)`, so a page restyles a
|
|
9
|
+
* chart with the CSS custom properties of `@link-foundation/ui-tokens`
|
|
10
|
+
* (`chartTokensLino()` is the theme), and a lone SVG still has its colours.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { formatLinks } from '@link-foundation/ui-core';
|
|
14
|
+
|
|
15
|
+
/** The number of categorical series colours. */
|
|
16
|
+
export const SERIES_COUNT = 8;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The token values of each mode. `background` is the surface the chart is
|
|
20
|
+
* drawn on; `text` titles and labels; `muted` tick labels; `axis` axis
|
|
21
|
+
* lines; `grid` the decorative grid lines; `focus` the focus ring.
|
|
22
|
+
*/
|
|
23
|
+
export const CHART_TOKENS = Object.freeze({
|
|
24
|
+
light: Object.freeze({
|
|
25
|
+
'color.chart.1': '#1f6fb2',
|
|
26
|
+
'color.chart.2': '#c2410c',
|
|
27
|
+
'color.chart.3': '#15803d',
|
|
28
|
+
'color.chart.4': '#b91c5c',
|
|
29
|
+
'color.chart.5': '#6d28d9',
|
|
30
|
+
'color.chart.6': '#0e7490',
|
|
31
|
+
'color.chart.7': '#a16207',
|
|
32
|
+
'color.chart.8': '#4b5563',
|
|
33
|
+
'color.chart.background': '#ffffff',
|
|
34
|
+
'color.chart.text': '#1c1b1f',
|
|
35
|
+
'color.chart.muted': '#5f6368',
|
|
36
|
+
'color.chart.axis': '#5f6368',
|
|
37
|
+
'color.chart.grid': '#e3e3e8',
|
|
38
|
+
'color.chart.focus': '#1c1b1f',
|
|
39
|
+
}),
|
|
40
|
+
dark: Object.freeze({
|
|
41
|
+
'color.chart.1': '#60a5fa',
|
|
42
|
+
'color.chart.2': '#fb923c',
|
|
43
|
+
'color.chart.3': '#4ade80',
|
|
44
|
+
'color.chart.4': '#f472b6',
|
|
45
|
+
'color.chart.5': '#a78bfa',
|
|
46
|
+
'color.chart.6': '#22d3ee',
|
|
47
|
+
'color.chart.7': '#facc15',
|
|
48
|
+
'color.chart.8': '#9ca3af',
|
|
49
|
+
'color.chart.background': '#141218',
|
|
50
|
+
'color.chart.text': '#e6e1e5',
|
|
51
|
+
'color.chart.muted': '#a8a3ad',
|
|
52
|
+
'color.chart.axis': '#a8a3ad',
|
|
53
|
+
'color.chart.grid': '#36343b',
|
|
54
|
+
'color.chart.focus': '#e6e1e5',
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/** The CSS custom property of a token path (`--color-chart-1`). */
|
|
59
|
+
export const tokenVariable = (path) => `--${path.split('.').join('-')}`;
|
|
60
|
+
|
|
61
|
+
/** The path of the series colour of a series index (0-based, cycling). */
|
|
62
|
+
export const seriesToken = (index) =>
|
|
63
|
+
`color.chart.${(index % SERIES_COUNT) + 1}`;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A colour of a token for a renderer: the literal value when `tokens`
|
|
67
|
+
* gives one (an object or a Map of token path to colour), otherwise the
|
|
68
|
+
* CSS custom property with the light value as fallback.
|
|
69
|
+
* @param {string} path
|
|
70
|
+
* @param {Record<string, string>|Map<string, string>|null} [tokens]
|
|
71
|
+
*/
|
|
72
|
+
export function tokenColor(path, tokens = null) {
|
|
73
|
+
const value = tokens instanceof Map ? tokens.get(path) : tokens?.[path];
|
|
74
|
+
if (typeof value === 'string' && value !== '') {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
return `var(${tokenVariable(path)}, ${CHART_TOKENS.light[path]})`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The chart tokens as a `@link-foundation/ui-tokens` theme in Links
|
|
82
|
+
* Notation, in the nested form (#133), with the dark values under
|
|
83
|
+
* `mode dark`.
|
|
84
|
+
* @param {string} [name] the theme name
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
export function chartTokensLino(name = 'charts') {
|
|
88
|
+
const token = ([path, value]) => ['token', path, value];
|
|
89
|
+
return formatLinks([
|
|
90
|
+
{
|
|
91
|
+
id: name,
|
|
92
|
+
values: [
|
|
93
|
+
'theme',
|
|
94
|
+
...Object.entries(CHART_TOKENS.light).map(token),
|
|
95
|
+
['mode', 'dark', ...Object.entries(CHART_TOKENS.dark).map(token)],
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const declarations = (mode) =>
|
|
102
|
+
Object.entries(CHART_TOKENS[mode])
|
|
103
|
+
.map(([path, value]) => `${tokenVariable(path)}: ${value};`)
|
|
104
|
+
.join(' ');
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The style sheet of the chart elements: the token custom properties (light,
|
|
108
|
+
* dark by `prefers-color-scheme` or `data-theme="dark"`), the visually
|
|
109
|
+
* hidden table twin, the tooltip and focus ring, and a fade that is off
|
|
110
|
+
* under `prefers-reduced-motion`.
|
|
111
|
+
*/
|
|
112
|
+
export const CHART_CSS = `:root { ${declarations('light')} }
|
|
113
|
+
@media (prefers-color-scheme: dark) {
|
|
114
|
+
:root:not([data-theme='light']) { ${declarations('dark')} }
|
|
115
|
+
}
|
|
116
|
+
[data-theme='dark'] { ${declarations('dark')} }
|
|
117
|
+
[data-theme='light'] { ${declarations('light')} }
|
|
118
|
+
.ui-chart, .ui-stat-tile, .ui-gauge, .ui-sparkline {
|
|
119
|
+
color: var(--color-chart-text); background: var(--color-chart-background);
|
|
120
|
+
font-family: system-ui, sans-serif; position: relative; display: block;
|
|
121
|
+
}
|
|
122
|
+
.ui-sparkline { display: inline-block; vertical-align: middle; }
|
|
123
|
+
.ui-chart svg, .ui-gauge svg { display: block; max-width: 100%; height: auto; }
|
|
124
|
+
.ui-chart-figure { margin: 0; }
|
|
125
|
+
.ui-chart-canvas { position: relative; border-radius: 4px; }
|
|
126
|
+
.ui-chart-canvas:focus { outline: none; }
|
|
127
|
+
.ui-chart-canvas:focus-visible {
|
|
128
|
+
outline: 2px solid var(--color-chart-focus); outline-offset: 2px;
|
|
129
|
+
}
|
|
130
|
+
.ui-chart-summary { margin: 0.25rem 0; font-size: 0.875rem; color: var(--color-chart-muted); }
|
|
131
|
+
.ui-chart-toggle {
|
|
132
|
+
font: inherit; font-size: 0.875rem; color: var(--color-chart-text);
|
|
133
|
+
background: transparent; border: 1px solid var(--color-chart-axis);
|
|
134
|
+
border-radius: 4px; padding: 0.25rem 0.75rem; cursor: pointer;
|
|
135
|
+
}
|
|
136
|
+
.ui-chart-toggle:focus-visible { outline: 2px solid var(--color-chart-focus); outline-offset: 2px; }
|
|
137
|
+
.ui-chart-table { border-collapse: collapse; margin-top: 0.5rem; font-size: 0.875rem; }
|
|
138
|
+
.ui-chart-table caption { text-align: start; font-weight: 600; padding-bottom: 0.25rem; }
|
|
139
|
+
.ui-chart-table th, .ui-chart-table td {
|
|
140
|
+
border: 1px solid var(--color-chart-grid); padding: 0.25rem 0.5rem; text-align: start;
|
|
141
|
+
}
|
|
142
|
+
.ui-visually-hidden {
|
|
143
|
+
position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
|
|
144
|
+
overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
|
|
145
|
+
}
|
|
146
|
+
.ui-chart-table.ui-visually-hidden { display: block; }
|
|
147
|
+
.ui-chart-tooltip {
|
|
148
|
+
position: absolute; pointer-events: none; z-index: 1; max-width: 16rem;
|
|
149
|
+
background: var(--color-chart-text); color: var(--color-chart-background);
|
|
150
|
+
border-radius: 4px; padding: 0.25rem 0.5rem; font-size: 0.8125rem; line-height: 1.3;
|
|
151
|
+
transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap;
|
|
152
|
+
}
|
|
153
|
+
.ui-chart-tooltip-top { inset: auto; margin: 0; border: 0; transform: none; }
|
|
154
|
+
.ui-chart-tooltip dl { display: grid; grid-template-columns: auto auto; gap: 0.25rem 1rem; margin: 0.5rem 0 0; }
|
|
155
|
+
.ui-chart-tooltip dd { margin: 0; }
|
|
156
|
+
.ui-calendar-scroll { overflow-x: auto; }
|
|
157
|
+
.ui-calendar-scroll svg { max-width: none; }
|
|
158
|
+
.ui-tag-cloud { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1rem; list-style: none; padding: 0; }
|
|
159
|
+
.ui-chart-tooltip[hidden] { display: none; }
|
|
160
|
+
.ui-chart-focus { fill: none; stroke: var(--color-chart-focus); stroke-width: 2; }
|
|
161
|
+
.ui-stat-tile { padding: 0.75rem 1rem; border: 1px solid var(--color-chart-grid); border-radius: 8px; min-width: 10rem; }
|
|
162
|
+
.ui-stat-tile a { color: var(--color-chart-text); text-decoration: underline; }
|
|
163
|
+
.ui-stat-tile-label { font-size: 0.875rem; color: var(--color-chart-muted); margin: 0; }
|
|
164
|
+
.ui-stat-tile-value { font-size: 1.75rem; font-weight: 600; margin: 0.125rem 0; }
|
|
165
|
+
.ui-stat-tile-delta { font-size: 0.875rem; margin: 0; }
|
|
166
|
+
.ui-gauge { width: max-content; }
|
|
167
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
168
|
+
.ui-chart svg, .ui-gauge svg, .ui-sparkline svg { animation: ui-chart-fade 200ms ease-out; }
|
|
169
|
+
}
|
|
170
|
+
@keyframes ui-chart-fade { from { opacity: 0; } to { opacity: 1; } }
|
|
171
|
+
`;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Rich tooltip content uses DOM text nodes only, never consumer HTML. */
|
|
2
|
+
import { positionFloating, virtualAnchor } from '../overlays/position.js';
|
|
3
|
+
|
|
4
|
+
export function tooltipContent(tooltip, point, spec) {
|
|
5
|
+
const content = spec.tooltip?.content?.(point.datum);
|
|
6
|
+
tooltip.replaceChildren();
|
|
7
|
+
if (!content || typeof content !== 'object') {
|
|
8
|
+
tooltip.textContent = point.text;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const document = tooltip.ownerDocument;
|
|
12
|
+
for (const [tag, value] of [
|
|
13
|
+
['strong', content.title],
|
|
14
|
+
['div', content.value],
|
|
15
|
+
]) {
|
|
16
|
+
if (value === null || value === undefined) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const element = document.createElement(tag);
|
|
20
|
+
element.textContent = String(value);
|
|
21
|
+
tooltip.append(element);
|
|
22
|
+
}
|
|
23
|
+
if (content.rows?.length) {
|
|
24
|
+
const list = document.createElement('dl');
|
|
25
|
+
for (const [label, value] of content.rows) {
|
|
26
|
+
const term = document.createElement('dt'),
|
|
27
|
+
detail = document.createElement('dd');
|
|
28
|
+
term.textContent = String(label);
|
|
29
|
+
detail.textContent = String(value);
|
|
30
|
+
list.append(term, detail);
|
|
31
|
+
}
|
|
32
|
+
tooltip.append(list);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function showTopTooltip(tooltip, canvas, x, y, left) {
|
|
37
|
+
tooltip.setAttribute('popover', 'manual');
|
|
38
|
+
tooltip.classList.add('ui-chart-tooltip-top');
|
|
39
|
+
tooltip.hidden = false;
|
|
40
|
+
if (!tooltip.matches(':popover-open')) {
|
|
41
|
+
tooltip.showPopover?.();
|
|
42
|
+
}
|
|
43
|
+
return positionFloating(virtualAnchor(x, y, canvas), tooltip, {
|
|
44
|
+
placement: left ? 'left-start' : 'right-start',
|
|
45
|
+
offset: 10,
|
|
46
|
+
});
|
|
47
|
+
}
|