egatari 0.6.19 → 0.6.20-rc.2
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/README.ja.md +7 -2
- package/README.md +7 -2
- package/components.lock.json +6 -3
- package/components2.lock.json +172 -1
- package/kit/check-messages.mjs +2 -2
- package/kit/check.mjs +5 -3
- package/kit/core/bookmark.mjs +13 -0
- package/kit/core/llm-pack-assemble.mjs +13 -8
- package/kit/core/llm-pack-data.mjs +48 -20
- package/kit/core/llm-pack.mjs +2 -1
- package/kit/core/script-unclosed.mjs +25 -8
- package/kit/instruction-version.json +1 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/presenter.js +15 -4
- package/kit/templates/new-deck.mjs +1 -1
- package/kit/tools.js +136 -4
- package/package.json +1 -1
- package/server/script-field.js +1 -1
- package/vendor/components/CATALOG.md +3 -3
- package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/README.en.md +38 -0
- package/vendor/components/sha256/8a9215c7fea15265c2f3038f3d01a2f72441fc1e931245dee46dcaacf3548a98/index.js +414 -0
- package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/README.en.md +40 -0
- package/vendor/components/sha256/91be5c714c046244436569ecac24d9d1eb84504b3e28d8899fc89a5865e8d955/index.js +355 -0
- package/vendor/components/sha256/9a426812105a44446e8b3f98e0ccfdb6701e8386c08e8aa201b69cb5b52a4c1f/index.js +278 -0
- package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/README.en.md +54 -0
- package/vendor/components/sha256/ad4d42a34eff125d8ccd7caf9ac329b7a8092960e7ee872fdeb853bd9c57942f/index.js +470 -0
- package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/README.en.md +23 -0
- package/vendor/components/sha256/b35d01e480a203dc27aa18b0d341cc1cbc2dcca69235e909919484f1545b371f/index.js +150 -0
- package/vendor/components-2/manifest-2.22.0.json +3240 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
// m-bars:棒を段階ごとに 0 から伸ばす(縦棒・横棒。系列が 2 つ以上なら組の棒)。値の数字は棒の端に直接書く
|
|
2
|
+
// <m-bars unit="億円" style="height:400px"><script type="application/json">
|
|
3
|
+
// {"series": [{"label": "売上"}],
|
|
4
|
+
// "groups": [{"label": "1 年目", "value": 1.2}, {"label": "3 年目", "values": [9.8], "tone": "emph"}]}
|
|
5
|
+
// (JSON の終わり)</m-bars>
|
|
6
|
+
// 段階:既定は組 1 つ = 1 段階(per-step で n 組ずつ、組の step で直接)。軸・目盛り・組の名前は段階 0 から見える
|
|
7
|
+
// scale:[{"step": 3, "max": 200}] で、その段階の始めに値の軸の上限を動かす(対数で補間。前の上限までの範囲は薄い帯で残す)。
|
|
8
|
+
// 上限を超える棒は軸の上端で止まり、上限が広がるにつれて伸びる(「軸を突き抜ける」見せ方)
|
|
9
|
+
// 値の数字は伸びきってから出す(途中の値を読ませない)。count="true" なら伸びに合わせて数え上げる
|
|
10
|
+
// stack="true":組の値を横に並べず 1 本に積み上げる(積み上げ棒)。下の系列から順に色が満ちていき、合計を棒の端に、
|
|
11
|
+
// それぞれの値を単位なしで区切りの中に(入るときだけ)書く。系列の名前は最後の組の棒の右(横棒なら最初の組の棒の上)に書く
|
|
12
|
+
// stack="percent":積み上げ棒の各組を 100 % にそろえ、区切りの中に % を書く(軸は 0〜100 %、端の合計は書かない)
|
|
13
|
+
// 負の値(積み上げでない棒):値の軸に 0 を含め、0 の基線から下(横棒は左)へ伸ばす。値の数字は棒の端の外側(下・左)に書く
|
|
14
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
15
|
+
// 要素が小さすぎるときは ctx.report で知らせる(1.x の console.warn("m-bars: …") の代わり)
|
|
16
|
+
egatariParts.define({name: "bars", version: "2.1.1", requires: {base: "1.3.0"}, element: "m-bars"}, function(deps){
|
|
17
|
+
"use strict";
|
|
18
|
+
var base = deps.base;
|
|
19
|
+
return class extends base.MotionElement {
|
|
20
|
+
static partName = "bars"; // the registry name (define meta name), for report prefixes
|
|
21
|
+
// データの形(kit/shape.js)
|
|
22
|
+
static shape = {
|
|
23
|
+
schema: {type: "object", additionalProperties: false, required: ["groups"], properties: {
|
|
24
|
+
groups: {type: "array", minItems: 1, items: {type: "object", anyOf: [{required: ["value"]}, {required: ["values"]}], properties: {
|
|
25
|
+
label: {type: "string"}, value: {type: "number"}, values: {type: "array", items: {type: "number"}}, err: {type: ["number", "array"]}, step: {type: "integer"}, at: {type: "number"}, tone: {type: "string"}}}},
|
|
26
|
+
sig: {type: "array", items: {type: "object", required: ["from", "to"], properties: {from: {type: "integer"}, to: {type: "integer"}, group: {type: "integer"}, label: {type: "string"}, step: {type: "integer"}}}},
|
|
27
|
+
series: {type: "array", items: {type: "object", properties: {label: {type: "string"}, tone: {type: "string"}}}},
|
|
28
|
+
scale: {type: "array", items: {type: "object", required: ["step"], properties: {step: {type: "integer"}, max: {type: "number"}, at: {type: "number"}}}},
|
|
29
|
+
max: {type: "number"}}},
|
|
30
|
+
example: {series: [{label: "売上"}], groups: [{label: "1 年目", value: 1.2}, {label: "2 年目", value: 3.4}]},
|
|
31
|
+
};
|
|
32
|
+
static props = {
|
|
33
|
+
orient: {type: "string", default: "v", doc: "v(縦棒)か h(横棒。順位や比較に)"},
|
|
34
|
+
max: {type: "number", default: 0, doc: "値の軸の上限(0 = 自動。scale があれば最初の上限)"},
|
|
35
|
+
unit: {type: "string", default: "", doc: "値の単位(数字の後ろに付ける。億円、%、社 など)"},
|
|
36
|
+
digits: {type: "number", default: 0, doc: "値の小数桁"},
|
|
37
|
+
"per-step": {type: "number", default: 1, doc: "1 ステップに出す組の数(0 = 全部をステップ 1 で)"},
|
|
38
|
+
dur: {type: "number", default: 0.8, doc: "1 本が伸びる秒数"},
|
|
39
|
+
stagger: {type: "number", default: 0.15, doc: "同じステップの組の出だしのずれ(秒)"},
|
|
40
|
+
count: {type: "bool", default: false, doc: "値の数字を伸びに合わせて数え上げる"},
|
|
41
|
+
ticks: {type: "bool", default: true, doc: "値の軸の目盛りと格子"},
|
|
42
|
+
zoom: {type: "number", default: 1.6, doc: "scale で上限を動かす秒数"},
|
|
43
|
+
al: {type: "string", default: "", doc: "値の軸の名前"},
|
|
44
|
+
stack: {type: "bool", default: false, doc: "組の値を 1 本に積み上げる(積み上げ棒)。\"percent\" なら各組を 100 % にそろえる"},
|
|
45
|
+
mark: {type: "string", default: "bar", doc: "bar(棒)か dot(点。平均と誤差棒を、0 からの棒にせずに見せる)"},
|
|
46
|
+
};
|
|
47
|
+
get steps(){
|
|
48
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
49
|
+
var m = 0;
|
|
50
|
+
this.plan().groups.forEach(function(g){ m = Math.max(m, g.step); });
|
|
51
|
+
(this.plan().scale).forEach(function(s){ m = Math.max(m, s.step); });
|
|
52
|
+
(this.plan().sig).forEach(function(s){ m = Math.max(m, s.step); });
|
|
53
|
+
return m;
|
|
54
|
+
}
|
|
55
|
+
// 組の段階と開始時刻、上限の動き(mount の前にも steps が要るので、データだけから決める)
|
|
56
|
+
plan(){
|
|
57
|
+
if (this._plan) return this._plan;
|
|
58
|
+
var d = this.data || {}, P = this.props, per = P["per-step"], seen = {};
|
|
59
|
+
var groups = (d.groups || []).map(function(g, i){
|
|
60
|
+
var vals = Array.isArray(g.values) ? g.values : [g.value];
|
|
61
|
+
var step = g.step !== undefined ? g.step : per > 0 ? Math.floor(i / per) + 1 : 1;
|
|
62
|
+
var j = seen[step] = (seen[step] || 0) + 1;
|
|
63
|
+
var o = {g: g, vals: vals.map(Number), step: step, at: g.at !== undefined ? g.at : +((j - 1) * P.stagger).toFixed(3)};
|
|
64
|
+
// 誤差棒:err は数(± その値)か [下, 上](区間の端そのもの)。values の組では系列ごとの並び(数 1 つなら全部の系列に)
|
|
65
|
+
if (g.err !== undefined && g.err !== null){
|
|
66
|
+
var ePer = Array.isArray(g.values) ? (Array.isArray(g.err) ? g.err : o.vals.map(function(){ return g.err; })) : [g.err];
|
|
67
|
+
o.errs = o.vals.map(function(v, k){
|
|
68
|
+
var x = ePer[k];
|
|
69
|
+
if (x === undefined || x === null) return null;
|
|
70
|
+
if (Array.isArray(x)) return x.length === 2 && isFinite(+x[0]) && isFinite(+x[1]) ? [Math.min(+x[0], +x[1]), Math.max(+x[0], +x[1])] : null;
|
|
71
|
+
return isFinite(+x) ? [v - Math.abs(+x), v + Math.abs(+x)] : null;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return o;
|
|
75
|
+
});
|
|
76
|
+
var scale = (d.scale || []).map(function(s){ return {step: s.step, max: +s.max, at: s.at || 0}; })
|
|
77
|
+
.sort(function(a, b){ return a.step - b.step; });
|
|
78
|
+
// 有意差の括弧の段階と出る時刻:既定は、つなぐ組のうち後に出る組の段階で、その棒の値が出てから
|
|
79
|
+
var sig = (Array.isArray(d.sig) && !P.stack ? d.sig : []).map(function(sg){
|
|
80
|
+
var gi = sg.group !== undefined ? [sg.group] : [sg.from, sg.to], gs = gi.map(function(i){ return groups[i]; }).filter(Boolean);
|
|
81
|
+
var step = sg.step !== undefined ? sg.step : Math.max.apply(null, gs.map(function(g){ return g.step; }).concat([1]));
|
|
82
|
+
var at = Math.max.apply(null, gs.filter(function(g){ return g.step === step; }).map(function(g){ return g.at + 0.1 * (g.vals.length - 1); }).concat([0])) + P.dur + 0.35;
|
|
83
|
+
return {sg: sg, step: step, at: +at.toFixed(3)};
|
|
84
|
+
});
|
|
85
|
+
return (this._plan = {groups: groups, scale: scale, sig: sig});
|
|
86
|
+
}
|
|
87
|
+
mount(ctx){
|
|
88
|
+
var P = this.props, D = base, self = this, d = this.data || {}, pl = this.plan();
|
|
89
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
90
|
+
var W = this.clientWidth, H = this.clientHeight, hor = P.orient === "h";
|
|
91
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
92
|
+
var series = d.series && d.series.length ? d.series : [{}];
|
|
93
|
+
var ns = Math.max(series.length, Math.max.apply(null, pl.groups.map(function(g){ return g.vals.length; }).concat([1])));
|
|
94
|
+
// 積み上げ棒では、軸と端の数字は組の合計で決める
|
|
95
|
+
var st = P.stack, sum = function(g){ return g.vals.reduce(function(a, v){ return a + Math.max(0, v); }, 0); };
|
|
96
|
+
// stack="percent":各組を 100 % にそろえる
|
|
97
|
+
var pct = this.pct = st && this.getAttribute("stack") === "percent";
|
|
98
|
+
var tops = function(g){ return pct ? [100] : st ? [sum(g)] : g.errs ? g.vals.concat([].concat.apply([], g.errs.filter(Boolean))) : g.vals; };
|
|
99
|
+
var dot = P.mark === "dot" && !st, sigs = !st && !hor && Array.isArray(d.sig) ? d.sig : [];
|
|
100
|
+
if (st && (P.mark === "dot" || pl.groups.some(function(g){ return g.errs; }))) ctx.report("data", "[bars] err and mark=\"dot\" are for unstacked bars; they are not drawn on stacked bars");
|
|
101
|
+
if ((st || hor) && Array.isArray(d.sig) && d.sig.length) ctx.report("data", "[bars] sig brackets are drawn on vertical, unstacked bars only");
|
|
102
|
+
var all = [].concat.apply([], pl.groups.map(tops));
|
|
103
|
+
// 軸の上限:scale の最初の段階より前に出る棒が収まるように
|
|
104
|
+
var first = pl.scale.length ? pl.scale[0].step : Infinity;
|
|
105
|
+
var early = [].concat.apply([], pl.groups.filter(function(g){ return g.step < first; }).map(tops));
|
|
106
|
+
// 負の値があれば(積み上げでない棒)、軸は 0 を含み、0 より下の範囲 N をとる(N は下で枠の大きさから決める)
|
|
107
|
+
var mn = st ? 0 : Math.min.apply(null, all.concat([0]));
|
|
108
|
+
this.neg = mn < 0; this.N = 0;
|
|
109
|
+
if (this.neg){
|
|
110
|
+
var pmax = Math.max.apply(null, (early.length ? early : all).concat([0]));
|
|
111
|
+
this.M0 = P.max || d.max || (pmax > 0 ? nice(pmax * 1.12) : 0);
|
|
112
|
+
this.levels = [this.M0].concat(pl.scale.map(function(s){ return s.max || nice(Math.max(Math.max.apply(null, all), 1e-9) * 1.12); }));
|
|
113
|
+
} else {
|
|
114
|
+
this.M0 = pct ? 100 : P.max || d.max || nice(Math.max.apply(null, (early.length ? early : all).concat([1e-9])) * 1.12);
|
|
115
|
+
this.levels = [this.M0].concat(pl.scale.map(function(s){ return s.max || nice(Math.max.apply(null, all) * 1.12); }));
|
|
116
|
+
}
|
|
117
|
+
pl.scale.forEach(function(s, i){ s.max = self.levels[i + 1]; });
|
|
118
|
+
// 余白:横棒は組の名前の幅、縦棒は値の軸の目盛り(字の幅は base の textWidth:テーマの字で測った幅。mk は mtext で書く字)
|
|
119
|
+
var est = function(s, size, mk){ return D.textWidth(s, size, {font: self, mark: !!mk}); };
|
|
120
|
+
var longest = Math.max.apply(null, pl.groups.map(function(g){ return Math.max.apply(null, String(g.g.label || "").split("\n").map(function(s){ return est(s, 26, true); })); }).concat([0]));
|
|
121
|
+
var valW = Math.max.apply(null, all.map(function(v){ return est(self.fmt(v), 26); }).concat([0]));
|
|
122
|
+
var lines = Math.max.apply(null, pl.groups.map(function(g){ return String(g.g.label || "").split("\n").length; }).concat([1]));
|
|
123
|
+
var m = this.m = hor ? {l: Math.min(W * 0.42, longest + 24), r: valW + 24, t: P.al ? 40 : 8, b: P.ticks ? 44 : 8}
|
|
124
|
+
: {l: P.ticks ? 24 + est(this.fmtTick(this.levels[this.levels.length - 1], 1), 24) + (P.al ? 36 : 0) : 16, r: 16, t: ns > 1 ? 80 : 44, b: 18 + 30 * lines};
|
|
125
|
+
// 積み上げ棒:系列の名前を縦棒は右に、横棒は最初の棒の上に書くので、その分をあける
|
|
126
|
+
var serW = Math.max.apply(null, series.map(function(sr){ return est(sr.label || "", 24, true); }).concat([0]));
|
|
127
|
+
if (st && hor && ns > 1) m.t = Math.max(m.t, P.al ? 40 : 36);
|
|
128
|
+
if (st && !hor){ m.t = 44; if (ns > 1 && serW) m.r = serW + 30; }
|
|
129
|
+
if (sigs.length){ m.t += 44 * sigs.length; this.y0 = m.t; }
|
|
130
|
+
this.x0 = m.l; this.x1 = W - m.r; this.y0 = m.t; this.y1 = H - m.b;
|
|
131
|
+
// 要素が小さすぎる(高さを書き忘れて 0 px など):大きさが負にならないように、枠を 0 にして知らせる
|
|
132
|
+
if (this.x1 < this.x0 || this.y1 < this.y0){
|
|
133
|
+
ctx.report("size", "[bars] the element (" + W + "×" + H + " px) is too small for the bars; give it a size, e.g. style=\"height:380px\"");
|
|
134
|
+
this.x1 = Math.max(this.x0, this.x1); this.y1 = Math.max(this.y0, this.y1);
|
|
135
|
+
}
|
|
136
|
+
this.len = hor ? this.x1 - this.x0 : this.y1 - this.y0;
|
|
137
|
+
if (this.neg){
|
|
138
|
+
// 0 より下の範囲:いちばん下の棒の端の外に値の数字が入るだけあける(縦棒 40 px、横棒は数字の幅 + 24 px)
|
|
139
|
+
var room = hor ? valW + 24 : 40, fr = Math.min(0.6, room / Math.max(1, this.len));
|
|
140
|
+
this.N = nice((-mn + fr * this.M0) / (1 - fr));
|
|
141
|
+
// 縦棒:負の目盛りの字の幅だけ左をあける
|
|
142
|
+
if (!hor && P.ticks){
|
|
143
|
+
var nl = 24 + est(this.fmtTick(-this.N, decs(tickStep(this.M0 + this.N))), 24) + (P.al ? 36 : 0);
|
|
144
|
+
if (nl > m.l){ m.l = nl; this.x0 = m.l; if (this.x1 < this.x0) this.x1 = this.x0; }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// 前の上限までの範囲(上限を動かす間だけ)
|
|
148
|
+
this.band = D.el("rect", {fill: "var(--term-tint)", opacity: 0}, svg);
|
|
149
|
+
// 目盛り:上限ごとに 1 組。上限が動く間は前の組を薄くし、次の組を濃くする
|
|
150
|
+
var gT = D.el("g", {}, svg);
|
|
151
|
+
this.tickSets = !P.ticks ? [] : this.levels.map(function(M){
|
|
152
|
+
var st = tickStep(self.neg ? M + self.N : M), dec = decs(st);
|
|
153
|
+
var out = [];
|
|
154
|
+
for (var i = 1; i * st <= M * 1.0001; i++){
|
|
155
|
+
var v = +(i * st).toFixed(8);
|
|
156
|
+
out.push({v: v, grid: D.el("line", {stroke: "var(--line)", "stroke-width": 1.2}, gT),
|
|
157
|
+
text: D.el("text", {"font-size": 24, "text-anchor": hor ? "middle" : "end", style: "font-variant-numeric:tabular-nums"}, gT), label: self.fmtTick(v, dec)});
|
|
158
|
+
}
|
|
159
|
+
// 負の側の目盛り(負の値があるときだけ)
|
|
160
|
+
if (self.neg) for (var i2 = 1; i2 * st <= self.N * 1.0001; i2++){
|
|
161
|
+
var v2 = -(+(i2 * st).toFixed(8));
|
|
162
|
+
out.push({v: v2, grid: D.el("line", {stroke: "var(--line)", "stroke-width": 1.2}, gT),
|
|
163
|
+
text: D.el("text", {"font-size": 24, "text-anchor": hor ? "middle" : "end", style: "font-variant-numeric:tabular-nums"}, gT), label: self.fmtTick(v2, dec)});
|
|
164
|
+
}
|
|
165
|
+
out.forEach(function(o){ o.text.textContent = o.label; });
|
|
166
|
+
return out;
|
|
167
|
+
});
|
|
168
|
+
// 0 の目盛りと基線(いつも出す)
|
|
169
|
+
if (P.ticks){
|
|
170
|
+
var z = D.el("text", {"font-size": 24, "text-anchor": hor ? "middle" : "end"}, gT);
|
|
171
|
+
z.textContent = pct ? "0%" : "0";
|
|
172
|
+
this.zeroT = z;
|
|
173
|
+
if (hor){ z.setAttribute("x", this.x0); z.setAttribute("y", this.y1 + 32); } else { z.setAttribute("x", this.x0 - 10); z.setAttribute("y", this.y1 + 8); }
|
|
174
|
+
}
|
|
175
|
+
if (P.al){
|
|
176
|
+
if (hor) D.mtext(svg, this.x1, this.y0 - 14, P.al, {"text-anchor": "end", fill: "var(--muted)"});
|
|
177
|
+
else D.mtext(svg, 20, (this.y0 + this.y1) / 2, P.al, {"text-anchor": "middle", fill: "var(--muted)", transform: "rotate(-90 20 " + (this.y0 + this.y1) / 2 + ")"});
|
|
178
|
+
}
|
|
179
|
+
var gB = D.el("g", {}, svg), gE = pl.groups.some(function(g){ return g.errs; }) || dot ? D.el("g", {}, svg) : null, gL = D.el("g", {}, svg);
|
|
180
|
+
if (hor) this.baseL = D.el("line", {x1: this.x0, y1: this.y0, x2: this.x0, y2: this.y1, stroke: "var(--fg)", "stroke-width": 1.5}, svg);
|
|
181
|
+
else this.baseL = D.el("line", {x1: this.x0, y1: this.y1, x2: this.x1, y2: this.y1, stroke: "var(--fg)", "stroke-width": 1.5}, svg);
|
|
182
|
+
// 組と棒の位置(組の幅は枠の 64%、棒は組の幅を系列で分ける)
|
|
183
|
+
var n = pl.groups.length || 1, cross = hor ? this.y1 - this.y0 : this.x1 - this.x0, slot = cross / n;
|
|
184
|
+
var bw = Math.min(hor ? 56 : 96, slot * 0.64 / (st ? 1 : ns));
|
|
185
|
+
this.bars = [];
|
|
186
|
+
this.stacks = null;
|
|
187
|
+
if (st) this.stacks = pl.groups.map(function(o, i){
|
|
188
|
+
var c = (hor ? self.y0 : self.x0) + slot * (i + 0.5), cum = 0, raw = sum(o);
|
|
189
|
+
String(o.g.label || "").split("\n").forEach(function(s, j, a){
|
|
190
|
+
if (hor) D.mtext(gL, self.x0 - 12, c + 8 + (j - (a.length - 1) / 2) * 30, s, {"text-anchor": "end", "font-size": 26});
|
|
191
|
+
else D.mtext(gL, c, self.y1 + 34 + j * 30, s, {"text-anchor": "middle", "font-size": 26});
|
|
192
|
+
});
|
|
193
|
+
var segs = o.vals.map(function(v, j){
|
|
194
|
+
v = Math.max(0, v);
|
|
195
|
+
if (pct) v = raw > 0 ? v / raw * 100 : 0;
|
|
196
|
+
var col = tone(series[j] && series[j].tone || (ns > 1 ? "series-" + (j % 4 + 1) : "term"));
|
|
197
|
+
var sg = {v: v, j: j, from: cum, col: col, rect: D.el("rect", {rx: 3, fill: col, opacity: 0}, gB),
|
|
198
|
+
val: D.el("text", {"font-size": 24, "font-weight": 700, "text-anchor": "middle", fill: "var(--bg)", opacity: 0, style: "font-variant-numeric:tabular-nums"}, gL)};
|
|
199
|
+
// 区切りの中の値は単位を付けない(単位は端の合計に付く)
|
|
200
|
+
sg.val.textContent = self.fmt(v, undefined, pct ? "%" : "");
|
|
201
|
+
// 太字 24 px の数字の幅(base の textWidth。字の読み込みを待たない)
|
|
202
|
+
sg.vw = est(sg.val.textContent, 24);
|
|
203
|
+
cum += v;
|
|
204
|
+
return sg;
|
|
205
|
+
});
|
|
206
|
+
var tot = D.el("text", {"font-size": 26, "font-weight": 700, "text-anchor": hor ? "start" : "middle", fill: o.g.tone ? tone(o.g.tone) : "var(--fg)", opacity: 0, style: "font-variant-numeric:tabular-nums"}, gL);
|
|
207
|
+
return {o: o, c: c, segs: segs, total: cum, tot: tot};
|
|
208
|
+
});
|
|
209
|
+
// 系列の名前:縦棒は最後の組の棒の右、横棒は最初の組の棒の上に、区切りの真ん中にそろえて書く(重なれば離す)
|
|
210
|
+
this.serLabs = [];
|
|
211
|
+
if (st && ns > 1){
|
|
212
|
+
var ref = hor ? this.stacks[0] : this.stacks[this.stacks.length - 1];
|
|
213
|
+
ref.segs.forEach(function(sg){
|
|
214
|
+
if (!series[sg.j] || !series[sg.j].label) return;
|
|
215
|
+
self.serLabs.push({sg: sg, ref: ref, el: D.mtext(gL, 0, 0, series[sg.j].label, {"text-anchor": hor ? "middle" : "start", "font-size": 24, "font-weight": 700, fill: sg.col, opacity: 0}), w: est(series[sg.j].label, 24, true)});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (!st) this.groups = pl.groups.map(function(o, i){
|
|
219
|
+
var c = (hor ? self.y0 : self.x0) + slot * (i + 0.5);
|
|
220
|
+
var lab = String(o.g.label || "").split("\n").map(function(s, j, a){
|
|
221
|
+
return hor ? D.mtext(gL, self.x0 - 12, c + 8 + (j - (a.length - 1) / 2) * 30, s, {"text-anchor": "end", "font-size": 26})
|
|
222
|
+
: D.mtext(gL, c, self.y1 + 34 + j * 30, s, {"text-anchor": "middle", "font-size": 26});
|
|
223
|
+
});
|
|
224
|
+
o.vals.forEach(function(v, j){
|
|
225
|
+
var col = tone(o.g.tone || series[j] && series[j].tone || (ns > 1 ? "series-" + (j % 4 + 1) : "term"));
|
|
226
|
+
var off = (j - (ns - 1) / 2) * (bw + 4);
|
|
227
|
+
var b = {o: o, v: v, j: j, c: c + off, col: col,
|
|
228
|
+
rect: D.el("rect", {rx: 3, fill: col}, gB),
|
|
229
|
+
val: D.el("text", {"font-size": 26, "font-weight": 700, "text-anchor": hor ? (v < 0 ? "end" : "start") : "middle", fill: o.g.tone ? col : "var(--fg)", style: "font-variant-numeric:tabular-nums"}, gL)};
|
|
230
|
+
// 誤差棒(--fg の線と両端の短い横線)と点(mark="dot":棒の代わりに値の位置の円)
|
|
231
|
+
var er = o.errs && o.errs[j];
|
|
232
|
+
if (er) b.err = {lo: er[0], hi: er[1], path: D.el("path", {d: "", fill: "none", stroke: "var(--fg)", "stroke-width": 2.5, "stroke-linecap": "round"}, gE)};
|
|
233
|
+
if (dot){ b.dot = D.el("circle", {r: 11, fill: col, stroke: "var(--bg)", "stroke-width": 2}, gE); b.rect.setAttribute("display", "none"); }
|
|
234
|
+
// 系列の名前は最初の組の棒の上(横棒なら右)に直接書く(凡例は作らない)
|
|
235
|
+
if (i === 0 && ns > 1 && series[j] && series[j].label) b.ser = D.mtext(gL, 0, 0, series[j].label, {"text-anchor": hor ? (v < 0 ? "end" : "start") : "middle", "font-size": 24, "font-weight": 700, fill: col});
|
|
236
|
+
self.bars.push(b);
|
|
237
|
+
});
|
|
238
|
+
return {o: o, lab: lab};
|
|
239
|
+
});
|
|
240
|
+
this.bw = bw;
|
|
241
|
+
this.hor = hor;
|
|
242
|
+
// 有意差の括弧:組 from と to(group を書けば、その組の中の系列 from と to)の棒の上に、括弧と印(既定は *)
|
|
243
|
+
var G = pl.groups;
|
|
244
|
+
this.sigs = sigs.map(function(sg, si){
|
|
245
|
+
var pick = function(gi, j){ return self.bars.filter(function(b){ return b.o === G[gi] && (j === undefined || b.j === j); }); };
|
|
246
|
+
var A = sg.group !== undefined ? pick(sg.group, sg.from) : pick(sg.from), B = sg.group !== undefined ? pick(sg.group, sg.to) : pick(sg.to);
|
|
247
|
+
if (!A.length || !B.length){ ctx.report("data", "[bars] sig " + JSON.stringify(sg) + " names a group or series that is not there"); return null; }
|
|
248
|
+
var lo = sg.group !== undefined ? G[sg.group] : G[Math.min(sg.from, sg.to)], hi2 = sg.group !== undefined ? G[sg.group] : G[Math.max(sg.from, sg.to)];
|
|
249
|
+
var inBetween = self.bars.filter(function(b){ var i = G.indexOf(b.o); return i >= G.indexOf(lo) && i <= G.indexOf(hi2); });
|
|
250
|
+
return {a: A, b: B, span: inBetween, step: pl.sig[si].step, at: pl.sig[si].at,
|
|
251
|
+
path: D.el("path", {d: "", fill: "none", stroke: "var(--fg)", "stroke-width": 2.5}, gL),
|
|
252
|
+
text: (function(){ var t = D.el("text", {"font-size": 28, "font-weight": 700, "text-anchor": "middle"}, gL); t.textContent = sg.label !== undefined ? sg.label : "*"; return t; })()};
|
|
253
|
+
}).filter(Boolean);
|
|
254
|
+
// 読み上げ:最後の形(すべての組の値)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
255
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
256
|
+
this.setAttribute("role", "img");
|
|
257
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja"), series));
|
|
258
|
+
function nice(v){ var e = Math.pow(10, Math.floor(Math.log10(v))), x = v / e;
|
|
259
|
+
return [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10].filter(function(s){ return s >= x - 1e-9; })[0] * e; }
|
|
260
|
+
function tickStep(M){ var r = M / 4.5, e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e;
|
|
261
|
+
return (x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e; }
|
|
262
|
+
function decs(s){ var k = 0; while (Math.abs(s * Math.pow(10, k) - Math.round(s * Math.pow(10, k))) > 1e-6 && k < 6) k++; return k; }
|
|
263
|
+
function tone(t){ return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(t) ? "var(--" + t + ")" : "var(--term)"; }
|
|
264
|
+
}
|
|
265
|
+
// 最後の形を 1 文で(読み上げの名前):「売上(億円):1 年目 1.2億円、3 年目 9.8億円」。系列が 2 つ以上なら組ごとに「系列 値」を並べ、
|
|
266
|
+
// 積み上げ棒は合計も、100 % の積み上げ棒は % を書く。組が 12 より多ければ初めの 12 組と組の数
|
|
267
|
+
summary(ja, series){
|
|
268
|
+
var self = this, P = this.props, pl = this.plan(), pct = this.pct, st = P.stack;
|
|
269
|
+
var names = series.map(function(sr){ return sr.label || ""; }).filter(Boolean);
|
|
270
|
+
var head = P.al || names.join(ja ? "・" : ", ") || (ja ? "棒グラフ" : "Bar chart");
|
|
271
|
+
if (P.unit && !pct) head += ja ? "(" + P.unit + ")" : " (" + P.unit + ")";
|
|
272
|
+
var one = function(o){
|
|
273
|
+
var raw = o.vals.reduce(function(a, v){ return a + Math.max(0, v); }, 0);
|
|
274
|
+
var vs = o.vals.map(function(v, j){
|
|
275
|
+
var x = pct ? self.fmt(raw > 0 ? Math.max(0, v) / raw * 100 : 0, undefined, "%") : self.fmt(st ? Math.max(0, v) : v);
|
|
276
|
+
var er = !st && o.errs && o.errs[j];
|
|
277
|
+
if (er) x += ja ? "(" + self.fmt(er[0]) + "〜" + self.fmt(er[1]) + ")" : " (" + self.fmt(er[0]) + " to " + self.fmt(er[1]) + ")";
|
|
278
|
+
return (o.vals.length > 1 && series[j] && series[j].label ? series[j].label + " " : "") + x;
|
|
279
|
+
});
|
|
280
|
+
var lab = String(o.g.label || "").replace(/\s*\n\s*/g, " ");
|
|
281
|
+
return (lab ? lab + " " : "") + vs.join(ja ? "・" : ", ") + (st && !pct && o.vals.length > 1 ? (ja ? "(計 " : " (total ") + self.fmt(raw) + (ja ? ")" : ")") : "");
|
|
282
|
+
};
|
|
283
|
+
var gs = pl.groups.slice(0, 12).map(one);
|
|
284
|
+
if (pl.groups.length > 12) gs.push(ja ? "…(全 " + pl.groups.length + " 組)" : "… (" + pl.groups.length + " groups)");
|
|
285
|
+
// 有意差の括弧:「1 組と 2 組の差 *」
|
|
286
|
+
var name = function(gi, j){ var g = pl.groups[gi]; if (!g) return "?"; var l = String(g.g.label || "").replace(/\s*\n\s*/g, " "); return j !== undefined && series[j] && series[j].label ? (l ? l + " " : "") + series[j].label : l; };
|
|
287
|
+
var sg = st || P.orient === "h" ? [] : pl.sig.map(function(x){
|
|
288
|
+
var a = x.sg.group !== undefined ? name(x.sg.group, x.sg.from) : name(x.sg.from), b = x.sg.group !== undefined ? name(x.sg.group, x.sg.to) : name(x.sg.to);
|
|
289
|
+
return ja ? a + "と" + b + "の差 " + (x.sg.label !== undefined ? x.sg.label : "*") : "difference between " + a + " and " + b + " " + (x.sg.label !== undefined ? x.sg.label : "*");
|
|
290
|
+
});
|
|
291
|
+
return head + (ja ? ":" : ": ") + gs.join(ja ? "、" : "; ") + (sg.length ? (ja ? "。" : ". ") + sg.join(ja ? "、" : "; ") : "");
|
|
292
|
+
}
|
|
293
|
+
// 数の書き方:3 桁ごとのカンマ、小数桁、単位
|
|
294
|
+
fmt(v, digits, unit){
|
|
295
|
+
var dg = digits !== undefined ? digits : this.props.digits;
|
|
296
|
+
var s = Math.abs(v).toFixed(dg).split("."), i = s[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
297
|
+
return (v < 0 ? "−" : "") + i + (s[1] ? "." + s[1] : "") + (unit !== undefined ? unit : this.props.unit);
|
|
298
|
+
}
|
|
299
|
+
fmtTick(v, dec){ return this.fmt(v, dec, this.pct ? "%" : ""); }
|
|
300
|
+
// 段階 k、時刻 t の上限
|
|
301
|
+
maxAt(k, t){
|
|
302
|
+
var P = this.props, m = this.M0, from = 0, e = 1, lv = 0;
|
|
303
|
+
for (var i = 0; i < this.plan().scale.length; i++){
|
|
304
|
+
var s = this.plan().scale[i];
|
|
305
|
+
if (s.step < k){ m = s.max; lv = i + 1; continue; }
|
|
306
|
+
if (s.step === k){ e = base.prog(t, s.at, P.zoom); from = m; m = Math.exp(base.lerp(Math.log(m), Math.log(s.max), e)); return {m: m, lv: i + 1, e: e, from: from}; }
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
return {m: m, lv: lv, e: 1, from: null};
|
|
310
|
+
}
|
|
311
|
+
duration(k){
|
|
312
|
+
var P = this.props, d = 0;
|
|
313
|
+
// 積み上げ棒の区切りの値と系列の名前は count でも伸びきってから 0.35 秒で出るので、その分も段階に含める
|
|
314
|
+
this.plan().groups.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + (P.stack ? 0 : 0.1 * (o.vals.length - 1)) + P.dur + (P.count && !P.stack ? 0 : 0.35)); });
|
|
315
|
+
this.plan().scale.forEach(function(s){ if (s.step === k) d = Math.max(d, s.at + P.zoom + 0.3); });
|
|
316
|
+
if (!this.props.stack && this.props.orient !== "h") this.plan().sig.forEach(function(s){ if (s.step === k) d = Math.max(d, s.at + 0.35); });
|
|
317
|
+
return d;
|
|
318
|
+
}
|
|
319
|
+
render(k, t, ctx){
|
|
320
|
+
var P = this.props, D = base, self = this, hor = this.hor;
|
|
321
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の棒と数字を、伸びきった形でテーマの --preview-opacity の濃さに。
|
|
322
|
+
// 軸の上限は今の段階のまま。今の上限に収まらない棒(後で上限が動いてから入る棒)は先に見せない(上限で切ると値を読み違える)
|
|
323
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
324
|
+
var sc = this.maxAt(k, t), M = sc.m;
|
|
325
|
+
var ahead = function(o, v){ return preview && o.step > k && !(v > M * 1.04); };
|
|
326
|
+
var pos = function(v){ var r = Math.min(v, M * 1.04) / M * self.len; return hor ? self.x0 + r : self.y1 - r; };
|
|
327
|
+
// 負の値があるとき:値の軸は -N から M。棒は 0 の基線から伸びる
|
|
328
|
+
var N = this.N;
|
|
329
|
+
if (this.neg){
|
|
330
|
+
pos = function(v){ var r = (Math.max(-N * 1.04, Math.min(v, M * 1.04)) + N) / (M + N) * self.len; return hor ? self.x0 + r : self.y1 - r; };
|
|
331
|
+
var z0 = pos(0);
|
|
332
|
+
if (hor){ this.baseL.setAttribute("x1", z0.toFixed(1)); this.baseL.setAttribute("x2", z0.toFixed(1)); if (this.zeroT) this.zeroT.setAttribute("x", z0.toFixed(1)); }
|
|
333
|
+
else { this.baseL.setAttribute("y1", z0.toFixed(1)); this.baseL.setAttribute("y2", z0.toFixed(1)); if (this.zeroT) this.zeroT.setAttribute("y", (z0 + 8).toFixed(1)); }
|
|
334
|
+
}
|
|
335
|
+
// 目盛り:今の上限の組を濃く、動いている間は前の組を薄く
|
|
336
|
+
// 前の組と次の組に同じ値の目盛りがあれば、重ねずに次の組のものだけを濃く出す
|
|
337
|
+
var moving = sc.from !== null, has = function(li, v){ return (self.tickSets[li] || []).some(function(o){ return Math.abs(o.v - v) < 1e-9; }); };
|
|
338
|
+
this.tickSets.forEach(function(set, li){
|
|
339
|
+
var op = li === sc.lv ? sc.e : li === sc.lv - 1 && moving ? 1 - sc.e : 0;
|
|
340
|
+
set.forEach(function(o){
|
|
341
|
+
var b = op;
|
|
342
|
+
if (moving && li === sc.lv - 1 && has(sc.lv, o.v)) b = 0;
|
|
343
|
+
if (moving && li === sc.lv && has(sc.lv - 1, o.v)) b = 1;
|
|
344
|
+
var p = pos(o.v), a = o.v > M * 1.001 || (self.neg && o.v < -N * 1.001) ? 0 : b;
|
|
345
|
+
if (hor){ o.grid.setAttribute("x1", p.toFixed(1)); o.grid.setAttribute("x2", p.toFixed(1)); o.grid.setAttribute("y1", self.y0); o.grid.setAttribute("y2", self.y1);
|
|
346
|
+
o.text.setAttribute("x", p.toFixed(1)); o.text.setAttribute("y", self.y1 + 32); }
|
|
347
|
+
else { o.grid.setAttribute("y1", p.toFixed(1)); o.grid.setAttribute("y2", p.toFixed(1)); o.grid.setAttribute("x1", self.x0); o.grid.setAttribute("x2", self.x1);
|
|
348
|
+
o.text.setAttribute("x", self.x0 - 10); o.text.setAttribute("y", (p + 8).toFixed(1)); }
|
|
349
|
+
o.grid.setAttribute("opacity", (0.8 * a).toFixed(3)); o.text.setAttribute("opacity", a.toFixed(3));
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
// 前の上限までの帯(上限が動く間だけ)
|
|
353
|
+
var bo = sc.from === null ? 0 : 0.6 * Math.min(1, sc.e * 4) * (1 - D.prog(t, P.zoom * 0.8, P.zoom * 0.4));
|
|
354
|
+
var pb = pos(Math.min(sc.from || 0, M));
|
|
355
|
+
if (hor){ this.band.setAttribute("x", this.x0); this.band.setAttribute("width", Math.max(0, pb - this.x0).toFixed(1)); this.band.setAttribute("y", this.y0); this.band.setAttribute("height", this.y1 - this.y0); }
|
|
356
|
+
else { this.band.setAttribute("x", this.x0); this.band.setAttribute("width", this.x1 - this.x0); this.band.setAttribute("y", pb.toFixed(1)); this.band.setAttribute("height", Math.max(0, this.y1 - pb).toFixed(1)); }
|
|
357
|
+
this.band.setAttribute("opacity", bo.toFixed(3));
|
|
358
|
+
if (this.stacks) return this.renderStack(k, t, pos, ahead, PV);
|
|
359
|
+
this.bars.forEach(function(b){
|
|
360
|
+
var o = b.o, at = o.at + 0.1 * b.j;
|
|
361
|
+
var e = o.step < k || ahead(o, b.v) ? 1 : o.step > k ? 0 : D.prog(t, at, P.dur);
|
|
362
|
+
var v = b.v * e, p = pos(v), w = self.bw;
|
|
363
|
+
if (self.neg){
|
|
364
|
+
// 0 の基線から値まで(負なら下・左へ)
|
|
365
|
+
var zb = pos(0);
|
|
366
|
+
if (hor){ b.rect.setAttribute("x", Math.min(p, zb).toFixed(1)); b.rect.setAttribute("width", Math.abs(p - zb).toFixed(1)); b.rect.setAttribute("y", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("height", w.toFixed(1)); }
|
|
367
|
+
else { b.rect.setAttribute("x", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("width", w.toFixed(1)); b.rect.setAttribute("y", Math.min(p, zb).toFixed(1)); b.rect.setAttribute("height", Math.abs(zb - p).toFixed(1)); }
|
|
368
|
+
} else if (hor){ b.rect.setAttribute("x", self.x0); b.rect.setAttribute("width", Math.max(0, p - self.x0).toFixed(1)); b.rect.setAttribute("y", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("height", w.toFixed(1)); }
|
|
369
|
+
else { b.rect.setAttribute("x", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("width", w.toFixed(1)); b.rect.setAttribute("y", p.toFixed(1)); b.rect.setAttribute("height", Math.max(0, self.y1 - p).toFixed(1)); }
|
|
370
|
+
b.rect.setAttribute("opacity", ahead(o, b.v) ? PV : e > 0 ? 1 : 0);
|
|
371
|
+
if (b.dot){
|
|
372
|
+
var dp = pos(b.v);
|
|
373
|
+
b.dot.setAttribute("cx", (hor ? dp : b.c).toFixed(1)); b.dot.setAttribute("cy", (hor ? b.c : dp).toFixed(1));
|
|
374
|
+
b.dot.setAttribute("opacity", (ahead(o, b.v) ? PV : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, at, P.dur)).toFixed(3));
|
|
375
|
+
}
|
|
376
|
+
// 値の数字:既定は伸びきってから。count なら伸びに合わせて
|
|
377
|
+
var vo = ahead(o, b.v) ? PV : P.count ? (e > 0 ? 1 : 0) : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, at + P.dur, 0.35);
|
|
378
|
+
b.val.textContent = self.fmt(P.count ? v : b.v);
|
|
379
|
+
var pe = P.count ? p : pos(b.v), dn = b.v < 0;
|
|
380
|
+
// 誤差棒があれば値の数字はその端の外、点なら点の外
|
|
381
|
+
if (b.err) pe = pos(dn ? b.err.lo : b.err.hi);
|
|
382
|
+
else if (b.dot) pe = pos(b.v) + (hor ? (dn ? -10 : 10) : (dn ? 10 : -10));
|
|
383
|
+
if (b.err){
|
|
384
|
+
var yl = pos(b.err.lo), yh = pos(b.err.hi), cw = Math.min(14, w * 0.3), c = b.c;
|
|
385
|
+
b.err.path.setAttribute("d", hor ? "M" + yl.toFixed(1) + "," + (c - cw).toFixed(1) + "V" + (c + cw).toFixed(1) + "M" + yl.toFixed(1) + "," + c.toFixed(1) + "H" + yh.toFixed(1) + "M" + yh.toFixed(1) + "," + (c - cw).toFixed(1) + "V" + (c + cw).toFixed(1)
|
|
386
|
+
: "M" + (c - cw).toFixed(1) + "," + yl.toFixed(1) + "H" + (c + cw).toFixed(1) + "M" + c.toFixed(1) + "," + yl.toFixed(1) + "V" + yh.toFixed(1) + "M" + (c - cw).toFixed(1) + "," + yh.toFixed(1) + "H" + (c + cw).toFixed(1));
|
|
387
|
+
b.err.path.setAttribute("opacity", (ahead(o, b.v) ? PV : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, at + P.dur, 0.35)).toFixed(3));
|
|
388
|
+
}
|
|
389
|
+
// 値の数字は棒の端の外側:正なら上(右)、負なら下(左)
|
|
390
|
+
if (hor){ b.val.setAttribute("x", (dn ? pe - 10 : pe + 10).toFixed(1)); b.val.setAttribute("y", (b.c + 9).toFixed(1)); }
|
|
391
|
+
else { b.val.setAttribute("x", b.c.toFixed(1)); b.val.setAttribute("y", (dn ? pe + 32 : pe - 12).toFixed(1)); }
|
|
392
|
+
b.val.setAttribute("opacity", vo.toFixed(3));
|
|
393
|
+
if (b.ser){
|
|
394
|
+
var sv = b.err ? (dn ? b.err.lo : b.err.hi) : b.v;
|
|
395
|
+
if (hor){ b.ser.setAttribute("x", (dn ? pos(sv) - 24 - self.fmt(b.v).length * 15 : pos(sv) + 24 + self.fmt(b.v).length * 15).toFixed(1)); b.ser.setAttribute("y", (b.c + 8).toFixed(1)); }
|
|
396
|
+
else { b.ser.setAttribute("x", b.c.toFixed(1)); b.ser.setAttribute("y", (dn ? pos(sv) + 62 : pos(sv) - 44).toFixed(1)); }
|
|
397
|
+
b.ser.setAttribute("opacity", vo.toFixed(3));
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
this.renderSig(k, t, pos, PV, preview);
|
|
401
|
+
}
|
|
402
|
+
// 有意差の括弧:つなぐ棒の間の、いちばん高い値の数字(と系列の名前)より上に。横に重なる括弧は 44 px ずつ上へ(内側の短い括弧から)
|
|
403
|
+
renderSig(k, t, pos, PV, preview){
|
|
404
|
+
if (!this.sigs || !this.sigs.length) return;
|
|
405
|
+
var D = base, self = this, placed = [];
|
|
406
|
+
var top = function(b){ var v = b.err ? b.err.hi : b.v; return pos(Math.max(0, v)) - (b.dot && !b.err ? 22 : 12) - 26 - (b.ser ? 34 : 0); };
|
|
407
|
+
var mid = function(bs){ return bs.reduce(function(a, b){ return a + b.c; }, 0) / bs.length; };
|
|
408
|
+
this.sigs.slice().sort(function(a, b){ return Math.abs(mid(a.b) - mid(a.a)) - Math.abs(mid(b.b) - mid(b.a)); }).forEach(function(sg){
|
|
409
|
+
var x1 = mid(sg.a), x2 = mid(sg.b), l = Math.min(x1, x2), r = Math.max(x1, x2);
|
|
410
|
+
var y = Math.min.apply(null, sg.span.map(top)) - 10;
|
|
411
|
+
for (var moved = true; moved;){
|
|
412
|
+
moved = false;
|
|
413
|
+
placed.forEach(function(q){ if (q.l < r + 20 && l < q.r + 20 && y > q.y - 44){ y = q.y - 44; moved = true; } });
|
|
414
|
+
}
|
|
415
|
+
placed.push({l: l, r: r, y: y});
|
|
416
|
+
sg.path.setAttribute("d", "M" + x1.toFixed(1) + "," + (y + 14).toFixed(1) + "V" + y.toFixed(1) + "H" + x2.toFixed(1) + "V" + (y + 14).toFixed(1));
|
|
417
|
+
sg.text.setAttribute("x", ((x1 + x2) / 2).toFixed(1)); sg.text.setAttribute("y", (y - 8).toFixed(1));
|
|
418
|
+
var op = preview && sg.step > k ? PV : sg.step < k ? 1 : sg.step > k ? 0 : D.prog(t, sg.at, 0.35);
|
|
419
|
+
sg.path.setAttribute("opacity", op.toFixed(3)); sg.text.setAttribute("opacity", op.toFixed(3));
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
// 積み上げ棒:棒の先が 0 から合計まで伸び、下の系列から順に色が満ちる。値の数字は伸びきってから
|
|
423
|
+
renderStack(k, t, pos, ahead, PV){
|
|
424
|
+
var P = this.props, D = base, self = this, hor = this.hor, w = this.bw;
|
|
425
|
+
var len = function(a, b){ return Math.abs(pos(b) - pos(a)); };
|
|
426
|
+
this.stacks.forEach(function(sk){
|
|
427
|
+
var o = sk.o, f = ahead(o, sk.total), e = o.step < k || f ? 1 : o.step > k ? 0 : D.prog(t, o.at, P.dur), top = sk.total * e;
|
|
428
|
+
var vo = f ? PV : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, o.at + P.dur, 0.35);
|
|
429
|
+
sk.segs.forEach(function(sg, j){
|
|
430
|
+
var a = Math.min(sg.from, top), b = Math.min(sg.from + sg.v, top), pa = pos(a), pb = pos(b), gap = j > 0 && b > a ? 2 : 0;
|
|
431
|
+
var px = Math.max(0, Math.abs(pb - pa) - gap);
|
|
432
|
+
if (hor){ sg.rect.setAttribute("x", (pa + gap).toFixed(1)); sg.rect.setAttribute("width", px.toFixed(1)); sg.rect.setAttribute("y", (sk.c - w / 2).toFixed(1)); sg.rect.setAttribute("height", w.toFixed(1)); }
|
|
433
|
+
else { sg.rect.setAttribute("x", (sk.c - w / 2).toFixed(1)); sg.rect.setAttribute("width", w.toFixed(1)); sg.rect.setAttribute("y", pb.toFixed(1)); sg.rect.setAttribute("height", px.toFixed(1)); }
|
|
434
|
+
sg.rect.setAttribute("opacity", px > 0 ? (f ? PV : 1) : 0);
|
|
435
|
+
// 区切りの中の値:伸びきった区切りに字が収まるときだけ。100 % の積み上げ棒では、字の箱(幅の見積もり × 24 px)が
|
|
436
|
+
// 四方に 6 px 以上の余白をもって入るときだけ
|
|
437
|
+
var full = len(sg.from, sg.from + sg.v) - gap, mid = (pos(sg.from) + pos(sg.from + sg.v)) / 2;
|
|
438
|
+
var room = self.pct ? (hor ? full >= sg.vw + 12 && w >= 36 : full >= 36 && w >= sg.vw + 12)
|
|
439
|
+
: hor ? full >= sg.vw + 12 && w >= 30 : full >= 30 && w >= sg.vw + 8;
|
|
440
|
+
if (hor){ sg.val.setAttribute("x", mid.toFixed(1)); sg.val.setAttribute("y", (sk.c + 8).toFixed(1)); }
|
|
441
|
+
else { sg.val.setAttribute("x", sk.c.toFixed(1)); sg.val.setAttribute("y", (mid + 8).toFixed(1)); }
|
|
442
|
+
sg.val.setAttribute("opacity", (room ? vo : 0).toFixed(3));
|
|
443
|
+
});
|
|
444
|
+
// 合計:棒の端(count なら伸びに合わせて数え上げる)
|
|
445
|
+
sk.tot.textContent = self.fmt(P.count ? top : sk.total);
|
|
446
|
+
var pe = P.count ? pos(top) : pos(sk.total);
|
|
447
|
+
if (hor){ sk.tot.setAttribute("x", (pe + 10).toFixed(1)); sk.tot.setAttribute("y", (sk.c + 9).toFixed(1)); }
|
|
448
|
+
else { sk.tot.setAttribute("x", sk.c.toFixed(1)); sk.tot.setAttribute("y", (pe - 12).toFixed(1)); }
|
|
449
|
+
// 100 % の積み上げ棒は端がどれも 100 % なので、合計は書かない
|
|
450
|
+
sk.tot.setAttribute("opacity", (self.pct ? 0 : f ? PV : P.count ? (e > 0 ? 1 : 0) : vo).toFixed(3));
|
|
451
|
+
});
|
|
452
|
+
// 系列の名前:区切りの真ん中。縦に並ぶ名前(縦棒)は 28 px、横に並ぶ名前(横棒)は字の幅より近づけない
|
|
453
|
+
var prev = null;
|
|
454
|
+
this.serLabs.forEach(function(sl){
|
|
455
|
+
var sk = sl.ref, o = sk.o, sg = sl.sg, mid = (pos(sg.from) + pos(sg.from + sg.v)) / 2;
|
|
456
|
+
var vo = ahead(o, sk.total) ? PV : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, o.at + P.dur, 0.35);
|
|
457
|
+
if (hor){
|
|
458
|
+
var x = prev ? Math.max(mid, prev.x + (prev.w + sl.w) / 2 + 12) : mid;
|
|
459
|
+
sl.el.setAttribute("x", x.toFixed(1)); sl.el.setAttribute("y", (sk.c - w / 2 - 10).toFixed(1));
|
|
460
|
+
prev = {x: x, w: sl.w};
|
|
461
|
+
} else {
|
|
462
|
+
var y = prev ? Math.min(mid + 8, prev.y - 28) : mid + 8;
|
|
463
|
+
sl.el.setAttribute("x", (sk.c + w / 2 + 12).toFixed(1)); sl.el.setAttribute("y", y.toFixed(1));
|
|
464
|
+
prev = {y: y};
|
|
465
|
+
}
|
|
466
|
+
sl.el.setAttribute("opacity", vo.toFixed(3));
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Screen steps: numbered circles on a screenshot, joined by leader lines to labels beside it, one per step
|
|
3
|
+
steps: max callout step (default 1 callout = 1 step)
|
|
4
|
+
props:
|
|
5
|
+
side: labels on right, left or both
|
|
6
|
+
label-width: label column (share of width)
|
|
7
|
+
per-step: callouts per step (0 = all)
|
|
8
|
+
dur: seconds per callout
|
|
9
|
+
size: label px (≥ 24)
|
|
10
|
+
example: {"callouts": [{"x": 0.12, "y": 0.08, "text": "Open the menu"}, {"x": 0.7, "y": 0.62, "text": "Press Send"}]}
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
For training and how-to guides: where to click, in order.
|
|
14
|
+
|
|
15
|
+
The screenshot is a child `<img src="figs/…" alt width height>` (inlined at build) or a `data:` URL. Without the screenshot, write a figure frame and the steps instead; place circles once it is in.
|
|
16
|
+
|
|
17
|
+
- **Never show real personal data on a screenshot** (names, ID numbers, resident or patient records). Use made-up data, or blur it.
|
|
18
|
+
- `alt`, `width` and `height` (px) are required (else data); an image over 1 MiB is size.
|
|
19
|
+
|
|
20
|
+
Child JSON: `{"callouts": [...]}`; callout: `x`, `y` (0–1 of the image), `text`, `box` (`[x, y, w, h]`, highlighted during its step), `step`, `at`.
|
|
21
|
+
<!-- llm: omit -->
|
|
22
|
+
- Labels follow the circles' vertical order, so leader lines never cross.
|
|
23
|
+
<!-- llm: end -->
|