fnloom 0.3.0 → 0.4.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 (587) hide show
  1. package/README.md +27 -20
  2. package/package.json +14 -11
  3. package/packages/build/package.json +2 -2
  4. package/packages/build/src/tests.ts +2 -2
  5. package/packages/cli/package.json +1 -1
  6. package/packages/cli/src/cli.ts +2 -2
  7. package/packages/cli/src/command.ts +2 -2
  8. package/packages/cli/src/commands/install.ts +1 -1
  9. package/packages/cli/src/commands/mcp.ts +6 -6
  10. package/packages/cli/src/commands/store.ts +3 -3
  11. package/packages/cli/src/hub.ts +25 -25
  12. package/packages/cli/src/index.ts +1 -1
  13. package/packages/cli/src/io.ts +2 -2
  14. package/packages/cli/src/local.ts +7 -7
  15. package/packages/cli/src/premade.ts +1 -1
  16. package/packages/core/package.json +4 -4
  17. package/packages/core/src/auto-pair.ts +1 -1
  18. package/packages/core/src/connections.ts +1 -14
  19. package/packages/core/src/context-graph.ts +1 -1
  20. package/packages/core/src/data.ts +1 -1
  21. package/packages/core/src/https.ts +2 -2
  22. package/packages/core/src/identity.ts +1 -1
  23. package/packages/core/src/image-embeddings.ts +1 -1
  24. package/packages/core/src/index.ts +5 -7
  25. package/packages/core/src/link.ts +1 -1
  26. package/packages/core/src/manifest.ts +2 -2
  27. package/packages/core/src/mention-search.ts +1 -1
  28. package/packages/core/src/model-calls.ts +1 -1
  29. package/packages/core/src/package.ts +1 -1
  30. package/packages/core/src/ports.ts +2 -2
  31. package/packages/core/src/query.ts +1 -1
  32. package/packages/core/src/records/chat.ts +1 -1
  33. package/packages/core/src/records/runs.ts +1 -1
  34. package/packages/core/src/records/spend.ts +4 -0
  35. package/packages/core/src/registries.ts +9 -3
  36. package/packages/core/src/sso.ts +2 -2
  37. package/packages/core/src/stores.ts +1 -1
  38. package/packages/core/src/suggestions.ts +2 -2
  39. package/packages/core/src/system-pages.ts +32 -6
  40. package/packages/core/src/tables.ts +233 -0
  41. package/packages/core/src/visuals.ts +47 -139
  42. package/packages/core/src/web.ts +2 -2
  43. package/packages/core/src/widgets-v1.ts +78 -1
  44. package/packages/hub/package.json +13 -11
  45. package/packages/hub/src/api/admin-ops.ts +5 -5
  46. package/packages/hub/src/api/auth.ts +2 -2
  47. package/packages/hub/src/api/https.ts +6 -6
  48. package/packages/hub/src/api/identities.ts +1 -1
  49. package/packages/hub/src/api/reads.ts +1 -1
  50. package/packages/hub/src/api/secrets.ts +1 -1
  51. package/packages/hub/src/api/serve.ts +2 -2
  52. package/packages/hub/src/api/sso-route.ts +2 -2
  53. package/packages/hub/src/api/sso.ts +6 -6
  54. package/packages/hub/src/api/testing/rig.ts +1 -1
  55. package/packages/hub/src/api/tls.ts +2 -2
  56. package/packages/hub/src/api/web/auth.ts +1 -1
  57. package/packages/hub/src/api/web/find.ts +1 -1
  58. package/packages/hub/src/api/web/pages.ts +4 -3
  59. package/packages/hub/src/api/web/pickers.ts +4 -4
  60. package/packages/hub/src/boot/env.ts +82 -78
  61. package/packages/hub/src/boot/hub-fns.ts +1 -1
  62. package/packages/hub/src/boot/identity.ts +2 -2
  63. package/packages/hub/src/boot/index.ts +1 -1
  64. package/packages/hub/src/boot/info.ts +1 -1
  65. package/packages/hub/src/boot/keys.ts +6 -6
  66. package/packages/hub/src/boot/log.ts +4 -4
  67. package/packages/hub/src/boot/modules.ts +4 -4
  68. package/packages/hub/src/boot/services.ts +9 -9
  69. package/packages/hub/src/boot/start.ts +23 -23
  70. package/packages/hub/src/chat/cache.ts +1 -1
  71. package/packages/hub/src/chat/chat.ts +1 -1
  72. package/packages/hub/src/chat/compare.ts +2 -2
  73. package/packages/hub/src/chat/deliveries.ts +1 -1
  74. package/packages/hub/src/chat/deps.ts +3 -3
  75. package/packages/hub/src/chat/enrich.ts +7 -7
  76. package/packages/hub/src/chat/env.ts +20 -20
  77. package/packages/hub/src/chat/mention-requests.ts +1 -1
  78. package/packages/hub/src/chat/mention-search.ts +1 -1
  79. package/packages/hub/src/chat/mentions.ts +3 -3
  80. package/packages/hub/src/chat/notifications.ts +2 -2
  81. package/packages/hub/src/chat/presence.ts +2 -2
  82. package/packages/hub/src/chat/sessions.ts +2 -2
  83. package/packages/hub/src/chat/suggestions.ts +8 -8
  84. package/packages/hub/src/chat/testing.ts +1 -1
  85. package/packages/hub/src/chat/turns.ts +6 -6
  86. package/packages/hub/src/chat/undo.ts +1 -1
  87. package/packages/hub/src/connections/create.ts +1 -1
  88. package/packages/hub/src/connections/env.ts +2 -2
  89. package/packages/hub/src/connections/service.ts +5 -9
  90. package/packages/hub/src/contextor/contextors.ts +9 -9
  91. package/packages/hub/src/contextor/crawl.ts +1 -1
  92. package/packages/hub/src/contextor/create.ts +5 -5
  93. package/packages/hub/src/contextor/dynamic.ts +5 -5
  94. package/packages/hub/src/contextor/env.ts +46 -46
  95. package/packages/hub/src/contextor/injected.ts +1 -1
  96. package/packages/hub/src/contextor/limits.ts +9 -9
  97. package/packages/hub/src/contextor/planner.ts +11 -11
  98. package/packages/hub/src/contextor/testing.ts +1 -1
  99. package/packages/hub/src/data/env.ts +3 -3
  100. package/packages/hub/src/data/service.ts +5 -5
  101. package/packages/hub/src/execution/agent.ts +8 -8
  102. package/packages/hub/src/execution/ai.ts +7 -7
  103. package/packages/hub/src/execution/create.ts +11 -6
  104. package/packages/hub/src/execution/env.ts +16 -16
  105. package/packages/hub/src/execution/executors.ts +2 -2
  106. package/packages/hub/src/execution/gateway.ts +1 -1
  107. package/packages/hub/src/execution/index.ts +1 -1
  108. package/packages/hub/src/execution/ledger.ts +2 -2
  109. package/packages/hub/src/execution/limits.ts +2 -2
  110. package/packages/hub/src/execution/models.ts +2 -2
  111. package/packages/hub/src/execution/ports.ts +1 -1
  112. package/packages/hub/src/execution/providers.ts +55 -11
  113. package/packages/hub/src/execution/queues.ts +6 -6
  114. package/packages/hub/src/execution/runs.ts +10 -10
  115. package/packages/hub/src/execution/stream-guard.ts +2 -2
  116. package/packages/hub/src/execution/testing.ts +5 -5
  117. package/packages/hub/src/execution/wire.ts +3 -3
  118. package/packages/hub/src/fns/auto.ts +2 -2
  119. package/packages/hub/src/fns/client-logs.ts +2 -2
  120. package/packages/hub/src/fns/create.ts +2 -2
  121. package/packages/hub/src/fns/decided.ts +2 -2
  122. package/packages/hub/src/fns/env.ts +14 -14
  123. package/packages/hub/src/fns/examples.ts +3 -3
  124. package/packages/hub/src/fns/facts.ts +5 -5
  125. package/packages/hub/src/fns/search.ts +5 -5
  126. package/packages/hub/src/graph/graph.ts +1 -1
  127. package/packages/hub/src/index/context-sections.ts +1 -1
  128. package/packages/hub/src/index/embedders.ts +3 -3
  129. package/packages/hub/src/index/env.ts +12 -12
  130. package/packages/hub/src/index/index.ts +1 -1
  131. package/packages/hub/src/index/indexer.ts +4 -4
  132. package/packages/hub/src/index/search.ts +1 -1
  133. package/packages/hub/src/index/testing.ts +2 -2
  134. package/packages/hub/src/link/build.ts +32 -32
  135. package/packages/hub/src/link/env.ts +14 -14
  136. package/packages/hub/src/link/grants.ts +10 -10
  137. package/packages/hub/src/link/lifecycle.ts +4 -4
  138. package/packages/hub/src/link/migrate-api.ts +55 -15
  139. package/packages/hub/src/link/pairing.ts +1 -1
  140. package/packages/hub/src/link/process.ts +1 -1
  141. package/packages/hub/src/link/rig.ts +12 -12
  142. package/packages/hub/src/link/supervisor.ts +1 -1
  143. package/packages/hub/src/mcp/calls.ts +6 -6
  144. package/packages/hub/src/mcp/create.ts +5 -5
  145. package/packages/hub/src/mcp/env.ts +6 -6
  146. package/packages/hub/src/mcp/fns.ts +2 -2
  147. package/packages/hub/src/mcp/index.ts +2 -2
  148. package/packages/hub/src/mcp/sources.ts +3 -3
  149. package/packages/hub/src/mcp/tokens.ts +1 -1
  150. package/packages/hub/src/models/create.ts +1 -1
  151. package/packages/hub/src/models/decide.ts +2 -2
  152. package/packages/hub/src/models/index.ts +1 -1
  153. package/packages/hub/src/models/roles.ts +12 -12
  154. package/packages/hub/src/query/env.ts +5 -5
  155. package/packages/hub/src/query/sources.ts +3 -3
  156. package/packages/hub/src/questions/plans.ts +1 -1
  157. package/packages/hub/src/questions/worker.ts +2 -2
  158. package/packages/hub/src/resources/context.ts +3 -3
  159. package/packages/hub/src/resources/converters.ts +2 -2
  160. package/packages/hub/src/resources/create.ts +6 -6
  161. package/packages/hub/src/resources/env.ts +15 -15
  162. package/packages/hub/src/resources/fetch.ts +5 -5
  163. package/packages/hub/src/resources/forms.ts +5 -5
  164. package/packages/hub/src/resources/index.ts +1 -1
  165. package/packages/hub/src/resources/library.ts +2 -2
  166. package/packages/hub/src/resources/raw.ts +1 -1
  167. package/packages/hub/src/resources/reader.ts +2 -2
  168. package/packages/hub/src/resources/sqlite-files.ts +1 -1
  169. package/packages/hub/src/resources/storage.ts +5 -5
  170. package/packages/hub/src/resources/testing.ts +6 -6
  171. package/packages/hub/src/store/env.ts +4 -4
  172. package/packages/hub/src/store/hybrid.ts +4 -4
  173. package/packages/hub/src/store/sqlite.ts +3 -3
  174. package/packages/hub/src/stores/drivers.ts +2 -2
  175. package/packages/hub/src/stores/host.ts +3 -3
  176. package/packages/hub/src/stores/moves.ts +2 -2
  177. package/packages/hub/src/stores/service.ts +2 -2
  178. package/packages/hub/src/tables/env.ts +3 -3
  179. package/packages/hub/src/tables/index.ts +5 -5
  180. package/packages/hub/src/tables/service.ts +7 -7
  181. package/packages/sdk/AUTHORING.md +1206 -881
  182. package/packages/sdk/package.json +11 -8
  183. package/packages/sdk/src/agent.ts +1 -1
  184. package/packages/sdk/src/app-parts.ts +95 -0
  185. package/packages/sdk/src/authored.ts +26 -0
  186. package/packages/sdk/src/authoring.ts +13 -30
  187. package/packages/sdk/src/client-runtime.ts +24 -1
  188. package/packages/sdk/src/client-ui/AddServiceDialog.vue +43 -0
  189. package/packages/sdk/src/client-ui/InstanceNameField.vue +29 -0
  190. package/packages/sdk/src/client-ui/PairRowsEditor.vue +74 -0
  191. package/packages/sdk/src/client-ui/RemoteAuthFields.vue +95 -0
  192. package/packages/sdk/src/client-ui/ServiceRows.vue +57 -0
  193. package/packages/sdk/src/client-ui/draft.ts +10 -0
  194. package/packages/sdk/src/client-ui/host.ts +37 -0
  195. package/packages/sdk/src/client-ui/index.ts +19 -0
  196. package/packages/sdk/src/client-ui/loaded.ts +69 -0
  197. package/packages/sdk/src/client-ui/problems.ts +98 -0
  198. package/packages/sdk/src/client-ui/remote-config.ts +199 -0
  199. package/packages/sdk/src/client-ui/service-rows.ts +25 -0
  200. package/packages/sdk/src/client-ui/state.ts +14 -0
  201. package/packages/sdk/src/client-ui/testing.ts +147 -0
  202. package/packages/sdk/src/client-ui/vue-shim.d.ts +13 -0
  203. package/packages/sdk/src/client.ts +82 -11
  204. package/packages/sdk/src/hub.ts +4 -4
  205. package/packages/sdk/src/index.ts +13 -9
  206. package/packages/sdk/src/page-parts.ts +4 -0
  207. package/packages/sdk/src/program/env.ts +7 -7
  208. package/packages/sdk/src/program/runtime.ts +5 -5
  209. package/packages/sdk/src/program/tools.ts +3 -3
  210. package/packages/sdk/src/remote-auth.ts +128 -7
  211. package/packages/sdk/src/server/context-files.ts +1 -1
  212. package/packages/sdk/src/server/env.ts +36 -36
  213. package/packages/sdk/src/server/fake-hub-widgets.ts +7 -6
  214. package/packages/sdk/src/server/host.ts +28 -28
  215. package/packages/sdk/src/server/index.ts +2 -2
  216. package/packages/sdk/src/server/live.ts +4 -4
  217. package/packages/sdk/src/server/llm-wire.ts +4 -4
  218. package/packages/sdk/src/server/pairing.ts +1 -1
  219. package/packages/sdk/src/server/results.ts +4 -4
  220. package/packages/sdk/src/server/socket-guard.ts +1 -1
  221. package/packages/sdk/src/server/start-gate.ts +2 -2
  222. package/packages/sdk/src/server/store/engines.ts +2 -2
  223. package/packages/sdk/src/server/store/keeper.ts +2 -2
  224. package/packages/sdk/src/server/supervise.ts +4 -4
  225. package/packages/sdk/src/testing/env.ts +6 -6
  226. package/packages/sdk/src/testing/hub.ts +3 -1
  227. package/packages/sdk/src/testing/models.ts +3 -3
  228. package/packages/sdk/src/testing/openrouter.ts +3 -2
  229. package/packages/sdk/src/testing/preview.ts +7 -7
  230. package/packages/sdk/src/widgets.ts +21 -136
  231. package/packages/sdk/tsconfig.json +2 -2
  232. package/packages/web/dist/assets/{ActorSettingsView-v2k7v454.js → ActorSettingsView-CDszUbHz.js} +2 -2
  233. package/packages/web/dist/assets/AdminLayout-CFIz4GsQ.js +2 -0
  234. package/packages/web/dist/assets/{AdminLayout-1hbRPV3d.css → AdminLayout-ggcdQGlQ.css} +1 -1
  235. package/packages/web/dist/assets/{AppPage-CFmKZS8G.js → AppPage-BvoVTk6h.js} +2 -2
  236. package/packages/web/dist/assets/{AutoPairPicker-C61gihmh.js → AutoPairPicker-CLjD-muP.js} +2 -2
  237. package/packages/web/dist/assets/{BrowserFrame-Sq9EmQRT.js → BrowserFrame-BcN-A76X.js} +2 -2
  238. package/packages/web/dist/assets/ChatPage-DhTpAyM2.js +4 -0
  239. package/packages/web/dist/assets/{ChatPage-CbsRmktV.css → ChatPage-DjPv238m.css} +1 -1
  240. package/packages/web/dist/assets/{CodeViewer-tUNXZB77.js → CodeViewer-K9jrTmFO.js} +2 -2
  241. package/packages/web/dist/assets/ConfigWithCustom-BvrvSVIp.js +3 -0
  242. package/packages/web/dist/assets/{ConfirmDialog-Dd3E4sJt.js → ConfirmDialog-BDvLleYf.js} +2 -2
  243. package/packages/web/dist/assets/{ConnectPage-CX9acyQH.js → ConnectPage-Dg6IPNNh.js} +2 -2
  244. package/packages/web/dist/assets/ContextItemPage-qisBQetR.js +2 -0
  245. package/packages/web/dist/assets/ContextPage-DXa6Yqk-.js +3 -0
  246. package/packages/web/dist/assets/{ContextRow-DrtPumZ5.js → ContextRow-DDYnYRaL.js} +2 -2
  247. package/packages/web/dist/assets/{DataPage-DDSsxHro.js → DataPage-DOE_pKAY.js} +2 -2
  248. package/packages/web/dist/assets/DataTypePage-BnP_JELT.js +2 -0
  249. package/packages/web/dist/assets/{DataTypePage-Cr238Hx_.css → DataTypePage-CWrWvUPs.css} +1 -1
  250. package/packages/web/dist/assets/{DesignPage-6e0XbOFC.js → DesignPage-B9MJbF10.js} +3 -3
  251. package/packages/web/dist/assets/{ExplorePage-B7ND0W0l.js → ExplorePage-cRDQZRea.js} +2 -2
  252. package/packages/web/dist/assets/{FnPill-Cp3KuLmP.js → FnPill-CbLZCXYM.js} +2 -2
  253. package/packages/web/dist/assets/{FnView-C0XZdnsS.js → FnView-CG_wBKTP.js} +2 -2
  254. package/packages/web/dist/assets/{FnsView-GTH3p7a0.js → FnsView-BybyK12w.js} +2 -2
  255. package/packages/web/dist/assets/{GinExprView-DGxns6lH.js → GinExprView-BYCKSD_n.js} +2 -2
  256. package/packages/web/dist/assets/{GinForm-BDBUzuDP.js → GinForm-CXjYVf2_.js} +2 -2
  257. package/packages/web/dist/assets/{GinTypeView-CUsymbVf.js → GinTypeView-Bmbmx9e_.js} +2 -2
  258. package/packages/web/dist/assets/{GinValueView-jsKIfiEA.js → GinValueView-CWUzS7ti.js} +2 -2
  259. package/packages/web/dist/assets/{GraphPage-BCcPPsHu.js → GraphPage-D6OhckfJ.js} +2 -2
  260. package/packages/web/dist/assets/GraphPanel-BTitgA-K.js +2 -0
  261. package/packages/web/dist/assets/{HubPicker-EoOErgmk.js → HubPicker-DVly8dLD.js} +2 -2
  262. package/packages/web/dist/assets/{InboxApprovals-Dkq7DFp_.js → InboxApprovals-BF84edZU.js} +2 -2
  263. package/packages/web/dist/assets/{InboxPage-CHhslePq.js → InboxPage-DohZ9EDP.js} +2 -2
  264. package/packages/web/dist/assets/InjectedList-e6qr1kdU.js +2 -0
  265. package/packages/web/dist/assets/{InstallDialog-D-VwfZYF.js → InstallDialog-JJCKYs2s.js} +2 -2
  266. package/packages/web/dist/assets/InstanceTypes-BqUzx87o.js +2 -0
  267. package/packages/web/dist/assets/InstanceView-C73pev7A.js +2 -0
  268. package/packages/web/dist/assets/{ItemHistory-NQAP69ma.js → ItemHistory-dbGgOZsw.js} +2 -2
  269. package/packages/web/dist/assets/LimitsView-Ddp5WakY.js +2 -0
  270. package/packages/web/dist/assets/{ListSearch-BunVrDO0.js → ListSearch-CYNNAuMB.js} +2 -2
  271. package/packages/web/dist/assets/{LlmCallDetails-BoVNDTVs.js → LlmCallDetails-C9H5Hc2J.js} +2 -2
  272. package/packages/web/dist/assets/{LlmCallsView-BGpV92RC.js → LlmCallsView-CBqyZ8Cj.js} +2 -2
  273. package/packages/web/dist/assets/{LoadState-h-K9bTYc.js → LoadState-B2YhZlyC.js} +2 -2
  274. package/packages/web/dist/assets/McpDialog-DhlLklIq.js +2 -0
  275. package/packages/web/dist/assets/{McpView-GPXdCMne.js → McpView-D_ZmNO56.js} +2 -2
  276. package/packages/web/dist/assets/{McpsView-DJIR2JX5.js → McpsView-9_gwBuzw.js} +2 -2
  277. package/packages/web/dist/assets/{MemoryDialog-BTeIHQyA.js → MemoryDialog-pTHIxKEX.js} +2 -2
  278. package/packages/web/dist/assets/{ModelCallsView-DMcnwF2S.js → ModelCallsView-FHv2XWRX.js} +2 -2
  279. package/packages/web/dist/assets/{ModelPicker-CgkMFxSO.js → ModelPicker-EqOuvVnE.js} +2 -2
  280. package/packages/web/dist/assets/ModelsView-D9UaL4PX.js +2 -0
  281. package/packages/web/dist/assets/{NotFoundPage-Tk92K7HN.js → NotFoundPage-BsuJysan.js} +2 -2
  282. package/packages/web/dist/assets/{PairPage-D0BK8CCw.js → PairPage-B_ZXsbL4.js} +2 -2
  283. package/packages/web/dist/assets/{PanelHost-C-gKrxAk.js → PanelHost-Dx-vNNl5.js} +2 -2
  284. package/packages/web/dist/assets/PeopleView-D6dmEgMs.js +2 -0
  285. package/packages/web/dist/assets/{PeopleView-CJ8yArTh.css → PeopleView-DBxdbT1C.css} +1 -1
  286. package/packages/web/dist/assets/{PoliciesView-BRi-QAuo.js → PoliciesView-Bn4rm-ao.js} +2 -2
  287. package/packages/web/dist/assets/{RefusalList-DVO0bmeB.js → RefusalList-aosRD1ie.js} +2 -2
  288. package/packages/web/dist/assets/RendererHost-Ym_SMkhp.css +1 -0
  289. package/packages/web/dist/assets/RendererHost-rjnpSgyQ.js +2 -0
  290. package/packages/web/dist/assets/{ResourceViewer-Do0chYxU.js → ResourceViewer-C4tRColf.js} +2 -2
  291. package/packages/web/dist/assets/ResourcesPage-7mCLBORZ.js +2 -0
  292. package/packages/web/dist/assets/ResultGrid-CL2WSYQH.css +1 -0
  293. package/packages/web/dist/assets/ResultGrid-GIMoQUAr.js +2 -0
  294. package/packages/web/dist/assets/{ReviewSummaryStrip-DO3p64Qj.js → ReviewSummaryStrip-Bvjn3Iq8.js} +2 -2
  295. package/packages/web/dist/assets/ReviewView-DIqsUedT.js +3 -0
  296. package/packages/web/dist/assets/{RuleRow-DX9v4iGP.js → RuleRow-zRg-e8Vj.js} +2 -2
  297. package/packages/web/dist/assets/RunCard-C7wOGaw8.js +2 -0
  298. package/packages/web/dist/assets/RunCard-CSDiz-Nt.css +1 -0
  299. package/packages/web/dist/assets/{RunDetails-DjR206q6.js → RunDetails-W4GbE6AE.js} +2 -2
  300. package/packages/web/dist/assets/{RunDot-lHRICdM5.js → RunDot-C46uzzNM.js} +2 -2
  301. package/packages/web/dist/assets/{RunPage-CbAQ_WPR.js → RunPage-DPLtZpeB.js} +2 -2
  302. package/packages/web/dist/assets/{RunProgress-C3-B4tQf.js → RunProgress-Cr_6TBaF.js} +2 -2
  303. package/packages/web/dist/assets/{RunsView-DMkPmkqX.js → RunsView-tU350TPK.js} +2 -2
  304. package/packages/web/dist/assets/SettingsPage-B8QmmMN3.js +3 -0
  305. package/packages/web/dist/assets/{SettingsPage-t03BqXw8.css → SettingsPage-BTl3Ie4F.css} +1 -1
  306. package/packages/web/dist/assets/SignInPage-CXxLf7Rp.css +1 -0
  307. package/packages/web/dist/assets/{SignInPage-ByqGEZfj.js → SignInPage-DTwdqlnB.js} +2 -2
  308. package/packages/web/dist/assets/{StatusBadge-CXne0sRZ.js → StatusBadge-D7wKMAcD.js} +2 -2
  309. package/packages/web/dist/assets/{StorePlacementStep-B6SwTmdM.js → StorePlacementStep-C04nRU-u.js} +2 -2
  310. package/packages/web/dist/assets/{SystemConfig-vQDL_eUl.js → SystemConfig-CE3keXWq.js} +2 -2
  311. package/packages/web/dist/assets/SystemPageHost-CEhz4li8.js +2 -0
  312. package/packages/web/dist/assets/SystemPageHost-DX7LrFoN.css +1 -0
  313. package/packages/web/dist/assets/SystemView-CBFzEGfm.js +2 -0
  314. package/packages/web/dist/assets/SystemsView-0G8JntMV.js +2 -0
  315. package/packages/web/dist/assets/TableView-BK0uwLHl.js +3 -0
  316. package/packages/web/dist/assets/TableView-B_4MViVb.css +1 -0
  317. package/packages/web/dist/assets/{TableViewer-Boxx86f5.js → TableViewer-nbMInGJJ.js} +3 -3
  318. package/packages/web/dist/assets/{ThemePicker-CIg_oRQX.js → ThemePicker-fZpVSYqG.js} +2 -2
  319. package/packages/web/dist/assets/{TurnTree-Ecm0yA5g.js → TurnTree-Co-iBqhT.js} +2 -2
  320. package/packages/web/dist/assets/{UserMessage-BtECa8ka.css → UserMessage-B63G9sxC.css} +1 -1
  321. package/packages/web/dist/assets/{UserMessage-BlnqZDVU.js → UserMessage-CDjUxKY0.js} +6 -6
  322. package/packages/web/dist/assets/{ValueVisual-C-MWpp7c.js → ValueVisual-EJnCKgSy.js} +2 -2
  323. package/packages/web/dist/assets/{fn-modal-B98MR7JN.js → fn-modal-DtE65mFt.js} +2 -2
  324. package/packages/web/dist/assets/{fn-notices-CfTa1E8y.js → fn-notices-CCZ-DFbi.js} +2 -2
  325. package/packages/web/dist/assets/{formats-JwoKfXIq.js → formats-CyHV2siv.js} +2 -2
  326. package/packages/web/dist/assets/index-BY7M8QUk.css +1 -0
  327. package/packages/web/dist/assets/index-OZS2EluT.js +4 -0
  328. package/packages/web/dist/assets/{labels-BFbk11BE.js → labels-CT7_K0Pt.js} +2 -2
  329. package/packages/web/dist/assets/{layout-D1gf481r.js → layout-B6fBDg80.js} +2 -2
  330. package/packages/web/dist/assets/loaded-LaPjk6mK.js +2 -0
  331. package/packages/web/dist/assets/{metrics-CBPX3W5Y.js → metrics-9n8bKI7u.js} +2 -2
  332. package/packages/web/dist/assets/problems--AW4igVY.js +2 -0
  333. package/packages/web/dist/assets/{push-payload-BeU1ADYt.js → push-payload-B3EcrsVz.js} +64 -64
  334. package/packages/web/dist/assets/record-edits-B-FWAbxR.js +2 -0
  335. package/packages/web/dist/assets/{review-fP-l9D6H.js → review-uLESCEz1.js} +3 -3
  336. package/packages/web/dist/assets/routes-B7Zmt8wh.js +4 -0
  337. package/packages/web/dist/assets/{runs-CveC2kKo.js → runs-CUb2PTFg.js} +2 -2
  338. package/packages/web/dist/assets/{shared-LbaIHjbV.js → shared-Bxhw_9et.js} +2 -2
  339. package/packages/web/dist/assets/{sources-VPrtgLIi.js → sources-YgkjgFLe.js} +2 -2
  340. package/packages/web/dist/assets/src-DY1fSFJS.js +43 -0
  341. package/packages/web/dist/assets/state-ChQDWWj-.js +2 -0
  342. package/packages/web/dist/assets/{systems-BqE3WTSF.js → systems-CjwjRySu.js} +2 -2
  343. package/packages/web/dist/assets/table-host-B_D9dmCz.js +2 -0
  344. package/packages/web/dist/assets/tables-CaxIuHdw.js +2 -0
  345. package/packages/web/dist/assets/{ui-BzgWquIU.js → ui-DWjytmDS.js} +5 -5
  346. package/packages/web/dist/assets/{url-DKGcECT1.js → url-DbGOI14W.js} +2 -2
  347. package/packages/web/dist/index.html +49 -47
  348. package/packages/web/dist/sw.js +1 -1
  349. package/packages/web/package.json +2 -4
  350. package/premade/claude.zip +0 -0
  351. package/premade/database.zip +0 -0
  352. package/premade/web.zip +0 -0
  353. package/scripts/dev-env.ts +9 -9
  354. package/scripts/run-stack.ts +15 -15
  355. package/scripts/stack.ts +3 -3
  356. package/scripts/start.ts +18 -18
  357. package/systems/api/client/ApiServiceForm.vue +55 -0
  358. package/systems/api/client/ServiceList.vue +90 -0
  359. package/systems/api/client/ServicePage.vue +142 -0
  360. package/systems/api/client/ServicesPage.vue +32 -0
  361. package/systems/api/client/index.ts +15 -0
  362. package/systems/api/client/logic.ts +140 -0
  363. package/systems/api/client/state.ts +92 -0
  364. package/systems/api/package.json +9 -6
  365. package/systems/api/server/authoring.ts +2 -1
  366. package/systems/api/server/env.ts +1 -1
  367. package/systems/api/server/guard.ts +1 -1
  368. package/systems/api/server/http.ts +3 -2
  369. package/systems/api/server/impl.ts +3 -2
  370. package/systems/api/server/main.ts +11 -7
  371. package/systems/api/server/openapi.ts +1 -1
  372. package/systems/api/server/program.ts +2 -1
  373. package/systems/api/server/services.ts +2 -1
  374. package/systems/api/shared/http.ts +2 -1
  375. package/systems/api/shared/index.ts +15 -5
  376. package/{packages/core/src/programs.ts → systems/api/shared/services.ts} +7 -51
  377. package/systems/api/system.json +2 -1
  378. package/systems/api/tsconfig.json +2 -2
  379. package/systems/code/package.json +4 -3
  380. package/systems/code/server/authoring.ts +2 -1
  381. package/systems/code/server/impl.ts +2 -1
  382. package/systems/code/server/main.ts +5 -5
  383. package/systems/code/shared/index.ts +2 -3
  384. package/systems/code/shared/program.ts +23 -0
  385. package/systems/embedder/package.json +1 -1
  386. package/systems/embedder/server/env.ts +1 -1
  387. package/systems/embedder/server/main.ts +5 -5
  388. package/systems/embedder/shared/index.ts +1 -1
  389. package/systems/fs/client/machines/fakes.ts +1 -1
  390. package/systems/fs/client/machines/files/fakes.ts +1 -1
  391. package/systems/fs/client/machines/palette.ts +3 -2
  392. package/systems/fs/context/authoring/parts/client.md +23 -5
  393. package/systems/fs/context/authoring/parts/client.reference/client.md +7 -16
  394. package/systems/fs/context/authoring/parts/client.reference/pageinbox.md +524 -0
  395. package/systems/fs/context/authoring/parts/client.reference/{resultview.md → visuals.md} +85 -116
  396. package/systems/fs/context/authoring/parts/client.reference.md +8 -8
  397. package/systems/fs/context/authoring/parts/context.md +1 -1
  398. package/systems/fs/context/authoring/parts/contract.md +1 -1
  399. package/systems/fs/context/authoring/parts/core-types/admin-ts.md +2 -2
  400. package/systems/fs/context/authoring/parts/core-types/connections-ts.md +12 -1
  401. package/systems/fs/context/authoring/parts/core-types/context-files-ts.md +2 -2
  402. package/systems/fs/context/authoring/parts/core-types/context-graph-ts.md +2 -2
  403. package/systems/fs/context/authoring/parts/core-types/contextdecl.md +2 -2
  404. package/systems/fs/context/authoring/parts/core-types/lifecycle-ts.md +27 -2
  405. package/systems/fs/context/authoring/parts/core-types/manifest.md +27 -2
  406. package/systems/fs/context/authoring/parts/core-types/manifestpatch.md +26 -2
  407. package/systems/fs/context/authoring/parts/core-types/modes-ts.md +3 -3
  408. package/systems/fs/context/authoring/parts/core-types/records-systems-ts.md +145 -1
  409. package/systems/fs/context/authoring/parts/core-types/registries-ts.md +98 -2
  410. package/systems/fs/context/authoring/parts/core-types/run-ts.md +2 -2
  411. package/systems/fs/context/authoring/parts/core-types/system-pages-ts.md +4 -2
  412. package/systems/fs/context/authoring/parts/core-types/system-providers-ts.md +2 -2
  413. package/systems/fs/context/authoring/parts/core-types/tables-ts.md +91 -0
  414. package/systems/fs/context/authoring/parts/core-types/web-ts.md +1 -2
  415. package/systems/fs/context/authoring/parts/core-types.md +5 -8
  416. package/systems/fs/context/authoring/parts/examples/server-main-ts.md +4 -4
  417. package/systems/fs/context/authoring/parts/examples/systems-fs-shared-index-ts-lines-568-660.md +1 -1
  418. package/systems/fs/context/authoring/parts/fns.md +1 -1
  419. package/systems/fs/context/authoring/parts/folder.md +6 -6
  420. package/systems/fs/context/authoring/parts/hub/hub-ctx-from-resource.md +2 -2
  421. package/systems/fs/context/authoring/parts/hub/hub-install-package.md +2 -2
  422. package/systems/fs/context/authoring/parts/hub.reference.md +3 -3
  423. package/systems/fs/context/authoring/parts/internals/manifestof.md +2 -2
  424. package/systems/fs/context/authoring/parts/internals/permissionargs.md +4 -4
  425. package/systems/fs/context/authoring/parts/kinds-agents.md +1 -1
  426. package/systems/fs/context/authoring/parts/kinds-agents.reference/authoringsession.md +7 -5
  427. package/systems/fs/context/authoring/parts/kinds-agents.reference/kind.md +4 -4
  428. package/systems/fs/context/authoring/parts/outcomes.md +2 -2
  429. package/systems/fs/context/authoring/parts/outcomes.reference.md +2 -2
  430. package/systems/fs/context/authoring/parts/packaging.md +4 -4
  431. package/systems/fs/context/authoring/parts/remote.md +5 -5
  432. package/systems/fs/context/authoring/parts/remote.reference.md +201 -17
  433. package/systems/fs/context/authoring/parts/server.md +7 -7
  434. package/systems/fs/context/authoring/parts/server.reference.md +15 -15
  435. package/systems/fs/context/authoring/parts/testing.reference/equal.md +3 -3
  436. package/systems/fs/context/authoring/parts/testing.reference/fakehub.md +1 -1
  437. package/systems/fs/context/authoring/parts/testing.reference/kindprops.md +22 -10
  438. package/systems/fs/context/authoring/parts/testing.reference/{openmemorystore.md → storeconnection.md} +7 -19
  439. package/systems/fs/context/authoring/parts/testing.reference.md +5 -5
  440. package/systems/fs/context/authoring/parts/widgets.md +32 -22
  441. package/systems/fs/context/authoring/parts/widgets.reference.md +503 -9
  442. package/systems/fs/package.json +3 -3
  443. package/systems/fs/server/hosting.ts +10 -10
  444. package/systems/fs/server/main.ts +8 -8
  445. package/systems/fs/server/shell.ts +1 -1
  446. package/systems/fs/shared/index.ts +1 -1
  447. package/systems/google-calendar/package.json +1 -1
  448. package/systems/google-calendar/server/main.ts +4 -4
  449. package/systems/input/package.json +3 -3
  450. package/systems/input/server/main.ts +6 -6
  451. package/systems/mcp/client/McpServerForm.vue +99 -0
  452. package/systems/mcp/client/ServerList.vue +78 -0
  453. package/systems/mcp/client/ServerPage.vue +194 -0
  454. package/systems/mcp/client/ServersPage.vue +32 -0
  455. package/systems/mcp/client/index.ts +15 -0
  456. package/systems/mcp/client/logic.ts +224 -0
  457. package/systems/mcp/client/state.ts +128 -0
  458. package/systems/mcp/package.json +9 -6
  459. package/systems/mcp/server/dial.ts +1 -1
  460. package/systems/mcp/server/impl.ts +2 -1
  461. package/systems/mcp/server/instance.ts +3 -5
  462. package/systems/mcp/server/main.ts +10 -6
  463. package/systems/mcp/server/mirror.ts +2 -3
  464. package/systems/mcp/server/oauth.ts +2 -1
  465. package/systems/mcp/server/server-link.ts +2 -1
  466. package/systems/mcp/shared/index.ts +15 -2
  467. package/{packages/core/src/mcp-servers.ts → systems/mcp/shared/servers.ts} +6 -5
  468. package/systems/mcp/system.json +2 -1
  469. package/systems/mcp/tsconfig.json +2 -2
  470. package/systems/ollama/package.json +3 -3
  471. package/systems/ollama/server/main.ts +5 -5
  472. package/systems/schedule/package.json +3 -3
  473. package/systems/schedule/server/main.ts +6 -6
  474. package/systems/template/README.md +2 -2
  475. package/systems/template/package.json +1 -1
  476. package/systems/template/server/main.ts +4 -4
  477. package/systems/widgets/client/ChipRow.vue +22 -0
  478. package/systems/widgets/client/ProposalCard.vue +6 -5
  479. package/systems/widgets/client/SavedWidget.vue +11 -8
  480. package/systems/widgets/client/WidgetChips.vue +137 -0
  481. package/systems/widgets/client/WidgetView.vue +32 -0
  482. package/systems/widgets/client/charts/ChartVisual.vue +157 -0
  483. package/systems/widgets/client/charts/chart-data.ts +230 -0
  484. package/systems/widgets/client/charts/echarts-setup.ts +69 -0
  485. package/systems/widgets/client/charts/export.ts +36 -0
  486. package/systems/widgets/client/charts/families/calendar.ts +105 -0
  487. package/systems/widgets/client/charts/families/category.ts +186 -0
  488. package/systems/widgets/client/charts/families/crosstab.ts +113 -0
  489. package/systems/widgets/client/charts/families/distribution.ts +160 -0
  490. package/systems/widgets/client/charts/families/finance.ts +96 -0
  491. package/systems/widgets/client/charts/families/gauge.ts +75 -0
  492. package/systems/widgets/client/charts/families/hierarchy.ts +166 -0
  493. package/systems/widgets/client/charts/families/index.ts +21 -0
  494. package/systems/widgets/client/charts/families/network.ts +140 -0
  495. package/systems/widgets/client/charts/families/part.ts +61 -0
  496. package/systems/widgets/client/charts/families/profile.ts +30 -0
  497. package/systems/widgets/client/charts/families/progress.ts +76 -0
  498. package/systems/widgets/client/charts/families/range.ts +107 -0
  499. package/systems/widgets/client/charts/families/time.ts +177 -0
  500. package/systems/widgets/client/charts/families/timeline.ts +114 -0
  501. package/systems/widgets/client/charts/families/wide.ts +41 -0
  502. package/systems/widgets/client/charts/index.ts +37 -0
  503. package/systems/widgets/client/charts/maths.ts +139 -0
  504. package/systems/widgets/client/charts/size.ts +39 -0
  505. package/systems/widgets/client/chips.ts +150 -0
  506. package/systems/widgets/client/index.ts +18 -5
  507. package/systems/widgets/client/proposal.ts +2 -1
  508. package/systems/widgets/package.json +7 -4
  509. package/systems/widgets/server/authoring.ts +13 -7
  510. package/systems/widgets/server/env.ts +1 -1
  511. package/systems/widgets/server/impl.ts +10 -6
  512. package/systems/widgets/server/main.ts +6 -6
  513. package/systems/widgets/server/run.ts +16 -9
  514. package/systems/widgets/server/upgrade.ts +34 -0
  515. package/systems/widgets/shared/args.ts +137 -0
  516. package/systems/widgets/shared/charts.ts +243 -0
  517. package/systems/widgets/shared/index.ts +12 -3
  518. package/{packages/sdk/src → systems/widgets/shared}/relative-dates.ts +2 -1
  519. package/systems/widgets/shared/spec.ts +208 -0
  520. package/{packages/sdk/src → systems/widgets/shared}/widget-check.ts +7 -9
  521. package/{packages/sdk/src → systems/widgets/shared}/widget-schema.ts +4 -4
  522. package/packages/core/src/remote-auth.ts +0 -111
  523. package/packages/core/src/widgets.ts +0 -427
  524. package/packages/web/dist/assets/AdminLayout-B6Jrc_4W.js +0 -2
  525. package/packages/web/dist/assets/ApiServiceForm-BxprSaAq.css +0 -1
  526. package/packages/web/dist/assets/ApiServiceForm-CuuQgOJc.js +0 -2
  527. package/packages/web/dist/assets/ApiServiceView-7bTHSO_Z.js +0 -2
  528. package/packages/web/dist/assets/ApiServiceView-BVmdRCjR.css +0 -1
  529. package/packages/web/dist/assets/ApiServicesView-BTLV6c8n.css +0 -1
  530. package/packages/web/dist/assets/ApiServicesView-BXi24n49.js +0 -2
  531. package/packages/web/dist/assets/ChartVisual-BnFG9aFi.css +0 -1
  532. package/packages/web/dist/assets/ChartVisual-C4mgw4wh.js +0 -11
  533. package/packages/web/dist/assets/ChatPage-CAhHE03Z.js +0 -4
  534. package/packages/web/dist/assets/ConfigWithCustom-D_-rY66L.js +0 -3
  535. package/packages/web/dist/assets/ContextItemPage-rUI3-T_L.js +0 -2
  536. package/packages/web/dist/assets/ContextPage-CtefzyKg.js +0 -3
  537. package/packages/web/dist/assets/DataTypePage-BW9fWaz8.js +0 -2
  538. package/packages/web/dist/assets/FnList-BCnb4kOB.css +0 -1
  539. package/packages/web/dist/assets/FnList-Bx6H-kux.js +0 -2
  540. package/packages/web/dist/assets/GraphPanel-9tztGHmu.js +0 -2
  541. package/packages/web/dist/assets/InjectedList-CSWqRiON.js +0 -2
  542. package/packages/web/dist/assets/InstanceTypes-D3rAEiE7.js +0 -2
  543. package/packages/web/dist/assets/InstanceView-DoH8C-1j.js +0 -2
  544. package/packages/web/dist/assets/LimitsView-DY2C9nYS.js +0 -2
  545. package/packages/web/dist/assets/McpDialog-DhOCk6_E.js +0 -2
  546. package/packages/web/dist/assets/McpServerForm-Cor3fI7s.js +0 -2
  547. package/packages/web/dist/assets/McpServerForm-DsHaf5Um.css +0 -1
  548. package/packages/web/dist/assets/McpServerView-7I76EznB.css +0 -1
  549. package/packages/web/dist/assets/McpServerView-ewXRPEmZ.js +0 -2
  550. package/packages/web/dist/assets/McpServersView-Dd0xmfws.js +0 -2
  551. package/packages/web/dist/assets/ModelsView-cMHygeiK.js +0 -2
  552. package/packages/web/dist/assets/PeopleView-DRfeNWK5.js +0 -2
  553. package/packages/web/dist/assets/RemoteAuthFields-CgiufuqQ.js +0 -2
  554. package/packages/web/dist/assets/RemoteAuthFields-Dm44vz2t.css +0 -1
  555. package/packages/web/dist/assets/ResourcesPage-BBx2u2mw.js +0 -2
  556. package/packages/web/dist/assets/ResultGrid-Bj-0I5HY.js +0 -2
  557. package/packages/web/dist/assets/ResultGrid-CuUQyTjW.css +0 -1
  558. package/packages/web/dist/assets/ReviewView-DZF9E1hb.js +0 -3
  559. package/packages/web/dist/assets/RunCard-BnrtK2Yp.js +0 -2
  560. package/packages/web/dist/assets/RunCard-CfyRaDLS.css +0 -1
  561. package/packages/web/dist/assets/ServiceRows-4WythFpF.js +0 -2
  562. package/packages/web/dist/assets/ServiceRows-HPQ0pN6b.css +0 -1
  563. package/packages/web/dist/assets/SettingsPage-BN4oSzoL.js +0 -3
  564. package/packages/web/dist/assets/SignInPage-Djx-M-0U.css +0 -1
  565. package/packages/web/dist/assets/SystemPageHost-BeZ-6N0-.css +0 -1
  566. package/packages/web/dist/assets/SystemPageHost-DrMrEPyh.js +0 -2
  567. package/packages/web/dist/assets/SystemView-Be6TBM4j.js +0 -2
  568. package/packages/web/dist/assets/SystemsView-DZtT3laz.js +0 -2
  569. package/packages/web/dist/assets/WidgetView-DQUDeFkB.css +0 -1
  570. package/packages/web/dist/assets/WidgetView-DX4ejNb6.js +0 -3
  571. package/packages/web/dist/assets/export-BwFkEtcm.js +0 -15
  572. package/packages/web/dist/assets/index-6ScWTFy2.js +0 -4
  573. package/packages/web/dist/assets/index-CEslGcrX.css +0 -1
  574. package/packages/web/dist/assets/problems-t1E_ovSz.js +0 -2
  575. package/packages/web/dist/assets/record-edits-Bfsi4lU3.js +0 -2
  576. package/packages/web/dist/assets/remote-config-BNQhSDzB.js +0 -2
  577. package/packages/web/dist/assets/routes-DV4IJpwe.js +0 -4
  578. package/packages/web/dist/assets/size-Bh__w5aI.js +0 -2
  579. package/packages/web/dist/assets/src-CT3TeFaM.js +0 -43
  580. package/packages/web/dist/assets/state-xfQqaQPX.js +0 -2
  581. package/packages/web/dist/assets/widget-host-B87MTaTn.js +0 -2
  582. package/packages/web/dist/assets/widgets-BBCuSS6E.js +0 -2
  583. package/systems/fs/context/authoring/parts/client.reference/textareaprops.md +0 -195
  584. package/systems/fs/context/authoring/parts/core-types/remote-auth-ts.md +0 -64
  585. package/systems/fs/context/authoring/parts/core-types/widgets-ts.md +0 -303
  586. package/systems/fs/context/authoring/parts/widgets.reference/hub-visuals.md +0 -627
  587. package/systems/fs/context/authoring/parts/widgets.reference/sourcecompatible.md +0 -154
@@ -0,0 +1,113 @@
1
+ /**
2
+ * A measure for each pair of two keys: a heatmap (`heatmap` on a grid), value cells (`heatmap` on the `matrix`
3
+ * coordinate, each cell labelled), small charts (a bar chart per row key, each a grid in a `matrix` cell with its own
4
+ * category labels), a punch card (`scatter` dots sized by the value on both keys' axes) and grouped or stacked bars
5
+ * (`bar`, a series per row key).
6
+ */
7
+ import type { BarSeriesOption } from 'echarts/charts';
8
+ import type { XAXisComponentOption, YAXisComponentOption } from 'echarts';
9
+ import type { GridComponentOption } from 'echarts/components';
10
+ import type { ChartOption } from '../echarts-setup.ts';
11
+ import { chartValue, distinctValues, labelOf, legend, needed, numberOf, plotGrid, tooltip, type ChartBuilder, type ChartInput } from '../chart-data.ts';
12
+
13
+ /** The most small charts drawn; past it the first ones are drawn. */
14
+ export const MULTIPLES_MAX = 24;
15
+
16
+ /** The shading scale: from the surface to the accent, at the bottom where it never covers a cell. */
17
+ function shading(input: ChartInput, values: readonly number[]): NonNullable<ChartOption['visualMap']> {
18
+ const min = values.length === 0 ? 0 : Math.min(...values);
19
+ const max = values.length === 0 ? 1 : Math.max(...values);
20
+ return {
21
+ type: 'continuous', min, max: max === min ? min + 1 : max, calculable: !input.phone, orient: 'horizontal', left: 'center', bottom: 0,
22
+ itemHeight: input.phone ? 120 : 180, itemWidth: 10, inRange: { color: [input.palette.grid, input.palette.series[0] ?? input.palette.text] },
23
+ };
24
+ }
25
+
26
+ export const crosstab: ChartBuilder = (input) => {
27
+ const x = needed(input, 'x'); const y = needed(input, 'y'); const value = needed(input, 'value');
28
+ const xs = distinctValues(input.table, x.index).map(labelOf);
29
+ const ys = distinctValues(input.table, y.index).map(labelOf);
30
+ const cells = input.table.rows.map((row) => [labelOf(chartValue(row[x.index])), labelOf(chartValue(row[y.index])), numberOf(row[value.index])] as const);
31
+ const numbers = cells.flatMap((cell) => (cell[2] === null ? [] : [cell[2]]));
32
+ const rowOf = (click: { readonly dataIndex?: number | undefined }): number | undefined => click.dataIndex;
33
+
34
+ if (input.style === 'multiples') {
35
+ const shown = ys.slice(0, MULTIPLES_MAX);
36
+ const columns = Math.min(shown.length, input.phone ? 2 : Math.ceil(Math.sqrt(shown.length)));
37
+ const lines = Math.ceil(shown.length / columns);
38
+ const grids: GridComponentOption[] = []; const xAxes: XAXisComponentOption[] = []; const yAxes: YAXisComponentOption[] = []; const series: BarSeriesOption[] = [];
39
+ shown.forEach((name, i) => {
40
+ grids.push({ coordinateSystem: 'matrix', coord: [i % columns, Math.floor(i / columns)], top: 22, bottom: 26, left: 30, right: 8 });
41
+ xAxes.push({ type: 'category', gridIndex: i, data: xs, axisLabel: { hideOverlap: true, fontSize: input.phone ? 10 : 11, color: input.palette.muted }, axisTick: { show: false } });
42
+ yAxes.push({ type: 'value', gridIndex: i, name, nameLocation: 'end', nameTextStyle: { align: 'left', color: input.palette.text }, splitNumber: 2 });
43
+ series.push({ type: 'bar', xAxisIndex: i, yAxisIndex: i, data: xs.map((key) => cells.find((cell) => cell[0] === key && cell[1] === name)?.[2] ?? null) });
44
+ });
45
+ return {
46
+ option: {
47
+ tooltip: tooltip('axis'),
48
+ matrix: { x: { show: false, data: Array.from({ length: columns }, (_, i) => String(i)) }, y: { show: false, data: Array.from({ length: lines }, (_, i) => String(i)) }, left: 4, right: 4, top: 4, bottom: 4, backgroundStyle: { borderWidth: 0 }, body: { itemStyle: { borderWidth: 0 } } },
49
+ grid: grids, xAxis: xAxes, yAxis: yAxes, series,
50
+ },
51
+ rowOf: (click) => {
52
+ const name = shown[click.seriesIndex ?? -1]; const key = xs[click.dataIndex ?? -1];
53
+ const at = cells.findIndex((cell) => cell[0] === key && cell[1] === name);
54
+ return at < 0 ? undefined : at;
55
+ },
56
+ points: shown.length * xs.length,
57
+ };
58
+ }
59
+
60
+ if (input.style === 'punch') {
61
+ // a dot per pair, sized by its value (area grows with the value), on the same two axes as the heatmap
62
+ const most = Math.max(1, ...numbers.map(Math.abs));
63
+ return {
64
+ option: {
65
+ tooltip: tooltip('item'), grid: { left: 8, right: 16, top: 16, bottom: 8, outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' },
66
+ xAxis: { type: 'category', data: xs, boundaryGap: true, splitLine: { show: true, lineStyle: { color: input.palette.grid } }, axisLabel: { hideOverlap: true } },
67
+ yAxis: { type: 'category', data: ys, boundaryGap: true, splitLine: { show: true, lineStyle: { color: input.palette.grid } }, axisLabel: { hideOverlap: true } },
68
+ series: [{
69
+ type: 'scatter', data: cells.map((cell) => [cell[0], cell[1], cell[2]]),
70
+ symbolSize: (value: readonly (number | string | null)[]) => { const v = typeof value[2] === 'number' ? value[2] : 0; return 4 + Math.sqrt(Math.abs(v) / most) * (input.phone ? 22 : 34); },
71
+ itemStyle: { opacity: 0.8 },
72
+ }],
73
+ },
74
+ rowOf, points: cells.length,
75
+ };
76
+ }
77
+
78
+ if (input.style === 'grouped' || input.style === 'stacked') {
79
+ // the row key's values as series of bars over the column key
80
+ const stacked = input.style === 'stacked';
81
+ const at = (key: string, name: string): number => cells.findIndex((cell) => cell[0] === key && cell[1] === name);
82
+ return {
83
+ option: {
84
+ tooltip: tooltip('axis'), legend: legend(true), grid: plotGrid(36),
85
+ xAxis: { type: 'category', data: xs, axisLabel: { hideOverlap: true, rotate: input.phone && xs.length > 6 ? 30 : 0 } }, yAxis: { type: 'value' },
86
+ series: ys.map((name) => ({ type: 'bar' as const, name, ...(stacked ? { stack: 'total' } : {}), barMaxWidth: 32, itemStyle: { borderRadius: stacked ? 0 : 3 }, data: xs.map((key) => cells[at(key, name)]?.[2] ?? null) })),
87
+ },
88
+ rowOf: (click) => { const found = at(xs[click.dataIndex ?? -1] ?? '', ys[click.seriesIndex ?? -1] ?? ''); return found < 0 ? undefined : found; },
89
+ points: xs.length * ys.length,
90
+ };
91
+ }
92
+
93
+ if (input.style === 'cells') {
94
+ return {
95
+ option: {
96
+ tooltip: tooltip('item'), visualMap: shading(input, numbers),
97
+ matrix: { x: { data: xs }, y: { data: ys }, left: 8, right: 8, top: 8, bottom: 44 },
98
+ series: [{ type: 'heatmap', coordinateSystem: 'matrix', data: cells.map((cell) => [cell[0], cell[1], cell[2]]), label: { show: true, color: input.palette.text } }],
99
+ },
100
+ rowOf, points: cells.length,
101
+ };
102
+ }
103
+
104
+ return {
105
+ option: {
106
+ tooltip: tooltip('item'), visualMap: shading(input, numbers),
107
+ grid: { left: 8, right: 8, top: 16, bottom: 48, outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' },
108
+ xAxis: { type: 'category', data: xs, splitArea: { show: false }, axisLabel: { hideOverlap: true } }, yAxis: { type: 'category', data: ys, axisLabel: { hideOverlap: true } },
109
+ series: [{ type: 'heatmap', data: cells.map((cell) => [cell[0], cell[1], cell[2]]), label: { show: !input.phone && xs.length * ys.length <= 120, color: input.palette.text }, itemStyle: { borderColor: input.palette.surface, borderWidth: 1 } }],
110
+ },
111
+ rowOf, points: cells.length,
112
+ };
113
+ };
@@ -0,0 +1,160 @@
1
+ /**
2
+ * How numbers spread: points and bubbles (`scatter`), rippling points (`effectScatter`), points with a least-squares
3
+ * trend line and points split into quadrants at the means (`scatter` with a `line` or `markLine`), a strip plot (points
4
+ * per group along one axis), a histogram (`bar` over bins), box plots (`boxplot`, quartiles from ECharts' `boxplot`
5
+ * transform), a density curve and the cumulative share (`line`), and parallel axes (`parallel`). A group column makes a
6
+ * series per group. Histogram, box plot, density and cumulative share are whole-result styles (ranking hides them
7
+ * otherwise).
8
+ */
9
+ import type { EffectScatterSeriesOption, LineSeriesOption, ScatterSeriesOption } from 'echarts/charts';
10
+ import { bound, boundAll, dimension, labelOf, legend, needed, numberOf, plotGrid, SMOOTH, splitRows, tooltip, type ChartBuilder, type ChartInput, type RowGroup } from '../chart-data.ts';
11
+ import { density, ecdf, histogram, jitter, linearFit } from '../maths.ts';
12
+
13
+ /** The smallest and largest bubble, in pixels. */
14
+ const BUBBLE = { min: 6, max: 36 } as const;
15
+
16
+ /** The rows by the group column, or every row as one group. */
17
+ function groupsOf(input: ChartInput): RowGroup[] {
18
+ const group = bound(input, 'group');
19
+ return group === undefined ? [{ key: null, rows: input.table.rows.map((_, i) => i) }] : splitRows(input.table, group.index);
20
+ }
21
+
22
+ export const distribution: ChartBuilder = (input) => {
23
+ const x = needed(input, 'x');
24
+ const groups = groupsOf(input);
25
+ const named = bound(input, 'group') !== undefined;
26
+ const values = (rows: readonly number[], index: number): number[] => rows.flatMap((at) => { const v = numberOf(input.table.rows[at]?.[index]); return v === null ? [] : [v]; });
27
+ const nameOf = (group: RowGroup): string => (named ? labelOf(group.key) : x.label);
28
+ const valueAxis = { type: 'value' as const, name: x.label, nameLocation: 'middle' as const, nameGap: 28, scale: true };
29
+
30
+ if (input.style === 'histogram') {
31
+ const bins = histogram(values(input.table.rows.map((_, i) => i), x.index));
32
+ return {
33
+ option: {
34
+ tooltip: tooltip('axis'), grid: plotGrid(8),
35
+ dataset: { dimensions: ['bin', 'count'], source: bins.map((bin) => [`${bin.from.toLocaleString()}–${bin.to.toLocaleString()}`, bin.count]) },
36
+ xAxis: { type: 'category', name: x.label, nameLocation: 'middle', nameGap: 28, axisLabel: { hideOverlap: true } }, yAxis: { type: 'value', minInterval: 1 },
37
+ series: [{ type: 'bar', encode: { x: 'bin', y: 'count' }, barCategoryGap: '2%' }],
38
+ },
39
+ points: bins.length,
40
+ };
41
+ }
42
+
43
+ if (input.style === 'boxplot') {
44
+ const samples = groups.map((group) => values(group.rows, x.index));
45
+ const names = groups.map(nameOf);
46
+ return {
47
+ option: {
48
+ tooltip: tooltip('item'), grid: plotGrid(8),
49
+ dataset: [
50
+ { source: samples },
51
+ { fromDatasetIndex: 0, transform: { type: 'boxplot', config: { itemNameFormatter: (params: { value: number }) => names[params.value] ?? '' } } },
52
+ { fromDatasetIndex: 1, fromTransformResult: 1 },
53
+ ],
54
+ xAxis: { type: 'category', axisLabel: { hideOverlap: true } }, yAxis: { type: 'value', name: x.label },
55
+ series: [{ type: 'boxplot', datasetIndex: 1, itemStyle: { color: input.palette.surface, borderColor: input.palette.series[0] ?? input.palette.text } }, { type: 'scatter', datasetIndex: 2, symbolSize: 6 }],
56
+ },
57
+ points: samples.reduce((sum, list) => sum + list.length, 0),
58
+ };
59
+ }
60
+
61
+ if (input.style === 'density' || input.style === 'ecdf') {
62
+ const curves = groups.map((group) => {
63
+ const sample = values(group.rows, x.index);
64
+ return input.style === 'density' ? density(sample) : ecdf(sample);
65
+ });
66
+ const share = input.style === 'ecdf';
67
+ return {
68
+ option: {
69
+ tooltip: { ...tooltip('axis'), axisPointer: { type: 'line' } }, legend: legend(named), grid: plotGrid(named ? 36 : 8),
70
+ xAxis: valueAxis, yAxis: share ? { type: 'value', max: 100, axisLabel: { formatter: '{value}%' } } : { type: 'value', axisLabel: { show: false }, splitLine: { show: false } },
71
+ series: groups.map((group, g): LineSeriesOption => ({
72
+ type: 'line', name: nameOf(group), data: (curves[g] ?? []).map((point) => [point.x, share ? Math.round(point.y * 1000) / 10 : point.y]),
73
+ showSymbol: false, ...(share ? {} : SMOOTH), ...(share ? { step: 'end' as const } : { areaStyle: { opacity: 0.14 } }),
74
+ })),
75
+ },
76
+ points: curves.reduce((sum, curve) => sum + curve.length, 0),
77
+ };
78
+ }
79
+
80
+ if (input.style === 'strip') {
81
+ // each group on its own row, its values along the axis, nudged up and down (the same way every time) so equal values don't hide each other
82
+ const names = groups.map(nameOf);
83
+ const drawn = groups.map((group) => group.rows.filter((at) => numberOf(input.table.rows[at]?.[x.index]) !== null));
84
+ return {
85
+ option: {
86
+ tooltip: tooltip('item'), grid: plotGrid(8),
87
+ xAxis: valueAxis,
88
+ // a row per group; each point nudged up or down within its row (the same way every draw)
89
+ yAxis: { type: 'category', data: names, inverse: true, axisTick: { show: false }, axisLabel: { width: input.phone ? 80 : 140, overflow: 'truncate' } },
90
+ series: drawn.map((rows, g): ScatterSeriesOption => ({
91
+ type: 'scatter', name: names[g] ?? '', symbolSize: 8, itemStyle: { opacity: 0.7 },
92
+ data: rows.map((at, i) => ({ value: [numberOf(input.table.rows[at]?.[x.index]) ?? 0, names[g] ?? ''], symbolOffset: [0, Math.round(jitter(i) * 24)] })),
93
+ })),
94
+ },
95
+ rowOf: (click) => (click.dataIndex === undefined ? undefined : drawn[click.seriesIndex ?? 0]?.[click.dataIndex]),
96
+ points: input.table.rows.length,
97
+ };
98
+ }
99
+
100
+ if (input.style === 'parallel') {
101
+ const axes = [x, needed(input, 'y'), ...boundAll(input, 'dims')];
102
+ return {
103
+ option: {
104
+ tooltip: tooltip('item'), legend: legend(named),
105
+ parallel: { left: 24, right: 32, top: 24, bottom: named ? 40 : 16 },
106
+ parallelAxis: axes.map((axis, dim) => ({ dim, name: axis.label, nameTextStyle: { color: input.palette.muted } })),
107
+ series: groups.map((group) => ({
108
+ type: 'parallel' as const, name: labelOf(group.key), lineStyle: { width: 1, opacity: 0.5 },
109
+ data: group.rows.map((at) => axes.map((axis) => numberOf(input.table.rows[at]?.[axis.index]) ?? 0)),
110
+ })),
111
+ },
112
+ rowOf: (click) => (click.dataIndex === undefined ? undefined : groups[click.seriesIndex ?? 0]?.rows[click.dataIndex]),
113
+ points: input.table.rows.length,
114
+ };
115
+ }
116
+
117
+ const y = needed(input, 'y');
118
+ const size = input.style === 'bubble' ? bound(input, 'size') : undefined;
119
+ const low = typeof size?.facts?.min === 'number' ? size.facts.min : 0;
120
+ const high = typeof size?.facts?.max === 'number' ? size.facts.max : 1;
121
+ const symbolSize = (value: readonly (number | null)[]): number => {
122
+ const v = value[2] ?? low;
123
+ return high === low ? (BUBBLE.min + BUBBLE.max) / 2 : BUBBLE.min + ((v - low) / (high - low)) * (BUBBLE.max - BUBBLE.min);
124
+ };
125
+ const pairs = input.table.rows.flatMap((row) => { const a = numberOf(row[x.index]); const b = numberOf(row[y.index]); return a === null || b === null ? [] : [{ x: a, y: b }]; });
126
+ const series: (ScatterSeriesOption | EffectScatterSeriesOption | LineSeriesOption)[] = groups.map((group, g): ScatterSeriesOption | EffectScatterSeriesOption => {
127
+ const common = {
128
+ name: named ? labelOf(group.key) : y.label, datasetIndex: g, encode: { x: 'x', y: 'y', tooltip: size === undefined ? ['x', 'y'] : ['x', 'y', 'size'] },
129
+ ...(size === undefined ? { symbolSize: 8 } : { symbolSize }), itemStyle: { opacity: size === undefined ? 0.85 : 0.6 },
130
+ };
131
+ if (input.style === 'quadrants' && g === 0 && pairs.length > 0) {
132
+ const mean = (pick: (p: { x: number; y: number }) => number): number => pairs.reduce((sum, p) => sum + pick(p), 0) / pairs.length;
133
+ return {
134
+ ...common, type: 'scatter',
135
+ markLine: { silent: true, symbol: 'none', label: { show: false }, lineStyle: { color: input.palette.muted, type: 'dashed' }, data: [{ xAxis: mean((p) => p.x) }, { yAxis: mean((p) => p.y) }] },
136
+ };
137
+ }
138
+ return input.style === 'ripple' ? { ...common, type: 'effectScatter', rippleEffect: { scale: 2.5 } } : { ...common, type: 'scatter' };
139
+ });
140
+ const fit = input.style === 'trend' ? linearFit(pairs) : undefined;
141
+ if (fit !== undefined) {
142
+ series.push({
143
+ type: 'line', name: 'Trend', data: fit.points.map((p) => [p.x, p.y]), showSymbol: false, silent: true,
144
+ lineStyle: { color: input.palette.text, width: 1.5, type: 'dashed' }, itemStyle: { color: input.palette.text }, tooltip: { show: false }, z: 4,
145
+ });
146
+ }
147
+ return {
148
+ option: {
149
+ tooltip: tooltip('item'), legend: legend(named || fit !== undefined), grid: plotGrid(named || fit !== undefined ? 36 : 8),
150
+ dataset: groups.map((group) => ({
151
+ dimensions: [dimension(x, 'x'), dimension(y, 'y'), ...(size === undefined ? [] : [dimension(size, 'size')])],
152
+ source: group.rows.map((at) => { const row = input.table.rows[at] ?? []; return [numberOf(row[x.index]), numberOf(row[y.index]), ...(size === undefined ? [] : [numberOf(row[size.index])])]; }),
153
+ })),
154
+ xAxis: valueAxis, yAxis: { type: 'value', name: y.label, scale: true },
155
+ series,
156
+ },
157
+ rowOf: (click) => (click.dataIndex === undefined || (click.seriesIndex ?? 0) >= groups.length ? undefined : groups[click.seriesIndex ?? 0]?.rows[click.dataIndex]),
158
+ points: input.table.rows.length,
159
+ };
160
+ };
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Open, high, low and close per period: candles (`candlestick`), candles with volume bars in a second grid under them
3
+ * (`bar`), candles with 5- and 20-period moving averages (`line`), OHLC bars (`custom`: a high–low stick with the open
4
+ * ticked left and the close right) and the close alone (`line`); rises and falls in the theme's ok and danger colours.
5
+ * The period axis zooms every grid; a zoom sets the widget's from/to args.
6
+ */
7
+ import type { CustomSeriesRenderItem } from 'echarts';
8
+ import { chartValue, dimension, needed, numberOf, SMOOTH, tooltip, type ChartBuilder } from '../chart-data.ts';
9
+ import { movingAverage } from '../maths.ts';
10
+
11
+ /** The moving averages the "Candles and averages" style draws, in periods. */
12
+ export const AVERAGE_PERIODS = [5, 20] as const;
13
+
14
+ /** An OHLC bar: values are [index, open, close, low, high]; the stick runs low to high, the open ticks left, the close right. */
15
+ function ohlcBar(up: string, down: string): CustomSeriesRenderItem {
16
+ return (_params, api) => {
17
+ const at = api.value(0);
18
+ const [open, close, low, high] = [api.value(1), api.value(2), api.value(3), api.value(4)].map(Number);
19
+ const [x = 0, yHigh = 0] = api.coord([at, high ?? 0]);
20
+ const [, yLow = 0] = api.coord([at, low ?? 0]);
21
+ const [, yOpen = 0] = api.coord([at, open ?? 0]);
22
+ const [, yClose = 0] = api.coord([at, close ?? 0]);
23
+ const size = api.size?.([1, 0]);
24
+ const tick = Math.max(3, Math.min(10, (Array.isArray(size) ? size[0] ?? 8 : 8) * 0.3));
25
+ const stroke = (close ?? 0) >= (open ?? 0) ? up : down;
26
+ const style = { stroke, lineWidth: 2 };
27
+ return {
28
+ type: 'group',
29
+ children: [
30
+ { type: 'line', shape: { x1: x, y1: yHigh, x2: x, y2: yLow }, style },
31
+ { type: 'line', shape: { x1: x - tick, y1: yOpen, x2: x, y2: yOpen }, style },
32
+ { type: 'line', shape: { x1: x, y1: yClose, x2: x + tick, y2: yClose }, style },
33
+ ],
34
+ };
35
+ };
36
+ }
37
+
38
+ export const finance: ChartBuilder = (input) => {
39
+ const x = needed(input, 'x');
40
+ const columns = ['open', 'close', 'low', 'high'].map((channel) => needed(input, channel));
41
+ const volume = input.style === 'volume' ? needed(input, 'volume') : undefined;
42
+ const all = [x, ...columns, ...(volume === undefined ? [] : [volume])];
43
+ const source = input.table.rows.map((row) => all.map((column) => chartValue(row[column.index])));
44
+ const dims = all.map((column) => dimension(column));
45
+ const periods = source.map((row) => row[0] ?? null);
46
+ const axes = volume === undefined ? [0] : [0, 1];
47
+ const zoomBottom = input.phone ? 0 : 28;
48
+ const averages = input.style === 'averages';
49
+ const legendRoom = averages ? 28 : 0;
50
+ const { up, down } = input.palette;
51
+ const [, closeColumn] = columns;
52
+ const closes = input.table.rows.map((row) => (closeColumn === undefined ? null : numberOf(row[closeColumn.index])));
53
+
54
+ const price = (() => {
55
+ switch (input.style) {
56
+ case 'close':
57
+ return [{ type: 'line' as const, name: closeColumn?.label ?? 'Close', encode: { x: x.name, y: closeColumn?.name ?? '' }, showSymbol: source.length <= 40, areaStyle: { opacity: 0.12 } }];
58
+ case 'ohlc':
59
+ return [{
60
+ type: 'custom' as const, name: x.label, renderItem: ohlcBar(up, down),
61
+ data: input.table.rows.map((row, at) => [at, ...columns.map((column) => numberOf(row[column.index]))]), encode: { x: 0, y: [1, 2, 3, 4], tooltip: [1, 2, 3, 4] },
62
+ dimensions: ['period', ...columns.map((column) => column.label)],
63
+ }];
64
+ default:
65
+ return [
66
+ { type: 'candlestick' as const, name: x.label, encode: { x: x.name, y: columns.map((column) => column.name) }, itemStyle: { color: up, color0: down, borderColor: up, borderColor0: down } },
67
+ ...(averages ? AVERAGE_PERIODS.map((period, i) => ({
68
+ type: 'line' as const, name: `${String(period)}-period average`, data: movingAverage(closes, period).map((average, i) => [String(periods[i] ?? ''), average]), showSymbol: false, ...SMOOTH,
69
+ lineStyle: { width: 1.5, color: input.palette.series[i + 1] ?? input.palette.muted }, itemStyle: { color: input.palette.series[i + 1] ?? input.palette.muted },
70
+ })) : []),
71
+ ];
72
+ }
73
+ })();
74
+ return {
75
+ option: {
76
+ dataset: { dimensions: dims, source },
77
+ tooltip: { ...tooltip('axis'), axisPointer: { type: 'cross' } },
78
+ ...(averages ? { legend: { show: true, type: 'scroll', bottom: input.phone ? 0 : 28, left: 'center', itemWidth: 12, itemHeight: 8 } } : {}),
79
+ grid: volume === undefined
80
+ ? [{ left: 8, right: 16, top: 16, bottom: zoomBottom + legendRoom + 12, outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' }]
81
+ : [{ left: 8, right: 16, top: 16, height: '56%', outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' }, { left: 8, right: 16, top: '72%', bottom: zoomBottom + 12, outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' }],
82
+ xAxis: axes.map((gridIndex) => ({ type: 'category' as const, gridIndex, boundaryGap: true, axisLabel: { show: gridIndex === axes.length - 1, hideOverlap: true }, ...(input.style === 'ohlc' ? { data: periods.map((p) => String(p ?? '')) } : {}) })),
83
+ // prices float (scale); volume bars start at 0, so their heights compare
84
+ yAxis: axes.map((gridIndex) => (gridIndex === 0 ? { type: 'value' as const, gridIndex, scale: true, splitNumber: 4 } : { type: 'value' as const, gridIndex, min: 0, splitNumber: 2 })),
85
+ dataZoom: input.phone ? [{ type: 'inside', xAxisIndex: axes }] : [{ type: 'inside', xAxisIndex: axes }, { type: 'slider', xAxisIndex: axes, height: 18, bottom: 4 }],
86
+ series: [
87
+ ...price,
88
+ ...(volume === undefined ? [] : [{ type: 'bar' as const, name: volume.label, xAxisIndex: 1, yAxisIndex: 1, encode: { x: x.name, y: volume.name }, itemStyle: { color: input.palette.muted, opacity: 0.5 } }]),
89
+ ],
90
+ },
91
+ rowOf: (click) => click.dataIndex,
92
+ range: { kind: 'category', values: periods, day: x.facts?.day === true },
93
+ points: source.length,
94
+ height: volume === undefined ? 300 : 360,
95
+ };
96
+ };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * One value against its known range: a dial, a half dial and a dial with low, middle and high bands (`gauge`), a
3
+ * progress ring (`gauge` without a pointer), and a bullet bar (`bar` against the range, the maximum marked). The range
4
+ * is the column's declared bound, or 0 to the bound maximum column.
5
+ */
6
+ import type { GaugeSeriesOption } from 'echarts/charts';
7
+ import { bound, needed, numberOf, type ChartBuilder } from '../chart-data.ts';
8
+
9
+ /** A value as a person reads it on a dial. */
10
+ function shownText(value: number): string {
11
+ return value.toLocaleString(undefined, { maximumFractionDigits: Number.isInteger(value) ? 0 : 2 });
12
+ }
13
+
14
+ export const gauge: ChartBuilder = (input) => {
15
+ const value = needed(input, 'value'); const maximum = bound(input, 'max');
16
+ const row = input.table.rows[0] ?? [];
17
+ const shown = numberOf(row[value.index]) ?? 0;
18
+ const min = value.facts?.bound?.min ?? 0;
19
+ const raw = (maximum === undefined ? undefined : numberOf(row[maximum.index])) ?? value.facts?.bound?.max ?? Math.max(1, shown);
20
+ const max = raw === min ? min + 1 : raw;
21
+ const accent = input.palette.series[0] ?? input.palette.text;
22
+ const { palette } = input;
23
+
24
+ if (input.style === 'bullet') {
25
+ return {
26
+ option: {
27
+ tooltip: { trigger: 'item', confine: true },
28
+ grid: { left: 8, right: 24, top: 56, bottom: 40, outerBoundsMode: 'same', outerBoundsContain: 'axisLabel' },
29
+ title: { text: shownText(shown), subtext: `${value.label} of ${shownText(max)}`, left: 8, top: 0, itemGap: 2, textStyle: { color: palette.text, fontSize: 22, fontWeight: 600 }, subtextStyle: { color: palette.muted } },
30
+ xAxis: { type: 'value', min, max, splitNumber: 4 }, yAxis: { type: 'category', data: [value.label], show: false },
31
+ series: [
32
+ { type: 'bar', data: [max], barWidth: 22, itemStyle: { color: palette.grid, borderRadius: 4 }, silent: true, barGap: '-100%', tooltip: { show: false } },
33
+ { type: 'bar', name: value.label, data: [shown], barWidth: 10, itemStyle: { color: accent, borderRadius: 3 }, z: 3, markLine: { symbol: 'none', silent: true, label: { show: false }, lineStyle: { color: palette.text, width: 2, type: 'solid' }, data: [{ xAxis: max }] } },
34
+ ],
35
+ },
36
+ rowOf: () => 0, points: 2, height: 160,
37
+ };
38
+ }
39
+
40
+ const common = { type: 'gauge' as const, min, max, data: [{ value: shown, name: value.label }], radius: '88%' };
41
+ const detail = { color: palette.text, valueAnimation: true, formatter: shownText };
42
+ const series = ((): GaugeSeriesOption => {
43
+ switch (input.style) {
44
+ case 'progress':
45
+ return {
46
+ ...common, center: ['50%', '50%'], startAngle: 90, endAngle: -270, pointer: { show: false }, progress: { show: true, roundCap: true, width: 14, itemStyle: { color: accent } },
47
+ axisLine: { lineStyle: { width: 14, color: [[1, palette.grid]] } }, splitLine: { show: false }, axisTick: { show: false }, axisLabel: { show: false },
48
+ title: { offsetCenter: [0, '28%'], color: palette.muted }, detail: { ...detail, offsetCenter: [0, '-4%'], fontSize: 26 },
49
+ };
50
+ case 'half':
51
+ return {
52
+ ...common, center: ['50%', '72%'], radius: '110%', startAngle: 180, endAngle: 0, pointer: { show: false }, progress: { show: true, width: 18, itemStyle: { color: accent } },
53
+ axisLine: { lineStyle: { width: 18, color: [[1, palette.grid]] } }, splitLine: { show: false }, axisTick: { show: false }, axisLabel: { show: !input.phone, color: palette.muted, distance: -40, fontSize: 11 },
54
+ title: { offsetCenter: [0, '18%'], color: palette.muted }, detail: { ...detail, offsetCenter: [0, '-12%'], fontSize: 26 },
55
+ };
56
+ case 'bands': {
57
+ // low, middle and high thirds in the theme's danger, a series colour and ok: the needle says which
58
+ const bands: [number, string][] = [[1 / 3, palette.down], [2 / 3, palette.series[5] ?? palette.muted], [1, palette.up]];
59
+ return {
60
+ ...common, center: ['50%', '58%'], axisLine: { lineStyle: { width: 12, color: bands } }, pointer: { itemStyle: { color: palette.text }, width: 5 },
61
+ splitLine: { length: 12, distance: -12, lineStyle: { color: palette.surface, width: 2 } }, axisTick: { show: false },
62
+ axisLabel: { show: !input.phone, color: palette.muted, distance: 18 }, anchor: { show: true, size: 10, itemStyle: { color: palette.text } },
63
+ title: { offsetCenter: [0, '72%'], color: palette.muted }, detail: { ...detail, offsetCenter: [0, '42%'], fontSize: 22 },
64
+ };
65
+ }
66
+ default:
67
+ return {
68
+ ...common, center: ['50%', '58%'], progress: { show: true, width: 10, itemStyle: { color: accent } }, axisLine: { lineStyle: { width: 10, color: [[1, palette.grid]] } },
69
+ pointer: { itemStyle: { color: palette.muted } }, splitLine: { length: 8, lineStyle: { color: palette.grid } }, axisTick: { show: false },
70
+ axisLabel: { show: !input.phone, color: palette.muted, distance: 16 }, title: { offsetCenter: [0, '72%'], color: palette.muted }, detail: { ...detail, offsetCenter: [0, '42%'], fontSize: 22 },
71
+ };
72
+ }
73
+ })();
74
+ return { option: { series: [series] }, rowOf: () => 0, points: 1, height: 240 };
75
+ };
@@ -0,0 +1,166 @@
1
+ /**
2
+ * A tree from a name column and its parent column: a tree, a top-down tree and a radial tree (`tree`), a treemap
3
+ * (`treemap`), a sunburst (`sunburst`) and a flow from each parent into its children (`sankey`), sized by a measure (each leaf counts 1 without one). Rows whose parent is empty or names no
4
+ * row are the roots; several roots hang under one "All" in the trees.
5
+ */
6
+ import { bound, chartValue, labelOf, needed, numberOf, tooltip, type ChartBuilder } from '../chart-data.ts';
7
+
8
+ /** A node of the tree, with the row it came from. */
9
+ export interface TreeNode {
10
+ name: string;
11
+ value?: number;
12
+ row: number;
13
+ children: TreeNode[];
14
+ }
15
+
16
+ /** The roots of the tree the rows make (a row whose parent is itself or forms a loop is a root, so nothing is lost). */
17
+ export function treeOf(rows: readonly { readonly name: string; readonly parent: string | null; readonly value: number | null }[]): TreeNode[] {
18
+ const nodes = rows.map((row, at): TreeNode => ({ name: row.name, row: at, children: [], ...(row.value === null ? {} : { value: row.value }) }));
19
+ const byName = new Map(nodes.map((node) => [node.name, node]));
20
+ const roots: TreeNode[] = [];
21
+ rows.forEach((row, at) => {
22
+ const node = nodes[at];
23
+ if (node === undefined) { return; }
24
+ const parent = row.parent === null ? undefined : byName.get(row.parent);
25
+ let up = parent; let loops = false;
26
+ for (let steps = 0; up !== undefined && steps <= rows.length; steps++) {
27
+ if (up === node) { loops = true; break; }
28
+ const above = rows[up.row]?.parent;
29
+ up = above === null || above === undefined ? undefined : byName.get(above);
30
+ }
31
+ if (parent === undefined || loops) { roots.push(node); } else { parent.children.push(node); }
32
+ });
33
+ return roots;
34
+ }
35
+
36
+ /** A tree node with the colour it is drawn in. */
37
+ export interface ColouredNode extends Omit<TreeNode, 'children'> {
38
+ children: ColouredNode[];
39
+ itemStyle?: { color: string };
40
+ }
41
+
42
+ /** A node and everything under it in one colour (the sunburst's levels lighten the deeper rings). */
43
+ function paint(node: TreeNode, colour: string | undefined): ColouredNode {
44
+ const children = node.children.map((child) => paint(child, colour));
45
+ return colour === undefined ? { ...node, children } : { ...node, children, itemStyle: { color: colour } };
46
+ }
47
+
48
+ /** A sunburst's nodes coloured by their top-level branch from the palette, each branch's descendants in its colour. */
49
+ export function byBranch(roots: readonly TreeNode[], colours: readonly string[]): ColouredNode[] {
50
+ return roots.map((node, i) => paint(node, colours[i % Math.max(1, colours.length)]));
51
+ }
52
+
53
+ /**
54
+ * The tree sized for area charts: a leaf without a value counts 1, and a branch is at least the sum of its children (a
55
+ * branch's own smaller or missing value would otherwise hide or squeeze them).
56
+ */
57
+ export function sized(nodes: readonly TreeNode[]): TreeNode[] {
58
+ return nodes.map((node) => {
59
+ if (node.children.length === 0) { return { ...node, value: node.value ?? 1 }; }
60
+ const children = sized(node.children);
61
+ const sum = children.reduce((total, child) => total + (child.value ?? 0), 0);
62
+ return { ...node, children, value: Math.max(node.value ?? 0, sum) };
63
+ });
64
+ }
65
+
66
+ /** The rings a sunburst draws: one root's children (the root is the centre, so its ring would be a plain disc), else the roots. */
67
+ export function rings(roots: readonly TreeNode[]): readonly TreeNode[] {
68
+ const [only] = roots;
69
+ return roots.length === 1 && only !== undefined && only.children.length > 0 ? only.children : roots;
70
+ }
71
+
72
+ export const hierarchy: ChartBuilder = (input) => {
73
+ const name = needed(input, 'name'); const parent = needed(input, 'parent'); const size = bound(input, 'value');
74
+ const roots = treeOf(input.table.rows.map((row) => {
75
+ const up = chartValue(row[parent.index]);
76
+ return { name: labelOf(chartValue(row[name.index])), parent: up === null || up === '' ? null : labelOf(up), value: size === undefined ? null : numberOf(row[size.index]) };
77
+ }));
78
+ const rowByName = new Map(input.table.rows.map((row, at) => [labelOf(chartValue(row[name.index])), at]));
79
+ const rowOf = (click: { readonly name?: string | undefined }): number | undefined => (click.name === undefined ? undefined : rowByName.get(click.name));
80
+ const points = input.table.rows.length;
81
+ const text = { color: input.palette.text };
82
+
83
+ if (input.style === 'treemap' || input.style === 'sunburst') {
84
+ const data = sized(roots);
85
+ const series = input.style === 'treemap'
86
+ ? [{ type: 'treemap' as const, data, roam: false, left: 4, right: 4, top: 4, bottom: 28, label: { show: true }, upperLabel: { show: !input.phone, height: 20, color: input.palette.text }, breadcrumb: { show: true, bottom: 0, itemStyle: { color: input.palette.grid, textStyle: text } }, levels: [{ itemStyle: { borderColor: input.palette.surface, borderWidth: 2, gapWidth: 2 } }, { colorSaturation: [0.35, 0.6], itemStyle: { borderColorSaturation: 0.7, gapWidth: 1, borderWidth: 1 } }] }]
87
+ : [{
88
+ type: 'sunburst' as const, data: byBranch(rings(data), input.palette.series), radius: ['18%', '92%'], nodeClick: false as const,
89
+ // each top-level branch takes a palette colour its children inherit; labels sit inside each segment, in the ground's colour on the palette's fills; tiny segments drop theirs
90
+ label: { show: true, rotate: 'radial' as const, color: input.palette.surface, fontSize: input.phone ? 9 : 11, minAngle: input.phone ? 12 : 8 },
91
+ itemStyle: { borderColor: input.palette.surface, borderWidth: 1 },
92
+ levels: [{}, { itemStyle: { opacity: 1 } }, { itemStyle: { opacity: 0.72 } }, { itemStyle: { opacity: 0.5 } }],
93
+ }];
94
+ return { option: { tooltip: tooltip('item'), series }, rowOf, points };
95
+ }
96
+
97
+ if (input.style === 'flow') {
98
+ // each parent's flow into its children, as wide as the child's size (a leaf without one counts 1)
99
+ const data = sized(roots);
100
+ const links: { source: string; target: string; value: number }[] = [];
101
+ const walk = (node: TreeNode): void => { for (const child of node.children) { links.push({ source: node.name, target: child.name, value: child.value ?? 1 }); walk(child); } };
102
+ for (const node of data) { walk(node); }
103
+ const names = [...new Set(links.flatMap((link) => [link.source, link.target]))];
104
+ if (names.length === 0) { return { problem: 'There are no parents with children here to draw as a flow. Try Tree.' }; }
105
+ return {
106
+ option: {
107
+ tooltip: tooltip('item'),
108
+ series: [{ type: 'sankey', data: names.map((name) => ({ name })), links, left: 8, right: input.phone ? 56 : 104, top: 8, bottom: 8, nodeGap: 10, lineStyle: { color: 'gradient', opacity: 0.35 }, label: text }],
109
+ },
110
+ rowOf, points,
111
+ };
112
+ }
113
+
114
+ const [only] = roots;
115
+ const root: TreeNode = roots.length === 1 && only !== undefined ? only : { name: 'All', row: -1, children: roots };
116
+ const radial = input.style === 'radial';
117
+ if (input.style === 'vertical') {
118
+ return {
119
+ option: {
120
+ tooltip: tooltip('item'),
121
+ series: [{
122
+ type: 'tree', data: [root], orient: 'TB', roam: true, initialTreeDepth: input.phone ? 2 : 3, symbolSize: 8, left: 24, right: 24, top: 24, bottom: 56,
123
+ label: { ...text, position: 'top', fontSize: 12 }, leaves: { label: { position: 'bottom', rotate: -60, verticalAlign: 'middle', align: 'left' } }, lineStyle: { color: input.palette.grid },
124
+ expandAndCollapse: true,
125
+ }],
126
+ },
127
+ rowOf, points,
128
+ };
129
+ }
130
+ if (radial) {
131
+ // the root's label sits upright above the centre; every other label runs along its spoke, outwards (ECharts turns
132
+ // and sides them by angle when no position or rotation is given), with room around the ring for the leaves' labels
133
+ // a branch's label points back towards the centre, where the spokes are closest: on a phone those go smaller, so
134
+ // they clear the root's and each other's
135
+ const branchSize = input.phone ? 8 : 11;
136
+ const branches = (node: TreeNode): TreeNode & { readonly label?: { readonly fontSize: number } } => ({
137
+ ...node, children: node.children.map(branches), ...(node.children.length > 0 ? { label: { fontSize: branchSize } } : {}),
138
+ });
139
+ const centre = { ...branches(root), label: { rotate: 0, position: 'top' as const, fontWeight: 'bold' as const, fontSize: input.phone ? 10 : 12 } };
140
+ const room = input.phone ? 48 : 104;
141
+ return {
142
+ option: {
143
+ tooltip: tooltip('item'),
144
+ series: [{
145
+ type: 'tree', data: [centre], layout: 'radial', roam: true, initialTreeDepth: input.phone ? 2 : 3, symbolSize: 7,
146
+ left: room, right: room, top: room * 0.6, bottom: room * 0.6,
147
+ label: { ...text, fontSize: input.phone ? 10 : 11, distance: 6 }, lineStyle: { color: input.palette.grid },
148
+ expandAndCollapse: true,
149
+ }],
150
+ },
151
+ rowOf, points, height: input.phone ? 400 : 440,
152
+ };
153
+ }
154
+ return {
155
+ option: {
156
+ tooltip: tooltip('item'),
157
+ series: [{
158
+ type: 'tree', data: [root], layout: 'orthogonal', roam: true, initialTreeDepth: input.phone ? 2 : 3, symbolSize: 8,
159
+ left: 8, right: input.phone ? 72 : 120, top: 8, bottom: 8,
160
+ label: { ...text, position: 'left', fontSize: 12 }, leaves: { label: { position: 'right' } }, lineStyle: { color: input.palette.grid },
161
+ expandAndCollapse: true,
162
+ }],
163
+ },
164
+ rowOf, points,
165
+ };
166
+ };
@@ -0,0 +1,21 @@
1
+ /** Every chart family's option builder, by family (`shared/charts.ts` declares what each draws). */
2
+ import type { ChartFamily } from '../../../shared/charts.ts';
3
+ import type { ChartBuilder } from '../chart-data.ts';
4
+ import { calendar } from './calendar.ts';
5
+ import { category } from './category.ts';
6
+ import { crosstab } from './crosstab.ts';
7
+ import { distribution } from './distribution.ts';
8
+ import { finance } from './finance.ts';
9
+ import { gauge } from './gauge.ts';
10
+ import { hierarchy } from './hierarchy.ts';
11
+ import { network } from './network.ts';
12
+ import { part } from './part.ts';
13
+ import { profile } from './profile.ts';
14
+ import { progress } from './progress.ts';
15
+ import { range } from './range.ts';
16
+ import { time } from './time.ts';
17
+ import { timeline } from './timeline.ts';
18
+
19
+ export const CHART_BUILDERS: Readonly<Record<ChartFamily, ChartBuilder>> = {
20
+ part, category, time, distribution, crosstab, calendar, timeline, network, hierarchy, gauge, finance, range, profile, progress,
21
+ };