@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,78 @@
|
|
|
1
|
+
/** Value-end rounding and redundant text labels for Cartesian marks. */
|
|
2
|
+
export function roundedBar(rect, radius, horizontal, reverse, fill, row) {
|
|
3
|
+
const { x, y, width: w, height: h } = rect;
|
|
4
|
+
const r = Math.min(radius, w / 2, h / 2);
|
|
5
|
+
// Trace from the baseline, rounding the two corners at the value end only.
|
|
6
|
+
let d;
|
|
7
|
+
if (horizontal) {
|
|
8
|
+
d = reverse
|
|
9
|
+
? `M${x + w},${y}H${x + r}Q${x},${y} ${x},${y + r}V${y + h - r}Q${x},${y + h} ${x + r},${y + h}H${x + w}Z`
|
|
10
|
+
: `M${x},${y}H${x + w - r}Q${x + w},${y} ${x + w},${y + r}V${y + h - r}Q${x + w},${y + h} ${x + w - r},${y + h}H${x}Z`;
|
|
11
|
+
} else {
|
|
12
|
+
d = reverse
|
|
13
|
+
? `M${x},${y + h}V${y + r}Q${x},${y} ${x + r},${y}H${x + w - r}Q${x + w},${y} ${x + w},${y + r}V${y + h}Z`
|
|
14
|
+
: `M${x},${y}V${y + h - r}Q${x},${y + h} ${x + r},${y + h}H${x + w - r}Q${x + w},${y + h} ${x + w},${y + h - r}V${y}Z`;
|
|
15
|
+
}
|
|
16
|
+
return { tag: 'path', attrs: { d, fill }, row };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const emphasized = (value) =>
|
|
20
|
+
value === true || value === 1 || value === 'true' || value === '1';
|
|
21
|
+
|
|
22
|
+
export function decorateSeries(spec, shapes, points) {
|
|
23
|
+
const horizontal =
|
|
24
|
+
spec.encoding.x.type === 'quantitative' &&
|
|
25
|
+
spec.encoding.y.type !== 'quantitative';
|
|
26
|
+
const field = (horizontal ? spec.encoding.x : spec.encoding.y).field;
|
|
27
|
+
const value = (i) => Number(spec.data.values[points[i].row][field]);
|
|
28
|
+
points.forEach((point, i) => {
|
|
29
|
+
const emphasis =
|
|
30
|
+
spec.emphasis && emphasized(spec.data.values[point.row][spec.emphasis]);
|
|
31
|
+
if (emphasis) {
|
|
32
|
+
point.text += ', ★ emphasized';
|
|
33
|
+
}
|
|
34
|
+
const label =
|
|
35
|
+
spec.labels === 'last'
|
|
36
|
+
? i === points.length - 1
|
|
37
|
+
: spec.labels === 'peaks' &&
|
|
38
|
+
i > 0 &&
|
|
39
|
+
i < points.length - 1 &&
|
|
40
|
+
value(i) > value(i - 1) &&
|
|
41
|
+
value(i) >= value(i + 1);
|
|
42
|
+
if (label || emphasis) {
|
|
43
|
+
shapes.push({
|
|
44
|
+
tag: 'text',
|
|
45
|
+
attrs: {
|
|
46
|
+
x: point.x,
|
|
47
|
+
y: point.y - 6,
|
|
48
|
+
fill: 'var(--color-chart-text, #1c1b1f)',
|
|
49
|
+
'font-size': 11,
|
|
50
|
+
'text-anchor': 'middle',
|
|
51
|
+
},
|
|
52
|
+
content: `${emphasis ? '★ ' : ''}${label ? value(i) : ''}`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Arc marks have no Cartesian value axis; emphasize them with a visible star. */
|
|
59
|
+
export function emphasizeArcs(spec, shapes, points) {
|
|
60
|
+
for (const point of points) {
|
|
61
|
+
if (
|
|
62
|
+
spec.emphasis &&
|
|
63
|
+
emphasized(spec.data.values[point.row][spec.emphasis])
|
|
64
|
+
) {
|
|
65
|
+
point.text += ', ★ emphasized';
|
|
66
|
+
shapes.push({
|
|
67
|
+
tag: 'text',
|
|
68
|
+
attrs: {
|
|
69
|
+
x: point.x,
|
|
70
|
+
y: point.y,
|
|
71
|
+
fill: 'var(--color-chart-text, #1c1b1f)',
|
|
72
|
+
'text-anchor': 'middle',
|
|
73
|
+
},
|
|
74
|
+
content: '★',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Readers of property links shared by the chart dialect and the small
|
|
3
|
+
* charts: `(name value)` atoms, numbers, booleans, and property lists.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { fail } from './errors.js';
|
|
7
|
+
import { headName, isAtom } from './lino.js';
|
|
8
|
+
import { toNumber } from './values.js';
|
|
9
|
+
|
|
10
|
+
/** The single atom value of a property node, or a ChartSpecError. */
|
|
11
|
+
export function single(node, path, name) {
|
|
12
|
+
const [, ...values] = node.values;
|
|
13
|
+
if (values.length !== 1 || !isAtom(values[0])) {
|
|
14
|
+
fail('invalid-value', `(${name}) needs exactly one value`, node, path);
|
|
15
|
+
}
|
|
16
|
+
return values[0].id;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A finite number property. */
|
|
20
|
+
export function numberOf(node, path, name) {
|
|
21
|
+
const value = toNumber(single(node, path, name));
|
|
22
|
+
if (value === null) {
|
|
23
|
+
fail('invalid-value', `(${name}) must be a number`, node, path);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A `true`/`false` property. */
|
|
29
|
+
export function booleanOf(node, path, name) {
|
|
30
|
+
const value = single(node, path, name);
|
|
31
|
+
if (value !== 'true' && value !== 'false') {
|
|
32
|
+
fail('invalid-value', `(${name}) must be true or false`, node, path);
|
|
33
|
+
}
|
|
34
|
+
return value === 'true';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The property nodes of a link after its kind (or name), each with its
|
|
39
|
+
* position, checked against the allowed names and for repeats.
|
|
40
|
+
* @param {import('./lino.js').Node} node
|
|
41
|
+
* @param {number[]} path
|
|
42
|
+
* @param {number} from the index of the first property
|
|
43
|
+
* @param {readonly string[]} allowed
|
|
44
|
+
* @param {readonly string[]} [repeatable]
|
|
45
|
+
* @returns {Map<string, {node: import('./lino.js').Node, path: number[]}[]>}
|
|
46
|
+
*/
|
|
47
|
+
export function properties(node, path, from, allowed, repeatable = []) {
|
|
48
|
+
const found = new Map();
|
|
49
|
+
node.values.slice(from).forEach((child, i) => {
|
|
50
|
+
const where = [...path, from + i];
|
|
51
|
+
const name = headName(child);
|
|
52
|
+
if (name === null || !allowed.includes(name)) {
|
|
53
|
+
fail(
|
|
54
|
+
'unknown-property',
|
|
55
|
+
name === null
|
|
56
|
+
? 'expected a property link (name value...)'
|
|
57
|
+
: `unknown property "${name}"`,
|
|
58
|
+
child,
|
|
59
|
+
where
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (found.has(name) && !repeatable.includes(name)) {
|
|
63
|
+
fail('duplicate-property', `(${name}) is given twice`, child, where);
|
|
64
|
+
}
|
|
65
|
+
found.set(name, [...(found.get(name) ?? []), { node: child, path: where }]);
|
|
66
|
+
});
|
|
67
|
+
return found;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The text of an optional single-atom property. */
|
|
71
|
+
export function optionalText(props, name) {
|
|
72
|
+
const entry = props.get(name)?.[0];
|
|
73
|
+
return entry === undefined ? null : single(entry.node, entry.path, name);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The numbers of a list property `(name 1 2 3)` (at least one). */
|
|
77
|
+
export function numberList(entry, name) {
|
|
78
|
+
const { node, path } = entry;
|
|
79
|
+
const values = node.values.slice(1);
|
|
80
|
+
if (values.length === 0) {
|
|
81
|
+
fail('invalid-value', `(${name}) needs at least one number`, node, path);
|
|
82
|
+
}
|
|
83
|
+
return values.map((value, i) => {
|
|
84
|
+
const number = isAtom(value) ? toNumber(value.id) : null;
|
|
85
|
+
if (number === null) {
|
|
86
|
+
fail('invalid-value', `(${name}) must hold numbers`, value, [
|
|
87
|
+
...path,
|
|
88
|
+
i + 1,
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
return number;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** An optional number property, or `fallback`. */
|
|
96
|
+
export function optionalNumber(props, name, fallback = null) {
|
|
97
|
+
const entry = props.get(name)?.[0];
|
|
98
|
+
return entry === undefined
|
|
99
|
+
? fallback
|
|
100
|
+
: numberOf(entry.node, entry.path, name);
|
|
101
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Extended activity features use the accessible SVG renderer in every host. */
|
|
2
|
+
export const supportsECharts = (spec) =>
|
|
3
|
+
['line', 'area', 'bar', 'point', 'arc'].includes(spec.mark.type) &&
|
|
4
|
+
!spec.cornerRadius &&
|
|
5
|
+
!spec.labels &&
|
|
6
|
+
!spec.emphasis &&
|
|
7
|
+
!spec.tooltip &&
|
|
8
|
+
!Object.values(spec.encoding).some((def) => def.scale);
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scales of the chart dialect: each encoding channel maps its field to
|
|
3
|
+
* pixels or colours through d3-scale. Temporal fields use UTC scales, so a
|
|
4
|
+
* chart looks the same in every time zone.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
scaleBand,
|
|
9
|
+
scaleLinear,
|
|
10
|
+
scaleLog,
|
|
11
|
+
scalePoint,
|
|
12
|
+
scaleSqrt,
|
|
13
|
+
scaleUtc,
|
|
14
|
+
} from 'd3-scale';
|
|
15
|
+
import { seriesToken, tokenColor } from './tokens.js';
|
|
16
|
+
import { formatNumber, formatTime, parseTemporal } from './values.js';
|
|
17
|
+
|
|
18
|
+
/** Whether a field is discrete (nominal or ordinal). */
|
|
19
|
+
export const isDiscrete = (def) =>
|
|
20
|
+
def.type === 'nominal' || def.type === 'ordinal';
|
|
21
|
+
|
|
22
|
+
/** The title of a field: its `(title)` or the field name. */
|
|
23
|
+
export const fieldTitle = (def) => def.title ?? def.field;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A value as people read it: a date for temporal fields, a grouped number
|
|
27
|
+
* for quantitative fields, the text otherwise.
|
|
28
|
+
* @param {import('./chart-model.js').FieldDef} def
|
|
29
|
+
* @param {string|number} value
|
|
30
|
+
*/
|
|
31
|
+
export function formatValue(def, value) {
|
|
32
|
+
if (def.type === 'temporal') {
|
|
33
|
+
const time = parseTemporal(value);
|
|
34
|
+
return time === null ? String(value) : formatTime(time);
|
|
35
|
+
}
|
|
36
|
+
if (def.type === 'quantitative' && typeof value === 'number') {
|
|
37
|
+
return formatNumber(value);
|
|
38
|
+
}
|
|
39
|
+
return String(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The number a continuous scale reads from a value. */
|
|
43
|
+
export const continuousValue = (def, value) =>
|
|
44
|
+
def.type === 'temporal' ? parseTemporal(value) : Number(value);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The distinct values of a field, as text keys: in data order for nominal
|
|
48
|
+
* and ordinal fields, ascending for temporal and quantitative ones.
|
|
49
|
+
* @param {import('./chart-model.js').FieldDef} def
|
|
50
|
+
* @param {readonly Record<string, string|number>[]} rows
|
|
51
|
+
* @returns {string[]}
|
|
52
|
+
*/
|
|
53
|
+
export function discreteDomain(def, rows) {
|
|
54
|
+
const keys = [...new Set(rows.map((row) => String(row[def.field])))];
|
|
55
|
+
if (isDiscrete(def)) {
|
|
56
|
+
return keys;
|
|
57
|
+
}
|
|
58
|
+
return keys.sort((a, b) => continuousValue(def, a) - continuousValue(def, b));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function logPositionScale(def, rows, range, extent) {
|
|
62
|
+
const base = def.scale.base ?? 10;
|
|
63
|
+
const positive = rows
|
|
64
|
+
.map((row) => Number(row[def.field]))
|
|
65
|
+
.concat(extent)
|
|
66
|
+
.filter((value) => value > 0);
|
|
67
|
+
const low = positive.length ? Math.min(...positive) : 1;
|
|
68
|
+
const high = positive.length ? Math.max(...positive) : base;
|
|
69
|
+
const scale = scaleLog()
|
|
70
|
+
.base(base)
|
|
71
|
+
.domain([low, high === low ? low * base : high])
|
|
72
|
+
.range(range)
|
|
73
|
+
.nice();
|
|
74
|
+
const minimum = scale.domain()[0];
|
|
75
|
+
const position = (value) => scale(Math.max(minimum, Number(value)));
|
|
76
|
+
return {
|
|
77
|
+
kind: 'continuous',
|
|
78
|
+
position,
|
|
79
|
+
continuous: position,
|
|
80
|
+
bandwidth: 0,
|
|
81
|
+
ticks: () => {
|
|
82
|
+
const [a, b] = scale.domain();
|
|
83
|
+
const ticks = [];
|
|
84
|
+
const first = Math.ceil(Math.log(a) / Math.log(base) - 1e-10);
|
|
85
|
+
const last = Math.floor(Math.log(b) / Math.log(base) + 1e-10);
|
|
86
|
+
const stride = Math.max(1, Math.ceil((last - first) / 32));
|
|
87
|
+
for (let power = first; power <= last; power += stride) {
|
|
88
|
+
const value = base ** power;
|
|
89
|
+
ticks.push({
|
|
90
|
+
value,
|
|
91
|
+
position: scale(value),
|
|
92
|
+
label: formatNumber(value),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return ticks;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A domain that is not a single point. */
|
|
101
|
+
function spread([low, high], def) {
|
|
102
|
+
if (low !== high) {
|
|
103
|
+
return [low, high];
|
|
104
|
+
}
|
|
105
|
+
const step = def.type === 'temporal' ? 86_400_000 : Math.abs(low) || 1;
|
|
106
|
+
return [low - step, high + step];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A domain widened by a share of its span at both ends. */
|
|
110
|
+
function padded([low, high], pad) {
|
|
111
|
+
const margin = (high - low) * pad;
|
|
112
|
+
return [low - margin, high + margin];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A position scale of a channel.
|
|
117
|
+
* @param {import('./chart-model.js').FieldDef} def
|
|
118
|
+
* @param {readonly Record<string, string|number>[]} rows
|
|
119
|
+
* @param {[number, number]} range
|
|
120
|
+
* @param {object} [options]
|
|
121
|
+
* @param {boolean} [options.band] a band per value (bars)
|
|
122
|
+
* @param {boolean} [options.zero] include zero (bars, areas)
|
|
123
|
+
* @param {number[]} [options.extent] extra values to include (stacks)
|
|
124
|
+
* @param {number} [options.pad] a share of the span added at both ends
|
|
125
|
+
* of a quantitative domain, so marks (points) clear the axes
|
|
126
|
+
* @returns {PositionScale}
|
|
127
|
+
*
|
|
128
|
+
* @typedef {object} PositionScale
|
|
129
|
+
* @property {'band'|'point'|'continuous'} kind
|
|
130
|
+
* @property {(value: string|number) => number} position the pixel centre
|
|
131
|
+
* @property {number} bandwidth the band width (0 unless `band`)
|
|
132
|
+
* @property {(value: number) => number} [continuous] the raw d3 scale
|
|
133
|
+
* @property {(count: number) => {position: number, label: string, value: number|string}[]} ticks
|
|
134
|
+
*/
|
|
135
|
+
export function positionScale(def, rows, range, options = {}) {
|
|
136
|
+
const { band = false, zero = false, extent = [], pad = 0 } = options;
|
|
137
|
+
if (band || isDiscrete(def)) {
|
|
138
|
+
const domain = discreteDomain(def, rows);
|
|
139
|
+
const scale = band
|
|
140
|
+
? scaleBand(domain, range).paddingInner(0.2).paddingOuter(0.1)
|
|
141
|
+
: scalePoint(domain, range).padding(0.5);
|
|
142
|
+
const half = scale.bandwidth() / 2;
|
|
143
|
+
const position = (value) => scale(String(value)) + half;
|
|
144
|
+
return {
|
|
145
|
+
kind: band ? 'band' : 'point',
|
|
146
|
+
position,
|
|
147
|
+
bandwidth: scale.bandwidth(),
|
|
148
|
+
ticks: () =>
|
|
149
|
+
domain.map((key) => ({
|
|
150
|
+
value: key,
|
|
151
|
+
position: position(key),
|
|
152
|
+
label: formatValue(
|
|
153
|
+
def,
|
|
154
|
+
def.type === 'quantitative' ? Number(key) : key
|
|
155
|
+
),
|
|
156
|
+
})),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (def.scale?.type === 'log') {
|
|
160
|
+
return logPositionScale(def, rows, range, extent);
|
|
161
|
+
}
|
|
162
|
+
const values = [
|
|
163
|
+
...rows.map((row) => continuousValue(def, row[def.field])),
|
|
164
|
+
...extent,
|
|
165
|
+
...(zero ? [0] : []),
|
|
166
|
+
];
|
|
167
|
+
const bounds = padded(
|
|
168
|
+
spread([Math.min(...values), Math.max(...values)], def),
|
|
169
|
+
def.type === 'quantitative' ? pad : 0
|
|
170
|
+
);
|
|
171
|
+
const scale =
|
|
172
|
+
def.type === 'temporal'
|
|
173
|
+
? scaleUtc().domain(bounds).range(range)
|
|
174
|
+
: scaleLinear().domain(bounds).range(range).nice();
|
|
175
|
+
return {
|
|
176
|
+
kind: 'continuous',
|
|
177
|
+
position: (value) => scale(continuousValue(def, value)),
|
|
178
|
+
continuous: (value) => scale(value),
|
|
179
|
+
bandwidth: 0,
|
|
180
|
+
ticks: (count) => {
|
|
181
|
+
const format = scale.tickFormat(count);
|
|
182
|
+
return scale.ticks(count).map((value) => ({
|
|
183
|
+
value: Number(value),
|
|
184
|
+
position: scale(value),
|
|
185
|
+
label: format(value),
|
|
186
|
+
}));
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The colour scale of the `color` channel: the series colour tokens in the
|
|
193
|
+
* order of the distinct values.
|
|
194
|
+
* @param {import('./chart-model.js').FieldDef|undefined} def
|
|
195
|
+
* @param {readonly Record<string, string|number>[]} rows
|
|
196
|
+
* @param {Record<string, string>|Map<string, string>|null} [tokens]
|
|
197
|
+
*/
|
|
198
|
+
export function colorScale(def, rows, tokens = null) {
|
|
199
|
+
const domain = def === undefined ? [] : discreteDomain(def, rows);
|
|
200
|
+
const colorAt = (index) => tokenColor(seriesToken(index), tokens);
|
|
201
|
+
return {
|
|
202
|
+
domain,
|
|
203
|
+
colorAt,
|
|
204
|
+
index: (value) => Math.max(0, domain.indexOf(String(value))),
|
|
205
|
+
color: (value) => colorAt(Math.max(0, domain.indexOf(String(value)))),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The radius scale of the `size` channel: the area of a point grows with
|
|
211
|
+
* the value.
|
|
212
|
+
* @param {import('./chart-model.js').FieldDef|undefined} def
|
|
213
|
+
* @param {readonly Record<string, string|number>[]} rows
|
|
214
|
+
* @param {[number, number]} [range] radii in pixels
|
|
215
|
+
*/
|
|
216
|
+
export function sizeScale(def, rows, range = [3, 12]) {
|
|
217
|
+
if (def === undefined) {
|
|
218
|
+
return () => 4.5;
|
|
219
|
+
}
|
|
220
|
+
const max = Math.max(...rows.map((row) => Math.abs(Number(row[def.field]))));
|
|
221
|
+
const scale = scaleSqrt([0, max || 1], range);
|
|
222
|
+
return (value) => scale(Math.abs(Number(value)));
|
|
223
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The small charts of the chart dialect: a single value with context.
|
|
3
|
+
*
|
|
4
|
+
* ```lino
|
|
5
|
+
* (cpu: gauge (label CPU) (value 72) (min 0) (max 100) (unit %))
|
|
6
|
+
* (revenue: stat-tile (label Revenue) (value 30200) (unit USD) (delta 12.5)
|
|
7
|
+
* (trend 12 18 21 25 30))
|
|
8
|
+
* (visits: sparkline (label Visits) (values 3 5 2 8 6) (mark area))
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { fail } from './errors.js';
|
|
13
|
+
import { prop } from './lino.js';
|
|
14
|
+
import {
|
|
15
|
+
numberList,
|
|
16
|
+
optionalNumber,
|
|
17
|
+
optionalText,
|
|
18
|
+
properties,
|
|
19
|
+
} from './read.js';
|
|
20
|
+
|
|
21
|
+
/** The kinds of the small charts. */
|
|
22
|
+
export const SMALL_KINDS = Object.freeze(['gauge', 'stat-tile', 'sparkline']);
|
|
23
|
+
|
|
24
|
+
/** The marks a sparkline can draw. */
|
|
25
|
+
export const SPARKLINE_MARKS = Object.freeze(['line', 'area', 'bar']);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} GaugeSpec
|
|
29
|
+
* @property {'gauge'} kind
|
|
30
|
+
* @property {string|null} id
|
|
31
|
+
* @property {string|null} label
|
|
32
|
+
* @property {string|null} description
|
|
33
|
+
* @property {number} value
|
|
34
|
+
* @property {number} min default 0
|
|
35
|
+
* @property {number} max default 100
|
|
36
|
+
* @property {string|null} unit
|
|
37
|
+
*
|
|
38
|
+
* @typedef {object} StatTileSpec
|
|
39
|
+
* @property {'stat-tile'} kind
|
|
40
|
+
* @property {string|null} id
|
|
41
|
+
* @property {string|null} label
|
|
42
|
+
* @property {string|null} description
|
|
43
|
+
* @property {number} value
|
|
44
|
+
* @property {string|null} unit
|
|
45
|
+
* @property {number|null} delta the change, in percent
|
|
46
|
+
* @property {number[]} trend recent values, drawn as a sparkline
|
|
47
|
+
*
|
|
48
|
+
* @typedef {object} SparklineSpec
|
|
49
|
+
* @property {'sparkline'} kind
|
|
50
|
+
* @property {string|null} id
|
|
51
|
+
* @property {string|null} label
|
|
52
|
+
* @property {string|null} description
|
|
53
|
+
* @property {number[]} values
|
|
54
|
+
* @property {'line'|'area'|'bar'} mark
|
|
55
|
+
*
|
|
56
|
+
* @typedef {GaugeSpec|StatTileSpec|SparklineSpec} SmallChartSpec
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
const COMMON = ['label', 'description'];
|
|
60
|
+
|
|
61
|
+
const PROPERTIES = {
|
|
62
|
+
gauge: [...COMMON, 'value', 'min', 'max', 'unit'],
|
|
63
|
+
'stat-tile': [
|
|
64
|
+
...COMMON,
|
|
65
|
+
'value',
|
|
66
|
+
'unit',
|
|
67
|
+
'delta',
|
|
68
|
+
'trend',
|
|
69
|
+
'notation',
|
|
70
|
+
'compact-threshold',
|
|
71
|
+
'hint',
|
|
72
|
+
'footnote',
|
|
73
|
+
],
|
|
74
|
+
sparkline: [...COMMON, 'values', 'mark'],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** A required property entry, or a ChartSpecError at the chart. */
|
|
78
|
+
function required(props, name, node, path, kind) {
|
|
79
|
+
const entry = props.get(name)?.[0];
|
|
80
|
+
if (entry === undefined) {
|
|
81
|
+
fail('missing-field', `a ${kind} needs (${name} ...)`, node, path);
|
|
82
|
+
}
|
|
83
|
+
return entry;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function readGauge(props, node, path) {
|
|
87
|
+
required(props, 'value', node, path, 'gauge');
|
|
88
|
+
const gauge = {
|
|
89
|
+
value: optionalNumber(props, 'value'),
|
|
90
|
+
min: optionalNumber(props, 'min', 0),
|
|
91
|
+
max: optionalNumber(props, 'max', 100),
|
|
92
|
+
unit: optionalText(props, 'unit'),
|
|
93
|
+
};
|
|
94
|
+
if (gauge.max <= gauge.min) {
|
|
95
|
+
const entry = props.get('max')?.[0] ?? { node, path };
|
|
96
|
+
fail('invalid-value', '(max) must be above (min)', entry.node, entry.path);
|
|
97
|
+
}
|
|
98
|
+
return gauge;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function readStatTile(props, node, path) {
|
|
102
|
+
required(props, 'value', node, path, 'stat-tile');
|
|
103
|
+
const trend = props.get('trend')?.[0];
|
|
104
|
+
const extras = {};
|
|
105
|
+
for (const name of ['notation', 'hint']) {
|
|
106
|
+
if (props.has(name)) {
|
|
107
|
+
extras[name] = optionalText(props, name);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (extras.notation && extras.notation !== 'compact') {
|
|
111
|
+
fail('invalid-value', 'notation must be compact', node, path);
|
|
112
|
+
}
|
|
113
|
+
if (props.has('compact-threshold')) {
|
|
114
|
+
extras.compactThreshold = optionalNumber(props, 'compact-threshold');
|
|
115
|
+
if (extras.compactThreshold < 0) {
|
|
116
|
+
fail(
|
|
117
|
+
'invalid-value',
|
|
118
|
+
'compact-threshold must be nonnegative',
|
|
119
|
+
node,
|
|
120
|
+
path
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (props.has('footnote')) {
|
|
125
|
+
const entry = props.get('footnote')[0];
|
|
126
|
+
const fields = properties(entry.node, entry.path, 1, ['label', 'href']);
|
|
127
|
+
const href = optionalText(fields, 'href');
|
|
128
|
+
if (!href || !/^(https?:|mailto:|\/|#)/u.test(href)) {
|
|
129
|
+
fail(
|
|
130
|
+
'invalid-value',
|
|
131
|
+
'footnote requires an http, mailto or relative href',
|
|
132
|
+
entry.node,
|
|
133
|
+
entry.path
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
extras.footnote = {
|
|
137
|
+
label: optionalText(fields, 'label') ?? 'Source',
|
|
138
|
+
href,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
...extras,
|
|
143
|
+
value: optionalNumber(props, 'value'),
|
|
144
|
+
unit: optionalText(props, 'unit'),
|
|
145
|
+
delta: optionalNumber(props, 'delta'),
|
|
146
|
+
trend: trend === undefined ? [] : numberList(trend, 'trend'),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function readSparkline(props, node, path) {
|
|
151
|
+
const values = numberList(
|
|
152
|
+
required(props, 'values', node, path, 'sparkline'),
|
|
153
|
+
'values'
|
|
154
|
+
);
|
|
155
|
+
const mark = optionalText(props, 'mark') ?? 'line';
|
|
156
|
+
if (!SPARKLINE_MARKS.includes(mark)) {
|
|
157
|
+
const entry = props.get('mark')[0];
|
|
158
|
+
fail(
|
|
159
|
+
'unknown-mark',
|
|
160
|
+
`unknown sparkline mark "${mark}" (expected ${SPARKLINE_MARKS.join(', ')})`,
|
|
161
|
+
entry.node,
|
|
162
|
+
entry.path
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
return { values, mark };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const READERS = {
|
|
169
|
+
gauge: readGauge,
|
|
170
|
+
'stat-tile': readStatTile,
|
|
171
|
+
sparkline: readSparkline,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Read one small chart node (already unfolded).
|
|
176
|
+
* @param {import('./lino.js').Node} node
|
|
177
|
+
* @param {number[]} path
|
|
178
|
+
* @param {'gauge'|'stat-tile'|'sparkline'} kind
|
|
179
|
+
* @returns {SmallChartSpec}
|
|
180
|
+
*/
|
|
181
|
+
export function readSmallChart(node, path, kind) {
|
|
182
|
+
const props = properties(node, path, 1, PROPERTIES[kind]);
|
|
183
|
+
return {
|
|
184
|
+
kind,
|
|
185
|
+
id: node.id,
|
|
186
|
+
label: optionalText(props, 'label'),
|
|
187
|
+
description: optionalText(props, 'description'),
|
|
188
|
+
...READERS[kind](props, node, path),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const DEFAULTS = { min: 0, max: 100, mark: 'line' };
|
|
193
|
+
|
|
194
|
+
/** Whether a property keeps its default (and is not written). */
|
|
195
|
+
const isDefault = (name, value) =>
|
|
196
|
+
value === null ||
|
|
197
|
+
value === undefined ||
|
|
198
|
+
DEFAULTS[name] === value ||
|
|
199
|
+
(Array.isArray(value) && value.length === 0);
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The LiNo node of a small chart spec.
|
|
203
|
+
* @param {SmallChartSpec} spec
|
|
204
|
+
*/
|
|
205
|
+
export function smallChartNode(spec) {
|
|
206
|
+
const values = [{ id: spec.kind, values: [] }];
|
|
207
|
+
for (const name of PROPERTIES[spec.kind]) {
|
|
208
|
+
const value =
|
|
209
|
+
spec[name === 'compact-threshold' ? 'compactThreshold' : name];
|
|
210
|
+
if (name === 'footnote' && value) {
|
|
211
|
+
values.push(
|
|
212
|
+
prop('footnote', prop('label', value.label), prop('href', value.href))
|
|
213
|
+
);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (!isDefault(name, value)) {
|
|
217
|
+
values.push(
|
|
218
|
+
prop(name, ...(Array.isArray(value) ? value : [value]).map(String))
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return { id: spec.id ?? null, values };
|
|
223
|
+
}
|