egatari 0.6.16 → 0.6.18
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 +43 -1
- package/README.ja.md +14 -13
- package/README.md +2 -1
- package/components.lock.json +119 -45
- package/components2.lock.json +639 -1
- package/kit/check-messages.mjs +5 -0
- package/kit/check.mjs +6 -0
- package/kit/core/bookmark.mjs +28 -0
- package/kit/core/build-core.mjs +4 -2
- package/kit/core/check-parity.mjs +4 -0
- package/kit/core/check-rules.mjs +3 -2
- package/kit/core/check-source.mjs +6 -0
- package/kit/core/llm-pack-assemble.mjs +37 -66
- package/kit/core/llm-pack-data.mjs +839 -45
- package/kit/core/llm-pack.mjs +6 -4
- package/kit/core/llm-request.mjs +2 -2
- package/kit/core/new-deck-pack.mjs +38 -44
- package/kit/core/new-deck.mjs +82 -74
- package/kit/core/part-labels.mjs +2 -0
- package/kit/core/purposes.mjs +9 -3
- package/kit/core/sample-info.mjs +17 -3
- package/kit/core/slide-ops.mjs +22 -0
- package/kit/core/tate-mix.mjs +25 -0
- package/kit/core/theme-derive.mjs +56 -17
- package/kit/core/theme-shapes.mjs +15 -1
- package/kit/deck.js +53 -2
- package/kit/instruction-version.json +1 -1
- package/kit/llm-pack.mjs +5 -7
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/presenter.js +36 -4
- package/kit/tools.js +54 -2
- package/package.json +1 -1
- package/vendor/components/CATALOG.md +24 -22
- package/vendor/components/sha256/038f9d32c89c8212ab25d6e3180023b6fe024a53053ab2ef1443ecab92e3ce43/index.js +205 -0
- package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/README.en.md +44 -0
- package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/index.js +306 -0
- package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/README.en.md +54 -0
- package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/index.js +470 -0
- package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/README.en.md +23 -0
- package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/index.js +289 -0
- package/vendor/components/sha256/0c25d49d23529879054737aa181951519fe585c4728fd505e0e3c8869953eac7/index.js +934 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/LICENSE-strokesvg.txt +115 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/OFL.txt +93 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/index.js +755 -0
- package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/strokes-CHANGES.md +20 -0
- package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/README.en.md +25 -0
- package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/index.js +317 -0
- package/vendor/components/sha256/12ef6a11055407f5cddc40154a49cf2737b0786429fe0fcc94ee1d8245597b40/index.js +244 -0
- package/vendor/components/sha256/13c9ce43396b2f5693ce430a924dae4ddcd1e8a4ad0c9b9e724ff52acb874d0c/index.js +354 -0
- package/vendor/components/sha256/1a0f21def0efbbdef64461cafa40f3883bc7f7122adf79d01f09ca4a245e5dcb/index.js +465 -0
- package/vendor/components/sha256/208175d05b37d326855fad792b10137f785e5d05d91a2cde119d0dbd69d2ed98/index.js +100 -0
- package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/README.en.md +34 -0
- package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/index.js +246 -0
- package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/README.en.md +24 -0
- package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/index.js +554 -0
- package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/README.en.md +28 -0
- package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/index.js +214 -0
- package/vendor/components/sha256/2a011338d0fc3c77e102eaa57cde2b6e3726bc279f133174b0b8c9a654263cbc/index.js +824 -0
- package/vendor/components/sha256/2fce5ab0c31dca0aa1586a2c69237870a9cce46c0bc6ab7392c27968d016bd15/index.js +75 -0
- package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/README.en.md +23 -0
- package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/index.js +150 -0
- package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/README.en.md +18 -0
- package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/index.js +279 -0
- package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/README.en.md +42 -0
- package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/index.js +272 -0
- package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/README.en.md +30 -0
- package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/index.js +305 -0
- package/vendor/components/sha256/4c8cae404d551a1bb021e8345af5aa45d4f412f13497aa84b142f11a29a365dc/index.js +124 -0
- package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/README.en.md +23 -0
- package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/index.js +120 -0
- package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/README.en.md +18 -0
- package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/index.js +243 -0
- package/vendor/components/sha256/631f4c4b90c9a41c0f26c9600d5cf2d6447251d04a20f08f48a85aeb4cb0f6fb/index.js +107 -0
- package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/README.en.md +31 -0
- package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/index.js +271 -0
- package/vendor/components/sha256/701f1deef79fe05eeb18e1119e5a5c4d60a9dfe265e93a4dff79223bc598dbf0/index.js +521 -0
- package/vendor/components/sha256/711cf58fa946c9c0abc953b2f695d02bf5a5a7f73851b09f834e894baf88be38/index.js +122 -0
- package/vendor/components/sha256/728576c57a5ccb39531ad4cb8074fce95480f01603a77dbf57dca0e52199f7c4/index.js +37 -0
- package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/README.en.md +18 -0
- package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/index.js +382 -0
- package/vendor/components/sha256/76bdb63c3e5e14fbb4816bc9f235490817bb5d7be990a826f5077aa08226702c/index.js +162 -0
- package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/README.en.md +51 -0
- package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/index.js +230 -0
- package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/README.en.md +26 -0
- package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/index.js +322 -0
- package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/README.en.md +18 -0
- package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/index.js +103 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/chords.json +89 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/extras.json +192 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ties.json +360 -0
- package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/index.js +508 -0
- package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/README.en.md +22 -0
- package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/index.js +145 -0
- package/vendor/components/sha256/8a4b6dce84d7a69aaafeb75c1c572fe7904fd49e3169c1c85851ccaeae2a7b11/index.js +41 -0
- package/vendor/components/sha256/8bb511cb90902bc7721e59ca08685b26adbf33539e36a4a45172485d6d3d455b/index.js +250 -0
- package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/README.en.md +21 -0
- package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/index.js +108 -0
- package/vendor/components/sha256/8e5e90c90cb6b06a790b0420e43d79d7da663f1cc19ff06d381ec849b4a8fc57/index.js +312 -0
- package/vendor/components/sha256/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -0
- package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/README.en.md +38 -0
- package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/index.js +414 -0
- package/vendor/components/sha256/aac2f8a23cb1b606e9635061cb288f006588c80a7258540cae846ae677f55ff5/index.js +238 -0
- package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/README.en.md +45 -0
- package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/index.js +211 -0
- package/vendor/components/sha256/aeb0b9b5991a5c1df7191c397780a699f2c7310123ca210a58486c0a23e44006/index.js +342 -0
- package/vendor/components/sha256/af3355efd6739a56c6cb53990100f41703361c475c123b9b2762421c68509036/index.js +315 -0
- package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/index.js +4868 -0
- package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/names.txt +4808 -0
- package/vendor/components/sha256/b348ea64cc19632df96a91dfd7c435e4a62095aede72b504d03537be70d6d930/index.js +606 -0
- package/vendor/components/sha256/b53bfa03d1e9feb3cb492f440bf9d100c96eb4fe6b76c42b512a56e9158829cd/index.js +351 -0
- package/vendor/components/sha256/b9443e1cdac4850b1ead9f8449a3061678bbb77fbc53eb9b23d01e1cf50750c3/index.js +619 -0
- package/vendor/components/sha256/bc1e2a02c959ac203819d03c0d25b3776a6a9a4290aae860b26cbbe3d29e876d/index.js +268 -0
- package/vendor/components/sha256/beeb180c0e2250bb04490b092c0a235cae47fca2ed1de2d9ef078a5c14b1a963/index.js +429 -0
- package/vendor/components/sha256/c5fd7713e55e96d75824a21146c0251896d7d9dd028b4d169191433135a97981/index.js +200 -0
- package/vendor/components/sha256/c61987e9994940fc668ed8a010e575ee52027b54ed9c5dd1cc9fdf67649092b3/index.js +404 -0
- package/vendor/components/sha256/ccc8bfe174b6903ec254dfef4f5d1c614271ea39963649add7fcb8d83c081eba/index.js +278 -0
- package/vendor/components/sha256/da267bc65fde0a9279127d5a82f6c253ad74984da6fb11391f00604ad9ffe80d/index.js +93 -0
- package/vendor/components/sha256/dea36cd7010991a572ef394ee32b5e17564aeff09d3ec4ed3820d7e43c9a58be/index.js +484 -0
- package/vendor/components/sha256/df3fdb2aed487d4f6e60a8abab1fe0d1e9fa2a4193fd162edf3c384ea8db5a1b/index.js +180 -0
- package/vendor/components/sha256/e27d517f39eb554c7a9ecea7b59fcf1d347c4deeb3fe2250797aa233bfb7e2b0/index.js +747 -0
- package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/README.en.md +20 -0
- package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/index.js +310 -0
- package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/README.en.md +30 -0
- package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/index.js +192 -0
- package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/README.en.md +24 -0
- package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/index.js +214 -0
- package/vendor/components-2/manifest-2.16.0.json +2919 -0
- package/vendor/components-2/manifest-2.17.0.json +2852 -0
- package/vendor/components-2/manifest-2.18.0.json +3182 -0
- package/vendor/egatari-spec/SOURCE.json +2 -2
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// m-tape:テープ図・線分図。行の長さは全部の行で同じ尺度。全体や部分を括る括弧と名前、行から行への「2 倍」の矢印
|
|
2
|
+
// <m-tape style="height:360px">
|
|
3
|
+
// <script type="application/json">{"rows": [{"label": "みかん", "segs": [{"v": 8, "label": "食べた 8 こ"}, {"v": 15, "label": "のこり 15 こ"}]}],
|
|
4
|
+
// "brace": [{"row": 0, "from": 0, "to": 1, "label": "はじめ □ こ", "side": "above"}]}
|
|
5
|
+
// (JSON の終わり)</m-tape>
|
|
6
|
+
// 段階:build="steps"(既定)は 行を 1 つずつ → 括弧を 1 つずつ → 倍の矢印を 1 つずつ。build="rows" は行を 1 つずつ(括弧と矢印はその行と)、
|
|
7
|
+
// build="whole" は全部を 1 段階で。項目の show で段階を指定できる
|
|
8
|
+
// kind="tape"(既定、テープ図)か "line"(線分図)
|
|
9
|
+
// 見せ方(docs/conventions.md §1):fade(フェード、既定)・grow(テープが左から伸び、括弧と矢印は線を引く)
|
|
10
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・variant・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
11
|
+
// データや大きさの問題は ctx.report で知らせる(1.x の console.warn の代わり)
|
|
12
|
+
egatariParts.define({name: "tape", version: "2.1.0", requires: {base: "1.3.0"}, element: "m-tape"}, function(deps){
|
|
13
|
+
"use strict";
|
|
14
|
+
var base = deps.base;
|
|
15
|
+
// 字の幅(base の textWidth:font の要素の字で測った幅。字は mtext で書くので *_^ は数えない)
|
|
16
|
+
var est = function(s, size, font){ return base.textWidth(s, size, {font: font, mark: true}); };
|
|
17
|
+
var TONES = /^(term|emph|muted|accent2|fg|series-[1-4])$/;
|
|
18
|
+
var UNK = ["?", "□"];
|
|
19
|
+
return class extends base.MotionElement {
|
|
20
|
+
static partName = "tape"; // the registry name (define meta name), for report prefixes
|
|
21
|
+
static variants = ["fade", "grow"];
|
|
22
|
+
static shape = {
|
|
23
|
+
schema: {type: "object", additionalProperties: false, required: ["rows"], properties: {
|
|
24
|
+
rows: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["segs"], properties: {
|
|
25
|
+
label: {type: "string"}, tone: {type: "string"}, show: {type: "integer"},
|
|
26
|
+
segs: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["v"], properties: {
|
|
27
|
+
v: {type: "number"}, label: {type: "string"}, unknown: {type: "string"}}}}}}},
|
|
28
|
+
brace: {type: "array", items: {type: "object", additionalProperties: false, required: ["row", "from", "to"], properties: {
|
|
29
|
+
row: {type: "integer"}, from: {type: "integer"}, to: {type: "integer"}, label: {type: "string"}, side: {type: "string", enum: ["above", "below"]}, show: {type: "integer"}}}},
|
|
30
|
+
times: {type: "array", items: {type: "object", additionalProperties: false, required: ["from", "to"], properties: {
|
|
31
|
+
from: {type: "integer"}, to: {type: "integer"}, label: {type: "string"}, show: {type: "integer"}}}}}},
|
|
32
|
+
example: {rows: [{label: "みかん", segs: [{v: 8, label: "食べた 8 こ"}, {v: 15, label: "のこり 15 こ"}]}], brace: [{row: 0, from: 0, to: 1, label: "はじめ □ こ", side: "above"}]},
|
|
33
|
+
note: {en: "rows [{label, segs: [{v, label, unknown: \"?\" | \"□\"}]}]; brace [{row, from, to, label, side: above|below}] (from/to are segment numbers from 0); times [{from, to, label}] (row numbers)",
|
|
34
|
+
ja: "rows [{label, segs: [{v, label, unknown: \"?\" か \"□\"}]}]、brace [{row, from, to, label, side: above|below}](from・to は 0 から数えた区切りの番号)、times [{from, to, label}](行の番号)"},
|
|
35
|
+
};
|
|
36
|
+
static props = {
|
|
37
|
+
kind: {type: "string", default: "tape", doc: "tape(テープ図)か line(線分図)"},
|
|
38
|
+
build: {type: "string", default: "steps", doc: "steps(行・括弧・矢印を 1 つずつ)・rows(行を 1 つずつ。括弧と矢印はその行と)・whole(全部を 1 ステップで)"},
|
|
39
|
+
dur: {type: "number", default: 0.8, doc: "1 ステップの動きの秒数"},
|
|
40
|
+
};
|
|
41
|
+
get steps(){
|
|
42
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
43
|
+
return this.plan().steps;
|
|
44
|
+
}
|
|
45
|
+
plan(){
|
|
46
|
+
if (this._plan) return this._plan;
|
|
47
|
+
var d = this.data || {}, P = this.props, notes = [];
|
|
48
|
+
var rows = d.rows.map(function(r, i){
|
|
49
|
+
r.segs.forEach(function(s){ if (s.unknown !== undefined && UNK.indexOf(s.unknown) < 0) notes.push('[tape] unknown "' + s.unknown + '" is not "?" or "□" ("?" is used)'); if (!(s.v > 0)) throw new Error("m-tape: a segment's v must be a positive number (" + s.v + ")"); });
|
|
50
|
+
return {i: i, o: r};
|
|
51
|
+
});
|
|
52
|
+
var R = rows.length;
|
|
53
|
+
var braces = (d.brace || []).filter(function(b){
|
|
54
|
+
if (b.row < 0 || b.row >= R){ notes.push("[tape] brace row " + b.row + " does not exist (ignored)"); return false; }
|
|
55
|
+
var n = rows[b.row].o.segs.length;
|
|
56
|
+
if (b.from < 0 || b.to >= n || b.from > b.to){ notes.push("[tape] brace from " + b.from + " to " + b.to + " is not a segment range of row " + b.row + " (0 to " + (n - 1) + ")"); return false; }
|
|
57
|
+
if (b.side !== undefined && b.side !== "above" && b.side !== "below"){ notes.push('[tape] brace side "' + b.side + '" is not above or below'); }
|
|
58
|
+
return true;
|
|
59
|
+
}).map(function(b){ return {o: b, row: b.row, side: b.side === "below" ? "below" : "above"}; });
|
|
60
|
+
var times = (d.times || []).filter(function(x){
|
|
61
|
+
var ok = x.from >= 0 && x.from < R && x.to >= 0 && x.to < R && x.from !== x.to;
|
|
62
|
+
if (!ok) notes.push("[tape] times from " + x.from + " to " + x.to + " needs two different rows (ignored)");
|
|
63
|
+
return ok;
|
|
64
|
+
}).map(function(x){ return {o: x}; });
|
|
65
|
+
var build = P.build;
|
|
66
|
+
if (["steps", "rows", "whole"].indexOf(build) < 0){ notes.push('[tape] build="' + build + '" is not steps, rows or whole (steps is used)'); build = "steps"; }
|
|
67
|
+
var sh = function(o){ return Number.isInteger(o.show) && o.show >= 1 ? o.show : null; };
|
|
68
|
+
var k = 0;
|
|
69
|
+
rows.forEach(function(r){ r.st = sh(r.o) || (build === "whole" ? 1 : ++k); });
|
|
70
|
+
braces.forEach(function(b){ b.st = sh(b.o) || (build === "whole" ? 1 : build === "rows" ? rows[b.row].st : ++k); });
|
|
71
|
+
times.forEach(function(x){ x.st = sh(x.o) || (build === "whole" ? 1 : build === "rows" ? Math.max(rows[x.o.from].st, rows[x.o.to].st) : ++k); });
|
|
72
|
+
var steps = Math.max.apply(null, [1].concat(rows.map(function(r){ return r.st; }), braces.map(function(b){ return b.st; }), times.map(function(x){ return x.st; })));
|
|
73
|
+
return (this._plan = {rows: rows, braces: braces, times: times, steps: steps, notes: notes});
|
|
74
|
+
}
|
|
75
|
+
duration(k){ return k >= 1 && k <= this.plan().steps ? this.props.dur : 0; }
|
|
76
|
+
// 最後の形を 1 文で(読み上げの名前):「テープ図:A 12 m、B 12 m+5 m、B 全体 □ m」。区切りは図に書く字(? □ と名前)を+でつなぎ、
|
|
77
|
+
// 字のない区切りは書かない。括弧は行の名前と括弧の名前、倍の矢印は「A→B 2 倍」
|
|
78
|
+
summary(ja, line){
|
|
79
|
+
var pl = this.plan(), rows = pl.rows, sep = ja ? "、" : ", ";
|
|
80
|
+
var segText = function(s){ return [s.unknown !== undefined ? (UNK.indexOf(s.unknown) >= 0 ? s.unknown : "?") : "", s.label || ""].filter(Boolean).join(" "); };
|
|
81
|
+
var name = function(i){ return rows[i].o.label || (ja ? (i + 1) + " 行目" : "row " + (i + 1)); };
|
|
82
|
+
var out = rows.map(function(r, i){
|
|
83
|
+
var segs = r.o.segs.map(segText).filter(Boolean);
|
|
84
|
+
return [r.o.label || (rows.length > 1 || !segs.length ? name(i) : ""), segs.join(ja ? "+" : " + ")].filter(Boolean).join(" ");
|
|
85
|
+
});
|
|
86
|
+
pl.braces.forEach(function(b){ if (b.o.label) out.push((rows[b.row].o.label || rows.length > 1 ? name(b.row) + " " : "") + b.o.label); });
|
|
87
|
+
pl.times.forEach(function(x){ out.push(name(x.o.from) + "→" + name(x.o.to) + (x.o.label ? " " + x.o.label : "")); });
|
|
88
|
+
return (line ? (ja ? "線分図" : "Line diagram") : (ja ? "テープ図" : "Tape diagram")) + (ja ? ":" : ": ") + out.join(sep);
|
|
89
|
+
}
|
|
90
|
+
mount(ctx){
|
|
91
|
+
var P = this.props, D = base, self = this, pl = this.plan();
|
|
92
|
+
this.variant = base.variant(this);
|
|
93
|
+
pl.notes.forEach(function(n){ ctx.report("data", n); });
|
|
94
|
+
var line = P.kind === "line";
|
|
95
|
+
if (P.kind !== "tape" && P.kind !== "line") ctx.report("data", '[tape] kind="' + P.kind + '" is not tape or line (tape is used)');
|
|
96
|
+
this.style.display = "block";
|
|
97
|
+
var W = this.clientWidth, H = this.clientHeight, dur = P.dur, grow = this.variant === "grow";
|
|
98
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
99
|
+
// 読み上げ:最後の形(行ごとの区切り、括弧、倍の矢印)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
100
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
101
|
+
this.setAttribute("role", "img");
|
|
102
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja"), line));
|
|
103
|
+
var items = this.items = [];
|
|
104
|
+
var add = function(el, o){ o.el = el; items.push(o); return el; };
|
|
105
|
+
var FS = 24, ROW = 34, BR = 16, BLV = BR + 6 + ROW + 6;
|
|
106
|
+
var rows = pl.rows, labW = Math.max.apply(null, [0].concat(rows.map(function(r){ return r.o.label ? est(r.o.label, 26, self) : 0; })));
|
|
107
|
+
// 倍の矢印は行の左の端(どの行もそろう)を結ぶ。名前はその左に
|
|
108
|
+
var tW = pl.times.length ? Math.max.apply(null, pl.times.map(function(x){ return x.o.label ? est(x.o.label, 26, self) + 14 : 0; })) + 52 : 0;
|
|
109
|
+
var x0 = (labW ? labW + 28 : 8) + tW, labX = tW ? labW + 8 : x0 - 18; // 矢印があれば行の名前は左の列に
|
|
110
|
+
var mR = 10;
|
|
111
|
+
var maxT = Math.max.apply(null, rows.map(function(r){ return r.o.segs.reduce(function(a, s){ return a + s.v; }, 0); }));
|
|
112
|
+
var sc = (W - x0 - mR) / maxT;
|
|
113
|
+
// 区切りの中身(□ の枠・?・名前)と幅
|
|
114
|
+
var content = function(s){
|
|
115
|
+
var parts = [];
|
|
116
|
+
if (s.unknown !== undefined) parts.push(s.unknown === "□" ? {box: true, w: 30} : {t: "?", w: est("?", 28, self), q: true});
|
|
117
|
+
if (s.label) parts.push({t: s.label, w: est(s.label, FS, self)});
|
|
118
|
+
return {parts: parts, w: parts.reduce(function(a, p){ return a + p.w; }, 0) + 8 * Math.max(0, parts.length - 1)};
|
|
119
|
+
};
|
|
120
|
+
// 行ごとの寸法
|
|
121
|
+
rows.forEach(function(r){
|
|
122
|
+
var x = x0;
|
|
123
|
+
r.segs = r.o.segs.map(function(s){ var o = {s: s, x: x, w: s.v * sc, c: content(s)}; x += o.w; return o; });
|
|
124
|
+
r.end = x;
|
|
125
|
+
r.tapeH = line ? 24 : 52;
|
|
126
|
+
r.out = line ? r.segs.some(function(g){ return g.c.parts.length; }) : r.segs.some(function(g){ return g.c.parts.length && g.c.w + 14 > g.w; });
|
|
127
|
+
r.segs.forEach(function(g){ g.outside = line || g.c.w + 14 > g.w; });
|
|
128
|
+
var lv = function(side){
|
|
129
|
+
var bs = pl.braces.filter(function(b){ return b.row === r.i && b.side === side; });
|
|
130
|
+
bs.sort(function(a, b){ return (a.o.to - a.o.from) - (b.o.to - b.o.from); });
|
|
131
|
+
var placed = [];
|
|
132
|
+
bs.forEach(function(b){
|
|
133
|
+
var l = 0;
|
|
134
|
+
while (placed.some(function(p){ return p.lv === l && p.o.from <= b.o.to && b.o.from <= p.o.to; })) l++;
|
|
135
|
+
b.lv = l; placed.push(b);
|
|
136
|
+
});
|
|
137
|
+
return bs.length ? Math.max.apply(null, bs.map(function(b){ return b.lv; })) + 1 : 0;
|
|
138
|
+
};
|
|
139
|
+
r.upN = lv("above"); r.downN = lv("below");
|
|
140
|
+
r.above = (r.out ? ROW + 8 : 0) + r.upN * BLV;
|
|
141
|
+
r.below = r.downN * BLV;
|
|
142
|
+
r.h = r.above + r.tapeH + r.below;
|
|
143
|
+
});
|
|
144
|
+
var need = rows.reduce(function(a, r){ return a + r.h; }, 0) + 24 * (rows.length - 1) + 8;
|
|
145
|
+
if (need > H + 1) ctx.report("size", "[tape] the element (" + W + "×" + H + " px) is too small; it needs about " + Math.ceil(need) + " px of height");
|
|
146
|
+
var gap = rows.length > 1 ? Math.min(60, 24 + Math.max(0, H - need) / (rows.length + 1)) : 0;
|
|
147
|
+
var total = rows.reduce(function(a, r){ return a + r.h; }, 0) + gap * (rows.length - 1);
|
|
148
|
+
var y = Math.max(4, (H - total) / 2);
|
|
149
|
+
rows.forEach(function(r){ r.top = y + r.above; r.cy = r.top + r.tapeH / 2; y += r.h + gap; });
|
|
150
|
+
var gT = D.el("g", {}, svg), gS = D.el("g", {}, svg), gA = D.el("g", {}, svg), gX = D.el("g", {}, svg);
|
|
151
|
+
// marks for the geometry check (spec §8.4): a tape segment is a box, a brace and a "times" arrow are edges between unnamed ends,
|
|
152
|
+
// and every name is a label of its segment, edge or row (@row…)
|
|
153
|
+
var pm = function(el, id, of, outside){
|
|
154
|
+
el.setAttribute("data-part", "label"); el.setAttribute("data-part-id", id); el.setAttribute("data-part-of", of);
|
|
155
|
+
if (outside) el.setAttribute("data-part-at", "outside");
|
|
156
|
+
return el;
|
|
157
|
+
};
|
|
158
|
+
var edge = function(id){ return D.el("g", {"data-part": "edge", "data-part-id": id, "data-part-from": "@" + id, "data-part-to": "@" + id}, gA); };
|
|
159
|
+
var drawContent = function(par, cx, base, c){
|
|
160
|
+
var x = cx - c.w / 2;
|
|
161
|
+
c.parts.forEach(function(p){
|
|
162
|
+
if (p.box) D.el("rect", {x: x.toFixed(1), y: (base - 25).toFixed(1), width: 30, height: 30, rx: 2, fill: "var(--bg)", stroke: "var(--fg)", "stroke-width": 2.5}, par);
|
|
163
|
+
else D.mtext(par, x + p.w / 2, base, p.t, {"text-anchor": "middle", "font-size": p.q ? 28 : FS, "font-weight": p.q ? 700 : 400, fill: "var(--fg)"});
|
|
164
|
+
x += p.w + 8;
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
rows.forEach(function(r, ri){
|
|
168
|
+
var col = TONES.test(r.o.tone || "") ? "var(--" + r.o.tone + ")" : "var(--series-" + (ri % 4 + 1) + ")", st = r.st, n = r.segs.length;
|
|
169
|
+
if (r.o.label) add(D.mtext(gX, labX, r.cy + 9, r.o.label, {"data-part": "label", "data-part-id": "@row" + (ri + 1), "data-part-of": "mark", "data-part-at": "outside", "text-anchor": "end", "font-size": 26, "font-weight": 700, fill: "var(--fg)", opacity: 0}), {st: st, at: 0, len: dur * 0.5, kind: "fade"});
|
|
170
|
+
r.segs.forEach(function(g, j){
|
|
171
|
+
var at = grow ? dur * 0.75 * j / n : 0, len = grow ? dur * 0.75 / n : dur * 0.7, sid = (line ? "@s" : "s") + (ri + 1) + "-" + (j + 1);
|
|
172
|
+
if (!line){
|
|
173
|
+
var rect = D.el("rect", {"data-part": "box", "data-part-id": sid, x: g.x.toFixed(1), y: r.top.toFixed(1), width: Math.max(0, g.w).toFixed(1), height: r.tapeH, fill: col, "fill-opacity": 0.14, stroke: "var(--fg)", "stroke-width": 2.5, opacity: 0}, gS);
|
|
174
|
+
add(rect, {st: st, at: at, len: len, kind: "seg", w: g.w});
|
|
175
|
+
} else {
|
|
176
|
+
add(D.el("line", {x1: g.x.toFixed(1), x2: (g.x + g.w).toFixed(1), y1: r.cy.toFixed(1), y2: r.cy.toFixed(1), stroke: col, "stroke-width": 4, opacity: 0}, gS), {st: st, at: at, len: len, kind: "line"});
|
|
177
|
+
[g.x, g.x + g.w].forEach(function(x, e){
|
|
178
|
+
if (e === 0 && j > 0) return;
|
|
179
|
+
add(D.el("line", {x1: x.toFixed(1), x2: x.toFixed(1), y1: (r.cy - 12).toFixed(1), y2: (r.cy + 12).toFixed(1), stroke: "var(--fg)", "stroke-width": 3, opacity: 0}, gS), {st: st, at: grow ? (e ? at + len * 0.8 : at) : 0, len: grow ? dur * 0.15 : dur * 0.7, kind: "fade"});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (g.c.parts.length){
|
|
183
|
+
var cg = D.el("g", {opacity: 0}, gT), base = g.outside ? r.top - 8 - ROW + 25 : r.cy + 9;
|
|
184
|
+
var cx = Math.max(x0 + g.c.w / 2, Math.min(W - g.c.w / 2 - 2, g.x + g.w / 2));
|
|
185
|
+
drawContent(pm(cg, sid, line ? "mark" : "box", line || g.outside), cx, base, g.c);
|
|
186
|
+
add(cg, {st: st, at: grow ? at + len * 0.6 : dur * 0.2, len: grow ? Math.max(0.15, dur * 0.25) : dur * 0.5, kind: "fade"});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
// 括弧
|
|
190
|
+
pl.braces.filter(function(b){ return b.row === ri; }).forEach(function(b, bi){
|
|
191
|
+
var bid = "brace" + (ri + 1) + "-" + (bi + 1);
|
|
192
|
+
var xa = r.segs[b.o.from].x + 2, xb = r.segs[b.o.to].x + r.segs[b.o.to].w - 2, up = b.side === "above", dsg = up ? -1 : 1;
|
|
193
|
+
var yb = up ? r.top - (r.out ? ROW + 8 : 0) - 6 - b.lv * BLV : r.top + r.tapeH + 6 + b.lv * BLV;
|
|
194
|
+
var xm = (xa + xb) / 2, q = BR, rr = Math.min(12, (xb - xa) / 4), f = function(v){ return v.toFixed(1); };
|
|
195
|
+
var d = "M" + f(xa) + "," + f(yb) + "Q" + f(xa) + "," + f(yb + dsg * q / 2) + " " + f(xa + rr) + "," + f(yb + dsg * q / 2) + "L" + f(xm - rr) + "," + f(yb + dsg * q / 2) +
|
|
196
|
+
"Q" + f(xm) + "," + f(yb + dsg * q / 2) + " " + f(xm) + "," + f(yb + dsg * q) + "Q" + f(xm) + "," + f(yb + dsg * q / 2) + " " + f(xm + rr) + "," + f(yb + dsg * q / 2) +
|
|
197
|
+
"L" + f(xb - rr) + "," + f(yb + dsg * q / 2) + "Q" + f(xb) + "," + f(yb + dsg * q / 2) + " " + f(xb) + "," + f(yb);
|
|
198
|
+
add(D.el("path", {"data-part-line": "", d: d, fill: "none", stroke: "var(--fg)", "stroke-width": 2.5, "stroke-linejoin": "round", opacity: 0}, edge(bid)), {st: b.st, at: 0, len: dur * 0.6, kind: "line"});
|
|
199
|
+
if (b.o.label){
|
|
200
|
+
var c = content({label: b.o.label}), cx = Math.max(c.w / 2 + 2, Math.min(W - c.w / 2 - 2, xm)), base = up ? yb - q - 6 - ROW + 25 : yb + q + 6 + 25;
|
|
201
|
+
var cg = pm(D.el("g", {opacity: 0}, gT), bid, "edge");
|
|
202
|
+
drawContent(cg, cx, base, c);
|
|
203
|
+
add(cg, {st: b.st, at: dur * 0.3, len: dur * 0.5, kind: "fade"});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
// 倍の矢印:行の左の端から端へ、左にふくらむ弧
|
|
208
|
+
pl.times.forEach(function(x, xi){
|
|
209
|
+
var tid = "times" + (xi + 1);
|
|
210
|
+
var a = rows[x.o.from], b = rows[x.o.to], xs = x0 - 8, xc = x0 - 44, ya = a.cy, yb = b.cy;
|
|
211
|
+
add(D.el("path", {d: "M" + xs.toFixed(1) + "," + ya.toFixed(1) + "C" + xc.toFixed(1) + "," + ya.toFixed(1) + " " + xc.toFixed(1) + "," + yb.toFixed(1) + " " + (xs - 10).toFixed(1) + "," + yb.toFixed(1),
|
|
212
|
+
fill: "none", stroke: "var(--emph)", "stroke-width": 3, "stroke-linecap": "round", opacity: 0, "data-part-line": ""}, edge(tid)), {st: x.st, at: 0, len: dur * 0.6, kind: "line"});
|
|
213
|
+
add(D.el("path", {d: "M" + xs.toFixed(1) + "," + yb.toFixed(1) + "l-14,-7v14Z", fill: "var(--emph)", opacity: 0}, gA), {st: x.st, at: dur * 0.5, len: dur * 0.2, kind: "fade"});
|
|
214
|
+
if (x.o.label){
|
|
215
|
+
var lx = 0.75 * xc + 0.125 * (xs + xs - 10) - 12;
|
|
216
|
+
add(D.mtext(gT, lx, (ya + yb) / 2 + 9, x.o.label, {"data-part": "label", "data-part-id": tid, "data-part-of": "edge", "text-anchor": "end", "font-size": 26, "font-weight": 700, fill: "var(--fg)", opacity: 0}), {st: x.st, at: dur * 0.3, len: dur * 0.5, kind: "fade"});
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (grow) items.forEach(function(it){ if (it.kind === "line") it.el.setAttribute("pathLength", 1); });
|
|
220
|
+
}
|
|
221
|
+
render(k, t, ctx){
|
|
222
|
+
var D = base, lecture = !!ctx.preview, grow = this.variant === "grow", FAINT = 0.45;
|
|
223
|
+
if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
224
|
+
this.items.forEach(function(it){
|
|
225
|
+
var e = it.st < k ? 1 : it.st > k ? (lecture ? -1 : 0) : D.prog(t, it.at, it.len), op;
|
|
226
|
+
if (e < 0){ op = FAINT; e = 1; } else op = e;
|
|
227
|
+
if (grow && it.kind === "seg"){
|
|
228
|
+
it.el.setAttribute("width", Math.max(0, it.w * e).toFixed(1));
|
|
229
|
+
op = e > 0 ? (op === FAINT && it.st > k ? FAINT : 1) : 0;
|
|
230
|
+
} else if (grow && it.kind === "line"){
|
|
231
|
+
it.el.setAttribute("stroke-dasharray", e >= 1 ? "none" : e.toFixed(4) + " 2");
|
|
232
|
+
op = e > 0 ? (op === FAINT && it.st > k ? FAINT : 1) : 0;
|
|
233
|
+
}
|
|
234
|
+
it.el.setAttribute("opacity", op.toFixed(3));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Lines drawn one at a time on shared axes, each named at its end (no legend)
|
|
3
|
+
steps: largest step (default: number of series)
|
|
4
|
+
props:
|
|
5
|
+
xr: x range
|
|
6
|
+
yr: y range
|
|
7
|
+
xt: x ticks
|
|
8
|
+
yt: y ticks
|
|
9
|
+
xf: x tick decimals
|
|
10
|
+
yf: y tick decimals
|
|
11
|
+
xl: x title
|
|
12
|
+
yl: y title
|
|
13
|
+
n: samples
|
|
14
|
+
dur: draw seconds
|
|
15
|
+
lw: line width
|
|
16
|
+
size: text px (≥ 24; 0 = default)
|
|
17
|
+
example: [{"label": "Demand D", "f": "10 - x"}, {"label": "Supply S", "f": "2 + x"}, {"label": "Equilibrium", "pts": [[4, 0], [4, 6]], "dash": true}]
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
One comparison at a time: mean, median, quantiles; losses.
|
|
21
|
+
|
|
22
|
+
Series: a JSON array in a child script. One series = one step; same `step` = together.
|
|
23
|
+
|
|
24
|
+
| Field | Meaning |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `label` | line name |
|
|
27
|
+
| `f` | expression in x (see below) |
|
|
28
|
+
| `pts` | points `[[x, y], …]` |
|
|
29
|
+
| `tone` | `term` `emph` `accent2` `muted` `fg` `series-1..4` |
|
|
30
|
+
| `dash` | dashed |
|
|
31
|
+
| `area` / `areaLabel` | shaded span `[a, b]` (several; null = edge), labels |
|
|
32
|
+
| `labelAt` / `anchor` / `dx` / `dy` / `ly` | name at x = `labelAt` (default: end); `anchor` `right` `left` `above` `below`; `ly` = y |
|
|
33
|
+
|
|
34
|
+
`f` is arithmetic, not code: numbers, `x`, `Math` functions/constants (`sin(x)`, `PI`; no `random`), `N(x, mean, sd)`, `+ - * / % **`, comparisons, `&& || !`, `? :`. Powers: `**`. An unreadable `f` shows a card.
|
|
35
|
+
|
|
36
|
+
<!-- llm: omit -->
|
|
37
|
+
- `xr` and `yr` default to `[0, 1]`. When one is not written and a line goes outside it, the line is cut flat at the edge, so the part reports it per series and axis (`ctx.report`; Studio's check warns; from 2.3.0). A written range that cuts a line is taken as intended.
|
|
38
|
+
- `area`: shades to y = 0; several spans; rejection regions, p-values; `areaLabel` per span
|
|
39
|
+
Older forms (still work; not described to the AI)
|
|
40
|
+
|
|
41
|
+
- `color` = `tone`; `at` = `labelAt` (only without `labelAt`)
|
|
42
|
+
- `anchor` `start` `middle` `end`: raw text-anchor
|
|
43
|
+
- Without `step`, series i is step i + 1. Showing later steps faintly draws later lines at `--preview-opacity`
|
|
44
|
+
- The demo is `demo.html`. Series fields match `m-scatter` (conventions §3)
|
|
45
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// m-curves:同じ座標軸に線を 1 本ずつ引く。線の名前は凡例でなく線の端に直接書く
|
|
2
|
+
// <m-curves xr="[-3,3]" yr="[0,0.5]" xt="[-2,0,2]" yt="[0,0.2,0.4]" xl="*y*" yl="密度" style="height:380px">
|
|
3
|
+
// <script type="application/json">[{"label":"予測分布","f":"N(x,0,1)"},{"label":"中央値","pts":[[0,0],[0,0.4]],"dash":true}]
|
|
4
|
+
// (JSON の終わり)</m-curves>
|
|
5
|
+
// 1 系列 = 1 段階(書いた順。系列の step で変えられ、同じ step の系列は一緒に引く)。f は x の式(Math の関数と N(x,平均,標準偏差) が使える)、pts は点列
|
|
6
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・previewOpacity、plot の Plot、expr の compile を使い、
|
|
7
|
+
// プレイヤーのグローバルは使わない(1.x は式の評価器 egatari-expr を写して持っていた)。破線の mask の id は
|
|
8
|
+
// curves-2-2-1-<n>m<系列>:このパーツの名前と版に、このパーツだけの数え(1.x は mc<n>m<系列> で、DECK.Plot の数えを進めていた)
|
|
9
|
+
egatariParts.define({name: "curves", version: "2.3.1", requires: {base: "1.3.0", expr: "1.0.0", plot: "1.1.3"}, element: "m-curves"}, function(deps){
|
|
10
|
+
"use strict";
|
|
11
|
+
var base = deps.base, plot = deps.plot, expr = deps.expr;
|
|
12
|
+
var ID = "curves-2-3-1-"; // name and version of this part, dots replaced (spec §6.1 Identifiers)
|
|
13
|
+
var count = 0; // this part's own counter for its ids (deterministic: the order of mounting)
|
|
14
|
+
// 線の名前(26px)の下付き・上付きの分の高さ(px)。base 1.1.0 で mtext の下付き・上付きは 24px 以上になり、下付きの字の下端は基線から
|
|
15
|
+
// 添字の 0.75 倍まで、上付きの字の上端は 1.4 倍まで届く(Source Sans 3 で測った値。BIZ UDPGothic ではそれぞれ 0.5 倍と 1.2 倍)。
|
|
16
|
+
// 字の下の余白(字の 0.12 倍)・上の高さ(0.88 倍)を超える分。記法がなければ 0
|
|
17
|
+
function subX(s, fs){ var ss = Math.max(24, Math.round(fs * 0.75)); return /_./.test(s) ? Math.max(0, 0.75 * ss - 0.12 * fs) : 0; }
|
|
18
|
+
function supX(s, fs){ var ss = Math.max(24, Math.round(fs * 0.75)); return /\^./.test(s) ? Math.max(0, 1.4 * ss - 0.88 * fs) : 0; }
|
|
19
|
+
return class extends base.MotionElement {
|
|
20
|
+
static partName = "curves"; // the registry name (define meta name), for report prefixes
|
|
21
|
+
// データの形(kit/shape.js):線の配列。軸(xr yr xt yt xl yl)は属性に書く(JSON の中ではない)
|
|
22
|
+
static shape = {
|
|
23
|
+
schema: {type: "array", items: {type: "object", additionalProperties: false, anyOf: [{required: ["f"]}, {required: ["pts"]}],
|
|
24
|
+
properties: {label: {type: "string"}, f: {type: "string"}, pts: {type: "array", items: {type: "array", items: {type: "number"}, minItems: 2, maxItems: 2}},
|
|
25
|
+
tone: {type: "string"}, step: {type: "integer"}, labelAt: {type: "number"},
|
|
26
|
+
color: {type: "string"}, dash: {type: "boolean"}, xr: {type: "array", items: {type: "number"}, minItems: 2, maxItems: 2},
|
|
27
|
+
area: {type: "array"}, areaLabel: {type: ["string", "array"]},
|
|
28
|
+
at: {type: "number"}, anchor: {enum: ["right", "left", "above", "below", "top", "bottom", "start", "middle", "end"]}, dx: {type: "number"}, dy: {type: "number"}, ly: {type: "number"}}}},
|
|
29
|
+
example: [{label: "需要 D", f: "10 - x"}, {label: "供給 S", f: "2 + x"}, {label: "均衡", pts: [[4, 0], [4, 6]], dash: true}],
|
|
30
|
+
// よくある書き違い(指示の部品の一覧に書く)
|
|
31
|
+
note: {en: "the data is the array itself, not {\"series\": […]}; axes go in attributes (xr=\"[0,10]\" xl=\"…\"); the expression field is f in x (not fn, not u)",
|
|
32
|
+
ja: "データは配列そのもの({\"series\": […]} ではない)。軸は属性に書く(xr=\"[0,10]\" xl=\"…\")。式の欄は f で、変数は x(fn・u ではない)"},
|
|
33
|
+
};
|
|
34
|
+
static props = {
|
|
35
|
+
xr: {type: "json", default: [0, 1], doc: "横軸の範囲"}, yr: {type: "json", default: [0, 1], doc: "縦軸の範囲"},
|
|
36
|
+
xt: {type: "json", default: []}, yt: {type: "json", default: []},
|
|
37
|
+
xf: {type: "number", default: undefined, doc: "横軸の目盛りの小数桁"}, yf: {type: "number", default: undefined, doc: "縦軸の目盛りの小数桁"},
|
|
38
|
+
xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
|
|
39
|
+
n: {type: "number", default: 300, doc: "f を描く分割数"},
|
|
40
|
+
dur: {type: "number", default: 1.0, doc: "1 本を引く秒数"},
|
|
41
|
+
lw: {type: "number", default: 3.5, doc: "線の太さ"},
|
|
42
|
+
size: {type: "number", default: 0, doc: "字の大きさ(24 以上。0 = 既定)"},
|
|
43
|
+
};
|
|
44
|
+
// 系列 i の段階:step(書いてあれば)、なければ i + 1。段階の数はその最大(step がなければ系列の数で、今までと同じ)
|
|
45
|
+
stepOf(s, i){ return s && s.step !== undefined ? s.step : i + 1; }
|
|
46
|
+
get steps(){
|
|
47
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
48
|
+
var self = this, m = 0;
|
|
49
|
+
(this.data || []).forEach(function(s, i){ m = Math.max(m, self.stepOf(s, i)); });
|
|
50
|
+
return m;
|
|
51
|
+
}
|
|
52
|
+
mount(ctx){
|
|
53
|
+
var P = this.props, D = base, self = this, S = this.data || [];
|
|
54
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
55
|
+
// size:字の大きさ(24 未満は 24 にして知らせる)。0 なら 2.0 と同じ大きさと余白
|
|
56
|
+
var SZ = P.size > 0 ? Math.max(24, P.size) : 0, K = SZ ? SZ / 26 : 1, F = SZ || 26;
|
|
57
|
+
if (P.size > 0 && P.size < 24) ctx.report("attr", "[curves] size " + P.size + " is under 24 px; 24 is used");
|
|
58
|
+
var p = this.p = plot.Plot(this, {xr: P.xr, yr: P.yr, xt: P.xt, yt: P.yt, xf: P.xf, yf: P.yf, xl: P.xl, yl: P.yl, fs: SZ || undefined, m: {l: Math.round(86 * K), r: 24, t: Math.round(24 * K), b: Math.round(64 * K)}});
|
|
59
|
+
var uid = ID + (++count), defs = D.el("defs", {}, p.svg);
|
|
60
|
+
var N = function(x, m, s){ return Math.exp(-0.5 * Math.pow((x - m) / s, 2)) / (s * Math.sqrt(2 * Math.PI)); };
|
|
61
|
+
var x0 = p.m.l, x1 = p.W - p.m.r, y0 = p.m.t, y1 = p.H - p.m.b;
|
|
62
|
+
// 系列ごとに:点列、線、(破線なら)描く範囲の mask、端の名前
|
|
63
|
+
this.items = S.map(function(s, i){
|
|
64
|
+
var pts;
|
|
65
|
+
var raw;
|
|
66
|
+
if (s.pts){ raw = s.pts; pts = s.pts.map(function(q){ return [p.x(q[0]), p.y(q[1])]; }); }
|
|
67
|
+
else {
|
|
68
|
+
// 式は木にしてから計算する(コードとしては実行しない。Egatari spec §6)。書けない式は SyntaxError で、base が受け止めて札を出す(spec §6.1 Containment)
|
|
69
|
+
var g = expr.compile(s.f, {name: "[" + i + "].f", vars: ["x"], funcs: {N: N}, bareMath: true}), a = s.xr ? s.xr[0] : P.xr[0], b = s.xr ? s.xr[1] : P.xr[1];
|
|
70
|
+
pts = []; raw = [];
|
|
71
|
+
for (var j = 0; j <= P.n; j++){ var v = a + (b - a) * j / P.n, w = g(v); raw.push([v, w]); pts.push([p.x(v), p.y(w)]); }
|
|
72
|
+
}
|
|
73
|
+
// 軸の範囲を書かなかったとき(既定の [0, 1])に線が範囲の外に出るなら知らせる(切れて平らな線に見えるため。書いた範囲で切るのは意図とみなす)
|
|
74
|
+
[["xr", 0], ["yr", 1]].forEach(function(ax){
|
|
75
|
+
if (self.hasAttribute(ax[0])) return;
|
|
76
|
+
var r = P[ax[0]], lo = Math.min(r[0], r[1]), hi = Math.max(r[0], r[1]), tol = (hi - lo) * 1e-9, vs = raw.map(function(q){ return q[ax[1]]; }).filter(function(v){ return typeof v === "number" && isFinite(v); });
|
|
77
|
+
var out = vs.filter(function(v){ return v < lo - tol || v > hi + tol; });
|
|
78
|
+
if (out.length) ctx.report("range", "[curves] series " + i + " (" + JSON.stringify(s.label || "") + "): " + out.length + " of " + vs.length + " points are outside " + ax[0] + " " + JSON.stringify(r) + " (the default; values from " + +Math.min.apply(null, vs).toPrecision(4) + " to " + +Math.max.apply(null, vs).toPrecision(4) + "), so the line is cut at the edge. Write " + ax[0] + " to cover them");
|
|
79
|
+
});
|
|
80
|
+
// 有限でない点(NaN・±Infinity)は線を切り、有限な区間ごとに M から引き直す(1 つの NaN で線全体が消えない)
|
|
81
|
+
var d = "", pen = false, gap = false;
|
|
82
|
+
pts.forEach(function(q){
|
|
83
|
+
if (isFinite(q[0]) && isFinite(q[1])){ d += (pen ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); pen = true; }
|
|
84
|
+
else { pen = false; gap = true; }
|
|
85
|
+
});
|
|
86
|
+
if (gap) ctx.report("data", "[curves] series " + i + " (" + JSON.stringify(s.label || "") + ") has points that are not finite numbers (NaN or ±Infinity, e.g. log or division by zero); the line is broken there");
|
|
87
|
+
pts = pts.filter(function(q){ return isFinite(q[0]) && isFinite(q[1]); });
|
|
88
|
+
var col = colorOf(s.tone || s.color, i);
|
|
89
|
+
var it = {step: self.stepOf(s, i)};
|
|
90
|
+
if (s.dash){
|
|
91
|
+
// 破線は dasharray を描画に使えないので、同じ線を mask にして引く
|
|
92
|
+
var mk = D.el("mask", {id: uid + "m" + i, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: p.W, height: p.H}, defs);
|
|
93
|
+
it.mpath = D.el("path", {d: d, fill: "none", stroke: "#fff", "stroke-width": P.lw + 6, pathLength: 1, "stroke-dasharray": "1 2"}, mk);
|
|
94
|
+
var gg = D.el("g", {mask: "url(#" + uid + "m" + i + ")", "clip-path": p.clip}, p.svg);
|
|
95
|
+
it.path = D.el("path", {d: d, fill: "none", stroke: col, "stroke-width": P.lw, "stroke-dasharray": "10 8", "stroke-linecap": "butt"}, gg);
|
|
96
|
+
it.draw = it.mpath;
|
|
97
|
+
} else {
|
|
98
|
+
it.path = D.el("path", {d: d, fill: "none", stroke: col, "stroke-width": P.lw, "clip-path": p.clip, pathLength: 1, "stroke-dasharray": "1 2", "stroke-linejoin": "round"}, p.svg);
|
|
99
|
+
it.draw = it.path;
|
|
100
|
+
}
|
|
101
|
+
// 面積(area:[a, b] か [[a, b], …]。null は軸の端):線と横軸(y = 0、範囲の外なら下の端)のあいだを、その区間だけ薄く塗る。
|
|
102
|
+
// 棄却域・p 値・信頼区間・確率など。線が引き終わってから出る(名前と同じ時に)。areaLabel は区間ごとに中に書く(字の列なら区間の順に)
|
|
103
|
+
if (s.area !== undefined){
|
|
104
|
+
var A = Array.isArray(s.area) && s.area.length && Array.isArray(s.area[0]) ? s.area : [s.area];
|
|
105
|
+
var yb = p.y(Math.max(Math.min(P.yr[0], P.yr[1]), Math.min(Math.max(P.yr[0], P.yr[1]), 0))), ad = "", segs = [];
|
|
106
|
+
A.forEach(function(r){
|
|
107
|
+
if (!Array.isArray(r) || r.length !== 2 || r.some(function(v){ return v !== null && !(typeof v === "number" && isFinite(v)); })){ ctx.report("data", "[curves] series " + i + ": area " + JSON.stringify(r) + " is not [from, to] (numbers, or null for the edge)"); return; }
|
|
108
|
+
var la = p.x(r[0] === null ? P.xr[0] : r[0]), lb = p.x(r[1] === null ? P.xr[1] : r[1]);
|
|
109
|
+
if (la > lb){ var tt = la; la = lb; lb = tt; }
|
|
110
|
+
var seg = pts.filter(function(q){ return isFinite(q[0]) && isFinite(q[1]) && q[0] >= la - 0.01 && q[0] <= lb + 0.01; });
|
|
111
|
+
if (seg.length < 2){ ctx.report("data", "[curves] series " + i + ": area " + JSON.stringify(r) + " has no part of the line in it"); return; }
|
|
112
|
+
ad += "M" + seg[0][0].toFixed(1) + "," + yb.toFixed(1) + seg.map(function(q){ return "L" + q[0].toFixed(1) + "," + q[1].toFixed(1); }).join("") + "L" + seg[seg.length - 1][0].toFixed(1) + "," + yb.toFixed(1) + "Z";
|
|
113
|
+
segs.push({w: seg[seg.length - 1][0] - seg[0][0], seg: seg});
|
|
114
|
+
});
|
|
115
|
+
if (ad){
|
|
116
|
+
it.area = D.el("path", {d: ad, fill: col, "fill-opacity": 0.28, stroke: "none", "clip-path": p.clip, opacity: 0}, p.svg);
|
|
117
|
+
p.svg.insertBefore(it.area, s.dash ? it.path.parentNode : it.path); // 線の下に
|
|
118
|
+
// 区間の名前:区間の真ん中の上(線より上、字の高さぶん離す)。細い区間でも読めるように線の上に置き、背景色で縁取る
|
|
119
|
+
it.areaLabs = [];
|
|
120
|
+
segs.forEach(function(o, j){
|
|
121
|
+
var t = Array.isArray(s.areaLabel) ? s.areaLabel[j] : s.areaLabel;
|
|
122
|
+
if (!t) return;
|
|
123
|
+
var mid = o.seg[Math.floor(o.seg.length / 2)], top = Math.min.apply(null, o.seg.map(function(q){ return q[1]; }));
|
|
124
|
+
var tx = Math.max(x0 + 4, Math.min(x1 - 4, mid[0])), ty = Math.max(y0 + F, top - 10);
|
|
125
|
+
it.areaLabs.push(D.mtext(p.svg, tx, ty, t, {"text-anchor": "middle", fill: col, stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": F, "font-weight": 700, opacity: 0}));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// 名前の位置:labelAt(横軸の値)の点、なければ描画範囲の中の最後の点。at は labelAt の古い名前(labelAt がないときだけ)
|
|
130
|
+
var inside = pts.filter(function(q){ return q[0] >= x0 - .5 && q[0] <= x1 + .5 && q[1] >= y0 - .5 && q[1] <= y1 + .5; });
|
|
131
|
+
var end = inside.length ? inside[inside.length - 1] : pts[pts.length - 1];
|
|
132
|
+
var lat = s.labelAt !== undefined ? s.labelAt : s.at;
|
|
133
|
+
if (!end){ it.lx = it.ly = it.x0 = it.x1 = 0; it.anchor = "start"; it.col = col; it.label = ""; return it; } // 有限な点がない:名前は書かない
|
|
134
|
+
if (lat !== undefined){
|
|
135
|
+
var ax = p.x(lat), best = pts[0];
|
|
136
|
+
pts.forEach(function(q){ if (Math.abs(q[0] - ax) < Math.abs(best[0] - ax)) best = q; });
|
|
137
|
+
end = best;
|
|
138
|
+
}
|
|
139
|
+
// anchor:right(点の右から書く)・left(点の左で終わる)・above / below(点の上・下に中央そろえ、約 0.9 字ぶん離す)。
|
|
140
|
+
// start / middle / end は古い書き方(text-anchor そのもの)で、今までどおり
|
|
141
|
+
var an = {top: "above", bottom: "below"}[s.anchor] || s.anchor; // top / bottom は above / below の別名
|
|
142
|
+
var side = {right: "start", left: "end", above: "middle", below: "middle"}, anchor = side[an] || an || (end[0] > x1 - 160 ? "end" : "start");
|
|
143
|
+
var ly0 = an === "above" ? end[1] - Math.round(14 * K) : an === "below" ? end[1] + Math.round(32 * K) : end[1] - Math.round(12 * K);
|
|
144
|
+
if (an === "below" && ly0 > y1 - 4) ly0 = end[1] - Math.round(14 * K); // 下に入らなければ上へ
|
|
145
|
+
it.lx = end[0] + (anchor === "end" ? -8 : anchor === "start" ? 10 : 0) + (s.dx || 0);
|
|
146
|
+
it.ly = (s.ly !== undefined ? p.y(s.ly) : ly0) + (s.dy || 0);
|
|
147
|
+
// 字の幅の見積もり(26px。base の textWidth:テーマの字で測った幅。記法の * _ ^ を除く)
|
|
148
|
+
var w = D.textWidth(s.label || "", F, {font: self, mark: true});
|
|
149
|
+
it.x0 = anchor === "end" ? it.lx - w : anchor === "middle" ? it.lx - w / 2 : it.lx; it.x1 = it.x0 + w;
|
|
150
|
+
it.anchor = anchor; it.col = col; it.label = s.label || "";
|
|
151
|
+
return it;
|
|
152
|
+
});
|
|
153
|
+
// 名前どうしが重ならないように、横に重なる名前を下へずらす。先に描く高さ(上は 26、下は横軸の 6 px 上)に収めてから離し、
|
|
154
|
+
// 下に収まらなければ下から上へ押し戻す(目盛りの数字にかからない)。上付きのある名前は上端を、下付きのある名前は下端を
|
|
155
|
+
// その分だけ内に、上の名前の下付き・下の名前の上付きの分だけ間を広げる(記法がなければ今までと同じ)
|
|
156
|
+
var min = Math.round(32 * K), lo = F, hi = y1 - 6, ov = function(u, v){ return u.x0 < v.x1 && v.x0 < u.x1; };
|
|
157
|
+
var loOf = function(it){ return lo + supX(it.label, F); }, hiOf = function(it){ return hi - subX(it.label, F); };
|
|
158
|
+
var gap = function(u, v){ return min + subX(u.label, F) + supX(v.label, F); }; // u が上、v が下
|
|
159
|
+
var g = self.items.filter(function(it){ return it.label; });
|
|
160
|
+
g.forEach(function(it){ it.ly = Math.min(hiOf(it), Math.max(loOf(it), it.ly)); });
|
|
161
|
+
g.sort(function(u, v){ return u.ly - v.ly; });
|
|
162
|
+
g.forEach(function(it, j){
|
|
163
|
+
for (var q = 0; q < j; q++){
|
|
164
|
+
var o = g[q];
|
|
165
|
+
if (ov(it, o) && it.ly - o.ly < gap(o, it)) it.ly = o.ly + gap(o, it);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
for (var j = g.length - 1; j >= 0; j--){
|
|
169
|
+
var it = g[j];
|
|
170
|
+
it.ly = Math.min(hiOf(it), it.ly);
|
|
171
|
+
for (var q = j + 1; q < g.length; q++) if (ov(it, g[q]) && g[q].ly - it.ly < gap(it, g[q])) it.ly = g[q].ly - gap(it, g[q]);
|
|
172
|
+
}
|
|
173
|
+
g.forEach(function(it){ it.ly = Math.max(loOf(it), it.ly); });
|
|
174
|
+
this.items.forEach(function(it){
|
|
175
|
+
it.lab = D.mtext(p.svg, it.lx, it.ly, it.label, {"text-anchor": it.anchor, fill: it.col, "font-size": F, "font-weight": 700, opacity: 0});
|
|
176
|
+
});
|
|
177
|
+
// tone:テーマの色の名前か var(--…)。知らない名前は既定の色(series-1..4 の順)にして知らせる
|
|
178
|
+
function colorOf(c, i){
|
|
179
|
+
var def = "var(--series-" + (i % 4 + 1) + ")";
|
|
180
|
+
if (!c) return def;
|
|
181
|
+
if (c.indexOf("var(") === 0) return c;
|
|
182
|
+
var nm = c.replace(/^--/, "");
|
|
183
|
+
if (/^(term|emph|accent2|muted|fg|line|series-[1-4])$/.test(nm)) return "var(--" + nm + ")";
|
|
184
|
+
ctx.report("attr", "[curves] series " + i + ": tone " + JSON.stringify(c) + " is not term, emph, accent2, muted, fg or series-1..4 (" + def.slice(6, -1) + " is used)");
|
|
185
|
+
return def;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
duration(k){ return k >= 1 ? this.props.dur * 0.7 + 0.6 : 0; }
|
|
189
|
+
render(k, t, ctx){
|
|
190
|
+
var dur = this.props.dur, preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0;
|
|
191
|
+
// 先を薄く見せる表示:後の段階の線と名前を、引き終えた形のままテーマの --preview-opacity(なければ 0.45)で描く
|
|
192
|
+
this.items.forEach(function(it){
|
|
193
|
+
if (preview && it.step > k){
|
|
194
|
+
it.draw.setAttribute("stroke-dashoffset", (0).toFixed(4));
|
|
195
|
+
it.path.setAttribute("opacity", PV);
|
|
196
|
+
it.lab.setAttribute("opacity", PV.toFixed(3));
|
|
197
|
+
if (it.area) it.area.setAttribute("opacity", PV.toFixed(3));
|
|
198
|
+
(it.areaLabs || []).forEach(function(e){ e.setAttribute("opacity", PV.toFixed(3)); });
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
var pd = it.step < k ? 1 : it.step === k ? base.prog(t, 0, dur) : 0;
|
|
202
|
+
var pl = it.step < k ? 1 : it.step === k ? base.prog(t, dur * 0.7, 0.6) : 0;
|
|
203
|
+
it.draw.setAttribute("stroke-dashoffset", (1 - pd).toFixed(4));
|
|
204
|
+
it.path.setAttribute("opacity", pd > 0 ? 1 : 0);
|
|
205
|
+
it.lab.setAttribute("opacity", pl.toFixed(3));
|
|
206
|
+
if (it.area) it.area.setAttribute("opacity", pl.toFixed(3));
|
|
207
|
+
(it.areaLabs || []).forEach(function(e){ e.setAttribute("opacity", pl.toFixed(3)); });
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
});
|