@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
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
command,
|
|
2
|
+
component2d,
|
|
4
3
|
fillOps,
|
|
5
4
|
Graphics2D,
|
|
6
|
-
|
|
7
|
-
PaintNode,
|
|
8
|
-
property,
|
|
9
|
-
strokeProperty,
|
|
10
|
-
withdraw,
|
|
11
|
-
type AssetScope,
|
|
5
|
+
Types,
|
|
12
6
|
type Color,
|
|
13
|
-
type Command,
|
|
14
|
-
type CommandArgs,
|
|
15
7
|
type Fill,
|
|
16
8
|
type FillResolved,
|
|
17
|
-
type
|
|
9
|
+
type NodeOf,
|
|
18
10
|
type NormalizedColor,
|
|
19
11
|
type PaintProps,
|
|
20
|
-
type
|
|
21
|
-
type
|
|
12
|
+
type RenderContext,
|
|
13
|
+
type ShadowResolved,
|
|
14
|
+
type Size2D,
|
|
22
15
|
type StrokeResolved,
|
|
16
|
+
type Values,
|
|
23
17
|
type Vector2,
|
|
18
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
19
|
+
type Node2D as _Node2D,
|
|
20
|
+
type Node2DProps as _Node2DProps,
|
|
21
|
+
type Shadow as _Shadow,
|
|
22
|
+
type Stroke as _Stroke,
|
|
24
23
|
} from "@motionscript/sdk";
|
|
25
24
|
import { braceOutline } from "../kit/brace";
|
|
26
|
-
import {
|
|
25
|
+
import { omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component";
|
|
26
|
+
import { drawLabels, loadFormulas, type Label } from "../kit/furniture";
|
|
27
27
|
import { lerpFillScale, readFillScale } from "../kit/scale";
|
|
28
28
|
import { formatTick } from "../kit/ticks";
|
|
29
|
-
import { FILL_PAINT, OUTLINE_TRIM } from "../kit/withdrawn";
|
|
30
29
|
|
|
31
30
|
export interface SampleSpaceProps extends PaintProps {
|
|
32
31
|
columnShares?: number[];
|
|
@@ -56,154 +55,156 @@ function lerpShares(from: number[], to: number[], t: number): number[] {
|
|
|
56
55
|
return to.map((share, i) => from[i] + (share - from[i]) * t);
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* (P(B | A) above, the rest below): each part's area is its probability.
|
|
63
|
-
* Braces name the columns below and the rows on the left; `divideTo` moves the
|
|
64
|
-
* cuts.
|
|
65
|
-
*/
|
|
66
|
-
@node({
|
|
67
|
-
key: "sampleSpace",
|
|
68
|
-
parentKey: "shape",
|
|
69
|
-
forkable: true,
|
|
70
|
-
layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: false },
|
|
71
|
-
seed: { width: 520, height: 420, columnShares: [0.4, 0.6], rowShares: [0.7, 0.25], columnLabels: ["A", "not A"], rowLabels: ["B", "not B"] },
|
|
72
|
-
})
|
|
73
|
-
@withdraw(...FILL_PAINT, ...OUTLINE_TRIM)
|
|
74
|
-
export class SampleSpace extends PaintNode<SampleSpaceProps> {
|
|
58
|
+
const state = {
|
|
59
|
+
// Its parts are painted from `columnFills`, and it trims no outline of its own.
|
|
60
|
+
...omit(PAINT, "fill", "start", "end"),
|
|
75
61
|
/** How the whole is shared across, left to right; any numbers, read as shares of their sum. */
|
|
76
|
-
|
|
62
|
+
columnShares: Types.custom<number[]>([1], { resolve: readShares, lerp: lerpShares, kind: "vector" }),
|
|
77
63
|
/** Each column's upper share, 0 to 1; a column without one is not cut across. */
|
|
78
|
-
|
|
64
|
+
rowShares: Types.custom<number[]>([], { resolve: readShares, lerp: lerpShares, kind: "vector" }),
|
|
79
65
|
/** Each column's paint, left to right, round again past the last; its lower part shows it fainter. */
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
columnFills: Types.custom<Fill[], FillResolved[][]>([], { resolve: readFillScale, lerp: lerpFillScale, kind: "vector" }),
|
|
67
|
+
columnLabels: Types.custom<string[]>([], { animatable: false, kind: "vector" }),
|
|
82
68
|
/** The upper part's name and the lower's, written on the left. */
|
|
83
|
-
|
|
69
|
+
rowLabels: Types.custom<string[]>([], { animatable: false, kind: "vector" }),
|
|
84
70
|
/** Write each part's probability in it. */
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
values: Types.boolean(false, { animatable: false }),
|
|
72
|
+
labelSize: Types.number(20, { min: 1, unit: "px" }),
|
|
73
|
+
labelColor: Types.color("#e5e7eb"),
|
|
74
|
+
fontFamily: Types.text("", { animatable: false }),
|
|
75
|
+
};
|
|
89
76
|
|
|
90
|
-
|
|
77
|
+
/** What a sample space is drawn from: its own entries, as its fields and its node both read them. */
|
|
78
|
+
export type SampleSpaceValues = Values<typeof state>;
|
|
91
79
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
80
|
+
/** One part of a sample space: its box in pixels from the node's centre, y up, and its probability. */
|
|
81
|
+
export interface SamplePart {
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
probability: number;
|
|
87
|
+
column: number;
|
|
88
|
+
upper: boolean;
|
|
89
|
+
}
|
|
95
90
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
/**
|
|
92
|
+
* A probability's whole, as a box cut into columns by `columnShares` (shares of
|
|
93
|
+
* the whole, P(A) and P(not A)) and each column cut again by its `rowShares` entry
|
|
94
|
+
* (P(B | A) above, the rest below): each part's area is its probability.
|
|
95
|
+
* Braces name the columns below and the rows on the left; `divideTo` moves the
|
|
96
|
+
* cuts.
|
|
97
|
+
*/
|
|
98
|
+
export const SampleSpace = component2d({
|
|
99
|
+
key: "sampleSpace",
|
|
100
|
+
state,
|
|
101
|
+
defaults: { stroke: { weight: 2, fill: "#0b0d12", align: "center" } },
|
|
102
|
+
load: (loader, s) => {
|
|
103
|
+
if (s.fontFamily !== "") loader.font(s.fontFamily);
|
|
104
|
+
loadFormulas(loader, [...s.columnLabels, ...s.rowLabels]);
|
|
105
|
+
},
|
|
106
|
+
commands: {
|
|
107
|
+
...omit(PAINT_COMMANDS, "fillTo", "progressTo", "flash"),
|
|
108
|
+
/** Move the cuts: the columns' shares, each column's upper share, or both. */
|
|
109
|
+
divideTo: { args: ["columnShares", "rowShares"] },
|
|
110
|
+
},
|
|
111
|
+
render: (ctx, s) => painted(ctx, () => drawSpace(ctx, s)),
|
|
112
|
+
});
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
super.declareAssets(assets);
|
|
107
|
-
if (this.fontFamily !== "") assets.font(this.fontFamily);
|
|
108
|
-
declareFormulas(assets, [...this.columnLabels, ...this.rowLabels]);
|
|
109
|
-
}
|
|
114
|
+
export type SampleSpace = NodeOf<typeof SampleSpace>;
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
/** Each part of a sample space of `size`: columns left to right, upper part first. */
|
|
117
|
+
export function sampleParts(space: SampleSpaceValues, size: Size2D): SamplePart[] {
|
|
118
|
+
const box = boxOf(space, size);
|
|
119
|
+
const shares = space.columnShares;
|
|
120
|
+
const total = shares.reduce((sum, share) => sum + share, 0);
|
|
121
|
+
if (!(total > 0) || box.width <= 0 || box.height <= 0) return [];
|
|
122
|
+
const out: SamplePart[] = [];
|
|
123
|
+
let left = box.x - box.width / 2;
|
|
124
|
+
shares.forEach((share, column) => {
|
|
125
|
+
const width = (box.width * share) / total;
|
|
126
|
+
const p = share / total;
|
|
127
|
+
const cut = space.rowShares[column];
|
|
128
|
+
const top = box.y + box.height / 2;
|
|
129
|
+
if (cut === undefined) {
|
|
130
|
+
out.push({ x: left + width / 2, y: box.y, width, height: box.height, probability: p, column, upper: true });
|
|
131
|
+
} else {
|
|
132
|
+
const upper = Math.min(1, Math.max(0, cut));
|
|
133
|
+
const h = box.height * upper;
|
|
134
|
+
out.push({ x: left + width / 2, y: top - h / 2, width, height: h, probability: p * upper, column, upper: true });
|
|
135
|
+
out.push({ x: left + width / 2, y: top - h - (box.height - h) / 2, width, height: box.height - h, probability: p * (1 - upper), column, upper: false });
|
|
136
|
+
}
|
|
137
|
+
left += width;
|
|
138
|
+
});
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
136
141
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
142
|
+
function drawSpace(ctx: RenderContext, space: SampleSpaceValues): void {
|
|
143
|
+
const parts = sampleParts(space, ctx.size);
|
|
144
|
+
if (parts.length === 0) return;
|
|
145
|
+
const fills = space.columnFills;
|
|
146
|
+
const stroke = space.stroke as StrokeResolved[];
|
|
147
|
+
const labels: Label[] = [];
|
|
148
|
+
for (const part of parts) {
|
|
149
|
+
if (!(part.width > 0) || !(part.height > 0)) continue;
|
|
150
|
+
const base = fills.length > 0 ? fills[part.column % fills.length] : fillOps.resolve(PALETTE[part.column % PALETTE.length]);
|
|
151
|
+
const paint = part.upper ? base : base.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * LOWER }));
|
|
152
|
+
const g = new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height });
|
|
153
|
+
ctx.draw(g.shadow(space.shadow as ShadowResolved[]).fill(paint));
|
|
154
|
+
if (stroke.length > 0) ctx.draw(new Graphics2D().rect({ x: part.x, y: part.y, width: part.width, height: part.height }).stroke(stroke));
|
|
155
|
+
if (space.values && part.height > space.labelSize && part.width > space.labelSize) {
|
|
156
|
+
labels.push({ text: formatTick(Math.round(part.probability * 1000) / 1000, 0.001), at: { x: part.x, y: part.y }, align: "center" });
|
|
153
157
|
}
|
|
154
|
-
labels.push(...this._braces(ctx, parts));
|
|
155
|
-
const style = { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor as NormalizedColor };
|
|
156
|
-
for (const part of drawLabels(labels, style)) ctx.draw(part);
|
|
157
158
|
}
|
|
159
|
+
labels.push(...braces(ctx, space, parts));
|
|
160
|
+
const style = { fontSize: space.labelSize, fontFamily: space.fontFamily, color: space.labelColor as NormalizedColor };
|
|
161
|
+
for (const part of drawLabels(labels, style)) ctx.draw(part);
|
|
162
|
+
}
|
|
158
163
|
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
/** Room for the braces and their names, below and on the left, taken from the box. */
|
|
165
|
+
function boxOf(space: SampleSpaceValues, size: Size2D): { x: number; y: number; width: number; height: number } {
|
|
166
|
+
const { width, height } = size;
|
|
167
|
+
const room = space.labelSize * 2.6;
|
|
168
|
+
const below = space.columnLabels.some((label) => label !== "") ? room : 0;
|
|
169
|
+
const left = space.rowLabels.some((label) => label !== "") ? room * 1.6 : 0;
|
|
170
|
+
return { x: left / 2, y: below / 2, width: Math.max(0, width - left), height: Math.max(0, height - below) };
|
|
171
|
+
}
|
|
161
172
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
/** Braces under each column and beside the first column's parts, and the labels that name them. */
|
|
174
|
+
function braces(ctx: RenderContext, space: SampleSpaceValues, parts: readonly SamplePart[]): Label[] {
|
|
175
|
+
const box = boxOf(space, ctx.size);
|
|
176
|
+
const reach = space.labelSize * 0.8;
|
|
177
|
+
const gap = 6;
|
|
178
|
+
const runs = new Graphics2D();
|
|
179
|
+
const labels: Label[] = [];
|
|
180
|
+
let drawn = false;
|
|
181
|
+
const brace = (from: Vector2, to: Vector2, out: Vector2, text: string, align: Label["align"]) => {
|
|
182
|
+
if (text === "") return;
|
|
183
|
+
// A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.
|
|
184
|
+
runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });
|
|
185
|
+
drawn = true;
|
|
186
|
+
const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
|
|
187
|
+
const far = reach + space.labelSize * 0.75;
|
|
188
|
+
labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });
|
|
189
|
+
};
|
|
190
|
+
const bottom = box.y - box.height / 2 - gap;
|
|
191
|
+
for (const part of parts) {
|
|
192
|
+
if (!part.upper && space.rowShares[part.column] !== undefined) continue;
|
|
193
|
+
const text = space.columnLabels[part.column] ?? "";
|
|
194
|
+
// Left to right along the bottom, so the bulge, to the edge's right, points down.
|
|
195
|
+
brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, "center");
|
|
169
196
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
// A frame centred on the node's own centre, so the path is drawn where it is and not moved onto it.
|
|
182
|
-
runs.path({ data: braceOutline(from, to, out, reach), centerBounds: [-1, -1, 1, 1] });
|
|
183
|
-
drawn = true;
|
|
184
|
-
const mid = { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2 };
|
|
185
|
-
const far = reach + this.labelSize * 0.75;
|
|
186
|
-
labels.push({ text, at: { x: mid.x + out.x * far, y: mid.y + out.y * far }, align });
|
|
187
|
-
};
|
|
188
|
-
const bottom = box.y - box.height / 2 - gap;
|
|
189
|
-
for (const part of parts) {
|
|
190
|
-
if (!part.upper && this.rowShares[part.column] !== undefined) continue;
|
|
191
|
-
const text = this.columnLabels[part.column] ?? "";
|
|
192
|
-
// Left to right along the bottom, so the bulge, to the edge's right, points down.
|
|
193
|
-
brace({ x: part.x + part.width / 2, y: bottom }, { x: part.x - part.width / 2, y: bottom }, { x: 0, y: -1 }, text, "center");
|
|
194
|
-
}
|
|
195
|
-
const first = parts.filter((part) => part.column === 0);
|
|
196
|
-
const left = box.x - box.width / 2 - gap;
|
|
197
|
-
if (this.rowShares[0] !== undefined) {
|
|
198
|
-
first.forEach((part) => {
|
|
199
|
-
const text = this.rowLabels[part.upper ? 0 : 1] ?? "";
|
|
200
|
-
brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, "right");
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
if (drawn) {
|
|
204
|
-
const fill = fillOps.resolve({ type: "solid", color: this.labelColor as NormalizedColor });
|
|
205
|
-
ctx.draw(runs.stroke({ weight: 2, fill, align: "center", cap: "round", join: "round" }));
|
|
206
|
-
}
|
|
207
|
-
return labels;
|
|
197
|
+
const first = parts.filter((part) => part.column === 0);
|
|
198
|
+
const left = box.x - box.width / 2 - gap;
|
|
199
|
+
if (space.rowShares[0] !== undefined) {
|
|
200
|
+
first.forEach((part) => {
|
|
201
|
+
const text = space.rowLabels[part.upper ? 0 : 1] ?? "";
|
|
202
|
+
brace({ x: left, y: part.y - part.height / 2 }, { x: left, y: part.y + part.height / 2 }, { x: -1, y: 0 }, text, "right");
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (drawn) {
|
|
206
|
+
const fill = fillOps.resolve({ type: "solid", color: space.labelColor as NormalizedColor });
|
|
207
|
+
ctx.draw(runs.stroke({ weight: 2, fill, align: "center", cap: "round", join: "round" }));
|
|
208
208
|
}
|
|
209
|
+
return labels;
|
|
209
210
|
}
|