@motionscript/math 0.1.0-alpha.4 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +132 -92
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +52 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +59 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +43 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- 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/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +58 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- 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 +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +24 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +28 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +37 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +30 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +38 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +30 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +107 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +34 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +38 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +34 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +31 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +99 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +69 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +126 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +51 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +92 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +47 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +56 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +55 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- 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 +140 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +159 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +70 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- 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/plot-point3d.d.ts +57 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +131 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +58 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +182 -161
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
package/dist/marks/drop-lines.js
CHANGED
|
@@ -1,58 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { node, property, strokeProperty, withdraw, } from "@motionscript/sdk";
|
|
8
|
-
import { clamp } from "../kit/geometry.js";
|
|
9
|
-
import { Mark } from "../kit/mark.js";
|
|
10
|
-
import { curveOf } from "../kit/curve.js";
|
|
1
|
+
import { component2d, } from "@motionscript/sdk";
|
|
2
|
+
import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
|
|
3
|
+
import { curveValue } from "../kit/curve.js";
|
|
11
4
|
import { AXIS_COLOR } from "../kit/furniture.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
5
|
+
import { clamp } from "../kit/geometry.js";
|
|
6
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
|
|
7
|
+
import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
|
|
8
|
+
const state = {
|
|
9
|
+
...omit(PAINT, "fill"),
|
|
10
|
+
/** A plot to take the point's height from, by id. */
|
|
11
|
+
on: PLOT_REF,
|
|
12
|
+
/** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */
|
|
13
|
+
axis: listed(["x", "y", "both"], "both", { animatable: false }),
|
|
14
|
+
graph: PLANE_ENTRY,
|
|
15
|
+
};
|
|
14
16
|
/**
|
|
15
17
|
* Guide lines from a graph point to the axes, reading its coordinates off them.
|
|
16
18
|
* The point is this node's `x`/`y`, or the point of a plot above its `x`.
|
|
17
19
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__decorate([
|
|
42
|
-
property({ default: "both", options: ["x", "y", "both"], animatable: false })
|
|
43
|
-
], DropLines.prototype, "axis", void 0);
|
|
44
|
-
__decorate([
|
|
45
|
-
strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center", dash: [8, 6] } })
|
|
46
|
-
], DropLines.prototype, "stroke", void 0);
|
|
47
|
-
DropLines = __decorate([
|
|
48
|
-
node({
|
|
49
|
-
key: "dropLines",
|
|
50
|
-
within: SYSTEMS_AND_PLOT,
|
|
51
|
-
parentKey: "shape",
|
|
52
|
-
forkable: true,
|
|
53
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
54
|
-
}),
|
|
55
|
-
withdraw(...FILL_PAINT)
|
|
56
|
-
], DropLines);
|
|
57
|
-
export { DropLines };
|
|
20
|
+
export const DropLines = traced(component2d({
|
|
21
|
+
key: "dropLines",
|
|
22
|
+
state,
|
|
23
|
+
defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center", dash: [8, 6] }, width: "hug", height: "hug" },
|
|
24
|
+
commands: omit(PAINT_COMMANDS, "fillTo"),
|
|
25
|
+
measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),
|
|
26
|
+
render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),
|
|
27
|
+
}), traceDrops);
|
|
28
|
+
function traceDrops(s, { map, plane }) {
|
|
29
|
+
const x = s.x;
|
|
30
|
+
const plot = curveFor(plane, s.on);
|
|
31
|
+
const y = plot ? curveValue(plot, x) : s.y;
|
|
32
|
+
if (!Number.isFinite(y))
|
|
33
|
+
return [];
|
|
34
|
+
const at = map.toPoint(x, y);
|
|
35
|
+
const runs = [];
|
|
36
|
+
// Each line starts on its axis, so drawing it on grows it towards the point.
|
|
37
|
+
if (s.axis !== "y")
|
|
38
|
+
runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);
|
|
39
|
+
if (s.axis !== "x")
|
|
40
|
+
runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);
|
|
41
|
+
return runs;
|
|
42
|
+
}
|
|
58
43
|
//# sourceMappingURL=drop-lines.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop-lines.js","sourceRoot":"","sources":["../../src/marks/drop-lines.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"drop-lines.js","sourceRoot":"","sources":["../../src/marks/drop-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,GAYd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAA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C,CAAC,EAAE,CAAC,CAAC;IACnC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,6EAA6E;IAC7E,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5F,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG;QAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC5F,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import {\r\n component2d,\r\n type NodeOf,\r\n type NodeView,\r\n type PaintProps,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport { curveValue } from \"../kit/curve\";\r\nimport { AXIS_COLOR } from \"../kit/furniture\";\r\nimport { clamp } from \"../kit/geometry\";\r\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport type DropAxis = \"x\" | \"y\" | \"both\";\r\n\r\nexport interface DropLinesProps extends PaintProps {\r\n on?: string;\r\n axis?: DropAxis;\r\n}\r\n\r\nconst state = {\r\n ...omit(PAINT, \"fill\"),\r\n /** A plot to take the point's height from, by id. */\r\n on: PLOT_REF,\r\n /** Which axis to drop to: `x` draws the vertical line, `y` the horizontal one. */\r\n axis: listed([\"x\", \"y\", \"both\"], \"both\", { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n};\r\n\r\ninterface DropValues {\r\n readonly x: number;\r\n readonly y: number;\r\n readonly on: NodeView | null;\r\n readonly axis: DropAxis;\r\n}\r\n\r\n/**\r\n * Guide lines from a graph point to the axes, reading its coordinates off them.\r\n * The point is this node's `x`/`y`, or the point of a plot above its `x`.\r\n */\r\nexport const DropLines = traced(component2d({\r\n key: \"dropLines\",\r\n state,\r\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\", dash: [8, 6] }, width: \"hug\", height: \"hug\" },\r\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\r\n measure: (_measurer, s) => inkSize(traceDrops(s, reading(s))),\r\n render: (ctx, s) => drawMark(ctx, s, traceDrops(s, reading(s))),\r\n}), traceDrops);\r\n\r\nexport type DropLines = NodeOf<typeof DropLines>;\r\n\r\nfunction traceDrops(s: DropValues, { map, plane }: MarkReading): Vector2[][] {\r\n const x = s.x;\r\n const plot = curveFor(plane, s.on);\r\n const y = plot ? curveValue(plot, x) : s.y;\r\n if (!Number.isFinite(y)) return [];\r\n const at = map.toPoint(x, y);\r\n const runs: Vector2[][] = [];\r\n // Each line starts on its axis, so drawing it on grows it towards the point.\r\n if (s.axis !== \"y\") runs.push([map.toPoint(x, clamp(0, map.yRange[0], map.yRange[1])), at]);\r\n if (s.axis !== \"x\") runs.push([map.toPoint(clamp(0, map.xRange[0], map.xRange[1]), y), at]);\r\n return runs;\r\n}\r\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
1
|
+
import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
import { type GraphPlane } from "../kit/graph.js";
|
|
3
3
|
export interface PlotPointProps extends PaintProps {
|
|
4
4
|
on?: string;
|
|
5
5
|
radius?: number;
|
|
@@ -13,23 +13,40 @@ export interface PlotPointProps extends PaintProps {
|
|
|
13
13
|
* A dot at graph coordinates, with an optional label. Named a plot in `on`, it
|
|
14
14
|
* rides that curve: its `x` is where along it, and its height is the curve's.
|
|
15
15
|
*/
|
|
16
|
-
export declare
|
|
16
|
+
export declare const PlotPoint: import("@motionscript/sdk").Component<"plotPoint", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
17
17
|
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
18
|
-
on: string
|
|
19
|
-
radius: number
|
|
20
|
-
label: string
|
|
21
|
-
labelSide: "
|
|
22
|
-
labelSize: number
|
|
23
|
-
labelColor: Color
|
|
24
|
-
fontFamily: string
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
19
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
20
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
21
|
+
labelSide: import("@motionscript/sdk").Type<"left" | "right" | "below" | "above", "left" | "right" | "below" | "above", false>;
|
|
22
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
23
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
24
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
25
|
+
graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
26
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
27
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
28
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
29
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
30
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
31
|
+
}>, {
|
|
32
|
+
fillTo: readonly ["fill"];
|
|
33
|
+
strokeTo: readonly ["stroke"];
|
|
34
|
+
shadowTo: readonly ["shadow"];
|
|
35
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
36
|
+
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
37
|
+
on: import("@motionscript/sdk").Type<string, import("@motionscript/sdk").NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
38
|
+
radius: import("@motionscript/sdk").Type<number, number, false>;
|
|
39
|
+
label: import("@motionscript/sdk").Type<string, string, false>;
|
|
40
|
+
labelSide: import("@motionscript/sdk").Type<"left" | "right" | "below" | "above", "left" | "right" | "below" | "above", false>;
|
|
41
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
42
|
+
labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
|
|
43
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
44
|
+
graph: import("@motionscript/sdk").Type<GraphPlane | null, GraphPlane | null, true>;
|
|
45
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
46
|
+
value: import("@motionscript/sdk").Type<number, number, true>;
|
|
47
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
48
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
49
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
50
|
+
}>, null>>;
|
|
51
|
+
export type PlotPoint = NodeOf<typeof PlotPoint>;
|
|
35
52
|
//# sourceMappingURL=plot-point.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plot-point.d.ts","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;;;;;UA4CvB,CAAC;AAE/F,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/marks/plot-point.js
CHANGED
|
@@ -1,97 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
|
|
2
|
+
import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
|
|
3
|
+
import { curveValue } from "../kit/curve.js";
|
|
4
|
+
import { drawLabels, loadFormulas } from "../kit/furniture.js";
|
|
5
|
+
import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
|
|
6
|
+
import { strokeShape } from "../kit/mark.js";
|
|
7
|
+
import { anchored } from "../kit/place.js";
|
|
8
|
+
const state = {
|
|
9
|
+
// A dot has no outline worth trimming.
|
|
10
|
+
...omit(PAINT, "start", "end"),
|
|
11
|
+
/** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
|
|
12
|
+
on: PLOT_REF,
|
|
13
|
+
radius: Types.number(7, { min: 0, unit: "px" }),
|
|
14
|
+
label: Types.text("", { animatable: false }),
|
|
15
|
+
labelSide: listed(["above", "below", "left", "right"], "above", { animatable: false }),
|
|
16
|
+
labelSize: Types.number(18, { min: 1, unit: "px" }),
|
|
17
|
+
labelColor: Types.color("#e5e7eb"),
|
|
18
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
19
|
+
graph: PLANE_ENTRY,
|
|
20
|
+
/** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
|
|
21
|
+
value: Types.number(0, { private: true }),
|
|
6
22
|
};
|
|
7
|
-
import { colorProperty, fillProperty, Graphics2D, node, PaintNode, property, withdraw, } from "@motionscript/sdk";
|
|
8
|
-
import { curveOf } from "../kit/curve.js";
|
|
9
|
-
import { declareFormulas, drawLabels } from "../kit/furniture.js";
|
|
10
|
-
import { SYSTEMS_AND_PLOT } from "../kit/placement.js";
|
|
11
|
-
import { OUTLINE_TRIM } from "../kit/withdrawn.js";
|
|
12
23
|
/**
|
|
13
24
|
* A dot at graph coordinates, with an optional label. Named a plot in `on`, it
|
|
14
25
|
* rides that curve: its `x` is where along it, and its height is the curve's.
|
|
15
26
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
__decorate([
|
|
63
|
-
property({ default: "", kind: "nodeRef", nodeTypes: ["functionPlot"], animatable: false })
|
|
64
|
-
], PlotPoint.prototype, "on", void 0);
|
|
65
|
-
__decorate([
|
|
66
|
-
property({ default: 7, min: 0, unit: "px" })
|
|
67
|
-
], PlotPoint.prototype, "radius", void 0);
|
|
68
|
-
__decorate([
|
|
69
|
-
property({ default: "", animatable: false })
|
|
70
|
-
], PlotPoint.prototype, "label", void 0);
|
|
71
|
-
__decorate([
|
|
72
|
-
property({ default: "above", options: ["above", "below", "left", "right"], animatable: false })
|
|
73
|
-
], PlotPoint.prototype, "labelSide", void 0);
|
|
74
|
-
__decorate([
|
|
75
|
-
property({ default: 18, min: 1, unit: "px" })
|
|
76
|
-
], PlotPoint.prototype, "labelSize", void 0);
|
|
77
|
-
__decorate([
|
|
78
|
-
colorProperty({ default: "#e5e7eb" })
|
|
79
|
-
], PlotPoint.prototype, "labelColor", void 0);
|
|
80
|
-
__decorate([
|
|
81
|
-
property({ default: "", animatable: false })
|
|
82
|
-
], PlotPoint.prototype, "fontFamily", void 0);
|
|
83
|
-
__decorate([
|
|
84
|
-
fillProperty({ default: "#e5e7eb" })
|
|
85
|
-
], PlotPoint.prototype, "fill", void 0);
|
|
86
|
-
PlotPoint = __decorate([
|
|
87
|
-
node({
|
|
88
|
-
key: "plotPoint",
|
|
89
|
-
within: SYSTEMS_AND_PLOT,
|
|
90
|
-
parentKey: "shape",
|
|
91
|
-
forkable: true,
|
|
92
|
-
layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
|
|
93
|
-
}),
|
|
94
|
-
withdraw(...OUTLINE_TRIM)
|
|
95
|
-
], PlotPoint);
|
|
96
|
-
export { PlotPoint };
|
|
27
|
+
export const PlotPoint = anchored(component2d({
|
|
28
|
+
key: "plotPoint",
|
|
29
|
+
state,
|
|
30
|
+
defaults: { fill: "#e5e7eb", width: "hug", height: "hug", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },
|
|
31
|
+
load: (loader, s) => {
|
|
32
|
+
if (s.label !== "" && s.fontFamily !== "")
|
|
33
|
+
loader.font(s.fontFamily);
|
|
34
|
+
loadFormulas(loader, [s.label]);
|
|
35
|
+
},
|
|
36
|
+
commands: omit(PAINT_COMMANDS, "progressTo", "flash"),
|
|
37
|
+
measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),
|
|
38
|
+
render: (ctx, s) => {
|
|
39
|
+
const size = s.radius * 2;
|
|
40
|
+
const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;
|
|
41
|
+
painted(ctx, () => {
|
|
42
|
+
if (shape)
|
|
43
|
+
ctx.draw(shape().shadow(s.shadow).fill(s.fill));
|
|
44
|
+
if (s.label === "")
|
|
45
|
+
return;
|
|
46
|
+
const gap = s.radius + s.labelSize * 0.45;
|
|
47
|
+
const side = s.labelSide;
|
|
48
|
+
const horizontal = side === "left" || side === "right";
|
|
49
|
+
const label = {
|
|
50
|
+
text: s.label,
|
|
51
|
+
align: side === "left" ? "right" : side === "right" ? "left" : "center",
|
|
52
|
+
at: {
|
|
53
|
+
x: horizontal ? (side === "left" ? -1 : 1) * gap : 0,
|
|
54
|
+
y: horizontal ? 0 : (side === "below" ? -1 : 1) * (gap + s.labelSize / 2),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor }));
|
|
58
|
+
}, () => {
|
|
59
|
+
if (shape)
|
|
60
|
+
strokeShape(ctx, shape, s);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
}), (s, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));
|
|
64
|
+
/** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */
|
|
65
|
+
function heightOf(plane, on, x, y) {
|
|
66
|
+
const curve = curveFor(plane, on);
|
|
67
|
+
const height = curve ? curveValue(curve, x) : NaN;
|
|
68
|
+
// Off the end of its curve a point stays where its own `y` puts it rather than vanishing.
|
|
69
|
+
return Number.isFinite(height) ? height : y;
|
|
70
|
+
}
|
|
97
71
|
//# sourceMappingURL=plot-point.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plot-point.js","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plot-point.js","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAmB,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAYxC,MAAM,KAAK,GAAG;IACV,uCAAuC;IACvC,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC;IAC9B,wFAAwF;IACxF,EAAE,EAAE,QAAQ;IACZ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC/C,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC5C,SAAS,EAAE,MAAM,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACtF,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;I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n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\r\nimport { curveValue } from \"../kit/curve\";\r\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\r\nimport { curveFor, PLANE_ENTRY, PLOT_REF, type GraphPlane } from \"../kit/graph\";\r\nimport { strokeShape } from \"../kit/mark\";\r\nimport { anchored } from \"../kit/place\";\r\n\r\nexport interface PlotPointProps extends PaintProps {\r\n on?: string;\r\n radius?: number;\r\n label?: string;\r\n labelSide?: \"above\" | \"below\" | \"left\" | \"right\";\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n}\r\n\r\nconst state = {\r\n // A dot has no outline worth trimming.\r\n ...omit(PAINT, \"start\", \"end\"),\r\n /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */\r\n on: PLOT_REF,\r\n radius: Types.number(7, { min: 0, unit: \"px\" }),\r\n label: Types.text(\"\", { animatable: false }),\r\n labelSide: listed([\"above\", \"below\", \"left\", \"right\"], \"above\", { animatable: false }),\r\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\r\n labelColor: Types.color(\"#e5e7eb\"),\r\n fontFamily: Types.text(\"\", { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */\r\n value: Types.number(0, { private: true }),\r\n};\r\n\r\n/**\r\n * A dot at graph coordinates, with an optional label. Named a plot in `on`, it\r\n * rides that curve: its `x` is where along it, and its height is the curve's.\r\n */\r\nexport const PlotPoint = anchored(component2d({\r\n key: \"plotPoint\",\r\n state,\r\n defaults: { fill: \"#e5e7eb\", width: \"hug\", height: \"hug\", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },\r\n load: (loader, s) => {\r\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\r\n loadFormulas(loader, [s.label]);\r\n },\r\n commands: omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\r\n measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),\r\n render: (ctx, s) => {\r\n const size = s.radius * 2;\r\n const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;\r\n painted(\r\n ctx,\r\n () => {\r\n if (shape) ctx.draw(shape().shadow(s.shadow).fill(s.fill));\r\n if (s.label === \"\") return;\r\n const gap = s.radius + s.labelSize * 0.45;\r\n const side = s.labelSide;\r\n const horizontal = side === \"left\" || side === \"right\";\r\n const label: Label = {\r\n text: s.label,\r\n align: side === \"left\" ? \"right\" : side === \"right\" ? \"left\" : \"center\",\r\n at: {\r\n x: horizontal ? (side === \"left\" ? -1 : 1) * gap : 0,\r\n y: horizontal ? 0 : (side === \"below\" ? -1 : 1) * (gap + s.labelSize / 2),\r\n },\r\n };\r\n ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\r\n },\r\n () => {\r\n if (shape) strokeShape(ctx, shape, s);\r\n },\r\n );\r\n },\r\n}), (s: { readonly on: unknown }, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));\r\n\r\nexport type PlotPoint = NodeOf<typeof PlotPoint>;\r\n\r\n/** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */\r\nfunction heightOf(plane: GraphPlane | null, on: unknown, x: number, y: number): number {\r\n const curve = curveFor(plane, on);\r\n const height = curve ? curveValue(curve, x) : NaN;\r\n // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.\r\n return Number.isFinite(height) ? height : y;\r\n}\r\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
3
|
-
import { Mark } from "../kit/mark.js";
|
|
1
|
+
import { type NodeOf, type NodeView, type PaintProps, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
|
|
2
|
+
import type { Interval } from "../kit/coords.js";
|
|
4
3
|
export type RiemannSample = "left" | "right" | "center";
|
|
5
4
|
export interface RiemannSumProps extends PaintProps {
|
|
6
5
|
on?: string;
|
|
@@ -9,29 +8,34 @@ export interface RiemannSumProps extends PaintProps {
|
|
|
9
8
|
sample?: RiemannSample;
|
|
10
9
|
}
|
|
11
10
|
/** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */
|
|
12
|
-
export declare
|
|
13
|
-
on: string
|
|
14
|
-
domain: Interval
|
|
11
|
+
export declare const RiemannSum: import("@motionscript/sdk").Component<"riemannSum", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
12
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
13
|
+
domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
|
|
15
14
|
/** Each rectangle's width, in graph units. */
|
|
16
|
-
dx: number
|
|
15
|
+
dx: import("@motionscript/sdk").Type<number, number, false>;
|
|
17
16
|
/** Where in its width a rectangle reads the curve's height. */
|
|
18
|
-
sample:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
sample: import("@motionscript/sdk").Type<"center" | "left" | "right", "center" | "left" | "right", false>;
|
|
18
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
19
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
20
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
21
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
22
|
+
}>, {
|
|
23
|
+
readonly refineTo: readonly ["dx"];
|
|
24
|
+
readonly domainTo: readonly ["domain"];
|
|
25
|
+
readonly fillTo: readonly ["fill"];
|
|
26
|
+
readonly strokeTo: readonly ["stroke"];
|
|
27
|
+
readonly shadowTo: readonly ["shadow"];
|
|
28
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
29
|
+
on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
|
|
30
|
+
domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
|
|
31
|
+
/** Each rectangle's width, in graph units. */
|
|
32
|
+
dx: import("@motionscript/sdk").Type<number, number, false>;
|
|
33
|
+
/** Where in its width a rectangle reads the curve's height. */
|
|
34
|
+
sample: import("@motionscript/sdk").Type<"center" | "left" | "right", "center" | "left" | "right", false>;
|
|
35
|
+
graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
|
|
36
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
37
|
+
stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
|
|
38
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
39
|
+
}>, null>>;
|
|
40
|
+
export type RiemannSum = NodeOf<typeof RiemannSum>;
|
|
37
41
|
//# sourceMappingURL=riemann-sum.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"riemann-sum.d.ts","sourceRoot":"","sources":["../../src/marks/riemann-sum.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"riemann-sum.d.ts","sourceRoot":"","sources":["../../src/marks/riemann-sum.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,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAO9C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExD,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAwBD,4FAA4F;AAC5F,eAAO,MAAM,UAAU;;;IAfnB,8CAA8C;;IAE9C,+DAA+D;;;;;;;;;;;;;;;IAF/D,8CAA8C;;IAE9C,+DAA+D;;;;;;UA+BtD,CAAC;AAEd,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
|