egatari 0.6.6 → 0.6.7
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 +92 -1
- 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,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 -->
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// m-fishbone:原因と結果の図(特性要因図・フィッシュボーン図)を、骨 1 本ずつ組み立てる
|
|
2
|
+
// <m-fishbone style="height:450px"><script type="application/json">
|
|
3
|
+
// {"effect": {"label": "配送の遅れ"},
|
|
4
|
+
// "nodes": [{"id": "p", "label": "人"}, {"id": "p1", "label": "人手が足りない", "parent": "p"}, …]}
|
|
5
|
+
// (JSON の終わり)</m-fishbone>
|
|
6
|
+
// 座標は書かない(docs/conventions.md §2)。parent のない節が大骨(分類:人・機械・方法・材料など)、その子が原因(中骨)、孫が細かい原因(小骨)。3 段まで
|
|
7
|
+
// 頭(結果の箱)は右、背骨は横。大骨は上下に交互に、斜めに付く。原因は大骨に付く横の線の上に書き、細かい原因は原因の線から大骨と平行に下ろした線に付ける
|
|
8
|
+
// 段階:order="causes-first"(既定:大骨 1 本ずつ(その原因と一緒に)、最後に頭)か order="effect-first"(頭と背骨、それから大骨 1 本ずつ)。節の step が勝つ
|
|
9
|
+
// edges:原因どうしなど、ほかのつながり(破線、矢印つき)。段階は両端の遅いほう
|
|
10
|
+
// 字の大きさは要素の大きさから決め(27 px から)、入らなければ 24 px まで縮める。それでも入らなければ、字は 24 px のまま
|
|
11
|
+
// 大骨の間を詰め、要素の箱からはみ出して ctx.report("size", …)(足りない px)
|
|
12
|
+
// 見せ方(docs/conventions.md §2.5):fade(箱と字が下から 12 px 上がりながら現れてから線を引く、既定)・draw(線を先に引き、
|
|
13
|
+
// その先に箱と字が現れる)・grow(分類の箱が背骨の側から 12 px 寄りながら 0.92 → 1 に、原因の字が大骨の側から 12 px 寄って出る)。
|
|
14
|
+
// 箱と字の動きはどれも 12 px まで。段階の数・長さ・最後の中身はどれも同じ
|
|
15
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
16
|
+
// 式(tex)は組み立てのときに KaTeX で描く(spec §6.2):build.fields の effect.tex・nodes[].tex を作り手が描いて texHtml を足し、
|
|
17
|
+
// この部品は markup-reader で決まった要素と属性だけを読んで置く(再生のときに KaTeX は動かない)。描いた結果がなければ tex を字のまま出して知らせる。
|
|
18
|
+
// 入らないときは ctx.report("size", "[fishbone] …") で知らせる(1.x の console.warn の代わり)
|
|
19
|
+
egatariParts.define({name: "fishbone", version: "2.0.2", requires: {base: "1.1.0", "markup-reader": "1.0.1"}, element: "m-fishbone"}, function(deps){
|
|
20
|
+
"use strict";
|
|
21
|
+
var base = deps.base, MR = deps["markup-reader"];
|
|
22
|
+
var Part = class extends base.MotionElement {
|
|
23
|
+
static partName = "fishbone"; // the registry name (define meta name), for report prefixes
|
|
24
|
+
// 組み立てのときに描く欄(spec §6.2)。式の意味は字(tex)でも持つので、KaTeX の出力は HTML だけ
|
|
25
|
+
static build = {fields: {"effect.tex": "katex", "nodes[].tex": "katex"}, options: {katex: {output: "html"}}};
|
|
26
|
+
static variants = ["fade", "draw", "grow"];
|
|
27
|
+
// データの形(kit/shape.js)
|
|
28
|
+
static shape = {
|
|
29
|
+
schema: {type: "object", additionalProperties: false, required: ["effect", "nodes"], properties: {
|
|
30
|
+
effect: {type: "object", properties: {label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, note: {type: "string"}, tone: {type: "string"}, step: {type: "integer"}, at: {type: "number"}}},
|
|
31
|
+
nodes: {type: "array", minItems: 1, items: {type: "object", required: ["id"], properties: {
|
|
32
|
+
id: {type: ["string", "integer"]}, label: {type: "string"}, tex: {type: "string"}, texHtml: {type: "string"}, note: {type: "string"}, tone: {type: "string"},
|
|
33
|
+
parent: {type: ["string", "integer"]}, step: {type: "integer"}, at: {type: "number"}}}},
|
|
34
|
+
edges: {type: "array", items: {type: "object", required: ["from", "to"], properties: {
|
|
35
|
+
from: {type: ["string", "integer"]}, to: {type: ["string", "integer"]}, label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"},
|
|
36
|
+
step: {type: "integer"}, at: {type: "number"}}}},
|
|
37
|
+
renderers: {type: "object"}}},
|
|
38
|
+
example: {effect: {label: "配送の遅れ"}, nodes: [{id: "p", label: "人"}, {id: "p1", label: "人手が足りない", parent: "p"}, {id: "m", label: "機械"}, {id: "m1", label: "車の故障", parent: "m"}]},
|
|
39
|
+
note: "parent のない節が大骨(分類)、その子が原因、孫が細かい原因(3 段まで)",
|
|
40
|
+
};
|
|
41
|
+
static props = {
|
|
42
|
+
order: {type: "string", default: "causes-first", doc: "段階の順:causes-first(大骨 1 本ずつ、最後に頭、既定)か effect-first(頭と背骨が先)"},
|
|
43
|
+
size: {type: "number", default: 0, doc: "箱の字の大きさ(px。0 = 27 から入るまで 24 まで縮める)"},
|
|
44
|
+
fade: {type: "number", default: 0.45, doc: "箱が現れる秒数"},
|
|
45
|
+
draw: {type: "number", default: 0.5, doc: "線を引く秒数"},
|
|
46
|
+
};
|
|
47
|
+
// 骨の形と段階(mount の前にも段階の数のために使う)
|
|
48
|
+
plan(){
|
|
49
|
+
if (this._plan) return this._plan;
|
|
50
|
+
var d = this.data || {}, P = this.props, byId = {}, cats = [], notes = this._notes = []; // データの問題:mount が ctx.report で知らせる
|
|
51
|
+
var nodes = (d.nodes || []).map(function(n){
|
|
52
|
+
var o = {n: n, kids: []};
|
|
53
|
+
if (byId[n.id]) notes.push("[fishbone] the id " + JSON.stringify(n.id) + " is used by more than one node (parent and edges refer to the last one; give each node its own id)");
|
|
54
|
+
byId[n.id] = o; return o;
|
|
55
|
+
});
|
|
56
|
+
nodes.forEach(function(o){
|
|
57
|
+
if (o.n.parent === undefined || o.n.parent === null) cats.push(o);
|
|
58
|
+
else if (!byId[o.n.parent]) throw new Error("m-fishbone: node " + JSON.stringify(o.n.id) + " has an unknown parent " + JSON.stringify(o.n.parent));
|
|
59
|
+
else byId[o.n.parent].kids.push(o);
|
|
60
|
+
});
|
|
61
|
+
if (!cats.length) throw new Error("m-fishbone: no main bone (a node without parent)");
|
|
62
|
+
var seen = 0;
|
|
63
|
+
cats.forEach(function(c){
|
|
64
|
+
(function walk(o, lv){
|
|
65
|
+
if (++seen > nodes.length) throw new Error("m-fishbone: the parents form a loop");
|
|
66
|
+
if (lv > 2) throw new Error("m-fishbone: " + JSON.stringify(o.n.id) + " is deeper than 3 levels (main bone, cause, sub-cause)");
|
|
67
|
+
o.lv = lv; o.kids.forEach(function(k){ k.par = o; walk(k, lv + 1); });
|
|
68
|
+
})(c, 0);
|
|
69
|
+
});
|
|
70
|
+
if (seen !== nodes.length) throw new Error("m-fishbone: the parents form a loop");
|
|
71
|
+
var ef = d.effect || {}, effFirst = P.order === "effect-first", n = cats.length;
|
|
72
|
+
var head = {n: ef, step: ef.step !== undefined ? ef.step : effFirst ? 1 : n + 1, at: ef.at || 0};
|
|
73
|
+
var spineStep = effFirst ? head.step : 1;
|
|
74
|
+
cats.forEach(function(c, i){
|
|
75
|
+
c.step = c.n.step !== undefined ? c.n.step : effFirst ? i + 2 : i + 1;
|
|
76
|
+
// 大骨の行:原因と、その下の細かい原因(上から下の順)
|
|
77
|
+
c.rows = [];
|
|
78
|
+
c.kids.forEach(function(k){ c.rows.push(k); k.kids.forEach(function(s){ c.rows.push(s); }); });
|
|
79
|
+
c.rows.forEach(function(r){ r.step = r.n.step !== undefined ? r.n.step : c.step; r.cat = c; });
|
|
80
|
+
});
|
|
81
|
+
var edges = (d.edges || []).map(function(e){
|
|
82
|
+
var a = byId[e.from], b = byId[e.to];
|
|
83
|
+
if (!a || !b) throw new Error("m-fishbone: edge to an unknown node " + JSON.stringify(a ? e.to : e.from));
|
|
84
|
+
return {e: e, a: a, b: b, step: e.step !== undefined ? e.step : Math.max(a.step, b.step)};
|
|
85
|
+
});
|
|
86
|
+
return (this._plan = {cats: cats, nodes: nodes, head: head, spineStep: spineStep, edges: edges, byId: byId});
|
|
87
|
+
}
|
|
88
|
+
get steps(){
|
|
89
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
90
|
+
var p = this.plan(), m = Math.max(p.head.step, p.spineStep);
|
|
91
|
+
p.nodes.concat(p.edges).forEach(function(o){ m = Math.max(m, o.step); });
|
|
92
|
+
return m;
|
|
93
|
+
}
|
|
94
|
+
// 1 つのものが現れて線を引き終わるまで(どの見せ方でも同じ)
|
|
95
|
+
span(){ return this.props.fade * 0.6 + this.props.draw; }
|
|
96
|
+
mount(ctx){
|
|
97
|
+
var P = this.props, D = base, self = this, pl = this.plan(), sk = MR.sink(this, ctx);
|
|
98
|
+
this._notes.forEach(function(m){ ctx.report("data", m); });
|
|
99
|
+
this.variant = base.variant(this);
|
|
100
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
101
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
102
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
103
|
+
var root = D.el("g", {}, svg), gL = D.el("g", {}, root), gT = D.el("g", {}, root), gE = D.el("g", {}, root), gN = D.el("g", {}, root);
|
|
104
|
+
// 字の幅の見積もり(字の大きさ 1 あたり。base の textWidth:テーマの字で測った幅。*斜体* などの記号は数えない)
|
|
105
|
+
var est = function(s){ return D.textWidth(s, 1, {font: self, mark: true}); };
|
|
106
|
+
var texEst = function(s){ return Math.max(1, String(s).replace(/\\[a-zA-Z]+/g, "x").replace(/[{}^_\\ ]/g, "").length) * 0.62; };
|
|
107
|
+
var tones = {term: ["var(--term)", "var(--term-tint)", "var(--fg)"], emph: ["var(--emph)", "var(--emph-tint)", "var(--emph)"]};
|
|
108
|
+
var toneOf = function(t, dflt){
|
|
109
|
+
if (tones[t]) return tones[t];
|
|
110
|
+
if (/^(muted|accent2|series-[1-4])$/.test(t || "")) return ["var(--" + t + ")", "var(--bg)", "var(--" + t + ")"];
|
|
111
|
+
return tones[dflt || "term"];
|
|
112
|
+
};
|
|
113
|
+
var NS = 24, NLH = 30, cats = pl.cats, nc = cats.length, cols = Math.ceil(nc / 2);
|
|
114
|
+
var R = Math.max(1, Math.max.apply(null, cats.map(function(c){ return c.rows.length; })));
|
|
115
|
+
var M1 = 12, M2 = 14, TXT = 31; // 箱と最初の行の間、最後の行と背骨の間、字の行の高さ(字の上端から線まで)
|
|
116
|
+
// 大きさ s、行の高さ rh、傾き k(縦 1 px あたりの横)で 1 本の大骨を局所座標(背骨に付く点が原点)で測る
|
|
117
|
+
function box(n, s){
|
|
118
|
+
var lines = n.tex ? [n.tex] : String(n.label || "").split("\n");
|
|
119
|
+
var tw = n.tex ? texEst(n.tex) * s : Math.max.apply(null, lines.map(est)) * s;
|
|
120
|
+
var notes = n.note ? String(n.note).split("\n") : [];
|
|
121
|
+
return {lines: lines, w: Math.max(s * 2.4, tw + s * 1.3), h: (n.tex ? s * 1.5 : lines.length * s * 1.25) + s * 0.75,
|
|
122
|
+
notes: notes, nw: notes.length ? Math.max.apply(null, notes.map(est)) * NS : 0, nh: notes.length ? notes.length * NLH + 4 : 0};
|
|
123
|
+
}
|
|
124
|
+
function boneGeom(c, i, s, rh, k){
|
|
125
|
+
var up = i % 2 === 0, sg = up ? -1 : 1, cs = Math.max(24, s - 1), ss = 24;
|
|
126
|
+
var Lv = R * rh + M1 + M2, g = {up: up, sg: sg, Lv: Lv, k: k, cs: cs};
|
|
127
|
+
g.b = box(c.n, s);
|
|
128
|
+
var xo = -Lv * k;
|
|
129
|
+
g.outer = [xo, sg * Lv];
|
|
130
|
+
g.boxX = xo - g.b.w / 2; g.boxY = up ? -Lv - g.b.h : Lv;
|
|
131
|
+
var xb = function(v){ return -v * k; };
|
|
132
|
+
var lo = Math.min(g.boxX, xo - g.b.nw / 2), hi = Math.max(0, g.boxX + g.b.w, xo + g.b.nw / 2);
|
|
133
|
+
g.rows = [];
|
|
134
|
+
c.rows.forEach(function(o, r){
|
|
135
|
+
// 行 r の横の線の、背骨からの縦の距離 v(上の骨は外から内へ、下の骨は内から外へ並ぶ)。字は線の上(画面で上)に書く
|
|
136
|
+
var v = up ? Lv - M1 - (r + 1) * rh + 6 : M2 + (r + 1) * rh - 6, y = sg * v, sz = o.lv === 1 ? cs : ss;
|
|
137
|
+
// 字の幅:tex は字数から見積もる。note は後ろに続けて小さく(--muted)書く
|
|
138
|
+
var nw = o.n.note ? est(" " + o.n.note) * NS : 0, tw = (o.n.tex ? texEst(o.n.tex) * sz : est(o.n.label || "") * sz) + nw, x0, xe, mini = null;
|
|
139
|
+
if (o.lv === 1){ x0 = xb(v); xe = Math.min(xb(v), xb(v - sg * TXT)) - 10; }
|
|
140
|
+
else {
|
|
141
|
+
// 細かい原因:親の原因の線から、大骨と平行な線を下ろした先に付く
|
|
142
|
+
var pr = g.rows[c.rows.indexOf(o.par)], xp = xb(pr.v) - (40 + 30 * k), py = pr.y;
|
|
143
|
+
var xm = function(yy){ return xp + (up ? 1 : -1) * k * (yy - py); };
|
|
144
|
+
x0 = xm(y); xe = Math.min(xm(y), xm(y - TXT)) - 10;
|
|
145
|
+
pr.miniEnd = Math.max(pr.miniEnd || 0, y - py);
|
|
146
|
+
pr.mini = {x0: xp, xm: xm};
|
|
147
|
+
}
|
|
148
|
+
var xl = xe - tw - 8;
|
|
149
|
+
lo = Math.min(lo, xl); hi = Math.max(hi, x0);
|
|
150
|
+
g.rows.push({o: o, v: v, y: y, x0: x0, xe: xe, xl: xl, tw: tw, nw: nw, sz: sz});
|
|
151
|
+
});
|
|
152
|
+
g.lo = lo; g.hi = hi;
|
|
153
|
+
g.ext = Lv + g.b.h + g.b.nh; // 背骨からの縦の広がり
|
|
154
|
+
return g;
|
|
155
|
+
}
|
|
156
|
+
function layout(s, rh, k, cgap){
|
|
157
|
+
var geo = cats.map(function(c, i){ return boneGeom(c, i, s, rh, k); });
|
|
158
|
+
var hb = box(pl.head.n, s), xs = [], x = 0;
|
|
159
|
+
for (var j = 0; j < cols; j++){
|
|
160
|
+
var a = geo[2 * j], b = geo[2 * j + 1], lo = Math.min(a.lo, b ? b.lo : 0), hi = Math.max(a.hi, b ? b.hi : 0);
|
|
161
|
+
x = j === 0 ? -lo : x + cgap - lo;
|
|
162
|
+
xs.push(x); x += hi;
|
|
163
|
+
}
|
|
164
|
+
var tail = Math.min(0, xs[0] + Math.min(geo[0].outer[0], geo[1] ? geo[1].outer[0] : 0) - 24);
|
|
165
|
+
var spineEnd = x + Math.max(36, cgap), width = spineEnd + hb.w - tail;
|
|
166
|
+
var ext = Math.max.apply(null, geo.map(function(g){ return g.ext; }));
|
|
167
|
+
var hh = Math.max(ext * 2, hb.h + 2 * hb.nh);
|
|
168
|
+
return {geo: geo, hb: hb, xs: xs, tail: tail, spineEnd: spineEnd, width: width, height: hh, ext: ext};
|
|
169
|
+
}
|
|
170
|
+
// 入る大きさを探す:字(27 → 24 px)、行の高さ(52 → 40 px)、傾き(0.5 → 0.3)
|
|
171
|
+
// size:24 より小さい字は使わない(24 にする)
|
|
172
|
+
var sz0 = P.size;
|
|
173
|
+
if (sz0 && sz0 < 24){ ctx.report("attr", "[fishbone] size=\"" + this.getAttribute("size") + "\" is below 24 (text is at least 24px; 24 is used)"); sz0 = 24; }
|
|
174
|
+
var sizes = sz0 ? [sz0] : [27, 26, 25, 24], L = null, fit = true;
|
|
175
|
+
search: for (var si = 0; si < sizes.length; si++){
|
|
176
|
+
for (var rh = 52; rh >= 40; rh -= 2){
|
|
177
|
+
for (var k = 0.5; k >= 0.29; k -= 0.1){
|
|
178
|
+
var t = layout(sizes[si], rh, k, 28);
|
|
179
|
+
if (t.width <= W && t.height <= H){ L = t; L.s = sizes[si]; L.rh = rh; L.k = k; break search; }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!L){
|
|
184
|
+
// 24 px でも入らない:字は小さくせず、大骨の間を 12 px まで詰め、はみ出しのいちばん少ない形にする(中央に置き、両側へ同じだけはみ出す)
|
|
185
|
+
fit = false;
|
|
186
|
+
var s24 = sizes[sizes.length - 1], miss = function(t){ return Math.max(0, t.width - W) + Math.max(0, t.height - H); };
|
|
187
|
+
for (var cg0 = 28; cg0 >= 12; cg0 -= 4){ var t0 = layout(s24, 40, 0.3, cg0); if (!L || miss(t0) < miss(L)) L = t0; }
|
|
188
|
+
L.s = s24; L.rh = 40; L.k = 0.3;
|
|
189
|
+
ctx.report("size", "[fishbone] the diagram does not fit at " + s24 + " px; it overflows its box by " + Math.ceil(Math.max(0, L.width - W)) + " px across and " +
|
|
190
|
+
Math.ceil(Math.max(0, L.height - H)) + " px up and down (text is not made smaller). Use fewer causes per bone, shorter causes or a larger element");
|
|
191
|
+
}
|
|
192
|
+
// 横に余れば、大骨の間を広げる(80 px まで)
|
|
193
|
+
if (fit) for (var cg = 80; cg > 28; cg -= 4){ var t2 = layout(L.s, L.rh, L.k, cg); if (t2.width <= W){ t2.s = L.s; t2.rh = L.rh; t2.k = L.k; L = t2; break; } }
|
|
194
|
+
var s = L.s, ox = (W - L.width) / 2 - L.tail, oy = H / 2;
|
|
195
|
+
this.size = s;
|
|
196
|
+
var X = function(x){ return ox + x; }, Y = function(y){ return oy + y; };
|
|
197
|
+
var mkLine = function(parent, w, col){ return D.el("path", {d: "", fill: "none", stroke: col || "var(--muted)", "stroke-width": w, "stroke-linecap": "round", "stroke-linejoin": "round"}, parent); };
|
|
198
|
+
var boxText = function(g, b, n, x, y, c, sz){
|
|
199
|
+
var cx = x + b.w / 2, cy = y + b.h / 2;
|
|
200
|
+
if (n.tex) MR.texFrame(g, cx, cy + sz * 0.36, n, "tex", {size: sz, anchor: "middle", color: c[2], w: b.w, h: b.h}, sk).firstChild.style.verticalAlign = "top";
|
|
201
|
+
else {
|
|
202
|
+
var lh = sz * 1.25, y0 = cy - (b.lines.length - 1) * lh / 2 + sz * 0.36;
|
|
203
|
+
b.lines.forEach(function(t, j){ D.mtext(g, cx, y0 + j * lh, t, {"text-anchor": "middle", "font-size": sz, fill: c[2]}); });
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
// 頭(結果)
|
|
207
|
+
var hb = L.hb, hx = X(L.spineEnd), hy = Y(0) - hb.h / 2, hc = toneOf(pl.head.n.tone, "emph");
|
|
208
|
+
var H0 = this.head = {o: pl.head, g: D.el("g", {opacity: 0}, gN), x: hx, y: hy, cx: hx + hb.w / 2, cy: Y(0), inP: [hx, Y(0)]};
|
|
209
|
+
D.el("rect", {class: "box", x: hx.toFixed(1), y: hy.toFixed(1), width: hb.w.toFixed(1), height: hb.h.toFixed(1), rx: 10, fill: hc[1], stroke: hc[0], "stroke-width": 3}, H0.g);
|
|
210
|
+
boxText(H0.g, hb, pl.head.n, hx, hy, hc, s);
|
|
211
|
+
hb.notes.forEach(function(t, j){ D.mtext(H0.g, hx + hb.w / 2, hy + hb.h + 4 + NLH * j + NS * 0.95, t, {"text-anchor": "middle", "font-size": NS, fill: "var(--muted)"}); });
|
|
212
|
+
// 背骨(尾から頭の手前まで)と矢じり
|
|
213
|
+
this.spine = {path: this.poly([[X(L.tail), Y(0)], [hx - 3, Y(0)]]), line: mkLine(gL, 5), step: pl.spineStep};
|
|
214
|
+
H0.arrow = D.el("path", {d: "M0,0L-16,-7L-16,7Z", fill: "var(--muted)", transform: "translate(" + (hx - 1).toFixed(1) + " " + Y(0).toFixed(1) + ")", opacity: 0}, gL);
|
|
215
|
+
// 大骨と原因
|
|
216
|
+
var cnt = {};
|
|
217
|
+
this.bones = cats.map(function(c, i){
|
|
218
|
+
var g = L.geo[i], bx = L.xs[Math.floor(i / 2)], col = c.n.tone ? toneOf(c.n.tone)[0] : "var(--muted)", cc = toneOf(c.n.tone);
|
|
219
|
+
var at = c.n.at !== undefined ? c.n.at : c.step === pl.spineStep && c.step !== pl.head.step ? P.draw * 0.8 : c.step === pl.head.step ? self.span() : 0;
|
|
220
|
+
var B = {o: c, step: c.step, at: at, g: D.el("g", {opacity: 0}, gN)};
|
|
221
|
+
// 大骨:背骨の点から外の端まで(path は外から背骨へ。fade と grow は外から引く、draw は背骨から引く)
|
|
222
|
+
B.spineP = [X(bx), Y(0)]; B.outP = [X(bx + g.outer[0]), Y(g.outer[1])];
|
|
223
|
+
B.path = self.poly([B.outP, B.spineP]); B.rpath = self.poly([B.spineP, B.outP]);
|
|
224
|
+
B.line = mkLine(gL, 3.5, col);
|
|
225
|
+
var x0 = X(bx + g.boxX), y0 = Y(g.boxY);
|
|
226
|
+
D.el("rect", {class: "box", x: x0.toFixed(1), y: y0.toFixed(1), width: g.b.w.toFixed(1), height: g.b.h.toFixed(1), rx: 10, fill: cc[1], stroke: cc[0], "stroke-width": c.n.tone === "emph" ? 3 : 2.2}, B.g);
|
|
227
|
+
boxText(B.g, g.b, c.n, x0, y0, cc, s);
|
|
228
|
+
g.b.notes.forEach(function(t, j){
|
|
229
|
+
var ny = g.up ? y0 - 8 - NLH * (g.b.notes.length - 1 - j) : y0 + g.b.h + 4 + NLH * j + NS * 0.95;
|
|
230
|
+
D.mtext(B.g, x0 + g.b.w / 2, ny, t, {"text-anchor": "middle", "font-size": NS, fill: "var(--muted)"});
|
|
231
|
+
});
|
|
232
|
+
B.cx = x0 + g.b.w / 2; B.cy = y0 + g.b.h / 2;
|
|
233
|
+
// 背骨の側から箱へ向かう向き(draw と grow で箱が寄ってくる向き)
|
|
234
|
+
var dx = B.cx - B.spineP[0], dy = B.cy - B.spineP[1], dl = Math.hypot(dx, dy) || 1;
|
|
235
|
+
B.dir = [dx / dl, dy / dl];
|
|
236
|
+
// 原因:横の線(大骨の点から左へ)と、その上の字
|
|
237
|
+
B.rows = g.rows.map(function(r, j){
|
|
238
|
+
var o = r.o, tc = o.n.tone ? toneOf(o.n.tone)[0] : "var(--fg)", lc = o.n.tone ? toneOf(o.n.tone)[0] : "var(--muted)";
|
|
239
|
+
var gr = D.el("g", {opacity: 0}, gT);
|
|
240
|
+
var y = Y(r.y), xa = X(bx + r.x0), xl = X(bx + r.xl);
|
|
241
|
+
var rec = {o: o, step: o.step, g: gr, path: self.poly([[xa, y], [xl, y]]), line: mkLine(gL, 2.5, lc)};
|
|
242
|
+
if (r.miniEnd){
|
|
243
|
+
// 細かい原因へ下ろす、大骨と平行な線(親の原因の行が持つ)
|
|
244
|
+
var p0 = [X(bx + r.mini.x0), y], p1 = [X(bx + r.mini.xm(r.y + r.miniEnd)), y + r.miniEnd];
|
|
245
|
+
rec.mpath = self.poly([p0, p1]); rec.mline = mkLine(gL, 2.5, lc);
|
|
246
|
+
}
|
|
247
|
+
var tx, xe = X(bx + r.xe);
|
|
248
|
+
if (o.n.tex){
|
|
249
|
+
// 式(組み立てのときに描いた KaTeX):箱と同じ枠(MR.texFrame)で、行の右端に寄せる。note はその右に別の字で
|
|
250
|
+
MR.texFrame(gr, xe - r.nw, y - 8, o.n, "tex", {size: r.sz, anchor: "end", color: tc, w: r.tw - r.nw + 40, h: r.sz * 1.6}, sk).firstChild.style.verticalAlign = "top";
|
|
251
|
+
if (o.n.note) D.mtext(gr, xe, y - 8, " " + o.n.note, {"text-anchor": "end", "font-size": NS, fill: "var(--muted)"});
|
|
252
|
+
} else {
|
|
253
|
+
tx = D.mtext(gr, xe, y - 8, o.n.label || "", {"text-anchor": "end", "font-size": r.sz, fill: tc});
|
|
254
|
+
if (o.n.tone === "emph") tx.setAttribute("font-weight", 700);
|
|
255
|
+
if (o.n.note){ var ns = D.el("tspan", {"font-size": NS, fill: "var(--muted)", "font-weight": 400}, tx); ns.textContent = " " + o.n.note; }
|
|
256
|
+
}
|
|
257
|
+
// 段階の中の開始時刻:同じ段階の行を上から順に少しずつずらす
|
|
258
|
+
var key = rec.step, base = rec.step === c.step ? at + self.span() * 0.8 : 0;
|
|
259
|
+
cnt[key + "|" + i] = (cnt[key + "|" + i] || 0) + 1;
|
|
260
|
+
rec.at = o.n.at !== undefined ? o.n.at : +(base + 0.12 * (cnt[key + "|" + i] - 1)).toFixed(3);
|
|
261
|
+
return rec;
|
|
262
|
+
});
|
|
263
|
+
return B;
|
|
264
|
+
});
|
|
265
|
+
// 細かい原因の平行の線は、細かい原因の行と同じ段階・時刻で引く(最初の子に合わせる)
|
|
266
|
+
this.bones.forEach(function(B){
|
|
267
|
+
B.rows.forEach(function(r){
|
|
268
|
+
if (!r.mpath) return;
|
|
269
|
+
var first = B.rows.filter(function(q){ return q.o.par === r.o; })[0];
|
|
270
|
+
r.mstep = first.step; r.mat = first.at;
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
// そのほかのつながり:字の左端どうしを、左へふくらむ破線で
|
|
274
|
+
var rowOf = {};
|
|
275
|
+
this.bones.forEach(function(B){ B.rows.forEach(function(r){ rowOf[r.o.n.id] = r; }); });
|
|
276
|
+
this.edges = pl.edges.map(function(x){
|
|
277
|
+
var e = x.e, ra = rowOf[e.from], rb = rowOf[e.to];
|
|
278
|
+
if (!ra || !rb) throw new Error("m-fishbone: edges connect causes (not main bones)");
|
|
279
|
+
var pa = [ra.path.pts[1][0] - 6, ra.path.pts[1][1]], pb = [rb.path.pts[1][0] - 10, rb.path.pts[1][1]];
|
|
280
|
+
var mid = [(pa[0] + pb[0]) / 2, (pa[1] + pb[1]) / 2], far = Math.min(pa[0], pb[0]) - 40, ctl = [2 * far - mid[0], mid[1]];
|
|
281
|
+
var pts = [];
|
|
282
|
+
for (var j = 0; j <= 24; j++){ var u = j / 24, v = 1 - u; 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]]); }
|
|
283
|
+
var col = e.tone ? toneOf(e.tone)[0] : "var(--muted)";
|
|
284
|
+
var g = D.el("g", {opacity: 0}, gE);
|
|
285
|
+
var line = D.el("path", {d: "", fill: "none", stroke: col, "stroke-width": 3, "stroke-dasharray": e.dash === false ? "none" : "8 6"}, g);
|
|
286
|
+
var head = D.el("path", {d: "M0,0L-16,-7L-16,7Z", fill: col}, g);
|
|
287
|
+
var lab = e.label ? D.mtext(g, far - 8, mid[1] + 8, e.label, {"text-anchor": "end", "font-size": 24, fill: col, opacity: 0}) : null;
|
|
288
|
+
var after = 0;
|
|
289
|
+
[ra, rb].forEach(function(r){ if (r.step === x.step) after = Math.max(after, r.at + 0.45); });
|
|
290
|
+
return {g: g, line: line, head: head, lab: lab, path: self.poly(pts), step: x.step, at: e.at !== undefined ? e.at : after};
|
|
291
|
+
});
|
|
292
|
+
// 読み上げ:最後の形(結果と、大骨ごとの原因)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
293
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
294
|
+
this.setAttribute("role", "img");
|
|
295
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
|
|
296
|
+
sk.flush(); // what the formulas have to report, once per kind (spec §6.2)
|
|
297
|
+
}
|
|
298
|
+
// 最後の形を 1 文で(読み上げの名前):「原因と結果の図。結果:配送の遅れ。人:人手が足りない(休みが多い)、新人が多い。機械:車の故障。つながり:…」
|
|
299
|
+
summary(ja){
|
|
300
|
+
var pl = this.plan(), one = function(n){ return String(n.label || n.tex || "").replace(/\s*\n\s*/g, " ").replace(/\*/g, "").replace(/[_^](.)/g, "$1") + (n.note ? " " + n.note : ""); };
|
|
301
|
+
var lp = ja ? "(" : " (", rp = ja ? ")" : ")", cm = ja ? "、" : ", ", dot = ja ? "。" : ". ";
|
|
302
|
+
var s = (ja ? "原因と結果の図" : "Cause-and-effect diagram") + (pl.head.n.label || pl.head.n.tex ? dot + (ja ? "結果:" : "Effect: ") + one(pl.head.n) : "");
|
|
303
|
+
pl.cats.forEach(function(c){
|
|
304
|
+
var ks = c.kids.map(function(k){ return one(k.n) + (k.kids.length ? lp + k.kids.map(function(x){ return one(x.n); }).join(cm) + rp : ""); });
|
|
305
|
+
s += dot + one(c.n) + (ks.length ? (ja ? ":" : ": ") + ks.join(cm) : "");
|
|
306
|
+
});
|
|
307
|
+
var ed = pl.edges.map(function(x){ return one(x.a.n) + " → " + one(x.b.n) + (x.e.label ? lp + x.e.label + rp : ""); });
|
|
308
|
+
if (ed.length) s += dot + (ja ? "つながり:" : "Links: ") + ed.join(cm);
|
|
309
|
+
return s;
|
|
310
|
+
}
|
|
311
|
+
poly(pts){
|
|
312
|
+
var L = [0];
|
|
313
|
+
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]));
|
|
314
|
+
return {pts: pts, L: L, len: L[L.length - 1] || 1};
|
|
315
|
+
}
|
|
316
|
+
part(pl, f){
|
|
317
|
+
var want = pl.len * Math.max(0, Math.min(1, f)), pts = pl.pts, out = [pts[0]], i = 1;
|
|
318
|
+
for (; i < pts.length && pl.L[i] <= want; i++) out.push(pts[i]);
|
|
319
|
+
var end = out[out.length - 1];
|
|
320
|
+
if (i < pts.length && want > pl.L[i - 1]){
|
|
321
|
+
var u = (want - pl.L[i - 1]) / (pl.L[i] - pl.L[i - 1]);
|
|
322
|
+
end = [base.lerp(pts[i - 1][0], pts[i][0], u), base.lerp(pts[i - 1][1], pts[i][1], u)];
|
|
323
|
+
out.push(end);
|
|
324
|
+
}
|
|
325
|
+
var pv = out.length > 1 ? out[out.length - 2] : pts[0], nx = i < pts.length ? pts[i] : end;
|
|
326
|
+
var ang = out.length < 2 ? Math.atan2(nx[1] - end[1], nx[0] - end[0]) : Math.atan2(end[1] - pv[1], end[0] - pv[0]);
|
|
327
|
+
return {d: "M" + out.map(function(p){ return p[0].toFixed(1) + "," + p[1].toFixed(1); }).join("L"), end: end, ang: ang};
|
|
328
|
+
}
|
|
329
|
+
duration(k){
|
|
330
|
+
var self = this, P = this.props, d = 0, S = this.span(), pl = this.plan();
|
|
331
|
+
if (pl.spineStep === k) d = Math.max(d, P.draw);
|
|
332
|
+
if (pl.head.step === k) d = Math.max(d, (pl.head.n.at || 0) + S);
|
|
333
|
+
(this.bones || []).forEach(function(B){
|
|
334
|
+
if (B.step === k) d = Math.max(d, B.at + S);
|
|
335
|
+
B.rows.forEach(function(r){ if (r.step === k) d = Math.max(d, r.at + 0.45); });
|
|
336
|
+
});
|
|
337
|
+
(this.edges || []).forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + P.draw + (o.lab ? 0.3 : 0)); });
|
|
338
|
+
return d;
|
|
339
|
+
}
|
|
340
|
+
render(k, t, ctx){
|
|
341
|
+
var P = this.props, D = base, self = this, vr = this.variant, lect = !!ctx.preview, S = this.span(), FAINT = 0.45;
|
|
342
|
+
if (lect) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
343
|
+
var tOf = function(step){ return step < k ? Infinity : step > k ? -1 : t; };
|
|
344
|
+
var pr = function(tt, at, dur){ return tt < 0 ? 0 : D.prog(tt, at, dur); };
|
|
345
|
+
// 授業の表示:後の段階は薄く(--preview-opacity)、今の段階は薄い状態から濃くなる。位置は動かさない(どの見せ方でも同じ)
|
|
346
|
+
var faint = function(tt, e){ return tt < 0 ? FAINT : FAINT + (1 - FAINT) * e; };
|
|
347
|
+
var line = function(el, path, e){ el.setAttribute("d", e > 0 ? self.part(path, e).d : ""); };
|
|
348
|
+
// 背骨:尾から頭へ引く(どの見せ方でも同じ)
|
|
349
|
+
var sp = this.spine, ts = tOf(sp.step), es = pr(ts, 0, P.draw);
|
|
350
|
+
if (lect){ line(sp.line, sp.path, 1); sp.line.setAttribute("opacity", faint(ts, es).toFixed(3)); }
|
|
351
|
+
else { line(sp.line, sp.path, es); sp.line.setAttribute("opacity", es > 0 ? 1 : 0); }
|
|
352
|
+
// 箱と字の動きは 12 px まで(docs/conventions.md §1.2:どの見せ方も fade より遠くへ動かさない)
|
|
353
|
+
// fade:下から 12 px 上がりながら現れる(0.92 → 1)。draw:線の後、背骨の側から 12 px 寄りながら現れる。
|
|
354
|
+
// grow:背骨の側から 12 px 寄りながら 0.92 → 1 に大きくなる
|
|
355
|
+
var OFF = 12;
|
|
356
|
+
var tf = function(cx, cy, s, dx, dy){
|
|
357
|
+
return s >= 1 && Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01 ? "" :
|
|
358
|
+
"translate(" + (cx + dx).toFixed(2) + " " + (cy + dy).toFixed(2) + ") scale(" + s.toFixed(4) + ") translate(" + (-cx).toFixed(2) + " " + (-cy).toFixed(2) + ")";
|
|
359
|
+
};
|
|
360
|
+
// 頭(背骨は左から来る)
|
|
361
|
+
var h = this.head, th = tOf(h.o.step), at = h.o.n.at || 0, eb, ea, sc = 1, m, sh;
|
|
362
|
+
if (vr === "draw"){ ea = pr(th, at, S * 0.5); eb = pr(th, at + S * 0.45, S * 0.55); sc = D.lerp(0.92, 1, eb); sh = [-OFF * (1 - eb), 0]; }
|
|
363
|
+
else if (vr === "grow"){ m = pr(th, at, P.fade); eb = pr(th, at, P.fade * 0.6); ea = pr(th, at, S * 0.5); sc = D.lerp(0.92, 1, m); sh = [-OFF * (1 - m), 0]; }
|
|
364
|
+
else { eb = pr(th, at, P.fade); ea = pr(th, at + P.fade * 0.6, P.draw * 0.5); sc = D.lerp(0.92, 1, eb); sh = [0, OFF * (1 - eb)]; }
|
|
365
|
+
if (lect){ var fh = faint(th, eb); h.g.setAttribute("opacity", fh.toFixed(3)); h.g.setAttribute("transform", ""); h.arrow.setAttribute("opacity", fh.toFixed(3)); }
|
|
366
|
+
else {
|
|
367
|
+
h.g.setAttribute("opacity", eb.toFixed(3));
|
|
368
|
+
h.g.setAttribute("transform", tf(h.cx, h.cy, sc, sh[0], sh[1]));
|
|
369
|
+
h.arrow.setAttribute("opacity", ea.toFixed(3));
|
|
370
|
+
}
|
|
371
|
+
// 大骨
|
|
372
|
+
this.bones.forEach(function(B){
|
|
373
|
+
var tt = tOf(B.step), eb, el, sc = 1, m, sh, path = B.path;
|
|
374
|
+
if (vr === "draw"){
|
|
375
|
+
el = pr(tt, B.at, S * 0.5); eb = pr(tt, B.at + S * 0.45, S * 0.55); sc = D.lerp(0.92, 1, eb); path = B.rpath;
|
|
376
|
+
sh = [-B.dir[0] * OFF * (1 - eb), -B.dir[1] * OFF * (1 - eb)];
|
|
377
|
+
} else if (vr === "grow"){
|
|
378
|
+
m = pr(tt, B.at, P.fade); eb = pr(tt, B.at, P.fade * 0.6); el = pr(tt, B.at, S); sc = D.lerp(0.92, 1, m); path = B.rpath;
|
|
379
|
+
sh = [-B.dir[0] * OFF * (1 - m), -B.dir[1] * OFF * (1 - m)];
|
|
380
|
+
} else { eb = pr(tt, B.at, P.fade); el = pr(tt, B.at + P.fade * 0.6, P.draw); sc = D.lerp(0.92, 1, eb); sh = [0, OFF * (1 - eb)]; }
|
|
381
|
+
if (lect){ var f = faint(tt, eb); B.g.setAttribute("opacity", f.toFixed(3)); B.g.setAttribute("transform", ""); line(B.line, B.path, 1); B.line.setAttribute("opacity", f.toFixed(3)); }
|
|
382
|
+
else {
|
|
383
|
+
B.g.setAttribute("opacity", eb.toFixed(3));
|
|
384
|
+
B.g.setAttribute("transform", tf(B.cx, B.cy, sc, sh[0], sh[1]));
|
|
385
|
+
line(B.line, path, el); B.line.setAttribute("opacity", el > 0 ? 1 : 0);
|
|
386
|
+
}
|
|
387
|
+
// 原因の行(どれも 0.45 秒):fade は字が下から 12 px 上がりながら現れてから線、draw は線から字、
|
|
388
|
+
// grow は字が大骨の側(右)から 12 px 寄りながら現れ、線は同時に大骨から引く
|
|
389
|
+
B.rows.forEach(function(r){
|
|
390
|
+
var tr = tOf(r.step), et, el2, dx = 0, dy = 0;
|
|
391
|
+
if (vr === "draw"){ el2 = pr(tr, r.at, 0.25); et = pr(tr, r.at + 0.15, 0.3); }
|
|
392
|
+
else if (vr === "grow"){ el2 = pr(tr, r.at, 0.45); et = pr(tr, r.at, 0.3); dx = OFF * (1 - et); }
|
|
393
|
+
else { et = pr(tr, r.at, 0.3); el2 = pr(tr, r.at + 0.15, 0.3); dy = OFF * (1 - et); }
|
|
394
|
+
if (lect){
|
|
395
|
+
var f = faint(tr, et);
|
|
396
|
+
r.g.setAttribute("opacity", f.toFixed(3)); r.g.setAttribute("transform", "");
|
|
397
|
+
line(r.line, r.path, 1); r.line.setAttribute("opacity", f.toFixed(3));
|
|
398
|
+
} else {
|
|
399
|
+
r.g.setAttribute("opacity", et.toFixed(3));
|
|
400
|
+
r.g.setAttribute("transform", Math.abs(dx) > 0.01 || Math.abs(dy) > 0.01 ? "translate(" + dx.toFixed(2) + " " + dy.toFixed(2) + ")" : "");
|
|
401
|
+
line(r.line, r.path, el2); r.line.setAttribute("opacity", el2 > 0 ? 1 : 0);
|
|
402
|
+
}
|
|
403
|
+
if (r.mline){
|
|
404
|
+
var tm = tOf(r.mstep), em = pr(tm, r.mat, vr === "fade" ? 0.3 : 0.25);
|
|
405
|
+
if (vr === "fade") em = pr(tm, r.mat + 0.15, 0.3);
|
|
406
|
+
if (lect){ line(r.mline, r.mpath, 1); r.mline.setAttribute("opacity", faint(tm, em).toFixed(3)); }
|
|
407
|
+
else { line(r.mline, r.mpath, em); r.mline.setAttribute("opacity", em > 0 ? 1 : 0); }
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
this.edges.forEach(function(o){
|
|
412
|
+
var tt = tOf(o.step), e = pr(tt, o.at, P.draw), lo = pr(tt, o.at + P.draw * 0.8, 0.3);
|
|
413
|
+
if (lect){ var f = faint(tt, e); e = 1; lo = 1; o.g.setAttribute("opacity", f.toFixed(3)); }
|
|
414
|
+
else o.g.setAttribute("opacity", e > 0 ? 1 : 0);
|
|
415
|
+
var p = self.part(o.path, e);
|
|
416
|
+
o.line.setAttribute("d", e > 0 ? p.d : "");
|
|
417
|
+
var hs = Math.min(1, e * o.path.len / 20);
|
|
418
|
+
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) + ")");
|
|
419
|
+
if (o.lab) o.lab.setAttribute("opacity", lo.toFixed(3));
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
return Part;
|
|
424
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Venn of 2–3 sets, one by one; then overlaps with items
|
|
3
|
+
steps: sets + 1 (overlaps="each": sets + overlaps with items, or all overlaps if none)
|
|
4
|
+
props:
|
|
5
|
+
size: item text px (shrinks to 24)
|
|
6
|
+
dur: set appear (s)
|
|
7
|
+
spread: centre distance ÷ radius (0.7–1.3)
|
|
8
|
+
overlaps: together or each
|
|
9
|
+
example: {"sets": [{"label": "Mammals"}, {"label": "Sea animals"}], "regions": {"A": ["Lion"], "B": ["Tuna"], "AB": ["Whale", "Dolphin"]}}
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Shared and distinct traits. Per-point values: `m-compare`.
|
|
13
|
+
|
|
14
|
+
Child JSON: `{"sets": [{"label", "tone"}, …], "regions": {"A": [...], "B": [...], "AB": [...], …}}`.
|
|
15
|
+
|
|
16
|
+
- `sets`: 2 or 3; `label` outside; `tone` (`term`, `emph`, `muted`, `accent2`, `series-1..4`; default `term`, `accent2`, `series-4`). Avoid `emph` (used for overlaps)
|
|
17
|
+
- `regions`: items per region (array or `\n` text). Keys: letters in alphabetical order, A B C = `sets` order:
|
|
18
|
+
- `A`: only A; `AB`: A and B (with 3 sets, not C); `ABC`: all three
|
|
19
|
+
- 2 sets: `A` `B` `AB`; 3: `A` `B` `C` `AB` `AC` `BC` `ABC`; all optional. C keys with 2 sets: error card
|
|
20
|
+
- Area not to scale. `spread` (default 1): smaller = more overlap
|
|
21
|
+
- Overlap items bold; 1–2 words with 3 sets
|
|
22
|
+
- Steps: each set with its own items → overlaps (those with items tinted `--emph`, outlined, items shown; if none have items, all). `overlaps="each"`: one by one (`AB`, `AC`, `BC`, `ABC`)
|
|
23
|
+
- `variant`: `fade` (default), `draw` (outlines first)
|
|
24
|
+
|
|
25
|
+
The demo is `demo.html` (skills example fictional).
|
|
26
|
+
|
|
27
|
+
<!-- llm: omit -->
|
|
28
|
+
Notes
|
|
29
|
+
|
|
30
|
+
- Layout: 2 sets left/right; 3 top-left, top-right, bottom. Items placed farthest from circle lines
|
|
31
|
+
- Item width estimated from characters (CJK 1, Latin 0.6). 3-set overlaps are small: 1–2 words. Shrinks to 24 px, then ctx.report
|
|
32
|
+
- Overlaps are clipPath cut-outs; theme variables only
|
|
33
|
+
- Lecture view (`ctx.preview`): later circles and overlaps at `--preview-opacity` (default 0.45)
|
|
34
|
+
<!-- llm: end -->
|