egatari 0.6.6 → 0.6.7-rc.1
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/NOTICE +6 -0
- package/README.ja.md +3 -3
- package/README.md +3 -3
- package/bin/egatari.mjs +2 -2
- package/components.lock.json +33 -15
- package/components2.lock.json +409 -1
- package/kit/build.mjs +28 -4
- package/kit/check-messages.mjs +14 -0
- package/kit/check.mjs +21 -0
- package/kit/core/build-core.mjs +84 -19
- package/kit/core/colab-core.mjs +3 -1
- package/kit/core/fill-measure.mjs +79 -0
- package/kit/core/font-coverage.mjs +52 -0
- package/kit/core/font-subset-core.mjs +101 -0
- package/kit/core/llm-fix.mjs +3 -2
- package/kit/core/llm-pack-data.mjs +39 -41
- package/kit/core/parts2.mjs +34 -0
- package/kit/core/portable.mjs +30 -2
- package/kit/core/scorm.mjs +109 -0
- package/kit/core/tier-a.mjs +72 -26
- package/kit/core/zip-write.mjs +57 -0
- package/kit/deck.js +118 -29
- package/kit/fill-scan.mjs +95 -0
- package/kit/font-subset.mjs +33 -0
- package/kit/instruction-version.json +1 -1
- package/kit/live.js +3 -1
- package/kit/llm-pack.mjs +15 -14
- package/kit/panes.js +26 -14
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/tools.js +20 -23
- package/kit/track.js +11 -5
- package/package.json +4 -2
- package/render/audio-track.mjs +112 -0
- package/render/render.mjs +99 -51
- package/tools/video.mjs +17 -9
- package/vendor/components/CATALOG.md +2 -2
- package/vendor/components/sha256/0787c5bbf2e61801398aeefc39a3674b1fc0e556173c450b85cafa4201cb44a6/README.en.md +40 -0
- package/vendor/components/sha256/0787c5bbf2e61801398aeefc39a3674b1fc0e556173c450b85cafa4201cb44a6/index.js +348 -0
- package/vendor/components/sha256/0cab77d128c5f304c2d2ba32841b0bc5adc54b4e72f6681e0a0dda68c96b5d7e/README.en.md +32 -0
- package/vendor/components/sha256/0cab77d128c5f304c2d2ba32841b0bc5adc54b4e72f6681e0a0dda68c96b5d7e/index.js +222 -0
- package/vendor/components/sha256/25eab59287c5c52f9d2f8a7cee3d61ed513cc1c9ca846bba96b45cd59b39f822/README.en.md +42 -0
- package/vendor/components/sha256/25eab59287c5c52f9d2f8a7cee3d61ed513cc1c9ca846bba96b45cd59b39f822/index.js +481 -0
- package/vendor/components/sha256/28238c4fa50a377b96ce8a130ce5bdbf7bfc0536ed9c331499ea22377c43adb6/README.en.md +39 -0
- package/vendor/components/sha256/28238c4fa50a377b96ce8a130ce5bdbf7bfc0536ed9c331499ea22377c43adb6/index.js +323 -0
- package/vendor/components/sha256/2f1c797ecd028d04ce12b3d55d8ef9d5a4180d564aa99afb492d0bfc9cd39c94/README.en.md +42 -0
- package/vendor/components/sha256/2f1c797ecd028d04ce12b3d55d8ef9d5a4180d564aa99afb492d0bfc9cd39c94/index.js +267 -0
- package/vendor/components/sha256/389ab61c0dafed88074c0c459ed40b6738bec05ebf6e4566bba1394405f2392e/README.en.md +52 -0
- package/vendor/components/sha256/389ab61c0dafed88074c0c459ed40b6738bec05ebf6e4566bba1394405f2392e/index.js +219 -0
- package/vendor/components/sha256/3df7d0ec0c3ed4a6b06fbe3befec78b65a2202e5571580d8b28700a14b7b4321/README.en.md +66 -0
- package/vendor/components/sha256/3df7d0ec0c3ed4a6b06fbe3befec78b65a2202e5571580d8b28700a14b7b4321/index.js +920 -0
- package/vendor/components/sha256/40571cbc11cd649c447da73ede0f89937da344b05d4386abeb4afeecedfe7d3e/README.en.md +32 -0
- package/vendor/components/sha256/40571cbc11cd649c447da73ede0f89937da344b05d4386abeb4afeecedfe7d3e/index.js +352 -0
- package/vendor/components/sha256/4dd7e6a02f4128e90d4e2a86cccd9bf267a02cebcff1cdf36e0aaff8848af66e/README.en.md +31 -0
- package/vendor/components/sha256/4dd7e6a02f4128e90d4e2a86cccd9bf267a02cebcff1cdf36e0aaff8848af66e/index.js +232 -0
- package/vendor/components/sha256/520606a746b0d38fdc1aa380e665a1b95eead2487b11f389d2ebac4abe8f07cb/README.en.md +48 -0
- package/vendor/components/sha256/520606a746b0d38fdc1aa380e665a1b95eead2487b11f389d2ebac4abe8f07cb/index.js +384 -0
- package/vendor/components/sha256/554ed56e1ec963627be86ba1f573099ff57cf4cb22e8e10ce00e2128e30d39e2/README.en.md +42 -0
- package/vendor/components/sha256/554ed56e1ec963627be86ba1f573099ff57cf4cb22e8e10ce00e2128e30d39e2/index.js +481 -0
- package/vendor/components/sha256/782ae2154247b00451fc30aa140bf386d3a7a56ac4ad9ee04916f4bd1d29dda0/README.en.md +37 -0
- package/vendor/components/sha256/782ae2154247b00451fc30aa140bf386d3a7a56ac4ad9ee04916f4bd1d29dda0/index.js +424 -0
- package/vendor/components/sha256/808f748e76833742bb12a80482b37cb3dedaf3dcd592ee477d611cb40e95b094/README.en.md +44 -0
- package/vendor/components/sha256/808f748e76833742bb12a80482b37cb3dedaf3dcd592ee477d611cb40e95b094/index.js +304 -0
- package/vendor/components/sha256/8c3d7e9921f249cf45ce26d5a449f2b01fef683f500afed69d0b189312c4464e/index.js +904 -0
- package/vendor/components/sha256/96ad8eaf0ea7c23a31b72657964f23a02165765845991cafc41ee2835b97e40f/README.en.md +42 -0
- package/vendor/components/sha256/96ad8eaf0ea7c23a31b72657964f23a02165765845991cafc41ee2835b97e40f/index.js +170 -0
- package/vendor/components/sha256/b86c0e95622ff3be5fb0b208672ebca5018c34fd192e1b431cfd0fe912df2a7f/index.js +916 -0
- package/vendor/components/sha256/bec04685638f8fc1217c380d361fd9a425ffeade0291a4f2b2d4e41a5628e0ef/index.js +809 -0
- package/vendor/components/sha256/c3d3d56101f430f3468a8f281055c3ea5093fc5c77a35f14fabeb85ad363e209/README.en.md +37 -0
- package/vendor/components/sha256/c3d3d56101f430f3468a8f281055c3ea5093fc5c77a35f14fabeb85ad363e209/index.js +424 -0
- package/vendor/components/sha256/e1a0240f83e1925ee59ef2752662e2b0ec27f69251c012f8bab682aadcd8695f/README.en.md +34 -0
- package/vendor/components/sha256/e1a0240f83e1925ee59ef2752662e2b0ec27f69251c012f8bab682aadcd8695f/index.js +244 -0
- package/vendor/components/sha256/e2181655ed2050668133e08eb14b5683cda48d6af8d76fd7b551c58798c95287/README.en.md +50 -0
- package/vendor/components/sha256/e2181655ed2050668133e08eb14b5683cda48d6af8d76fd7b551c58798c95287/index.js +171 -0
- package/vendor/components/sha256/ef9c8c77ddf2b3953376a2db700c1277f550ea2606eab11cd8e18056dcba84c1/README.en.md +35 -0
- package/vendor/components/sha256/ef9c8c77ddf2b3953376a2db700c1277f550ea2606eab11cd8e18056dcba84c1/index.js +179 -0
- package/vendor/components/sha256/f3d5b6ce53f40c5f355a67538ff11b9cd28297da6292125ccb6e055aeddef906/README.en.md +51 -0
- package/vendor/components/sha256/f3d5b6ce53f40c5f355a67538ff11b9cd28297da6292125ccb6e055aeddef906/index.js +228 -0
- package/vendor/components-2/manifest-2.4.3.json +1962 -0
- package/vendor/components-2/manifest-2.4.4.json +1911 -0
- package/vendor/components-2/manifest-2.5.0.json +1911 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
// m-tree:階層・分類の木(組織図、生物の分類など)を、上の段から順に組み立てる
|
|
2
|
+
// <m-tree style="height:480px"><script type="application/json">
|
|
3
|
+
// {"nodes": [{"id": "co", "label": "本社"}, {"id": "a", "label": "営業部", "parent": "co"}, …],
|
|
4
|
+
// "edges": [{"from": "a", "to": "b", "label": "連携"}]}
|
|
5
|
+
// (JSON の終わり)</m-tree>
|
|
6
|
+
// 座標は書かない(docs/conventions.md §2)。parent のない節がちょうど 1 つ(根)。子は配列の順に並べる
|
|
7
|
+
// 配置:親を子の並びの中央に置き、隣り合う部分木は段ごとの輪郭(左右の端)がぶつからないところまで寄せる(Reingold–Tilford の考え方)
|
|
8
|
+
// orient:down(既定、上から下)か right(左から右)。link:elbow(既定、かぎ形)か straight(まっすぐ)
|
|
9
|
+
// 段階:by="level"(既定、根、それから深さごとに 1 段)か by="node"(深さ優先の順に 1 つずつ)。節の step が勝つ
|
|
10
|
+
// edges:親子のほかのつながり(破線、矢印つき)。段階は両端の遅いほう
|
|
11
|
+
// 字の大きさは要素の大きさから決め(27 px から)、入らなければ 24 px まで縮める。それでも入らなければ、字は 24 px のまま
|
|
12
|
+
// 葉だけの子を 2 段に互い違いに並べ、名前を 2 行に折る。それでも入らなければ要素の箱からはみ出して ctx.report("size", …)(足りない px)
|
|
13
|
+
// 見せ方(docs/conventions.md §2.5):fade(箱が下から 12 px 上がりながら現れてから線を引く、既定)・draw(線を先に引き、
|
|
14
|
+
// その先に箱が親の側から 12 px 寄りながら現れる)・grow(箱が親の側から 12 px 寄りながら 0.92 → 1 に大きくなる)。
|
|
15
|
+
// 箱の動きはどれも 12 px まで。段階の数・長さ・最後の中身はどれも同じ
|
|
16
|
+
// branch(子の節):親からの線に添える字(確率・条件・はい/いいえ)。path:根から葉への id の列を --emph で示す
|
|
17
|
+
// (既定は木の後に線 1 本ごとに 1 段階、pathStep があればその段階に)。pathNote:終わりの箱の外の一言
|
|
18
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
19
|
+
// 式(tex)は組み立てのときに KaTeX で描く(spec §6.2):build.fields の nodes[].tex を作り手が描いて texHtml を足し、
|
|
20
|
+
// この部品は markup-reader で決まった要素と属性だけを読んで置く(再生のときに KaTeX は動かない)。描いた結果がなければ tex を字のまま出して知らせる。
|
|
21
|
+
// 入らないときは ctx.report("size", "[tree] …") で知らせる(1.x の console.warn の代わり)
|
|
22
|
+
egatariParts.define({name: "tree", version: "2.0.3", requires: {base: "1.1.0", "markup-reader": "1.0.1"}, element: "m-tree"}, function(deps){
|
|
23
|
+
"use strict";
|
|
24
|
+
var base = deps.base, MR = deps["markup-reader"];
|
|
25
|
+
// 形の要素ごとに、書き直すと形が作り直される属性(render の終わりで使う)
|
|
26
|
+
var SHAPE_GEOM = {rect: "width", circle: "r", ellipse: "rx", path: "d", line: "x1", polyline: "points", polygon: "points"};
|
|
27
|
+
// 複数行の名前の行の位置(1 行目からの下がり、px)と、上下に足す余白。base 1.1.0 で mtext の下付き・上付きは 24px 以上になり、
|
|
28
|
+
// 行の間 lh(字の 1.25 倍)では上の行の下付きと下の行の上付きが重なる。下付きの字の下端は基線から添字の 0.75 倍まで、上付きの字の
|
|
29
|
+
// 上端は添字の 1.4 倍まで(Source Sans 3 で測った値。BIZ UDPGothic ではそれぞれ 0.5 倍と 1.2 倍)。上の行に下付き(_)があれば
|
|
30
|
+
// その下端から字の下の余白(字の 0.12 倍)を引いた分、下の行に上付き(^)があればその上端から字の上の高さ(0.88 倍)を引いた分だけ
|
|
31
|
+
// 行の間を広げる。top・bottom は 1 行目の上付き・最後の行の下付きの分(添字がなければどれも 0 で、行は lh ずつ)
|
|
32
|
+
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; }
|
|
33
|
+
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; }
|
|
34
|
+
function lineYs(lines, lh, fs){
|
|
35
|
+
var y = [0];
|
|
36
|
+
for (var j = 1; j < lines.length; j++) y.push(y[j - 1] + lh + subX(lines[j - 1], fs) + supX(lines[j], fs));
|
|
37
|
+
y.top = supX(lines[0], fs); y.bottom = subX(lines[lines.length - 1], fs);
|
|
38
|
+
return y;
|
|
39
|
+
}
|
|
40
|
+
var Part = class extends base.MotionElement {
|
|
41
|
+
static partName = "tree"; // the registry name (define meta name), for report prefixes
|
|
42
|
+
// 組み立てのときに描く欄(spec §6.2)。式の意味は字(tex)でも持つので、KaTeX の出力は HTML だけ
|
|
43
|
+
static build = {fields: {"nodes[].tex": "katex"}, options: {katex: {output: "html"}}};
|
|
44
|
+
static variants = ["fade", "draw", "grow"];
|
|
45
|
+
// データの形(kit/shape.js)
|
|
46
|
+
static shape = {
|
|
47
|
+
schema: {type: "object", additionalProperties: false, required: ["nodes"], properties: {
|
|
48
|
+
nodes: {type: "array", minItems: 1, items: {type: "object", required: ["id"], properties: {
|
|
49
|
+
id: {type: ["string", "integer"]}, label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, note: {type: "string"}, tone: {type: "string"},
|
|
50
|
+
parent: {type: ["string", "integer"]}, branch: {type: "string"}, step: {type: "integer"}, at: {type: "number"}}}},
|
|
51
|
+
edges: {type: "array", items: {type: "object", required: ["from", "to"], properties: {
|
|
52
|
+
from: {type: ["string", "integer"]}, to: {type: ["string", "integer"]}, label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"},
|
|
53
|
+
step: {type: "integer"}, at: {type: "number"}}}},
|
|
54
|
+
path: {type: "array", minItems: 2, items: {type: ["string", "integer"]}}, pathStep: {type: "integer"}, pathNote: {type: "string"}, renderers: {type: "object"}}},
|
|
55
|
+
example: {nodes: [{id: "r", label: "動物"}, {id: "a", label: "脊椎動物", parent: "r"}, {id: "b", label: "無脊椎動物", parent: "r"}]},
|
|
56
|
+
note: {en: "exactly one node without parent (the root)", ja: "parent のない節(根)はちょうど 1 つ"},
|
|
57
|
+
};
|
|
58
|
+
static props = {
|
|
59
|
+
orient: {type: "string", default: "down", doc: "down(上から下、既定)か right(左から右)"},
|
|
60
|
+
by: {type: "string", default: "level", doc: "段階の分け方:level(深さごと、既定)か node(1 つずつ、深さ優先の順)"},
|
|
61
|
+
link: {type: "string", default: "elbow", doc: "親子の線:elbow(かぎ形、既定)か straight(まっすぐ)"},
|
|
62
|
+
size: {type: "number", default: 0, doc: "箱の字の大きさ(px。0 = 27 から入るまで 24 まで縮める)"},
|
|
63
|
+
fade: {type: "number", default: 0.45, doc: "箱が現れる秒数"},
|
|
64
|
+
draw: {type: "number", default: 0.5, doc: "線を引く秒数"},
|
|
65
|
+
};
|
|
66
|
+
// 木の形と段階(mount の前にも段階の数のために使う)
|
|
67
|
+
plan(){
|
|
68
|
+
if (this._plan) return this._plan;
|
|
69
|
+
var d = this.data || {}, P = this.props, byId = {}, roots = [], notes = this._notes = []; // データの問題:mount が ctx.report で知らせる
|
|
70
|
+
var nodes = (d.nodes || []).map(function(n){
|
|
71
|
+
var o = {n: n, kids: [], depth: 0};
|
|
72
|
+
if (byId[n.id]) notes.push("[tree] the id " + JSON.stringify(n.id) + " is used by more than one node (parent, edges and path refer to the last one; give each node its own id)");
|
|
73
|
+
byId[n.id] = o; return o;
|
|
74
|
+
});
|
|
75
|
+
nodes.forEach(function(o){
|
|
76
|
+
if (o.n.parent === undefined || o.n.parent === null) roots.push(o);
|
|
77
|
+
else if (!byId[o.n.parent]) throw new Error("m-tree: node " + JSON.stringify(o.n.id) + " has an unknown parent " + JSON.stringify(o.n.parent));
|
|
78
|
+
else byId[o.n.parent].kids.push(o);
|
|
79
|
+
});
|
|
80
|
+
if (roots.length !== 1) throw new Error("m-tree: exactly one node must have no parent (the root); found " + roots.length);
|
|
81
|
+
var order = [], seen = 0;
|
|
82
|
+
(function walk(o, dep){
|
|
83
|
+
if (++seen > nodes.length) throw new Error("m-tree: the parents form a loop");
|
|
84
|
+
o.depth = dep; order.push(o);
|
|
85
|
+
o.kids.forEach(function(c){ c.par = o; walk(c, dep + 1); });
|
|
86
|
+
})(roots[0], 0);
|
|
87
|
+
if (order.length !== nodes.length) throw new Error("m-tree: the parents form a loop");
|
|
88
|
+
var byNode = P.by === "node";
|
|
89
|
+
order.forEach(function(o, i){ o.step = o.n.step !== undefined ? o.n.step : byNode ? i + 1 : o.depth + 1; o.at = o.n.at || 0; });
|
|
90
|
+
var edges = (d.edges || []).map(function(e){
|
|
91
|
+
var a = byId[e.from], b = byId[e.to];
|
|
92
|
+
if (!a || !b) throw new Error("m-tree: edge to an unknown node " + JSON.stringify(a ? e.to : e.from));
|
|
93
|
+
return {e: e, a: a, b: b, step: e.step !== undefined ? e.step : Math.max(a.step, b.step)};
|
|
94
|
+
});
|
|
95
|
+
// 強調する道(path:根から葉への id の列)。既定は木ができた後に 1 段階に 1 本ずつ、pathStep があればその段階に順に
|
|
96
|
+
var path = null;
|
|
97
|
+
if (d.path !== undefined){
|
|
98
|
+
if (!Array.isArray(d.path) || d.path.length < 2) throw new Error("m-tree: path must list at least two ids, from the root");
|
|
99
|
+
var pn = d.path.map(function(id){ if (!byId[id]) throw new Error("m-tree: path names an unknown node " + JSON.stringify(id)); return byId[id]; });
|
|
100
|
+
if (pn[0] !== roots[0]) throw new Error("m-tree: path must start at the root " + JSON.stringify(roots[0].n.id));
|
|
101
|
+
pn.forEach(function(o, i){ if (i && o.par !== pn[i - 1]) throw new Error("m-tree: path: " + JSON.stringify(o.n.id) + " is not a child of " + JSON.stringify(pn[i - 1].n.id)); });
|
|
102
|
+
var last = 1, one = d.pathStep !== undefined;
|
|
103
|
+
nodes.concat(edges).forEach(function(o){ last = Math.max(last, o.step); });
|
|
104
|
+
path = {nodes: pn, note: d.pathNote, links: pn.slice(1).map(function(o, i){ return {o: o, step: one ? d.pathStep : last + 1 + i, at: one ? i * P.draw : 0}; })};
|
|
105
|
+
}
|
|
106
|
+
return (this._plan = {nodes: nodes, order: order, root: roots[0], byId: byId, edges: edges, path: path});
|
|
107
|
+
}
|
|
108
|
+
get steps(){
|
|
109
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
110
|
+
var p = this.plan(), m = 1;
|
|
111
|
+
p.nodes.concat(p.edges, p.path ? p.path.links : []).forEach(function(o){ m = Math.max(m, o.step); });
|
|
112
|
+
return m;
|
|
113
|
+
}
|
|
114
|
+
mount(ctx){
|
|
115
|
+
var P = this.props, D = base, self = this, pl = this.plan(), sk = MR.sink(this, ctx);
|
|
116
|
+
this._notes.forEach(function(m){ ctx.report("data", m); });
|
|
117
|
+
this.variant = base.variant(this);
|
|
118
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
119
|
+
var W = this.clientWidth, H = this.clientHeight, right = P.orient === "right";
|
|
120
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
121
|
+
var root = D.el("g", {}, svg), gL = D.el("g", {}, root), gE = D.el("g", {}, root), gN = D.el("g", {}, root);
|
|
122
|
+
// 字の幅の見積もり(字の大きさ 1 あたり。base の textWidth:テーマの字で測った幅。*斜体* などの記号は数えない)
|
|
123
|
+
var est = function(s){ return D.textWidth(s, 1, {font: self, mark: true}); };
|
|
124
|
+
var texEst = function(s){ return Math.max(1, String(s).replace(/\\[a-zA-Z]+/g, "x").replace(/[{}^_\\ ]/g, "").length) * 0.62; };
|
|
125
|
+
var NS = 24, NLH = 30; // 注(note)の字の大きさと行の高さ
|
|
126
|
+
var levels = 0;
|
|
127
|
+
pl.nodes.forEach(function(o){ levels = Math.max(levels, o.depth + 1); });
|
|
128
|
+
var labW = 0;
|
|
129
|
+
pl.edges.forEach(function(x){ if (x.e.label) labW = Math.max(labW, est(x.e.label) * 24); });
|
|
130
|
+
var edgeRoom = pl.edges.length ? 56 + (labW ? (right ? labW + 14 : 36) : 0) : 0;
|
|
131
|
+
// 枝の名前(node.branch:親からの線に添える字。確率・条件・はい/いいえ)と、道の終わりの一言(pathNote)の場所
|
|
132
|
+
var brs = pl.nodes.filter(function(o){ o.brw = o.par && o.n.branch ? est(o.n.branch) * 24 : 0; return o.brw > 0; }), brW = 0;
|
|
133
|
+
brs.forEach(function(o){ brW = Math.max(brW, o.brw); });
|
|
134
|
+
var pnote = pl.path && pl.path.note ? String(pl.path.note) : "", pnRoom = pnote ? (right ? est(pnote) * 27 + 18 : 44) : 0;
|
|
135
|
+
// 名前を 2 行に折る(入らないときだけ)。\n も *_^ もない 4 字以上の名前に限る。空白があれば真ん中に近い空白で、
|
|
136
|
+
// 和文は真ん中あたりで(小さい仮名・長音・句読点を行の頭にしない)。空白のない欧文の 1 語は折らない
|
|
137
|
+
function wrap2(t){
|
|
138
|
+
var ch = [...t], n = ch.length, best = -1;
|
|
139
|
+
if (n < 4 || /[*_^]/.test(t)) return null;
|
|
140
|
+
if (/ /.test(t)){
|
|
141
|
+
ch.forEach(function(c, i){ if (c === " " && (best < 0 || Math.abs(i - n / 2) < Math.abs(best - n / 2))) best = i; });
|
|
142
|
+
return [ch.slice(0, best).join(""), ch.slice(best + 1).join("")];
|
|
143
|
+
}
|
|
144
|
+
if (/^[\u0000-ɏ]+$/.test(t)) return null;
|
|
145
|
+
// 真ん中から 2 字以内で、平仮名の後ろで平仮名でない字の前(「とても長い|分類」)があればそこで
|
|
146
|
+
var cut = Math.ceil(n / 2), hira = /[ぁ-ゖ]/, d;
|
|
147
|
+
for (d = 0; d <= 2; d++){
|
|
148
|
+
if (cut - d >= 2 && hira.test(ch[cut - d - 1]) && !hira.test(ch[cut - d])){ cut -= d; break; }
|
|
149
|
+
if (d && cut + d <= n - 2 && hira.test(ch[cut + d - 1]) && !hira.test(ch[cut + d])){ cut += d; break; }
|
|
150
|
+
}
|
|
151
|
+
while (cut < n - 1 && /[ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヮー、。・)」』]/.test(ch[cut])) cut++;
|
|
152
|
+
return [ch.slice(0, cut).join(""), ch.slice(cut).join("")];
|
|
153
|
+
}
|
|
154
|
+
var wrapOn = false, RG = 14; // RG:2 段に並べた子の、段の間
|
|
155
|
+
// 大きさ s の字で箱を測る(b:並ぶ向きの幅、d:深さの向きの幅)
|
|
156
|
+
function measure(s){
|
|
157
|
+
pl.nodes.forEach(function(o){
|
|
158
|
+
var n = o.n, lines = n.tex ? [n.tex] : String(n.label || "").split("\n");
|
|
159
|
+
if (wrapOn && !n.tex && lines.length === 1){ var w2 = wrap2(lines[0]); if (w2) lines = w2; }
|
|
160
|
+
var tw = n.tex ? texEst(n.tex) * s : Math.max.apply(null, lines.map(est)) * s;
|
|
161
|
+
o.lines = lines;
|
|
162
|
+
var ys0 = n.tex ? null : lineYs(lines, s * 1.25, s);
|
|
163
|
+
o.w = Math.max(s * 2.4, tw + s * 1.3);
|
|
164
|
+
o.h = (n.tex ? s * 1.5 : ys0[lines.length - 1] + s * 1.25 + ys0.top + ys0.bottom) + s * 0.75;
|
|
165
|
+
o.notes = n.note ? String(n.note).split("\n") : [];
|
|
166
|
+
o.nw = o.notes.length ? Math.max.apply(null, o.notes.map(est)) * NS : 0; o.nh = o.notes.length ? o.notes.length * NLH + 4 : 0;
|
|
167
|
+
o.fb = right ? o.h + o.nh : Math.max(o.w, o.nw);
|
|
168
|
+
o.fd = right ? Math.max(o.w, o.nw) : o.h + o.nh;
|
|
169
|
+
// 下向きでは枝の名前が線の横に並ぶので、その分を並ぶ向きの幅にとる
|
|
170
|
+
if (!right && o.brw) o.fb = Math.max(o.fb, o.w + 2 * (o.brw + 14));
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// 部分木を置く:段ごとの輪郭 [左, 右] を返し、子の親からのずれ off を決める
|
|
174
|
+
function lay(o, gap){
|
|
175
|
+
var half = o.fb / 2, ks = o.kids;
|
|
176
|
+
if (!ks.length){ o.cont = [[-half, half]]; return; }
|
|
177
|
+
if (o.fold){
|
|
178
|
+
// 葉だけの子を 2 段に互い違いに並べる(row 1 が奥の段)。奥の段への線は手前の段の箱の間を通るので、箱から C 空ける
|
|
179
|
+
var p = [], C = 12;
|
|
180
|
+
ks.forEach(function(c, j){
|
|
181
|
+
c.cont = [[-c.fb / 2, c.fb / 2]];
|
|
182
|
+
if (!j){ p.push(0); return; }
|
|
183
|
+
var v = j % 2 ? p[j - 1] + ks[j - 1].fb / 2 + C : p[j - 1] + C + c.fb / 2;
|
|
184
|
+
if (j >= 2) v = Math.max(v, p[j - 2] + (ks[j - 2].fb + c.fb) / 2 + gap);
|
|
185
|
+
p.push(v);
|
|
186
|
+
});
|
|
187
|
+
var m0 = (p[0] + p[p.length - 1]) / 2, lo = Infinity, hi = -Infinity;
|
|
188
|
+
ks.forEach(function(c, j){ c.off = p[j] - m0; c.row = j % 2; lo = Math.min(lo, c.off - c.fb / 2); hi = Math.max(hi, c.off + c.fb / 2); });
|
|
189
|
+
o.cont = [[-half, half], [lo, hi]];
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var acc = null, pos = [];
|
|
193
|
+
ks.forEach(function(c){
|
|
194
|
+
c.row = 0;
|
|
195
|
+
lay(c, gap);
|
|
196
|
+
if (!acc){ pos.push(0); acc = c.cont.map(function(a){ return a.slice(); }); return; }
|
|
197
|
+
var sh = -Infinity, dd;
|
|
198
|
+
for (dd = 0; dd < Math.min(acc.length, c.cont.length); dd++) sh = Math.max(sh, acc[dd][1] + gap - c.cont[dd][0]);
|
|
199
|
+
pos.push(sh);
|
|
200
|
+
for (dd = 0; dd < c.cont.length; dd++){
|
|
201
|
+
var l = c.cont[dd][0] + sh, r = c.cont[dd][1] + sh;
|
|
202
|
+
if (dd < acc.length){ acc[dd][0] = Math.min(acc[dd][0], l); acc[dd][1] = Math.max(acc[dd][1], r); } else acc.push([l, r]);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
var mid = (pos[0] + pos[pos.length - 1]) / 2;
|
|
206
|
+
ks.forEach(function(c, i){ c.off = pos[i] - mid; });
|
|
207
|
+
o.cont = [[-half, half]].concat(acc.map(function(a){ return [a[0] - mid, a[1] - mid]; }));
|
|
208
|
+
}
|
|
209
|
+
function breadth(gap){
|
|
210
|
+
lay(pl.root, gap);
|
|
211
|
+
var lo = Infinity, hi = -Infinity;
|
|
212
|
+
pl.root.cont.forEach(function(a){ lo = Math.min(lo, a[0]); hi = Math.max(hi, a[1]); });
|
|
213
|
+
return {lo: lo, hi: hi, span: hi - lo};
|
|
214
|
+
}
|
|
215
|
+
// 深さの向きの段ごとの幅(2 段に並べた子のある段は、奥の段の分だけ広い)
|
|
216
|
+
function depthSum(){
|
|
217
|
+
var ext = [], r2 = [], rowOff = [];
|
|
218
|
+
pl.nodes.forEach(function(o){ if (o.row) r2[o.depth] = Math.max(r2[o.depth] || 0, o.fd); else ext[o.depth] = Math.max(ext[o.depth] || 0, o.fd); });
|
|
219
|
+
r2.forEach(function(e, d){ rowOff[d] = (ext[d] || 0) + RG; ext[d] = rowOff[d] + e; });
|
|
220
|
+
return {ext: ext, rowOff: rowOff, sum: ext.reduce(function(a, b){ return a + b; }, 0)};
|
|
221
|
+
}
|
|
222
|
+
var B = right ? H : W, DA = (right ? W : H) - edgeRoom - pnRoom;
|
|
223
|
+
var gmin = right ? 14 : 22, gmax = right ? 30 : 64, lgmin = right ? 56 : 40, lgmax = right ? 110 : 90;
|
|
224
|
+
// 枝の名前があれば、段の間に名前の入る長さをとる(right:線の上に横書き、down:線の横)
|
|
225
|
+
if (brs.length){ lgmin = Math.max(lgmin, right ? brW + 52 : 76); lgmax = Math.max(lgmax, lgmin); }
|
|
226
|
+
// 入れ方を順に試す:字を 27 → 24 px、それでも入らなければ 24 px のまま、葉だけの子の多い親から順に子を 2 段にし、
|
|
227
|
+
// さらに名前を 2 行に折る。字は 24 px より小さくしない(docs/conventions.md §2.3)。どれでも入らなければ、
|
|
228
|
+
// はみ出しのいちばん少ない形で描き、足りない px を ctx.report("size", …) で知らせる
|
|
229
|
+
var cands = P.link === "straight" || brs.length ? [] : pl.nodes.filter(function(o){ return o.kids.length >= 3 && o.kids.every(function(c){ return !c.kids.length; }); })
|
|
230
|
+
.sort(function(a, b){ return b.kids.length - a.kids.length; });
|
|
231
|
+
var sizes = P.size ? [P.size] : [27, 26, 25, 24], s24 = sizes[sizes.length - 1], tries = [], cfg = null, best = null, nf;
|
|
232
|
+
sizes.forEach(function(z){ tries.push([z, false, 0]); });
|
|
233
|
+
for (nf = 1; nf <= cands.length; nf++) tries.push([s24, false, nf]);
|
|
234
|
+
for (nf = 0; nf <= cands.length; nf++) tries.push([s24, true, nf]);
|
|
235
|
+
var setup = function(t){
|
|
236
|
+
wrapOn = t[1];
|
|
237
|
+
pl.nodes.forEach(function(o){ o.fold = false; o.row = 0; });
|
|
238
|
+
cands.slice(0, t[2]).forEach(function(o){ o.fold = true; });
|
|
239
|
+
measure(t[0]);
|
|
240
|
+
var b = breadth(gmin), d = depthSum();
|
|
241
|
+
return [Math.max(0, b.span - B), Math.max(0, d.sum + (levels - 1) * lgmin - DA)];
|
|
242
|
+
};
|
|
243
|
+
for (var i = 0; i < tries.length && !cfg; i++){
|
|
244
|
+
var miss = setup(tries[i]);
|
|
245
|
+
if (!miss[0] && !miss[1]) cfg = tries[i];
|
|
246
|
+
else if (!best || miss[0] + miss[1] < best.m[0] + best.m[1]) best = {t: tries[i], m: miss};
|
|
247
|
+
}
|
|
248
|
+
var fit = !!cfg;
|
|
249
|
+
if (!fit){ cfg = best.t; ctx.report("size", "[tree] the tree does not fit at " + cfg[0] + " px; it overflows its box by " + Math.ceil(best.m[0]) + " px across and " + Math.ceil(best.m[1]) + " px along the levels (text is not made smaller). Split the tree, shorten the labels or make the element larger"); }
|
|
250
|
+
setup(cfg);
|
|
251
|
+
var s = cfg[0], br, ds;
|
|
252
|
+
// 並ぶ向きの間:入る範囲で広げる
|
|
253
|
+
var gap = gmin;
|
|
254
|
+
if (fit) for (var g = gmax; g > gmin; g -= 2){ if (breadth(g).span <= B){ gap = g; break; } }
|
|
255
|
+
br = breadth(gap); ds = depthSum();
|
|
256
|
+
var lgap = levels > 1 ? Math.max(lgmin, Math.min(lgmax, (DA - ds.sum) / (levels - 1))) : 0;
|
|
257
|
+
var totalD = ds.sum + (levels - 1) * lgap;
|
|
258
|
+
var lvStart = [], acc = 0;
|
|
259
|
+
ds.ext.forEach(function(e, d){ lvStart[d] = acc; acc += e + lgap; });
|
|
260
|
+
// 絶対位置(b:並ぶ向きの中心、d0:その段の始まり)。入らないときは並ぶ向きに中央(両側へ同じだけはみ出す)、深さの向きは端から
|
|
261
|
+
(function place(o, b){ o.b = b; o.kids.forEach(function(c){ place(c, b + c.off); }); })(pl.root, 0);
|
|
262
|
+
var oB = (B - br.span) / 2 - br.lo, oD = Math.max(0, (DA - totalD) / 2);
|
|
263
|
+
var tones = {term: ["var(--term)", "var(--term-tint)", "var(--fg)"], emph: ["var(--emph)", "var(--emph-tint)", "var(--emph)"]};
|
|
264
|
+
var toneOf = function(t){
|
|
265
|
+
if (tones[t]) return tones[t];
|
|
266
|
+
if (/^(muted|accent2|series-[1-4])$/.test(t || "")) return ["var(--" + t + ")", "var(--bg)", "var(--" + t + ")"];
|
|
267
|
+
return tones.term;
|
|
268
|
+
};
|
|
269
|
+
this.size = s;
|
|
270
|
+
// 箱
|
|
271
|
+
pl.nodes.forEach(function(o){
|
|
272
|
+
var n = o.n, c = toneOf(n.tone), b = o.b + oB, d0 = lvStart[o.depth] + oD + (o.row ? ds.rowOff[o.depth] : 0);
|
|
273
|
+
if (right){ o.x = d0; o.y = b - o.fb / 2; } else { o.x = b - o.w / 2; o.y = d0; }
|
|
274
|
+
o.cx = o.x + o.w / 2; o.cy = o.y + o.h / 2;
|
|
275
|
+
o.g = D.el("g", {opacity: 0}, gN);
|
|
276
|
+
D.el("rect", {class: "box", x: o.x.toFixed(1), y: o.y.toFixed(1), width: o.w.toFixed(1), height: o.h.toFixed(1), rx: 10, fill: c[1], stroke: c[0], "stroke-width": n.tone === "emph" ? 3 : 2.2}, o.g);
|
|
277
|
+
if (n.tex) MR.texFrame(o.g, o.cx, o.cy + s * 0.36, n, "tex", {size: s, anchor: "middle", color: c[2], w: o.w, h: o.h}, sk).firstChild.style.verticalAlign = "top";
|
|
278
|
+
else {
|
|
279
|
+
var ys = lineYs(o.lines, s * 1.25, s), y0 = o.cy - ys[ys.length - 1] / 2 + s * 0.36 + (ys.top - ys.bottom) / 2;
|
|
280
|
+
o.lines.forEach(function(t, j){ D.mtext(o.g, o.cx, y0 + ys[j], t, {"text-anchor": "middle", "font-size": s, fill: c[2]}); });
|
|
281
|
+
}
|
|
282
|
+
o.notes.forEach(function(t, j){
|
|
283
|
+
var ny = o.y + o.h + 4 + NLH * j + NS * 0.95;
|
|
284
|
+
D.mtext(o.g, right ? o.x + 2 : o.cx, ny, t, {"text-anchor": right ? "start" : "middle", "font-size": NS, fill: "var(--muted)"});
|
|
285
|
+
});
|
|
286
|
+
// 線が付く点:入る点(親からの線の終わり)と出る点(子への線の始まり)
|
|
287
|
+
o.inP = right ? [o.x, o.cy] : [o.cx, o.y];
|
|
288
|
+
o.outP = right ? [o.x + o.w, o.cy] : [o.cx, o.y + o.h + o.nh];
|
|
289
|
+
});
|
|
290
|
+
// 親子の線。o.dir:親の中心から箱の中心への向き(draw と grow で箱が寄ってくる向き)
|
|
291
|
+
// 枝の名前があれば、かぎの曲がり角を親の側に寄せ(20 px)、子へ入る線を長くしてそこに名前を添える
|
|
292
|
+
var bo = brs.length ? Math.min(lgap / 2, 20) : lgap / 2, gB = brs.length ? D.el("g", {}) : null;
|
|
293
|
+
pl.nodes.forEach(function(o){
|
|
294
|
+
if (!o.par){ o.dir = [0, 1]; return; }
|
|
295
|
+
var dx = o.cx - o.par.cx, dy = o.cy - o.par.cy, dl = Math.hypot(dx, dy) || 1;
|
|
296
|
+
o.dir = [dx / dl, dy / dl];
|
|
297
|
+
var p = o.par, a = p.outP, z = o.inP, pts;
|
|
298
|
+
if (P.link === "straight") pts = [a, z];
|
|
299
|
+
else if (right){ var bx = lvStart[p.depth] + oD + ds.ext[p.depth] + bo; pts = [a, [bx, a[1]], [bx, z[1]], z]; }
|
|
300
|
+
else { var by = lvStart[p.depth] + oD + ds.ext[p.depth] + bo; pts = [a, [a[0], by], [z[0], by], z]; }
|
|
301
|
+
o.path = self.poly(pts);
|
|
302
|
+
if (o.brw){
|
|
303
|
+
// 名前は子へ入る線に添え、線とほかの名前を避ける。right:線の上、down:線の外側(親から離れる側)の横
|
|
304
|
+
var sd = o.cx < p.cx - 0.5 ? -1 : 1, lx, ly, an, q = pts[pts.length - 2];
|
|
305
|
+
if (P.link === "straight"){
|
|
306
|
+
var mx = (a[0] + z[0]) / 2, my = (a[1] + z[1]) / 2, ddx = z[0] - a[0], ddy = z[1] - a[1];
|
|
307
|
+
if (right){ var sl = Math.abs(ddy / (ddx || 1)) * o.brw / 2; lx = mx; an = "middle"; ly = ddy <= 0 ? my - sl - 12 : my + sl + 27; }
|
|
308
|
+
else { lx = mx + sd * (10 + 14 * Math.abs(ddx / (ddy || 1))); ly = my + 8; an = sd > 0 ? "start" : "end"; }
|
|
309
|
+
} else if (right){ lx = (q[0] + z[0]) / 2; ly = z[1] - 9; an = "middle"; }
|
|
310
|
+
else { lx = z[0] + sd * 10; ly = (q[1] + z[1]) / 2 + 8; an = sd > 0 ? "start" : "end"; }
|
|
311
|
+
o.blab = D.mtext(gB, lx.toFixed(1), ly.toFixed(1), String(o.n.branch), {"text-anchor": an, "font-size": 24, fill: "var(--fg)", opacity: 0});
|
|
312
|
+
}
|
|
313
|
+
o.line = D.el("path", {d: "", fill: "none", stroke: "var(--muted)", "stroke-width": 3, "stroke-linejoin": "round"}, gL);
|
|
314
|
+
});
|
|
315
|
+
// そのほかのつながり:外側(down は下、right は右)にふくらむ破線の曲線
|
|
316
|
+
var depthEnd = oD + totalD;
|
|
317
|
+
this.edges = pl.edges.map(function(x){
|
|
318
|
+
var e = x.e, a = x.a, b = x.b;
|
|
319
|
+
var pa = right ? [a.x + a.fd, a.cy] : [a.cx, a.y + a.fd], pb = right ? [b.x + b.fd, b.cy] : [b.cx, b.y + b.fd];
|
|
320
|
+
var sg = right ? (b.cy > a.cy ? 1 : -1) : (b.cx > a.cx ? 1 : -1), q = Math.min(18, (right ? a.fb : a.w) / 4);
|
|
321
|
+
if (right){ pa = [pa[0] + 6, pa[1] + sg * q]; pb = [pb[0] + 10, pb[1] - sg * q]; } else { pa = [pa[0] + sg * q, pa[1] + 6]; pb = [pb[0] - sg * q, pb[1] + 10]; }
|
|
322
|
+
var far = Math.max(right ? pa[0] : pa[1], right ? pb[0] : pb[1]) + 44;
|
|
323
|
+
var mid = [(pa[0] + pb[0]) / 2, (pa[1] + pb[1]) / 2], ctl = right ? [2 * far - mid[0], mid[1]] : [mid[0], 2 * far - mid[1]];
|
|
324
|
+
// 頂点が far になるように制御点を置く(2 次ベジェの中点 = (端の中点 + 制御点) / 2)
|
|
325
|
+
var pts = [];
|
|
326
|
+
for (var j = 0; j <= 24; j++){
|
|
327
|
+
var u = j / 24, v = 1 - u;
|
|
328
|
+
pts.push([v * v * pa[0] + 2 * u * v * ctl[0] + u * u * pb[0], v * v * pa[1] + 2 * u * v * ctl[1] + u * u * pb[1]]);
|
|
329
|
+
}
|
|
330
|
+
var col = e.tone ? toneOf(e.tone)[0] : "var(--muted)";
|
|
331
|
+
var g = D.el("g", {opacity: 0}, gE);
|
|
332
|
+
var line = D.el("path", {d: "", fill: "none", stroke: col, "stroke-width": 3, "stroke-dasharray": e.dash === false ? "none" : "8 6"}, g);
|
|
333
|
+
var head = D.el("path", {d: "M0,0L-16,-7L-16,7Z", fill: col}, g);
|
|
334
|
+
var lab = e.label ? D.mtext(g, right ? far + 10 : (pa[0] + pb[0]) / 2, right ? mid[1] + 8 : far + 30, e.label,
|
|
335
|
+
{"text-anchor": right ? "start" : "middle", "font-size": 24, fill: col, opacity: 0}) : null;
|
|
336
|
+
depthEnd = Math.max(depthEnd, far);
|
|
337
|
+
var after = 0;
|
|
338
|
+
[a, b].forEach(function(o){ if (o.step === x.step) after = Math.max(after, o.at + self.span()); });
|
|
339
|
+
return {g: g, line: line, head: head, lab: lab, path: self.poly(pts), step: x.step, at: e.at !== undefined ? e.at : after};
|
|
340
|
+
});
|
|
341
|
+
if (gB) root.appendChild(gB);
|
|
342
|
+
// 強調する道:線の上に --emph の太い線を引き、箱を --emph の枠で囲む。終わりの箱の外に pathNote
|
|
343
|
+
if (pl.path){
|
|
344
|
+
var gPL = D.el("g", {}), gPF = D.el("g", {});
|
|
345
|
+
root.insertBefore(gPL, gE); root.appendChild(gPF);
|
|
346
|
+
var frame = function(o){ return D.el("rect", {x: (o.x - 4).toFixed(1), y: (o.y - 4).toFixed(1), width: (o.w + 8).toFixed(1), height: (o.h + 8).toFixed(1), rx: 13, fill: "none", stroke: "var(--emph)", "stroke-width": 4, opacity: 0}, gPF); };
|
|
347
|
+
this.pathRoot = frame(pl.root);
|
|
348
|
+
this.pathEls = pl.path.links.map(function(x){
|
|
349
|
+
return {x: x, line: D.el("path", {d: "", fill: "none", stroke: "var(--emph)", "stroke-width": 6, "stroke-linejoin": "round", "stroke-linecap": "round", opacity: 0}, gPL), frame: frame(x.o)};
|
|
350
|
+
});
|
|
351
|
+
if (pnote){
|
|
352
|
+
var lf = pl.path.links[pl.path.links.length - 1].o;
|
|
353
|
+
this.pathNote = right ? D.mtext(gPF, (lf.x + Math.max(lf.w, lf.nw) + 16).toFixed(1), (lf.cy + s * 0.36).toFixed(1), pnote, {"text-anchor": "start", "font-size": s, fill: "var(--emph)", opacity: 0})
|
|
354
|
+
: D.mtext(gPF, lf.cx.toFixed(1), (lf.y + lf.h + lf.nh + 10 + s * 0.95).toFixed(1), pnote, {"text-anchor": "middle", "font-size": s, fill: "var(--emph)", opacity: 0});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// 形の一覧(render の終わりに形を作り直すため。下の render を見る)
|
|
358
|
+
this.shapes = [].slice.call(svg.querySelectorAll("rect,circle,ellipse,path,line,polyline,polygon"));
|
|
359
|
+
// 読み上げ:最後の形(すべての節、ほかのつながり、強調した道)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
360
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
361
|
+
this.setAttribute("role", "img");
|
|
362
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
|
|
363
|
+
sk.flush(); // what the formulas have to report, once per kind (spec §6.2)
|
|
364
|
+
}
|
|
365
|
+
// 最後の形を 1 文で(読み上げの名前):「木:動物。動物の下に 脊椎動物、無脊椎動物。脊椎動物の下に(はい)魚類、…。つながり:…。強調した道:動物 → 脊椎動物(…)」
|
|
366
|
+
summary(ja){
|
|
367
|
+
var pl = this.plan(), one = function(n){ return String(n.label || n.tex || "").replace(/\s*\n\s*/g, " ").replace(/\*/g, "").replace(/[_^](.)/g, "$1"); };
|
|
368
|
+
var lp = ja ? "(" : " (", rp = ja ? ")" : ")", cm = ja ? "、" : ", ", dot = ja ? "。" : ". ";
|
|
369
|
+
var full = function(n){ return one(n) + (n.note ? lp + n.note + rp : ""); };
|
|
370
|
+
var s = (ja ? "木:" : "Tree: ") + full(pl.root.n);
|
|
371
|
+
pl.order.forEach(function(o){
|
|
372
|
+
if (!o.kids.length) return;
|
|
373
|
+
s += dot + (ja ? one(o.n) + "の下に " : "Under " + one(o.n) + ": ") + o.kids.map(function(c){ return (c.n.branch ? (ja ? "(" + c.n.branch + ")" : "(" + c.n.branch + ") ") : "") + full(c.n); }).join(cm);
|
|
374
|
+
});
|
|
375
|
+
var ed = pl.edges.map(function(x){ return one(x.a.n) + " → " + one(x.b.n) + (x.e.label ? lp + x.e.label + rp : ""); });
|
|
376
|
+
if (ed.length) s += dot + (ja ? "つながり:" : "Links: ") + ed.join(cm);
|
|
377
|
+
if (pl.path) s += dot + (ja ? "強調した道:" : "Highlighted path: ") + pl.path.nodes.map(function(o){ return one(o.n); }).join(" → ") + (pl.path.note ? lp + pl.path.note + rp : "");
|
|
378
|
+
return s;
|
|
379
|
+
}
|
|
380
|
+
// 箱 1 つの動きの長さ(どの見せ方でも同じ):箱が現れて線を引き終わるまで
|
|
381
|
+
span(){ return this.props.fade * 0.6 + this.props.draw; }
|
|
382
|
+
// 折れ線:点と累積の長さ
|
|
383
|
+
poly(pts){
|
|
384
|
+
var L = [0];
|
|
385
|
+
for (var i = 1; i < pts.length; i++) L.push(L[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
|
|
386
|
+
return {pts: pts, L: L, len: L[L.length - 1] || 1};
|
|
387
|
+
}
|
|
388
|
+
// 折れ線の始めから割合 f までの部分:{d, end, ang}
|
|
389
|
+
part(pl, f){
|
|
390
|
+
var want = pl.len * Math.max(0, Math.min(1, f)), pts = pl.pts, out = [pts[0]], i = 1;
|
|
391
|
+
for (; i < pts.length && pl.L[i] <= want; i++) out.push(pts[i]);
|
|
392
|
+
var end = out[out.length - 1];
|
|
393
|
+
if (i < pts.length && want > pl.L[i - 1]){
|
|
394
|
+
var u = (want - pl.L[i - 1]) / (pl.L[i] - pl.L[i - 1]);
|
|
395
|
+
end = [base.lerp(pts[i - 1][0], pts[i][0], u), base.lerp(pts[i - 1][1], pts[i][1], u)];
|
|
396
|
+
out.push(end);
|
|
397
|
+
}
|
|
398
|
+
var pv = out.length > 1 ? out[out.length - 2] : pts[0], nx = i < pts.length ? pts[i] : end;
|
|
399
|
+
var ang = Math.atan2(end[1] - pv[1], end[0] - pv[0]);
|
|
400
|
+
if (out.length < 2) ang = Math.atan2(nx[1] - end[1], nx[0] - end[0]);
|
|
401
|
+
return {d: "M" + out.map(function(p){ return p[0].toFixed(1) + "," + p[1].toFixed(1); }).join("L"), end: end, ang: ang};
|
|
402
|
+
}
|
|
403
|
+
duration(k){
|
|
404
|
+
var self = this, d = 0, pl = this.plan();
|
|
405
|
+
pl.nodes.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + (o.par ? self.span() : self.props.fade)); });
|
|
406
|
+
(this.edges || []).forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + self.props.draw + (o.lab ? 0.3 : 0)); });
|
|
407
|
+
if (pl.path){
|
|
408
|
+
var P = this.props, ls = pl.path.links, z = ls[ls.length - 1];
|
|
409
|
+
ls.forEach(function(x){ if (x.step === k) d = Math.max(d, x.at + Math.max(P.draw, P.draw * 0.8 + P.fade * 0.6)); });
|
|
410
|
+
if (pl.path.note && z.step === k) d = Math.max(d, z.at + P.draw + 0.4);
|
|
411
|
+
}
|
|
412
|
+
return d;
|
|
413
|
+
}
|
|
414
|
+
render(k, t, ctx){
|
|
415
|
+
var P = this.props, D = base, self = this, vr = this.variant, lect = !!ctx.preview, S = this.span(), FAINT = 0.45;
|
|
416
|
+
if (lect) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
417
|
+
// 段階 step の要素の、その段階の中の時刻(-1 = まだ、Infinity = 済み)
|
|
418
|
+
var tOf = function(step){ return step < k ? Infinity : step > k ? -1 : t; };
|
|
419
|
+
var pr = function(tt, at, dur){ return tt < 0 ? 0 : D.prog(tt, at, dur); };
|
|
420
|
+
// 箱の動きは 12 px まで(docs/conventions.md §1.2:どの見せ方も fade より遠くへ動かさない)
|
|
421
|
+
var OFF = 12;
|
|
422
|
+
this.plan().nodes.forEach(function(o){
|
|
423
|
+
var tt = tOf(o.step), eb, el, sc = 1, m, sh;
|
|
424
|
+
if (!o.par || vr === "fade"){
|
|
425
|
+
// fade:箱が下から 12 px 上がりながら現れ(0.92 → 1)、それから線を引く
|
|
426
|
+
eb = pr(tt, o.at, P.fade); el = pr(tt, o.at + P.fade * 0.6, P.draw); sc = D.lerp(0.92, 1, eb); sh = [0, OFF * (1 - eb)];
|
|
427
|
+
} else if (vr === "draw"){
|
|
428
|
+
// draw:線を先に引き、その先に箱が親の側から 12 px 寄りながら現れる
|
|
429
|
+
el = pr(tt, o.at, S * 0.5); eb = pr(tt, o.at + S * 0.45, S * 0.55); sc = D.lerp(0.92, 1, eb);
|
|
430
|
+
sh = [-o.dir[0] * OFF * (1 - eb), -o.dir[1] * OFF * (1 - eb)];
|
|
431
|
+
} else {
|
|
432
|
+
// grow:箱が親の側から 12 px 寄りながら 0.92 → 1 に大きくなる。線は同時に親から引く
|
|
433
|
+
m = pr(tt, o.at, P.fade); eb = pr(tt, o.at, P.fade * 0.6); el = pr(tt, o.at, S); sc = D.lerp(0.92, 1, m);
|
|
434
|
+
sh = [-o.dir[0] * OFF * (1 - m), -o.dir[1] * OFF * (1 - m)];
|
|
435
|
+
}
|
|
436
|
+
if (lect){
|
|
437
|
+
// 授業の表示:後の段階は薄く、今の段階は薄い状態から濃くなる(位置は動かさない。どの見せ方でも同じ)
|
|
438
|
+
var f = tt < 0 ? FAINT : FAINT + (1 - FAINT) * eb;
|
|
439
|
+
o.g.setAttribute("opacity", f.toFixed(3)); o.g.setAttribute("transform", "");
|
|
440
|
+
if (o.line){ o.line.setAttribute("d", self.part(o.path, 1).d); o.line.setAttribute("opacity", f.toFixed(3)); }
|
|
441
|
+
if (o.blab) o.blab.setAttribute("opacity", f.toFixed(3));
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
o.g.setAttribute("opacity", eb.toFixed(3));
|
|
445
|
+
o.g.setAttribute("transform", sc >= 1 && Math.abs(sh[0]) < 0.01 && Math.abs(sh[1]) < 0.01 ? "" :
|
|
446
|
+
"translate(" + (o.cx + sh[0]).toFixed(2) + " " + (o.cy + sh[1]).toFixed(2) + ") scale(" + sc.toFixed(4) + ") translate(" + (-o.cx).toFixed(2) + " " + (-o.cy).toFixed(2) + ")");
|
|
447
|
+
if (o.line){ o.line.setAttribute("d", el > 0 ? self.part(o.path, el).d : ""); o.line.setAttribute("opacity", el > 0 ? 1 : 0); }
|
|
448
|
+
if (o.blab) o.blab.setAttribute("opacity", Math.max(0, Math.min(1, el * 2 - 1)).toFixed(3));
|
|
449
|
+
});
|
|
450
|
+
// 強調する道:線を親から引き、届いたら箱の枠と枝の名前を --emph に。授業の表示では後の段階を薄く、全部引いた形で
|
|
451
|
+
if (this.pathEls){
|
|
452
|
+
var pth = this.plan().path, lit = function(tt, v){ return lect ? (tt < 0 ? FAINT : FAINT + (1 - FAINT) * v) : v; };
|
|
453
|
+
this.pathEls.forEach(function(e, i){
|
|
454
|
+
var x = e.x, tt = tOf(x.step), l = pr(tt, x.at, P.draw), f = pr(tt, x.at + P.draw * 0.8, P.fade * 0.6);
|
|
455
|
+
e.line.setAttribute("d", lect || l > 0 ? self.part(x.o.path, lect ? 1 : l).d : "");
|
|
456
|
+
e.line.setAttribute("opacity", lit(tt, l > 0 ? 1 : 0).toFixed(3));
|
|
457
|
+
e.frame.setAttribute("opacity", lit(tt, f).toFixed(3));
|
|
458
|
+
if (x.o.blab) x.o.blab.setAttribute("style", "fill:" + (l >= 1 ? "var(--emph)" : "var(--fg)") + ";");
|
|
459
|
+
if (!i){ var r = pr(tt, x.at, P.fade * 0.6); self.pathRoot.setAttribute("opacity", lit(tt, r).toFixed(3)); }
|
|
460
|
+
});
|
|
461
|
+
if (this.pathNote){ var z = pth.links[pth.links.length - 1], zt = tOf(z.step); this.pathNote.setAttribute("opacity", lit(zt, pr(zt, z.at + P.draw, 0.4)).toFixed(3)); }
|
|
462
|
+
}
|
|
463
|
+
this.edges.forEach(function(o){
|
|
464
|
+
var tt = tOf(o.step), e = pr(tt, o.at, P.draw), lo = pr(tt, o.at + P.draw * 0.8, 0.3);
|
|
465
|
+
if (lect){ var f = tt < 0 ? FAINT : FAINT + (1 - FAINT) * e; e = 1; lo = 1; o.g.setAttribute("opacity", f.toFixed(3)); }
|
|
466
|
+
else o.g.setAttribute("opacity", e > 0 ? 1 : 0);
|
|
467
|
+
var p = self.part(o.path, e);
|
|
468
|
+
o.line.setAttribute("d", e > 0 ? p.d : "");
|
|
469
|
+
// 矢じりは線が 20px 伸びるまでに大きくなる
|
|
470
|
+
var hs = Math.min(1, e * o.path.len / 20);
|
|
471
|
+
o.head.setAttribute("transform", "translate(" + p.end[0].toFixed(2) + " " + p.end[1].toFixed(2) + ") rotate(" + (p.ang * 180 / Math.PI).toFixed(2) + ") scale(" + hs.toFixed(4) + ")");
|
|
472
|
+
if (o.lab) o.lab.setAttribute("opacity", lo.toFixed(3));
|
|
473
|
+
});
|
|
474
|
+
// 形を作り直す(同じ値を書き直すだけで、DOM は変わらない)。Chrome は、変わっていない形を近くの変化のために塗り直す(ラスタライズし直す)と、
|
|
475
|
+
// 2 回目からその形の輪郭(曲線の縁)を別の方法で描き、縁の画素が数十個変わる(ソフトウェアの GPU、CI の Linux・Windows)。
|
|
476
|
+
// 何回塗り直されたかは呼び出しの間にコマが描かれたかで決まるので、作り直さないと同じ (k, t) でも呼び出しの順と時刻で画素が変わる(docs/contract.md §3)
|
|
477
|
+
this.shapes.forEach(function(e){ var a = SHAPE_GEOM[e.localName], v = e.getAttribute(a); if (v !== null) e.setAttribute(a, v); });
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
return Part;
|
|
481
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Fishbone (cause-and-effect) diagram, one main bone at a time, head last; auto layout
|
|
3
|
+
steps: bones + 1 (head), or the largest step
|
|
4
|
+
props:
|
|
5
|
+
order: causes-first (default) or effect-first
|
|
6
|
+
size: box text px (0 = 27, shrink to 24)
|
|
7
|
+
fade: box appear (s)
|
|
8
|
+
draw: line draw (s)
|
|
9
|
+
example: {"effect": {"label": "Late delivery"}, "nodes": [{"id": "p", "label": "People"}, {"id": "p1", "label": "Short-staffed", "parent": "p"}, {"id": "m", "label": "Machines"}, {"id": "m1", "label": "Truck breakdown", "parent": "m"}]}
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Grouped causes of one effect (e.g. 4M: people, machines, methods, materials). No coordinates.
|
|
13
|
+
|
|
14
|
+
Child JSON: `{"effect": {...}, "nodes": [...], "edges": [...]}` (`edges` optional).
|
|
15
|
+
|
|
16
|
+
- effect (head): `label` (`\n`) or `tex`, `note` (under box), `tone` (default `emph`), `step`, `at`
|
|
17
|
+
- node: `id`, `label` (or `tex`), `note`, `parent`, `tone`, `step`, `at`. No `parent` = main bone; child = cause; grandchild = sub-cause (3 levels)
|
|
18
|
+
- Bones in array order, left to right, top/bottom alternating; name boxed at the outer end (`note` outside)
|
|
19
|
+
- Cause `tex` = KaTeX; `note` small after the name (`--muted`)
|
|
20
|
+
- `tone`: bone = box and bone; cause = text and line (`emph` bold)
|
|
21
|
+
- edge: extra cause links (`from` `to` `label` `tone` `dash` `step`), dashed arrow bulging left of text; best within one bone
|
|
22
|
+
- `order`: `causes-first` or `effect-first` (head, spine first); node `step` wins
|
|
23
|
+
- `variant`: `fade` (default), `draw` (lines first), `grow` (boxes grow in); moves ≤ 12 px
|
|
24
|
+
- Fit (1280×720 body, ~440 px high): ≤ 3 rows (causes + sub-causes) per bone (4 if short), 4–6 bones, causes ≤ ~10 chars. Text ≥ 24 px; overflow spills and is reported. Too many: split or shorten
|
|
25
|
+
|
|
26
|
+
The demo is `demo.html` (delivery example fictional).
|
|
27
|
+
|
|
28
|
+
<!-- llm: omit -->
|
|
29
|
+
Notes
|
|
30
|
+
|
|
31
|
+
- Causes on lines off the bone; sub-causes off a drop from the cause line. `emph` box: `--emph-tint` fill, `--emph` frame/text. Bones 3.5 px, cause lines 2.5
|
|
32
|
+
- Moves within `fade` time. Lecture view (`ctx.preview`): later bones faint
|
|
33
|
+
- `fade`: boxes and text rise 12 px, then lines. `draw`: lines, then boxes slide 12 px from the spine side. `grow`: category boxes slide 12 px and grow from 0.92×; cause text slides from the bone; lines drawn together. Moves measured at box centre (conventions §1.2)
|
|
34
|
+
- Text 27 → 24 px; row height (52 → 40 px) and bone slope chosen to fit. Cause width estimated from characters (`tex`: non-symbol characters × 0.62). If 24 px won't fit: no smaller text (conventions §2.3), bones close to 12 px, least-overflow layout centred, shortfall via `ctx.report("size", …)`
|
|
35
|
+
- Spine 5 px (the only thick line); others ~3 px; all `--muted` (`--line` is for axes, ticks, grids)
|
|
36
|
+
- Edges are not in the layout (need room left of the text); linking causes on different bones may pass near other text
|
|
37
|
+
<!-- llm: end -->
|