@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.6

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 (233) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +39 -33
  3. package/dist/annotate/angle-mark.d.ts +52 -27
  4. package/dist/annotate/angle-mark.d.ts.map +1 -1
  5. package/dist/annotate/angle-mark.js +80 -115
  6. package/dist/annotate/angle-mark.js.map +1 -1
  7. package/dist/annotate/curly-brace.d.ts +59 -25
  8. package/dist/annotate/curly-brace.d.ts.map +1 -1
  9. package/dist/annotate/curly-brace.js +85 -100
  10. package/dist/annotate/curly-brace.js.map +1 -1
  11. package/dist/annotate/emphasis-mark.d.ts +43 -9
  12. package/dist/annotate/emphasis-mark.d.ts.map +1 -1
  13. package/dist/annotate/emphasis-mark.js +33 -34
  14. package/dist/annotate/emphasis-mark.js.map +1 -1
  15. package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
  16. package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
  17. package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
  18. package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
  19. package/dist/browser/index.js +1 -1
  20. package/dist/browser/index.js.map +3 -3
  21. package/dist/browser/kit.js +1 -1
  22. package/dist/browser/manifest.json +1 -1
  23. package/dist/browser/tex.js +1 -1
  24. package/dist/browser/tex.js.map +2 -2
  25. package/dist/engine.d.ts +26 -19
  26. package/dist/engine.d.ts.map +1 -1
  27. package/dist/engine.js +17 -14
  28. package/dist/engine.js.map +1 -1
  29. package/dist/kit/component.d.ts +51 -0
  30. package/dist/kit/component.d.ts.map +1 -0
  31. package/dist/kit/component.js +30 -0
  32. package/dist/kit/component.js.map +1 -0
  33. package/dist/kit/curve.d.ts +22 -11
  34. package/dist/kit/curve.d.ts.map +1 -1
  35. package/dist/kit/curve.js +25 -18
  36. package/dist/kit/curve.js.map +1 -1
  37. package/dist/kit/field-mark.d.ts +58 -35
  38. package/dist/kit/field-mark.d.ts.map +1 -1
  39. package/dist/kit/field-mark.js +100 -120
  40. package/dist/kit/field-mark.js.map +1 -1
  41. package/dist/kit/follow.d.ts +67 -29
  42. package/dist/kit/follow.d.ts.map +1 -1
  43. package/dist/kit/follow.js +114 -110
  44. package/dist/kit/follow.js.map +1 -1
  45. package/dist/kit/furniture.d.ts +3 -1
  46. package/dist/kit/furniture.d.ts.map +1 -1
  47. package/dist/kit/furniture.js +5 -0
  48. package/dist/kit/furniture.js.map +1 -1
  49. package/dist/kit/graph.d.ts +46 -0
  50. package/dist/kit/graph.d.ts.map +1 -0
  51. package/dist/kit/graph.js +90 -0
  52. package/dist/kit/graph.js.map +1 -0
  53. package/dist/kit/mark.d.ts +64 -39
  54. package/dist/kit/mark.d.ts.map +1 -1
  55. package/dist/kit/mark.js +80 -96
  56. package/dist/kit/mark.js.map +1 -1
  57. package/dist/kit/place.d.ts +10 -8
  58. package/dist/kit/place.d.ts.map +1 -1
  59. package/dist/kit/place.js +28 -30
  60. package/dist/kit/place.js.map +1 -1
  61. package/dist/kit/system.d.ts +27 -29
  62. package/dist/kit/system.d.ts.map +1 -1
  63. package/dist/kit/system.js +62 -58
  64. package/dist/kit/system.js.map +1 -1
  65. package/dist/kit/withdrawn.d.ts +3 -3
  66. package/dist/kit/withdrawn.js +3 -3
  67. package/dist/kit/withdrawn.js.map +1 -1
  68. package/dist/marks/curve-area.d.ts +24 -18
  69. package/dist/marks/curve-area.d.ts.map +1 -1
  70. package/dist/marks/curve-area.js +50 -73
  71. package/dist/marks/curve-area.js.map +1 -1
  72. package/dist/marks/drop-lines.d.ts +28 -10
  73. package/dist/marks/drop-lines.d.ts.map +1 -1
  74. package/dist/marks/drop-lines.js +37 -52
  75. package/dist/marks/drop-lines.js.map +1 -1
  76. package/dist/marks/plot-point.d.ts +37 -20
  77. package/dist/marks/plot-point.d.ts.map +1 -1
  78. package/dist/marks/plot-point.js +65 -91
  79. package/dist/marks/plot-point.js.map +1 -1
  80. package/dist/marks/riemann-sum.d.ts +30 -26
  81. package/dist/marks/riemann-sum.d.ts.map +1 -1
  82. package/dist/marks/riemann-sum.js +57 -85
  83. package/dist/marks/riemann-sum.js.map +1 -1
  84. package/dist/marks/tangent-line.d.ts +38 -14
  85. package/dist/marks/tangent-line.d.ts.map +1 -1
  86. package/dist/marks/tangent-line.js +73 -87
  87. package/dist/marks/tangent-line.js.map +1 -1
  88. package/dist/marks/vector-arrow.d.ts +30 -20
  89. package/dist/marks/vector-arrow.d.ts.map +1 -1
  90. package/dist/marks/vector-arrow.js +58 -78
  91. package/dist/marks/vector-arrow.js.map +1 -1
  92. package/dist/nodes.d.ts +13 -5
  93. package/dist/nodes.d.ts.map +1 -1
  94. package/dist/nodes.js +0 -6
  95. package/dist/nodes.js.map +1 -1
  96. package/dist/plots/function-plot.d.ts +107 -43
  97. package/dist/plots/function-plot.d.ts.map +1 -1
  98. package/dist/plots/function-plot.js +146 -177
  99. package/dist/plots/function-plot.js.map +1 -1
  100. package/dist/plots/points-plot.d.ts +34 -19
  101. package/dist/plots/points-plot.d.ts.map +1 -1
  102. package/dist/plots/points-plot.js +31 -58
  103. package/dist/plots/points-plot.js.map +1 -1
  104. package/dist/plots/stream-lines.d.ts +38 -19
  105. package/dist/plots/stream-lines.d.ts.map +1 -1
  106. package/dist/plots/stream-lines.js +60 -79
  107. package/dist/plots/stream-lines.js.map +1 -1
  108. package/dist/plots/traced-path.d.ts +34 -15
  109. package/dist/plots/traced-path.d.ts.map +1 -1
  110. package/dist/plots/traced-path.js +33 -48
  111. package/dist/plots/traced-path.js.map +1 -1
  112. package/dist/plots/vector-field.d.ts +31 -11
  113. package/dist/plots/vector-field.d.ts.map +1 -1
  114. package/dist/plots/vector-field.js +50 -64
  115. package/dist/plots/vector-field.js.map +1 -1
  116. package/dist/structures/network-graph.d.ts +99 -49
  117. package/dist/structures/network-graph.d.ts.map +1 -1
  118. package/dist/structures/network-graph.js +168 -217
  119. package/dist/structures/network-graph.js.map +1 -1
  120. package/dist/structures/sample-space.d.ts +69 -38
  121. package/dist/structures/sample-space.d.ts.map +1 -1
  122. package/dist/structures/sample-space.js +132 -170
  123. package/dist/structures/sample-space.js.map +1 -1
  124. package/dist/systems/axes2d.d.ts +126 -37
  125. package/dist/systems/axes2d.d.ts.map +1 -1
  126. package/dist/systems/axes2d.js +147 -183
  127. package/dist/systems/axes2d.js.map +1 -1
  128. package/dist/systems/number-line.d.ts +51 -28
  129. package/dist/systems/number-line.d.ts.map +1 -1
  130. package/dist/systems/number-line.js +82 -118
  131. package/dist/systems/number-line.js.map +1 -1
  132. package/dist/systems/number-plane.d.ts +92 -31
  133. package/dist/systems/number-plane.d.ts.map +1 -1
  134. package/dist/systems/number-plane.js +142 -149
  135. package/dist/systems/number-plane.js.map +1 -1
  136. package/dist/systems/polar-plane.d.ts +47 -26
  137. package/dist/systems/polar-plane.d.ts.map +1 -1
  138. package/dist/systems/polar-plane.js +107 -133
  139. package/dist/systems/polar-plane.js.map +1 -1
  140. package/dist/tex/index.d.ts.map +1 -1
  141. package/dist/tex/index.js +1 -0
  142. package/dist/tex/index.js.map +1 -1
  143. package/dist/tex/matrix.d.ts +56 -18
  144. package/dist/tex/matrix.d.ts.map +1 -1
  145. package/dist/tex/matrix.js +33 -50
  146. package/dist/tex/matrix.js.map +1 -1
  147. package/dist/tex/node.d.ts +55 -201
  148. package/dist/tex/node.d.ts.map +1 -1
  149. package/dist/tex/node.js +23 -593
  150. package/dist/tex/node.js.map +1 -1
  151. package/dist/tex/typeset.d.ts +133 -0
  152. package/dist/tex/typeset.d.ts.map +1 -0
  153. package/dist/tex/typeset.js +403 -0
  154. package/dist/tex/typeset.js.map +1 -0
  155. package/dist/three/axes3d.d.ts +140 -54
  156. package/dist/three/axes3d.d.ts.map +1 -1
  157. package/dist/three/axes3d.js +159 -204
  158. package/dist/three/axes3d.js.map +1 -1
  159. package/dist/three/curve-plot3d.d.ts +70 -42
  160. package/dist/three/curve-plot3d.d.ts.map +1 -1
  161. package/dist/three/curve-plot3d.js +97 -132
  162. package/dist/three/curve-plot3d.js.map +1 -1
  163. package/dist/three/entries.d.ts +17 -0
  164. package/dist/three/entries.d.ts.map +1 -0
  165. package/dist/three/entries.js +15 -0
  166. package/dist/three/entries.js.map +1 -0
  167. package/dist/three/plot-point3d.d.ts +57 -12
  168. package/dist/three/plot-point3d.d.ts.map +1 -1
  169. package/dist/three/plot-point3d.js +27 -53
  170. package/dist/three/plot-point3d.js.map +1 -1
  171. package/dist/three/space.d.ts +17 -2
  172. package/dist/three/space.d.ts.map +1 -1
  173. package/dist/three/space.js +19 -8
  174. package/dist/three/space.js.map +1 -1
  175. package/dist/three/surface-plot3d.d.ts +131 -49
  176. package/dist/three/surface-plot3d.d.ts.map +1 -1
  177. package/dist/three/surface-plot3d.js +227 -261
  178. package/dist/three/surface-plot3d.js.map +1 -1
  179. package/dist/three/vector-arrow3d.d.ts +58 -16
  180. package/dist/three/vector-arrow3d.d.ts.map +1 -1
  181. package/dist/three/vector-arrow3d.js +48 -67
  182. package/dist/three/vector-arrow3d.js.map +1 -1
  183. package/package.json +4 -4
  184. package/src/annotate/angle-mark.ts +95 -105
  185. package/src/annotate/curly-brace.ts +107 -85
  186. package/src/annotate/emphasis-mark.ts +55 -26
  187. package/src/engine.ts +35 -21
  188. package/src/kit/component.ts +57 -0
  189. package/src/kit/curve.ts +38 -20
  190. package/src/kit/field-mark.ts +124 -108
  191. package/src/kit/follow.ts +146 -120
  192. package/src/kit/furniture.ts +6 -1
  193. package/src/kit/graph.ts +116 -0
  194. package/src/kit/mark.ts +135 -114
  195. package/src/kit/place.ts +32 -56
  196. package/src/kit/system.ts +77 -71
  197. package/src/kit/withdrawn.ts +3 -3
  198. package/src/marks/curve-area.ts +65 -65
  199. package/src/marks/drop-lines.ts +50 -42
  200. package/src/marks/plot-point.ts +77 -82
  201. package/src/marks/riemann-sum.ts +73 -72
  202. package/src/marks/tangent-line.ts +87 -71
  203. package/src/marks/vector-arrow.ts +73 -73
  204. package/src/nodes.ts +41 -5
  205. package/src/plots/function-plot.ts +155 -171
  206. package/src/plots/points-plot.ts +46 -50
  207. package/src/plots/stream-lines.ts +75 -66
  208. package/src/plots/traced-path.ts +51 -33
  209. package/src/plots/vector-field.ts +68 -49
  210. package/src/structures/network-graph.ts +168 -185
  211. package/src/structures/sample-space.ts +149 -148
  212. package/src/systems/axes2d.ts +165 -156
  213. package/src/systems/number-line.ts +91 -92
  214. package/src/systems/number-plane.ts +149 -120
  215. package/src/systems/polar-plane.ts +117 -116
  216. package/src/tex/index.ts +2 -1
  217. package/src/tex/matrix.ts +62 -40
  218. package/src/tex/node.ts +54 -621
  219. package/src/tex/typeset.ts +461 -0
  220. package/src/three/axes3d.ts +182 -161
  221. package/src/three/curve-plot3d.ts +107 -110
  222. package/src/three/entries.ts +42 -0
  223. package/src/three/plot-point3d.ts +42 -45
  224. package/src/three/space.ts +34 -9
  225. package/src/three/surface-plot3d.ts +312 -323
  226. package/src/three/vector-arrow3d.ts +65 -54
  227. package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
  228. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
  229. package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
  230. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
  231. package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
  232. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
  233. package/src/kit/placement.ts +0 -8
@@ -1,58 +1,43 @@
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 { node, property, strokeProperty, withdraw, } from "@motionscript/sdk";
8
- import { clamp } from "../kit/geometry.js";
9
- import { Mark } from "../kit/mark.js";
10
- import { curveOf } from "../kit/curve.js";
1
+ import { component2d, } from "@motionscript/sdk";
2
+ import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
3
+ import { curveValue } from "../kit/curve.js";
11
4
  import { AXIS_COLOR } from "../kit/furniture.js";
12
- import { SYSTEMS_AND_PLOT } from "../kit/placement.js";
13
- import { FILL_PAINT } from "../kit/withdrawn.js";
5
+ import { clamp } from "../kit/geometry.js";
6
+ import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
7
+ import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
8
+ const state = {
9
+ ...omit(PAINT, "fill"),
10
+ /** A plot to take the point's height from, by id. */
11
+ on: PLOT_REF,
12
+ /** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
13
+ axis: listed(["x", "y", "both"], "both", { animatable: false }),
14
+ graph: PLANE_ENTRY,
15
+ };
14
16
  /**
15
17
  * Guide lines from a graph point to the axes, reading its coordinates off them.
16
18
  * The point is this node's `x`/`y`, or the point of a plot above its `x`.
17
19
  */
18
- let DropLines = class DropLines extends Mark {
19
- constructor(props) {
20
- super(props ?? {});
21
- }
22
- trace(map) {
23
- const x = this.x;
24
- const plot = curveOf(this, this.on);
25
- const y = plot ? plot.valueAt(x) : this.y;
26
- if (!Number.isFinite(y))
27
- return [];
28
- const at = map.toPoint(x, y);
29
- const runs = [];
30
- // Each line starts on its axis, so drawing it on grows it towards the point.
31
- if (this.axis !== "y")
32
- runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);
33
- if (this.axis !== "x")
34
- runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);
35
- return runs;
36
- }
37
- };
38
- __decorate([
39
- property({ default: "", kind: "nodeRef", nodeTypes: ["functionPlot"], animatable: false })
40
- ], DropLines.prototype, "on", void 0);
41
- __decorate([
42
- property({ default: "both", options: ["x", "y", "both"], animatable: false })
43
- ], DropLines.prototype, "axis", void 0);
44
- __decorate([
45
- strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center", dash: [8, 6] } })
46
- ], DropLines.prototype, "stroke", void 0);
47
- DropLines = __decorate([
48
- node({
49
- key: "dropLines",
50
- within: SYSTEMS_AND_PLOT,
51
- parentKey: "shape",
52
- forkable: true,
53
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
54
- }),
55
- withdraw(...FILL_PAINT)
56
- ], DropLines);
57
- export { DropLines };
20
+ export const DropLines = traced(component2d({
21
+ key: "dropLines",
22
+ state,
23
+ defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center", dash: [8, 6] }, width: "hug", height: "hug" },
24
+ commands: omit(PAINT_COMMANDS, "fillTo"),
25
+ measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),
26
+ render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),
27
+ }), traceDrops);
28
+ function traceDrops(s, { map, plane }) {
29
+ const x = s.x;
30
+ const plot = curveFor(plane, s.on);
31
+ const y = plot ? curveValue(plot, x) : s.y;
32
+ if (!Number.isFinite(y))
33
+ return [];
34
+ const at = map.toPoint(x, y);
35
+ const runs = [];
36
+ // Each line starts on its axis, so drawing it on grows it towards the point.
37
+ if (s.axis !== "y")
38
+ runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);
39
+ if (s.axis !== "x")
40
+ runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);
41
+ return runs;
42
+ }
58
43
  //# sourceMappingURL=drop-lines.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"drop-lines.js","sourceRoot":"","sources":["../../src/marks/drop-lines.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,c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ke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"../kit/coords\";\r\nimport { clamp } from \"../kit/geometry\";\r\nimport { Mark } from \"../kit/mark\";\r\nimport { curveOf } from \"../kit/curve\";\r\nimport { AXIS_COLOR } from \"../kit/furniture\";\r\nimport { SYSTEMS_AND_PLOT } from \"../kit/placement\";\r\nimport { FILL_PAINT } from \"../kit/withdrawn\";\r\n\r\nexport type DropAxis = \"x\" | \"y\" | \"both\";\r\n\r\nexport interface DropLinesProps extends PaintProps {\r\n on?: string;\r\n axis?: DropAxis;\r\n}\r\n\r\n/**\r\n * Guide lines from a graph point to the axes, reading its coordinates off them.\r\n * The point is this node's `x`/`y`, or the point of a plot above its `x`.\r\n */\r\n@node({\r\n key: \"dropLines\",\r\n within: SYSTEMS_AND_PLOT,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\n@withdraw(...FILL_PAINT)\r\nexport class DropLines extends Mark<DropLinesProps> {\r\n /** A plot to take the point's height from, by id. */\r\n @property({ default: \"\", kind: \"nodeRef\", nodeTypes: [\"functionPlot\"], animatable: false }) declare on: string;\r\n /** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */\r\n @property({ default: \"both\", options: [\"x\", \"y\", \"both\"], animatable: false }) declare axis: DropAxis;\r\n\r\n @strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: \"center\", dash: [8, 6] } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<DropLines, DropLinesProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const x = this.x;\r\n const plot = curveOf(this, this.on);\r\n const y = plot ? plot.valueAt(x) : this.y;\r\n if (!Number.isFinite(y)) return [];\r\n const at = map.toPoint(x, y);\r\n const runs: Vector2[][] = [];\r\n // Each line starts on its axis, so drawing it on grows it towards the point.\r\n if (this.axis !== \"y\") runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);\r\n if (this.axis !== \"x\") runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);\r\n return runs;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"drop-lines.js","sourceRoot":"","sources":["../../src/marks/drop-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,GAYd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AASnF,MAAM,KAAK,GAAG;IACV,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,EAAE,EAAE,QAAQ;IACZ,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC/D,KAAK,EAAE,WAAW;CACrB,CAAC;AASF;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC;IACxC,GAAG,EAAE,WAAW;IAChB,KAAK;IACL,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CA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AE,EAAE,CAAC,CAAC,CAAC;IAC5F,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5F,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import {\r\n component2d,\r\n type NodeOf,\r\n type NodeView,\r\n type PaintProps,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport { curveValue } from \"../kit/curve\";\r\nimport { AXIS_COLOR } from \"../kit/furniture\";\r\nimport { clamp } from \"../kit/geometry\";\r\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport type DropAxis = \"x\" | \"y\" | \"both\";\r\n\r\nexport interface DropLinesProps extends PaintProps {\r\n on?: string;\r\n axis?: DropAxis;\r\n}\r\n\r\nconst state = {\r\n ...omit(PAINT, \"fill\"),\r\n /** A plot to take the point's height from, by id. */\r\n on: PLOT_REF,\r\n /** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */\r\n axis: listed([\"x\", \"y\", \"both\"], \"both\", { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n};\r\n\r\ninterface DropValues {\r\n readonly x: number;\r\n readonly y: number;\r\n readonly on: NodeView | null;\r\n readonly axis: DropAxis;\r\n}\r\n\r\n/**\r\n * Guide lines from a graph point to the axes, reading its coordinates off them.\r\n * The point is this node's `x`/`y`, or the point of a plot above its `x`.\r\n */\r\nexport const DropLines = traced(component2d({\r\n key: \"dropLines\",\r\n state,\r\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\", dash: [8, 6] }, width: \"hug\", height: \"hug\" },\r\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\r\n measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),\r\n render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),\r\n}), traceDrops);\r\n\r\nexport type DropLines = NodeOf<typeof DropLines>;\r\n\r\nfunction traceDrops(s: DropValues, { map, plane }: MarkReading): Vector2[][] {\r\n const x = s.x;\r\n const plot = curveFor(plane, s.on);\r\n const y = plot ? curveValue(plot, x) : s.y;\r\n if (!Number.isFinite(y)) return [];\r\n const at = map.toPoint(x, y);\r\n const runs: Vector2[][] = [];\r\n // Each line starts on its axis, so drawing it on grows it towards the point.\r\n if (s.axis !== \"y\") runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);\r\n if (s.axis !== \"x\") runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);\r\n return runs;\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
- import { Graphics2D, PaintNode, type AssetScope, type Color, type Fill, type NodeConfig, type PaintProps, type RenderContext2D, type Size2D, type Vector2 } from "@motionscript/sdk";
2
- import type { Anchored } from "../kit/place.js";
1
+ import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
2
+ import { type GraphPlane } from "../kit/graph.js";
3
3
  export interface PlotPointProps extends PaintProps {
4
4
  on?: string;
5
5
  radius?: number;
@@ -13,23 +13,40 @@ export interface PlotPointProps extends PaintProps {
13
13
  * A dot at graph coordinates, with an optional label. Named a plot in `on`, it
14
14
  * rides that curve: its `x` is where along it, and its height is the curve's.
15
15
  */
16
- export declare class PlotPoint extends PaintNode<PlotPointProps> implements Anchored {
16
+ export declare const PlotPoint: import("@motionscript/sdk").Component<"plotPoint", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
17
17
  /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
18
- on: string;
19
- radius: number;
20
- label: string;
21
- labelSide: "above" | "below" | "left" | "right";
22
- labelSize: number;
23
- labelColor: Color;
24
- fontFamily: string;
25
- fill: Fill;
26
- constructor(props?: NodeConfig<PlotPoint, PlotPointProps>);
27
- /** The graph height the point is at: the curve's when it rides one. */
28
- get value(): number;
29
- anchorAt(x: number, y: number): Vector2;
30
- measure(): Partial<Size2D>;
31
- declareAssets(assets: AssetScope): void;
32
- protected shapeGraphics(): Graphics2D | null;
33
- protected renderSelf(ctx: RenderContext2D): void;
34
- }
18
+ on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
19
+ radius: import("@motionscript/sdk").Type<number, number, false>;
20
+ label: import("@motionscript/sdk").Type<string, string, false>;
21
+ labelSide: import("@motionscript/sdk").Type<"left" | "right" | "below" | "above", "left" | "right" | "below" | "above", false>;
22
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
23
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
24
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
25
+ graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
26
+ /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
27
+ value: import("@motionscript/sdk").Type<number, number, true>;
28
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
29
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
30
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
31
+ }>, {
32
+ fillTo: readonly ["fill"];
33
+ strokeTo: readonly ["stroke"];
34
+ shadowTo: readonly ["shadow"];
35
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
36
+ /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
37
+ on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
38
+ radius: import("@motionscript/sdk").Type<number, number, false>;
39
+ label: import("@motionscript/sdk").Type<string, string, false>;
40
+ labelSide: import("@motionscript/sdk").Type<"left" | "right" | "below" | "above", "left" | "right" | "below" | "above", false>;
41
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
42
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
43
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
44
+ graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
45
+ /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
46
+ value: import("@motionscript/sdk").Type<number, number, true>;
47
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
48
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
49
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
50
+ }>, null>>;
51
+ export type PlotPoint = NodeOf<typeof PlotPoint>;
35
52
  //# sourceMappingURL=plot-point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plot-point.d.ts","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,EAEV,SAAS,EAGT,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,IAAI,EACT,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAA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marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,UAAU,EAEf,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAmC,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAIhF,MAAM,WAAW,cAAe,SAAQ,UAAU;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAkBD;;;GAGG;AACH,eAAO,MAAM,SAAS;IAjBlB,wFAAwF;;;;;;;;;IASxF,iHAAiH;;;;;;;;;;IATjH,wFAAwF;;;;;;;;;IASxF,iHAAiH;;;;;UA4CvB,CAAC;AAE/F,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
@@ -1,97 +1,71 @@
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;
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
3
+ import { curveValue } from "../kit/curve.js";
4
+ import { drawLabels, loadFormulas } from "../kit/furniture.js";
5
+ import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
6
+ import { strokeShape } from "../kit/mark.js";
7
+ import { anchored } from "../kit/place.js";
8
+ const state = {
9
+ // A dot has no outline worth trimming.
10
+ ...omit(PAINT, "start", "end"),
11
+ /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
12
+ on: PLOT_REF,
13
+ radius: Types.number(7, { min: 0, unit: "px" }),
14
+ label: Types.text("", { animatable: false }),
15
+ labelSide: listed(["above", "below", "left", "right"], "above", { animatable: false }),
16
+ labelSize: Types.number(18, { min: 1, unit: "px" }),
17
+ labelColor: Types.color("#e5e7eb"),
18
+ fontFamily: Types.text("", { animatable: false }),
19
+ graph: PLANE_ENTRY,
20
+ /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
21
+ value: Types.number(0, { private: true }),
6
22
  };
7
- import { colorProperty, fillProperty, Graphics2D, node, PaintNode, property, withdraw, } from "@motionscript/sdk";
8
- import { curveOf } from "../kit/curve.js";
9
- import { declareFormulas, drawLabels } from "../kit/furniture.js";
10
- import { SYSTEMS_AND_PLOT } from "../kit/placement.js";
11
- import { OUTLINE_TRIM } from "../kit/withdrawn.js";
12
23
  /**
13
24
  * A dot at graph coordinates, with an optional label. Named a plot in `on`, it
14
25
  * rides that curve: its `x` is where along it, and its height is the curve's.
15
26
  */
16
- let PlotPoint = class PlotPoint extends PaintNode {
17
- constructor(props) {
18
- super(props ?? {});
19
- }
20
- /** The graph height the point is at: the curve's when it rides one. */
21
- get value() {
22
- return this.anchorAt(this.x, this.y).y;
23
- }
24
- anchorAt(x, y) {
25
- const height = curveOf(this, this.on)?.valueAt(x);
26
- // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.
27
- return { x, y: height !== undefined && Number.isFinite(height) ? height : y };
28
- }
29
- measure() {
30
- return { width: this.radius * 2, height: this.radius * 2 };
31
- }
32
- declareAssets(assets) {
33
- super.declareAssets(assets);
34
- if (this.label !== "" && this.fontFamily !== "")
35
- assets.font(this.fontFamily);
36
- declareFormulas(assets, [this.label]);
37
- }
38
- shapeGraphics() {
39
- const size = this.radius * 2;
40
- return size > 0 ? new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;
41
- }
42
- renderSelf(ctx) {
43
- super.renderSelf(ctx);
44
- if (this.label === "")
45
- return;
46
- const gap = this.radius + this.labelSize * 0.45;
47
- const side = this.labelSide;
48
- const horizontal = side === "left" || side === "right";
49
- const label = {
50
- text: this.label,
51
- align: side === "left" ? "right" : side === "right" ? "left" : "center",
52
- at: {
53
- x: horizontal ? (side === "left" ? -1 : 1) * gap : 0,
54
- y: horizontal ? 0 : (side === "below" ? -1 : 1) * (gap + this.labelSize / 2),
55
- },
56
- };
57
- const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor };
58
- for (const part of drawLabels([label], style))
59
- ctx.draw(part);
60
- }
61
- };
62
- __decorate([
63
- property({ default: "", kind: "nodeRef", nodeTypes: ["functionPlot"], animatable: false })
64
- ], PlotPoint.prototype, "on", void 0);
65
- __decorate([
66
- property({ default: 7, min: 0, unit: "px" })
67
- ], PlotPoint.prototype, "radius", void 0);
68
- __decorate([
69
- property({ default: "", animatable: false })
70
- ], PlotPoint.prototype, "label", void 0);
71
- __decorate([
72
- property({ default: "above", options: ["above", "below", "left", "right"], animatable: false })
73
- ], PlotPoint.prototype, "labelSide", void 0);
74
- __decorate([
75
- property({ default: 18, min: 1, unit: "px" })
76
- ], PlotPoint.prototype, "labelSize", void 0);
77
- __decorate([
78
- colorProperty({ default: "#e5e7eb" })
79
- ], PlotPoint.prototype, "labelColor", void 0);
80
- __decorate([
81
- property({ default: "", animatable: false })
82
- ], PlotPoint.prototype, "fontFamily", void 0);
83
- __decorate([
84
- fillProperty({ default: "#e5e7eb" })
85
- ], PlotPoint.prototype, "fill", void 0);
86
- PlotPoint = __decorate([
87
- node({
88
- key: "plotPoint",
89
- within: SYSTEMS_AND_PLOT,
90
- parentKey: "shape",
91
- forkable: true,
92
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
93
- }),
94
- withdraw(...OUTLINE_TRIM)
95
- ], PlotPoint);
96
- export { PlotPoint };
27
+ export const PlotPoint = anchored(component2d({
28
+ key: "plotPoint",
29
+ state,
30
+ defaults: { fill: "#e5e7eb", width: "hug", height: "hug", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },
31
+ load: (loader, s) => {
32
+ if (s.label !== "" && s.fontFamily !== "")
33
+ loader.font(s.fontFamily);
34
+ loadFormulas(loader, [s.label]);
35
+ },
36
+ commands: omit(PAINT_COMMANDS, "progressTo", "flash"),
37
+ measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),
38
+ render: (ctx, s) => {
39
+ const size = s.radius * 2;
40
+ const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;
41
+ painted(ctx, () => {
42
+ if (shape)
43
+ ctx.draw(shape().shadow(s.shadow).fill(s.fill));
44
+ if (s.label === "")
45
+ return;
46
+ const gap = s.radius + s.labelSize * 0.45;
47
+ const side = s.labelSide;
48
+ const horizontal = side === "left" || side === "right";
49
+ const label = {
50
+ text: s.label,
51
+ align: side === "left" ? "right" : side === "right" ? "left" : "center",
52
+ at: {
53
+ x: horizontal ? (side === "left" ? -1 : 1) * gap : 0,
54
+ y: horizontal ? 0 : (side === "below" ? -1 : 1) * (gap + s.labelSize / 2),
55
+ },
56
+ };
57
+ ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor }));
58
+ }, () => {
59
+ if (shape)
60
+ strokeShape(ctx, shape, s);
61
+ });
62
+ },
63
+ }), (s, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));
64
+ /** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */
65
+ function heightOf(plane, on, x, y) {
66
+ const curve = curveFor(plane, on);
67
+ const height = curve ? curveValue(curve, x) : NaN;
68
+ // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.
69
+ return Number.isFinite(height) ? height : y;
70
+ }
97
71
  //# sourceMappingURL=plot-point.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plot-point.js","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,aAAa,EACb,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,QAAQ,GAUX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAc,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAYhD;;;GAGG;AASI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,SAAyB;IAapD,YAAY,KAA6C;QACrD,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACvB,CAAC;IAED,uEAAuE;IACvE,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,QAAQ,CAAC,CAAS,EAAE,CAAS;QACzB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAClD,0FAA0F;QAC1F,OAAO,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,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;wCAAuB;AAE5D;IADP,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;4CACxC;AACD;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;4CAA2B;AAC1B;IAA9C,aAAa,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;6CAA2B;AACX;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;6CAA4B;AAE3B;IAA7C,YAAY,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;uCAAoB;AAXhD,SAAS;IARrB,IAAI,CAAC;QACF,GAAG,EAAE,WAAW;QAChB,MAAM,EAAE,gBAAgB;QACxB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;KAC9G,CAAC;IACD,QAAQ,CAAC,GAAG,YAAY,CAAC;GACb,SAAS,CA4DrB","sourcesContent":["import {\r\n colorProperty,\r\n fillProperty,\r\n Graphics2D,\r\n node,\r\n PaintNode,\r\n property,\r\n withdraw,\r\n type AssetScope,\r\n type Color,\r\n type Fill,\r\n type NodeConfig,\r\n type NormalizedColor,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type Size2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { Anchored } from \"../kit/place\";\r\nimport { curveOf } from \"../kit/curve\";\r\nimport { declareFormulas, drawLabels, type Label } from \"../kit/furniture\";\r\nimport { SYSTEMS_AND_PLOT } from \"../kit/placement\";\r\nimport { OUTLINE_TRIM } from \"../kit/withdrawn\";\r\n\r\nexport interface PlotPointProps extends PaintProps {\r\n on?: string;\r\n radius?: number;\r\n label?: string;\r\n labelSide?: \"above\" | \"below\" | \"left\" | \"right\";\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\n/**\r\n * A dot at graph coordinates, with an optional label. Named a plot in `on`, it\r\n * rides that curve: its `x` is where along it, and its height is the curve's.\r\n */\r\n@node({\r\n key: \"plotPoint\",\r\n within: SYSTEMS_AND_PLOT,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\n@withdraw(...OUTLINE_TRIM)\r\nexport class PlotPoint extends PaintNode<PlotPointProps> implements Anchored {\r\n /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */\r\n @property({ default: \"\", kind: \"nodeRef\", nodeTypes: [\"functionPlot\"], animatable: false }) declare on: string;\r\n @property({ default: 7, min: 0, unit: \"px\" }) declare radius: number;\r\n @property({ default: \"\", animatable: false }) declare label: string;\r\n @property({ default: \"above\", options: [\"above\", \"below\", \"left\", \"right\"], animatable: false })\r\n declare labelSide: \"above\" | \"below\" | \"left\" | \"right\";\r\n @property({ default: 18, min: 1, unit: \"px\" }) declare labelSize: number;\r\n @colorProperty({ default: \"#e5e7eb\" }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n\r\n @fillProperty({ default: \"#e5e7eb\" }) declare fill: Fill;\r\n\r\n constructor(props?: NodeConfig<PlotPoint, PlotPointProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** The graph height the point is at: the curve's when it rides one. */\r\n get value(): number {\r\n return this.anchorAt(this.x, this.y).y;\r\n }\r\n\r\n anchorAt(x: number, y: number): Vector2 {\r\n const height = curveOf(this, this.on)?.valueAt(x);\r\n // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.\r\n return { x, y: height !== undefined && Number.isFinite(height) ? height : y };\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n return { width: this.radius * 2, height: this.radius * 2 };\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.label !== \"\" && this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n declareFormulas(assets, [this.label]);\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const size = this.radius * 2;\r\n return size > 0 ? new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;\r\n }\r\n\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n super.renderSelf(ctx);\r\n if (this.label === \"\") return;\r\n const gap = this.radius + this.labelSize * 0.45;\r\n const side = this.labelSide;\r\n const horizontal = side === \"left\" || side === \"right\";\r\n const label: Label = {\r\n text: this.label,\r\n align: side === \"left\" ? \"right\" : side === \"right\" ? \"left\" : \"center\",\r\n at: {\r\n x: horizontal ? (side === \"left\" ? -1 : 1) * gap : 0,\r\n y: horizontal ? 0 : (side === \"below\" ? -1 : 1) * (gap + this.labelSize / 2),\r\n },\r\n };\r\n const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };\r\n for (const part of drawLabels([label], style)) ctx.draw(part);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"plot-point.js","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,kBAAkB,CAAC;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CAAC;QAC1C,CAAC,CACJ,CAAC;IACN,CAAC;CACJ,CAAC,EAAE,CAAC,CAA2B,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAI/F,oGAAoG;AACpG,SAAS,QAAQ,CAAC,KAAwB,EAAE,EAAW,EAAE,CAAS,EAAE,CAAS;IACzE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAClD,0FAA0F;IAC1F,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\r\n component2d,\r\n Graphics2D,\r\n Types,\r\n type Color,\r\n type NodeOf,\r\n type NormalizedColor,\r\n type PaintProps,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\r\nimport { curveValue } from \"../kit/curve\";\r\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\r\nimport { curveFor, PLANE_ENTRY, PLOT_REF, type GraphPlane } from \"../kit/graph\";\r\nimport { strokeShape } from \"../kit/mark\";\r\nimport { anchored } from \"../kit/place\";\r\n\r\nexport interface PlotPointProps extends PaintProps {\r\n on?: string;\r\n radius?: number;\r\n label?: string;\r\n labelSide?: \"above\" | \"below\" | \"left\" | \"right\";\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\nconst state = {\r\n // A dot has no outline worth trimming.\r\n ...omit(PAINT, \"start\", \"end\"),\r\n /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */\r\n on: PLOT_REF,\r\n radius: Types.number(7, { min: 0, unit: \"px\" }),\r\n label: Types.text(\"\", { animatable: false }),\r\n labelSide: listed([\"above\", \"below\", \"left\", \"right\"], \"above\", { animatable: false }),\r\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\r\n labelColor: Types.color(\"#e5e7eb\"),\r\n fontFamily: Types.text(\"\", { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */\r\n value: Types.number(0, { private: true }),\r\n};\r\n\r\n/**\r\n * A dot at graph coordinates, with an optional label. Named a plot in `on`, it\r\n * rides that curve: its `x` is where along it, and its height is the curve's.\r\n */\r\nexport const PlotPoint = anchored(component2d({\r\n key: \"plotPoint\",\r\n state,\r\n defaults: { fill: \"#e5e7eb\", width: \"hug\", height: \"hug\", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },\r\n load: (loader, s) => {\r\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\r\n loadFormulas(loader, [s.label]);\r\n },\r\n commands: omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\r\n measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),\r\n render: (ctx, s) => {\r\n const size = s.radius * 2;\r\n const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;\r\n painted(\r\n ctx,\r\n () => {\r\n if (shape) ctx.draw(shape().shadow(s.shadow).fill(s.fill));\r\n if (s.label === \"\") return;\r\n const gap = s.radius + s.labelSize * 0.45;\r\n const side = s.labelSide;\r\n const horizontal = side === \"left\" || side === \"right\";\r\n const label: Label = {\r\n text: s.label,\r\n align: side === \"left\" ? \"right\" : side === \"right\" ? \"left\" : \"center\",\r\n at: {\r\n x: horizontal ? (side === \"left\" ? -1 : 1) * gap : 0,\r\n y: horizontal ? 0 : (side === \"below\" ? -1 : 1) * (gap + s.labelSize / 2),\r\n },\r\n };\r\n ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\r\n },\r\n () => {\r\n if (shape) strokeShape(ctx, shape, s);\r\n },\r\n );\r\n },\r\n}), (s: { readonly on: unknown }, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));\r\n\r\nexport type PlotPoint = NodeOf<typeof PlotPoint>;\r\n\r\n/** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */\r\nfunction heightOf(plane: GraphPlane | null, on: unknown, x: number, y: number): number {\r\n const curve = curveFor(plane, on);\r\n const height = curve ? curveValue(curve, x) : NaN;\r\n // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.\r\n return Number.isFinite(height) ? height : y;\r\n}\r\n"]}
@@ -1,6 +1,5 @@
1
- import { type Command, type CommandArgs, type Fill, type NodeConfig, type PaintProps, type Stroke, type Vector2 } from "@motionscript/sdk";
2
- import type { CoordinateMap, Interval } from "../kit/coords.js";
3
- import { Mark } from "../kit/mark.js";
1
+ import { type NodeOf, type NodeView, type PaintProps, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
2
+ import type { Interval } from "../kit/coords.js";
4
3
  export type RiemannSample = "left" | "right" | "center";
5
4
  export interface RiemannSumProps extends PaintProps {
6
5
  on?: string;
@@ -9,29 +8,34 @@ export interface RiemannSumProps extends PaintProps {
9
8
  sample?: RiemannSample;
10
9
  }
11
10
  /** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */
12
- export declare class RiemannSum extends Mark<RiemannSumProps> {
13
- on: string;
14
- domain: Interval;
11
+ export declare const RiemannSum: import("@motionscript/sdk").Component<"riemannSum", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
12
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
13
+ domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
15
14
  /** Each rectangle's width, in graph units. */
16
- dx: number;
15
+ dx: import("@motionscript/sdk").Type<number, number, false>;
17
16
  /** Where in its width a rectangle reads the curve's height. */
18
- sample: RiemannSample;
19
- fill: Fill;
20
- stroke: Stroke;
21
- constructor(props?: NodeConfig<RiemannSum, RiemannSumProps>);
22
- /** Animate the rectangles' width: narrower is the sum closing in on the area. */
23
- refineTo(args: CommandArgs<{
24
- dx: number;
25
- }> & {
26
- duration: number;
27
- }): Command<RiemannSumProps>;
28
- /** Animate the span of x the rectangles cover. */
29
- domainTo(args: CommandArgs<{
30
- domain: Interval;
31
- }> & {
32
- duration: number;
33
- }): Command<RiemannSumProps>;
34
- protected isClosed(): boolean;
35
- protected trace(map: CoordinateMap): Vector2[][];
36
- }
17
+ sample: import("@motionscript/sdk").Type<"center" | "left" | "right", "center" | "left" | "right", false>;
18
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
19
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
20
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
21
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
22
+ }>, {
23
+ readonly refineTo: readonly ["dx"];
24
+ readonly domainTo: readonly ["domain"];
25
+ readonly fillTo: readonly ["fill"];
26
+ readonly strokeTo: readonly ["stroke"];
27
+ readonly shadowTo: readonly ["shadow"];
28
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
29
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
30
+ domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
31
+ /** Each rectangle's width, in graph units. */
32
+ dx: import("@motionscript/sdk").Type<number, number, false>;
33
+ /** Where in its width a rectangle reads the curve's height. */
34
+ sample: import("@motionscript/sdk").Type<"center" | "left" | "right", "center" | "left" | "right", false>;
35
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
36
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
37
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
38
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
39
+ }>, null>>;
40
+ export type RiemannSum = NodeOf<typeof RiemannSum>;
37
41
  //# sourceMappingURL=riemann-sum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"riemann-sum.d.ts","sourceRoot":"","sources":["../../src/marks/riemann-sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAOH,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAMnC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExD,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,QAAQ,CAAC;IACl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