@link-foundation/ui-components 0.0.0-stage → 0.0.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.
Files changed (402) hide show
  1. package/CONFIGURATIONS.md +74 -0
  2. package/ICONS.md +76 -0
  3. package/LICENSE +24 -0
  4. package/README.md +1499 -2
  5. package/bin/lino-network.mjs +71 -0
  6. package/dist/icons/ATTRIBUTION.md +602 -0
  7. package/dist/icons/NOTICE.lino +1261 -0
  8. package/dist/icons/brand.js +31 -0
  9. package/dist/icons/brand.svg +3 -0
  10. package/dist/icons/licenses/brand/DISCLAIMER.md +51 -0
  11. package/dist/icons/licenses/brand/LICENSE.md +30 -0
  12. package/dist/icons/licenses/lucide/LICENSE +43 -0
  13. package/dist/icons/licenses/material-symbols/LICENSE +202 -0
  14. package/dist/icons/licenses/material-symbols/NOTICE +12 -0
  15. package/dist/icons/licenses/tabler/LICENSE +21 -0
  16. package/dist/icons/lucide.js +681 -0
  17. package/dist/icons/lucide.svg +34 -0
  18. package/dist/icons/material-symbols.js +681 -0
  19. package/dist/icons/material-symbols.svg +34 -0
  20. package/dist/icons/own.js +521 -0
  21. package/dist/icons/own.svg +34 -0
  22. package/dist/icons/tabler.js +681 -0
  23. package/dist/icons/tabler.svg +34 -0
  24. package/dist/network-layout-NOTICE.md +6 -0
  25. package/dist/network-layout-d3-dispatch-LICENSE.txt +13 -0
  26. package/dist/network-layout-d3-force-LICENSE.txt +13 -0
  27. package/dist/network-layout-d3-quadtree-LICENSE.txt +13 -0
  28. package/dist/network-layout-d3-timer-LICENSE.txt +13 -0
  29. package/dist/network-layout-dagre-LICENSE.txt +19 -0
  30. package/dist/network-layout.worker.mjs +2 -0
  31. package/package.json +246 -4
  32. package/src/a11y/announce.js +88 -0
  33. package/src/a11y/bind-machine.js +181 -0
  34. package/src/a11y/focus.js +169 -0
  35. package/src/a11y/index.d.ts +89 -0
  36. package/src/a11y/index.js +19 -0
  37. package/src/a11y/keys.js +182 -0
  38. package/src/a11y/roving.js +167 -0
  39. package/src/a11y/typeahead.js +82 -0
  40. package/src/behavior/actions.js +235 -0
  41. package/src/behavior/diagnostics.js +73 -0
  42. package/src/behavior/dom.d.ts +38 -0
  43. package/src/behavior/dom.js +420 -0
  44. package/src/behavior/index.d.ts +211 -0
  45. package/src/behavior/index.js +29 -0
  46. package/src/behavior/interpret.js +454 -0
  47. package/src/behavior/machines/disclosure.lino +46 -0
  48. package/src/behavior/machines/index.js +91 -0
  49. package/src/behavior/machines/toggle.lino +25 -0
  50. package/src/behavior/parse-machine.js +367 -0
  51. package/src/charts/README.md +78 -0
  52. package/src/charts/activity-layout.js +350 -0
  53. package/src/charts/activity-model.js +130 -0
  54. package/src/charts/activity-validation.js +31 -0
  55. package/src/charts/chart-model.js +667 -0
  56. package/src/charts/chart.js +518 -0
  57. package/src/charts/echarts-adapter.d.ts +23 -0
  58. package/src/charts/echarts-adapter.js +240 -0
  59. package/src/charts/element.js +330 -0
  60. package/src/charts/errors.js +62 -0
  61. package/src/charts/gauge.js +27 -0
  62. package/src/charts/index.d.ts +344 -0
  63. package/src/charts/index.js +59 -0
  64. package/src/charts/layout.js +542 -0
  65. package/src/charts/lino.js +158 -0
  66. package/src/charts/mark-options.js +78 -0
  67. package/src/charts/read.js +101 -0
  68. package/src/charts/renderer-features.js +8 -0
  69. package/src/charts/scales.js +223 -0
  70. package/src/charts/small-model.js +223 -0
  71. package/src/charts/small-svg.js +269 -0
  72. package/src/charts/sparkline.js +27 -0
  73. package/src/charts/stat-tile.js +37 -0
  74. package/src/charts/summary.js +193 -0
  75. package/src/charts/svg-renderer.js +226 -0
  76. package/src/charts/svg.js +69 -0
  77. package/src/charts/tag-cloud.js +129 -0
  78. package/src/charts/tokens.js +171 -0
  79. package/src/charts/tooltip.js +47 -0
  80. package/src/charts/values.js +146 -0
  81. package/src/chat/README.md +142 -0
  82. package/src/chat/actions.js +75 -0
  83. package/src/chat/chat-contract.js +95 -0
  84. package/src/chat/chat-list.js +42 -0
  85. package/src/chat/chat-model.js +125 -0
  86. package/src/chat/chat.css +228 -0
  87. package/src/chat/composer.js +131 -0
  88. package/src/chat/day-separator.js +12 -0
  89. package/src/chat/dom.js +33 -0
  90. package/src/chat/follow.js +49 -0
  91. package/src/chat/index.d.ts +142 -0
  92. package/src/chat/index.js +13 -0
  93. package/src/chat/message-bubble.js +191 -0
  94. package/src/chat/message-stream.js +331 -0
  95. package/src/chat/reasoning-trace.js +70 -0
  96. package/src/chat/selection.js +39 -0
  97. package/src/chat/skins/bubbles.lino +2 -0
  98. package/src/chat/skins/cards.lino +4 -0
  99. package/src/chat/skins/compact.lino +4 -0
  100. package/src/chat/skins/signal.lino +25 -0
  101. package/src/chat/skins/t3.lino +25 -0
  102. package/src/chat/skins/telegram.lino +31 -0
  103. package/src/chat/skins/whatsapp.lino +25 -0
  104. package/src/chat/stream-keys.js +57 -0
  105. package/src/chat/stream-window.js +159 -0
  106. package/src/chat/vocabulary.js +19 -0
  107. package/src/controls/accordion.js +160 -0
  108. package/src/controls/avatar.js +80 -0
  109. package/src/controls/badge.js +48 -0
  110. package/src/controls/button-template.js +32 -0
  111. package/src/controls/button.js +97 -0
  112. package/src/controls/catalog.lino +84 -0
  113. package/src/controls/checkbox.js +112 -0
  114. package/src/controls/chip.js +140 -0
  115. package/src/controls/choices.js +45 -0
  116. package/src/controls/color-field.js +217 -0
  117. package/src/controls/color-popover.js +135 -0
  118. package/src/controls/color-rgb.js +80 -0
  119. package/src/controls/color.js +67 -0
  120. package/src/controls/combobox.js +192 -0
  121. package/src/controls/dom.js +261 -0
  122. package/src/controls/icon-button.js +33 -0
  123. package/src/controls/index.d.ts +163 -0
  124. package/src/controls/index.js +182 -0
  125. package/src/controls/kinds-text.js +358 -0
  126. package/src/controls/kinds.lino +350 -0
  127. package/src/controls/label.js +52 -0
  128. package/src/controls/link.js +101 -0
  129. package/src/controls/listbox.js +144 -0
  130. package/src/controls/machines/button.lino +20 -0
  131. package/src/controls/machines/checkbox.lino +17 -0
  132. package/src/controls/machines/chip.lino +20 -0
  133. package/src/controls/machines/color-field.lino +23 -0
  134. package/src/controls/machines/combobox.lino +82 -0
  135. package/src/controls/machines/icon-button.lino +20 -0
  136. package/src/controls/machines/index.js +586 -0
  137. package/src/controls/machines/number-field.lino +71 -0
  138. package/src/controls/machines/radio-group.lino +17 -0
  139. package/src/controls/machines/select.lino +122 -0
  140. package/src/controls/machines/slider.lino +99 -0
  141. package/src/controls/machines/switch.lino +19 -0
  142. package/src/controls/machines/text-area.lino +26 -0
  143. package/src/controls/machines/text-field.lino +26 -0
  144. package/src/controls/number-field.js +239 -0
  145. package/src/controls/numeric-keys.js +125 -0
  146. package/src/controls/option.js +54 -0
  147. package/src/controls/progress.js +76 -0
  148. package/src/controls/radio-group.js +234 -0
  149. package/src/controls/select.js +229 -0
  150. package/src/controls/slider.js +234 -0
  151. package/src/controls/stories.js +172 -0
  152. package/src/controls/styles.css +1060 -0
  153. package/src/controls/switch.js +95 -0
  154. package/src/controls/text-area.js +39 -0
  155. package/src/controls/text-field.js +131 -0
  156. package/src/controls/vocabulary.js +164 -0
  157. package/src/data/data.css +95 -0
  158. package/src/data/index.d.ts +83 -0
  159. package/src/data/index.js +10 -0
  160. package/src/data/keyboard.js +189 -0
  161. package/src/data/list.js +215 -0
  162. package/src/data/render-data.js +116 -0
  163. package/src/data/selection-dom.js +39 -0
  164. package/src/data/selection-model.js +43 -0
  165. package/src/data/sort-model.js +42 -0
  166. package/src/data/source.js +45 -0
  167. package/src/data/table.js +160 -0
  168. package/src/data/tree-model.js +41 -0
  169. package/src/data/tree.js +55 -0
  170. package/src/data/viewport.js +216 -0
  171. package/src/data/virtual-range.js +92 -0
  172. package/src/data/vocabulary.js +67 -0
  173. package/src/diagrams/diagram-model.js +511 -0
  174. package/src/diagrams/diagram.js +204 -0
  175. package/src/diagrams/index.d.ts +225 -0
  176. package/src/diagrams/index.js +48 -0
  177. package/src/diagrams/layout-dagre.js +164 -0
  178. package/src/diagrams/layout-plugins.js +131 -0
  179. package/src/diagrams/mermaid-export.js +232 -0
  180. package/src/diagrams/mermaid-view.js +229 -0
  181. package/src/diagrams/svg-diagram.js +215 -0
  182. package/src/editor/code-editor.js +206 -0
  183. package/src/editor/documents-model.js +170 -0
  184. package/src/editor/documents-persistence.js +85 -0
  185. package/src/editor/editor-engine.js +22 -0
  186. package/src/editor/editor-ui.js +203 -0
  187. package/src/editor/editor.css +106 -0
  188. package/src/editor/engines/codemirror.js +227 -0
  189. package/src/editor/engines/monaco.js +219 -0
  190. package/src/editor/index.d.ts +111 -0
  191. package/src/editor/index.js +14 -0
  192. package/src/editor/lino-highlight.js +106 -0
  193. package/src/editor/lino-structure.js +85 -0
  194. package/src/editor/validate-lino.js +43 -0
  195. package/src/embed/README.md +161 -0
  196. package/src/embed/controller.js +223 -0
  197. package/src/embed/element.js +141 -0
  198. package/src/embed/index.d.ts +75 -0
  199. package/src/embed/index.js +9 -0
  200. package/src/embed/providers/telegram.d.ts +3 -0
  201. package/src/embed/providers/telegram.js +38 -0
  202. package/src/embed/providers/vk.d.ts +3 -0
  203. package/src/embed/providers/vk.js +42 -0
  204. package/src/embed/providers/x.d.ts +3 -0
  205. package/src/embed/providers/x.js +31 -0
  206. package/src/embed/registry.js +35 -0
  207. package/src/embed/script.js +73 -0
  208. package/src/embed/view.js +122 -0
  209. package/src/icons/adapters/lucide.d.ts +15 -0
  210. package/src/icons/adapters/lucide.js +142 -0
  211. package/src/icons/adapters/material-symbols.d.ts +13 -0
  212. package/src/icons/adapters/material-symbols.js +113 -0
  213. package/src/icons/adapters/shared.d.ts +38 -0
  214. package/src/icons/adapters/shared.js +157 -0
  215. package/src/icons/adapters/simple-icons.d.ts +9 -0
  216. package/src/icons/adapters/simple-icons.js +38 -0
  217. package/src/icons/adapters/tabler.d.ts +9 -0
  218. package/src/icons/adapters/tabler.js +86 -0
  219. package/src/icons/icon-registry.js +215 -0
  220. package/src/icons/icon.js +356 -0
  221. package/src/icons/index.d.ts +123 -0
  222. package/src/icons/index.js +30 -0
  223. package/src/icons/names.js +51 -0
  224. package/src/icons/own-icons.js +521 -0
  225. package/src/icons/presentation.js +55 -0
  226. package/src/icons/svg.js +136 -0
  227. package/src/index.d.ts +14 -0
  228. package/src/index.js +40 -0
  229. package/src/layout/README.md +102 -0
  230. package/src/layout/app-shell.js +150 -0
  231. package/src/layout/catalog.lino +27 -0
  232. package/src/layout/dock-model.js +576 -0
  233. package/src/layout/dock-view.js +312 -0
  234. package/src/layout/dock.js +352 -0
  235. package/src/layout/dom.js +312 -0
  236. package/src/layout/grid.js +192 -0
  237. package/src/layout/index.d.ts +267 -0
  238. package/src/layout/index.js +60 -0
  239. package/src/layout/layer-manager.js +120 -0
  240. package/src/layout/layout.css +760 -0
  241. package/src/layout/menu.js +141 -0
  242. package/src/layout/nav-strip.js +174 -0
  243. package/src/layout/page-links.js +166 -0
  244. package/src/layout/panel.js +26 -0
  245. package/src/layout/pref-switches.js +209 -0
  246. package/src/layout/split-model.js +270 -0
  247. package/src/layout/split.js +430 -0
  248. package/src/layout/stack.js +86 -0
  249. package/src/layout/surfaces.js +119 -0
  250. package/src/layout/tab-group.js +151 -0
  251. package/src/layout/tab-strip.js +277 -0
  252. package/src/layout/vocabulary.js +229 -0
  253. package/src/layout/window-frame.js +222 -0
  254. package/src/layout/window.js +146 -0
  255. package/src/links-view/animator.js +144 -0
  256. package/src/links-view/configuration-classes.js +150 -0
  257. package/src/links-view/configuration-model.js +191 -0
  258. package/src/links-view/configuration-notations.js +230 -0
  259. package/src/links-view/configurations.d.ts +73 -0
  260. package/src/links-view/configurations.js +33 -0
  261. package/src/links-view/create-layout-runner.js +79 -0
  262. package/src/links-view/doublet-curves.js +239 -0
  263. package/src/links-view/doublet-layout.js +148 -0
  264. package/src/links-view/doublet-markers.js +109 -0
  265. package/src/links-view/doublet-options.js +369 -0
  266. package/src/links-view/doublet-svg.js +156 -0
  267. package/src/links-view/doublet.js +230 -0
  268. package/src/links-view/export.js +146 -0
  269. package/src/links-view/geometry.js +409 -0
  270. package/src/links-view/index.d.ts +1029 -0
  271. package/src/links-view/index.js +140 -0
  272. package/src/links-view/labels.js +28 -0
  273. package/src/links-view/layout-worker-entry.mjs +2 -0
  274. package/src/links-view/layout-worker.js +28 -0
  275. package/src/links-view/layouts/circle.js +7 -0
  276. package/src/links-view/layouts/force.js +76 -0
  277. package/src/links-view/layouts/grid.js +7 -0
  278. package/src/links-view/layouts/hex.js +8 -0
  279. package/src/links-view/layouts/index.js +15 -0
  280. package/src/links-view/layouts/layered.js +29 -0
  281. package/src/links-view/layouts/regular.js +27 -0
  282. package/src/links-view/layouts/spiral.js +10 -0
  283. package/src/links-view/link-view.js +494 -0
  284. package/src/links-view/links-gallery.js +306 -0
  285. package/src/links-view/links-network.js +496 -0
  286. package/src/links-view/lino-network-source.js +122 -0
  287. package/src/links-view/lino-network.js +233 -0
  288. package/src/links-view/lino-to-network.js +252 -0
  289. package/src/links-view/markers.js +192 -0
  290. package/src/links-view/model.js +233 -0
  291. package/src/links-view/network-editor/dom.js +36 -0
  292. package/src/links-view/network-editor/editor.js +202 -0
  293. package/src/links-view/network-editor/model.js +163 -0
  294. package/src/links-view/network-editor/options.js +265 -0
  295. package/src/links-view/network-editor/panels.js +423 -0
  296. package/src/links-view/network-editor/presets.js +76 -0
  297. package/src/links-view/network-editor/provider.js +93 -0
  298. package/src/links-view/network-editor/remap.js +45 -0
  299. package/src/links-view/network-editor/schema.js +224 -0
  300. package/src/links-view/network-editor/share.js +232 -0
  301. package/src/links-view/network-editor/styles.js +19 -0
  302. package/src/links-view/network-editor/url-sync.js +131 -0
  303. package/src/links-view/network-interaction.js +228 -0
  304. package/src/links-view/network-model.js +85 -0
  305. package/src/links-view/network-renderer.js +259 -0
  306. package/src/links-view/network-scene.js +245 -0
  307. package/src/links-view/network-source.js +82 -0
  308. package/src/links-view/network-vocabulary.js +18 -0
  309. package/src/links-view/presentation.js +199 -0
  310. package/src/links-view/render-canvas.js +102 -0
  311. package/src/links-view/render-svg.js +118 -0
  312. package/src/links-view/scene.js +233 -0
  313. package/src/links-view/solver-job.js +106 -0
  314. package/src/links-view/tokens.js +114 -0
  315. package/src/links-view/zoom-pan.js +203 -0
  316. package/src/overlays/catalog.lino +89 -0
  317. package/src/overlays/context-menu.js +110 -0
  318. package/src/overlays/dialog.js +117 -0
  319. package/src/overlays/dom.js +168 -0
  320. package/src/overlays/drawer.js +8 -0
  321. package/src/overlays/index.d.ts +80 -0
  322. package/src/overlays/index.js +25 -0
  323. package/src/overlays/kinds.lino +137 -0
  324. package/src/overlays/list-popover.js +129 -0
  325. package/src/overlays/machines/index.js +71 -0
  326. package/src/overlays/machines/surface.lino +11 -0
  327. package/src/overlays/machines/tabs.lino +7 -0
  328. package/src/overlays/machines/toast.lino +16 -0
  329. package/src/overlays/machines/tooltip.lino +29 -0
  330. package/src/overlays/menu.js +240 -0
  331. package/src/overlays/popover.js +194 -0
  332. package/src/overlays/position.js +84 -0
  333. package/src/overlays/radial-geometry.js +38 -0
  334. package/src/overlays/radial-menu.js +50 -0
  335. package/src/overlays/styles.css +155 -0
  336. package/src/overlays/tabs.js +125 -0
  337. package/src/overlays/toast-queue.js +105 -0
  338. package/src/overlays/toast.js +163 -0
  339. package/src/overlays/tooltip.js +110 -0
  340. package/src/overlays/vocabulary.js +3 -0
  341. package/src/settings/conditions.js +44 -0
  342. package/src/settings/control-for.js +62 -0
  343. package/src/settings/field-control.js +201 -0
  344. package/src/settings/index.d.ts +201 -0
  345. package/src/settings/index.js +3 -0
  346. package/src/settings/messages.js +112 -0
  347. package/src/settings/miniature.js +26 -0
  348. package/src/settings/panel-actions.js +234 -0
  349. package/src/settings/panel-model.js +49 -0
  350. package/src/settings/panel-refresh.js +56 -0
  351. package/src/settings/panel-rows.js +200 -0
  352. package/src/settings/preset-cards.js +43 -0
  353. package/src/settings/saved-looks.js +227 -0
  354. package/src/settings/section-layout.js +95 -0
  355. package/src/settings/section-tabs.js +175 -0
  356. package/src/settings/settings-panel.js +192 -0
  357. package/src/settings/settings.css +178 -0
  358. package/stories/accordion.lino +14 -0
  359. package/stories/alert-dialog.lino +4 -0
  360. package/stories/app-bar.lino +10 -0
  361. package/stories/avatar.lino +7 -0
  362. package/stories/badge.lino +12 -0
  363. package/stories/button.lino +17 -0
  364. package/stories/card.lino +10 -0
  365. package/stories/checkbox.lino +14 -0
  366. package/stories/chip.lino +19 -0
  367. package/stories/color-field.lino +9 -0
  368. package/stories/combobox.lino +10 -0
  369. package/stories/container.lino +11 -0
  370. package/stories/context-menu.lino +15 -0
  371. package/stories/dialog.lino +16 -0
  372. package/stories/drawer.lino +12 -0
  373. package/stories/icon-button.lino +13 -0
  374. package/stories/label.lino +7 -0
  375. package/stories/link-cards.lino +9 -0
  376. package/stories/link.lino +9 -0
  377. package/stories/menu-item.lino +6 -0
  378. package/stories/menu-separator.lino +7 -0
  379. package/stories/menu.lino +30 -0
  380. package/stories/nav-strip.lino +11 -0
  381. package/stories/number-field.lino +16 -0
  382. package/stories/option.lino +10 -0
  383. package/stories/paper.lino +11 -0
  384. package/stories/popover.lino +4 -0
  385. package/stories/pref-switches.lino +4 -0
  386. package/stories/progress.lino +14 -0
  387. package/stories/radial-menu.lino +19 -0
  388. package/stories/radio-group.lino +22 -0
  389. package/stories/radio.lino +10 -0
  390. package/stories/section-nav.lino +9 -0
  391. package/stories/select.lino +16 -0
  392. package/stories/slider.lino +14 -0
  393. package/stories/switch.lino +10 -0
  394. package/stories/tab-panel.lino +7 -0
  395. package/stories/tab.lino +7 -0
  396. package/stories/tabs.lino +25 -0
  397. package/stories/text-area.lino +12 -0
  398. package/stories/text-field.lino +23 -0
  399. package/stories/titled-section.lino +7 -0
  400. package/stories/toast.lino +3 -0
  401. package/stories/toaster.lino +2 -0
  402. package/stories/tooltip.lino +3 -0
@@ -0,0 +1,350 @@
1
+ /** Deterministic activity geometry. Dates use UTC and ongoing ends are explicit. */
2
+ import { emphasized } from './mark-options.js';
3
+ import { colorScale } from './scales.js';
4
+ import { tokenColor } from './tokens.js';
5
+
6
+ const DAY = 86400000;
7
+ const box = (width, height) => ({
8
+ x: 48,
9
+ y: 48,
10
+ width: Math.max(40, width - 72),
11
+ height: Math.max(40, height - 100),
12
+ });
13
+ const labelShape = (x, y, content) => ({
14
+ tag: 'text',
15
+ attrs: { x, y, fill: 'var(--color-chart-text, #1c1b1f)', 'font-size': 11 },
16
+ content,
17
+ });
18
+ const year = (time) => new Date(time).getUTCFullYear();
19
+ const PATTERNS = ['solid', 'hatched', 'dotted'];
20
+
21
+ /** Overlay paths distinguish categories even with all colour removed. */
22
+ export function patternShapes(rect, pattern) {
23
+ const { x, y, width, height } = rect;
24
+ if (!pattern || pattern === 'solid') {
25
+ return [];
26
+ }
27
+ const shapes = [];
28
+ for (let dx = 3; dx < width; dx += 8) {
29
+ if (pattern === 'dotted') {
30
+ shapes.push({
31
+ tag: 'circle',
32
+ attrs: {
33
+ cx: x + dx,
34
+ cy: y + height / 2,
35
+ r: 1.5,
36
+ fill: 'var(--color-chart-background, #fff)',
37
+ },
38
+ });
39
+ } else {
40
+ shapes.push({
41
+ tag: 'path',
42
+ attrs: {
43
+ d: `M${x + dx},${y + height}l${Math.min(height, width - dx)},-${Math.min(height, width - dx)}`,
44
+ stroke: 'var(--color-chart-background, #fff)',
45
+ 'stroke-width': 1.5,
46
+ fill: 'none',
47
+ },
48
+ });
49
+ }
50
+ }
51
+ return shapes;
52
+ }
53
+
54
+ export function compositionLayout(spec, width, height, tokens) {
55
+ const plot = box(width, height);
56
+ plot.height = 28;
57
+ const { theta, color } = spec.encoding;
58
+ const totals = new Map();
59
+ for (const row of spec.data.values) {
60
+ const key = String(row[color.field]);
61
+ totals.set(
62
+ key,
63
+ (totals.get(key) ?? 0) + Math.max(0, Number(row[theta.field]))
64
+ );
65
+ }
66
+ let items = [...totals].map(([name, value]) => ({
67
+ name,
68
+ value,
69
+ emphasis:
70
+ spec.emphasis &&
71
+ spec.data.values.some(
72
+ (row) =>
73
+ String(row[color.field]) === name && emphasized(row[spec.emphasis])
74
+ ),
75
+ }));
76
+ if (spec.topN) {
77
+ items.sort((a, b) => b.value - a.value);
78
+ const tail = items.slice(spec.topN);
79
+ items = items.slice(0, spec.topN);
80
+ if (tail.length) {
81
+ items.push({
82
+ name: 'Other',
83
+ value: tail.reduce((sum, item) => sum + item.value, 0),
84
+ other: true,
85
+ emphasis: tail.some((item) => item.emphasis),
86
+ });
87
+ }
88
+ }
89
+ const total = items.reduce((sum, item) => sum + item.value, 0);
90
+ const colors = colorScale(color, spec.data.values, tokens);
91
+ const shapes = [],
92
+ points = [],
93
+ legend = [];
94
+ let cursor = 0;
95
+ items.forEach((item, i) => {
96
+ const share = total ? item.value / total : 0;
97
+ const fill = item.other
98
+ ? tokenColor('color.chart.muted', tokens)
99
+ : colors.color(item.name);
100
+ const segment = {
101
+ x: cursor,
102
+ y: 0,
103
+ width: share * plot.width,
104
+ height: 28,
105
+ fill,
106
+ };
107
+ shapes.push({ tag: 'rect', attrs: segment, row: i });
108
+ if (item.emphasis) {
109
+ shapes.push(labelShape(cursor + segment.width / 2, -6, '★'));
110
+ }
111
+ const text = `${item.name}: ${(share * 100).toFixed(1)}%${item.emphasis ? ' ★ emphasized' : ''}`;
112
+ points.push({
113
+ row: i,
114
+ x: cursor + segment.width / 2,
115
+ y: 0,
116
+ text,
117
+ datum: {
118
+ [color.field]: item.name,
119
+ [theta.field]: item.value,
120
+ percentage: share * 100,
121
+ },
122
+ });
123
+ legend.push({
124
+ label: `${item.name} ${(share * 100).toFixed(1)}%${item.emphasis ? ' ★' : ''}`,
125
+ color: fill,
126
+ x: plot.x,
127
+ y: 100 + i * 24,
128
+ });
129
+ cursor += segment.width;
130
+ });
131
+ return {
132
+ plot,
133
+ axes: [],
134
+ legend,
135
+ series: [{ key: null, color: colors.colorAt(0), shapes, points }],
136
+ };
137
+ }
138
+
139
+ export function calendarLayout(spec, width, height, tokens) {
140
+ const { x, y } = spec.encoding;
141
+ const entries = spec.data.values
142
+ .map((row, i) => ({
143
+ row: i,
144
+ time: Date.parse(row[x.field]),
145
+ value: Number(row[y.field]),
146
+ datum: row,
147
+ }))
148
+ .sort((a, b) => a.time - b.time);
149
+ const startDay = spec.weekStart ?? 0;
150
+ const first = entries[0].time;
151
+ const start =
152
+ first - ((new Date(first).getUTCDay() - startDay + 7) % 7) * DAY;
153
+ const weeks = Math.floor((entries.at(-1).time - start) / (7 * DAY)) + 1;
154
+ const cell = 14;
155
+ const plot = { x: 48, y: 48, width: weeks * cell, height: 7 * cell };
156
+ const values = entries.map((e) => e.value).sort((a, b) => a - b);
157
+ const thresholds =
158
+ spec.thresholds ??
159
+ [0.2, 0.4, 0.6, 0.8].map(
160
+ (q) => values[Math.floor((values.length - 1) * q)]
161
+ );
162
+ const colors = [
163
+ tokenColor('color.chart.grid', tokens),
164
+ '#9cc5e5',
165
+ '#5797cc',
166
+ '#1f6fb2',
167
+ '#164b78',
168
+ ];
169
+ const shapes = [],
170
+ points = [];
171
+ const months = new Set();
172
+ for (const entry of entries) {
173
+ const offset = Math.round((entry.time - start) / DAY);
174
+ const column = Math.floor(offset / 7),
175
+ day = offset % 7;
176
+ const level = thresholds.filter((t) => entry.value > t).length;
177
+ const date = new Date(entry.time).toISOString().slice(0, 10);
178
+ const star =
179
+ spec.emphasis && emphasized(entry.datum[spec.emphasis]) ? ' ★' : '';
180
+ const text = `${date}: ${entry.value}${star}`;
181
+ shapes.push({
182
+ tag: 'rect',
183
+ attrs: {
184
+ x: column * cell,
185
+ y: day * cell,
186
+ width: 11,
187
+ height: 11,
188
+ rx: 2,
189
+ fill: colors[level],
190
+ role: 'img',
191
+ 'aria-label': text,
192
+ },
193
+ row: entry.row,
194
+ title: text,
195
+ });
196
+ if (star) {
197
+ shapes.push(labelShape(column * cell, day * cell + 10, '★'));
198
+ }
199
+ points.push({
200
+ row: entry.row,
201
+ x: column * cell + 5.5,
202
+ y: day * cell,
203
+ text,
204
+ day: offset,
205
+ datum: entry.datum,
206
+ });
207
+ const month = date.slice(0, 7);
208
+ if (!months.has(month)) {
209
+ months.add(month);
210
+ shapes.push(
211
+ labelShape(
212
+ column * cell,
213
+ -12,
214
+ new Date(entry.time).toLocaleString('en-US', {
215
+ month: 'short',
216
+ timeZone: 'UTC',
217
+ })
218
+ )
219
+ );
220
+ }
221
+ }
222
+ for (const [weekday, name] of [
223
+ [1, 'Mon'],
224
+ [3, 'Wed'],
225
+ [5, 'Fri'],
226
+ ]) {
227
+ shapes.push(
228
+ labelShape(-32, ((weekday - startDay + 7) % 7) * cell + 9, name)
229
+ );
230
+ }
231
+ const legend = colors.map((color, i) => ({
232
+ label: i === 0 ? 'Less' : i === 4 ? 'More' : String(i + 1),
233
+ color,
234
+ x: 48 + i * 65,
235
+ y: plot.y + plot.height + 28,
236
+ }));
237
+ return {
238
+ width: Math.max(width, plot.width + 72),
239
+ height: Math.max(210, height),
240
+ weeks,
241
+ plot,
242
+ axes: [],
243
+ legend,
244
+ series: [{ key: null, color: colors[3], shapes, points }],
245
+ };
246
+ }
247
+
248
+ export function rangeLayout(spec, width, height, tokens) {
249
+ const { x, x2, y, color } = spec.encoding;
250
+ const rows = spec.data.values;
251
+ const starts = rows.map((row) => Date.parse(row[x.field]));
252
+ // No ambient clock: omitted ongoingEnd extends to the next year after the
253
+ // latest supplied start or closed end. Consumers can inject their snapshot date.
254
+ const latest = Math.max(
255
+ ...starts,
256
+ ...rows.flatMap((row) =>
257
+ row[x2.field] && row[x2.field] !== 'ongoing'
258
+ ? [Date.parse(row[x2.field])]
259
+ : []
260
+ )
261
+ );
262
+ const ongoing = spec.ongoingEnd
263
+ ? Date.parse(spec.ongoingEnd)
264
+ : Date.UTC(year(latest) + 1, 0, 1);
265
+ const ends = rows.map((row) =>
266
+ row[x2.field] && row[x2.field] !== 'ongoing'
267
+ ? Date.parse(row[x2.field])
268
+ : ongoing
269
+ );
270
+ const low = Date.UTC(year(Math.min(...starts)), 0, 1),
271
+ high = Math.max(...ends, low + DAY);
272
+ const plot = box(width, Math.max(height, rows.length * 32 + 110));
273
+ plot.y = 60;
274
+ plot.height -= 12;
275
+ plot.x = Math.min(
276
+ width / 2,
277
+ Math.max(80, ...rows.map((row) => String(row[y.field]).length * 7 + 16))
278
+ );
279
+ plot.width = Math.max(40, width - plot.x - 24);
280
+ const position = (time) => ((time - low) / (high - low)) * plot.width;
281
+ const colors = colorScale(color, rows, tokens);
282
+ const shapes = [],
283
+ points = [];
284
+ rows.forEach((row, i) => {
285
+ const fill = color ? colors.color(row[color.field]) : colors.colorAt(0);
286
+ const pattern = PATTERNS[color ? colors.index(row[color.field]) % 3 : 0];
287
+ const rect = {
288
+ x: position(starts[i]),
289
+ y: i * 32,
290
+ width: Math.max(1, position(ends[i]) - position(starts[i])),
291
+ height: 20,
292
+ fill,
293
+ };
294
+ const end =
295
+ row[x2.field] && row[x2.field] !== 'ongoing' ? row[x2.field] : 'ongoing';
296
+ const star = spec.emphasis && emphasized(row[spec.emphasis]) ? ' ★' : '';
297
+ const text = `${row[y.field]}: ${row[x.field]} – ${end}${color ? `, ${row[color.field]}` : ''}${star}`;
298
+ shapes.push(
299
+ {
300
+ tag: 'rect',
301
+ attrs: { ...rect, tabindex: 0, role: 'img', 'aria-label': text },
302
+ row: i,
303
+ title: text,
304
+ pattern,
305
+ },
306
+ ...patternShapes(rect, pattern),
307
+ {
308
+ ...labelShape(-10, i * 32 + 14, `${row[y.field]}${star}`),
309
+ attrs: {
310
+ ...labelShape(-10, i * 32 + 14, '').attrs,
311
+ 'text-anchor': 'end',
312
+ },
313
+ }
314
+ );
315
+ points.push({
316
+ row: i,
317
+ x: rect.x + rect.width / 2,
318
+ y: rect.y,
319
+ text,
320
+ datum: row,
321
+ });
322
+ });
323
+ const ticks = [];
324
+ for (let value = year(low); value <= year(high); value++) {
325
+ ticks.push({
326
+ value: Date.UTC(value, 0, 1),
327
+ position: position(Date.UTC(value, 0, 1)),
328
+ label: String(value),
329
+ });
330
+ }
331
+ return {
332
+ height: Math.max(height, rows.length * 32 + 110),
333
+ plot,
334
+ axes: [{ orient: 'bottom', title: 'Year', ticks, grid: false }],
335
+ legend: colors.domain.map((label, i) => ({
336
+ label,
337
+ color: colors.colorAt(i),
338
+ pattern: PATTERNS[i % 3],
339
+ x: 48 + i * 140,
340
+ y: 38,
341
+ })),
342
+ series: [{ key: null, color: colors.colorAt(0), shapes, points }],
343
+ };
344
+ }
345
+
346
+ export const ACTIVITY_LAYOUTS = {
347
+ calendar: calendarLayout,
348
+ range: rangeLayout,
349
+ composition: compositionLayout,
350
+ };
@@ -0,0 +1,130 @@
1
+ /** Optional activity-chart vocabulary shared by the LiNo reader and writer. */
2
+ import { fail } from './errors.js';
3
+ import { prop } from './lino.js';
4
+ import {
5
+ numberList,
6
+ optionalNumber,
7
+ optionalText,
8
+ properties,
9
+ } from './read.js';
10
+
11
+ export const ACTIVITY_PROPERTIES = [
12
+ 'corner-radius',
13
+ 'labels',
14
+ 'emphasis',
15
+ 'top-n',
16
+ 'week-start',
17
+ 'thresholds',
18
+ 'ongoing-end',
19
+ 'tooltip',
20
+ ];
21
+ const NAMES = {
22
+ 'corner-radius': 'cornerRadius',
23
+ 'top-n': 'topN',
24
+ 'week-start': 'weekStart',
25
+ 'ongoing-end': 'ongoingEnd',
26
+ };
27
+
28
+ export function readActivity(props) {
29
+ const result = {};
30
+ for (const name of ACTIVITY_PROPERTIES) {
31
+ const entry = props.get(name)?.[0];
32
+ if (!entry) {
33
+ continue;
34
+ }
35
+ let value;
36
+ if (name === 'thresholds') {
37
+ value = numberList(entry, name);
38
+ if (
39
+ value.length !== 4 ||
40
+ value.some((v, i) => i > 0 && v <= value[i - 1])
41
+ ) {
42
+ fail(
43
+ 'invalid-value',
44
+ 'thresholds must be four increasing numbers',
45
+ entry.node,
46
+ entry.path
47
+ );
48
+ }
49
+ } else if (name === 'tooltip') {
50
+ const fields = properties(entry.node, entry.path, 1, ['layer']);
51
+ value = { layer: optionalText(fields, 'layer') ?? 'top' };
52
+ if (!['top', 'inline'].includes(value.layer)) {
53
+ fail(
54
+ 'invalid-value',
55
+ 'tooltip layer must be top or inline',
56
+ entry.node,
57
+ entry.path
58
+ );
59
+ }
60
+ } else {
61
+ value = scalarActivity(props, name, entry);
62
+ }
63
+ result[NAMES[name] ?? name] = value;
64
+ }
65
+ return result;
66
+ }
67
+
68
+ export function activityNodes(spec) {
69
+ return ACTIVITY_PROPERTIES.flatMap((name) => {
70
+ const value = spec[NAMES[name] ?? name];
71
+ if (value === undefined || value === null) {
72
+ return [];
73
+ }
74
+ if (name === 'tooltip') {
75
+ return [prop(name, prop('layer', value.layer ?? 'top'))];
76
+ }
77
+ return [
78
+ prop(name, ...(Array.isArray(value) ? value : [value]).map(String)),
79
+ ];
80
+ });
81
+ }
82
+
83
+ export function readScale(entry) {
84
+ const fields = properties(entry.node, entry.path, 1, ['type', 'base']);
85
+ const type = optionalText(fields, 'type');
86
+ const base = optionalNumber(fields, 'base', 10);
87
+ if (type !== 'log' || base <= 1) {
88
+ fail(
89
+ 'invalid-value',
90
+ 'scale requires type log and base > 1',
91
+ entry.node,
92
+ entry.path
93
+ );
94
+ }
95
+ return { type, base };
96
+ }
97
+
98
+ function scalarActivity(props, name, entry) {
99
+ let value;
100
+ if (['corner-radius', 'top-n', 'week-start'].includes(name)) {
101
+ value = optionalNumber(props, name);
102
+ if (
103
+ value < 0 ||
104
+ (name !== 'corner-radius' && !Number.isInteger(value)) ||
105
+ (name === 'top-n' && value < 1) ||
106
+ (name === 'week-start' && value > 6)
107
+ ) {
108
+ fail('invalid-value', `invalid ${name}`, entry.node, entry.path);
109
+ }
110
+ } else {
111
+ value = optionalText(props, name);
112
+ if (name === 'labels' && !['peaks', 'last'].includes(value)) {
113
+ fail(
114
+ 'invalid-value',
115
+ 'labels must be peaks or last',
116
+ entry.node,
117
+ entry.path
118
+ );
119
+ }
120
+ if (name === 'ongoing-end' && !Number.isFinite(Date.parse(value))) {
121
+ fail(
122
+ 'invalid-value',
123
+ 'ongoing-end must be a date',
124
+ entry.node,
125
+ entry.path
126
+ );
127
+ }
128
+ }
129
+ return value;
130
+ }
@@ -0,0 +1,31 @@
1
+ /** Validate the field roles needed by the activity layouts before drawing. */
2
+ import { fail } from './errors.js';
3
+
4
+ export function validateActivity(spec, node, path) {
5
+ const { mark, encoding, data } = spec;
6
+ const expected = {
7
+ calendar: { x: 'temporal', y: 'quantitative' },
8
+ range: { x: 'temporal', x2: 'temporal' },
9
+ composition: { theta: 'quantitative' },
10
+ }[mark.type];
11
+ for (const [channel, type] of Object.entries(expected ?? {})) {
12
+ if (encoding[channel].type !== type) {
13
+ fail(
14
+ 'invalid-value',
15
+ `${mark.type} requires ${type} ${channel}`,
16
+ node,
17
+ path
18
+ );
19
+ }
20
+ }
21
+ if (mark.type === 'range') {
22
+ for (const row of data.values) {
23
+ const end = row[encoding.x2.field];
24
+ const endTime = !end || end === 'ongoing' ? spec.ongoingEnd : end;
25
+ if (endTime && Date.parse(endTime) < Date.parse(row[encoding.x.field])) {
26
+ fail('invalid-value', 'range end must not precede start', node, path);
27
+ }
28
+ }
29
+ }
30
+ return spec;
31
+ }