@motionscript/math 0.0.0-stage → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +92 -0
- package/LICENSE +201 -0
- package/NOTICE +48 -0
- package/README.md +385 -3
- package/dist/annotate/angle-mark.d.ts +46 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +132 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +46 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +114 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +20 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +81 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.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 +64 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +42 -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/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 +17 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +22 -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 +58 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +129 -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 +71 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +159 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +30 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +87 -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/mark.d.ts +47 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +103 -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 +18 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +68 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/placement.d.ts +8 -0
- package/dist/kit/placement.d.ts.map +1 -0
- package/dist/kit/placement.js +8 -0
- package/dist/kit/placement.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 +33 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +67 -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 +32 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +82 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +22 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +58 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +35 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +97 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +37 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +91 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +27 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +103 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +32 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +87 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +35 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +63 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +67 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +215 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +28 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +99 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +35 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +141 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +31 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +56 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +23 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +91 -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 +83 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +289 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +62 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +199 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +75 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +193 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +49 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +127 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +59 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +193 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +48 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +165 -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 +9 -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 +31 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +73 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +215 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +595 -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/three/axes3d.d.ts +87 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +228 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +60 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +143 -0
- package/dist/three/curve-plot3d.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 +40 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +26 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +60 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +28 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +47 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +80 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +290 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +25 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +72 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +79 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +147 -0
- package/src/annotate/curly-brace.ts +126 -0
- package/src/annotate/emphasis-mark.ts +89 -0
- package/src/engine.ts +72 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +29 -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 +155 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +203 -0
- package/src/kit/furniture.ts +108 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/mark.ts +131 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +101 -0
- package/src/kit/placement.ts +8 -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 +99 -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 +63 -0
- package/src/marks/plot-point.ts +107 -0
- package/src/marks/riemann-sum.ts +98 -0
- package/src/marks/tangent-line.ts +103 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +63 -0
- package/src/plots/function-plot.ts +236 -0
- package/src/plots/points-plot.ts +107 -0
- package/src/plots/stream-lines.ts +151 -0
- package/src/plots/traced-path.ts +52 -0
- package/src/plots/vector-field.ts +88 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +308 -0
- package/src/structures/sample-space.ts +209 -0
- package/src/systems/axes2d.ts +217 -0
- package/src/systems/number-line.ts +131 -0
- package/src/systems/number-plane.ts +203 -0
- package/src/systems/polar-plane.ts +176 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +14 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +75 -0
- package/src/tex/node.ts +641 -0
- package/src/tex/tween.ts +308 -0
- package/src/three/axes3d.ts +240 -0
- package/src/three/curve-plot3d.ts +147 -0
- package/src/three/label3d.ts +50 -0
- package/src/three/plot-point3d.ts +66 -0
- package/src/three/space.ts +67 -0
- package/src/three/surface-plot3d.ts +323 -0
- package/src/three/vector-arrow3d.ts +77 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
colorProperty,
|
|
3
|
+
command,
|
|
4
|
+
Graphics2D,
|
|
5
|
+
node,
|
|
6
|
+
property,
|
|
7
|
+
strokeProperty,
|
|
8
|
+
type AssetScope,
|
|
9
|
+
type Color,
|
|
10
|
+
type Command,
|
|
11
|
+
type CommandArgs,
|
|
12
|
+
type Extents,
|
|
13
|
+
type NodeConfig,
|
|
14
|
+
type NormalizedColor,
|
|
15
|
+
type PaintProps,
|
|
16
|
+
type Stroke,
|
|
17
|
+
type StrokeResolved,
|
|
18
|
+
} from "@motionscript/sdk";
|
|
19
|
+
import { cartesianMap, type CoordinateMap } from "../kit/coords";
|
|
20
|
+
import { AXIS_COLOR, drawLabels, type Label } from "../kit/furniture";
|
|
21
|
+
import { stated } from "../kit/geometry";
|
|
22
|
+
import { CoordinateSystem } from "../kit/system";
|
|
23
|
+
import { formatTick, ticksFor } from "../kit/ticks";
|
|
24
|
+
|
|
25
|
+
export interface PolarPlaneProps extends PaintProps {
|
|
26
|
+
radius?: number;
|
|
27
|
+
ringStep?: number;
|
|
28
|
+
spokes?: number;
|
|
29
|
+
angleUnit?: "degrees" | "radians";
|
|
30
|
+
gridStroke?: Stroke;
|
|
31
|
+
labels?: boolean;
|
|
32
|
+
labelSize?: number;
|
|
33
|
+
labelColor?: Color;
|
|
34
|
+
fontFamily?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** How much room, in label sizes, the angles written round the outer ring take from the plane. */
|
|
38
|
+
const LABEL_ROOM = 2.2;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Rings and spokes about an origin: the plane a polar curve is read on.
|
|
42
|
+
* Children sit in its graph coordinates, x and y in the units its rings count,
|
|
43
|
+
* so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
|
|
44
|
+
*/
|
|
45
|
+
@node({
|
|
46
|
+
key: "polarPlane",
|
|
47
|
+
parentKey: "node",
|
|
48
|
+
forkable: true,
|
|
49
|
+
layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
|
|
50
|
+
seed: { width: 560, height: 560 },
|
|
51
|
+
})
|
|
52
|
+
export class PolarPlane extends CoordinateSystem<PolarPlaneProps> {
|
|
53
|
+
/** The radius of the outermost ring, in graph units. */
|
|
54
|
+
@property({ default: 4, min: 0.0001, step: 0.5 }) declare radius: number;
|
|
55
|
+
/** The spacing of the rings; zero picks a tidy one for the plane's size. */
|
|
56
|
+
@property({ default: 0, min: 0 }) declare ringStep: number;
|
|
57
|
+
/** How many spokes divide the turn; zero draws none. */
|
|
58
|
+
@property({ default: 12, min: 0, max: 72, step: 1, animatable: false }) declare spokes: number;
|
|
59
|
+
@property({ default: "degrees", options: ["degrees", "radians"], animatable: false }) declare angleUnit: "degrees" | "radians";
|
|
60
|
+
|
|
61
|
+
/** The inner rings and the spokes. */
|
|
62
|
+
@strokeProperty({ default: { weight: 1.25, fill: "#3b4658", align: "center" } }) declare gridStroke: Stroke;
|
|
63
|
+
/** The outer ring and the two lines through the origin. */
|
|
64
|
+
@strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center" } }) declare stroke: Stroke;
|
|
65
|
+
|
|
66
|
+
/** A number at each ring, and an angle at each spoke. */
|
|
67
|
+
@property({ default: true, animatable: false }) declare labels: boolean;
|
|
68
|
+
@property({ default: 16, min: 1, unit: "px" }) declare labelSize: number;
|
|
69
|
+
@colorProperty({ default: AXIS_COLOR }) declare labelColor: Color;
|
|
70
|
+
@property({ default: "", animatable: false }) declare fontFamily: string;
|
|
71
|
+
|
|
72
|
+
constructor(props?: NodeConfig<PolarPlane, PolarPlaneProps>) {
|
|
73
|
+
super(props ?? {});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Animate how far out the plane reaches: a zoom about its origin. */
|
|
77
|
+
@command({ args: ["radius"] })
|
|
78
|
+
rangeTo(args: CommandArgs<{ radius: number }> & { duration: number }): Command<PolarPlaneProps> {
|
|
79
|
+
return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override declareAssets(assets: AssetScope): void {
|
|
83
|
+
super.declareAssets(assets);
|
|
84
|
+
if (this.fontFamily !== "") assets.font(this.fontFamily);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected mapFor(area: Extents): CoordinateMap {
|
|
88
|
+
const width = area.maxX - area.minX;
|
|
89
|
+
const height = area.maxY - area.minY;
|
|
90
|
+
// The outer ring fits the shorter side, less the room its angles are written in; units are square.
|
|
91
|
+
const reach = Math.max(1, Math.min(width, height) / 2 - (this.labels ? this.labelSize * LABEL_ROOM : 0));
|
|
92
|
+
const unit = reach / Math.max(this.radius, 1e-9);
|
|
93
|
+
return cartesianMap({
|
|
94
|
+
xRange: [-width / 2 / unit, width / 2 / unit],
|
|
95
|
+
yRange: [-height / 2 / unit, height / 2 / unit],
|
|
96
|
+
area,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected furniture(map: CoordinateMap): Graphics2D[] {
|
|
101
|
+
const stroke = this.stroke as StrokeResolved[];
|
|
102
|
+
const grid = this.gridStroke as StrokeResolved[];
|
|
103
|
+
const { start, end, radius } = this;
|
|
104
|
+
const centre = map.toPoint(0, 0);
|
|
105
|
+
const reach = map.toPoint(radius, 0).x - centre.x;
|
|
106
|
+
if (!(reach > 0)) return [];
|
|
107
|
+
const at = (r: number, degrees: number) => {
|
|
108
|
+
const angle = (degrees * Math.PI) / 180;
|
|
109
|
+
return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
|
|
110
|
+
};
|
|
111
|
+
const ring = (g: Graphics2D, r: number): Graphics2D => {
|
|
112
|
+
const size = (map.toPoint(r, 0).x - centre.x) * 2;
|
|
113
|
+
return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const parts: Graphics2D[] = [];
|
|
117
|
+
const marks = ticksFor([0, radius], this.ringStep, reach);
|
|
118
|
+
const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));
|
|
119
|
+
const count = Math.round(this.spokes);
|
|
120
|
+
const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);
|
|
121
|
+
|
|
122
|
+
if (grid.length > 0) {
|
|
123
|
+
const inner = new Graphics2D();
|
|
124
|
+
for (const r of rings) ring(inner, r);
|
|
125
|
+
// The four along the axes are drawn with them.
|
|
126
|
+
for (const degrees of turns) {
|
|
127
|
+
if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });
|
|
128
|
+
}
|
|
129
|
+
if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));
|
|
130
|
+
}
|
|
131
|
+
if (stroke.length > 0) {
|
|
132
|
+
parts.push(
|
|
133
|
+
ring(new Graphics2D(), radius)
|
|
134
|
+
.line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })
|
|
135
|
+
.line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })
|
|
136
|
+
.stroke(stroke),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (!this.labels) return parts;
|
|
140
|
+
|
|
141
|
+
const size = this.labelSize;
|
|
142
|
+
const labels: Label[] = [];
|
|
143
|
+
for (const r of [...rings, radius]) {
|
|
144
|
+
const p = map.toPoint(r, 0);
|
|
145
|
+
labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: "right" });
|
|
146
|
+
}
|
|
147
|
+
for (const degrees of turns) {
|
|
148
|
+
const p = at(radius, degrees);
|
|
149
|
+
const cos = Math.cos((degrees * Math.PI) / 180);
|
|
150
|
+
const sin = Math.sin((degrees * Math.PI) / 180);
|
|
151
|
+
labels.push({
|
|
152
|
+
text: this.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
|
|
153
|
+
at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
|
|
154
|
+
align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
parts.push(...drawLabels(labels, { fontSize: size, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor }));
|
|
158
|
+
return parts;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
|
|
163
|
+
function radians(degrees: number): string {
|
|
164
|
+
if (degrees === 0) return "0";
|
|
165
|
+
let numerator = Math.round(degrees);
|
|
166
|
+
let denominator = 180;
|
|
167
|
+
for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {
|
|
168
|
+
if (b === 0) {
|
|
169
|
+
numerator /= a;
|
|
170
|
+
denominator /= a;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const top = numerator === 1 ? "π" : `${numerator}π`;
|
|
175
|
+
return denominator === 1 ? top : `${top}/${denominator}`;
|
|
176
|
+
}
|