@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,31 @@
|
|
|
1
|
+
import { Graphics2D, type ChildPlane, type ChildView, type Extents, type InsetsResolved, type Placement2D, type Provided, type RenderContext, type Shadow, type Fill, type Size2D } from "@motionscript/sdk";
|
|
2
|
+
import type { CoordinateMap } from "./coords.js";
|
|
3
|
+
/** What a system's helpers read of its state. */
|
|
4
|
+
export interface SystemState {
|
|
5
|
+
readonly padding: InsetsResolved;
|
|
6
|
+
readonly fill: Fill;
|
|
7
|
+
readonly shadow: Shadow;
|
|
8
|
+
readonly clip: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** How a system's graph values land on its plot area. */
|
|
11
|
+
export type MapFor<S> = (area: Extents, state: S) => CoordinateMap;
|
|
12
|
+
/** The plot area: the box less its padding, y-up from the box's centre. */
|
|
13
|
+
export declare function plotArea(size: Size2D, padding: InsetsResolved): Extents;
|
|
14
|
+
/** A system's map at a laid-out `size`. */
|
|
15
|
+
export declare function systemMap<S extends SystemState>(size: Size2D, state: S, mapFor: MapFor<S>): CoordinateMap;
|
|
16
|
+
/** A system is the size it is given: its children are placed in it, not measured into it. */
|
|
17
|
+
export declare function systemSize(state: SystemState): Size2D;
|
|
18
|
+
/** What a system hands its subtree: its plane, which its layout keeps current. */
|
|
19
|
+
export declare function systemProvides(state: object): readonly Provided[];
|
|
20
|
+
/** Lay a system's children out on its map. */
|
|
21
|
+
export declare function systemLayout<S extends SystemState>(size: Size2D, state: S, children: readonly ChildView[], mapFor: MapFor<S>): Placement2D[];
|
|
22
|
+
/** Where a child dropped on a system would sit. */
|
|
23
|
+
export declare function systemOpenPlane<S extends SystemState>(size: Size2D, state: S, mapFor: MapFor<S>): ChildPlane;
|
|
24
|
+
/**
|
|
25
|
+
* A system's paint: the backdrop, then the furniture under its children, kept
|
|
26
|
+
* in the plot area where the map spills from it, then the children, confined
|
|
27
|
+
* to the plot area when `clip` is set. The stroke is the axis line, drawn with
|
|
28
|
+
* the furniture: painted after the children it would land over them.
|
|
29
|
+
*/
|
|
30
|
+
export declare function drawSystem(ctx: RenderContext, state: SystemState, map: CoordinateMap, furniture: (map: CoordinateMap) => Graphics2D[]): void;
|
|
31
|
+
//# sourceMappingURL=system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.d.ts","sourceRoot":"","sources":["../../src/kit/system.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAIV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,IAAI,EACT,KAAK,MAAM,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAiB9C,iDAAiD;AACjD,MAAM,WAAW,WAAW;IACxB,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CAC1B;AAED,yDAAyD;AACzD,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,aAAa,CAAC;AAEnE,2EAA2E;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAQvE;AAED,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,aAAa,CAEzG;AAED,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAGrD;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE,CAEjE;AAED,8CAA8C;AAC9C,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,SAAS,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW,EAAE,CAM5I;AAED,mDAAmD;AACnD,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAE5G;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,UAAU,EAAE,GAAG,IAAI,CAY5I"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Graphics2D, insetsOps, Paint, provides, } from "@motionscript/sdk";
|
|
2
|
+
import { settle, SYSTEM, systemPlane } from "./graph.js";
|
|
3
|
+
import { openPlane, placeOnMap } from "./place.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a coordinate system shares: a node whose children sit in its graph
|
|
6
|
+
* coordinates. A child's `x`/`y` are in the system's units and the child keeps
|
|
7
|
+
* its own size, so anything can be put on a graph: a dot, a label, an image. A
|
|
8
|
+
* mark is drawn through the system's map instead and laid out on its ink.
|
|
9
|
+
*
|
|
10
|
+
* The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`
|
|
11
|
+
* the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a
|
|
12
|
+
* document's children would otherwise share their indices with them.
|
|
13
|
+
*/
|
|
14
|
+
const CENTRE = { x: 0, y: 0 };
|
|
15
|
+
/** The plot area: the box less its padding, y-up from the box's centre. */
|
|
16
|
+
export function plotArea(size, padding) {
|
|
17
|
+
const inner = insetsOps.insetBounds(size.width, size.height, padding);
|
|
18
|
+
return {
|
|
19
|
+
minX: inner.x - inner.width / 2,
|
|
20
|
+
maxX: inner.x + inner.width / 2,
|
|
21
|
+
minY: -inner.y - inner.height / 2,
|
|
22
|
+
maxY: -inner.y + inner.height / 2,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** A system's map at a laid-out `size`. */
|
|
26
|
+
export function systemMap(size, state, mapFor) {
|
|
27
|
+
return mapFor(plotArea(size, state.padding), state);
|
|
28
|
+
}
|
|
29
|
+
/** A system is the size it is given: its children are placed in it, not measured into it. */
|
|
30
|
+
export function systemSize(state) {
|
|
31
|
+
const { left, right, top, bottom } = state.padding;
|
|
32
|
+
return { width: left + right, height: top + bottom };
|
|
33
|
+
}
|
|
34
|
+
/** What a system hands its subtree: its plane, which its layout keeps current. */
|
|
35
|
+
export function systemProvides(state) {
|
|
36
|
+
return [provides(SYSTEM, systemPlane(state))];
|
|
37
|
+
}
|
|
38
|
+
/** Lay a system's children out on its map. */
|
|
39
|
+
export function systemLayout(size, state, children, mapFor) {
|
|
40
|
+
const map = systemMap(size, state, mapFor);
|
|
41
|
+
const plane = systemPlane(state);
|
|
42
|
+
settle(plane, map, children);
|
|
43
|
+
const inner = insetsOps.insetBounds(size.width, size.height, state.padding);
|
|
44
|
+
return placeOnMap(children, map, CENTRE, inner, plane);
|
|
45
|
+
}
|
|
46
|
+
/** Where a child dropped on a system would sit. */
|
|
47
|
+
export function systemOpenPlane(size, state, mapFor) {
|
|
48
|
+
return openPlane(systemMap(size, state, mapFor), CENTRE);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A system's paint: the backdrop, then the furniture under its children, kept
|
|
52
|
+
* in the plot area where the map spills from it, then the children, confined
|
|
53
|
+
* to the plot area when `clip` is set. The stroke is the axis line, drawn with
|
|
54
|
+
* the furniture: painted after the children it would land over them.
|
|
55
|
+
*/
|
|
56
|
+
export function drawSystem(ctx, state, map, furniture) {
|
|
57
|
+
const { width, height } = ctx.size;
|
|
58
|
+
const { minX, minY, maxX, maxY } = map.area;
|
|
59
|
+
const area = new Graphics2D().rect({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width: maxX - minX, height: maxY - minY });
|
|
60
|
+
ctx.inFront(() => {
|
|
61
|
+
ctx.draw(new Graphics2D().rect({ x: 0, y: 0, width, height }).shadow(state.shadow).fill(state.fill));
|
|
62
|
+
const parts = furniture(map);
|
|
63
|
+
if (map.spills)
|
|
64
|
+
ctx.clip(area, () => ctx.draw(parts));
|
|
65
|
+
else
|
|
66
|
+
ctx.draw(parts);
|
|
67
|
+
});
|
|
68
|
+
// No shape of its own to paint here; the plot area is what clips the children and what picking tests.
|
|
69
|
+
Paint.draw(ctx, state, null, { clipShape: area });
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../src/kit/system.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,SAAS,EACT,KAAK,EACL,QAAQ,GAYX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,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K,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC;IAC5H,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACrG,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,GAAG,CAAC,MAAM;YAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;;YACjD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IACH,sGAAsG;IACtG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,KAAoC,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACrF,CAAC","sourcesContent":["import {\n Graphics2D,\n insetsOps,\n Paint,\n provides,\n type ChildPlane,\n type ChildView,\n type Extents,\n type InsetsResolved,\n type Placement2D,\n type Provided,\n type RenderContext,\n type Shadow,\n type Fill,\n type Size2D,\n type Vector2,\n} from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"./coords\";\nimport { settle, SYSTEM, systemPlane } from \"./graph\";\nimport { openPlane, placeOnMap } from \"./place\";\n\n/**\n * What a coordinate system shares: a node whose children sit in its graph\n * coordinates. A child's `x`/`y` are in the system's units and the child keeps\n * its own size, so anything can be put on a graph: a dot, a label, an image. A\n * mark is drawn through the system's map instead and laid out on its ink.\n *\n * The system's `stroke` is its axis line (so `endCap` is the tip) and its `fill`\n * the backdrop. Ticks, grid and labels are drawing ops, never child nodes: a\n * document's children would otherwise share their indices with them.\n */\n\nconst CENTRE: Vector2 = { x: 0, y: 0 };\n\n/** What a system's helpers read of its state. */\nexport interface SystemState {\n readonly padding: InsetsResolved;\n readonly fill: Fill;\n readonly shadow: Shadow;\n readonly clip: boolean;\n}\n\n/** How a system's graph values land on its plot area. */\nexport type MapFor<S> = (area: Extents, state: S) => CoordinateMap;\n\n/** The plot area: the box less its padding, y-up from the box's centre. */\nexport function plotArea(size: Size2D, padding: InsetsResolved): Extents {\n const inner = insetsOps.insetBounds(size.width, size.height, padding);\n return {\n minX: inner.x - inner.width / 2,\n maxX: inner.x + inner.width / 2,\n minY: -inner.y - inner.height / 2,\n maxY: -inner.y + inner.height / 2,\n };\n}\n\n/** A system's map at a laid-out `size`. */\nexport function systemMap<S extends SystemState>(size: Size2D, state: S, mapFor: MapFor<S>): CoordinateMap {\n return mapFor(plotArea(size, state.padding), state);\n}\n\n/** A system is the size it is given: its children are placed in it, not measured into it. */\nexport function systemSize(state: SystemState): Size2D {\n const { left, right, top, bottom } = state.padding;\n return { width: left + right, height: top + bottom };\n}\n\n/** What a system hands its subtree: its plane, which its layout keeps current. */\nexport function systemProvides(state: object): readonly Provided[] {\n return [provides(SYSTEM, systemPlane(state))];\n}\n\n/** Lay a system's children out on its map. */\nexport function systemLayout<S extends SystemState>(size: Size2D, state: S, children: readonly ChildView[], mapFor: MapFor<S>): Placement2D[] {\n const map = systemMap(size, state, mapFor);\n const plane = systemPlane(state);\n settle(plane, map, children);\n const inner = insetsOps.insetBounds(size.width, size.height, state.padding);\n return placeOnMap(children, map, CENTRE, inner, plane);\n}\n\n/** Where a child dropped on a system would sit. */\nexport function systemOpenPlane<S extends SystemState>(size: Size2D, state: S, mapFor: MapFor<S>): ChildPlane {\n return openPlane(systemMap(size, state, mapFor), CENTRE);\n}\n\n/**\n * A system's paint: the backdrop, then the furniture under its children, kept\n * in the plot area where the map spills from it, then the children, confined\n * to the plot area when `clip` is set. The stroke is the axis line, drawn with\n * the furniture: painted after the children it would land over them.\n */\nexport function drawSystem(ctx: RenderContext, state: SystemState, map: CoordinateMap, furniture: (map: CoordinateMap) => Graphics2D[]): void {\n const { width, height } = ctx.size;\n const { minX, minY, maxX, maxY } = map.area;\n const area = new Graphics2D().rect({ x: (minX + maxX) / 2, y: (minY + maxY) / 2, width: maxX - minX, height: maxY - minY });\n ctx.inFront(() => {\n ctx.draw(new Graphics2D().rect({ x: 0, y: 0, width, height }).shadow(state.shadow).fill(state.fill));\n const parts = furniture(map);\n if (map.spills) ctx.clip(area, () => ctx.draw(parts));\n else ctx.draw(parts);\n });\n // No shape of its own to paint here; the plot area is what clips the children and what picking tests.\n Paint.draw(ctx, state as unknown as Paint.PaintState, null, { clipShape: area });\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AxisScaling, Interval } from "./coords.js";
|
|
2
|
+
/** Where an axis is marked, and the spacing its labels are rounded to. */
|
|
3
|
+
export interface Ticks {
|
|
4
|
+
values: number[];
|
|
5
|
+
step: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The marks along `range`, drawn over `length` pixels. A `step` of zero lets the
|
|
9
|
+
* axis choose a tidy one (1, 2 or 5 times a power of ten) for its size; a log
|
|
10
|
+
* axis is marked at the powers of ten whatever the step.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ticksFor(range: Interval, step: number, length: number, scaling?: AxisScaling): Ticks;
|
|
13
|
+
/**
|
|
14
|
+
* `value` as a tick label, with as many decimals as `step` needs and no more:
|
|
15
|
+
* 0.30000000000000004 on a 0.1 ladder is `0.3`. A `step` of zero (a log axis)
|
|
16
|
+
* prints the value as it is.
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatTick(value: number, step: number): string;
|
|
19
|
+
//# sourceMappingURL=ticks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticks.d.ts","sourceRoot":"","sources":["../../src/kit/ticks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEtD,0EAA0E;AAC1E,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAQD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,WAAsB,GAAG,KAAK,CAO9G;AAyBD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAa9D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { niceStep } from "@motionscript/sdk/component";
|
|
2
|
+
/** Past this an axis is not marked at all, rather than drawn as a solid bar of ticks. */
|
|
3
|
+
const MAX_TICKS = 200;
|
|
4
|
+
/** How far apart, in pixels, marks sit when the axis picks its own step. */
|
|
5
|
+
const AUTO_SPACING = 64;
|
|
6
|
+
/**
|
|
7
|
+
* The marks along `range`, drawn over `length` pixels. A `step` of zero lets the
|
|
8
|
+
* axis choose a tidy one (1, 2 or 5 times a power of ten) for its size; a log
|
|
9
|
+
* axis is marked at the powers of ten whatever the step.
|
|
10
|
+
*/
|
|
11
|
+
export function ticksFor(range, step, length, scaling = "linear") {
|
|
12
|
+
const [min, max] = range;
|
|
13
|
+
if (scaling === "log")
|
|
14
|
+
return decades(min, max);
|
|
15
|
+
const span = max - min;
|
|
16
|
+
if (!(span > 0))
|
|
17
|
+
return { values: [], step: 1 };
|
|
18
|
+
const chosen = step > 0 ? step : niceStep((AUTO_SPACING / Math.max(1, length)) * span);
|
|
19
|
+
return { values: multiplesWithin(min, max, chosen), step: chosen };
|
|
20
|
+
}
|
|
21
|
+
function decades(min, max) {
|
|
22
|
+
const values = [];
|
|
23
|
+
for (let k = Math.ceil(Math.log10(min) - 1e-9); k <= Math.floor(Math.log10(max) + 1e-9) && values.length < MAX_TICKS; k++) {
|
|
24
|
+
values.push(10 ** k);
|
|
25
|
+
}
|
|
26
|
+
return { values, step: 0 };
|
|
27
|
+
}
|
|
28
|
+
function multiplesWithin(min, max, step) {
|
|
29
|
+
const first = Math.ceil(min / step - 1e-9);
|
|
30
|
+
const last = Math.floor(max / step + 1e-9);
|
|
31
|
+
const count = last - first + 1;
|
|
32
|
+
if (!Number.isFinite(count) || count <= 0 || count > MAX_TICKS)
|
|
33
|
+
return [];
|
|
34
|
+
const out = new Array(count);
|
|
35
|
+
// Multiplied rather than accumulated, so the tenth tick of 0.1 is 1 and not 0.9999999999999999.
|
|
36
|
+
for (let i = 0; i < count; i++)
|
|
37
|
+
out[i] = (first + i) * step;
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
function decadeOf(value) {
|
|
41
|
+
return Math.floor(Math.log10(value) + 1e-12);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* `value` as a tick label, with as many decimals as `step` needs and no more:
|
|
45
|
+
* 0.30000000000000004 on a 0.1 ladder is `0.3`. A `step` of zero (a log axis)
|
|
46
|
+
* prints the value as it is.
|
|
47
|
+
*/
|
|
48
|
+
export function formatTick(value, step) {
|
|
49
|
+
if (value === 0)
|
|
50
|
+
return "0";
|
|
51
|
+
if (!Number.isFinite(value))
|
|
52
|
+
return "";
|
|
53
|
+
if (!(step > 0)) {
|
|
54
|
+
const decade = decadeOf(Math.abs(value));
|
|
55
|
+
return decade >= 6 || decade <= -5 ? trimExponent(value.toExponential(0)) : String(Number(value.toPrecision(12)));
|
|
56
|
+
}
|
|
57
|
+
const decade = decadeOf(Math.abs(value));
|
|
58
|
+
const digits = Math.max(1, decade - decadeOf(step) + 1);
|
|
59
|
+
if ((decade >= 6 || decade <= -5) && digits <= 6)
|
|
60
|
+
return trimExponent(value.toExponential(digits - 1));
|
|
61
|
+
const decimals = decimalsOf(step);
|
|
62
|
+
const text = value.toFixed(decimals);
|
|
63
|
+
return decimals > 0 ? text.replace(/\.?0+$/, "") : text;
|
|
64
|
+
}
|
|
65
|
+
/** The decimal places it takes to write `step` out: 1 for 0.5, 2 for 0.25. */
|
|
66
|
+
function decimalsOf(step) {
|
|
67
|
+
for (let d = 0; d < 12; d++) {
|
|
68
|
+
const scaled = step * 10 ** d;
|
|
69
|
+
if (Math.abs(scaled - Math.round(scaled)) < 1e-9 * Math.max(1, scaled))
|
|
70
|
+
return d;
|
|
71
|
+
}
|
|
72
|
+
return 12;
|
|
73
|
+
}
|
|
74
|
+
function trimExponent(text) {
|
|
75
|
+
const [mantissa, exponent] = text.split("e");
|
|
76
|
+
return `${mantissa.replace(/\.?0+$/, "")}e${Number(exponent)}`;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=ticks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticks.js","sourceRoot":"","sources":["../../src/kit/ticks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AASvD,yFAAyF;AACzF,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,4EAA4E;AAC5E,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAe,EAAE,IAAY,EAAE,MAAc,EAAE,UAAuB,QAAQ;IACnG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;IACzB,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;IACvB,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAChD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,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IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACvG,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,OAAO,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC;AAED,8EAA8E;AAC9E,SAAS,UAAU,CAAC,IAAY;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC;QAC9B,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC;YAAE,OAAO,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAC9B,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;AACnE,CAAC","sourcesContent":["import { niceStep } from \"@motionscript/sdk/component\";\nimport type { AxisScaling, Interval } from \"./coords\";\n\n/** Where an axis is marked, and the spacing its labels are rounded to. */\nexport interface Ticks {\n values: number[];\n step: number;\n}\n\n/** Past this an axis is not marked at all, rather than drawn as a solid bar of ticks. */\nconst MAX_TICKS = 200;\n\n/** How far apart, in pixels, marks sit when the axis picks its own step. */\nconst AUTO_SPACING = 64;\n\n/**\n * The marks along `range`, drawn over `length` pixels. A `step` of zero lets the\n * axis choose a tidy one (1, 2 or 5 times a power of ten) for its size; a log\n * axis is marked at the powers of ten whatever the step.\n */\nexport function ticksFor(range: Interval, step: number, length: number, scaling: AxisScaling = \"linear\"): Ticks {\n const [min, max] = range;\n if (scaling === \"log\") return decades(min, max);\n const span = max - min;\n if (!(span > 0)) return { values: [], step: 1 };\n const chosen = step > 0 ? step : niceStep((AUTO_SPACING / Math.max(1, length)) * span);\n return { values: multiplesWithin(min, max, chosen), step: chosen };\n}\n\nfunction decades(min: number, max: number): Ticks {\n const values: number[] = [];\n for (let k = Math.ceil(Math.log10(min) - 1e-9); k <= Math.floor(Math.log10(max) + 1e-9) && values.length < MAX_TICKS; k++) {\n values.push(10 ** k);\n }\n return { values, step: 0 };\n}\n\nfunction multiplesWithin(min: number, max: number, step: number): number[] {\n const first = Math.ceil(min / step - 1e-9);\n const last = Math.floor(max / step + 1e-9);\n const count = last - first + 1;\n if (!Number.isFinite(count) || count <= 0 || count > MAX_TICKS) return [];\n const out = new Array<number>(count);\n // Multiplied rather than accumulated, so the tenth tick of 0.1 is 1 and not 0.9999999999999999.\n for (let i = 0; i < count; i++) out[i] = (first + i) * step;\n return out;\n}\n\nfunction decadeOf(value: number): number {\n return Math.floor(Math.log10(value) + 1e-12);\n}\n\n/**\n * `value` as a tick label, with as many decimals as `step` needs and no more:\n * 0.30000000000000004 on a 0.1 ladder is `0.3`. A `step` of zero (a log axis)\n * prints the value as it is.\n */\nexport function formatTick(value: number, step: number): string {\n if (value === 0) return \"0\";\n if (!Number.isFinite(value)) return \"\";\n if (!(step > 0)) {\n const decade = decadeOf(Math.abs(value));\n return decade >= 6 || decade <= -5 ? trimExponent(value.toExponential(0)) : String(Number(value.toPrecision(12)));\n }\n const decade = decadeOf(Math.abs(value));\n const digits = Math.max(1, decade - decadeOf(step) + 1);\n if ((decade >= 6 || decade <= -5) && digits <= 6) return trimExponent(value.toExponential(digits - 1));\n const decimals = decimalsOf(step);\n const text = value.toFixed(decimals);\n return decimals > 0 ? text.replace(/\\.?0+$/, \"\") : text;\n}\n\n/** The decimal places it takes to write `step` out: 1 for 0.5, 2 for 0.25. */\nfunction decimalsOf(step: number): number {\n for (let d = 0; d < 12; d++) {\n const scaled = step * 10 ** d;\n if (Math.abs(scaled - Math.round(scaled)) < 1e-9 * Math.max(1, scaled)) return d;\n }\n return 12;\n}\n\nfunction trimExponent(text: string): string {\n const [mantissa, exponent] = text.split(\"e\");\n return `${mantissa.replace(/\\.?0+$/, \"\")}e${Number(exponent)}`;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paint entries and commands a math node may have no use for: a node that
|
|
3
|
+
* is only a line has no fill, an area no outline, and one that reveals itself
|
|
4
|
+
* in its own way no outline trim.
|
|
5
|
+
*/
|
|
6
|
+
export declare const FILL_PAINT: readonly ["fill", "fillTo"];
|
|
7
|
+
export declare const STROKE_PAINT: readonly ["stroke", "strokeTo"];
|
|
8
|
+
export declare const OUTLINE_TRIM: readonly ["start", "end", "progressTo", "flash"];
|
|
9
|
+
//# sourceMappingURL=withdrawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawn.d.ts","sourceRoot":"","sources":["../../src/kit/withdrawn.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,UAAU,6BAA8B,CAAC;AACtD,eAAO,MAAM,YAAY,iCAAkC,CAAC;AAC5D,eAAO,MAAM,YAAY,kDAAmD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The paint entries and commands a math node may have no use for: a node that
|
|
3
|
+
* is only a line has no fill, an area no outline, and one that reveals itself
|
|
4
|
+
* in its own way no outline trim.
|
|
5
|
+
*/
|
|
6
|
+
export const FILL_PAINT = ["fill", "fillTo"];
|
|
7
|
+
export const STROKE_PAINT = ["stroke", "strokeTo"];
|
|
8
|
+
export const OUTLINE_TRIM = ["start", "end", "progressTo", "flash"];
|
|
9
|
+
//# sourceMappingURL=withdrawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawn.js","sourceRoot":"","sources":["../../src/kit/withdrawn.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAU,CAAC;AACtD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAU,CAAC;AAC5D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,CAAU,CAAC","sourcesContent":["/**\n * The paint entries and commands a math node may have no use for: a node that\n * is only a line has no fill, an area no outline, and one that reveals itself\n * in its own way no outline trim.\n */\nexport const FILL_PAINT = [\"fill\", \"fillTo\"] as const;\nexport const STROKE_PAINT = [\"stroke\", \"strokeTo\"] as const;\nexport const OUTLINE_TRIM = [\"start\", \"end\", \"progressTo\", \"flash\"] as const;\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type NodeOf, type NodeView, type PaintProps, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved } from "@motionscript/sdk";
|
|
2
|
+
import type { Interval } from "../kit/coords.js";
|
|
3
|
+
export interface CurveAreaProps extends PaintProps {
|
|
4
|
+
on?: string;
|
|
5
|
+
under?: string;
|
|
6
|
+
domain?: Interval;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The region between a plot and the x axis, or between two plots, over a span
|
|
10
|
+
* of x. It sits beside the plots it reads rather than inside one: it may read
|
|
11
|
+
* two, and it has a life of its own on the timeline, swept open or kept while
|
|
12
|
+
* a curve changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CurveArea: import("@motionscript/sdk").Component<"curveArea", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
15
|
+
/** The plot that bounds the area, by id. */
|
|
16
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
17
|
+
/** A second plot to fill down to, in place of the x axis. */
|
|
18
|
+
under: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
19
|
+
domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
|
|
20
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
21
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
22
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
23
|
+
}>, {
|
|
24
|
+
readonly domainTo: readonly ["domain"];
|
|
25
|
+
readonly fillTo: readonly ["fill"];
|
|
26
|
+
readonly shadowTo: readonly ["shadow"];
|
|
27
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
28
|
+
/** The plot that bounds the area, by id. */
|
|
29
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
30
|
+
/** A second plot to fill down to, in place of the x axis. */
|
|
31
|
+
under: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
32
|
+
domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
|
|
33
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
34
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
35
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
36
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
37
|
+
/** The plot that bounds the area, by id. */
|
|
38
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
39
|
+
/** A second plot to fill down to, in place of the x axis. */
|
|
40
|
+
under: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
41
|
+
domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
|
|
42
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
43
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
44
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
45
|
+
}>, {
|
|
46
|
+
readonly domainTo: readonly ["domain"];
|
|
47
|
+
readonly fillTo: readonly ["fill"];
|
|
48
|
+
readonly shadowTo: readonly ["shadow"];
|
|
49
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
50
|
+
export type CurveArea = NodeOf<typeof CurveArea>;
|
|
51
|
+
//# sourceMappingURL=curve-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curve-area.d.ts","sourceRoot":"","sources":["../../src/marks/curve-area.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,UAAU,EAGf,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAO9C,MAAM,WAAW,cAAe,SAAQ,UAAU;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,QAAQ,CAAC;CACrB;AAmBD;;;;;GAKG;AACH,eAAO,MAAM,SAAS;IApBlB,4CAA4C;;IAE5C,6DAA6D;;;;;;;;;;;IAF7D,4CAA4C;;IAE5C,6DAA6D;;;;;;;IAF7D,4CAA4C;;IAE5C,6DAA6D;;;;;;;;;;2BA6BnD,CAAC;AAEf,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { component2d, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
|
|
3
|
+
import { curveValue } from "../kit/curve.js";
|
|
4
|
+
import { lerpInterval, PLOT_COLOR, readInterval } from "../kit/furniture.js";
|
|
5
|
+
import { clamp } from "../kit/geometry.js";
|
|
6
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
|
|
7
|
+
import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
|
|
8
|
+
const state = {
|
|
9
|
+
// An area is only its fill, and has no outline to trim.
|
|
10
|
+
...omit(PAINT, "stroke", "start", "end"),
|
|
11
|
+
/** The plot that bounds the area, by id. */
|
|
12
|
+
on: PLOT_REF,
|
|
13
|
+
/** A second plot to fill down to, in place of the x axis. */
|
|
14
|
+
under: PLOT_REF,
|
|
15
|
+
domain: Types.custom([0, 1], { resolve: readInterval, lerp: lerpInterval }),
|
|
16
|
+
graph: PLANE_ENTRY,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The region between a plot and the x axis, or between two plots, over a span
|
|
20
|
+
* of x. It sits beside the plots it reads rather than inside one: it may read
|
|
21
|
+
* two, and it has a life of its own on the timeline, swept open or kept while
|
|
22
|
+
* a curve changes.
|
|
23
|
+
*/
|
|
24
|
+
export const CurveArea = traced(component2d({
|
|
25
|
+
key: "curveArea",
|
|
26
|
+
state,
|
|
27
|
+
defaults: { fill: { type: "solid", color: PLOT_COLOR, opacity: 0.35 }, width: "hug", height: "hug" },
|
|
28
|
+
commands: {
|
|
29
|
+
...omit(PAINT_COMMANDS, "strokeTo", "progressTo", "flash"),
|
|
30
|
+
/** Animate the span of x that is filled: sweep an area open, or slide it along. */
|
|
31
|
+
domainTo: { args: ["domain"] },
|
|
32
|
+
},
|
|
33
|
+
measure: (_measurer, s) => inkSize(traceArea(s, reading(s))),
|
|
34
|
+
render: (ctx, s) => drawMark(ctx, s, traceArea(s, reading(s)), { closed: true }),
|
|
35
|
+
}), traceArea);
|
|
36
|
+
function traceArea(s, { map, plane }) {
|
|
37
|
+
const top = curveFor(plane, s.on);
|
|
38
|
+
if (!top)
|
|
39
|
+
return [];
|
|
40
|
+
const floor = curveFor(plane, s.under, false);
|
|
41
|
+
const [yMin, yMax] = map.yRange;
|
|
42
|
+
const a = Math.max(s.domain[0], map.xRange[0]);
|
|
43
|
+
const b = Math.min(s.domain[1], map.xRange[1]);
|
|
44
|
+
if (!(b > a))
|
|
45
|
+
return [];
|
|
46
|
+
const width = Math.abs(map.toPoint(b, 0).x - map.toPoint(a, 0).x);
|
|
47
|
+
const steps = Math.max(8, Math.min(600, Math.round(width / 2)));
|
|
48
|
+
// Held inside the system's range, and at the axis where a curve has no value.
|
|
49
|
+
const height = (value) => (Number.isFinite(value) ? clamp(value, yMin, yMax) : clamp(0, yMin, yMax));
|
|
50
|
+
const upper = [];
|
|
51
|
+
const lower = [];
|
|
52
|
+
for (let i = 0; i <= steps; i++) {
|
|
53
|
+
const x = a + ((b - a) * i) / steps;
|
|
54
|
+
upper.push(map.toPoint(x, height(curveValue(top, x))));
|
|
55
|
+
lower.push(map.toPoint(x, height(floor ? curveValue(floor, x) : 0)));
|
|
56
|
+
}
|
|
57
|
+
return [[...upper, ...lower.reverse()]];
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=curve-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curve-area.js","sourceRoot":"","sources":["../../src/marks/curve-area.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AAQnF,MAAM,KAAK,GAAG;IACV,wDAAwD;IACxD,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC;IACxC,4CAA4C;IAC5C,EAAE,EAAE,QAAQ;IACZ,6DAA6D;IAC7D,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,KAAK,CAAC,MAAM,CAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IACrF,KAAK,EAAE,WAAW;CACrB,CAAC;AAQF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC;IACxC,GAAG,EAAE,WAAW;IAChB,KAAK;IACL,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAA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AC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import {\n component2d,\n Types,\n type NodeOf,\n type NodeView,\n type PaintProps,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport type { Interval } from \"../kit/coords\";\nimport { curveValue } from \"../kit/curve\";\nimport { lerpInterval, PLOT_COLOR, readInterval } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport interface CurveAreaProps extends PaintProps {\n on?: string;\n under?: string;\n domain?: Interval;\n}\n\nconst state = {\n // An area is only its fill, and has no outline to trim.\n ...omit(PAINT, \"stroke\", \"start\", \"end\"),\n /** The plot that bounds the area, by id. */\n on: PLOT_REF,\n /** A second plot to fill down to, in place of the x axis. */\n under: PLOT_REF,\n domain: Types.custom<Interval>([0, 1], { resolve: readInterval, lerp: lerpInterval }),\n graph: PLANE_ENTRY,\n};\n\ninterface AreaValues {\n readonly on: NodeView | null;\n readonly under: NodeView | null;\n readonly domain: Interval;\n}\n\n/**\n * The region between a plot and the x axis, or between two plots, over a span\n * of x. It sits beside the plots it reads rather than inside one: it may read\n * two, and it has a life of its own on the timeline, swept open or kept while\n * a curve changes.\n */\nexport const CurveArea = traced(component2d({\n key: \"curveArea\",\n state,\n defaults: { fill: { type: \"solid\", color: PLOT_COLOR, opacity: 0.35 }, width: \"hug\", height: \"hug\" },\n commands: {\n ...omit(PAINT_COMMANDS, \"strokeTo\", \"progressTo\", \"flash\"),\n /** Animate the span of x that is filled: sweep an area open, or slide it along. */\n domainTo: { args: [\"domain\"] },\n },\n measure: (_measurer, s) => inkSize(traceArea(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceArea(s, reading(s)), { closed: true }),\n}), traceArea);\n\nexport type CurveArea = NodeOf<typeof CurveArea>;\n\nfunction traceArea(s: AreaValues, { map, plane }: MarkReading): Vector2[][] {\n const top = curveFor(plane, s.on);\n if (!top) return [];\n const floor = curveFor(plane, s.under, false);\n const [yMin, yMax] = map.yRange;\n const a = Math.max(s.domain[0], map.xRange[0]);\n const b = Math.min(s.domain[1], map.xRange[1]);\n if (!(b > a)) return [];\n\n const width = Math.abs(map.toPoint(b, 0).x - map.toPoint(a, 0).x);\n const steps = Math.max(8, Math.min(600, Math.round(width / 2)));\n // Held inside the system's range, and at the axis where a curve has no value.\n const height = (value: number) => (Number.isFinite(value) ? clamp(value, yMin, yMax) : clamp(0, yMin, yMax));\n const upper: Vector2[] = [];\n const lower: Vector2[] = [];\n for (let i = 0; i <= steps; i++) {\n const x = a + ((b - a) * i) / steps;\n upper.push(map.toPoint(x, height(curveValue(top, x))));\n lower.push(map.toPoint(x, height(floor ? curveValue(floor, x) : 0)));\n }\n return [[...upper, ...lower.reverse()]];\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type NodeOf, type NodeView, type PaintProps, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
export type DropAxis = "x" | "y" | "both";
|
|
3
|
+
export interface DropLinesProps extends PaintProps {
|
|
4
|
+
on?: string;
|
|
5
|
+
axis?: DropAxis;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Guide lines from a graph point to the axes, reading its coordinates off them.
|
|
9
|
+
* The point is this node's `x`/`y`, or the point of a plot above its `x`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DropLines: import("@motionscript/sdk").Component<"dropLines", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
12
|
+
/** A plot to take the point's height from, by id. */
|
|
13
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
14
|
+
/** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
|
|
15
|
+
axis: import("@motionscript/sdk").Type<"x" | "y" | "both", "x" | "y" | "both", false>;
|
|
16
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
17
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
18
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
19
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
20
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
21
|
+
}>, {
|
|
22
|
+
strokeTo: readonly ["stroke"];
|
|
23
|
+
shadowTo: readonly ["shadow"];
|
|
24
|
+
progressTo: readonly ["start", "end"];
|
|
25
|
+
flash: {
|
|
26
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
27
|
+
};
|
|
28
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
29
|
+
/** A plot to take the point's height from, by id. */
|
|
30
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
31
|
+
/** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
|
|
32
|
+
axis: import("@motionscript/sdk").Type<"x" | "y" | "both", "x" | "y" | "both", false>;
|
|
33
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
34
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
35
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
36
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
37
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
38
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
39
|
+
/** A plot to take the point's height from, by id. */
|
|
40
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
41
|
+
/** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
|
|
42
|
+
axis: import("@motionscript/sdk").Type<"x" | "y" | "both", "x" | "y" | "both", false>;
|
|
43
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
44
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
45
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
46
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
47
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
48
|
+
}>, {
|
|
49
|
+
strokeTo: readonly ["stroke"];
|
|
50
|
+
shadowTo: readonly ["shadow"];
|
|
51
|
+
progressTo: readonly ["start", "end"];
|
|
52
|
+
flash: {
|
|
53
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
54
|
+
};
|
|
55
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
56
|
+
export type DropLines = NodeOf<typeof DropLines>;
|
|
57
|
+
//# sourceMappingURL=drop-lines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-lines.d.ts","sourceRoot":"","sources":["../../src/marks/drop-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,UAAU,EAGf,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAQ3B,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC;AAE1C,MAAM,WAAW,cAAe,SAAQ,UAAU;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,QAAQ,CAAC;CACnB;AAkBD;;;GAGG;AACH,eAAO,MAAM,SAAS;IAlBlB,qDAAqD;;IAErD,kFAAkF;;;;;;;;;;;;;;;IAFlF,qDAAqD;;IAErD,kFAAkF;;;;;;;;IAFlF,qDAAqD;;IAErD,kFAAkF;;;;;;;;;;;;;;2BAuBvE,CAAC;AAEhB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { component2d, } from "@motionscript/sdk";
|
|
2
|
+
import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
|
|
3
|
+
import { curveValue } from "../kit/curve.js";
|
|
4
|
+
import { AXIS_COLOR } from "../kit/furniture.js";
|
|
5
|
+
import { clamp } from "../kit/geometry.js";
|
|
6
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
|
|
7
|
+
import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
|
|
8
|
+
const state = {
|
|
9
|
+
...omit(PAINT, "fill"),
|
|
10
|
+
/** A plot to take the point's height from, by id. */
|
|
11
|
+
on: PLOT_REF,
|
|
12
|
+
/** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
|
|
13
|
+
axis: listed(["x", "y", "both"], "both", { animatable: false }),
|
|
14
|
+
graph: PLANE_ENTRY,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Guide lines from a graph point to the axes, reading its coordinates off them.
|
|
18
|
+
* The point is this node's `x`/`y`, or the point of a plot above its `x`.
|
|
19
|
+
*/
|
|
20
|
+
export const DropLines = traced(component2d({
|
|
21
|
+
key: "dropLines",
|
|
22
|
+
state,
|
|
23
|
+
defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center", dash: [8, 6] }, width: "hug", height: "hug" },
|
|
24
|
+
commands: omit(PAINT_COMMANDS, "fillTo"),
|
|
25
|
+
measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),
|
|
26
|
+
render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),
|
|
27
|
+
}), traceDrops);
|
|
28
|
+
function traceDrops(s, { map, plane }) {
|
|
29
|
+
const x = s.x;
|
|
30
|
+
const plot = curveFor(plane, s.on);
|
|
31
|
+
const y = plot ? curveValue(plot, x) : s.y;
|
|
32
|
+
if (!Number.isFinite(y))
|
|
33
|
+
return [];
|
|
34
|
+
const at = map.toPoint(x, y);
|
|
35
|
+
const runs = [];
|
|
36
|
+
// Each line starts on its axis, so drawing it on grows it towards the point.
|
|
37
|
+
if (s.axis !== "y")
|
|
38
|
+
runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);
|
|
39
|
+
if (s.axis !== "x")
|
|
40
|
+
runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);
|
|
41
|
+
return runs;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=drop-lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-lines.js","sourceRoot":"","sources":["../../src/marks/drop-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,GAYd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CAAC,CAAC;IAC5F,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import {\n component2d,\n type NodeOf,\n type NodeView,\n type PaintProps,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { curveValue } from \"../kit/curve\";\nimport { AXIS_COLOR } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport type DropAxis = \"x\" | \"y\" | \"both\";\n\nexport interface DropLinesProps extends PaintProps {\n on?: string;\n axis?: DropAxis;\n}\n\nconst state = {\n ...omit(PAINT, \"fill\"),\n /** A plot to take the point's height from, by id. */\n on: PLOT_REF,\n /** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */\n axis: listed([\"x\", \"y\", \"both\"], \"both\", { animatable: false }),\n graph: PLANE_ENTRY,\n};\n\ninterface DropValues {\n readonly x: number;\n readonly y: number;\n readonly on: NodeView | null;\n readonly axis: DropAxis;\n}\n\n/**\n * Guide lines from a graph point to the axes, reading its coordinates off them.\n * The point is this node's `x`/`y`, or the point of a plot above its `x`.\n */\nexport const DropLines = traced(component2d({\n key: \"dropLines\",\n state,\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\", dash: [8, 6] }, width: \"hug\", height: \"hug\" },\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\n measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),\n}), traceDrops);\n\nexport type DropLines = NodeOf<typeof DropLines>;\n\nfunction traceDrops(s: DropValues, { map, plane }: MarkReading): Vector2[][] {\n const x = s.x;\n const plot = curveFor(plane, s.on);\n const y = plot ? curveValue(plot, x) : s.y;\n if (!Number.isFinite(y)) return [];\n const at = map.toPoint(x, y);\n const runs: Vector2[][] = [];\n // Each line starts on its axis, so drawing it on grows it towards the point.\n if (s.axis !== \"y\") runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);\n if (s.axis !== \"x\") runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);\n return runs;\n}\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
import { type GraphPlane } from "../kit/graph.js";
|
|
3
|
+
export interface PlotPointProps extends PaintProps {
|
|
4
|
+
on?: string;
|
|
5
|
+
radius?: number;
|
|
6
|
+
label?: string;
|
|
7
|
+
labelSide?: "above" | "below" | "left" | "right";
|
|
8
|
+
labelSize?: number;
|
|
9
|
+
labelColor?: Color;
|
|
10
|
+
fontFamily?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A dot at graph coordinates, with an optional label. Named a plot in `on`, it
|
|
14
|
+
* rides that curve: its `x` is where along it, and its height is the curve's.
|
|
15
|
+
*/
|
|
16
|
+
export declare const PlotPoint: import("@motionscript/sdk").Component<"plotPoint", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
17
|
+
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
18
|
+
on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
19
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
20
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
21
|
+
labelSide: import("@motionscript/sdk").Type<"right" | "left" | "below" | "above", "right" | "left" | "below" | "above", false>;
|
|
22
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
23
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
24
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
25
|
+
graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
26
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
27
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
28
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
29
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
30
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
31
|
+
}>, {
|
|
32
|
+
fillTo: readonly ["fill"];
|
|
33
|
+
strokeTo: readonly ["stroke"];
|
|
34
|
+
shadowTo: readonly ["shadow"];
|
|
35
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
36
|
+
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
37
|
+
on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
38
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
39
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
40
|
+
labelSide: import("@motionscript/sdk").Type<"right" | "left" | "below" | "above", "right" | "left" | "below" | "above", false>;
|
|
41
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
42
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
43
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
44
|
+
graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
45
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
46
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
47
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
48
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
49
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
50
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
51
|
+
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
52
|
+
on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
53
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
54
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
55
|
+
labelSide: import("@motionscript/sdk").Type<"right" | "left" | "below" | "above", "right" | "left" | "below" | "above", false>;
|
|
56
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
57
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
58
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
59
|
+
graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
60
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
61
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
62
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
63
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
64
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
65
|
+
}>, {
|
|
66
|
+
fillTo: readonly ["fill"];
|
|
67
|
+
strokeTo: readonly ["stroke"];
|
|
68
|
+
shadowTo: readonly ["shadow"];
|
|
69
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
70
|
+
export type PlotPoint = NodeOf<typeof PlotPoint>;
|
|
71
|
+
//# sourceMappingURL=plot-point.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plot-point.d.ts","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,UAAU,EAEf,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAmC,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAIhF,MAAM,WAAW,cAAe,SAAQ,UAAU;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAkBD;;;GAGG;AACH,eAAO,MAAM,SAAS;IAjBlB,wFAAwF;;;;;;;;;IASxF,iHAAiH;;;;;;;;;;IATjH,wFAAwF;;;;;;;;;IASxF,iHAAiH;;;;;;IATjH,wFAAwF;;;;;;;;;IASxF,iHAAiH;;;;;;;;;2BA4CvB,CAAC;AAE/F,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
|