@motionscript/math 0.0.0-stage → 0.1.0-alpha.4

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 (322) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +385 -3
  5. package/dist/annotate/angle-mark.d.ts +46 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +132 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +46 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +114 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +20 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +81 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
  19. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
  20. package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
  21. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
  22. package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
  23. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
  24. package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
  25. package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
  26. package/dist/browser/index.js +2 -0
  27. package/dist/browser/index.js.map +7 -0
  28. package/dist/browser/kit.js +2 -0
  29. package/dist/browser/kit.js.map +7 -0
  30. package/dist/browser/manifest.json +30 -0
  31. package/dist/browser/tex.js +2 -0
  32. package/dist/browser/tex.js.map +7 -0
  33. package/dist/engine.d.ts +64 -0
  34. package/dist/engine.d.ts.map +1 -0
  35. package/dist/engine.js +42 -0
  36. package/dist/engine.js.map +1 -0
  37. package/dist/index.d.ts +30 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +30 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/kit/brace.d.ts +8 -0
  42. package/dist/kit/brace.d.ts.map +1 -0
  43. package/dist/kit/brace.js +36 -0
  44. package/dist/kit/brace.js.map +1 -0
  45. package/dist/kit/cache.d.ts +30 -0
  46. package/dist/kit/cache.d.ts.map +1 -0
  47. package/dist/kit/cache.js +53 -0
  48. package/dist/kit/cache.js.map +1 -0
  49. package/dist/kit/contour.d.ts +8 -0
  50. package/dist/kit/contour.d.ts.map +1 -0
  51. package/dist/kit/contour.js +93 -0
  52. package/dist/kit/contour.js.map +1 -0
  53. package/dist/kit/coords.d.ts +69 -0
  54. package/dist/kit/coords.d.ts.map +1 -0
  55. package/dist/kit/coords.js +224 -0
  56. package/dist/kit/coords.js.map +1 -0
  57. package/dist/kit/curve.d.ts +17 -0
  58. package/dist/kit/curve.d.ts.map +1 -0
  59. package/dist/kit/curve.js +22 -0
  60. package/dist/kit/curve.js.map +1 -0
  61. package/dist/kit/equation.d.ts +61 -0
  62. package/dist/kit/equation.d.ts.map +1 -0
  63. package/dist/kit/equation.js +168 -0
  64. package/dist/kit/equation.js.map +1 -0
  65. package/dist/kit/equation3d.d.ts +50 -0
  66. package/dist/kit/equation3d.d.ts.map +1 -0
  67. package/dist/kit/equation3d.js +103 -0
  68. package/dist/kit/equation3d.js.map +1 -0
  69. package/dist/kit/expression.d.ts +35 -0
  70. package/dist/kit/expression.d.ts.map +1 -0
  71. package/dist/kit/expression.js +124 -0
  72. package/dist/kit/expression.js.map +1 -0
  73. package/dist/kit/field-mark.d.ts +58 -0
  74. package/dist/kit/field-mark.d.ts.map +1 -0
  75. package/dist/kit/field-mark.js +129 -0
  76. package/dist/kit/field-mark.js.map +1 -0
  77. package/dist/kit/field.d.ts +14 -0
  78. package/dist/kit/field.d.ts.map +1 -0
  79. package/dist/kit/field.js +46 -0
  80. package/dist/kit/field.js.map +1 -0
  81. package/dist/kit/follow.d.ts +71 -0
  82. package/dist/kit/follow.d.ts.map +1 -0
  83. package/dist/kit/follow.js +159 -0
  84. package/dist/kit/follow.js.map +1 -0
  85. package/dist/kit/furniture.d.ts +30 -0
  86. package/dist/kit/furniture.d.ts.map +1 -0
  87. package/dist/kit/furniture.js +87 -0
  88. package/dist/kit/furniture.js.map +1 -0
  89. package/dist/kit/geometry.d.ts +13 -0
  90. package/dist/kit/geometry.d.ts.map +1 -0
  91. package/dist/kit/geometry.js +54 -0
  92. package/dist/kit/geometry.js.map +1 -0
  93. package/dist/kit/mark.d.ts +47 -0
  94. package/dist/kit/mark.d.ts.map +1 -0
  95. package/dist/kit/mark.js +103 -0
  96. package/dist/kit/mark.js.map +1 -0
  97. package/dist/kit/part-fills.d.ts +23 -0
  98. package/dist/kit/part-fills.d.ts.map +1 -0
  99. package/dist/kit/part-fills.js +46 -0
  100. package/dist/kit/part-fills.js.map +1 -0
  101. package/dist/kit/place.d.ts +18 -0
  102. package/dist/kit/place.d.ts.map +1 -0
  103. package/dist/kit/place.js +68 -0
  104. package/dist/kit/place.js.map +1 -0
  105. package/dist/kit/placement.d.ts +8 -0
  106. package/dist/kit/placement.d.ts.map +1 -0
  107. package/dist/kit/placement.js +8 -0
  108. package/dist/kit/placement.js.map +1 -0
  109. package/dist/kit/sampler.d.ts +17 -0
  110. package/dist/kit/sampler.d.ts.map +1 -0
  111. package/dist/kit/sampler.js +250 -0
  112. package/dist/kit/sampler.js.map +1 -0
  113. package/dist/kit/scale.d.ts +12 -0
  114. package/dist/kit/scale.d.ts.map +1 -0
  115. package/dist/kit/scale.js +37 -0
  116. package/dist/kit/scale.js.map +1 -0
  117. package/dist/kit/source.d.ts +22 -0
  118. package/dist/kit/source.d.ts.map +1 -0
  119. package/dist/kit/source.js +45 -0
  120. package/dist/kit/source.js.map +1 -0
  121. package/dist/kit/system.d.ts +33 -0
  122. package/dist/kit/system.d.ts.map +1 -0
  123. package/dist/kit/system.js +67 -0
  124. package/dist/kit/system.js.map +1 -0
  125. package/dist/kit/ticks.d.ts +19 -0
  126. package/dist/kit/ticks.d.ts.map +1 -0
  127. package/dist/kit/ticks.js +78 -0
  128. package/dist/kit/ticks.js.map +1 -0
  129. package/dist/kit/withdrawn.d.ts +9 -0
  130. package/dist/kit/withdrawn.d.ts.map +1 -0
  131. package/dist/kit/withdrawn.js +9 -0
  132. package/dist/kit/withdrawn.js.map +1 -0
  133. package/dist/marks/curve-area.d.ts +32 -0
  134. package/dist/marks/curve-area.d.ts.map +1 -0
  135. package/dist/marks/curve-area.js +82 -0
  136. package/dist/marks/curve-area.js.map +1 -0
  137. package/dist/marks/drop-lines.d.ts +22 -0
  138. package/dist/marks/drop-lines.d.ts.map +1 -0
  139. package/dist/marks/drop-lines.js +58 -0
  140. package/dist/marks/drop-lines.js.map +1 -0
  141. package/dist/marks/plot-point.d.ts +35 -0
  142. package/dist/marks/plot-point.d.ts.map +1 -0
  143. package/dist/marks/plot-point.js +97 -0
  144. package/dist/marks/plot-point.js.map +1 -0
  145. package/dist/marks/riemann-sum.d.ts +37 -0
  146. package/dist/marks/riemann-sum.d.ts.map +1 -0
  147. package/dist/marks/riemann-sum.js +91 -0
  148. package/dist/marks/riemann-sum.js.map +1 -0
  149. package/dist/marks/tangent-line.d.ts +27 -0
  150. package/dist/marks/tangent-line.d.ts.map +1 -0
  151. package/dist/marks/tangent-line.js +103 -0
  152. package/dist/marks/tangent-line.js.map +1 -0
  153. package/dist/marks/vector-arrow.d.ts +32 -0
  154. package/dist/marks/vector-arrow.d.ts.map +1 -0
  155. package/dist/marks/vector-arrow.js +87 -0
  156. package/dist/marks/vector-arrow.js.map +1 -0
  157. package/dist/nodes.d.ts +35 -0
  158. package/dist/nodes.d.ts.map +1 -0
  159. package/dist/nodes.js +63 -0
  160. package/dist/nodes.js.map +1 -0
  161. package/dist/plots/function-plot.d.ts +67 -0
  162. package/dist/plots/function-plot.d.ts.map +1 -0
  163. package/dist/plots/function-plot.js +215 -0
  164. package/dist/plots/function-plot.js.map +1 -0
  165. package/dist/plots/points-plot.d.ts +28 -0
  166. package/dist/plots/points-plot.d.ts.map +1 -0
  167. package/dist/plots/points-plot.js +99 -0
  168. package/dist/plots/points-plot.js.map +1 -0
  169. package/dist/plots/stream-lines.d.ts +35 -0
  170. package/dist/plots/stream-lines.d.ts.map +1 -0
  171. package/dist/plots/stream-lines.js +141 -0
  172. package/dist/plots/stream-lines.js.map +1 -0
  173. package/dist/plots/traced-path.d.ts +31 -0
  174. package/dist/plots/traced-path.d.ts.map +1 -0
  175. package/dist/plots/traced-path.js +56 -0
  176. package/dist/plots/traced-path.js.map +1 -0
  177. package/dist/plots/vector-field.d.ts +23 -0
  178. package/dist/plots/vector-field.d.ts.map +1 -0
  179. package/dist/plots/vector-field.js +91 -0
  180. package/dist/plots/vector-field.js.map +1 -0
  181. package/dist/structures/graph-layout.d.ts +11 -0
  182. package/dist/structures/graph-layout.d.ts.map +1 -0
  183. package/dist/structures/graph-layout.js +135 -0
  184. package/dist/structures/graph-layout.js.map +1 -0
  185. package/dist/structures/network-graph.d.ts +83 -0
  186. package/dist/structures/network-graph.d.ts.map +1 -0
  187. package/dist/structures/network-graph.js +289 -0
  188. package/dist/structures/network-graph.js.map +1 -0
  189. package/dist/structures/sample-space.d.ts +62 -0
  190. package/dist/structures/sample-space.d.ts.map +1 -0
  191. package/dist/structures/sample-space.js +199 -0
  192. package/dist/structures/sample-space.js.map +1 -0
  193. package/dist/systems/axes2d.d.ts +75 -0
  194. package/dist/systems/axes2d.d.ts.map +1 -0
  195. package/dist/systems/axes2d.js +193 -0
  196. package/dist/systems/axes2d.js.map +1 -0
  197. package/dist/systems/number-line.d.ts +49 -0
  198. package/dist/systems/number-line.d.ts.map +1 -0
  199. package/dist/systems/number-line.js +127 -0
  200. package/dist/systems/number-line.js.map +1 -0
  201. package/dist/systems/number-plane.d.ts +59 -0
  202. package/dist/systems/number-plane.d.ts.map +1 -0
  203. package/dist/systems/number-plane.js +193 -0
  204. package/dist/systems/number-plane.js.map +1 -0
  205. package/dist/systems/polar-plane.d.ts +48 -0
  206. package/dist/systems/polar-plane.d.ts.map +1 -0
  207. package/dist/systems/polar-plane.js +165 -0
  208. package/dist/systems/polar-plane.js.map +1 -0
  209. package/dist/tex/geometry.d.ts +85 -0
  210. package/dist/tex/geometry.d.ts.map +1 -0
  211. package/dist/tex/geometry.js +632 -0
  212. package/dist/tex/geometry.js.map +1 -0
  213. package/dist/tex/index.d.ts +11 -0
  214. package/dist/tex/index.d.ts.map +1 -0
  215. package/dist/tex/index.js +9 -0
  216. package/dist/tex/index.js.map +1 -0
  217. package/dist/tex/mathjax.d.ts +33 -0
  218. package/dist/tex/mathjax.d.ts.map +1 -0
  219. package/dist/tex/mathjax.js +74 -0
  220. package/dist/tex/mathjax.js.map +1 -0
  221. package/dist/tex/matrix.d.ts +31 -0
  222. package/dist/tex/matrix.d.ts.map +1 -0
  223. package/dist/tex/matrix.js +73 -0
  224. package/dist/tex/matrix.js.map +1 -0
  225. package/dist/tex/node.d.ts +215 -0
  226. package/dist/tex/node.d.ts.map +1 -0
  227. package/dist/tex/node.js +595 -0
  228. package/dist/tex/node.js.map +1 -0
  229. package/dist/tex/tween.d.ts +50 -0
  230. package/dist/tex/tween.d.ts.map +1 -0
  231. package/dist/tex/tween.js +253 -0
  232. package/dist/tex/tween.js.map +1 -0
  233. package/dist/three/axes3d.d.ts +87 -0
  234. package/dist/three/axes3d.d.ts.map +1 -0
  235. package/dist/three/axes3d.js +228 -0
  236. package/dist/three/axes3d.js.map +1 -0
  237. package/dist/three/curve-plot3d.d.ts +60 -0
  238. package/dist/three/curve-plot3d.d.ts.map +1 -0
  239. package/dist/three/curve-plot3d.js +143 -0
  240. package/dist/three/curve-plot3d.js.map +1 -0
  241. package/dist/three/label3d.d.ts +11 -0
  242. package/dist/three/label3d.d.ts.map +1 -0
  243. package/dist/three/label3d.js +40 -0
  244. package/dist/three/label3d.js.map +1 -0
  245. package/dist/three/plot-point3d.d.ts +26 -0
  246. package/dist/three/plot-point3d.d.ts.map +1 -0
  247. package/dist/three/plot-point3d.js +60 -0
  248. package/dist/three/plot-point3d.js.map +1 -0
  249. package/dist/three/space.d.ts +28 -0
  250. package/dist/three/space.d.ts.map +1 -0
  251. package/dist/three/space.js +47 -0
  252. package/dist/three/space.js.map +1 -0
  253. package/dist/three/surface-plot3d.d.ts +80 -0
  254. package/dist/three/surface-plot3d.d.ts.map +1 -0
  255. package/dist/three/surface-plot3d.js +290 -0
  256. package/dist/three/surface-plot3d.js.map +1 -0
  257. package/dist/three/vector-arrow3d.d.ts +25 -0
  258. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  259. package/dist/three/vector-arrow3d.js +72 -0
  260. package/dist/three/vector-arrow3d.js.map +1 -0
  261. package/package.json +79 -3
  262. package/registry.json +251 -0
  263. package/src/annotate/angle-mark.ts +147 -0
  264. package/src/annotate/curly-brace.ts +126 -0
  265. package/src/annotate/emphasis-mark.ts +89 -0
  266. package/src/engine.ts +72 -0
  267. package/src/index.ts +29 -0
  268. package/src/kit/brace.ts +37 -0
  269. package/src/kit/cache.ts +61 -0
  270. package/src/kit/contour.ts +94 -0
  271. package/src/kit/coords.ts +278 -0
  272. package/src/kit/curve.ts +29 -0
  273. package/src/kit/equation.ts +181 -0
  274. package/src/kit/equation3d.ts +137 -0
  275. package/src/kit/expression.ts +159 -0
  276. package/src/kit/field-mark.ts +155 -0
  277. package/src/kit/field.ts +50 -0
  278. package/src/kit/follow.ts +203 -0
  279. package/src/kit/furniture.ts +108 -0
  280. package/src/kit/geometry.ts +49 -0
  281. package/src/kit/mark.ts +131 -0
  282. package/src/kit/part-fills.ts +61 -0
  283. package/src/kit/place.ts +101 -0
  284. package/src/kit/placement.ts +8 -0
  285. package/src/kit/sampler.ts +281 -0
  286. package/src/kit/scale.ts +39 -0
  287. package/src/kit/source.ts +57 -0
  288. package/src/kit/system.ts +99 -0
  289. package/src/kit/ticks.ts +85 -0
  290. package/src/kit/withdrawn.ts +8 -0
  291. package/src/marks/curve-area.ts +89 -0
  292. package/src/marks/drop-lines.ts +63 -0
  293. package/src/marks/plot-point.ts +107 -0
  294. package/src/marks/riemann-sum.ts +98 -0
  295. package/src/marks/tangent-line.ts +103 -0
  296. package/src/marks/vector-arrow.ts +98 -0
  297. package/src/nodes.ts +63 -0
  298. package/src/plots/function-plot.ts +236 -0
  299. package/src/plots/points-plot.ts +107 -0
  300. package/src/plots/stream-lines.ts +151 -0
  301. package/src/plots/traced-path.ts +52 -0
  302. package/src/plots/vector-field.ts +88 -0
  303. package/src/structures/graph-layout.ts +145 -0
  304. package/src/structures/network-graph.ts +308 -0
  305. package/src/structures/sample-space.ts +209 -0
  306. package/src/systems/axes2d.ts +217 -0
  307. package/src/systems/number-line.ts +131 -0
  308. package/src/systems/number-plane.ts +203 -0
  309. package/src/systems/polar-plane.ts +176 -0
  310. package/src/tex/geometry.ts +703 -0
  311. package/src/tex/index.ts +14 -0
  312. package/src/tex/mathjax.ts +82 -0
  313. package/src/tex/matrix.ts +75 -0
  314. package/src/tex/node.ts +641 -0
  315. package/src/tex/tween.ts +308 -0
  316. package/src/three/axes3d.ts +240 -0
  317. package/src/three/curve-plot3d.ts +147 -0
  318. package/src/three/label3d.ts +50 -0
  319. package/src/three/plot-point3d.ts +66 -0
  320. package/src/three/space.ts +67 -0
  321. package/src/three/surface-plot3d.ts +323 -0
  322. package/src/three/vector-arrow3d.ts +77 -0
@@ -0,0 +1,289 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { colorProperty, command, fillProperty, Graphics2D, node, PaintNode, property, strokeProperty, } from "@motionscript/sdk";
8
+ import { declareFormulas, drawLabels } from "../kit/furniture.js";
9
+ import { lerpPartFills, partPaint, readPartFills, withPartFill } from "../kit/part-fills.js";
10
+ import { GRAPH_LAYOUTS, layOut } from "./graph-layout.js";
11
+ // Every list keeps each entry as it was written, a blank or a repeat included, so
12
+ // an editor showing the list shows the row it just added. What is drawn skips
13
+ // what is not complete yet (`_names`, `_links`).
14
+ function readVertices(value) {
15
+ return (Array.isArray(value) ? value : []).map((name) => String(name ?? ""));
16
+ }
17
+ // An edge reads from `{ from, to }` or a pair, so a list written by hand is as good as one from a table.
18
+ function readEdges(value) {
19
+ return (Array.isArray(value) ? value : []).map((edge) => {
20
+ const [from, to] = Array.isArray(edge) ? edge : [edge?.from, edge?.to];
21
+ return { from: String(from ?? ""), to: String(to ?? "") };
22
+ });
23
+ }
24
+ function readPositions(value) {
25
+ const at = (n) => (typeof n === "number" && Number.isFinite(n) ? n : 0);
26
+ return (Array.isArray(value) ? value : []).map((entry) => ({ vertex: String(entry?.vertex ?? ""), x: at(entry?.x), y: at(entry?.y) }));
27
+ }
28
+ /** How far a directed edge and the one back between the same two vertices bow apart, as a share of their length. */
29
+ const BOW = 0.12;
30
+ /**
31
+ * Vertices and the edges between them, arranged by a rule: in a circle, by
32
+ * springs, as a tree from `root`, or in a grid. Its `fill` is the vertices and
33
+ * its `stroke` the edges, with an arrowhead each when `directed`. `arrangeTo`
34
+ * moves every vertex to where another rule places it; `partFillTo` paints a
35
+ * vertex, or an edge written `a-b`. (`layout` is every node's own box.)
36
+ */
37
+ let NetworkGraph = class NetworkGraph extends PaintNode {
38
+ constructor(props) {
39
+ super(props ?? {});
40
+ this.applyProp("_layoutFrom", "");
41
+ this.applyProp("_layoutMix", 1);
42
+ }
43
+ /** Move every vertex to where another arrangement places it. */
44
+ arrangeTo(args) {
45
+ const from = this.arrangement;
46
+ const to = args.data?.arrangement ?? from;
47
+ return this.command((t) => ({ arrangement: to, _layoutFrom: from, _layoutMix: t }), args.duration, args.easing);
48
+ }
49
+ /** Paint one part of the graph: a vertex by its name, or an edge written `a-b`. */
50
+ partFillTo(args) {
51
+ const { part, fill } = args.data ?? {};
52
+ if (!part || fill == null)
53
+ return this.to({ data: {}, duration: args.duration, easing: args.easing });
54
+ return this.to({
55
+ data: { partFills: withPartFill(this.partFills, { part, fill }) },
56
+ duration: args.duration,
57
+ easing: args.easing,
58
+ });
59
+ }
60
+ declareAssets(assets) {
61
+ super.declareAssets(assets);
62
+ if (this.fontFamily !== "")
63
+ assets.font(this.fontFamily);
64
+ if (this.labels)
65
+ declareFormulas(assets, this._names());
66
+ }
67
+ /** Where each vertex is drawn, in pixels from the node's centre, y up. */
68
+ vertexPoints() {
69
+ const { width, height } = this.layoutBounds;
70
+ const room = this.vertexRadius + Math.max(2, this.labelSize * 0.2);
71
+ const halfX = Math.max(0, width / 2 - room);
72
+ const halfY = Math.max(0, height / 2 - room);
73
+ const to = this._placed(this.arrangement);
74
+ const from = this._layoutMix < 1 && this._layoutFrom !== "" ? this._placed(this._layoutFrom) : null;
75
+ const t = this._layoutMix;
76
+ const out = new Map();
77
+ for (const [name, p] of to) {
78
+ const q = from?.get(name) ?? p;
79
+ out.set(name, { x: (q.x + (p.x - q.x) * t) * halfX, y: (q.y + (p.y - q.y) * t) * halfY });
80
+ }
81
+ return out;
82
+ }
83
+ renderSelf(ctx) {
84
+ const points = this.vertexPoints();
85
+ if (points.size === 0)
86
+ return;
87
+ const parts = new Map(this.partFills.map((entry) => [entry.part, entry]));
88
+ this._drawEdges(ctx, points, parts);
89
+ this._drawVertices(ctx, points, parts);
90
+ }
91
+ // The edges are drawn under the vertices, in `renderSelf`; there is no outline of the node's own.
92
+ renderStroke() { }
93
+ _layouts = new Map();
94
+ /** Each vertex's place under `layout`, from -1 to 1, a hand-placed one where it is. */
95
+ _placed(layout) {
96
+ const vertices = this._names();
97
+ const edges = this._links();
98
+ const key = [layout, this.root, vertices.join("\u0000"), JSON.stringify(edges), JSON.stringify(this.positions)].join("|");
99
+ let placed = this._layouts.get(key);
100
+ if (!placed) {
101
+ placed = layOut(layout, vertices, edges, this.root.trim());
102
+ for (const { vertex, x, y } of this.positions) {
103
+ const name = vertex.trim();
104
+ if (placed.has(name))
105
+ placed.set(name, { x, y });
106
+ }
107
+ // Two layouts are held at once while one becomes the other.
108
+ if (this._layouts.size > 4)
109
+ this._layouts.clear();
110
+ this._layouts.set(key, placed);
111
+ }
112
+ return placed;
113
+ }
114
+ _drawEdges(ctx, points, parts) {
115
+ const stroke = this.stroke;
116
+ if (stroke.length === 0)
117
+ return;
118
+ const r = this.vertexRadius;
119
+ const links = this._links();
120
+ const pairs = new Set(links.map(({ from, to }) => `${from}\u0000${to}`));
121
+ const plain = new Graphics2D();
122
+ let drawnPlain = false;
123
+ for (const { from, to } of links) {
124
+ const a = points.get(from);
125
+ const b = points.get(to);
126
+ if (!a || !b)
127
+ continue;
128
+ const run = from === to ? loop(a, r) : edge(a, b, r, this.directed && pairs.has(`${to}\u0000${from}`) ? BOW : 0);
129
+ if (run.length < 2)
130
+ continue;
131
+ const paint = parts.get(`${from}-${to}`) ?? (this.directed ? undefined : parts.get(`${to}-${from}`));
132
+ const own = this.directed || paint !== undefined;
133
+ const g = own ? new Graphics2D() : plain;
134
+ g.line({ points: run, radius: 0, start: this.start, end: this.end });
135
+ if (!own) {
136
+ drawnPlain = true;
137
+ continue;
138
+ }
139
+ let layers = stroke;
140
+ if (paint)
141
+ layers = layers.map((layer) => ({ ...layer, fill: partPaint(layer.fill, paint) }));
142
+ if (this.directed && from !== to)
143
+ layers = layers.map((layer) => ({ ...layer, endCap: layer.endCap ?? "triangle" }));
144
+ ctx.draw(g.stroke(layers));
145
+ }
146
+ if (drawnPlain)
147
+ ctx.draw(plain.stroke(stroke));
148
+ }
149
+ _drawVertices(ctx, points, parts) {
150
+ const r = this.vertexRadius;
151
+ const fill = this.fill;
152
+ const outline = this.vertexStroke;
153
+ const labels = [];
154
+ for (const [name, p] of points) {
155
+ if (r > 0) {
156
+ const paint = partPaint(fill, parts.get(name));
157
+ const disc = new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 });
158
+ ctx.draw(disc.shadow(this.shadow).fill(paint));
159
+ if (outline.length > 0)
160
+ ctx.draw(new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 }).stroke(outline));
161
+ }
162
+ if (this.labels)
163
+ labels.push({ text: name, at: { x: p.x, y: p.y }, align: "center" });
164
+ }
165
+ for (const part of drawLabels(labels, { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor })) {
166
+ ctx.draw(part);
167
+ }
168
+ }
169
+ /** The vertices drawn: each name once, trimmed, the blank ones left out. */
170
+ _names() {
171
+ return [...new Set(this.vertices.map((name) => name.trim()).filter((name) => name !== ""))];
172
+ }
173
+ /** The edges drawn: both ends named. */
174
+ _links() {
175
+ return this.edges.flatMap(({ from, to }) => {
176
+ const a = from.trim();
177
+ const b = to.trim();
178
+ return a === "" || b === "" ? [] : [{ from: a, to: b }];
179
+ });
180
+ }
181
+ };
182
+ __decorate([
183
+ property({ default: [], mapper: readVertices, animatable: false, kind: "vector" })
184
+ ], NetworkGraph.prototype, "vertices", void 0);
185
+ __decorate([
186
+ property({ default: [], mapper: readEdges, animatable: false, kind: "vector" })
187
+ ], NetworkGraph.prototype, "edges", void 0);
188
+ __decorate([
189
+ property({ default: false, animatable: false })
190
+ ], NetworkGraph.prototype, "directed", void 0);
191
+ __decorate([
192
+ property({ default: "circular", options: GRAPH_LAYOUTS, animatable: false })
193
+ ], NetworkGraph.prototype, "arrangement", void 0);
194
+ __decorate([
195
+ property({ default: "", animatable: false })
196
+ ], NetworkGraph.prototype, "root", void 0);
197
+ __decorate([
198
+ property({ default: [], mapper: readPositions, animatable: false, kind: "vector" })
199
+ ], NetworkGraph.prototype, "positions", void 0);
200
+ __decorate([
201
+ property({ default: 18, min: 0, unit: "px" })
202
+ ], NetworkGraph.prototype, "vertexRadius", void 0);
203
+ __decorate([
204
+ strokeProperty({ default: [] })
205
+ ], NetworkGraph.prototype, "vertexStroke", void 0);
206
+ __decorate([
207
+ property({ default: true, animatable: false })
208
+ ], NetworkGraph.prototype, "labels", void 0);
209
+ __decorate([
210
+ property({ default: 18, min: 1, unit: "px" })
211
+ ], NetworkGraph.prototype, "labelSize", void 0);
212
+ __decorate([
213
+ colorProperty({ default: "#111827" })
214
+ ], NetworkGraph.prototype, "labelColor", void 0);
215
+ __decorate([
216
+ property({ default: "", animatable: false })
217
+ ], NetworkGraph.prototype, "fontFamily", void 0);
218
+ __decorate([
219
+ property({ default: [], mapper: readPartFills, tween: lerpPartFills, kind: "vector" })
220
+ ], NetworkGraph.prototype, "partFills", void 0);
221
+ __decorate([
222
+ fillProperty({ default: "#e5e7eb" })
223
+ ], NetworkGraph.prototype, "fill", void 0);
224
+ __decorate([
225
+ strokeProperty({ default: { weight: 3, fill: "#9ca3af", align: "center", cap: "round" } })
226
+ ], NetworkGraph.prototype, "stroke", void 0);
227
+ __decorate([
228
+ command({ args: ["arrangement"] })
229
+ ], NetworkGraph.prototype, "arrangeTo", null);
230
+ __decorate([
231
+ command({
232
+ args: [
233
+ { key: "part", kind: "text", default: "" },
234
+ { key: "fill", kind: "fills", default: "#facc15" },
235
+ ],
236
+ })
237
+ ], NetworkGraph.prototype, "partFillTo", null);
238
+ NetworkGraph = __decorate([
239
+ node({
240
+ key: "networkGraph",
241
+ parentKey: "shape",
242
+ forkable: true,
243
+ layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: false },
244
+ seed: {
245
+ width: 560,
246
+ height: 400,
247
+ vertices: ["1", "2", "3", "4", "5"],
248
+ edges: [{ from: "1", to: "2" }, { from: "2", to: "3" }, { from: "3", to: "4" }, { from: "4", to: "5" }, { from: "5", to: "1" }, { from: "1", to: "3" }],
249
+ },
250
+ })
251
+ ], NetworkGraph);
252
+ export { NetworkGraph };
253
+ /** An edge from one vertex's rim to the other's, straight or bowed to its left. */
254
+ function edge(a, b, r, bow) {
255
+ const dx = b.x - a.x;
256
+ const dy = b.y - a.y;
257
+ const length = Math.hypot(dx, dy);
258
+ if (!(length > 2 * r))
259
+ return [];
260
+ if (bow === 0) {
261
+ const ux = dx / length;
262
+ const uy = dy / length;
263
+ return [{ x: a.x + ux * r, y: a.y + uy * r }, { x: b.x - ux * r, y: b.y - uy * r }];
264
+ }
265
+ const mid = { x: (a.x + b.x) / 2 - (dy / length) * bow * length, y: (a.y + b.y) / 2 + (dx / length) * bow * length };
266
+ const run = [];
267
+ for (let i = 0; i <= 16; i++) {
268
+ const t = i / 16;
269
+ const u = 1 - t;
270
+ run.push({ x: u * u * a.x + 2 * u * t * mid.x + t * t * b.x, y: u * u * a.y + 2 * u * t * mid.y + t * t * b.y });
271
+ }
272
+ // Trimmed back to the rims along the curve.
273
+ const outside = (p, c) => Math.hypot(p.x - c.x, p.y - c.y) >= r;
274
+ return run.filter((p) => outside(p, a) && outside(p, b));
275
+ }
276
+ /** An edge from a vertex to itself: a small loop above it. */
277
+ function loop(c, r) {
278
+ const run = [];
279
+ const radius = Math.max(r * 0.8, 6);
280
+ const cy = c.y + r + radius * 0.6;
281
+ for (let i = 0; i <= 24; i++) {
282
+ const angle = -Math.PI / 2 + (2 * Math.PI * i) / 24;
283
+ const p = { x: c.x + Math.cos(angle) * radius, y: cy + Math.sin(angle) * radius };
284
+ if (Math.hypot(p.x - c.x, p.y - c.y) >= r)
285
+ run.push(p);
286
+ }
287
+ return run;
288
+ }
289
+ //# sourceMappingURL=network-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-graph.js","sourceRoot":"","sources":["../../src/structures/network-graph.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,YAAY,EACZ,UAAU,EACV,IAAI,E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AAC,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,8DAA8D;AAC9D,SAAS,IAAI,CAAC,CAAU,EAAE,CAAS;IAC/B,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,GAAG,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACpD,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC;QAClF,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\r\n colorProperty,\r\n command,\r\n fillProperty,\r\n Graphics2D,\r\n node,\r\n PaintNode,\r\n property,\r\n strokeProperty,\r\n type AssetScope,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { declareFormulas, drawLabels, type Label } from \"../kit/furniture\";\r\nimport { lerpPartFills, partPaint, readPartFills, withPartFill, type PartFill, type PartFillResolved } from \"../kit/part-fills\";\r\nimport { GRAPH_LAYOUTS, layOut, type GraphEdge, type GraphLayout } from \"./graph-layout\";\r\n\r\n/** A vertex placed by hand, in the graph's box from -1 to 1 each way, y up. */\r\nexport interface GraphPosition {\r\n vertex: string;\r\n x: number;\r\n y: number;\r\n}\r\n\r\nexport interface NetworkGraphProps extends PaintProps {\r\n vertices?: string[];\r\n edges?: GraphEdge[];\r\n directed?: boolean;\r\n arrangement?: GraphLayout;\r\n root?: string;\r\n positions?: GraphPosition[];\r\n vertexRadius?: number;\r\n vertexStroke?: Stroke;\r\n labels?: boolean;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n partFills?: PartFill[];\r\n}\r\n\r\n// Every list keeps each entry as it was written, a blank or a repeat included, so\r\n// an editor showing the list shows the row it just added. What is drawn skips\r\n// what is not complete yet (`_names`, `_links`).\r\n\r\nfunction readVertices(value: readonly unknown[] | undefined): string[] {\r\n return (Array.isArray(value) ? value : []).map((name) => String(name ?? \"\"));\r\n}\r\n\r\n// An edge reads from `{ from, to }` or a pair, so a list written by hand is as good as one from a table.\r\nfunction readEdges(value: readonly unknown[] | undefined): GraphEdge[] {\r\n return (Array.isArray(value) ? value : []).map((edge) => {\r\n const [from, to] = Array.isArray(edge) ? edge : [(edge as GraphEdge)?.from, (edge as GraphEdge)?.to];\r\n return { from: String(from ?? \"\"), to: String(to ?? \"\") };\r\n });\r\n}\r\n\r\nfunction readPositions(value: readonly GraphPosition[] | undefined): GraphPosition[] {\r\n const at = (n: unknown) => (typeof n === \"number\" && Number.isFinite(n) ? n : 0);\r\n return (Array.isArray(value) ? value : []).map((entry) => ({ vertex: String(entry?.vertex ?? \"\"), x: at(entry?.x), y: at(entry?.y) }));\r\n}\r\n\r\n/** How far a directed edge and the one back between the same two vertices bow apart, as a share of their length. */\r\nconst BOW = 0.12;\r\n\r\n/**\r\n * Vertices and the edges between them, arranged by a rule: in a circle, by\r\n * springs, as a tree from `root`, or in a grid. Its `fill` is the vertices and\r\n * its `stroke` the edges, with an arrowhead each when `directed`. `arrangeTo`\r\n * moves every vertex to where another rule places it; `partFillTo` paints a\r\n * vertex, or an edge written `a-b`. (`layout` is every node's own box.)\r\n */\r\n@node({\r\n key: \"networkGraph\",\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: false },\r\n seed: {\r\n width: 560,\r\n height: 400,\r\n vertices: [\"1\", \"2\", \"3\", \"4\", \"5\"],\r\n edges: [{ from: \"1\", to: \"2\" }, { from: \"2\", to: \"3\" }, { from: \"3\", to: \"4\" }, { from: \"4\", to: \"5\" }, { from: \"5\", to: \"1\" }, { from: \"1\", to: \"3\" }],\r\n },\r\n})\r\nexport class NetworkGraph extends PaintNode<NetworkGraphProps> {\r\n @property({ default: [], mapper: readVertices, animatable: false, kind: \"vector\" }) declare vertices: string[];\r\n @property({ default: [], mapper: readEdges, animatable: false, kind: \"vector\" }) declare edges: GraphEdge[];\r\n /** Draw each edge as an arrow from its `from` to its `to`. */\r\n @property({ default: false, animatable: false }) declare directed: boolean;\r\n @property({ default: \"circular\", options: GRAPH_LAYOUTS, animatable: false }) declare arrangement: GraphLayout;\r\n /** The vertex a tree hangs from; left empty, the first. */\r\n @property({ default: \"\", animatable: false }) declare root: string;\r\n /** Vertices placed by hand, whatever the layout says, in the box from -1 to 1 each way. */\r\n @property({ default: [], mapper: readPositions, animatable: false, kind: \"vector\" }) declare positions: GraphPosition[];\r\n\r\n @property({ default: 18, min: 0, unit: \"px\" }) declare vertexRadius: number;\r\n @strokeProperty({ default: [] }) declare vertexStroke: Stroke;\r\n @property({ default: true, animatable: false }) declare labels: boolean;\r\n @property({ default: 18, min: 1, unit: \"px\" }) declare labelSize: number;\r\n @colorProperty({ default: \"#111827\" }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n /** Paints for a vertex by its name, or an edge written `a-b`, over the graph's own. */\r\n @property({ default: [], mapper: readPartFills, tween: lerpPartFills, kind: \"vector\" }) declare partFills: PartFill[];\r\n\r\n @fillProperty({ default: \"#e5e7eb\" }) declare fill: Fill;\r\n @strokeProperty({ default: { weight: 3, fill: \"#9ca3af\", align: \"center\", cap: \"round\" } }) declare stroke: Stroke;\r\n\r\n declare private _layoutFrom: string;\r\n declare private _layoutMix: number;\r\n\r\n constructor(props?: NodeConfig<NetworkGraph, NetworkGraphProps>) {\r\n super(props ?? {});\r\n this.applyProp(\"_layoutFrom\", \"\");\r\n this.applyProp(\"_layoutMix\", 1);\r\n }\r\n\r\n /** Move every vertex to where another arrangement places it. */\r\n @command({ args: [\"arrangement\"] })\r\n arrangeTo(args: CommandArgs<{ arrangement: GraphLayout }> & { duration: number }): Command<NetworkGraphProps> {\r\n const from = this.arrangement;\r\n const to = args.data?.arrangement ?? from;\r\n return this.command<NetworkGraphProps>(\r\n (t) => ({ arrangement: to, _layoutFrom: from, _layoutMix: t }) as Partial<NetworkGraphProps>,\r\n args.duration,\r\n args.easing,\r\n );\r\n }\r\n\r\n /** Paint one part of the graph: a vertex by its name, or an edge written `a-b`. */\r\n @command({\r\n args: [\r\n { key: \"part\", kind: \"text\", default: \"\" },\r\n { key: \"fill\", kind: \"fills\", default: \"#facc15\" },\r\n ],\r\n })\r\n partFillTo(args: CommandArgs<{ part: string; fill: Fill }> & { duration: number }): Command<NetworkGraphProps> {\r\n const { part, fill } = args.data ?? {};\r\n if (!part || fill == null) return this.to({ data: {}, duration: args.duration, easing: args.easing });\r\n return this.to({\r\n data: { partFills: withPartFill(this.partFills as unknown as PartFillResolved[], { part, fill }) } as Partial<NetworkGraphProps>,\r\n duration: args.duration,\r\n easing: args.easing,\r\n });\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n if (this.labels) declareFormulas(assets, this._names());\r\n }\r\n\r\n /** Where each vertex is drawn, in pixels from the node's centre, y up. */\r\n vertexPoints(): Map<string, Vector2> {\r\n const { width, height } = this.layoutBounds;\r\n const room = this.vertexRadius + Math.max(2, this.labelSize * 0.2);\r\n const halfX = Math.max(0, width / 2 - room);\r\n const halfY = Math.max(0, height / 2 - room);\r\n const to = this._placed(this.arrangement);\r\n const from = this._layoutMix < 1 && this._layoutFrom !== \"\" ? this._placed(this._layoutFrom as GraphLayout) : null;\r\n const t = this._layoutMix;\r\n const out = new Map<string, Vector2>();\r\n for (const [name, p] of to) {\r\n const q = from?.get(name) ?? p;\r\n out.set(name, { x: (q.x + (p.x - q.x) * t) * halfX, y: (q.y + (p.y - q.y) * t) * halfY });\r\n }\r\n return out;\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n const points = this.vertexPoints();\r\n if (points.size === 0) return;\r\n const parts = new Map((this.partFills as unknown as PartFillResolved[]).map((entry) => [entry.part, entry]));\r\n this._drawEdges(ctx, points, parts);\r\n this._drawVertices(ctx, points, parts);\r\n }\r\n\r\n // The edges are drawn under the vertices, in `renderSelf`; there is no outline of the node's own.\r\n protected override renderStroke(): void {}\r\n\r\n private _layouts = new Map<string, Map<string, Vector2>>();\r\n\r\n /** Each vertex's place under `layout`, from -1 to 1, a hand-placed one where it is. */\r\n private _placed(layout: GraphLayout): Map<string, Vector2> {\r\n const vertices = this._names();\r\n const edges = this._links();\r\n const key = [layout, this.root, vertices.join(\"\\u0000\"), JSON.stringify(edges), JSON.stringify(this.positions)].join(\"|\");\r\n let placed = this._layouts.get(key);\r\n if (!placed) {\r\n placed = layOut(layout, vertices, edges, this.root.trim());\r\n for (const { vertex, x, y } of this.positions) {\r\n const name = vertex.trim();\r\n if (placed.has(name)) placed.set(name, { x, y });\r\n }\r\n // Two layouts are held at once while one becomes the other.\r\n if (this._layouts.size > 4) this._layouts.clear();\r\n this._layouts.set(key, placed);\r\n }\r\n return placed;\r\n }\r\n\r\n private _drawEdges(ctx: RenderContext2D, points: Map<string, Vector2>, parts: Map<string, PartFillResolved>): void {\r\n const stroke = this.stroke as StrokeResolved[];\r\n if (stroke.length === 0) return;\r\n const r = this.vertexRadius;\r\n const links = this._links();\r\n const pairs = new Set(links.map(({ from, to }) => `${from}\\u0000${to}`));\r\n const plain = new Graphics2D();\r\n let drawnPlain = false;\r\n for (const { from, to } of links) {\r\n const a = points.get(from);\r\n const b = points.get(to);\r\n if (!a || !b) continue;\r\n const run = from === to ? loop(a, r) : edge(a, b, r, this.directed && pairs.has(`${to}\\u0000${from}`) ? BOW : 0);\r\n if (run.length < 2) continue;\r\n const paint = parts.get(`${from}-${to}`) ?? (this.directed ? undefined : parts.get(`${to}-${from}`));\r\n const own = this.directed || paint !== undefined;\r\n const g = own ? new Graphics2D() : plain;\r\n g.line({ points: run, radius: 0, start: this.start, end: this.end });\r\n if (!own) {\r\n drawnPlain = true;\r\n continue;\r\n }\r\n let layers = stroke;\r\n if (paint) layers = layers.map((layer) => ({ ...layer, fill: partPaint(layer.fill, paint) }));\r\n if (this.directed && from !== to) layers = layers.map((layer) => ({ ...layer, endCap: layer.endCap ?? \"triangle\" }));\r\n ctx.draw(g.stroke(layers));\r\n }\r\n if (drawnPlain) ctx.draw(plain.stroke(stroke));\r\n }\r\n\r\n private _drawVertices(ctx: RenderContext2D, points: Map<string, Vector2>, parts: Map<string, PartFillResolved>): void {\r\n const r = this.vertexRadius;\r\n const fill = this.fill as FillResolved[];\r\n const outline = this.vertexStroke as StrokeResolved[];\r\n const labels: Label[] = [];\r\n for (const [name, p] of points) {\r\n if (r > 0) {\r\n const paint = partPaint(fill, parts.get(name));\r\n const disc = new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 });\r\n ctx.draw(disc.shadow(this.shadow).fill(paint));\r\n if (outline.length > 0) ctx.draw(new Graphics2D().ellipse({ x: p.x, y: p.y, width: r * 2, height: r * 2 }).stroke(outline));\r\n }\r\n if (this.labels) labels.push({ text: name, at: { x: p.x, y: p.y }, align: \"center\" });\r\n }\r\n for (const part of drawLabels(labels, { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor })) {\r\n ctx.draw(part);\r\n }\r\n }\r\n\r\n /** The vertices drawn: each name once, trimmed, the blank ones left out. */\r\n private _names(): string[] {\r\n return [...new Set(this.vertices.map((name) => name.trim()).filter((name) => name !== \"\"))];\r\n }\r\n\r\n /** The edges drawn: both ends named. */\r\n private _links(): GraphEdge[] {\r\n return this.edges.flatMap(({ from, to }) => {\r\n const a = from.trim();\r\n const b = to.trim();\r\n return a === \"\" || b === \"\" ? [] : [{ from: a, to: b }];\r\n });\r\n }\r\n}\r\n\r\n/** An edge from one vertex's rim to the other's, straight or bowed to its left. */\r\nfunction edge(a: Vector2, b: Vector2, r: number, bow: number): Vector2[] {\r\n const dx = b.x - a.x;\r\n const dy = b.y - a.y;\r\n const length = Math.hypot(dx, dy);\r\n if (!(length > 2 * r)) return [];\r\n if (bow === 0) {\r\n const ux = dx / length;\r\n const uy = dy / length;\r\n return [{ x: a.x + ux * r, y: a.y + uy * r }, { x: b.x - ux * r, y: b.y - uy * r }];\r\n }\r\n const mid = { x: (a.x + b.x) / 2 - (dy / length) * bow * length, y: (a.y + b.y) / 2 + (dx / length) * bow * length };\r\n const run: Vector2[] = [];\r\n for (let i = 0; i <= 16; i++) {\r\n const t = i / 16;\r\n const u = 1 - t;\r\n run.push({ x: u * u * a.x + 2 * u * t * mid.x + t * t * b.x, y: u * u * a.y + 2 * u * t * mid.y + t * t * b.y });\r\n }\r\n // Trimmed back to the rims along the curve.\r\n const outside = (p: Vector2, c: Vector2) => Math.hypot(p.x - c.x, p.y - c.y) >= r;\r\n return run.filter((p) => outside(p, a) && outside(p, b));\r\n}\r\n\r\n/** An edge from a vertex to itself: a small loop above it. */\r\nfunction loop(c: Vector2, r: number): Vector2[] {\r\n const run: Vector2[] = [];\r\n const radius = Math.max(r * 0.8, 6);\r\n const cy = c.y + r + radius * 0.6;\r\n for (let i = 0; i <= 24; i++) {\r\n const angle = -Math.PI / 2 + (2 * Math.PI * i) / 24;\r\n const p = { x: c.x + Math.cos(angle) * radius, y: cy + Math.sin(angle) * radius };\r\n if (Math.hypot(p.x - c.x, p.y - c.y) >= r) run.push(p);\r\n }\r\n return run;\r\n}\r\n"]}
@@ -0,0 +1,62 @@
1
+ import { PaintNode, type AssetScope, type Color, type Command, type CommandArgs, type Fill, type NodeConfig, type PaintProps, type RenderContext2D, type Stroke } from "@motionscript/sdk";
2
+ export interface SampleSpaceProps extends PaintProps {
3
+ columnShares?: number[];
4
+ rowShares?: number[];
5
+ columnFills?: Fill[];
6
+ columnLabels?: string[];
7
+ rowLabels?: string[];
8
+ values?: boolean;
9
+ labelSize?: number;
10
+ labelColor?: Color;
11
+ fontFamily?: string;
12
+ }
13
+ /**
14
+ * A probability's whole, as a box cut into columns by `columnShares` (shares of
15
+ * the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry
16
+ * (P(B | A) above, the rest below): each part's area is its probability.
17
+ * Braces name the columns below and the rows on the left; `divideTo` moves the
18
+ * cuts.
19
+ */
20
+ export declare class SampleSpace extends PaintNode<SampleSpaceProps> {
21
+ /** How the whole is shared across, left to right; any numbers, read as shares of their sum. */
22
+ columnShares: number[];
23
+ /** Each column's upper share, 0 to 1; a column without one is not cut across. */
24
+ rowShares: number[];
25
+ /** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */
26
+ columnFills: Fill[];
27
+ columnLabels: string[];
28
+ /** The upper part's name and the lower's, written on the left. */
29
+ rowLabels: string[];
30
+ /** Write each part's probability in it. */
31
+ values: boolean;
32
+ labelSize: number;
33
+ labelColor: Color;
34
+ fontFamily: string;
35
+ stroke: Stroke;
36
+ constructor(props?: NodeConfig<SampleSpace, SampleSpaceProps>);
37
+ /** Move the cuts: the columns' shares, each column's upper share, or both. */
38
+ divideTo(args: CommandArgs<{
39
+ columnShares?: number[];
40
+ rowShares?: number[];
41
+ }> & {
42
+ duration: number;
43
+ }): Command<SampleSpaceProps>;
44
+ declareAssets(assets: AssetScope): void;
45
+ /** Each part's box in pixels from the node's centre, y up, and its probability: columns left to right, upper part first. */
46
+ parts(): {
47
+ x: number;
48
+ y: number;
49
+ width: number;
50
+ height: number;
51
+ probability: number;
52
+ column: number;
53
+ upper: boolean;
54
+ }[];
55
+ protected renderSelf(ctx: RenderContext2D): void;
56
+ protected renderStroke(): void;
57
+ /** Room for the braces and their names, below and on the left, taken from the box. */
58
+ private _box;
59
+ /** Braces under each column and beside the first column's parts, and the labels that name them. */
60
+ private _braces;
61
+ }
62
+ //# sourceMappingURL=sample-space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-space.d.ts","sourceRoot":"","sources":["../../src/structures/sample-space.ts"],"names":[],"mappings":"AAAA,OAAO,EAMH,SAAS,EAIT,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,IAAI,EAET,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,MAAM,EAGd,MAAM,mBAAmB,CAAC;AAO3B,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,IAAI,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CA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CAAC,OAAO;CAqClB"}
@@ -0,0 +1,199 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { colorProperty, command, fillOps, Graphics2D, node, PaintNode, property, strokeProperty, withdraw, } from "@motionscript/sdk";
8
+ import { braceOutline } from "../kit/brace.js";
9
+ import { declareFormulas, drawLabels } from "../kit/furniture.js";
10
+ import { lerpFillScale, readFillScale } from "../kit/scale.js";
11
+ import { formatTick } from "../kit/ticks.js";
12
+ import { FILL_PAINT, OUTLINE_TRIM } from "../kit/withdrawn.js";
13
+ /** The parts' paints until told otherwise, a column each, round again past the last. */
14
+ const PALETTE = ["#58a6ff", "#f59e0b", "#4ade80", "#f472b6", "#a78bfa", "#2dd4bf"];
15
+ /** How strongly the lower part of a split column shows its paint. */
16
+ const LOWER = 0.45;
17
+ function readShares(value) {
18
+ return (Array.isArray(value) ? value : []).map((share) => (Number.isFinite(share) && share > 0 ? share : 0));
19
+ }
20
+ // Shares tween one by one; a different count has nothing to pair with, and changes at the end.
21
+ function lerpShares(from, to, t) {
22
+ if (from.length !== to.length)
23
+ return t < 1 ? from : to;
24
+ return to.map((share, i) => from[i] + (share - from[i]) * t);
25
+ }
26
+ /**
27
+ * A probability's whole, as a box cut into columns by `columnShares` (shares of
28
+ * the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry
29
+ * (P(B | A) above, the rest below): each part's area is its probability.
30
+ * Braces name the columns below and the rows on the left; `divideTo` moves the
31
+ * cuts.
32
+ */
33
+ let SampleSpace = class SampleSpace extends PaintNode {
34
+ constructor(props) {
35
+ super(props ?? {});
36
+ }
37
+ /** Move the cuts: the columns' shares, each column's upper share, or both. */
38
+ divideTo(args) {
39
+ const data = {};
40
+ if (args.data?.columnShares !== undefined)
41
+ data.columnShares = args.data.columnShares;
42
+ if (args.data?.rowShares !== undefined)
43
+ data.rowShares = args.data.rowShares;
44
+ return this.to({ data, duration: args.duration, easing: args.easing });
45
+ }
46
+ declareAssets(assets) {
47
+ super.declareAssets(assets);
48
+ if (this.fontFamily !== "")
49
+ assets.font(this.fontFamily);
50
+ declareFormulas(assets, [...this.columnLabels, ...this.rowLabels]);
51
+ }
52
+ /** Each part's box in pixels from the node's centre, y up, and its probability: columns left to right, upper part first. */
53
+ parts() {
54
+ const box = this._box();
55
+ const shares = this.columnShares;
56
+ const total = shares.reduce((sum, share) => sum + share, 0);
57
+ if (!(total > 0) || box.width <= 0 || box.height <= 0)
58
+ return [];
59
+ const out = [];
60
+ let left = box.x - box.width / 2;
61
+ shares.forEach((share, column) => {
62
+ const width = (box.width * share) / total;
63
+ const p = share / total;
64
+ const cut = this.rowShares[column];
65
+ const top = box.y + box.height / 2;
66
+ if (cut === undefined) {
67
+ out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });
68
+ }
69
+ else {
70
+ const upper = Math.min(1, Math.max(0, cut));
71
+ const h = box.height * upper;
72
+ out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });
73
+ out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });
74
+ }
75
+ left += width;
76
+ });
77
+ return out;
78
+ }
79
+ renderSelf(ctx) {
80
+ const parts = this.parts();
81
+ if (parts.length === 0)
82
+ return;
83
+ const fills = this.columnFills;
84
+ const stroke = this.stroke;
85
+ const labels = [];
86
+ for (const part of parts) {
87
+ if (!(part.width > 0) || !(part.height > 0))
88
+ continue;
89
+ const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);
90
+ const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));
91
+ const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });
92
+ ctx.draw(g.shadow(this.shadow).fill(paint));
93
+ if (stroke.length > 0)
94
+ ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));
95
+ if (this.values && part.height > this.labelSize && part.width > this.labelSize) {
96
+ labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: "center" });
97
+ }
98
+ }
99
+ labels.push(...this._braces(ctx, parts));
100
+ const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor };
101
+ for (const part of drawLabels(labels, style))
102
+ ctx.draw(part);
103
+ }
104
+ // The outlines are drawn with the parts, and there is no outline of the node's own.
105
+ renderStroke() { }
106
+ /** Room for the braces and their names, below and on the left, taken from the box. */
107
+ _box() {
108
+ const { width, height } = this.layoutBounds;
109
+ const room = this.labelSize * 2.6;
110
+ const below = this.columnLabels.some((label) => label !== "") ? room : 0;
111
+ const left = this.rowLabels.some((label) => label !== "") ? room * 1.6 : 0;
112
+ return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };
113
+ }
114
+ /** Braces under each column and beside the first column's parts, and the labels that name them. */
115
+ _braces(ctx, parts) {
116
+ const box = this._box();
117
+ const reach = this.labelSize * 0.8;
118
+ const gap = 6;
119
+ const runs = new Graphics2D();
120
+ const labels = [];
121
+ let drawn = false;
122
+ const brace = (from, to, out, text, align) => {
123
+ if (text === "")
124
+ return;
125
+ // A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.
126
+ runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });
127
+ drawn = true;
128
+ const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
129
+ const far = reach + this.labelSize * 0.75;
130
+ labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });
131
+ };
132
+ const bottom = box.y - box.height / 2 - gap;
133
+ for (const part of parts) {
134
+ if (!part.upper && this.rowShares[part.column] !== undefined)
135
+ continue;
136
+ const text = this.columnLabels[part.column] ?? "";
137
+ // Left to right along the bottom, so the bulge, to the edge's right, points down.
138
+ brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, "center");
139
+ }
140
+ const first = parts.filter((part) => part.column === 0);
141
+ const left = box.x - box.width / 2 - gap;
142
+ if (this.rowShares[0] !== undefined) {
143
+ first.forEach((part) => {
144
+ const text = this.rowLabels[part.upper ? 0 : 1] ?? "";
145
+ brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, "right");
146
+ });
147
+ }
148
+ if (drawn) {
149
+ const fill = fillOps.resolve({ type: "solid", color: this.labelColor });
150
+ ctx.draw(runs.stroke({ weight: 2, fill, align: "center", cap: "round", join: "round" }));
151
+ }
152
+ return labels;
153
+ }
154
+ };
155
+ __decorate([
156
+ property({ default: [1], mapper: readShares, tween: lerpShares, kind: "vector" })
157
+ ], SampleSpace.prototype, "columnShares", void 0);
158
+ __decorate([
159
+ property({ default: [], mapper: readShares, tween: lerpShares, kind: "vector" })
160
+ ], SampleSpace.prototype, "rowShares", void 0);
161
+ __decorate([
162
+ property({ default: [], mapper: readFillScale, tween: lerpFillScale, kind: "vector" })
163
+ ], SampleSpace.prototype, "columnFills", void 0);
164
+ __decorate([
165
+ property({ default: [], animatable: false, kind: "vector" })
166
+ ], SampleSpace.prototype, "columnLabels", void 0);
167
+ __decorate([
168
+ property({ default: [], animatable: false, kind: "vector" })
169
+ ], SampleSpace.prototype, "rowLabels", void 0);
170
+ __decorate([
171
+ property({ default: false, animatable: false })
172
+ ], SampleSpace.prototype, "values", void 0);
173
+ __decorate([
174
+ property({ default: 20, min: 1, unit: "px" })
175
+ ], SampleSpace.prototype, "labelSize", void 0);
176
+ __decorate([
177
+ colorProperty({ default: "#e5e7eb" })
178
+ ], SampleSpace.prototype, "labelColor", void 0);
179
+ __decorate([
180
+ property({ default: "", animatable: false })
181
+ ], SampleSpace.prototype, "fontFamily", void 0);
182
+ __decorate([
183
+ strokeProperty({ default: { weight: 2, fill: "#0b0d12", align: "center" } })
184
+ ], SampleSpace.prototype, "stroke", void 0);
185
+ __decorate([
186
+ command({ args: ["columnShares", "rowShares"] })
187
+ ], SampleSpace.prototype, "divideTo", null);
188
+ SampleSpace = __decorate([
189
+ node({
190
+ key: "sampleSpace",
191
+ parentKey: "shape",
192
+ forkable: true,
193
+ layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: false },
194
+ seed: { width: 520, height: 420, columnShares: [0.4, 0.6], rowShares: [0.7, 0.25], columnLabels: ["A", "not A"], rowLabels: ["B", "not B"] },
195
+ }),
196
+ withdraw(...FILL_PAINT, ...OUTLINE_TRIM)
197
+ ], SampleSpace);
198
+ export { SampleSpace };
199
+ //# sourceMappingURL=sample-space.js.map