@motionscript/math 0.0.0-stage → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +144 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +389 -2
- package/dist/annotate/angle-mark.d.ts +96 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +97 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +115 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +99 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +80 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +80 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-IRZCG6PM.js +2 -0
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
- package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
- package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
- package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +71 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +45 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +28 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +29 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +79 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +109 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +109 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +163 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +32 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +92 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +72 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +87 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +20 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +66 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +31 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +71 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +51 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +59 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +57 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +43 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +71 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +71 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +58 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +63 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +71 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +89 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +60 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +67 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +43 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +57 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +159 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +184 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +64 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +72 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +76 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +122 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +70 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +41 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +60 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +77 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +174 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +240 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +114 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +161 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +197 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +157 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +101 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +91 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +168 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +186 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +98 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +139 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +10 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +101 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +56 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +98 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +25 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +247 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +187 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +126 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +109 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +42 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +99 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +34 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +43 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +58 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +207 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +261 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +96 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +53 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +80 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +137 -0
- package/src/annotate/curly-brace.ts +148 -0
- package/src/annotate/emphasis-mark.ts +118 -0
- package/src/engine.ts +86 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/component.ts +57 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +47 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +171 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +229 -0
- package/src/kit/furniture.ts +113 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +152 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +77 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +105 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +71 -0
- package/src/marks/plot-point.ts +102 -0
- package/src/marks/riemann-sum.ts +99 -0
- package/src/marks/tangent-line.ts +119 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +99 -0
- package/src/plots/function-plot.ts +220 -0
- package/src/plots/points-plot.ts +103 -0
- package/src/plots/stream-lines.ts +160 -0
- package/src/plots/traced-path.ts +70 -0
- package/src/plots/vector-field.ts +107 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +291 -0
- package/src/structures/sample-space.ts +210 -0
- package/src/systems/axes2d.ts +226 -0
- package/src/systems/number-line.ts +130 -0
- package/src/systems/number-plane.ts +232 -0
- package/src/systems/polar-plane.ts +177 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +15 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +97 -0
- package/src/tex/node.ts +74 -0
- package/src/tex/tween.ts +308 -0
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +267 -0
- package/src/three/curve-plot3d.ts +146 -0
- package/src/three/entries.ts +42 -0
- package/src/three/label3d.ts +52 -0
- package/src/three/plot-point3d.ts +63 -0
- package/src/three/space.ts +92 -0
- package/src/three/surface-plot3d.ts +318 -0
- package/src/three/vector-arrow3d.ts +88 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
component2d,
|
|
3
|
+
type NodeOf,
|
|
4
|
+
type NodeView,
|
|
5
|
+
type PaintProps,
|
|
6
|
+
type Vector2,
|
|
7
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
8
|
+
type Node2D as _Node2D,
|
|
9
|
+
type Node2DProps as _Node2DProps,
|
|
10
|
+
type Shadow as _Shadow,
|
|
11
|
+
type ShadowResolved as _ShadowResolved,
|
|
12
|
+
type Stroke as _Stroke,
|
|
13
|
+
type StrokeResolved as _StrokeResolved,
|
|
14
|
+
} from "@motionscript/sdk";
|
|
15
|
+
import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
16
|
+
import { curveValue } from "../kit/curve";
|
|
17
|
+
import { AXIS_COLOR } from "../kit/furniture";
|
|
18
|
+
import { clamp } from "../kit/geometry";
|
|
19
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph";
|
|
20
|
+
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
21
|
+
|
|
22
|
+
export type DropAxis = "x" | "y" | "both";
|
|
23
|
+
|
|
24
|
+
export interface DropLinesProps extends PaintProps {
|
|
25
|
+
on?: string;
|
|
26
|
+
axis?: DropAxis;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const state = {
|
|
30
|
+
...omit(PAINT, "fill"),
|
|
31
|
+
/** A plot to take the point's height from, by id. */
|
|
32
|
+
on: PLOT_REF,
|
|
33
|
+
/** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
|
|
34
|
+
axis: listed(["x", "y", "both"], "both", { animatable: false }),
|
|
35
|
+
graph: PLANE_ENTRY,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface DropValues {
|
|
39
|
+
readonly x: number;
|
|
40
|
+
readonly y: number;
|
|
41
|
+
readonly on: NodeView | null;
|
|
42
|
+
readonly axis: DropAxis;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Guide lines from a graph point to the axes, reading its coordinates off them.
|
|
47
|
+
* The point is this node's `x`/`y`, or the point of a plot above its `x`.
|
|
48
|
+
*/
|
|
49
|
+
export const DropLines = traced(component2d({
|
|
50
|
+
key: "dropLines",
|
|
51
|
+
state,
|
|
52
|
+
defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center", dash: [8, 6] }, width: "hug", height: "hug" },
|
|
53
|
+
commands: omit(PAINT_COMMANDS, "fillTo"),
|
|
54
|
+
measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),
|
|
55
|
+
render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),
|
|
56
|
+
}), traceDrops);
|
|
57
|
+
|
|
58
|
+
export type DropLines = NodeOf<typeof DropLines>;
|
|
59
|
+
|
|
60
|
+
function traceDrops(s: DropValues, { map, plane }: MarkReading): Vector2[][] {
|
|
61
|
+
const x = s.x;
|
|
62
|
+
const plot = curveFor(plane, s.on);
|
|
63
|
+
const y = plot ? curveValue(plot, x) : s.y;
|
|
64
|
+
if (!Number.isFinite(y)) return [];
|
|
65
|
+
const at = map.toPoint(x, y);
|
|
66
|
+
const runs: Vector2[][] = [];
|
|
67
|
+
// Each line starts on its axis, so drawing it on grows it towards the point.
|
|
68
|
+
if (s.axis !== "y") runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);
|
|
69
|
+
if (s.axis !== "x") runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);
|
|
70
|
+
return runs;
|
|
71
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
component2d,
|
|
3
|
+
Graphics2D,
|
|
4
|
+
Types,
|
|
5
|
+
type Color,
|
|
6
|
+
type NodeOf,
|
|
7
|
+
type NormalizedColor,
|
|
8
|
+
type PaintProps,
|
|
9
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
10
|
+
type Fill as _Fill,
|
|
11
|
+
type FillResolved as _FillResolved,
|
|
12
|
+
type Node2D as _Node2D,
|
|
13
|
+
type Node2DProps as _Node2DProps,
|
|
14
|
+
type Shadow as _Shadow,
|
|
15
|
+
type ShadowResolved as _ShadowResolved,
|
|
16
|
+
type Stroke as _Stroke,
|
|
17
|
+
type StrokeResolved as _StrokeResolved,
|
|
18
|
+
} from "@motionscript/sdk";
|
|
19
|
+
import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component";
|
|
20
|
+
import { curveValue } from "../kit/curve";
|
|
21
|
+
import { drawLabels, loadFormulas, type Label } from "../kit/furniture";
|
|
22
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF, type GraphPlane } from "../kit/graph";
|
|
23
|
+
import { strokeShape } from "../kit/mark";
|
|
24
|
+
import { anchored } from "../kit/place";
|
|
25
|
+
|
|
26
|
+
export interface PlotPointProps extends PaintProps {
|
|
27
|
+
on?: string;
|
|
28
|
+
radius?: number;
|
|
29
|
+
label?: string;
|
|
30
|
+
labelSide?: "above" | "below" | "left" | "right";
|
|
31
|
+
labelSize?: number;
|
|
32
|
+
labelColor?: Color;
|
|
33
|
+
fontFamily?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const state = {
|
|
37
|
+
// A dot has no outline worth trimming.
|
|
38
|
+
...omit(PAINT, "start", "end"),
|
|
39
|
+
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
40
|
+
on: PLOT_REF,
|
|
41
|
+
radius: Types.number(7, { min: 0, unit: "px" }),
|
|
42
|
+
label: Types.text("", { animatable: false }),
|
|
43
|
+
labelSide: listed(["above", "below", "left", "right"], "above", { animatable: false }),
|
|
44
|
+
labelSize: Types.number(18, { min: 1, unit: "px" }),
|
|
45
|
+
labelColor: Types.color("#e5e7eb"),
|
|
46
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
47
|
+
graph: PLANE_ENTRY,
|
|
48
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
49
|
+
value: Types.number(0, { private: true }),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A dot at graph coordinates, with an optional label. Named a plot in `on`, it
|
|
54
|
+
* rides that curve: its `x` is where along it, and its height is the curve's.
|
|
55
|
+
*/
|
|
56
|
+
export const PlotPoint = anchored(component2d({
|
|
57
|
+
key: "plotPoint",
|
|
58
|
+
state,
|
|
59
|
+
defaults: { fill: "#e5e7eb", width: "hug", height: "hug", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },
|
|
60
|
+
load: (loader, s) => {
|
|
61
|
+
if (s.label !== "" && s.fontFamily !== "") loader.font(s.fontFamily);
|
|
62
|
+
loadFormulas(loader, [s.label]);
|
|
63
|
+
},
|
|
64
|
+
commands: omit(PAINT_COMMANDS, "progressTo", "flash"),
|
|
65
|
+
measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),
|
|
66
|
+
render: (ctx, s) => {
|
|
67
|
+
const size = s.radius * 2;
|
|
68
|
+
const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;
|
|
69
|
+
painted(
|
|
70
|
+
ctx,
|
|
71
|
+
() => {
|
|
72
|
+
if (shape) ctx.draw(shape().shadow(s.shadow).fill(s.fill));
|
|
73
|
+
if (s.label === "") return;
|
|
74
|
+
const gap = s.radius + s.labelSize * 0.45;
|
|
75
|
+
const side = s.labelSide;
|
|
76
|
+
const horizontal = side === "left" || side === "right";
|
|
77
|
+
const label: Label = {
|
|
78
|
+
text: s.label,
|
|
79
|
+
align: side === "left" ? "right" : side === "right" ? "left" : "center",
|
|
80
|
+
at: {
|
|
81
|
+
x: horizontal ? (side === "left" ? -1 : 1) * gap : 0,
|
|
82
|
+
y: horizontal ? 0 : (side === "below" ? -1 : 1) * (gap + s.labelSize / 2),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));
|
|
86
|
+
},
|
|
87
|
+
() => {
|
|
88
|
+
if (shape) strokeShape(ctx, shape, s);
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
}), (s: { readonly on: unknown }, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));
|
|
93
|
+
|
|
94
|
+
export type PlotPoint = NodeOf<typeof PlotPoint>;
|
|
95
|
+
|
|
96
|
+
/** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */
|
|
97
|
+
function heightOf(plane: GraphPlane | null, on: unknown, x: number, y: number): number {
|
|
98
|
+
const curve = curveFor(plane, on);
|
|
99
|
+
const height = curve ? curveValue(curve, x) : NaN;
|
|
100
|
+
// Off the end of its curve a point stays where its own `y` puts it rather than vanishing.
|
|
101
|
+
return Number.isFinite(height) ? height : y;
|
|
102
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
component2d,
|
|
3
|
+
Types,
|
|
4
|
+
type NodeOf,
|
|
5
|
+
type NodeView,
|
|
6
|
+
type PaintProps,
|
|
7
|
+
type Vector2,
|
|
8
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
9
|
+
type Fill as _Fill,
|
|
10
|
+
type FillResolved as _FillResolved,
|
|
11
|
+
type Node2D as _Node2D,
|
|
12
|
+
type Node2DProps as _Node2DProps,
|
|
13
|
+
type Shadow as _Shadow,
|
|
14
|
+
type ShadowResolved as _ShadowResolved,
|
|
15
|
+
type Stroke as _Stroke,
|
|
16
|
+
type StrokeResolved as _StrokeResolved,
|
|
17
|
+
} from "@motionscript/sdk";
|
|
18
|
+
import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
19
|
+
import type { Interval } from "../kit/coords";
|
|
20
|
+
import { curveValue } from "../kit/curve";
|
|
21
|
+
import { lerpInterval, PLOT_COLOR, readInterval } from "../kit/furniture";
|
|
22
|
+
import { clamp } from "../kit/geometry";
|
|
23
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph";
|
|
24
|
+
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
25
|
+
|
|
26
|
+
export type RiemannSample = "left" | "right" | "center";
|
|
27
|
+
|
|
28
|
+
export interface RiemannSumProps extends PaintProps {
|
|
29
|
+
on?: string;
|
|
30
|
+
domain?: Interval;
|
|
31
|
+
dx?: number;
|
|
32
|
+
sample?: RiemannSample;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** More rectangles than this is a filled area with extra steps. */
|
|
36
|
+
const MAX_RECTANGLES = 2000;
|
|
37
|
+
|
|
38
|
+
const state = {
|
|
39
|
+
// Its rectangles are revealed by `dx`, not by trimming their outlines.
|
|
40
|
+
...omit(PAINT, "start", "end"),
|
|
41
|
+
on: PLOT_REF,
|
|
42
|
+
domain: Types.custom<Interval>([0, 1], { resolve: readInterval, lerp: lerpInterval }),
|
|
43
|
+
/** Each rectangle's width, in graph units. */
|
|
44
|
+
dx: Types.number(0.25, { min: 0.001 }),
|
|
45
|
+
/** Where in its width a rectangle reads the curve's height. */
|
|
46
|
+
sample: listed(["left", "right", "center"], "left", { animatable: false }),
|
|
47
|
+
graph: PLANE_ENTRY,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
interface SumValues {
|
|
51
|
+
readonly on: NodeView | null;
|
|
52
|
+
readonly domain: Interval;
|
|
53
|
+
readonly dx: number;
|
|
54
|
+
readonly sample: RiemannSample;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */
|
|
58
|
+
export const RiemannSum = traced(component2d({
|
|
59
|
+
key: "riemannSum",
|
|
60
|
+
state,
|
|
61
|
+
defaults: {
|
|
62
|
+
fill: { type: "solid", color: PLOT_COLOR, opacity: 0.35 },
|
|
63
|
+
stroke: { weight: 1.5, fill: PLOT_COLOR, align: "center", join: "round" },
|
|
64
|
+
width: "hug",
|
|
65
|
+
height: "hug",
|
|
66
|
+
},
|
|
67
|
+
commands: {
|
|
68
|
+
...omit(PAINT_COMMANDS, "progressTo", "flash"),
|
|
69
|
+
/** Animate the rectangles' width: narrower is the sum closing in on the area. */
|
|
70
|
+
refineTo: { args: ["dx"] },
|
|
71
|
+
/** Animate the span of x the rectangles cover. */
|
|
72
|
+
domainTo: { args: ["domain"] },
|
|
73
|
+
},
|
|
74
|
+
measure: (_measurer, s) => inkSize(traceSum(s, reading(s))),
|
|
75
|
+
render: (ctx, s) => drawMark(ctx, s, traceSum(s, reading(s)), { closed: true }),
|
|
76
|
+
}), traceSum);
|
|
77
|
+
|
|
78
|
+
export type RiemannSum = NodeOf<typeof RiemannSum>;
|
|
79
|
+
|
|
80
|
+
function traceSum(s: SumValues, { map, plane }: MarkReading): Vector2[][] {
|
|
81
|
+
const plot = curveFor(plane, s.on);
|
|
82
|
+
const [a, b] = s.domain;
|
|
83
|
+
const dx = s.dx;
|
|
84
|
+
if (!plot || !(b > a) || !(dx > 0)) return [];
|
|
85
|
+
const [yMin, yMax] = map.yRange;
|
|
86
|
+
const base = clamp(0, yMin, yMax);
|
|
87
|
+
const at = s.sample === "left" ? 0 : s.sample === "right" ? 1 : 0.5;
|
|
88
|
+
const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));
|
|
89
|
+
const runs: Vector2[][] = [];
|
|
90
|
+
for (let i = 0; i < count; i++) {
|
|
91
|
+
const left = a + i * dx;
|
|
92
|
+
const right = Math.min(b, left + dx);
|
|
93
|
+
const value = curveValue(plot, left + (right - left) * at);
|
|
94
|
+
if (!Number.isFinite(value)) continue;
|
|
95
|
+
const height = clamp(value, yMin, yMax);
|
|
96
|
+
runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);
|
|
97
|
+
}
|
|
98
|
+
return runs;
|
|
99
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
component2d,
|
|
3
|
+
Types,
|
|
4
|
+
type NodeOf,
|
|
5
|
+
type NodeView,
|
|
6
|
+
type PaintProps,
|
|
7
|
+
type Vector2,
|
|
8
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
9
|
+
type Node2D as _Node2D,
|
|
10
|
+
type Node2DProps as _Node2DProps,
|
|
11
|
+
type Shadow as _Shadow,
|
|
12
|
+
type ShadowResolved as _ShadowResolved,
|
|
13
|
+
type Stroke as _Stroke,
|
|
14
|
+
type StrokeResolved as _StrokeResolved,
|
|
15
|
+
} from "@motionscript/sdk";
|
|
16
|
+
import { omit, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
17
|
+
import { curveValue, type CurveValues } from "../kit/curve";
|
|
18
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph";
|
|
19
|
+
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
20
|
+
|
|
21
|
+
export interface TangentLineProps extends PaintProps {
|
|
22
|
+
on?: string;
|
|
23
|
+
length?: number;
|
|
24
|
+
dx?: number;
|
|
25
|
+
legs?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The step a slope is measured over, as a share of the system's width. */
|
|
29
|
+
const SLOPE_STEP = 1e-4;
|
|
30
|
+
|
|
31
|
+
const state = {
|
|
32
|
+
...omit(PAINT, "fill"),
|
|
33
|
+
on: PLOT_REF,
|
|
34
|
+
length: Types.number(260, { min: 0, unit: "px" }),
|
|
35
|
+
/** The second point's distance along x; zero is the tangent itself. */
|
|
36
|
+
dx: Types.number(0, { min: 0 }),
|
|
37
|
+
legs: Types.boolean(false, { animatable: false }),
|
|
38
|
+
graph: PLANE_ENTRY,
|
|
39
|
+
/** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */
|
|
40
|
+
slope: Types.number(NaN, { private: true }),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
interface TangentValues {
|
|
44
|
+
readonly x: number;
|
|
45
|
+
readonly on: NodeView | null;
|
|
46
|
+
readonly length: number;
|
|
47
|
+
readonly dx: number;
|
|
48
|
+
readonly legs: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The tangent to a plot at this node's `x`, a fixed length on screen. With a
|
|
53
|
+
* `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that
|
|
54
|
+
* secant's run and rise.
|
|
55
|
+
*/
|
|
56
|
+
export const TangentLine = traced(component2d({
|
|
57
|
+
key: "tangentLine",
|
|
58
|
+
state,
|
|
59
|
+
defaults: {
|
|
60
|
+
stroke: { weight: 3, fill: "#f59e0b", align: "center", cap: "round", join: "round" },
|
|
61
|
+
width: "hug",
|
|
62
|
+
height: "hug",
|
|
63
|
+
slope: (s) => {
|
|
64
|
+
const plot = curveFor(s.graph, s.on);
|
|
65
|
+
return plot ? tangentSlope(plot, s.x, s.dx) : NaN;
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
commands: omit(PAINT_COMMANDS, "fillTo"),
|
|
69
|
+
measure: (_measurer, s) => inkSize(traceTangent(s, reading(s))),
|
|
70
|
+
render: (ctx, s) => drawMark(ctx, s, traceTangent(s, reading(s))),
|
|
71
|
+
}), traceTangent);
|
|
72
|
+
|
|
73
|
+
export type TangentLine = NodeOf<typeof TangentLine>;
|
|
74
|
+
|
|
75
|
+
/** The slope a tangent at `x` draws on `curve`, in graph units: the curve's at `x`, or the secant's to `x + dx`. */
|
|
76
|
+
export function tangentSlope(curve: CurveValues, x: number, dx = 0): number {
|
|
77
|
+
if (dx > 0) return (curveValue(curve, x + dx) - curveValue(curve, x)) / dx;
|
|
78
|
+
const h = 1e-6 * Math.max(1, Math.abs(x));
|
|
79
|
+
return (curveValue(curve, x + h) - curveValue(curve, x - h)) / (2 * h);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function traceTangent(s: TangentValues, { map, plane }: MarkReading): Vector2[][] {
|
|
83
|
+
const plot = curveFor(plane, s.on);
|
|
84
|
+
if (!plot) return [];
|
|
85
|
+
const x = s.x;
|
|
86
|
+
const y = curveValue(plot, x);
|
|
87
|
+
if (!Number.isFinite(y)) return [];
|
|
88
|
+
const half = s.length / 2;
|
|
89
|
+
|
|
90
|
+
if (s.dx > 0) {
|
|
91
|
+
const y2 = curveValue(plot, x + s.dx);
|
|
92
|
+
if (!Number.isFinite(y2)) return [];
|
|
93
|
+
const a = map.toPoint(x, y);
|
|
94
|
+
const b = map.toPoint(x + s.dx, y2);
|
|
95
|
+
const span = Math.hypot(b.x - a.x, b.y - a.y);
|
|
96
|
+
if (span === 0) return [];
|
|
97
|
+
const reach = Math.max(half, span / 2 + 16);
|
|
98
|
+
const ux = (b.x - a.x) / span;
|
|
99
|
+
const uy = (b.y - a.y) / span;
|
|
100
|
+
const mx = (a.x + b.x) / 2;
|
|
101
|
+
const my = (a.y + b.y) / 2;
|
|
102
|
+
const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];
|
|
103
|
+
return s.legs ? [secant, [a, map.toPoint(x + s.dx, y), b]] : [secant];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const [xMin, xMax] = map.xRange;
|
|
107
|
+
const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;
|
|
108
|
+
const before = curveValue(plot, x - h);
|
|
109
|
+
const after = curveValue(plot, x + h);
|
|
110
|
+
if (!Number.isFinite(before) || !Number.isFinite(after)) return [];
|
|
111
|
+
const p = map.toPoint(x, y);
|
|
112
|
+
const a = map.toPoint(x - h, before);
|
|
113
|
+
const b = map.toPoint(x + h, after);
|
|
114
|
+
const span = Math.hypot(b.x - a.x, b.y - a.y);
|
|
115
|
+
if (span === 0) return [];
|
|
116
|
+
const ux = (b.x - a.x) / span;
|
|
117
|
+
const uy = (b.y - a.y) / span;
|
|
118
|
+
return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];
|
|
119
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
component2d,
|
|
3
|
+
Types,
|
|
4
|
+
type NodeOf,
|
|
5
|
+
type PaintProps,
|
|
6
|
+
type Vector2,
|
|
7
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
8
|
+
type Node2D as _Node2D,
|
|
9
|
+
type Node2DProps as _Node2DProps,
|
|
10
|
+
type Shadow as _Shadow,
|
|
11
|
+
type ShadowResolved as _ShadowResolved,
|
|
12
|
+
type Stroke as _Stroke,
|
|
13
|
+
type StrokeResolved as _StrokeResolved,
|
|
14
|
+
} from "@motionscript/sdk";
|
|
15
|
+
import { omit, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
16
|
+
import { PLANE_ENTRY } from "../kit/graph";
|
|
17
|
+
import { drawMark, graphPoint, inkSize, ownPoint, reading, traced, type MarkReading, type MarkState } from "../kit/mark";
|
|
18
|
+
|
|
19
|
+
export interface VectorArrowProps extends PaintProps {
|
|
20
|
+
tail?: Vector2;
|
|
21
|
+
head?: Vector2;
|
|
22
|
+
bend?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Degrees of arc per drawn segment of a bent arrow. */
|
|
26
|
+
const BEND_STEP = 4;
|
|
27
|
+
|
|
28
|
+
const state = {
|
|
29
|
+
...omit(PAINT, "fill"),
|
|
30
|
+
tail: Types.vector2(),
|
|
31
|
+
head: Types.vector2({ x: 1, y: 1 }),
|
|
32
|
+
/** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */
|
|
33
|
+
bend: Types.number(0, { min: -180, max: 180, unit: "°" }),
|
|
34
|
+
graph: PLANE_ENTRY,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
interface ArrowValues {
|
|
38
|
+
readonly tail: Vector2;
|
|
39
|
+
readonly head: Vector2;
|
|
40
|
+
readonly bend: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A handle on one end of the arrow: where the end is in its own frame, and the graph point a drop there gives. */
|
|
44
|
+
const end = (which: "tail" | "head") => ({
|
|
45
|
+
at: (s: ArrowValues & MarkState) => {
|
|
46
|
+
const read = reading(s);
|
|
47
|
+
return ownPoint(read, traceArrow(s, read), s[which]);
|
|
48
|
+
},
|
|
49
|
+
value: (at: Vector2, s: ArrowValues & MarkState) => {
|
|
50
|
+
const read = reading(s);
|
|
51
|
+
return graphPoint(read, traceArrow(s, read), at);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* An arrow from `tail` to `head`, two graph points. Its arrowhead is the stroke's
|
|
57
|
+
* `endCap`, so a plain segment, a double arrow or a dashed one is a change of
|
|
58
|
+
* stroke. (`from` and `to` are not its names because every node has a `to`.)
|
|
59
|
+
*/
|
|
60
|
+
export const VectorArrow = traced(component2d({
|
|
61
|
+
key: "vectorArrow",
|
|
62
|
+
state,
|
|
63
|
+
defaults: { stroke: { weight: 4, fill: "#e5e7eb", align: "center", endCap: "triangle" }, width: "hug", height: "hug" },
|
|
64
|
+
commands: {
|
|
65
|
+
...omit(PAINT_COMMANDS, "fillTo"),
|
|
66
|
+
/** Move either end, in graph coordinates. */
|
|
67
|
+
endpointsTo: { args: ["tail", "head"] },
|
|
68
|
+
},
|
|
69
|
+
handles: { tail: end("tail"), head: end("head") },
|
|
70
|
+
measure: (_measurer, s) => inkSize(traceArrow(s, reading(s))),
|
|
71
|
+
render: (ctx, s) => drawMark(ctx, s, traceArrow(s, reading(s))),
|
|
72
|
+
}), traceArrow);
|
|
73
|
+
|
|
74
|
+
export type VectorArrow = NodeOf<typeof VectorArrow>;
|
|
75
|
+
|
|
76
|
+
function traceArrow(s: ArrowValues, { map, shift }: MarkReading): Vector2[][] {
|
|
77
|
+
const a = map.toPoint(s.tail.x + shift.x, s.tail.y + shift.y);
|
|
78
|
+
const b = map.toPoint(s.head.x + shift.x, s.head.y + shift.y);
|
|
79
|
+
const sweep = (s.bend * Math.PI) / 180;
|
|
80
|
+
const chord = Math.hypot(b.x - a.x, b.y - a.y);
|
|
81
|
+
if (Math.abs(sweep) < 1e-3 || chord === 0) return [[a, b]];
|
|
82
|
+
|
|
83
|
+
// The circle through both ends that subtends `sweep` at its centre.
|
|
84
|
+
const radius = chord / (2 * Math.sin(Math.abs(sweep) / 2));
|
|
85
|
+
const side = Math.sign(sweep);
|
|
86
|
+
const reach = radius * Math.cos(sweep / 2);
|
|
87
|
+
// The centre sits to the arrow's right for a positive sweep, so the arc bows to its left.
|
|
88
|
+
const cx = (a.x + b.x) / 2 + (side * (b.y - a.y) * reach) / chord;
|
|
89
|
+
const cy = (a.y + b.y) / 2 - (side * (b.x - a.x) * reach) / chord;
|
|
90
|
+
const from = Math.atan2(a.y - cy, a.x - cx);
|
|
91
|
+
const steps = Math.max(8, Math.ceil(Math.abs(s.bend) / BEND_STEP));
|
|
92
|
+
const run: Vector2[] = [];
|
|
93
|
+
for (let i = 0; i <= steps; i++) {
|
|
94
|
+
const angle = from - (sweep * i) / steps;
|
|
95
|
+
run.push({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });
|
|
96
|
+
}
|
|
97
|
+
return [run];
|
|
98
|
+
}
|
package/src/nodes.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AngleMark } from "./annotate/angle-mark";
|
|
2
|
+
import { CurlyBrace } from "./annotate/curly-brace";
|
|
3
|
+
import { EmphasisMark } from "./annotate/emphasis-mark";
|
|
4
|
+
import { CurveArea } from "./marks/curve-area";
|
|
5
|
+
import { DropLines } from "./marks/drop-lines";
|
|
6
|
+
import { PlotPoint } from "./marks/plot-point";
|
|
7
|
+
import { RiemannSum } from "./marks/riemann-sum";
|
|
8
|
+
import { TangentLine } from "./marks/tangent-line";
|
|
9
|
+
import { VectorArrow } from "./marks/vector-arrow";
|
|
10
|
+
import { FunctionPlot } from "./plots/function-plot";
|
|
11
|
+
import { PointsPlot } from "./plots/points-plot";
|
|
12
|
+
import { StreamLines } from "./plots/stream-lines";
|
|
13
|
+
import { TracedPath } from "./plots/traced-path";
|
|
14
|
+
import { VectorField } from "./plots/vector-field";
|
|
15
|
+
import { Axes2d } from "./systems/axes2d";
|
|
16
|
+
import { NumberLine } from "./systems/number-line";
|
|
17
|
+
import { NumberPlane } from "./systems/number-plane";
|
|
18
|
+
import { PolarPlane } from "./systems/polar-plane";
|
|
19
|
+
import { NetworkGraph } from "./structures/network-graph";
|
|
20
|
+
import { SampleSpace } from "./structures/sample-space";
|
|
21
|
+
import { LatexMatrix } from "./tex/matrix";
|
|
22
|
+
import { Latex } from "./tex/node";
|
|
23
|
+
import { Axes3d } from "./three/axes3d";
|
|
24
|
+
import { CurvePlot3d } from "./three/curve-plot3d";
|
|
25
|
+
import { PlotPoint3d } from "./three/plot-point3d";
|
|
26
|
+
import { SurfacePlot3d } from "./three/surface-plot3d";
|
|
27
|
+
import { VectorArrow3d } from "./three/vector-arrow3d";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Every node type this package publishes.
|
|
31
|
+
*
|
|
32
|
+
* A host registers these by handing the array to an engine —
|
|
33
|
+
* `new Engine(platform, { nodes: NODES })` — which reads each component's key.
|
|
34
|
+
* Defining a component only *declares* that key: nothing is registered by
|
|
35
|
+
* importing a module, so a registry holds exactly what its owner asked for.
|
|
36
|
+
*
|
|
37
|
+
* Listing the component **values** is also what survives bundling: this package
|
|
38
|
+
* declares `sideEffects: false`, and a document names a node type by string, so
|
|
39
|
+
* an import kept only for its side effect is exactly what gets shaken out.
|
|
40
|
+
*/
|
|
41
|
+
// Typed by name, so the declaration names each component rather than spelling out its type through core.
|
|
42
|
+
type KitNode =
|
|
43
|
+
| typeof Latex
|
|
44
|
+
| typeof LatexMatrix
|
|
45
|
+
| typeof NumberLine
|
|
46
|
+
| typeof Axes2d
|
|
47
|
+
| typeof NumberPlane
|
|
48
|
+
| typeof FunctionPlot
|
|
49
|
+
| typeof PointsPlot
|
|
50
|
+
| typeof PlotPoint
|
|
51
|
+
| typeof VectorArrow
|
|
52
|
+
| typeof CurveArea
|
|
53
|
+
| typeof RiemannSum
|
|
54
|
+
| typeof TangentLine
|
|
55
|
+
| typeof DropLines
|
|
56
|
+
| typeof CurlyBrace
|
|
57
|
+
| typeof AngleMark
|
|
58
|
+
| typeof EmphasisMark
|
|
59
|
+
| typeof Axes3d
|
|
60
|
+
| typeof SurfacePlot3d
|
|
61
|
+
| typeof CurvePlot3d
|
|
62
|
+
| typeof PlotPoint3d
|
|
63
|
+
| typeof VectorArrow3d
|
|
64
|
+
| typeof PolarPlane
|
|
65
|
+
| typeof VectorField
|
|
66
|
+
| typeof StreamLines
|
|
67
|
+
| typeof TracedPath
|
|
68
|
+
| typeof NetworkGraph
|
|
69
|
+
| typeof SampleSpace;
|
|
70
|
+
|
|
71
|
+
export const NODES: KitNode[] = [
|
|
72
|
+
Latex,
|
|
73
|
+
LatexMatrix,
|
|
74
|
+
NumberLine,
|
|
75
|
+
Axes2d,
|
|
76
|
+
NumberPlane,
|
|
77
|
+
FunctionPlot,
|
|
78
|
+
PointsPlot,
|
|
79
|
+
PlotPoint,
|
|
80
|
+
VectorArrow,
|
|
81
|
+
CurveArea,
|
|
82
|
+
RiemannSum,
|
|
83
|
+
TangentLine,
|
|
84
|
+
DropLines,
|
|
85
|
+
CurlyBrace,
|
|
86
|
+
AngleMark,
|
|
87
|
+
EmphasisMark,
|
|
88
|
+
Axes3d,
|
|
89
|
+
SurfacePlot3d,
|
|
90
|
+
CurvePlot3d,
|
|
91
|
+
PlotPoint3d,
|
|
92
|
+
VectorArrow3d,
|
|
93
|
+
PolarPlane,
|
|
94
|
+
VectorField,
|
|
95
|
+
StreamLines,
|
|
96
|
+
TracedPath,
|
|
97
|
+
NetworkGraph,
|
|
98
|
+
SampleSpace,
|
|
99
|
+
];
|