egatari 0.6.8 → 0.6.9
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 +37 -1
- package/README.ja.md +2 -2
- package/README.md +2 -2
- package/components.lock.json +84 -3
- package/components2.lock.json +202 -1
- package/kit/check-messages.mjs +5 -0
- package/kit/check.mjs +18 -4
- package/kit/core/check-parity.mjs +62 -0
- package/kit/core/check-source.mjs +56 -0
- package/kit/core/colab-core.mjs +1 -1
- package/kit/core/color-vocab.mjs +8 -2
- package/kit/core/layout-scan.mjs +7 -4
- package/kit/core/llm-pack-assemble.mjs +1 -1
- package/kit/core/llm-pack-data.mjs +185 -9
- package/kit/core/llm-pack.mjs +1 -1
- package/kit/core/narration-lint.mjs +12 -0
- package/kit/core/new-deck.mjs +3 -0
- package/kit/core/part-labels.mjs +6 -0
- package/kit/core/template-text.mjs +5 -3
- package/kit/deck.js +88 -13
- package/kit/instruction-version.json +1 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/presenter.js +33 -9
- package/kit/tools.js +4 -0
- package/package.json +1 -1
- package/themes/asagi/theme.json +1 -1
- package/themes/asagi/tokens.css +12 -0
- package/themes/business/theme.json +1 -1
- package/themes/business/tokens.css +12 -0
- package/themes/default/README.ja.md +24 -1
- package/themes/default/README.md +24 -1
- package/themes/default/theme.json +1 -1
- package/themes/default/tokens.css +12 -0
- package/themes/kogecha/theme.json +1 -1
- package/themes/kogecha/tokens.css +12 -0
- package/themes/kokugo/theme.json +1 -1
- package/themes/kokugo/tokens.css +12 -0
- package/themes/murasaki/theme.json +1 -1
- package/themes/murasaki/tokens.css +12 -0
- package/themes/sumi/theme.json +1 -1
- package/themes/sumi/tokens.css +12 -0
- package/themes/tokiwa/theme.json +1 -1
- package/themes/tokiwa/tokens.css +12 -0
- package/themes.lock.json +80 -24
- package/vendor/components/CATALOG.md +7 -1
- package/vendor/components/sha256/1298d779fe60ccfc09747fbdba47e2111175bd7fd2385a5b68c8f2644cd267be/README.en.md +23 -0
- package/vendor/components/sha256/1298d779fe60ccfc09747fbdba47e2111175bd7fd2385a5b68c8f2644cd267be/index.js +120 -0
- package/vendor/components/sha256/7aea8341beffcd4ad95c12b7e7e3be3f0f52eb7932d424be9e74e2fbd7339e45/README.en.md +23 -0
- package/vendor/components/sha256/7aea8341beffcd4ad95c12b7e7e3be3f0f52eb7932d424be9e74e2fbd7339e45/index.js +289 -0
- package/vendor/components/sha256/90ed438b40ed8d765348834b2bed2baad9b0053c2168c218335b6d95b9c80283/README.en.md +44 -0
- package/vendor/components/sha256/90ed438b40ed8d765348834b2bed2baad9b0053c2168c218335b6d95b9c80283/index.js +203 -0
- package/vendor/components/sha256/a69ab76ff7d0746d093b4e606d7b113be921cbb156edc16c2ad40aafab280d42/README.en.md +22 -0
- package/vendor/components/sha256/a69ab76ff7d0746d093b4e606d7b113be921cbb156edc16c2ad40aafab280d42/index.js +145 -0
- package/vendor/components/sha256/d75c461bb7b2b1c9a2b6d15bee1e11bcec88ef94931174d6b222cd309f6a0287/README.en.md +24 -0
- package/vendor/components/sha256/d75c461bb7b2b1c9a2b6d15bee1e11bcec88ef94931174d6b222cd309f6a0287/index.js +103 -0
- package/vendor/components/sha256/decb7c026527ea269a401efedcb5d4d56d186074b286d2f94772068bef56b256/README.en.md +31 -0
- package/vendor/components/sha256/decb7c026527ea269a401efedcb5d4d56d186074b286d2f94772068bef56b256/index.js +267 -0
- package/vendor/components/sha256/f13af97d7ebf9893d5783eff27e4e1ce092ccd01783b332ad01aa0d201356548/README.en.md +38 -0
- package/vendor/components/sha256/f13af97d7ebf9893d5783eff27e4e1ce092ccd01783b332ad01aa0d201356548/index.js +266 -0
- package/vendor/components-2/manifest-2.6.0.json +2104 -0
- package/vendor/egatari-spec/SOURCE.json +2 -2
- package/vendor/egatari-spec/schema/egatari-audio.schema.json +21 -0
- package/vendor/themes/asagi/1.1.0/theme.json +14 -0
- package/vendor/themes/asagi/1.1.0/tokens.css +18 -0
- package/vendor/themes/business/1.1.0/theme.json +5 -0
- package/vendor/themes/business/1.1.0/tokens.css +29 -0
- package/vendor/themes/default/1.3.0/theme.json +4 -0
- package/vendor/themes/default/1.3.0/tokens.css +74 -0
- package/vendor/themes/kogecha/1.1.0/theme.json +10 -0
- package/vendor/themes/kogecha/1.1.0/tokens.css +17 -0
- package/vendor/themes/kokugo/1.1.0/theme.json +5 -0
- package/vendor/themes/kokugo/1.1.0/tokens.css +13 -0
- package/vendor/themes/murasaki/1.1.0/theme.json +10 -0
- package/vendor/themes/murasaki/1.1.0/tokens.css +13 -0
- package/vendor/themes/sumi/1.1.0/theme.json +10 -0
- package/vendor/themes/sumi/1.1.0/tokens.css +37 -0
- package/vendor/themes/tokiwa/1.1.0/theme.json +10 -0
- package/vendor/themes/tokiwa/1.1.0/tokens.css +15 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// m-sampling: population → sample → simulated sampling distribution.
|
|
2
|
+
egatariParts.define({name: "sampling", version: "2.0.0", requires: {base: "1.1.0", plot: "1.1.1"}, element: "m-sampling"}, function(deps){
|
|
3
|
+
"use strict";
|
|
4
|
+
var base = deps.base;
|
|
5
|
+
var TEXT = {
|
|
6
|
+
ja: {population: "母集団", sample: "標本", distribution: "標本分布", with: "戻す(復元抽出)", without: "戻さない(非復元抽出)", mean: "平均", proportion: "の割合", meanAxis: "標本平均", proportionAxis: "標本比率", statsMean: "標本統計量の平均", caption: function(n, r){ return "n = " + n + "、" + r + " 回"; }},
|
|
7
|
+
en: {population: "population", sample: "Sample", distribution: "Sampling distribution", with: "with replacement", without: "without replacement", mean: "Mean", proportion: " proportion", meanAxis: "Sample mean", proportionAxis: "Sample proportion", statsMean: "mean of sample statistics", caption: function(n, r){ return "n = " + n + ", " + r + " samples"; }}
|
|
8
|
+
};
|
|
9
|
+
var OBJ = {white: "#ffffff", black: "#222222", red: "#d62728", green: "#2ca02c", yellow: "#f2c12e", blue: "#1f77b4", brown: "#8c564b", purple: "#9467bd", pink: "#e377c2", orange: "#ff7f0e", gray: "#7f7f7f"};
|
|
10
|
+
var OBJ_NAME = {"白": "white", "黒": "black", "赤": "red", "緑": "green", "黄": "yellow", "青": "blue", "茶": "brown", "紫": "purple", "桃": "pink", "橙": "orange", "灰": "gray",
|
|
11
|
+
"白色": "white", "黒色": "black", "赤色": "red", "緑色": "green", "黄色": "yellow", "青色": "blue", "茶色": "brown", "紫色": "purple", "桃色": "pink", "橙色": "orange", "灰色": "gray", "ピンク": "pink", "オレンジ": "orange", "グレー": "gray", "grey": "gray"};
|
|
12
|
+
function objColor(name){
|
|
13
|
+
var k = String(name).trim(), lower = k.toLowerCase(), own = Object.prototype.hasOwnProperty;
|
|
14
|
+
var en = own.call(OBJ, lower) ? lower : own.call(OBJ_NAME, k) ? OBJ_NAME[k] : own.call(OBJ_NAME, lower) ? OBJ_NAME[lower] : null;
|
|
15
|
+
return en ? "var(--obj-" + en + ", " + OBJ[en] + ")" : null;
|
|
16
|
+
}
|
|
17
|
+
// Mulberry32; the only mutable random state lives in mount's local generator.
|
|
18
|
+
function random(seed){
|
|
19
|
+
return function(){
|
|
20
|
+
seed = (seed + 0x6D2B79F5) | 0;
|
|
21
|
+
var z = Math.imul(seed ^ seed >>> 15, 1 | seed);
|
|
22
|
+
z ^= z + Math.imul(z ^ z >>> 7, 61 | z);
|
|
23
|
+
return ((z ^ z >>> 14) >>> 0) / 4294967296;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function set(e, a, v){ e.setAttribute(a, String(v)); }
|
|
27
|
+
function mean(values){
|
|
28
|
+
var scale = Math.max.apply(null, values.map(function(v){ return Math.abs(v); }).concat([1]));
|
|
29
|
+
var average = values.reduce(function(s, v){ return s + v / scale; }, 0) / values.length;
|
|
30
|
+
return Math.max(-1, Math.min(1, average)) * scale;
|
|
31
|
+
}
|
|
32
|
+
function meanTicks(lo, hi, values){
|
|
33
|
+
if (lo === hi) return [lo];
|
|
34
|
+
if (hi - lo <= 10 && values.every(Number.isInteger)) return Array.from({length: hi - lo + 1}, function(_, i){ return lo + i; });
|
|
35
|
+
var scale = Math.max(1, Math.abs(lo), Math.abs(hi));
|
|
36
|
+
var rough = Math.max(Number.MIN_VALUE, (hi / scale - lo / scale) / 4 * scale);
|
|
37
|
+
var power = Math.pow(10, Math.floor(Math.log10(rough))) || Number.MIN_VALUE, fraction = rough / power;
|
|
38
|
+
var step = (fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10) * power;
|
|
39
|
+
var start = Math.ceil(lo / step), ticks = [];
|
|
40
|
+
for (var i = 0; i < 10; i++){
|
|
41
|
+
var v = (start + i) * step;
|
|
42
|
+
if (!Number.isFinite(v) || v > hi + step * 1e-10) break;
|
|
43
|
+
ticks.push(v);
|
|
44
|
+
}
|
|
45
|
+
return ticks;
|
|
46
|
+
}
|
|
47
|
+
return class extends base.MotionElement {
|
|
48
|
+
static partName = "sampling";
|
|
49
|
+
static preview = "none";
|
|
50
|
+
static steps = 4;
|
|
51
|
+
static shape = {
|
|
52
|
+
schema: {type: "object", additionalProperties: false, required: ["n"], anyOf: [{required: ["balls"]}, {required: ["values"]}], properties: {
|
|
53
|
+
balls: {type: "object"}, values: {type: "array", minItems: 2, maxItems: 30, items: {type: "number"}},
|
|
54
|
+
of: {type: "string"}, n: {type: "number"}, replace: {type: "boolean"}, repeat: {type: "number"}, seed: {type: "number"},
|
|
55
|
+
stat: {enum: ["mean", "proportion"]}, digits: {type: "number"}
|
|
56
|
+
}},
|
|
57
|
+
example: {values: [1, 2, 3, 4, 5, 6], n: 2, replace: true, repeat: 40, seed: 3}
|
|
58
|
+
};
|
|
59
|
+
static props = {
|
|
60
|
+
dur: {type: "number", default: 1, doc: "段階の秒数"},
|
|
61
|
+
stagger: {type: "number", default: 0.25, doc: "抽出のずれ(秒)"},
|
|
62
|
+
fast: {type: "number", default: 2.5, doc: "反復の秒数"},
|
|
63
|
+
size: {type: "number", default: 0, doc: "文字 px(0 は 26)"}
|
|
64
|
+
};
|
|
65
|
+
timing(name, fallback, zero){ var v = this.props[name]; return Number.isFinite(v) && (zero ? v >= 0 : v > 0) ? v : fallback; }
|
|
66
|
+
duration(k){
|
|
67
|
+
if (k < 1 || k > 4) return 0;
|
|
68
|
+
if (k === 4) return this.timing("fast", 2.5);
|
|
69
|
+
var n = this.model ? this.model.n : Math.max(1, Math.min(30, Math.round(this.data.n)));
|
|
70
|
+
return this.timing("dur", 1) + (k === 2 ? (n - 1) * this.timing("stagger", 0.25, true) : 0);
|
|
71
|
+
}
|
|
72
|
+
fmt(v){ return v.toFixed(this.model.digits); }
|
|
73
|
+
label(g, x, y, s, anchor){
|
|
74
|
+
var t = base.el("text", {x: x, y: y, "font-size": this.fs, "text-anchor": anchor || "start", fill: "var(--fg)"}, g);
|
|
75
|
+
t.textContent = s; return t;
|
|
76
|
+
}
|
|
77
|
+
mount(ctx){
|
|
78
|
+
var self = this, d = this.data, P = this.props;
|
|
79
|
+
this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
|
|
80
|
+
var T = this.T;
|
|
81
|
+
[["dur", 1, false], ["stagger", 0.25, true], ["fast", 2.5, false]].forEach(function(a){
|
|
82
|
+
if (self.timing(a[0], -1, a[2]) === -1){ ctx.report("attr", "[sampling] invalid " + a[0] + "; using " + a[1]); P[a[0]] = a[1]; }
|
|
83
|
+
});
|
|
84
|
+
if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[sampling] size must be 0 or at least 24; using 26"); P.size = 0; }
|
|
85
|
+
this.fs = P.size || 26;
|
|
86
|
+
this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb";
|
|
87
|
+
this.setAttribute("role", "img");
|
|
88
|
+
var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight);
|
|
89
|
+
var items = [], composition = [], balls = d.balls !== undefined;
|
|
90
|
+
var invalid = balls && d.values !== undefined;
|
|
91
|
+
if (balls){
|
|
92
|
+
Object.keys(d.balls).forEach(function(name){
|
|
93
|
+
var count = d.balls[name], col = objColor(name);
|
|
94
|
+
if (!col) ctx.report("data", "[sampling] unknown colour " + name + "; drawn as gray with its name");
|
|
95
|
+
if (!Number.isInteger(count) || count < 0 || count > 30){ invalid = true; return; }
|
|
96
|
+
composition.push(name + " " + count);
|
|
97
|
+
for (var i = 0; i < count; i++) items.push({label: name, color: col || objColor("gray")});
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
items = d.values.map(function(v){ return {label: String(v), value: v}; });
|
|
101
|
+
composition = items.map(function(o){ return o.label; });
|
|
102
|
+
}
|
|
103
|
+
if (invalid || items.length < 2 || items.length > 30){
|
|
104
|
+
ctx.report("data", "[sampling] supply exactly one population: 2–30 values or balls with non-negative integer counts totalling 2–30");
|
|
105
|
+
this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
|
|
106
|
+
this.label(this.svg, 8, this.fs + 4, T.population + ": 2–30");
|
|
107
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.population + ": 2–30");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
function integer(key, fallback, lo, hi){
|
|
111
|
+
var v = d[key] === undefined ? fallback : d[key];
|
|
112
|
+
if (!Number.isInteger(v) || v < lo || v > hi){
|
|
113
|
+
v = Math.max(lo, Math.min(hi, Math.round(v)));
|
|
114
|
+
ctx.report("data", "[sampling] " + key + " must be an integer " + lo + "–" + hi + "; clamped to " + v);
|
|
115
|
+
}
|
|
116
|
+
return v;
|
|
117
|
+
}
|
|
118
|
+
var stat = balls ? "proportion" : "mean", of = d.of === undefined ? (balls ? Object.keys(d.balls)[0] : "") : d.of;
|
|
119
|
+
if (d.stat !== undefined && d.stat !== stat) ctx.report("data", "[sampling] stat=" + d.stat + " is incompatible with this population; using " + stat);
|
|
120
|
+
if (balls && !Object.prototype.hasOwnProperty.call(d.balls, of)) ctx.report("data", "[sampling] of=" + of + " is absent from the population; proportion is zero");
|
|
121
|
+
var n = integer("n", 1, 1, d.replace ? 30 : items.length), repeat = integer("repeat", 40, 1, 200), digits = integer("digits", 2, 0, 10);
|
|
122
|
+
var seed = d.seed === undefined ? 1 : d.seed;
|
|
123
|
+
if (!Number.isSafeInteger(seed)){ ctx.report("data", "[sampling] seed must be a safe integer; using 1"); seed = 1; }
|
|
124
|
+
function statistic(sample){
|
|
125
|
+
return balls ? sample.filter(function(id){ return items[id].label === of; }).length / sample.length : mean(sample.map(function(id){ return items[id].value; }));
|
|
126
|
+
}
|
|
127
|
+
var rng = random(seed), samples = [];
|
|
128
|
+
for (var r = 0; r < repeat; r++){
|
|
129
|
+
var pool = items.map(function(_, i){ return i; }), ids = [];
|
|
130
|
+
for (var j = 0; j < n; j++){
|
|
131
|
+
var at = Math.floor(rng() * pool.length); ids.push(pool[at]);
|
|
132
|
+
if (!d.replace) pool.splice(at, 1);
|
|
133
|
+
}
|
|
134
|
+
samples.push({ids: ids, value: statistic(ids)});
|
|
135
|
+
}
|
|
136
|
+
this.model = {items: items, samples: samples, n: n, repeat: repeat, digits: digits, replace: !!d.replace, stat: stat, of: of,
|
|
137
|
+
population: statistic(items.map(function(_, i){ return i; })), average: mean(samples.map(function(o){ return o.value; }))};
|
|
138
|
+
var m = this.model, rule = m.replace ? T.with : T.without;
|
|
139
|
+
this.composition = composition.join(T === TEXT.ja ? "・" : ", ");
|
|
140
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", T.population + ": " + this.composition + "; " + rule + "; " + T.caption(n, repeat) + "; " + T.population + " " + this.fmt(m.population) + "; " + T.statsMean + " " + this.fmt(m.average));
|
|
141
|
+
// Source Sans 3's SVG box is 1.43em tall, including its descender.
|
|
142
|
+
var fs = this.fs, line = fs * 1.45 + 4, width = function(s){ return base.textWidth(s, fs, {font: self}) + 8; };
|
|
143
|
+
var left = W * 0.24, middle = W * 0.38, sx = left + 22, px = left + middle + 48, pw = Math.max(1, W - px - 22);
|
|
144
|
+
// Plot supplies the numerical mapping and axis; normalized values avoid overflow.
|
|
145
|
+
var vals = items.map(function(o){ return o.value; }), lo = balls ? 0 : Math.min.apply(null, vals), hi = balls ? 1 : Math.max.apply(null, vals);
|
|
146
|
+
var scale = Math.max(1, Math.abs(lo), Math.abs(hi)), a = lo / scale, b = hi / scale;
|
|
147
|
+
var captionY = H - fs * 0.4 - 4, axisY = captionY - 3 * line;
|
|
148
|
+
var plotTop = fs + 4 + fs * 0.4 + 8, plotH = axisY - plotTop;
|
|
149
|
+
var plot = deps.plot.Plot(this, {xr: a === b ? [a - 1, b + 1] : [a, b], yr: [0, 1], xt: [], yt: [], noY: true,
|
|
150
|
+
m: {l: px + 12, r: W - px - 12 - Math.max(1, pw - 24), t: plotTop, b: H - axisY}});
|
|
151
|
+
this.svg = plot.svg;
|
|
152
|
+
set(this.svg, "width", W); set(this.svg, "height", H); set(this.svg, "aria-hidden", "true");
|
|
153
|
+
var axes = [].filter.call(this.svg.children, function(e){ return e.getAttribute("class") === "axes"; })[0];
|
|
154
|
+
this.svg.removeChild(axes);
|
|
155
|
+
var X = function(v){ return plot.x(v / scale); };
|
|
156
|
+
this.populationLayer = base.el("g", {opacity: 0}, this.svg);
|
|
157
|
+
this.sampleLayer = base.el("g", {opacity: 0}, this.svg);
|
|
158
|
+
this.plotLayer = base.el("g", {opacity: 0}, this.svg);
|
|
159
|
+
this.plotLayer.appendChild(axes);
|
|
160
|
+
this.finalLayer = base.el("g", {opacity: 0}, this.plotLayer);
|
|
161
|
+
this.label(this.populationLayer, 8, fs + 4, T.population);
|
|
162
|
+
this.label(this.sampleLayer, sx, fs + 4, T.sample);
|
|
163
|
+
this.label(this.plotLayer, px, fs + 4, T.distribution);
|
|
164
|
+
var small = false, itemW = Math.max(52, ...items.map(function(o){ return width(o.label) + (balls ? 36 : 16); }));
|
|
165
|
+
var cols = Math.max(1, Math.min(items.length, Math.floor((left - 24) / itemW))), rows = Math.ceil(items.length / cols), rowH = Math.max(48, line);
|
|
166
|
+
var bagTop = line + 10, bagBottom = bagTop + rows * rowH + 12;
|
|
167
|
+
base.el("rect", {x: 4, y: bagTop, width: Math.max(1, left - 8), height: bagBottom - bagTop, rx: 18, fill: "none", stroke: "var(--fg)", "stroke-width": 2}, this.populationLayer);
|
|
168
|
+
function item(g, o){
|
|
169
|
+
var shape = base.el(balls ? "circle" : "rect", balls ? {cx: 14, cy: 0, r: 12, fill: o.color, stroke: "var(--fg)", "stroke-width": 2} : {x: 0, y: -rowH / 2 + 3, width: itemW - 8, height: rowH - 6, rx: 6, fill: "var(--bg)", stroke: "var(--fg)", "stroke-width": 2}, g);
|
|
170
|
+
var text = self.label(g, balls ? 34 : (itemW - 8) / 2, fs * 0.312, o.label, balls ? "start" : "middle");
|
|
171
|
+
return {g: g, shape: shape, text: text};
|
|
172
|
+
}
|
|
173
|
+
this.originals = items.map(function(o, i){
|
|
174
|
+
var x = 14 + (i % cols) * itemW, y = bagTop + 8 + rowH / 2 + Math.floor(i / cols) * rowH;
|
|
175
|
+
var q = item(base.el("g", {transform: "translate(" + x + " " + y + ")"}, self.populationLayer), o); q.x = x; q.y = y; return q;
|
|
176
|
+
});
|
|
177
|
+
// Wrap word groups below the bag; reserve a full font box between baselines.
|
|
178
|
+
var y = bagBottom;
|
|
179
|
+
if (balls){
|
|
180
|
+
// Keep separators inside the string: width padding must not add spaces around ・.
|
|
181
|
+
var words = "";
|
|
182
|
+
composition.forEach(function(s){
|
|
183
|
+
var joined = words ? words + (T === TEXT.ja ? "・" : ", ") + s : s;
|
|
184
|
+
if (words && width(joined) > left - 16){ y += line; self.label(self.populationLayer, 8, y, words); words = s; }
|
|
185
|
+
else words = joined;
|
|
186
|
+
if (width(s) > left - 16) small = true;
|
|
187
|
+
});
|
|
188
|
+
y += line; self.label(self.populationLayer, 8, y, words);
|
|
189
|
+
}
|
|
190
|
+
var rules = width(rule) <= left - 16 ? [rule] : (T === TEXT.ja ? [m.replace ? "戻す" : "戻さない", m.replace ? "(復元抽出)" : "(非復元抽出)"] : rule.split(" "));
|
|
191
|
+
rules.forEach(function(s){ y += line; self.label(self.populationLayer, 8, y, s); if (width(s) > left - 16) small = true; });
|
|
192
|
+
if (y + fs * 0.4 + 4 > H || itemW > left - 24) small = true;
|
|
193
|
+
var sampleY = bagTop + rowH / 2 + 8, sampleW = n * itemW;
|
|
194
|
+
if (sampleW > middle - 10) small = true;
|
|
195
|
+
this.drawn = Array.from({length: n}, function(_, j){ var q = item(base.el("g", {}, self.sampleLayer), items[samples[0].ids[j]]); q.x = sx + j * itemW; q.y = sampleY; return q; });
|
|
196
|
+
this.statLayer = base.el("g", {opacity: 0}, this.sampleLayer);
|
|
197
|
+
var statY = sampleY + rowH / 2 + line;
|
|
198
|
+
this.statName = this.label(this.statLayer, sx, statY, balls ? of + T.proportion : T.mean);
|
|
199
|
+
this.statValue = this.label(this.statLayer, sx, statY + line, "");
|
|
200
|
+
var statLabel = balls ? of + T.proportion : T.mean;
|
|
201
|
+
if (width(statLabel) > middle - 10 || statY + line + fs * 0.4 > H) small = true;
|
|
202
|
+
var ticks = balls ? [0, 0.25, 0.5, 0.75, 1] : meanTicks(lo, hi, vals), lastRight = -Infinity;
|
|
203
|
+
ticks.forEach(function(v){
|
|
204
|
+
var xx = X(v), rounded = +v.toPrecision(4), s = Number.isFinite(rounded) ? String(rounded) : String(v), w = width(s);
|
|
205
|
+
base.el("line", {x1: xx, x2: xx, y1: axisY, y2: axisY + 7, stroke: "var(--fg)", "stroke-width": 2}, self.plotLayer);
|
|
206
|
+
var anchor = v === lo ? "start" : v === hi ? "end" : "middle";
|
|
207
|
+
var tx = anchor === "start" ? xx : anchor === "end" ? xx - w : xx - w / 2;
|
|
208
|
+
if (tx < lastRight + 4) small = true; lastRight = tx + w;
|
|
209
|
+
self.label(self.plotLayer, xx, axisY + line, s, anchor);
|
|
210
|
+
});
|
|
211
|
+
this.label(this.plotLayer, px, axisY + 2 * line, balls ? T.proportionAxis : T.meanAxis);
|
|
212
|
+
this.label(this.finalLayer, px, captionY, T.caption(n, repeat));
|
|
213
|
+
var markerLabel = T.population + " " + this.fmt(m.population);
|
|
214
|
+
var markerY = fs + 4 + line, markerRight = px + width(markerLabel);
|
|
215
|
+
this.label(this.finalLayer, px, markerY, markerLabel);
|
|
216
|
+
var markerBottom = markerY + fs * 0.4 + 8;
|
|
217
|
+
base.el("line", {x1: X(m.population), x2: X(m.population), y1: markerBottom, y2: axisY, stroke: "var(--emph)", "stroke-width": 2, "stroke-dasharray": "6 5"}, this.finalLayer);
|
|
218
|
+
// Stack horizontally intersecting dots at separate levels, preserving exact numerical x.
|
|
219
|
+
function stack(radius){
|
|
220
|
+
var levels = [];
|
|
221
|
+
return samples.map(function(o){
|
|
222
|
+
var xx = X(o.value), lv = 0;
|
|
223
|
+
while (levels[lv] && levels[lv].some(function(v){ return Math.abs(v - xx) < 2 * radius + 2; })) lv++;
|
|
224
|
+
if (!levels[lv]) levels[lv] = []; levels[lv].push(xx);
|
|
225
|
+
return {x: xx, level: lv};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
// The marker label occupies only the plot's upper-left corner, not a whole row.
|
|
229
|
+
// A 1px gap between circle fills leaves more room for repeated values.
|
|
230
|
+
function fits(positions, radius){
|
|
231
|
+
return positions.every(function(o){
|
|
232
|
+
var top = axisY - 2 * radius - 3 - o.level * (2 * radius + 1);
|
|
233
|
+
return top >= (o.x - radius < markerRight && o.x + radius > px ? markerBottom : plotTop);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
var radius = 8, positions;
|
|
237
|
+
while (true){
|
|
238
|
+
positions = stack(radius);
|
|
239
|
+
if (fits(positions, radius) || radius === 5) break;
|
|
240
|
+
radius--;
|
|
241
|
+
}
|
|
242
|
+
if (!fits(positions, radius)) ctx.report("size", "[sampling] dot stack exceeds plot at minimum 5px radius; increase height or reduce repeat");
|
|
243
|
+
this.dots = positions.map(function(o){
|
|
244
|
+
var yy = axisY - radius - 3 - o.level * (2 * radius + 1);
|
|
245
|
+
return {x: o.x, y: yy, el: base.el("circle", {cx: o.x, cy: yy, r: radius, fill: "var(--term)", stroke: "var(--fg)", "stroke-width": 1, opacity: 0}, self.plotLayer)};
|
|
246
|
+
});
|
|
247
|
+
this.plotTop = plotTop;
|
|
248
|
+
if ([T.distribution, markerLabel, T.caption(n, repeat), balls ? T.proportionAxis : T.meanAxis].some(function(s){ return width(s) > pw; }) || plotH < 40) small = true;
|
|
249
|
+
if (small) ctx.report("size", "[sampling] population, sample row or plot labels do not fit; enlarge the element or shorten names");
|
|
250
|
+
// Check all statistic strings, since a later sample can be wider than the first.
|
|
251
|
+
if (samples.some(function(o){ return width(self.statText(o)) > middle - 10; })) ctx.report("size", "[sampling] statistic does not fit; enlarge width or reduce digits");
|
|
252
|
+
}
|
|
253
|
+
statText(sample){
|
|
254
|
+
var m = this.model;
|
|
255
|
+
return (m.stat === "proportion" ? sample.ids.filter(function(i){ return m.items[i].label === m.of; }).length + "/" + m.n + " = " : "") + this.fmt(sample.value);
|
|
256
|
+
}
|
|
257
|
+
render(k, t){
|
|
258
|
+
if (!this.model) return;
|
|
259
|
+
var self = this, m = this.model, P = this.props;
|
|
260
|
+
var phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, P.dur); };
|
|
261
|
+
set(this.populationLayer, "opacity", phase(1));
|
|
262
|
+
set(this.sampleLayer, "opacity", k >= 2 ? 1 : 0);
|
|
263
|
+
set(this.statLayer, "opacity", phase(3));
|
|
264
|
+
set(this.plotLayer, "opacity", phase(3));
|
|
265
|
+
var progress = k > 4 ? 1 : k < 4 ? 0 : Math.max(0, Math.min(1, t / P.fast));
|
|
266
|
+
var completed = k < 3 ? 0 : k === 3 ? (t >= P.dur ? 1 : 0) : 1 + Math.floor(progress * (m.repeat - 1));
|
|
267
|
+
var rep = k >= 4 ? Math.min(m.repeat - 1, completed - 1) : 0, sample = m.samples[rep];
|
|
268
|
+
var full = k >= 4 && progress === 1 || k === 3 && t >= P.dur;
|
|
269
|
+
this.originals.forEach(function(o, i){
|
|
270
|
+
var j = sample.ids.indexOf(i), gone = !m.replace && j >= 0 && !full && (k >= 3 || k === 2 && t > j * P.stagger);
|
|
271
|
+
set(o.g, "opacity", gone ? 0 : 1);
|
|
272
|
+
});
|
|
273
|
+
this.drawn.forEach(function(o, j){
|
|
274
|
+
var id = sample.ids[j], original = self.originals[id], e = k > 2 ? 1 : k < 2 ? 0 : base.prog(t, j * P.stagger, P.dur);
|
|
275
|
+
set(o.g, "opacity", k >= 2 && (k > 2 || t > j * P.stagger) ? 1 : 0);
|
|
276
|
+
set(o.g, "transform", "translate(" + base.lerp(original.x, o.x, e) + " " + base.lerp(original.y, o.y, e) + ")");
|
|
277
|
+
o.text.textContent = m.items[id].label;
|
|
278
|
+
if (m.stat === "proportion") set(o.shape, "style", "fill:" + m.items[id].color + ";stroke:var(--fg)");
|
|
279
|
+
});
|
|
280
|
+
this.statValue.textContent = this.statText(sample);
|
|
281
|
+
this.dots.forEach(function(o, i){
|
|
282
|
+
var drop = i === 0 && k === 3 ? base.prog(t, 0, P.dur) : 1;
|
|
283
|
+
set(o.el, "opacity", i < completed || i === 0 && k === 3 && t > 0 ? 1 : 0);
|
|
284
|
+
set(o.el, "cy", base.lerp(self.plotTop, o.y, drop));
|
|
285
|
+
});
|
|
286
|
+
set(this.finalLayer, "opacity", k >= 4 && progress === 1 ? 1 : 0);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Lines drawn one at a time on shared axes, each named at its end (no legend)
|
|
3
|
+
steps: largest step (default: number of series)
|
|
4
|
+
props:
|
|
5
|
+
xr: x range
|
|
6
|
+
yr: y range
|
|
7
|
+
xt: x ticks
|
|
8
|
+
yt: y ticks
|
|
9
|
+
xf: x tick decimals
|
|
10
|
+
yf: y tick decimals
|
|
11
|
+
xl: x title
|
|
12
|
+
yl: y title
|
|
13
|
+
n: samples
|
|
14
|
+
dur: draw seconds
|
|
15
|
+
lw: line width
|
|
16
|
+
size: text px (≥ 24; 0 = default)
|
|
17
|
+
example: [{"label": "Demand D", "f": "10 - x"}, {"label": "Supply S", "f": "2 + x"}, {"label": "Equilibrium", "pts": [[4, 0], [4, 6]], "dash": true}]
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
One comparison at a time: mean, median, quantiles; losses.
|
|
21
|
+
|
|
22
|
+
Series: a JSON array in a child script. One series = one step; same `step` = together.
|
|
23
|
+
|
|
24
|
+
| Field | Meaning |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `label` | line name |
|
|
27
|
+
| `f` | expression in x (see below) |
|
|
28
|
+
| `pts` | points `[[x, y], …]` |
|
|
29
|
+
| `tone` | `term` `emph` `accent2` `muted` `fg` `series-1..4` |
|
|
30
|
+
| `dash` | dashed |
|
|
31
|
+
| `area` / `areaLabel` | shaded span `[a, b]` (several; null = edge), labels |
|
|
32
|
+
| `labelAt` / `anchor` / `dx` / `dy` / `ly` | name at x = `labelAt` (default: end); `anchor` `right` `left` `above` `below`; `ly` = y |
|
|
33
|
+
|
|
34
|
+
`f` is arithmetic, not code: numbers, `x`, `Math` functions/constants (`sin(x)`, `PI`; no `random`), `N(x, mean, sd)`, `+ - * / % **`, comparisons, `&& || !`, `? :`. Powers: `**`. An unreadable `f` shows a card.
|
|
35
|
+
|
|
36
|
+
<!-- llm: omit -->
|
|
37
|
+
- `area`: shades to y = 0; several spans; rejection regions, p-values; `areaLabel` per span
|
|
38
|
+
Older forms (still work; not described to the AI)
|
|
39
|
+
|
|
40
|
+
- `color` = `tone`; `at` = `labelAt` (only without `labelAt`)
|
|
41
|
+
- `anchor` `start` `middle` `end`: raw text-anchor
|
|
42
|
+
- Without `step`, series i is step i + 1. Lecture view shows later lines at `--preview-opacity`
|
|
43
|
+
- The demo is `demo.html`. Series fields match `m-scatter` (conventions §3)
|
|
44
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// m-curves:同じ座標軸に線を 1 本ずつ引く。線の名前は凡例でなく線の端に直接書く
|
|
2
|
+
// <m-curves xr="[-3,3]" yr="[0,0.5]" xt="[-2,0,2]" yt="[0,0.2,0.4]" xl="*y*" yl="密度" style="height:380px">
|
|
3
|
+
// <script type="application/json">[{"label":"予測分布","f":"N(x,0,1)"},{"label":"中央値","pts":[[0,0],[0,0.4]],"dash":true}]
|
|
4
|
+
// (JSON の終わり)</m-curves>
|
|
5
|
+
// 1 系列 = 1 段階(書いた順。系列の step で変えられ、同じ step の系列は一緒に引く)。f は x の式(Math の関数と N(x,平均,標準偏差) が使える)、pts は点列
|
|
6
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・previewOpacity、plot の Plot、expr の compile を使い、
|
|
7
|
+
// プレイヤーのグローバルは使わない(1.x は式の評価器 egatari-expr を写して持っていた)。破線の mask の id は
|
|
8
|
+
// curves-2-0-2-<n>m<系列>:このパーツの名前と版に、このパーツだけの数え(1.x は mc<n>m<系列> で、DECK.Plot の数えを進めていた)
|
|
9
|
+
egatariParts.define({name: "curves", version: "2.2.0", requires: {base: "1.1.0", expr: "1.0.0", plot: "1.1.1"}, element: "m-curves"}, function(deps){
|
|
10
|
+
"use strict";
|
|
11
|
+
var base = deps.base, plot = deps.plot, expr = deps.expr;
|
|
12
|
+
var ID = "curves-2-0-2-"; // name and version of this part, dots replaced (spec §6.1 Identifiers)
|
|
13
|
+
var count = 0; // this part's own counter for its ids (deterministic: the order of mounting)
|
|
14
|
+
// 線の名前(26px)の下付き・上付きの分の高さ(px)。base 1.1.0 で mtext の下付き・上付きは 24px 以上になり、下付きの字の下端は基線から
|
|
15
|
+
// 添字の 0.75 倍まで、上付きの字の上端は 1.4 倍まで届く(Source Sans 3 で測った値。BIZ UDPGothic ではそれぞれ 0.5 倍と 1.2 倍)。
|
|
16
|
+
// 字の下の余白(字の 0.12 倍)・上の高さ(0.88 倍)を超える分。記法がなければ 0
|
|
17
|
+
function subX(s, fs){ var ss = Math.max(24, Math.round(fs * 0.75)); return /_./.test(s) ? Math.max(0, 0.75 * ss - 0.12 * fs) : 0; }
|
|
18
|
+
function supX(s, fs){ var ss = Math.max(24, Math.round(fs * 0.75)); return /\^./.test(s) ? Math.max(0, 1.4 * ss - 0.88 * fs) : 0; }
|
|
19
|
+
return class extends base.MotionElement {
|
|
20
|
+
static partName = "curves"; // the registry name (define meta name), for report prefixes
|
|
21
|
+
// データの形(kit/shape.js):線の配列。軸(xr yr xt yt xl yl)は属性に書く(JSON の中ではない)
|
|
22
|
+
static shape = {
|
|
23
|
+
schema: {type: "array", items: {type: "object", additionalProperties: false, anyOf: [{required: ["f"]}, {required: ["pts"]}],
|
|
24
|
+
properties: {label: {type: "string"}, f: {type: "string"}, pts: {type: "array", items: {type: "array", items: {type: "number"}, minItems: 2, maxItems: 2}},
|
|
25
|
+
tone: {type: "string"}, step: {type: "integer"}, labelAt: {type: "number"},
|
|
26
|
+
color: {type: "string"}, dash: {type: "boolean"}, xr: {type: "array", items: {type: "number"}, minItems: 2, maxItems: 2},
|
|
27
|
+
area: {type: "array"}, areaLabel: {type: ["string", "array"]},
|
|
28
|
+
at: {type: "number"}, anchor: {enum: ["right", "left", "above", "below", "top", "bottom", "start", "middle", "end"]}, dx: {type: "number"}, dy: {type: "number"}, ly: {type: "number"}}}},
|
|
29
|
+
example: [{label: "需要 D", f: "10 - x"}, {label: "供給 S", f: "2 + x"}, {label: "均衡", pts: [[4, 0], [4, 6]], dash: true}],
|
|
30
|
+
// よくある書き違い(指示の部品の一覧に書く)
|
|
31
|
+
note: {en: "the data is the array itself, not {\"series\": […]}; axes go in attributes (xr=\"[0,10]\" xl=\"…\"); the expression field is f in x (not fn, not u)",
|
|
32
|
+
ja: "データは配列そのもの({\"series\": […]} ではない)。軸は属性に書く(xr=\"[0,10]\" xl=\"…\")。式の欄は f で、変数は x(fn・u ではない)"},
|
|
33
|
+
};
|
|
34
|
+
static props = {
|
|
35
|
+
xr: {type: "json", default: [0, 1], doc: "横軸の範囲"}, yr: {type: "json", default: [0, 1], doc: "縦軸の範囲"},
|
|
36
|
+
xt: {type: "json", default: []}, yt: {type: "json", default: []},
|
|
37
|
+
xf: {type: "number", default: undefined, doc: "横軸の目盛りの小数桁"}, yf: {type: "number", default: undefined, doc: "縦軸の目盛りの小数桁"},
|
|
38
|
+
xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
|
|
39
|
+
n: {type: "number", default: 300, doc: "f を描く分割数"},
|
|
40
|
+
dur: {type: "number", default: 1.0, doc: "1 本を引く秒数"},
|
|
41
|
+
lw: {type: "number", default: 3.5, doc: "線の太さ"},
|
|
42
|
+
size: {type: "number", default: 0, doc: "字の大きさ(24 以上。0 = 既定)"},
|
|
43
|
+
};
|
|
44
|
+
// 系列 i の段階:step(書いてあれば)、なければ i + 1。段階の数はその最大(step がなければ系列の数で、今までと同じ)
|
|
45
|
+
stepOf(s, i){ return s && s.step !== undefined ? s.step : i + 1; }
|
|
46
|
+
get steps(){
|
|
47
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
48
|
+
var self = this, m = 0;
|
|
49
|
+
(this.data || []).forEach(function(s, i){ m = Math.max(m, self.stepOf(s, i)); });
|
|
50
|
+
return m;
|
|
51
|
+
}
|
|
52
|
+
mount(ctx){
|
|
53
|
+
var P = this.props, D = base, self = this, S = this.data || [];
|
|
54
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
55
|
+
// size:字の大きさ(24 未満は 24 にして知らせる)。0 なら 2.0 と同じ大きさと余白
|
|
56
|
+
var SZ = P.size > 0 ? Math.max(24, P.size) : 0, K = SZ ? SZ / 26 : 1, F = SZ || 26;
|
|
57
|
+
if (P.size > 0 && P.size < 24) ctx.report("attr", "[curves] size " + P.size + " is under 24 px; 24 is used");
|
|
58
|
+
var p = this.p = plot.Plot(this, {xr: P.xr, yr: P.yr, xt: P.xt, yt: P.yt, xf: P.xf, yf: P.yf, xl: P.xl, yl: P.yl, fs: SZ || undefined, m: {l: Math.round(86 * K), r: 24, t: Math.round(24 * K), b: Math.round(64 * K)}});
|
|
59
|
+
var uid = ID + (++count), defs = D.el("defs", {}, p.svg);
|
|
60
|
+
var N = function(x, m, s){ return Math.exp(-0.5 * Math.pow((x - m) / s, 2)) / (s * Math.sqrt(2 * Math.PI)); };
|
|
61
|
+
var x0 = p.m.l, x1 = p.W - p.m.r, y0 = p.m.t, y1 = p.H - p.m.b;
|
|
62
|
+
// 系列ごとに:点列、線、(破線なら)描く範囲の mask、端の名前
|
|
63
|
+
this.items = S.map(function(s, i){
|
|
64
|
+
var pts;
|
|
65
|
+
if (s.pts) pts = s.pts.map(function(q){ return [p.x(q[0]), p.y(q[1])]; });
|
|
66
|
+
else {
|
|
67
|
+
// 式は木にしてから計算する(コードとしては実行しない。Egatari spec §6)。書けない式は SyntaxError で、base が受け止めて札を出す(spec §6.1 Containment)
|
|
68
|
+
var g = expr.compile(s.f, {name: "[" + i + "].f", vars: ["x"], funcs: {N: N}, bareMath: true}), a = s.xr ? s.xr[0] : P.xr[0], b = s.xr ? s.xr[1] : P.xr[1];
|
|
69
|
+
pts = [];
|
|
70
|
+
for (var j = 0; j <= P.n; j++){ var v = a + (b - a) * j / P.n; pts.push([p.x(v), p.y(g(v))]); }
|
|
71
|
+
}
|
|
72
|
+
// 有限でない点(NaN・±Infinity)は線を切り、有限な区間ごとに M から引き直す(1 つの NaN で線全体が消えない)
|
|
73
|
+
var d = "", pen = false, gap = false;
|
|
74
|
+
pts.forEach(function(q){
|
|
75
|
+
if (isFinite(q[0]) && isFinite(q[1])){ d += (pen ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); pen = true; }
|
|
76
|
+
else { pen = false; gap = true; }
|
|
77
|
+
});
|
|
78
|
+
if (gap) ctx.report("data", "[curves] series " + i + " (" + JSON.stringify(s.label || "") + ") has points that are not finite numbers (NaN or ±Infinity, e.g. log or division by zero); the line is broken there");
|
|
79
|
+
pts = pts.filter(function(q){ return isFinite(q[0]) && isFinite(q[1]); });
|
|
80
|
+
var col = colorOf(s.tone || s.color, i);
|
|
81
|
+
var it = {step: self.stepOf(s, i)};
|
|
82
|
+
if (s.dash){
|
|
83
|
+
// 破線は dasharray を描画に使えないので、同じ線を mask にして引く
|
|
84
|
+
var mk = D.el("mask", {id: uid + "m" + i, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: p.W, height: p.H}, defs);
|
|
85
|
+
it.mpath = D.el("path", {d: d, fill: "none", stroke: "#fff", "stroke-width": P.lw + 6, pathLength: 1, "stroke-dasharray": "1 2"}, mk);
|
|
86
|
+
var gg = D.el("g", {mask: "url(#" + uid + "m" + i + ")", "clip-path": p.clip}, p.svg);
|
|
87
|
+
it.path = D.el("path", {d: d, fill: "none", stroke: col, "stroke-width": P.lw, "stroke-dasharray": "10 8", "stroke-linecap": "butt"}, gg);
|
|
88
|
+
it.draw = it.mpath;
|
|
89
|
+
} else {
|
|
90
|
+
it.path = D.el("path", {d: d, fill: "none", stroke: col, "stroke-width": P.lw, "clip-path": p.clip, pathLength: 1, "stroke-dasharray": "1 2", "stroke-linejoin": "round"}, p.svg);
|
|
91
|
+
it.draw = it.path;
|
|
92
|
+
}
|
|
93
|
+
// 面積(area:[a, b] か [[a, b], …]。null は軸の端):線と横軸(y = 0、範囲の外なら下の端)のあいだを、その区間だけ薄く塗る。
|
|
94
|
+
// 棄却域・p 値・信頼区間・確率など。線が引き終わってから出る(名前と同じ時に)。areaLabel は区間ごとに中に書く(字の列なら区間の順に)
|
|
95
|
+
if (s.area !== undefined){
|
|
96
|
+
var A = Array.isArray(s.area) && s.area.length && Array.isArray(s.area[0]) ? s.area : [s.area];
|
|
97
|
+
var yb = p.y(Math.max(Math.min(P.yr[0], P.yr[1]), Math.min(Math.max(P.yr[0], P.yr[1]), 0))), ad = "", segs = [];
|
|
98
|
+
A.forEach(function(r){
|
|
99
|
+
if (!Array.isArray(r) || r.length !== 2 || r.some(function(v){ return v !== null && !(typeof v === "number" && isFinite(v)); })){ ctx.report("data", "[curves] series " + i + ": area " + JSON.stringify(r) + " is not [from, to] (numbers, or null for the edge)"); return; }
|
|
100
|
+
var la = p.x(r[0] === null ? P.xr[0] : r[0]), lb = p.x(r[1] === null ? P.xr[1] : r[1]);
|
|
101
|
+
if (la > lb){ var tt = la; la = lb; lb = tt; }
|
|
102
|
+
var seg = pts.filter(function(q){ return isFinite(q[0]) && isFinite(q[1]) && q[0] >= la - 0.01 && q[0] <= lb + 0.01; });
|
|
103
|
+
if (seg.length < 2){ ctx.report("data", "[curves] series " + i + ": area " + JSON.stringify(r) + " has no part of the line in it"); return; }
|
|
104
|
+
ad += "M" + seg[0][0].toFixed(1) + "," + yb.toFixed(1) + seg.map(function(q){ return "L" + q[0].toFixed(1) + "," + q[1].toFixed(1); }).join("") + "L" + seg[seg.length - 1][0].toFixed(1) + "," + yb.toFixed(1) + "Z";
|
|
105
|
+
segs.push({w: seg[seg.length - 1][0] - seg[0][0], seg: seg});
|
|
106
|
+
});
|
|
107
|
+
if (ad){
|
|
108
|
+
it.area = D.el("path", {d: ad, fill: col, "fill-opacity": 0.28, stroke: "none", "clip-path": p.clip, opacity: 0}, p.svg);
|
|
109
|
+
p.svg.insertBefore(it.area, s.dash ? it.path.parentNode : it.path); // 線の下に
|
|
110
|
+
// 区間の名前:区間の真ん中の上(線より上、字の高さぶん離す)。細い区間でも読めるように線の上に置き、背景色で縁取る
|
|
111
|
+
it.areaLabs = [];
|
|
112
|
+
segs.forEach(function(o, j){
|
|
113
|
+
var t = Array.isArray(s.areaLabel) ? s.areaLabel[j] : s.areaLabel;
|
|
114
|
+
if (!t) return;
|
|
115
|
+
var mid = o.seg[Math.floor(o.seg.length / 2)], top = Math.min.apply(null, o.seg.map(function(q){ return q[1]; }));
|
|
116
|
+
var tx = Math.max(x0 + 4, Math.min(x1 - 4, mid[0])), ty = Math.max(y0 + F, top - 10);
|
|
117
|
+
it.areaLabs.push(D.mtext(p.svg, tx, ty, t, {"text-anchor": "middle", fill: col, stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": F, "font-weight": 700, opacity: 0}));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// 名前の位置:labelAt(横軸の値)の点、なければ描画範囲の中の最後の点。at は labelAt の古い名前(labelAt がないときだけ)
|
|
122
|
+
var inside = pts.filter(function(q){ return q[0] >= x0 - .5 && q[0] <= x1 + .5 && q[1] >= y0 - .5 && q[1] <= y1 + .5; });
|
|
123
|
+
var end = inside.length ? inside[inside.length - 1] : pts[pts.length - 1];
|
|
124
|
+
var lat = s.labelAt !== undefined ? s.labelAt : s.at;
|
|
125
|
+
if (!end){ it.lx = it.ly = it.x0 = it.x1 = 0; it.anchor = "start"; it.col = col; it.label = ""; return it; } // 有限な点がない:名前は書かない
|
|
126
|
+
if (lat !== undefined){
|
|
127
|
+
var ax = p.x(lat), best = pts[0];
|
|
128
|
+
pts.forEach(function(q){ if (Math.abs(q[0] - ax) < Math.abs(best[0] - ax)) best = q; });
|
|
129
|
+
end = best;
|
|
130
|
+
}
|
|
131
|
+
// anchor:right(点の右から書く)・left(点の左で終わる)・above / below(点の上・下に中央そろえ、約 0.9 字ぶん離す)。
|
|
132
|
+
// start / middle / end は古い書き方(text-anchor そのもの)で、今までどおり
|
|
133
|
+
var an = {top: "above", bottom: "below"}[s.anchor] || s.anchor; // top / bottom は above / below の別名
|
|
134
|
+
var side = {right: "start", left: "end", above: "middle", below: "middle"}, anchor = side[an] || an || (end[0] > x1 - 160 ? "end" : "start");
|
|
135
|
+
var ly0 = an === "above" ? end[1] - Math.round(14 * K) : an === "below" ? end[1] + Math.round(32 * K) : end[1] - Math.round(12 * K);
|
|
136
|
+
if (an === "below" && ly0 > y1 - 4) ly0 = end[1] - Math.round(14 * K); // 下に入らなければ上へ
|
|
137
|
+
it.lx = end[0] + (anchor === "end" ? -8 : anchor === "start" ? 10 : 0) + (s.dx || 0);
|
|
138
|
+
it.ly = (s.ly !== undefined ? p.y(s.ly) : ly0) + (s.dy || 0);
|
|
139
|
+
// 字の幅の見積もり(26px。base の textWidth:テーマの字で測った幅。記法の * _ ^ を除く)
|
|
140
|
+
var w = D.textWidth(s.label || "", F, {font: self, mark: true});
|
|
141
|
+
it.x0 = anchor === "end" ? it.lx - w : anchor === "middle" ? it.lx - w / 2 : it.lx; it.x1 = it.x0 + w;
|
|
142
|
+
it.anchor = anchor; it.col = col; it.label = s.label || "";
|
|
143
|
+
return it;
|
|
144
|
+
});
|
|
145
|
+
// 名前どうしが重ならないように、横に重なる名前を下へずらす。先に描く高さ(上は 26、下は横軸の 6 px 上)に収めてから離し、
|
|
146
|
+
// 下に収まらなければ下から上へ押し戻す(目盛りの数字にかからない)。上付きのある名前は上端を、下付きのある名前は下端を
|
|
147
|
+
// その分だけ内に、上の名前の下付き・下の名前の上付きの分だけ間を広げる(記法がなければ今までと同じ)
|
|
148
|
+
var min = Math.round(32 * K), lo = F, hi = y1 - 6, ov = function(u, v){ return u.x0 < v.x1 && v.x0 < u.x1; };
|
|
149
|
+
var loOf = function(it){ return lo + supX(it.label, F); }, hiOf = function(it){ return hi - subX(it.label, F); };
|
|
150
|
+
var gap = function(u, v){ return min + subX(u.label, F) + supX(v.label, F); }; // u が上、v が下
|
|
151
|
+
var g = self.items.filter(function(it){ return it.label; });
|
|
152
|
+
g.forEach(function(it){ it.ly = Math.min(hiOf(it), Math.max(loOf(it), it.ly)); });
|
|
153
|
+
g.sort(function(u, v){ return u.ly - v.ly; });
|
|
154
|
+
g.forEach(function(it, j){
|
|
155
|
+
for (var q = 0; q < j; q++){
|
|
156
|
+
var o = g[q];
|
|
157
|
+
if (ov(it, o) && it.ly - o.ly < gap(o, it)) it.ly = o.ly + gap(o, it);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
for (var j = g.length - 1; j >= 0; j--){
|
|
161
|
+
var it = g[j];
|
|
162
|
+
it.ly = Math.min(hiOf(it), it.ly);
|
|
163
|
+
for (var q = j + 1; q < g.length; q++) if (ov(it, g[q]) && g[q].ly - it.ly < gap(it, g[q])) it.ly = g[q].ly - gap(it, g[q]);
|
|
164
|
+
}
|
|
165
|
+
g.forEach(function(it){ it.ly = Math.max(loOf(it), it.ly); });
|
|
166
|
+
this.items.forEach(function(it){
|
|
167
|
+
it.lab = D.mtext(p.svg, it.lx, it.ly, it.label, {"text-anchor": it.anchor, fill: it.col, "font-size": F, "font-weight": 700, opacity: 0});
|
|
168
|
+
});
|
|
169
|
+
// tone:テーマの色の名前か var(--…)。知らない名前は既定の色(series-1..4 の順)にして知らせる
|
|
170
|
+
function colorOf(c, i){
|
|
171
|
+
var def = "var(--series-" + (i % 4 + 1) + ")";
|
|
172
|
+
if (!c) return def;
|
|
173
|
+
if (c.indexOf("var(") === 0) return c;
|
|
174
|
+
var nm = c.replace(/^--/, "");
|
|
175
|
+
if (/^(term|emph|accent2|muted|fg|line|series-[1-4])$/.test(nm)) return "var(--" + nm + ")";
|
|
176
|
+
ctx.report("attr", "[curves] series " + i + ": tone " + JSON.stringify(c) + " is not term, emph, accent2, muted, fg or series-1..4 (" + def.slice(6, -1) + " is used)");
|
|
177
|
+
return def;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
duration(k){ return k >= 1 ? this.props.dur * 0.7 + 0.6 : 0; }
|
|
181
|
+
render(k, t, ctx){
|
|
182
|
+
var dur = this.props.dur, preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0;
|
|
183
|
+
// 先を薄く見せる表示:後の段階の線と名前を、引き終えた形のままテーマの --preview-opacity(なければ 0.45)で描く
|
|
184
|
+
this.items.forEach(function(it){
|
|
185
|
+
if (preview && it.step > k){
|
|
186
|
+
it.draw.setAttribute("stroke-dashoffset", (0).toFixed(4));
|
|
187
|
+
it.path.setAttribute("opacity", PV);
|
|
188
|
+
it.lab.setAttribute("opacity", PV.toFixed(3));
|
|
189
|
+
if (it.area) it.area.setAttribute("opacity", PV.toFixed(3));
|
|
190
|
+
(it.areaLabs || []).forEach(function(e){ e.setAttribute("opacity", PV.toFixed(3)); });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
var pd = it.step < k ? 1 : it.step === k ? base.prog(t, 0, dur) : 0;
|
|
194
|
+
var pl = it.step < k ? 1 : it.step === k ? base.prog(t, dur * 0.7, 0.6) : 0;
|
|
195
|
+
it.draw.setAttribute("stroke-dashoffset", (1 - pd).toFixed(4));
|
|
196
|
+
it.path.setAttribute("opacity", pd > 0 ? 1 : 0);
|
|
197
|
+
it.lab.setAttribute("opacity", pl.toFixed(3));
|
|
198
|
+
if (it.area) it.area.setAttribute("opacity", pl.toFixed(3));
|
|
199
|
+
(it.areaLabs || []).forEach(function(e){ e.setAttribute("opacity", pl.toFixed(3)); });
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Repeated z intervals
|
|
3
|
+
steps: Axis → intervals → coverage (3)
|
|
4
|
+
props:
|
|
5
|
+
dur: Seconds
|
|
6
|
+
fast: Fast seconds
|
|
7
|
+
size: Text px
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
JSON:
|
|
11
|
+
- `mu`, `sigma`, `n`: mean, SD, size.
|
|
12
|
+
- `reps` (40), `level` (.95), `seed`.
|
|
13
|
+
|
|
14
|
+
<!-- llm: omit -->
|
|
15
|
+
Known σ, z=1.645/1.96/2.576 for .90/.95/.99; Acklam inverse-normal otherwise. Mulberry32 + Box–Muller. Coverage is observed, not guaranteed. Confidence concerns repeated intervals containing fixed μ.
|
|
16
|
+
|
|
17
|
+
First three: dur each; rest: fast total. Final misses: thicker emph; hits: term. dur 1s, fast 2.5s; size 0=26px, ≥24. Bad props default/report; bad data or unrepresentable range: report, no draw; bad seed: 2.
|
|
18
|
+
|
|
19
|
+
1184×440px for 40 intervals. Rows ≥6px; nice ticks; report cramped layouts.
|
|
20
|
+
|
|
21
|
+
ctx.lang selects ja/en. Font boxes ≥1.43em plus gap. Image role, final summary; preserve author label, hide SVG. No answer preview. Fictional demo.
|
|
22
|
+
<!-- llm: end -->
|