@motionscript/math 0.1.0-alpha.9 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/annotate/angle-mark.d.ts +4 -14
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +2 -1
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +4 -16
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +0 -5
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-FZ2YBTPL.js +2 -0
- package/dist/browser/chunks/chunk-FZ2YBTPL.js.map +7 -0
- package/dist/browser/chunks/chunk-T42HWKBC.js +2 -0
- package/dist/browser/chunks/chunk-T42HWKBC.js.map +7 -0
- package/dist/browser/chunks/{mathjax-WV55AC2P.js → mathjax-SOM6RSPV.js} +1 -1
- package/dist/browser/chunks/{mathjax-WV55AC2P.js.map → mathjax-SOM6RSPV.js.map} +2 -2
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/engine.d.ts +3 -4
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +3 -4
- package/dist/engine.js.map +1 -1
- package/dist/kit/cache.d.ts +10 -21
- package/dist/kit/cache.d.ts.map +1 -1
- package/dist/kit/cache.js +33 -24
- package/dist/kit/cache.js.map +1 -1
- package/dist/kit/component.d.ts +5 -14
- package/dist/kit/component.d.ts.map +1 -1
- package/dist/kit/component.js +1 -8
- package/dist/kit/component.js.map +1 -1
- package/dist/kit/coords.d.ts +1 -1
- package/dist/kit/coords.d.ts.map +1 -1
- package/dist/kit/coords.js +2 -1
- package/dist/kit/coords.js.map +1 -1
- package/dist/kit/curve.d.ts +1 -5
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/equation.d.ts +10 -30
- package/dist/kit/equation.d.ts.map +1 -1
- package/dist/kit/equation.js +9 -44
- package/dist/kit/equation.js.map +1 -1
- package/dist/kit/equation3d.d.ts +3 -3
- package/dist/kit/equation3d.d.ts.map +1 -1
- package/dist/kit/equation3d.js +27 -59
- package/dist/kit/equation3d.js.map +1 -1
- package/dist/kit/expression.d.ts +7 -7
- package/dist/kit/expression.d.ts.map +1 -1
- package/dist/kit/expression.js +18 -17
- package/dist/kit/expression.js.map +1 -1
- package/dist/kit/field-mark.d.ts +0 -7
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/field.d.ts +2 -2
- package/dist/kit/field.d.ts.map +1 -1
- package/dist/kit/field.js +11 -31
- package/dist/kit/field.js.map +1 -1
- package/dist/kit/follow.d.ts +3 -10
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +5 -11
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +2 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +6 -3
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/geometry.d.ts +1 -0
- package/dist/kit/geometry.d.ts.map +1 -1
- package/dist/kit/geometry.js +3 -0
- package/dist/kit/geometry.js.map +1 -1
- package/dist/kit/mark.d.ts +4 -10
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +3 -5
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +3 -5
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/sampler.d.ts +0 -5
- package/dist/kit/sampler.d.ts.map +1 -1
- package/dist/kit/sampler.js.map +1 -1
- package/dist/kit/system.d.ts +0 -1
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +3 -10
- package/dist/kit/system.js.map +1 -1
- package/dist/marks/curve-area.d.ts +2 -12
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +4 -9
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +1 -5
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +4 -13
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +1 -7
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +2 -2
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +2 -12
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +1 -5
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +2 -11
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +3 -6
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +1 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +1 -6
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +1 -5
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +1 -6
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +0 -7
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +1 -12
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +1 -6
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +1 -10
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +3 -6
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +15 -34
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +2 -5
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +8 -22
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +3 -5
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +0 -1
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +3 -4
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +7 -22
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +2 -2
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +12 -27
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +1 -7
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +11 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +7 -10
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/geometry.d.ts +5 -24
- package/dist/tex/geometry.d.ts.map +1 -1
- package/dist/tex/geometry.js +19 -90
- package/dist/tex/geometry.js.map +1 -1
- package/dist/tex/mathjax.d.ts +0 -13
- package/dist/tex/mathjax.d.ts.map +1 -1
- package/dist/tex/mathjax.js +4 -24
- package/dist/tex/mathjax.js.map +1 -1
- package/dist/tex/matrix.d.ts +1 -10
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +1 -5
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/tween.d.ts +9 -30
- package/dist/tex/tween.d.ts.map +1 -1
- package/dist/tex/tween.js +19 -67
- package/dist/tex/tween.js.map +1 -1
- package/dist/tex/typeset.d.ts +2 -23
- package/dist/tex/typeset.d.ts.map +1 -1
- package/dist/tex/typeset.js +4 -30
- package/dist/tex/typeset.js.map +1 -1
- package/dist/three/axes3d.d.ts +32 -62
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +5 -13
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +4 -15
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/plot-point3d.d.ts +7 -14
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +3 -8
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +1 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +9 -23
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +1 -7
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +4 -14
- package/src/annotate/curly-brace.ts +2 -14
- package/src/annotate/emphasis-mark.ts +1 -6
- package/src/engine.ts +3 -4
- package/src/kit/cache.ts +33 -25
- package/src/kit/component.ts +5 -19
- package/src/kit/coords.ts +2 -2
- package/src/kit/curve.ts +1 -5
- package/src/kit/equation.ts +12 -50
- package/src/kit/equation3d.ts +23 -59
- package/src/kit/expression.ts +18 -23
- package/src/kit/field-mark.ts +1 -7
- package/src/kit/field.ts +10 -26
- package/src/kit/follow.ts +5 -13
- package/src/kit/furniture.ts +7 -4
- package/src/kit/geometry.ts +4 -0
- package/src/kit/mark.ts +4 -11
- package/src/kit/place.ts +3 -5
- package/src/kit/sampler.ts +0 -6
- package/src/kit/system.ts +3 -12
- package/src/marks/curve-area.ts +3 -16
- package/src/marks/drop-lines.ts +0 -6
- package/src/marks/plot-point.ts +2 -12
- package/src/marks/riemann-sum.ts +2 -10
- package/src/marks/tangent-line.ts +1 -13
- package/src/marks/vector-arrow.ts +3 -13
- package/src/nodes.ts +1 -12
- package/src/plots/function-plot.ts +1 -6
- package/src/plots/points-plot.ts +0 -7
- package/src/plots/stream-lines.ts +1 -8
- package/src/plots/traced-path.ts +2 -13
- package/src/plots/vector-field.ts +4 -12
- package/src/structures/network-graph.ts +6 -25
- package/src/structures/sample-space.ts +5 -20
- package/src/systems/axes2d.ts +3 -6
- package/src/systems/number-line.ts +4 -20
- package/src/systems/number-plane.ts +4 -19
- package/src/systems/polar-plane.ts +11 -25
- package/src/tex/geometry.ts +24 -126
- package/src/tex/mathjax.ts +4 -26
- package/src/tex/matrix.ts +1 -11
- package/src/tex/tween.ts +21 -75
- package/src/tex/typeset.ts +4 -37
- package/src/three/axes3d.ts +7 -42
- package/src/three/curve-plot3d.ts +0 -12
- package/src/three/plot-point3d.ts +0 -10
- package/src/three/space.ts +2 -11
- package/src/three/surface-plot3d.ts +0 -15
- package/src/three/vector-arrow3d.ts +0 -8
- package/dist/browser/chunks/chunk-IRZCG6PM.js +0 -2
- package/dist/browser/chunks/chunk-IRZCG6PM.js.map +0 -7
- package/dist/browser/chunks/chunk-WMVW6ZIV.js +0 -2
- package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +0 -7
- package/dist/kit/withdrawn.d.ts +0 -9
- package/dist/kit/withdrawn.d.ts.map +0 -1
- package/dist/kit/withdrawn.js +0 -9
- package/dist/kit/withdrawn.js.map +0 -1
- package/src/kit/withdrawn.ts +0 -8
package/src/marks/drop-lines.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
type NodeOf,
|
|
4
4
|
type NodeView,
|
|
5
|
-
type PaintProps,
|
|
6
5
|
type Vector2,
|
|
7
6
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
8
7
|
type Node2D as _Node2D,
|
|
@@ -21,11 +20,6 @@ import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mar
|
|
|
21
20
|
|
|
22
21
|
export type DropAxis = "x" | "y" | "both";
|
|
23
22
|
|
|
24
|
-
export interface DropLinesProps extends PaintProps {
|
|
25
|
-
on?: string;
|
|
26
|
-
axis?: DropAxis;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
23
|
const state = {
|
|
30
24
|
...omit(PAINT, "fill"),
|
|
31
25
|
/** A plot to take the point's height from, by id. */
|
package/src/marks/plot-point.ts
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
4
|
Types,
|
|
5
|
-
type Color,
|
|
6
5
|
type NodeOf,
|
|
6
|
+
type Color as _Color,
|
|
7
|
+
|
|
7
8
|
type NormalizedColor,
|
|
8
|
-
type PaintProps,
|
|
9
9
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
10
10
|
type Fill as _Fill,
|
|
11
11
|
type FillResolved as _FillResolved,
|
|
@@ -23,16 +23,6 @@ import { curveFor, PLANE_ENTRY, PLOT_REF, type GraphPlane } from "../kit/graph";
|
|
|
23
23
|
import { strokeShape } from "../kit/mark";
|
|
24
24
|
import { anchored } from "../kit/place";
|
|
25
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
26
|
const state = {
|
|
37
27
|
// A dot has no outline worth trimming.
|
|
38
28
|
...omit(PAINT, "start", "end"),
|
package/src/marks/riemann-sum.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Types,
|
|
4
4
|
type NodeOf,
|
|
5
5
|
type NodeView,
|
|
6
|
-
type PaintProps,
|
|
7
6
|
type Vector2,
|
|
8
7
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
9
8
|
type Fill as _Fill,
|
|
@@ -18,20 +17,13 @@ import {
|
|
|
18
17
|
import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
19
18
|
import type { Interval } from "../kit/coords";
|
|
20
19
|
import { curveValue } from "../kit/curve";
|
|
21
|
-
import {
|
|
20
|
+
import { intervalEntry, PLOT_COLOR } from "../kit/furniture";
|
|
22
21
|
import { clamp } from "../kit/geometry";
|
|
23
22
|
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph";
|
|
24
23
|
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
25
24
|
|
|
26
25
|
export type RiemannSample = "left" | "right" | "center";
|
|
27
26
|
|
|
28
|
-
export interface RiemannSumProps extends PaintProps {
|
|
29
|
-
on?: string;
|
|
30
|
-
domain?: Interval;
|
|
31
|
-
dx?: number;
|
|
32
|
-
sample?: RiemannSample;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
27
|
/** More rectangles than this is a filled area with extra steps. */
|
|
36
28
|
const MAX_RECTANGLES = 2000;
|
|
37
29
|
|
|
@@ -39,7 +31,7 @@ const state = {
|
|
|
39
31
|
// Its rectangles are revealed by `dx`, not by trimming their outlines.
|
|
40
32
|
...omit(PAINT, "start", "end"),
|
|
41
33
|
on: PLOT_REF,
|
|
42
|
-
domain:
|
|
34
|
+
domain: intervalEntry([0, 1]),
|
|
43
35
|
/** Each rectangle's width, in graph units. */
|
|
44
36
|
dx: Types.number(0.25, { min: 0.001 }),
|
|
45
37
|
/** Where in its width a rectangle reads the curve's height. */
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Types,
|
|
4
4
|
type NodeOf,
|
|
5
5
|
type NodeView,
|
|
6
|
-
type PaintProps,
|
|
7
6
|
type Vector2,
|
|
8
7
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
9
8
|
type Node2D as _Node2D,
|
|
@@ -18,13 +17,6 @@ import { curveValue, type CurveValues } from "../kit/curve";
|
|
|
18
17
|
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph";
|
|
19
18
|
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
20
19
|
|
|
21
|
-
export interface TangentLineProps extends PaintProps {
|
|
22
|
-
on?: string;
|
|
23
|
-
length?: number;
|
|
24
|
-
dx?: number;
|
|
25
|
-
legs?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
20
|
/** The step a slope is measured over, as a share of the system's width. */
|
|
29
21
|
const SLOPE_STEP = 1e-4;
|
|
30
22
|
|
|
@@ -48,11 +40,7 @@ interface TangentValues {
|
|
|
48
40
|
readonly legs: boolean;
|
|
49
41
|
}
|
|
50
42
|
|
|
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
|
-
*/
|
|
43
|
+
/** The tangent to a plot at this node's `x`, a fixed length on screen; with a `dx`, the secant through `x` and `x + dx`. */
|
|
56
44
|
export const TangentLine = traced(component2d({
|
|
57
45
|
key: "tangentLine",
|
|
58
46
|
state,
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Types,
|
|
4
4
|
type NodeOf,
|
|
5
|
-
type PaintProps,
|
|
6
5
|
type Vector2,
|
|
7
6
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
8
7
|
type Node2D as _Node2D,
|
|
@@ -13,15 +12,10 @@ import {
|
|
|
13
12
|
type StrokeResolved as _StrokeResolved,
|
|
14
13
|
} from "@motionscript/sdk";
|
|
15
14
|
import { omit, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
15
|
+
import { radians } from "../kit/geometry";
|
|
16
16
|
import { PLANE_ENTRY } from "../kit/graph";
|
|
17
17
|
import { drawMark, graphPoint, inkSize, ownPoint, reading, traced, type MarkReading, type MarkState } from "../kit/mark";
|
|
18
18
|
|
|
19
|
-
export interface VectorArrowProps extends PaintProps {
|
|
20
|
-
tail?: Vector2;
|
|
21
|
-
head?: Vector2;
|
|
22
|
-
bend?: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
19
|
/** Degrees of arc per drawn segment of a bent arrow. */
|
|
26
20
|
const BEND_STEP = 4;
|
|
27
21
|
|
|
@@ -52,11 +46,7 @@ const end = (which: "tail" | "head") => ({
|
|
|
52
46
|
},
|
|
53
47
|
});
|
|
54
48
|
|
|
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
|
-
*/
|
|
49
|
+
/** An arrow from `tail` to `head`, two graph points; its arrowhead is the stroke's `endCap`. (Not `from`/`to`: every node has a `to`.) */
|
|
60
50
|
export const VectorArrow = traced(component2d({
|
|
61
51
|
key: "vectorArrow",
|
|
62
52
|
state,
|
|
@@ -76,7 +66,7 @@ export type VectorArrow = NodeOf<typeof VectorArrow>;
|
|
|
76
66
|
function traceArrow(s: ArrowValues, { map, shift }: MarkReading): Vector2[][] {
|
|
77
67
|
const a = map.toPoint(s.tail.x + shift.x, s.tail.y + shift.y);
|
|
78
68
|
const b = map.toPoint(s.head.x + shift.x, s.head.y + shift.y);
|
|
79
|
-
const sweep = (s.bend
|
|
69
|
+
const sweep = radians(s.bend);
|
|
80
70
|
const chord = Math.hypot(b.x - a.x, b.y - a.y);
|
|
81
71
|
if (Math.abs(sweep) < 1e-3 || chord === 0) return [[a, b]];
|
|
82
72
|
|
package/src/nodes.ts
CHANGED
|
@@ -26,18 +26,7 @@ import { PlotPoint3d } from "./three/plot-point3d";
|
|
|
26
26
|
import { SurfacePlot3d } from "./three/surface-plot3d";
|
|
27
27
|
import { VectorArrow3d } from "./three/vector-arrow3d";
|
|
28
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
|
-
*/
|
|
29
|
+
/** Every node type this package publishes, for `new Engine(platform, { nodes: NODES })`. Listing the values survives `sideEffects: false` bundling. */
|
|
41
30
|
// Typed by name, so the declaration names each component rather than spelling out its type through core.
|
|
42
31
|
type KitNode =
|
|
43
32
|
| typeof Latex
|
|
@@ -66,17 +66,12 @@ export const PLOT_COMMANDS = {
|
|
|
66
66
|
|
|
67
67
|
export const PLOT_STROKE = { weight: 3, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" } as const;
|
|
68
68
|
|
|
69
|
-
/** What a plot's curve is drawn from. */
|
|
70
69
|
export interface PlotValues {
|
|
71
70
|
readonly expression: PlotSource;
|
|
72
71
|
readonly params: ExpressionScope;
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
/**
|
|
76
|
-
* The curve of an equation, drawn in the coordinate system it is a child of.
|
|
77
|
-
* How the equation is written says what it is: see `Equation`. A mark put
|
|
78
|
-
* inside it reads it: the area under it, a tangent, a point that rides it.
|
|
79
|
-
*/
|
|
74
|
+
/** The curve of an equation, drawn in the system it is a child of; a mark put inside it reads it. */
|
|
80
75
|
export const FunctionPlot = traced(component2d({
|
|
81
76
|
key: "functionPlot",
|
|
82
77
|
state: PLOT_STATE,
|
package/src/plots/points-plot.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Types,
|
|
4
4
|
type NodeOf,
|
|
5
|
-
type PaintProps,
|
|
6
5
|
type Vector2,
|
|
7
6
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
8
7
|
type Fill as _Fill,
|
|
@@ -19,12 +18,6 @@ import { PLOT_COLOR } from "../kit/furniture";
|
|
|
19
18
|
import { PLANE_ENTRY } from "../kit/graph";
|
|
20
19
|
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
21
20
|
|
|
22
|
-
export interface PointsPlotProps extends PaintProps {
|
|
23
|
-
points?: Vector2[];
|
|
24
|
-
closed?: boolean;
|
|
25
|
-
smooth?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
21
|
// A shorter list is padded with its own last point, so a line grows new points out of its end.
|
|
29
22
|
function lerpPoints(from: Vector2[], to: Vector2[], t: number): Vector2[] {
|
|
30
23
|
const count = Math.max(from.length, to.length);
|
|
@@ -14,18 +14,11 @@ import {
|
|
|
14
14
|
type StrokeResolved as _StrokeResolved,
|
|
15
15
|
} from "@motionscript/sdk";
|
|
16
16
|
import type { CoordinateMap } from "../kit/coords";
|
|
17
|
-
import { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type
|
|
17
|
+
import { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldSampler, type FieldStroke, type FieldValues } from "../kit/field-mark";
|
|
18
18
|
import { PLOT_COLOR } from "../kit/furniture";
|
|
19
19
|
import { clamp } from "../kit/geometry";
|
|
20
20
|
import { inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
21
21
|
|
|
22
|
-
export interface StreamLinesProps extends FieldProps {
|
|
23
|
-
spacing?: number;
|
|
24
|
-
length?: number;
|
|
25
|
-
window?: number;
|
|
26
|
-
phase?: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
22
|
const MAX_LINES = 1600;
|
|
30
23
|
/** Steps a line takes across one spacing: what keeps a tight swirl round. */
|
|
31
24
|
const STEPS_PER_SPACING = 8;
|
package/src/plots/traced-path.ts
CHANGED
|
@@ -13,13 +13,7 @@ import {
|
|
|
13
13
|
import { omit } from "../kit/component";
|
|
14
14
|
import type { Interval } from "../kit/coords";
|
|
15
15
|
import { drawMark, inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
16
|
-
import { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot, type
|
|
17
|
-
|
|
18
|
-
export interface TracedPathProps extends FunctionPlotProps {
|
|
19
|
-
from?: number;
|
|
20
|
-
value?: number;
|
|
21
|
-
tail?: number;
|
|
22
|
-
}
|
|
16
|
+
import { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot, type PlotValues } from "./function-plot";
|
|
23
17
|
|
|
24
18
|
const state = {
|
|
25
19
|
// It reveals itself by its value, so it trims no outline of its own.
|
|
@@ -38,12 +32,7 @@ interface TrailValues extends PlotValues {
|
|
|
38
32
|
readonly tail: number;
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
/**
|
|
42
|
-
* The trail a point leaves as a value changes: the curve of its equation from
|
|
43
|
-
* where the value began to where it is now. Bind `value` to a variable
|
|
44
|
-
* (`"=[t]"`) and the trail grows as the variable is driven, or drive it with
|
|
45
|
-
* `traceTo`; a `tail` keeps only its most recent stretch.
|
|
46
|
-
*/
|
|
35
|
+
/** The trail a point leaves as a value changes: the curve of its equation from where the value began to where it is. */
|
|
47
36
|
export const TracedPath = traced(component2d({
|
|
48
37
|
key: "tracedPath",
|
|
49
38
|
state,
|
|
@@ -14,21 +14,17 @@ import {
|
|
|
14
14
|
type StrokeResolved as _StrokeResolved,
|
|
15
15
|
} from "@motionscript/sdk";
|
|
16
16
|
import type { CoordinateMap } from "../kit/coords";
|
|
17
|
-
import { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type
|
|
17
|
+
import { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldValues, type FieldSampler, type FieldStroke } from "../kit/field-mark";
|
|
18
18
|
import { PLOT_COLOR } from "../kit/furniture";
|
|
19
|
+
import { radians } from "../kit/geometry";
|
|
19
20
|
import { inkSize, reading, traced, type MarkReading } from "../kit/mark";
|
|
20
21
|
|
|
21
|
-
export interface VectorFieldProps extends FieldProps {
|
|
22
|
-
spacing?: number;
|
|
23
|
-
arrowScale?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
22
|
/** Past this many arrows the spacing is widened, so a field over a huge range is still a field and not a wash. */
|
|
27
23
|
const MAX_ARROWS = 2400;
|
|
28
24
|
/** An arrow's head, as a share of its length and in pixels at most, and the half-angle it opens to. */
|
|
29
25
|
const HEAD_SHARE = 0.38;
|
|
30
26
|
const HEAD_MAX = 11;
|
|
31
|
-
const HEAD_ANGLE = (26
|
|
27
|
+
const HEAD_ANGLE = radians(26);
|
|
32
28
|
|
|
33
29
|
const state = {
|
|
34
30
|
...FIELD_STATE,
|
|
@@ -50,11 +46,7 @@ const ARROWS: FieldDrawing<ArrowsValues> = {
|
|
|
50
46
|
|
|
51
47
|
const traceArrows = (s: ArrowsValues, read: MarkReading) => traceField("vectorField", ARROWS, s, read);
|
|
52
48
|
|
|
53
|
-
/**
|
|
54
|
-
* A grid of arrows showing a vector field, two parts in x and y: `(-y, x)`.
|
|
55
|
-
* Each arrow is centred on its point and is as long as the field is strong
|
|
56
|
-
* there, up to the spacing.
|
|
57
|
-
*/
|
|
49
|
+
/** A grid of arrows showing a vector field, `(-y, x)`: each is centred on its point and as long as the field is strong there, up to the spacing. */
|
|
58
50
|
export const VectorField = traced(component2d({
|
|
59
51
|
key: "vectorField",
|
|
60
52
|
state,
|
|
@@ -2,16 +2,17 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
4
|
Types,
|
|
5
|
-
type Color,
|
|
6
5
|
type Fill,
|
|
7
6
|
type FillResolved,
|
|
8
7
|
type NodeOf,
|
|
8
|
+
type Color as _Color,
|
|
9
|
+
|
|
9
10
|
type NormalizedColor,
|
|
10
|
-
type PaintProps,
|
|
11
11
|
type RenderContext,
|
|
12
12
|
type ShadowResolved,
|
|
13
13
|
type Size2D,
|
|
14
|
-
type Stroke,
|
|
14
|
+
type Stroke as _Stroke,
|
|
15
|
+
|
|
15
16
|
type StrokeResolved,
|
|
16
17
|
type Values,
|
|
17
18
|
type Vector2,
|
|
@@ -33,22 +34,6 @@ export interface GraphPosition {
|
|
|
33
34
|
y: number;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export interface NetworkGraphProps extends PaintProps {
|
|
37
|
-
vertices?: string[];
|
|
38
|
-
edges?: GraphEdge[];
|
|
39
|
-
directed?: boolean;
|
|
40
|
-
arrangement?: GraphLayout;
|
|
41
|
-
root?: string;
|
|
42
|
-
positions?: GraphPosition[];
|
|
43
|
-
vertexRadius?: number;
|
|
44
|
-
vertexStroke?: Stroke;
|
|
45
|
-
labels?: boolean;
|
|
46
|
-
labelSize?: number;
|
|
47
|
-
labelColor?: Color;
|
|
48
|
-
fontFamily?: string;
|
|
49
|
-
partFills?: PartFill[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
37
|
// Every list keeps each entry as it was written, a blank or a repeat included, so
|
|
53
38
|
// an editor showing the list shows the row it just added. What is drawn skips
|
|
54
39
|
// what is not complete yet (`names`, `links`).
|
|
@@ -99,15 +84,11 @@ const state = {
|
|
|
99
84
|
layoutMix: Types.number(1, { private: true }),
|
|
100
85
|
};
|
|
101
86
|
|
|
102
|
-
/** What a graph is drawn from: its own entries, as its fields and its node both read them. */
|
|
103
87
|
export type GraphValues = Values<typeof state>;
|
|
104
88
|
|
|
105
89
|
/**
|
|
106
|
-
* Vertices and the edges between them, arranged by a rule
|
|
107
|
-
*
|
|
108
|
-
* its `stroke` the edges, with an arrowhead each when `directed`. `arrangeTo`
|
|
109
|
-
* moves every vertex to where another rule places it; `partFillTo` paints a
|
|
110
|
-
* vertex, or an edge written `a-b`. (`layout` is every node's own box.)
|
|
90
|
+
* Vertices and the edges between them, arranged by a rule (circle, springs, tree,
|
|
91
|
+
* grid). Its `fill` is the vertices and its `stroke` the edges. (`layout` is every node's own box.)
|
|
111
92
|
*/
|
|
112
93
|
export const NetworkGraph = component2d({
|
|
113
94
|
key: "networkGraph",
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
fillOps,
|
|
4
4
|
Graphics2D,
|
|
5
5
|
Types,
|
|
6
|
-
type Color,
|
|
7
6
|
type Fill,
|
|
8
7
|
type FillResolved,
|
|
9
8
|
type NodeOf,
|
|
9
|
+
type Color as _Color,
|
|
10
|
+
|
|
10
11
|
type NormalizedColor,
|
|
11
|
-
type PaintProps,
|
|
12
12
|
type RenderContext,
|
|
13
13
|
type ShadowResolved,
|
|
14
14
|
type Size2D,
|
|
@@ -27,18 +27,6 @@ import { drawLabels, loadFormulas, type Label } from "../kit/furniture";
|
|
|
27
27
|
import { lerpFillScale, readFillScale } from "../kit/scale";
|
|
28
28
|
import { formatTick } from "../kit/ticks";
|
|
29
29
|
|
|
30
|
-
export interface SampleSpaceProps extends PaintProps {
|
|
31
|
-
columnShares?: number[];
|
|
32
|
-
rowShares?: number[];
|
|
33
|
-
columnFills?: Fill[];
|
|
34
|
-
columnLabels?: string[];
|
|
35
|
-
rowLabels?: string[];
|
|
36
|
-
values?: boolean;
|
|
37
|
-
labelSize?: number;
|
|
38
|
-
labelColor?: Color;
|
|
39
|
-
fontFamily?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
30
|
/** The parts' paints until told otherwise, a column each, round again past the last. */
|
|
43
31
|
const PALETTE = ["#58a6ff", "#f59e0b", "#4ade80", "#f472b6", "#a78bfa", "#2dd4bf"];
|
|
44
32
|
|
|
@@ -74,7 +62,6 @@ const state = {
|
|
|
74
62
|
fontFamily: Types.text("", { animatable: false }),
|
|
75
63
|
};
|
|
76
64
|
|
|
77
|
-
/** What a sample space is drawn from: its own entries, as its fields and its node both read them. */
|
|
78
65
|
export type SampleSpaceValues = Values<typeof state>;
|
|
79
66
|
|
|
80
67
|
/** One part of a sample space: its box in pixels from the node's centre, y up, and its probability. */
|
|
@@ -89,11 +76,9 @@ export interface SamplePart {
|
|
|
89
76
|
}
|
|
90
77
|
|
|
91
78
|
/**
|
|
92
|
-
* A probability's whole
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* Braces name the columns below and the rows on the left; `divideTo` moves the
|
|
96
|
-
* cuts.
|
|
79
|
+
* A probability's whole as a box cut into columns by `columnShares`, each cut
|
|
80
|
+
* again by its `rowShares` entry (P(B | A) above, the rest below): each part's
|
|
81
|
+
* area is its probability.
|
|
97
82
|
*/
|
|
98
83
|
export const SampleSpace = component2d({
|
|
99
84
|
key: "sampleSpace",
|
package/src/systems/axes2d.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { cartesianMap, lineThrough, resolveInterval, type AxisScaling, type Coor
|
|
|
26
26
|
import { clamp } from "../kit/geometry";
|
|
27
27
|
import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
|
|
28
28
|
import { formatTick, ticksFor, type Ticks } from "../kit/ticks";
|
|
29
|
-
import { along, AXIS_COLOR, drawLabels, drawn, loadFormulas, type Label,
|
|
29
|
+
import { along, AXIS_COLOR, drawLabels, drawn, loadFormulas, intervalEntry, type Label, withoutTips } from "../kit/furniture";
|
|
30
30
|
|
|
31
31
|
export interface Axes2dProps extends PaintProps {
|
|
32
32
|
xRange?: Interval;
|
|
@@ -59,13 +59,11 @@ export interface AxisLayout {
|
|
|
59
59
|
at(value: number): Vector2;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const interval = (initial: Interval) => Types.custom<Interval>(initial, { resolve: readInterval, lerp: lerpInterval });
|
|
63
|
-
|
|
64
62
|
/** An x and a y axis's entries: what a number plane is built on too. */
|
|
65
63
|
export const AXES = {
|
|
66
64
|
...PAINT,
|
|
67
|
-
xRange:
|
|
68
|
-
yRange:
|
|
65
|
+
xRange: intervalEntry([-5, 5]),
|
|
66
|
+
yRange: intervalEntry([-3, 3]),
|
|
69
67
|
/** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */
|
|
70
68
|
xStep: Types.number(0, { min: 0 }),
|
|
71
69
|
yStep: Types.number(0, { min: 0 }),
|
|
@@ -91,7 +89,6 @@ export const AXES_COMMANDS = {
|
|
|
91
89
|
rangeTo: { args: ["xRange", "yRange"] as const },
|
|
92
90
|
};
|
|
93
91
|
|
|
94
|
-
/** What axes are drawn from: their own entries, as a number plane's helpers read them too. */
|
|
95
92
|
export type AxesValues = Values<typeof AXES> & { readonly padding: InsetsResolved; readonly clip: boolean };
|
|
96
93
|
|
|
97
94
|
/** What axes declare before they are laid out: their face, and MathJax for a title written as a formula. */
|
|
@@ -2,11 +2,10 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
4
|
Types,
|
|
5
|
-
type Color,
|
|
6
5
|
type Extents,
|
|
7
6
|
type NodeOf,
|
|
7
|
+
type Color as _Color,
|
|
8
8
|
type NormalizedColor,
|
|
9
|
-
type PaintProps,
|
|
10
9
|
type StrokeResolved,
|
|
11
10
|
type Values,
|
|
12
11
|
type Vector2,
|
|
@@ -20,29 +19,14 @@ import {
|
|
|
20
19
|
type Stroke as _Stroke,
|
|
21
20
|
} from "@motionscript/sdk";
|
|
22
21
|
import { listed, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
23
|
-
import { cartesianMap, resolveInterval, type
|
|
24
|
-
import { along, AXIS_COLOR, drawLabels, drawn,
|
|
22
|
+
import { cartesianMap, resolveInterval, type CoordinateMap } from "../kit/coords";
|
|
23
|
+
import { along, AXIS_COLOR, drawLabels, drawn, intervalEntry, withoutTips, type Label } from "../kit/furniture";
|
|
25
24
|
import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
|
|
26
25
|
import { formatTick, ticksFor } from "../kit/ticks";
|
|
27
26
|
|
|
28
|
-
export interface NumberLineProps extends PaintProps {
|
|
29
|
-
range?: Interval;
|
|
30
|
-
step?: number;
|
|
31
|
-
scaling?: AxisScaling;
|
|
32
|
-
ticks?: boolean;
|
|
33
|
-
tickSize?: number;
|
|
34
|
-
longTicks?: number[];
|
|
35
|
-
labels?: boolean;
|
|
36
|
-
labelExclude?: number[];
|
|
37
|
-
labelSide?: "below" | "above";
|
|
38
|
-
labelSize?: number;
|
|
39
|
-
labelColor?: Color;
|
|
40
|
-
fontFamily?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
27
|
const state = {
|
|
44
28
|
...PAINT,
|
|
45
|
-
range:
|
|
29
|
+
range: intervalEntry([-5, 5]),
|
|
46
30
|
/** The spacing of the ticks; zero picks a tidy one for the line's length. */
|
|
47
31
|
step: Types.number(0, { min: 0 }),
|
|
48
32
|
scaling: listed(["linear", "log"], "linear", { animatable: false }),
|
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
Types,
|
|
5
5
|
type Extents,
|
|
6
6
|
type NodeOf,
|
|
7
|
-
type Stroke,
|
|
7
|
+
type Stroke as _Stroke,
|
|
8
|
+
|
|
8
9
|
type StrokeResolved,
|
|
9
10
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
10
11
|
type Color as _Color,
|
|
@@ -31,17 +32,7 @@ import { fieldParams, parseField } from "../kit/field";
|
|
|
31
32
|
import { AXIS_COLOR } from "../kit/furniture";
|
|
32
33
|
import { lerpSource, readSource, type PlotSource } from "../kit/source";
|
|
33
34
|
import { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
|
|
34
|
-
import { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type
|
|
35
|
-
|
|
36
|
-
export interface NumberPlaneProps extends Axes2dProps {
|
|
37
|
-
grid?: boolean;
|
|
38
|
-
gridStroke?: Stroke;
|
|
39
|
-
minorStroke?: Stroke;
|
|
40
|
-
minorDivisions?: number;
|
|
41
|
-
matrix?: Matrix2 | readonly (readonly number[])[];
|
|
42
|
-
warp?: string | PlotSource;
|
|
43
|
-
ghost?: boolean;
|
|
44
|
-
}
|
|
35
|
+
import { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type AxesValues, type AxisLayout } from "./axes2d";
|
|
45
36
|
|
|
46
37
|
const state = {
|
|
47
38
|
...AXES,
|
|
@@ -73,13 +64,7 @@ type PlaneValues = AxesValues & {
|
|
|
73
64
|
readonly ghost: boolean;
|
|
74
65
|
};
|
|
75
66
|
|
|
76
|
-
/**
|
|
77
|
-
* Axes over a full grid, with square units unless told otherwise: the plane
|
|
78
|
-
* vectors and transformations are drawn on. Its `matrix` shears, turns or
|
|
79
|
-
* squeezes the whole plane about its origin, and its `warp` bends it by a
|
|
80
|
-
* function of its own points; the grid, the axes and everything on the plane
|
|
81
|
-
* go with it.
|
|
82
|
-
*/
|
|
67
|
+
/** Axes over a full grid with square units: the plane vectors and transformations are drawn on. `matrix` and `warp` move the grid, the axes and everything on the plane. */
|
|
83
68
|
export const NumberPlane = component2d({
|
|
84
69
|
key: "numberPlane",
|
|
85
70
|
state,
|
|
@@ -2,12 +2,13 @@ import {
|
|
|
2
2
|
component2d,
|
|
3
3
|
Graphics2D,
|
|
4
4
|
Types,
|
|
5
|
-
type Color,
|
|
6
5
|
type Extents,
|
|
7
6
|
type NodeOf,
|
|
7
|
+
type Color as _Color,
|
|
8
|
+
|
|
8
9
|
type NormalizedColor,
|
|
9
|
-
type
|
|
10
|
-
|
|
10
|
+
type Stroke as _Stroke,
|
|
11
|
+
|
|
11
12
|
type StrokeResolved,
|
|
12
13
|
type Values,
|
|
13
14
|
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
@@ -21,21 +22,10 @@ import {
|
|
|
21
22
|
import { listed, PAINT, PAINT_COMMANDS } from "../kit/component";
|
|
22
23
|
import { cartesianMap, type CoordinateMap } from "../kit/coords";
|
|
23
24
|
import { AXIS_COLOR, drawLabels, type Label } from "../kit/furniture";
|
|
25
|
+
import { radians } from "../kit/geometry";
|
|
24
26
|
import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system";
|
|
25
27
|
import { formatTick, ticksFor } from "../kit/ticks";
|
|
26
28
|
|
|
27
|
-
export interface PolarPlaneProps extends PaintProps {
|
|
28
|
-
radius?: number;
|
|
29
|
-
ringStep?: number;
|
|
30
|
-
spokes?: number;
|
|
31
|
-
angleUnit?: "degrees" | "radians";
|
|
32
|
-
gridStroke?: Stroke;
|
|
33
|
-
labels?: boolean;
|
|
34
|
-
labelSize?: number;
|
|
35
|
-
labelColor?: Color;
|
|
36
|
-
fontFamily?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
29
|
/** How much room, in label sizes, the angles written round the outer ring take from the plane. */
|
|
40
30
|
const LABEL_ROOM = 2.2;
|
|
41
31
|
|
|
@@ -59,11 +49,7 @@ const state = {
|
|
|
59
49
|
|
|
60
50
|
type PolarValues = Values<typeof state>;
|
|
61
51
|
|
|
62
|
-
/**
|
|
63
|
-
* Rings and spokes about an origin: the plane a polar curve is read on.
|
|
64
|
-
* Children sit in its graph coordinates, x and y in the units its rings count,
|
|
65
|
-
* so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
|
|
66
|
-
*/
|
|
52
|
+
/** Rings and spokes about an origin: the plane a polar curve is read on. Children sit in its graph coordinates, as on axes. */
|
|
67
53
|
export const PolarPlane = component2d({
|
|
68
54
|
key: "polarPlane",
|
|
69
55
|
state,
|
|
@@ -107,7 +93,7 @@ function polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {
|
|
|
107
93
|
const reach = map.toPoint(radius, 0).x - centre.x;
|
|
108
94
|
if (!(reach > 0)) return [];
|
|
109
95
|
const at = (r: number, degrees: number) => {
|
|
110
|
-
const angle = (degrees
|
|
96
|
+
const angle = radians(degrees);
|
|
111
97
|
return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
|
|
112
98
|
};
|
|
113
99
|
const ring = (g: Graphics2D, r: number): Graphics2D => {
|
|
@@ -148,10 +134,10 @@ function polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {
|
|
|
148
134
|
}
|
|
149
135
|
for (const degrees of turns) {
|
|
150
136
|
const p = at(radius, degrees);
|
|
151
|
-
const cos = Math.cos((degrees
|
|
152
|
-
const sin = Math.sin((degrees
|
|
137
|
+
const cos = Math.cos(radians(degrees));
|
|
138
|
+
const sin = Math.sin(radians(degrees));
|
|
153
139
|
labels.push({
|
|
154
|
-
text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` :
|
|
140
|
+
text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radiansLabel(degrees),
|
|
155
141
|
at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
|
|
156
142
|
align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
|
|
157
143
|
});
|
|
@@ -161,7 +147,7 @@ function polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {
|
|
|
161
147
|
}
|
|
162
148
|
|
|
163
149
|
/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
|
|
164
|
-
function
|
|
150
|
+
function radiansLabel(degrees: number): string {
|
|
165
151
|
if (degrees === 0) return "0";
|
|
166
152
|
let numerator = Math.round(degrees);
|
|
167
153
|
let denominator = 180;
|