egatari 0.6.10 → 0.6.11-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/README.ja.md +22 -22
- package/README.md +1 -1
- package/bin/egatari.mjs +1 -1
- package/components.lock.json +288 -144
- package/components2.lock.json +657 -1
- package/kit/build.mjs +3 -2
- package/kit/check-messages.mjs +46 -12
- package/kit/check.mjs +54 -19
- package/kit/core/article-messages.mjs +5 -4
- package/kit/core/attachments.mjs +2 -1
- package/kit/core/build-core.mjs +2 -1
- package/kit/core/check-parity.mjs +3 -1
- package/kit/core/check-result.mjs +2 -1
- package/kit/core/check-rules.mjs +132 -0
- package/kit/core/colab-core.mjs +2 -2
- package/kit/core/geometry-check.mjs +302 -0
- package/kit/core/layout-scan.mjs +9 -2
- package/kit/core/live-results.mjs +1 -1
- package/kit/core/llm-fix.mjs +3 -2
- package/kit/core/llm-outline.mjs +3 -2
- package/kit/core/llm-pack-data.mjs +114 -114
- package/kit/core/narration-lint.mjs +37 -0
- package/kit/core/new-deck-pack.mjs +2 -1
- package/kit/core/new-deck.mjs +1 -1
- package/kit/core/plural.mjs +5 -0
- package/kit/core/portable.mjs +6 -5
- package/kit/core/sample-layout.mjs +14 -0
- package/kit/core/text-band.mjs +37 -0
- package/kit/core/tier-a.mjs +2 -1
- package/kit/instruction-version.json +1 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/render-compare.mjs +5 -4
- package/kit/tools.js +2 -2
- package/package.json +3 -2
- package/server/editor-ui.js +2 -2
- package/vendor/components/CATALOG.md +12 -12
- package/vendor/components/sha256/00d9072cb279a1a68166787f53395c747072388971d916c082a106844dbf888f/index.js +315 -0
- package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/README.en.md +23 -0
- package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/index.js +289 -0
- package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/README.en.md +40 -0
- package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/index.js +341 -0
- package/vendor/components/sha256/1073e03374f0fe65d2691f160bfd8c092986c168d0bd6a6094ebd444d4b89c27/index.js +592 -0
- package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/README.en.md +48 -0
- package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/index.js +384 -0
- package/vendor/components/sha256/147987bd84722249dab609293d4fafa93f0a2aac25b8517fda1710840b575d00/index.js +341 -0
- package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/README.en.md +23 -0
- package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/index.js +120 -0
- package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/README.en.md +32 -0
- package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/index.js +222 -0
- package/vendor/components/sha256/1b30dfd9b366ff07556024eb8ce75cca2eac8001fa392eed4e1232047001ec74/index.js +404 -0
- package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/README.en.md +66 -0
- package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/index.js +920 -0
- package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/README.en.md +50 -0
- package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/index.js +171 -0
- package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/README.en.md +31 -0
- package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/index.js +232 -0
- package/vendor/components/sha256/43740da51de85c1b7ec1eaf688f93fd9ea25b15977ab075e6abac196f08643a6/index.js +122 -0
- package/vendor/components/sha256/4817f77bd021ec5c77d5a15ee56e2e34d31d1d98630e86225eb20f2f9bf095e9/index.js +812 -0
- package/vendor/components/sha256/4e4bf3b2968c36a334dc997e32e36f22ecbc4f5dfe1c76bb7a5beef002fe8899/index.js +228 -0
- package/vendor/components/sha256/553e132d1f84caad648bb7175a206d4c5d18c005b5ca17989f5e8a5e3f5cdfa1/index.js +75 -0
- package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/README.en.md +34 -0
- package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/index.js +244 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/index.js +4868 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/names.txt +4808 -0
- package/vendor/components/sha256/636f47e955f5550f046cfc7a3de8de70c4b97aa77771bde2ee0e31d706bb032e/index.js +278 -0
- package/vendor/components/sha256/65ddc34bd9c75e073f4c2cd283369417fe88769521809670c6b8730852d4f647/index.js +97 -0
- package/vendor/components/sha256/6b0c75b0f697fe451197301de82a113f1c2548b67f7a8d2b56576d2bae8e240c/index.js +607 -0
- package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/README.en.md +33 -0
- package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/index.js +390 -0
- package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/README.en.md +31 -0
- package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/index.js +267 -0
- package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/README.en.md +22 -0
- package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/index.js +145 -0
- package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/README.en.md +44 -0
- package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/index.js +203 -0
- package/vendor/components/sha256/781a45d97f1325cfb40aa98d00e1db9600949158fdb2749b0223b019c67a80f2/index.js +919 -0
- package/vendor/components/sha256/850944419734168be3dc202057de128131869c471cb8ab3baec2cfe789d56493/index.js +465 -0
- package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/README.en.md +37 -0
- package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/index.js +424 -0
- package/vendor/components/sha256/8a892d25d0bb6105ba31ea690b465876ce3af1fbaf18e2a9ce44ad2fee81260e/index.js +162 -0
- package/vendor/components/sha256/8acec8f299510287fbad6a69311ec58a39b0e99647dd03609c818e053b3b6087/index.js +484 -0
- package/vendor/components/sha256/8ef66bd1e800bcbedef436585469d308665aaa1ab6011aee699544302d0a8ad0/index.js +312 -0
- package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/README.en.md +40 -0
- package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/index.js +348 -0
- package/vendor/components/sha256/a0c71874d83045baaef70285bd00d87a7c6c43219fa5630dfff60d5cb08509be/index.js +250 -0
- package/vendor/components/sha256/a31f39625d7d1087d06a72b644cec417372f98add940288257ef07f812d8395a/index.js +747 -0
- package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/README.en.md +38 -0
- package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/index.js +289 -0
- package/vendor/components/sha256/ae06622a328da2a01260bc68b28bb632c391e8d62a4e8387638e5a944525a418/index.js +521 -0
- package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/README.en.md +24 -0
- package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/index.js +103 -0
- package/vendor/components/sha256/b756c66d5c6e6ace90912ab467dea3031f2c9b291d8b2a786ca660faa0e8ac84/index.js +121 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/chords.json +89 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/extras.json +192 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ties.json +360 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/index.js +508 -0
- package/vendor/components/sha256/bea7cb344f55677d5756c9711b90cc971126830ec5f66a03f71f13dbfadc401e/index.js +351 -0
- package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/README.en.md +42 -0
- package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/index.js +268 -0
- package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/README.en.md +51 -0
- package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/index.js +228 -0
- package/vendor/components/sha256/d2df3d70fc7c6e07e3cad7332a7e5501e84abeb24653786e567f57046adebcba/index.js +268 -0
- package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/README.en.md +35 -0
- package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/index.js +179 -0
- package/vendor/components/sha256/e6d219f67d241fdf00a40d4cec261d9dd3c09ad3110d3418d4e843d0f2b8c196/index.js +429 -0
- package/vendor/components/sha256/ef60e6c089f5f6e909f439af8fc0c9c0a2d7a1aafad5e65be6328ba993b990a0/index.js +354 -0
- package/vendor/components/sha256/f6f47601c90f0195353e94b76d57499591d6330a7e35714958a2c41229f70da2/index.js +198 -0
- package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/README.en.md +44 -0
- package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/index.js +304 -0
- package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/README.en.md +42 -0
- package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/index.js +481 -0
- package/vendor/components/sha256/fdcea28e27638d8bfe234016672375e14de8bb97c32f7b6840d1b7b10ac4b1cd/index.js +233 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/LICENSE-strokesvg.txt +115 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/OFL.txt +93 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/index.js +749 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/strokes-CHANGES.md +20 -0
- package/vendor/components-2/manifest-2.7.0.json +2118 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// m-gendai:現代文の読解の図。傍線・二重傍線を引き、指示語から指す内容へ矢印を出し、段落を役割(主張・具体例・対比)の枠で囲んで線でつなぐ
|
|
2
|
+
// <m-gendai tate style="height:440px">
|
|
3
|
+
// @具体例#p1>p3
|
|
4
|
+
// 駅までの道を、私は{地図アプリ|#app}に頼って歩く。…{それ|>app}を閉じると、…
|
|
5
|
+
//
|
|
6
|
+
// @主張#p3
|
|
7
|
+
// 便利な道具は、私たちから=={迷う機会を奪う}==。…{迷うことこそが…営みなのである|_A}
|
|
8
|
+
// </m-gendai>
|
|
9
|
+
// 段落は空行で区切る。段落の頭の行「@役割#名前」で役割(主張・具体例・対比・反論・結論など、自由な言葉)と名前を付け、
|
|
10
|
+
// 「>名前」(その段落を支える・つながる。矢印)か「~名前」(対比。両向きの線)で別の段落とつなぐ。
|
|
11
|
+
// 本文の中:__語句__ 傍線、==語句== 二重傍線、{語句|しるし,…}(しるし:_A 傍線と記号 A、=B 二重傍線と記号 B、#名前 指す先、>名前 指示語)
|
|
12
|
+
// 段階(phases の順。中身のないものは飛ばす。既定は marks refs roles):marks 傍線 → refs 指示語の矢印 → roles 段落の枠と線
|
|
13
|
+
// 線と枠は、字の位置を測って SVG で描く(部品の中の座標。描く度に測るので、呼び出しの順によらない)
|
|
14
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
15
|
+
// 書き方の誤りは ctx.report("data", "[gendai] …") で知らせる(1.x の console.warn("m-gendai: …") の代わり)。
|
|
16
|
+
// 読み取り(parse)は試験のために static testing に出す(ほかのパーツは読まない)
|
|
17
|
+
egatariParts.define({name: "gendai", version: "2.0.3", requires: {base: "1.2.0"}, element: "m-gendai"}, function(deps){
|
|
18
|
+
"use strict";
|
|
19
|
+
var base = deps.base;
|
|
20
|
+
var D = base;
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------- 読み取り
|
|
23
|
+
// parse(文字列) → {paras: [{role, id, to, rel, runs: [{t, line, label, id, ref}]}], warnings}
|
|
24
|
+
function parse(src){
|
|
25
|
+
var paras = [], warnings = [], blocks = String(src || "").replace(/\r/g, "").split(/\n\s*\n/);
|
|
26
|
+
blocks.forEach(function(b){
|
|
27
|
+
var lines = b.split("\n").map(function(l){ return l.trim(); }).filter(Boolean);
|
|
28
|
+
if (!lines.length) return;
|
|
29
|
+
var p = {role: "", id: "", to: "", rel: "", runs: []};
|
|
30
|
+
var m = /^@([^#>~\s]*)(?:#([^>~\s]+))?(?:([>~])(\S+))?\s*$/.exec(lines[0]);
|
|
31
|
+
if (m){ p.role = m[1]; p.id = m[2] || ""; p.rel = m[3] || ""; p.to = m[4] || ""; lines.shift(); }
|
|
32
|
+
p.runs = inline(lines.join(""), warnings);
|
|
33
|
+
paras.push(p);
|
|
34
|
+
});
|
|
35
|
+
var ids = {};
|
|
36
|
+
paras.forEach(function(p){ if (p.id) ids[p.id] = true; });
|
|
37
|
+
paras.forEach(function(p){ if (p.to && !ids[p.to]) warnings.push("段落「" + p.to + "」がない(@" + p.role + ")"); });
|
|
38
|
+
var anchors = {};
|
|
39
|
+
paras.forEach(function(p){ p.runs.forEach(function(r){ if (r.id) anchors[r.id] = true; }); });
|
|
40
|
+
paras.forEach(function(p){ p.runs.forEach(function(r){ if (r.ref && !anchors[r.ref]) warnings.push("指す先「#" + r.ref + "」がない(" + r.t + ")"); }); });
|
|
41
|
+
return {paras: paras, warnings: warnings};
|
|
42
|
+
}
|
|
43
|
+
// 本文の中のしるし → 字の並び(runs)。run = {t, line: 0 | 1 | 2(傍線・二重傍線), label, id, ref}
|
|
44
|
+
function inline(s, warnings){
|
|
45
|
+
var runs = [], re = /__(.+?)__|==(.+?)==|\{([^{}|]+)\|([^{}]*)\}/g, last = 0, m;
|
|
46
|
+
var plain = function(t){ if (t) runs.push({t: t, line: 0, label: "", id: "", ref: ""}); };
|
|
47
|
+
while ((m = re.exec(s))){
|
|
48
|
+
plain(s.slice(last, m.index)); last = re.lastIndex;
|
|
49
|
+
if (m[1] !== undefined){ runs.push({t: m[1], line: 1, label: "", id: "", ref: ""}); continue; }
|
|
50
|
+
if (m[2] !== undefined){ runs.push({t: m[2], line: 2, label: "", id: "", ref: ""}); continue; }
|
|
51
|
+
var r = {t: m[3], line: 0, label: "", id: "", ref: ""};
|
|
52
|
+
m[4].split(/[,,、]/).map(function(f){ return f.trim(); }).filter(Boolean).forEach(function(f){
|
|
53
|
+
if (f[0] === "_"){ r.line = 1; r.label = f.slice(1); }
|
|
54
|
+
else if (f[0] === "="){ r.line = 2; r.label = f.slice(1); }
|
|
55
|
+
else if (f[0] === "#") r.id = f.slice(1);
|
|
56
|
+
else if (f[0] === ">") r.ref = f.slice(1);
|
|
57
|
+
else warnings.push("知らないしるし「" + f + "」(" + m[3] + ")");
|
|
58
|
+
});
|
|
59
|
+
runs.push(r);
|
|
60
|
+
}
|
|
61
|
+
plain(s.slice(last));
|
|
62
|
+
// 残った { } __ ==:閉じていないか、入れ子にしたしるし(しるしは入れ子にできない。{語句|=,#名前} のように 1 つにまとめる)
|
|
63
|
+
runs.forEach(function(r){ if (/[{}]|__|==/.test(r.t)) warnings.push("しるしの書き方が違う(閉じていない・入れ子):" + r.t); });
|
|
64
|
+
return runs;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------- 部品
|
|
68
|
+
var ROLE_COLOR = function(role){ return /主張|結論|筆者/.test(role) ? "var(--emph)" : /対比|反論|対立/.test(role) ? "var(--accent2)" : /具体|例/.test(role) ? "var(--term)" : "var(--muted)"; };
|
|
69
|
+
var PH = ["marks", "refs", "roles"];
|
|
70
|
+
// 枠をつなぐ線は札(枠の上の名前)から札へ、札と枠の外の通り道(縦書きは札の上、横書きは札の左)を通す。
|
|
71
|
+
// 通り道は線ごとに段(level)を分け、間の段落を越える線ほど外の段を通る。段の数だけ場所を空ける(線が札や枠に重ならないように)
|
|
72
|
+
var CHIP = 34; // 札の高さ
|
|
73
|
+
var STUB = 22, STEP = 16; // 札から 1 段目までの距離、段の間
|
|
74
|
+
var LH_TATE = 2.4; // 縦書きの行の送り(傍線と記号 A の入る列の間を空ける)
|
|
75
|
+
return class extends base.MotionElement {
|
|
76
|
+
static partName = "gendai"; // the registry name (define meta name), for report prefixes
|
|
77
|
+
static testing = {parse: parse}; // for tools/test-kokugo.mjs only (no part reads it)
|
|
78
|
+
// データの形(kit/shape.js):JSON ではなく、要素の中に本文の字(段落は空行で区切る)
|
|
79
|
+
static shape = {text: true, example: "@主張#p1\n便利な道具は、私たちから==迷う機会を奪う==。"};
|
|
80
|
+
static props = {
|
|
81
|
+
size: {type: "number", default: 28, doc: "本文の字の大きさ(px)"},
|
|
82
|
+
tate: {type: "bool", default: false, doc: "縦書きにする(段落は右から左へ、枠をつなぐ線は上を通す)"},
|
|
83
|
+
phases: {type: "string", default: "marks refs roles", doc: "ステップの並び(marks 傍線・refs 指示語・roles 段落の枠から選ぶ。中身のないものは飛ばす)"},
|
|
84
|
+
draw: {type: "number", default: 0.7, doc: "線 1 本を引く秒数"},
|
|
85
|
+
};
|
|
86
|
+
get model(){ if (!this._m) this._m = parse(this._src !== undefined ? this._src : this.textContent); return this._m; }
|
|
87
|
+
get phaseList(){
|
|
88
|
+
var m = this.model, has = {
|
|
89
|
+
marks: m.paras.some(function(p){ return p.runs.some(function(r){ return r.line; }); }),
|
|
90
|
+
refs: m.paras.some(function(p){ return p.runs.some(function(r){ return r.ref; }); }),
|
|
91
|
+
roles: m.paras.some(function(p){ return p.role; })};
|
|
92
|
+
return String(this.props.phases || "").split(/[\s,]+/).filter(function(x){ return PH.indexOf(x) >= 0 && has[x]; });
|
|
93
|
+
}
|
|
94
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.phaseList.length; }
|
|
95
|
+
phaseStep(name){ return this.phaseList.indexOf(name) + 1; }
|
|
96
|
+
mount(ctx){
|
|
97
|
+
var self = this, P = this.props, tate = P.tate;
|
|
98
|
+
this._src = this.textContent;
|
|
99
|
+
var m = this.model;
|
|
100
|
+
m.warnings.forEach(function(w){ ctx.report("data", "[gendai] " + w); });
|
|
101
|
+
this.textContent = "";
|
|
102
|
+
this.classList.add("plot");
|
|
103
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
104
|
+
this.style.fontFamily = "var(--font-mincho)";
|
|
105
|
+
var W =this.clientWidth || 1184, H = this.clientHeight || 440;
|
|
106
|
+
var roles = m.paras.some(function(p){ return p.role; });
|
|
107
|
+
// つなぐ線の段:つなぐ段落の間の短いものから順に、重なる線より 1 つ外の段へ
|
|
108
|
+
var pIdx = {};
|
|
109
|
+
m.paras.forEach(function(p, i){ if (p.id) pIdx[p.id] = i; });
|
|
110
|
+
var spans = m.paras.map(function(p, i){ return p.to && pIdx[p.to] !== undefined ? {i: i, lo: Math.min(i, pIdx[p.to]), hi: Math.max(i, pIdx[p.to])} : null; }).filter(Boolean)
|
|
111
|
+
.sort(function(a, b){ return (a.hi - a.lo) - (b.hi - b.lo) || a.lo - b.lo; });
|
|
112
|
+
var levelOf = {}, placed = [], nLev = 0;
|
|
113
|
+
spans.forEach(function(o){
|
|
114
|
+
var lv = 1;
|
|
115
|
+
placed.forEach(function(q){ if (q.lo < o.hi && o.lo < q.hi) lv = Math.max(lv, q.lv + 1); });
|
|
116
|
+
o.lv = lv; placed.push(o); levelOf[o.i] = lv; nLev = Math.max(nLev, lv);
|
|
117
|
+
});
|
|
118
|
+
this.nLev = nLev;
|
|
119
|
+
// 通り道と札の場所:縦書きは上に(札 + 段)、横書きは左に(段)と上に(札)
|
|
120
|
+
var lane = nLev ? STUB + (nLev - 1) * STEP + 10 : 0;
|
|
121
|
+
this.padTop = tate ? (roles ? CHIP + lane + 10 : 20) : (roles ? CHIP + 10 : 20);
|
|
122
|
+
this.padLeft = tate ? 0 : (nLev ? lane - 2 : 4);
|
|
123
|
+
// 重ね順:塗り(指す先の淡い色)→ 字 → 線・枠・矢印
|
|
124
|
+
this.back = D.el("svg", {width: W, height: H, viewBox: "0 0 " + W + " " + H, "aria-hidden": "true", style: "position:absolute;left:0;top:0;overflow:visible;pointer-events:none"}, this);
|
|
125
|
+
var text = document.createElement("div");
|
|
126
|
+
text.style.cssText = "position:absolute;inset:0;font-size:" + P.size + "px;line-height:" + (tate ? LH_TATE : 1.85) + ";padding-top:" + this.padTop + "px;" + (tate ? "writing-mode:vertical-rl;" : "padding-left:" + this.padLeft + "px;");
|
|
127
|
+
this.appendChild(text);
|
|
128
|
+
this.front = D.el("svg", {width: W, height: H, viewBox: "0 0 " + W + " " + H, "aria-hidden": "true", style: "position:absolute;left:0;top:0;overflow:visible;pointer-events:none"}, this);
|
|
129
|
+
this.text = text;
|
|
130
|
+
var byId = {};
|
|
131
|
+
this.paras = m.paras.map(function(p, pi){
|
|
132
|
+
var d = document.createElement("div");
|
|
133
|
+
// 枠の内側の余白と、段落の間(枠の名前の札が入る)
|
|
134
|
+
// 横書きは次の段落の札が前の枠に掛からないように空ける
|
|
135
|
+
d.style.cssText = "padding:10px 14px;text-indent:1em;" + (tate ? "margin:0 0 0 22px;" : "margin:0 0 " + (roles ? CHIP + 12 : 22) + "px 0;");
|
|
136
|
+
text.appendChild(d);
|
|
137
|
+
var P2 = {p: p, el: d, spans: []};
|
|
138
|
+
p.runs.forEach(function(r){
|
|
139
|
+
if (!r.line && !r.id && !r.ref){ d.appendChild(document.createTextNode(r.t)); return; }
|
|
140
|
+
var s = document.createElement("span"); s.textContent = r.t; d.appendChild(s);
|
|
141
|
+
P2.spans.push({r: r, el: s});
|
|
142
|
+
if (r.id) byId[r.id] = s;
|
|
143
|
+
});
|
|
144
|
+
return P2;
|
|
145
|
+
});
|
|
146
|
+
this.byId = byId;
|
|
147
|
+
// 傍線(引く順に)
|
|
148
|
+
this.lines = [];
|
|
149
|
+
this.paras.forEach(function(P2){ P2.spans.forEach(function(s){ if (s.r.line){
|
|
150
|
+
var g = D.el("g", {}, self.front), o = {el: s.el, r: s.r, g: g, segs: [], lab: null};
|
|
151
|
+
if (s.r.label) o.lab = D.el("text", {"font-size": 24, "font-weight": 700, fill: "var(--emph)", "text-anchor": "middle", opacity: 0}, g);
|
|
152
|
+
if (o.lab) o.lab.textContent = s.r.label;
|
|
153
|
+
self.lines.push(o);
|
|
154
|
+
} }); });
|
|
155
|
+
// 指示語 → 指す先
|
|
156
|
+
this.refs = [];
|
|
157
|
+
this.paras.forEach(function(P2){ P2.spans.forEach(function(s){ if (s.r.ref && byId[s.r.ref]){
|
|
158
|
+
self.refs.push({from: s.el, to: byId[s.r.ref],
|
|
159
|
+
fill: D.el("g", {opacity: 0}, self.back),
|
|
160
|
+
box: D.el("g", {opacity: 0}, self.front),
|
|
161
|
+
path: D.el("path", {fill: "none", stroke: "var(--emph)", "stroke-width": 3, "stroke-linecap": "round", pathLength: 1, "stroke-dasharray": 1, "stroke-dashoffset": 1}, self.front),
|
|
162
|
+
head: D.el("path", {d: "M0,0L-14,-7L-14,7Z", fill: "var(--emph)", opacity: 0}, self.front)});
|
|
163
|
+
} }); });
|
|
164
|
+
// 段落の枠・札・つなぐ線
|
|
165
|
+
var pById = {};
|
|
166
|
+
this.paras.forEach(function(P2){ if (P2.p.id) pById[P2.p.id] = P2; });
|
|
167
|
+
this.boxes = this.paras.filter(function(P2){ return P2.p.role; }).map(function(P2){
|
|
168
|
+
var c = ROLE_COLOR(P2.p.role);
|
|
169
|
+
var rect = D.el("rect", {fill: "none", stroke: c, "stroke-width": 2.5, rx: 10, pathLength: 1, "stroke-dasharray": 1, "stroke-dashoffset": 1}, self.front);
|
|
170
|
+
var chip = D.el("g", {opacity: 0}, self.front);
|
|
171
|
+
var cr = D.el("rect", {fill: "var(--bg)", stroke: c, "stroke-width": 2, rx: 14, height: 34}, chip);
|
|
172
|
+
var ct = D.el("text", {"font-size": 24, "font-weight": 700, fill: c, "text-anchor": "middle"}, chip);
|
|
173
|
+
ct.textContent = P2.p.role;
|
|
174
|
+
return {P2: P2, c: c, rect: rect, chip: chip, cr: cr, ct: ct};
|
|
175
|
+
});
|
|
176
|
+
this.links = this.paras.filter(function(P2){ return P2.p.to && pById[P2.p.to]; }).map(function(P2){
|
|
177
|
+
var c = P2.p.rel === "~" ? "var(--accent2)" : "var(--muted)";
|
|
178
|
+
return {a: P2, b: pById[P2.p.to], rel: P2.p.rel, c: c, lv: levelOf[self.paras.indexOf(P2)] || 1,
|
|
179
|
+
path: D.el("path", {fill: "none", stroke: c, "stroke-width": 2.5, "stroke-dasharray": P2.p.rel === "~" ? "none" : "none", pathLength: 1}, self.front),
|
|
180
|
+
h1: D.el("path", {d: "M0,0L-13,-6.5L-13,6.5Z", fill: c, opacity: 0}, self.front),
|
|
181
|
+
h0: P2.p.rel === "~" ? D.el("path", {d: "M0,0L-13,-6.5L-13,6.5Z", fill: c, opacity: 0}, self.front) : null};
|
|
182
|
+
});
|
|
183
|
+
// 読み上げ:本文はそのまま読める字(role="figure" の中身)。名前は最後の形の読解のしるし(傍線・指示語・段落の役割とつながり。
|
|
184
|
+
// phases にある段階のものだけ)を 1 文で。線と枠の SVG は aria-hidden。作者の aria-label があればそれを使う(上書きしない)
|
|
185
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
186
|
+
this.setAttribute("role", "figure");
|
|
187
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary());
|
|
188
|
+
}
|
|
189
|
+
// 最後の形の読解のしるしを 1 文で(読み上げの名前)
|
|
190
|
+
summary(){
|
|
191
|
+
var m = this.model, ph = this.phaseList, out = [], anchors = {};
|
|
192
|
+
m.paras.forEach(function(p){ p.runs.forEach(function(r){ if (r.id) anchors[r.id] = r.t; }); });
|
|
193
|
+
var runs = [].concat.apply([], m.paras.map(function(p){ return p.runs; }));
|
|
194
|
+
if (ph.indexOf("marks") >= 0) out.push(runs.filter(function(r){ return r.line; }).map(function(r){ return (r.line === 2 ? "二重傍線" : "傍線") + (r.label ? " " + r.label : "") + "「" + r.t + "」"; }).join("、"));
|
|
195
|
+
if (ph.indexOf("refs") >= 0) out.push(runs.filter(function(r){ return r.ref && anchors[r.ref] !== undefined; }).map(function(r){ return "指示語「" + r.t + "」は「" + anchors[r.ref] + "」を指す"; }).join("、"));
|
|
196
|
+
if (ph.indexOf("roles") >= 0){
|
|
197
|
+
var byId = {};
|
|
198
|
+
m.paras.forEach(function(p){ if (p.id) byId[p.id] = p; });
|
|
199
|
+
var links = m.paras.filter(function(p){ return p.to && byId[p.to]; }).map(function(p){ return (p.role || "段落") + (p.rel === "~" ? " ↔ " : " → ") + (byId[p.to].role || "段落"); });
|
|
200
|
+
out.push("段落の役割:" + m.paras.map(function(p){ return p.role; }).filter(Boolean).join("・") + (links.length ? "(" + links.join("、") + ")" : ""));
|
|
201
|
+
}
|
|
202
|
+
out = out.filter(Boolean);
|
|
203
|
+
return "現代文の読解" + (out.length ? ":" + out.join("。") : "");
|
|
204
|
+
}
|
|
205
|
+
// 要素の字の箱(行ごと)を部品の座標で。部品の外側の拡大(舞台の scale・段階の translate)によらない
|
|
206
|
+
rects(e){
|
|
207
|
+
var R = this.getBoundingClientRect(), sc = R.width / (this.offsetWidth || 1) || 1;
|
|
208
|
+
return [].map.call(e.getClientRects(), function(r){ return {l: (r.left - R.left) / sc, t: (r.top - R.top) / sc, r: (r.right - R.left) / sc, b: (r.bottom - R.top) / sc}; })
|
|
209
|
+
.filter(function(r){ return r.r - r.l > 0.5 && r.b - r.t > 0.5; });
|
|
210
|
+
}
|
|
211
|
+
box(e){ var r = this.rects(e), o = null; r.forEach(function(x){ o = o ? {l: Math.min(o.l, x.l), t: Math.min(o.t, x.t), r: Math.max(o.r, x.r), b: Math.max(o.b, x.b)} : x; }); return o; }
|
|
212
|
+
duration(k){
|
|
213
|
+
var name = this.phaseList[k - 1], P = this.props;
|
|
214
|
+
if (name === "marks") return this.lines.length * P.draw * 0.8 + 0.3;
|
|
215
|
+
if (name === "refs") return this.refs.length * (P.draw + 0.3) + 0.2;
|
|
216
|
+
if (name === "roles") return this.boxes.length * 0.35 + P.draw + (this.links.length ? 0.3 + P.draw : 0);
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
render(k, t, ctx){
|
|
220
|
+
var self = this, P = this.props, tate = P.tate;
|
|
221
|
+
var at = function(name){ var s = self.phaseStep(name); if (!s) return -1; return k > s ? Infinity : k < s ? -1 : t; };
|
|
222
|
+
var pr = function(tt, a, d){ return tt < 0 ? 0 : D.prog(tt, a, d); };
|
|
223
|
+
var tm = at("marks"), trf = at("refs"), tro = at("roles");
|
|
224
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の傍線・指示語の囲みと矢印・段落の枠と札とつなぐ線を、
|
|
225
|
+
// 引き終えた形のまま --preview-opacity の濃さで出す
|
|
226
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0.45;
|
|
227
|
+
var later = function(name){ return preview && self.phaseStep(name) > k; };
|
|
228
|
+
var fM = later("marks"), fR = later("refs"), fO = later("roles");
|
|
229
|
+
if (fM) tm = Infinity;
|
|
230
|
+
if (fR) trf = Infinity;
|
|
231
|
+
if (fO) tro = Infinity;
|
|
232
|
+
var f1 = function(x){ return x.toFixed(1); };
|
|
233
|
+
// ---- 傍線:縦書きは字の右、横書きは字の下。二重傍線は 2 本。行をまたぐときは行ごとに順に引く
|
|
234
|
+
this.lines.forEach(function(o, j){
|
|
235
|
+
var e = pr(tm, j * P.draw * 0.8, P.draw), rs = self.rects(o.el), total = 0;
|
|
236
|
+
rs.forEach(function(r){ total += tate ? r.b - r.t : r.r - r.l; });
|
|
237
|
+
while (o.g.childNodes.length > (o.lab ? 1 : 0)) o.g.removeChild(o.g.lastChild);
|
|
238
|
+
if (fM) o.g.setAttribute("opacity", PV); else o.g.removeAttribute("opacity");
|
|
239
|
+
var left = e * total;
|
|
240
|
+
rs.forEach(function(r){
|
|
241
|
+
var len = tate ? r.b - r.t : r.r - r.l, d = Math.max(0, Math.min(len, left)); left -= len;
|
|
242
|
+
if (d <= 0) return;
|
|
243
|
+
for (var q = 0; q < o.r.line; q++){
|
|
244
|
+
var off = 3 + q * 5;
|
|
245
|
+
var attrs = tate ? {x1: f1(r.r + off), x2: f1(r.r + off), y1: f1(r.t), y2: f1(r.t + d)} : {x1: f1(r.l), x2: f1(r.l + d), y1: f1(r.b + off), y2: f1(r.b + off)};
|
|
246
|
+
attrs.stroke = "var(--emph)"; attrs["stroke-width"] = 2.2;
|
|
247
|
+
D.el("line", attrs, o.g);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
if (o.lab && rs.length){
|
|
251
|
+
var r0 = rs[0];
|
|
252
|
+
// 記号(A など)は線の始まりの外:縦書きは線の右の列の間で始まりより上、横書きは線の下の行の間
|
|
253
|
+
// 縦書きは線のすぐ右(列の間の、自分の列に寄ったところ)に、線の始まりから下へ
|
|
254
|
+
if (tate){ o.lab.setAttribute("x", f1(r0.r + 3 + o.r.line * 5 + 7)); o.lab.setAttribute("y", f1(r0.t + 22)); }
|
|
255
|
+
else { o.lab.setAttribute("x", f1(r0.l + 10)); o.lab.setAttribute("y", f1(r0.b + 3 + o.r.line * 5 + 20)); }
|
|
256
|
+
o.lab.setAttribute("opacity", pr(tm, j * P.draw * 0.8, 0.3).toFixed(3));
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
// ---- 指示語:指示語を四角で囲み、指す先に淡い色を敷き、指示語から指す先へ矢印
|
|
260
|
+
this.refs.forEach(function(o, j){
|
|
261
|
+
var a0 = j * (P.draw + 0.3), eb = pr(trf, a0, 0.3), ea = pr(trf, a0 + 0.25, P.draw);
|
|
262
|
+
var A = self.box(o.from), B = self.box(o.to);
|
|
263
|
+
while (o.box.firstChild) o.box.removeChild(o.box.firstChild);
|
|
264
|
+
while (o.fill.firstChild) o.fill.removeChild(o.fill.firstChild);
|
|
265
|
+
if (!A || !B){ o.box.setAttribute("opacity", 0); return; }
|
|
266
|
+
if (fR) eb = ea = PV;
|
|
267
|
+
D.el("rect", {x: f1(A.l - 3), y: f1(A.t - 2), width: f1(A.r - A.l + 6), height: f1(A.b - A.t + 4), rx: 5, fill: "none", stroke: "var(--emph)", "stroke-width": 2.5}, o.box);
|
|
268
|
+
self.rects(o.to).forEach(function(r){ D.el("rect", {x: f1(r.l - 2), y: f1(r.t), width: f1(r.r - r.l + 4), height: f1(r.b - r.t), rx: 4, fill: "var(--emph-tint)"}, o.fill); });
|
|
269
|
+
o.box.setAttribute("opacity", eb.toFixed(3)); o.fill.setAttribute("opacity", ea.toFixed(3));
|
|
270
|
+
// 矢印:指す先の行(字の箱)のうち指示語に近いものへ。同じ列(行)なら列の右(行の上)に弧、違えば列の頭(行の上)の側を通す
|
|
271
|
+
var ac = {x: (A.l + A.r) / 2, y: (A.t + A.b) / 2}, Bn = null, bd = Infinity;
|
|
272
|
+
self.rects(o.to).forEach(function(r){ var d = Math.hypot((r.l + r.r) / 2 - ac.x, (r.t + r.b) / 2 - ac.y); if (d < bd){ bd = d; Bn = r; } });
|
|
273
|
+
var x0, y0, x1, y1, cx, cy, same = tate ? Math.abs((Bn.l + Bn.r) / 2 - ac.x) < 6 : Math.abs((Bn.t + Bn.b) / 2 - ac.y) < 6;
|
|
274
|
+
if (tate && same){ var up = Bn.b <= A.t; x0 = A.r + 4; y0 = up ? A.t + 4 : A.b - 4; x1 = Bn.r + 4; y1 = up ? Bn.b - 4 : Bn.t + 4; cx = Math.max(x0, x1) + 44; cy = (y0 + y1) / 2; }
|
|
275
|
+
else if (tate){ x0 = ac.x; y0 = A.t - 4; x1 = (Bn.l + Bn.r) / 2; y1 = Bn.t - 4; cx = (x0 + x1) / 2; cy = Math.min(y0, y1) - 60; }
|
|
276
|
+
else if (same){ x0 = ac.x; y0 = A.t - 2; x1 = (Bn.l + Bn.r) / 2; y1 = Bn.t - 2; cx = (x0 + x1) / 2; cy = Math.min(y0, y1) - 46; }
|
|
277
|
+
else { var above = Bn.b <= A.t; x0 = ac.x; y0 = above ? A.t - 2 : A.b + 2; x1 = (Bn.l + Bn.r) / 2; y1 = above ? Bn.b + 2 : Bn.t - 2; cx = (x0 + x1) / 2 + 40; cy = (y0 + y1) / 2; }
|
|
278
|
+
// 指示語と指す先が同じ段落なら、弧の膨らみをその段落の枠の内側にとどめる(2 次曲線の頂は端と制御点の中ほど)
|
|
279
|
+
var para = o.from.parentNode === o.to.parentNode ? self.box(o.from.parentNode) : null, pad = 6;
|
|
280
|
+
if (para){
|
|
281
|
+
var mid = function(a, b){ return (a + b) / 2; };
|
|
282
|
+
if (cy < mid(y0, y1)) cy = Math.max(cy, 2 * (para.t + pad) - mid(y0, y1));
|
|
283
|
+
if (cx > mid(x0, x1)) cx = Math.min(cx, 2 * (para.r - pad) - mid(x0, x1));
|
|
284
|
+
}
|
|
285
|
+
o.path.setAttribute("d", "M" + f1(x0) + "," + f1(y0) + "Q" + f1(cx) + "," + f1(cy) + " " + f1(x1) + "," + f1(y1));
|
|
286
|
+
o.path.setAttribute("stroke-dashoffset", (fR ? 0 : 1 - ea).toFixed(4));
|
|
287
|
+
o.path.setAttribute("opacity", fR ? PV : ea > 0 ? 1 : 0);
|
|
288
|
+
o.head.setAttribute("transform", "translate(" + f1(x1) + " " + f1(y1) + ") rotate(" + (Math.atan2(y1 - cy, x1 - cx) * 180 / Math.PI).toFixed(1) + ")");
|
|
289
|
+
o.head.setAttribute("opacity", fR ? PV : ea >= 0.98 ? 1 : 0);
|
|
290
|
+
});
|
|
291
|
+
// ---- 段落の枠:順に囲み、札を出し、最後につなぐ線
|
|
292
|
+
var nb = this.boxes.length, tLink = nb * 0.35 + P.draw;
|
|
293
|
+
var boxOf = {}, chipOf = {};
|
|
294
|
+
this.boxes.forEach(function(o, j){
|
|
295
|
+
var e = pr(tro, j * 0.35, P.draw), el = o.P2.el;
|
|
296
|
+
var x = el.offsetLeft, y = el.offsetTop, w = el.offsetWidth, h = el.offsetHeight;
|
|
297
|
+
// offset は .text の中の座標。.text は部品の左上にある
|
|
298
|
+
boxOf[o.P2.p.id || j] = {x: x, y: y, w: w, h: h};
|
|
299
|
+
o.rect.setAttribute("x", x); o.rect.setAttribute("y", y); o.rect.setAttribute("width", w); o.rect.setAttribute("height", h);
|
|
300
|
+
o.rect.setAttribute("stroke-dashoffset", (1 - e).toFixed(4));
|
|
301
|
+
o.rect.setAttribute("opacity", fO ? PV : e > 0 ? 1 : 0);
|
|
302
|
+
// 札:縦書きは枠の上の辺の右寄り、横書きは左上の角
|
|
303
|
+
var tw = Array.from(o.P2.p.role).length * 24 + 24;
|
|
304
|
+
var cx = tate ? x + w - tw / 2 - 12 : x + tw / 2 + 12, cy = tate ? y - 17 : y - 17;
|
|
305
|
+
o.cr.setAttribute("x", f1(cx - tw / 2)); o.cr.setAttribute("y", f1(cy - 17)); o.cr.setAttribute("width", tw);
|
|
306
|
+
o.ct.setAttribute("x", f1(cx)); o.ct.setAttribute("y", f1(cy + 8.5));
|
|
307
|
+
o.chip.setAttribute("opacity", (fO ? PV : pr(tro, j * 0.35 + P.draw * 0.5, 0.3)).toFixed(3));
|
|
308
|
+
chipOf[o.P2.p.id || j] = {l: cx - tw / 2, r: cx + tw / 2, t: cy - 17, b: cy + 17, at: []};
|
|
309
|
+
});
|
|
310
|
+
// 札に付く線の端:縦書きは札の上の辺に左から、横書きは札の左の辺に上から並べる。
|
|
311
|
+
// 相手が左(上)にある線を先に、段の低い順に。相手が右(下)にある線は後に、段の高い順に(縦の線が横の線を横切らないように)
|
|
312
|
+
var ends = [];
|
|
313
|
+
this.links.forEach(function(o){
|
|
314
|
+
var A = chipOf[o.a.p.id], B = chipOf[o.b.p.id];
|
|
315
|
+
if (!A || !B) return;
|
|
316
|
+
var ca = tate ? (A.l + A.r) / 2 : (A.t + A.b) / 2, cb = tate ? (B.l + B.r) / 2 : (B.t + B.b) / 2;
|
|
317
|
+
o.ea = {link: o, chip: A, dir: cb < ca ? -1 : 1}; o.eb = {link: o, chip: B, dir: ca < cb ? -1 : 1};
|
|
318
|
+
A.at.push(o.ea); B.at.push(o.eb); ends.push(A, B);
|
|
319
|
+
});
|
|
320
|
+
ends.forEach(function(C){
|
|
321
|
+
if (C.done) return; C.done = true;
|
|
322
|
+
C.at.sort(function(p, q){ return p.dir !== q.dir ? p.dir - q.dir : p.dir < 0 ? p.link.lv - q.link.lv : q.link.lv - p.link.lv; });
|
|
323
|
+
var n = C.at.length;
|
|
324
|
+
C.at.forEach(function(e, i){
|
|
325
|
+
if (tate){ e.x = C.l + (C.r - C.l) * (i + 1) / (n + 1); e.y = C.t - 1; }
|
|
326
|
+
else { e.x = C.l - 1; e.y = C.t + (C.b - C.t) * (i + 1) / (n + 1); }
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
this.links.forEach(function(o){
|
|
330
|
+
if (!o.ea){ o.path.setAttribute("opacity", 0); o.h1.setAttribute("opacity", 0); if (o.h0) o.h0.setAttribute("opacity", 0); return; }
|
|
331
|
+
var e = pr(tro, tLink, P.draw), d, ang1, ang0, x0 = o.ea.x, y0 = o.ea.y, x1 = o.eb.x, y1 = o.eb.y, rr = 8;
|
|
332
|
+
if (tate){
|
|
333
|
+
// 札の上の辺から上へ出て、段の高さを横に通り、相手の札の上の辺へ下りる(角は丸める)
|
|
334
|
+
var top = Math.min(o.ea.chip.t, o.eb.chip.t), yl = top - STUB - (o.lv - 1) * STEP, sx = x1 < x0 ? -1 : 1;
|
|
335
|
+
d = "M" + f1(x0) + "," + f1(y0) + "V" + f1(yl + rr) + "Q" + f1(x0) + "," + f1(yl) + " " + f1(x0 + sx * rr) + "," + f1(yl) +
|
|
336
|
+
"H" + f1(x1 - sx * rr) + "Q" + f1(x1) + "," + f1(yl) + " " + f1(x1) + "," + f1(yl + rr) + "V" + f1(y1);
|
|
337
|
+
ang1 = 90; ang0 = 90;
|
|
338
|
+
} else {
|
|
339
|
+
// 札の左の辺から左へ出て、段の位置を縦に通り、相手の札の左の辺へ
|
|
340
|
+
var lft = Math.min(o.ea.chip.l, o.eb.chip.l), xl = lft - STUB - (o.lv - 1) * STEP, sy = y1 < y0 ? -1 : 1;
|
|
341
|
+
d = "M" + f1(x0) + "," + f1(y0) + "H" + f1(xl + rr) + "Q" + f1(xl) + "," + f1(y0) + " " + f1(xl) + "," + f1(y0 + sy * rr) +
|
|
342
|
+
"V" + f1(y1 - sy * rr) + "Q" + f1(xl) + "," + f1(y1) + " " + f1(xl + rr) + "," + f1(y1) + "H" + f1(x1);
|
|
343
|
+
ang1 = 0; ang0 = 0;
|
|
344
|
+
}
|
|
345
|
+
o.path.setAttribute("d", d);
|
|
346
|
+
o.path.setAttribute("stroke-dasharray", "1"); o.path.setAttribute("stroke-dashoffset", (1 - e).toFixed(4));
|
|
347
|
+
o.path.setAttribute("opacity", fO ? PV : e > 0 ? 1 : 0);
|
|
348
|
+
o.h1.setAttribute("transform", "translate(" + f1(x1) + " " + f1(y1) + ") rotate(" + ang1 + ")");
|
|
349
|
+
o.h1.setAttribute("opacity", fO ? PV : e >= 0.98 ? 1 : 0);
|
|
350
|
+
if (o.h0){ o.h0.setAttribute("transform", "translate(" + f1(x0) + " " + f1(y0) + ") rotate(" + ang0 + ")"); o.h0.setAttribute("opacity", fO ? PV : e >= 0.98 ? 1 : 0); }
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
});
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// m-sweep:パラメータを動かして関数の形の変化を見せる。前の形は灰色で残す
|
|
2
|
+
// <m-sweep f="u*u + c*u*u*u + c*c*u**4" values="[0,0.5,1]" xr="[-3,3]" yr="[0,16]" xt="[-2,0,2]" yt="[0,5,10,15]"
|
|
3
|
+
// xl="*u*" yl="損失" param="c" style="height:380px"></m-sweep>
|
|
4
|
+
// 段階 k(1〜values.length-1)で、値を values[k-1] から values[k] へ動かす。at="[0.5, 3]" なら変化をすべて段階 1 に入れ、
|
|
5
|
+
// i 番目の変化を at[i] 秒から始める。point='{"u": 9.8, "label": "平均待ち {y} 日"}' は u の所の曲線の上の点(値の変化について動く)
|
|
6
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity、plot の Plot、expr の compile を使い、
|
|
7
|
+
// プレイヤーのグローバルは使わない(1.x は式の評価器 egatari-expr を写して持っていた)
|
|
8
|
+
egatariParts.define({name: "sweep", version: "2.1.2", requires: {base: "1.2.0", expr: "1.0.0", plot: "1.1.2"}, element: "m-sweep"}, function(deps){
|
|
9
|
+
"use strict";
|
|
10
|
+
var base = deps.base, plot = deps.plot, expr = deps.expr;
|
|
11
|
+
// 関数 f を [a, b] で n 分割した点列(px)。有限でない値(NaN・±Infinity)の点は null
|
|
12
|
+
function samples(p, f, a, b, n){
|
|
13
|
+
var out = [];
|
|
14
|
+
for (var i = 0; i <= n; i++){ var v = a + (b - a) * i / n, x = p.x(v), y = p.y(f(v)); out.push(isFinite(x) && isFinite(y) ? [x, y] : null); }
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
// 点列の d。null の所で線を切り、次の有限な点から M で引き直す(plot の p.d と同じ字。切れ目がなければ同じ d)
|
|
18
|
+
function pathOf(pts){
|
|
19
|
+
var d = "", pen = false;
|
|
20
|
+
pts.forEach(function(q){ if (q){ d += (pen ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); pen = true; } else pen = false; });
|
|
21
|
+
return d;
|
|
22
|
+
}
|
|
23
|
+
// 線分 s = [[x, y], [x, y]] が箱 r = [x0, y0, x1, y1] にかかるか(Liang–Barsky)
|
|
24
|
+
function segHitsBox(s, r){
|
|
25
|
+
var x = s[0][0], y = s[0][1], dx = s[1][0] - x, dy = s[1][1] - y, t0 = 0, t1 = 1;
|
|
26
|
+
var pp = [-dx, dx, -dy, dy], qq = [x - r[0], r[2] - x, y - r[1], r[3] - y];
|
|
27
|
+
for (var i = 0; i < 4; i++){
|
|
28
|
+
if (pp[i] === 0){ if (qq[i] < 0) return false; continue; }
|
|
29
|
+
var u = qq[i] / pp[i];
|
|
30
|
+
if (pp[i] < 0){ if (u > t1) return false; if (u > t0) t0 = u; }
|
|
31
|
+
else { if (u < t0) return false; if (u < t1) t1 = u; }
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
// 灰色の線の名前の置き場所:その線のすぐ上か下に、どの線(自分の線も)にもかからないように置く(線の上に字を重ねない)。
|
|
36
|
+
// 候補は自分の線の描かれている点ごとに、字の箱を点の上・下(6 px 離す)、点を中心・左端・右端にした 6 通り。
|
|
37
|
+
// bd(字を置ける範囲)の中で、置いた字(boxes)に重ならず、線にかかる数が最も少なく(1 本 1000)、自分の線に近く、
|
|
38
|
+
// ほかの線から離れている所(40 px まで)。w は字の幅の見積もり、fs は字の大きさ。置けなければ null
|
|
39
|
+
function placeOn(own, w, fs, lines, boxes, bd, cl){
|
|
40
|
+
var best = null, bc = Infinity;
|
|
41
|
+
var hits = function(L, r){
|
|
42
|
+
var q = [Math.max(r[0], cl[0]), Math.max(r[1], cl[1]), Math.min(r[2], cl[2]), Math.min(r[3], cl[3])];
|
|
43
|
+
if (q[0] >= q[2] || q[1] >= q[3]) return false;
|
|
44
|
+
for (var i = 1; i < L.length; i++) if (L[i - 1] && L[i] && segHitsBox([L[i - 1], L[i]], q)) return true;
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
var near = function(L, r){
|
|
48
|
+
var g = 40;
|
|
49
|
+
L.forEach(function(z){ if (z && z[0] >= cl[0] && z[0] <= cl[2] && z[1] >= cl[1] && z[1] <= cl[3]) g = Math.min(g, Math.hypot(Math.max(r[0] - z[0], 0, z[0] - r[2]), Math.max(r[1] - z[1], 0, z[1] - r[3]))); });
|
|
50
|
+
return g;
|
|
51
|
+
};
|
|
52
|
+
for (var j = 0; j < own.length; j += 3){
|
|
53
|
+
var q = own[j];
|
|
54
|
+
if (!q || q[0] < cl[0] || q[0] > cl[2] || q[1] < cl[1] || q[1] > cl[3]) continue; // 描かれている点だけ
|
|
55
|
+
[-1, 1].forEach(function(side){
|
|
56
|
+
[0.5, 0, 1].forEach(function(f){
|
|
57
|
+
// side −1:箱の下の端が点の 6 px 上。+1:箱の上の端が点の 6 px 下。f:点が箱の横の何割の所か
|
|
58
|
+
var y = side < 0 ? q[1] - 6 - fs * 0.22 : q[1] + 6 + fs * 0.88, x0 = q[0] - w * f;
|
|
59
|
+
var r = [x0, y - fs * 0.88, x0 + w, y + fs * 0.22];
|
|
60
|
+
if (r[0] < bd[0] || r[2] > bd[2] || r[1] < bd[1] || r[3] > bd[3]) return;
|
|
61
|
+
if (boxes.some(function(b){ return r[0] < b[2] + 6 && b[0] < r[2] + 6 && r[1] < b[3] + 4 && b[1] < r[3] + 4; })) return;
|
|
62
|
+
var c = 0, r3 = [r[0] - 3, r[1] - 3, r[2] + 3, r[3] + 3], gap = 40;
|
|
63
|
+
lines.forEach(function(L){ if (hits(L, r3)) c += 1000; else if (L !== own) gap = Math.min(gap, near(L, r)); });
|
|
64
|
+
if (hits(own, r3) && lines.indexOf(own) < 0) c += 1000;
|
|
65
|
+
c += 40 - gap + (f === 0.5 ? 0 : 2);
|
|
66
|
+
if (c < bc){ bc = c; best = {x: x0 + w / 2, y: y, box: r, hits: Math.floor(c / 1000)}; }
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return best;
|
|
71
|
+
}
|
|
72
|
+
return class extends base.MotionElement {
|
|
73
|
+
static partName = "sweep"; // the registry name (define meta name), for report prefixes
|
|
74
|
+
// データの形(kit/shape.js):JSON の子はなく、属性で書く(values は数の配列、2 つ以上)
|
|
75
|
+
static shape = {schema: null, example: '<m-sweep f="u*u + c*u" values="[0,0.5,1]" xr="[-3,3]" yr="[0,10]"></m-sweep>'};
|
|
76
|
+
static props = {
|
|
77
|
+
f: {type: "string", default: "u*u", doc: "関数の式(算術の式。変数は横軸 u とパラメータ c。Math.exp(…) などの Math の関数と定数、+ - * / % **、比較と ? : が使える)"},
|
|
78
|
+
values: {type: "json", default: [0, 1], doc: "パラメータの値の列。ステップごとに次の値へ動く", shape: {type: "array", items: {type: "number"}, minItems: 2}, example: [0, 0.5, 1]},
|
|
79
|
+
param: {type: "string", default: "c", doc: "表示するパラメータの名前"},
|
|
80
|
+
xr: {type: "json", default: [-3, 3]}, yr: {type: "json", default: [0, 10]},
|
|
81
|
+
xt: {type: "json", default: []}, yt: {type: "json", default: []},
|
|
82
|
+
xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
|
|
83
|
+
digits: {type: "number", default: 2, doc: "表示する値の小数の桁数"},
|
|
84
|
+
at: {type: "json", default: null, doc: "変化ごとの開始秒(増える順)。あれば全部をステップ 1 で", shape: {type: "array", items: {type: "number"}}, example: [0.5, 3]},
|
|
85
|
+
point: {type: "json", default: null, doc: "曲線上の点 {u, label({y} = 値), digits}", shape: {type: "object", properties: {u: {type: "number"}, label: {type: "string"}, digits: {type: "number"}}, required: ["u"]}, example: {u: 9.8, label: "平均待ち {y} 日", digits: 1}},
|
|
86
|
+
dur: {type: "number", default: 1.2, doc: "1 ステップの動きの秒数"},
|
|
87
|
+
size: {type: "number", default: 0, doc: "字の大きさ(24 以上。0 = 既定)"},
|
|
88
|
+
};
|
|
89
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.ats ? 1 : this.props.values.length - 1; }
|
|
90
|
+
// at のときの変化の開始秒(なければ null)。数でない・数が合わない・減る列は知らせて、段階ごとの動きに戻す
|
|
91
|
+
get ats(){
|
|
92
|
+
var A = this.props.at, n = this.props.values.length - 1;
|
|
93
|
+
if (A === null || A === undefined) return null;
|
|
94
|
+
if (!Array.isArray(A) || A.length !== n || A.some(function(x, i){ return typeof x !== "number" || !isFinite(x) || x < 0 || (i > 0 && x < A[i - 1]); })) return null;
|
|
95
|
+
return A;
|
|
96
|
+
}
|
|
97
|
+
mount(ctx){
|
|
98
|
+
var P = this.props, D = base, self = this;
|
|
99
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
100
|
+
// 式は木にしてから計算する(コードとしては実行しない。Egatari spec §6)。書けない式は SyntaxError で、base が受け止めて札を出す(spec §6.1 Containment)
|
|
101
|
+
var g = expr.compile(P.f, {name: "f", vars: ["u", "c"]});
|
|
102
|
+
this.g = function(c){ return function(u){ return g(u, c); }; };
|
|
103
|
+
// size:字の大きさ(24 未満は 24 にして知らせる)。0 なら 2.0 と同じ大きさと余白
|
|
104
|
+
var S = P.size > 0 ? Math.max(24, P.size) : 0, k = S ? S / 26 : 1;
|
|
105
|
+
if (P.size > 0 && P.size < 24) ctx.report("attr", "[sweep] size " + P.size + " is under 24 px; 24 is used");
|
|
106
|
+
this.fs = {lab: S ? Math.round(S * 1.04) : 27, ghost: S ? Math.max(24, Math.round(S * 0.92)) : 24, pt: S || 26};
|
|
107
|
+
var p = this.p = plot.Plot(this, {xr: P.xr, yr: P.yr, xt: P.xt, yt: P.yt, xl: P.xl, yl: P.yl, fs: S || undefined, m: {l: Math.round(86 * k), r: 10, t: Math.round(40 * k), b: Math.round(64 * k)}});
|
|
108
|
+
this.ghosts = P.values.map(function(){ return D.el("path", {fill: "none", stroke: "var(--line)", "stroke-width": 2.5, "clip-path": p.clip, opacity: 0}, p.svg); });
|
|
109
|
+
// 有限でない値のある線は、その所で切って引き、値ごとに 1 回知らせる
|
|
110
|
+
var pts = P.values.map(function(v, i){
|
|
111
|
+
var q = samples(p, self.g(v), P.xr[0], P.xr[1], 300);
|
|
112
|
+
self.ghosts[i].setAttribute("d", pathOf(q));
|
|
113
|
+
if (q.indexOf(null) >= 0) ctx.report("data", "[sweep] f is not a finite number (NaN or ±Infinity) at some u for " + P.param + " = " + v + "; the line is broken there");
|
|
114
|
+
return q;
|
|
115
|
+
});
|
|
116
|
+
this.cur = D.el("path", {fill: "none", stroke: "var(--emph)", "stroke-width": 3.5, "clip-path": p.clip}, p.svg);
|
|
117
|
+
if (P.at !== null && P.at !== undefined && !this.ats) ctx.report("attr", "[sweep] at must be " + (P.values.length - 1) + " non-negative seconds in increasing order (one per change); each change gets its own step instead");
|
|
118
|
+
var A = this.ats; if (A) for (var j = 1; j < A.length; j++) if (A[j] < A[j - 1] + P.dur) { ctx.report("attr", "[sweep] change " + (j + 1) + " starts at " + A[j] + " s, before change " + j + " ends (" + (A[j - 1] + P.dur) + " s); it takes over from there"); break; }
|
|
119
|
+
// 曲線の上の点:u の所の f。値ごとに図の中にあるか確かめる(外なら知らせて、その間は点と字を隠す)
|
|
120
|
+
this.pt = null;
|
|
121
|
+
if (P.point !== null && P.point !== undefined){
|
|
122
|
+
var pt = P.point;
|
|
123
|
+
if (!pt || typeof pt !== "object" || typeof pt.u !== "number" || !isFinite(pt.u)) ctx.report("attr", "[sweep] point needs a number u (where on the curve)");
|
|
124
|
+
else {
|
|
125
|
+
if (pt.u < Math.min(P.xr[0], P.xr[1]) || pt.u > Math.max(P.xr[0], P.xr[1])) ctx.report("range", "[sweep] point.u = " + pt.u + " is outside xr");
|
|
126
|
+
P.values.forEach(function(v){ var y = self.g(v)(pt.u); if (!isFinite(y) || y < Math.min(P.yr[0], P.yr[1]) || y > Math.max(P.yr[0], P.yr[1])) ctx.report("range", "[sweep] the point at u = " + pt.u + " is " + (isFinite(y) ? y : "not a number") + " for " + P.param + " = " + v + ", outside yr (hidden there)"); });
|
|
127
|
+
this.pt = {u: pt.u, label: typeof pt.label === "string" ? pt.label : "", digits: typeof pt.digits === "number" ? pt.digits : P.digits,
|
|
128
|
+
dot: D.el("circle", {r: 9, fill: "var(--emph)", stroke: "var(--bg)", "stroke-width": 3}, p.svg),
|
|
129
|
+
text: D.el("text", {fill: "var(--emph)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": this.fs.pt}, p.svg)};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.lab = D.mtext(p.svg, p.m.l + 10, Math.round(30 * k), "", {fill: "var(--emph)", "font-size": this.fs.lab});
|
|
133
|
+
// 灰色の線の名前(「σ = 0.5」):最後の段階で残る線(最後の値と違う値。同じ値は最初の 1 本)に、--muted の 24px で線の上に(背景色で縁取って)書く。
|
|
134
|
+
// 5 本以上なら最初と最後だけ。置き場所は最後の段階の形(今の線と灰色の線)で決め、灰色の線が見えている間だけ出す
|
|
135
|
+
var V = P.values, L = V.length - 1, fs = this.fs.ghost, wOf = function(str){ return D.textWidth(str, fs, {font: self, mark: true}); }; // base の textWidth(記法の * _ ^ を除く)
|
|
136
|
+
var shown = [];
|
|
137
|
+
V.forEach(function(v, i){ if (i < L && v !== V[L] && V.indexOf(v) === i) shown.push(i); });
|
|
138
|
+
if (shown.length > 4) shown = [shown[0], shown[shown.length - 1]];
|
|
139
|
+
var LS = this.fs.lab, LY = Math.round(30 * k), lw = 0; V.forEach(function(v){ lw = Math.max(lw, wOf(P.param + " = " + v.toFixed(P.digits)) * LS / fs); });
|
|
140
|
+
var boxes = [[p.m.l + 10, LY - LS * 0.88, p.m.l + 10 + lw, LY + LS * 0.22]];
|
|
141
|
+
// 曲線の上の点の字(最後の値の所)にも灰色の線の名前をかけない
|
|
142
|
+
if (this.pt){ var fa = this.ptAt(V[L]); if (fa.inside && fa.str) boxes.push(fa.box); }
|
|
143
|
+
var lines = [pts[L]].concat(V.map(function(v, i){ return i < L && v !== V[L] ? pts[i] : null; }).filter(Boolean));
|
|
144
|
+
// 字は図の中か上の余白に(横軸の目盛りの数字にはかからない)。線は clip の中だけ描かれる
|
|
145
|
+
var bd = [p.m.l + 4, 4, p.W - p.m.r, p.H - p.m.b - 2], cl = [p.m.l, p.m.t - 4, p.W - p.m.r, p.H - p.m.b];
|
|
146
|
+
this.glabs = [];
|
|
147
|
+
shown.forEach(function(i){
|
|
148
|
+
var str = P.param + " = " + V[i].toFixed(P.digits), at = placeOn(pts[i], wOf(str), fs, lines, boxes, bd, cl);
|
|
149
|
+
if (!at){ ctx.report("layout", "[sweep] no free place for the name of the grey line " + JSON.stringify(str) + " (not drawn)"); return; }
|
|
150
|
+
if (at.hits) ctx.report("layout", "[sweep] the name of the grey line " + JSON.stringify(str) + " crosses a line (no free place beside it); give the element more room or a shorter param");
|
|
151
|
+
boxes.push(at.box);
|
|
152
|
+
self.glabs.push({i: i, el: D.mtext(p.svg, +at.x.toFixed(1), +at.y.toFixed(1), str, {"text-anchor": "middle", fill: "var(--muted)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": fs, opacity: 0})});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// 曲線の上の点の置き場所(値 c のとき):点、字({y} を今の値に)、字の箱。字は点の右上、図の右端に近ければ左上。図の外なら inside = false
|
|
156
|
+
ptAt(c){
|
|
157
|
+
var q = this.pt, P = this.props, p = this.p, y = this.g(c)(q.u), inside = isFinite(y) && y >= Math.min(P.yr[0], P.yr[1]) && y <= Math.max(P.yr[0], P.yr[1]);
|
|
158
|
+
var X = p.x(q.u), Y = inside ? p.y(y) : 0, str = q.label.replace(/\{y\}/g, inside ? y.toFixed(q.digits) : "");
|
|
159
|
+
var F = this.fs.pt, w = base.textWidth(str, F, {font: this}), right = X + 14 + w <= p.W - p.m.r, tx = right ? X + 14 : X - 14, ty = Math.max(p.m.t + F * 0.8, Y - 14);
|
|
160
|
+
return {inside: inside, X: X, Y: Y, str: str, tx: tx, ty: ty, anchor: right ? "start" : "end", box: [right ? tx : tx - w, ty - F * 0.88, right ? tx + w : tx, ty + F * 0.22]};
|
|
161
|
+
}
|
|
162
|
+
duration(k){ var A = this.ats; return k >= 1 ? (A ? A[A.length - 1] + this.props.dur : this.props.dur) : 0; }
|
|
163
|
+
// 変化の始まり(at のとき):口述原稿の {cue} に合わせる同期点
|
|
164
|
+
cues(k){ var A = this.ats; return A && k === 1 ? A.slice() : null; }
|
|
165
|
+
render(k, t, ctx){
|
|
166
|
+
var P = this.props, V = P.values, preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0;
|
|
167
|
+
// 先を薄く見せる表示:後の段階で動いていく先の値の線を、強調の色でテーマの --preview-opacity(なければ 0.45)で描く
|
|
168
|
+
// pos:始まった変化の数(灰色の線と先を見せる線の境)。at なら段階 1 の中の秒で、なければ段階で決まる
|
|
169
|
+
var A = this.ats, c, pos;
|
|
170
|
+
if (A){
|
|
171
|
+
pos = 0; c = V[0];
|
|
172
|
+
if (k >= 1) for (var i = 0; i < A.length; i++) if (t >= A[i]){ pos = i + 1; c = base.lerp(V[i], V[i + 1], base.prog(t, A[i], P.dur)); }
|
|
173
|
+
} else {
|
|
174
|
+
var to = V[Math.min(k, V.length - 1)], from = k >= 1 ? V[k - 1] : to;
|
|
175
|
+
c = base.lerp(from, to, base.prog(t, 0, P.dur)); pos = Math.min(k, V.length - 1);
|
|
176
|
+
}
|
|
177
|
+
this.cur.setAttribute("d", pathOf(samples(this.p, this.g(c), P.xr[0], P.xr[1], 300)));
|
|
178
|
+
this.lab.textContent = P.param + " = " + c.toFixed(P.digits);
|
|
179
|
+
V.forEach(function(v, i){
|
|
180
|
+
var e = this.ghosts[i], ahead = preview && i > pos && v !== c, col = ahead ? "var(--emph)" : "var(--line)";
|
|
181
|
+
// style は base.el と同じ書き方で書く(style.stroke に代入すると "stroke: var(--x);" になり、作った直後と字が変わる)
|
|
182
|
+
e.setAttribute("style", "stroke:" + col + ";");
|
|
183
|
+
e.setAttribute("opacity", ahead ? PV : i < pos && v !== c ? 1 : 0);
|
|
184
|
+
}, this);
|
|
185
|
+
// 灰色の線の名前は、その線が灰色で見えている間だけ
|
|
186
|
+
this.glabs.forEach(function(o){ o.el.setAttribute("opacity", o.i < pos && V[o.i] !== c ? 1 : 0); });
|
|
187
|
+
// 曲線の上の点と、その字({y} は今の値)。字は点の右上、図の右端に近ければ左上。図の外の値なら隠す
|
|
188
|
+
var q = this.pt;
|
|
189
|
+
if (q){
|
|
190
|
+
var a = this.ptAt(c);
|
|
191
|
+
q.dot.setAttribute("cx", a.X.toFixed(1)); q.dot.setAttribute("cy", a.Y.toFixed(1)); q.dot.setAttribute("opacity", a.inside ? 1 : 0);
|
|
192
|
+
q.text.setAttribute("x", a.tx.toFixed(1)); q.text.setAttribute("y", a.ty.toFixed(1)); q.text.setAttribute("text-anchor", a.anchor);
|
|
193
|
+
if (q.text.textContent !== a.str) q.text.textContent = a.str;
|
|
194
|
+
q.text.setAttribute("opacity", a.inside && a.str ? 1 : 0);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Scatter plot; point series by step, then a trend line (least squares or 2 points)
|
|
3
|
+
steps: series + trend (default 1 series = 1 step, lines 1 step)
|
|
4
|
+
props:
|
|
5
|
+
xr: x range
|
|
6
|
+
yr: y range
|
|
7
|
+
xt: x ticks
|
|
8
|
+
yt: y ticks
|
|
9
|
+
xf: x tick decimals
|
|
10
|
+
yf: y tick decimals
|
|
11
|
+
xl: x title
|
|
12
|
+
yl: y title
|
|
13
|
+
r: point radius px
|
|
14
|
+
dur: step seconds
|
|
15
|
+
example: {"series": [{"label": "Sunny", "points": [[24, 210], [28, 380], [31, 560], {"x": 34, "y": 690, "label": "Heatwave"}]}], "trend": "linear"}
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
Relation of two quantities (heat vs sales). Points, then trend.
|
|
19
|
+
|
|
20
|
+
Child JSON: `{"series": [...], "trend": ...}`.
|
|
21
|
+
|
|
22
|
+
- series: `points` (`[x, y]` or `{"x", "y", "label", "anchor", "tone"}`), `label` (series name, top with marker), `tone` (`term` `emph` `accent2` `muted` `fg` `series-1..4`), `step` (1 series = 1 step; same = together), `at` (start s)
|
|
23
|
+
- Point `label` placed clear of overlaps (`anchor` = first try: `right` `left` `above` `below`); outliers only
|
|
24
|
+
- Marker shape per series; repeats after 4, so ≤ 4 series
|
|
25
|
+
- trend: `"linear"` (least squares on all points), or `{"fit": "linear", "series": 0, "label", "tone", "dash", "step", "at", "digits"}`, or `{"pts": [[x0, y0], [x1, y1]]}` (segment; exactly 2 points; vertical OK); several = array
|
|
26
|
+
- `series`: fitted series index from 0, or array (default all)
|
|
27
|
+
- `label`: `{r}` correlation, `{a}` slope, `{b}` intercept (`digits`, default 2), e.g. `"Trend (r = {r})"`
|
|
28
|
+
- `step`: default after the last series
|
|
29
|
+
- Clipped to the plot; lines outside reported. Vertical `pts`: `{a}` `{b}` empty; `{r}` only for fits
|
|
30
|
+
- Axes: `xr` `yr` range, `xt` `yt` ticks, `xf` `yf` decimals, `xl` `yl` titles; range/ticks auto if omitted
|
|
31
|
+
- `variant`: `fade` (default), `sweep` (left to right), `grow` (points grow, line from the middle)
|
|
32
|
+
- Show later steps faintly (`ctx.preview`): later points and lines faint
|
|
33
|
+
|
|
34
|
+
The demo is `demo.html`. All numbers are fictional.
|
|
35
|
+
|
|
36
|
+
<!-- llm: omit -->
|
|
37
|
+
Notes
|
|
38
|
+
|
|
39
|
+
- Marker shapes: circle, square, triangle, diamond (colour not relied on); repeat after 4. Point labels try right → left → above → below
|
|
40
|
+
- Fits span the fitted x range, `pts` the 2 points
|
|
41
|
+
- Step length `dur` (default 1 s): points in 0.7 s, then point and series names; line names after the line is drawn
|
|
42
|
+
- `sweep` only orders points; `grow` only scales them; nothing moves (conventions §1.2). No rise-from-below variant: it would move more than variant 0
|
|
43
|
+
- Text width estimated from characters; no room for a name is reported (`ctx.report`)
|
|
44
|
+
<!-- llm: end -->
|