egatari 0.6.17 → 0.6.19
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 +68 -1
- package/README.ja.md +14 -13
- package/README.md +2 -1
- package/components.lock.json +153 -54
- package/components2.lock.json +1001 -1
- package/kit/build.mjs +1 -1
- package/kit/check-messages.mjs +9 -0
- package/kit/check.mjs +8 -0
- package/kit/core/bookmark.mjs +28 -0
- package/kit/core/build-core.mjs +5 -3
- package/kit/core/check-parity.mjs +6 -0
- package/kit/core/check-rules.mjs +4 -3
- package/kit/core/check-source.mjs +10 -1
- package/kit/core/checks.mjs +79 -0
- package/kit/core/find-replace.mjs +170 -0
- package/kit/core/format.mjs +4 -1
- package/kit/core/image-insert.mjs +197 -0
- package/kit/core/image-size.mjs +1 -1
- package/kit/core/layout-scan.mjs +1 -1
- package/kit/core/llm-fix.mjs +1 -1
- package/kit/core/llm-pack-assemble.mjs +40 -67
- package/kit/core/llm-pack-data.mjs +882 -52
- 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 +3 -0
- package/kit/core/portable.mjs +5 -2
- package/kit/core/purposes.mjs +9 -3
- package/kit/core/sample-info.mjs +17 -3
- package/kit/core/scorm.mjs +30 -6
- package/kit/core/script-unclosed.mjs +49 -0
- package/kit/core/slide-ops.mjs +27 -1
- package/kit/core/tate-mix.mjs +25 -0
- package/kit/core/template-text.mjs +2 -0
- package/kit/core/theme-derive.mjs +56 -17
- package/kit/core/theme-shapes.mjs +15 -1
- package/kit/deck.js +124 -6
- package/kit/instruction-version.json +1 -1
- package/kit/layouts.css +8 -0
- package/kit/llm-pack.mjs +5 -7
- package/kit/panes.js +17 -1
- 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/kit/track.js +46 -5
- package/package.json +1 -1
- package/server/editor-ui.js +21 -1
- package/vendor/components/CATALOG.md +25 -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/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
- package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -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/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
- package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -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/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
- package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -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/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
- package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -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/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
- package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
- package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
- package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
- package/vendor/components/sha256/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -0
- package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
- package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -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/components-2/manifest-2.20.0.json +3217 -0
- package/vendor/components-2/manifest-2.21.0.json +3220 -0
- package/vendor/egatari-spec/SOURCE.json +2 -2
- package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
- package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// m-contrast 2.0.0: a contrast figure, earlier work against this work, for positioning a study (handoff #71).
|
|
2
|
+
// kind "answers" (default): questions and their answers. A row per question (1 to 3): the question on the left, the
|
|
3
|
+
// earlier answer in the middle ({"text", "by"}, or {"unknown": true, "near"}: a dashed box with 不明 / Unknown and what is
|
|
4
|
+
// known under nearby conditions), an arrow, and this work's answer on the right with its basis, framed in --emph.
|
|
5
|
+
// Columns are headed 問い / 従来 / 本研究 (heads, selfLabel). Steps (order "build"): the questions → the earlier
|
|
6
|
+
// answers → the arrows and this work's answers; order "row": a row per step; order "whole": everything at once.
|
|
7
|
+
// kind "assumptions": the assumptions of near studies (2 to 3 rows of chips, each with what it yields), then this work's
|
|
8
|
+
// row: the assumptions it keeps, those it drops (written 外した / dropped, struck through) and those it adds (written
|
|
9
|
+
// 加えた / added, in --emph), and what it newly yields. Steps: the studies → this work's row with what it keeps and
|
|
10
|
+
// drops → what it adds → its result (order "whole": at once).
|
|
11
|
+
// This work is written out (selfLabel, default 本研究 / This work) and framed, never colour alone. The readable table
|
|
12
|
+
// (data-readable) gives the final state. Boxes and chips are data-part boxes and their texts labels (Studio's geometry
|
|
13
|
+
// check). Text is size px (≥ 24); when the figure does not fit at 24 px the part reports size with what it needs.
|
|
14
|
+
// Colours: earlier boxes --muted, unknown dashed --muted, this work --emph, chips --term, lines --line, notes --muted.
|
|
15
|
+
egatariParts.define({name: "contrast", version: "2.0.0", requires: {base: "1.3.0"}, element: "m-contrast"}, function(deps){
|
|
16
|
+
"use strict";
|
|
17
|
+
var base = deps.base;
|
|
18
|
+
var T = {ja: {self: "本研究", answers: ["問い", "従来", null], assumptions: ["研究", "仮定", "得られること"], unknown: "不明",
|
|
19
|
+
dropped: "外した", added: "加えた", sep: ":", label: "対比の図:", list: "、"},
|
|
20
|
+
en: {self: "This work", answers: ["Question", "Earlier", null], assumptions: ["Study", "Assumptions", "Yields"], unknown: "Unknown",
|
|
21
|
+
dropped: "dropped", added: "added", sep: ": ", label: "Contrast: ", list: ", "}};
|
|
22
|
+
var STR = {type: "string"}, STRS = {type: "array", items: STR};
|
|
23
|
+
// lines no wider than maxW by measure (as m-matrix 2.1): "\n" breaks; Latin runs, "7 割" and 、。)」 stay together;
|
|
24
|
+
// a break after 、。 late in the line, or after hiragana before a kanji, is preferred
|
|
25
|
+
var TOKEN = /[A-Za-z0-9.,%+\-\/]+(?: [^\sA-Za-z0-9、。,.)」])?[、。,.)」]*|\S[、。,.・)」]*|\s+/g;
|
|
26
|
+
var HIRA = /[ぁ-ゟ]/, WORD = /[一-鿿゠-ヿA-Za-z0-9]/;
|
|
27
|
+
function breakAt(t){
|
|
28
|
+
var n = t.length, i;
|
|
29
|
+
for (i = n - 1; i >= n * 0.6; i--) if (/[、。,.]/.test(t[i - 1]) && i < n) return i;
|
|
30
|
+
for (i = n - 1; i >= n * 0.35; i--) if (HIRA.test(t[i - 1]) && (WORD.test(t[i]) || (t[i] === " " && WORD.test(t[i + 1] || "")))) return i;
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
function wrap(s, maxW, measure){
|
|
34
|
+
var out = [];
|
|
35
|
+
String(s).split("\n").forEach(function(part){
|
|
36
|
+
var cur = "", toks = part.match(TOKEN) || [];
|
|
37
|
+
toks.forEach(function(tok){
|
|
38
|
+
if (/^\s+$/.test(tok)) { if (cur) cur += " "; return; }
|
|
39
|
+
if (!cur || measure(cur + tok) <= maxW) { cur += tok; return; }
|
|
40
|
+
var line = cur.replace(/ +$/, ""), rest = "", p = breakAt(line + tok);
|
|
41
|
+
if (p > 0 && p < line.length) { rest = line.slice(p).replace(/^ +/, ""); line = line.slice(0, p).replace(/ +$/, ""); }
|
|
42
|
+
out.push(line); cur = rest + tok;
|
|
43
|
+
});
|
|
44
|
+
out.push(cur.replace(/ +$/, ""));
|
|
45
|
+
});
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
// balanced: the narrowest width that keeps the number of lines (no one-character last line)
|
|
49
|
+
function balanced(s, full, measure){
|
|
50
|
+
var ls = wrap(s, full, measure);
|
|
51
|
+
if (ls.length < 2) return ls;
|
|
52
|
+
var lo = full / ls.length, hi = full;
|
|
53
|
+
for (var it = 0; it < 12; it++) { var mid = (lo + hi) / 2; if (wrap(s, mid, measure).length > ls.length) lo = mid; else hi = mid; }
|
|
54
|
+
return wrap(s, hi, measure);
|
|
55
|
+
}
|
|
56
|
+
var str = function(v){ return typeof v === "string" && v.trim() ? v.trim() : ""; };
|
|
57
|
+
var arr = function(v){ return Array.isArray(v) ? v.map(String).filter(function(s){ return s.trim(); }) : []; };
|
|
58
|
+
return class extends base.MotionElement {
|
|
59
|
+
static partName = "contrast";
|
|
60
|
+
static shape = {
|
|
61
|
+
schema: {type: "object", additionalProperties: false, properties: {
|
|
62
|
+
kind: {type: "string", enum: ["answers", "assumptions"]},
|
|
63
|
+
heads: {type: "array", minItems: 3, maxItems: 3, items: STR},
|
|
64
|
+
selfLabel: STR,
|
|
65
|
+
rows: {type: "array", minItems: 1, maxItems: 3, items: {type: "object", additionalProperties: false, required: ["q", "before", "after"], properties: {
|
|
66
|
+
q: STR, after: STR, basis: STR,
|
|
67
|
+
before: {type: "object", additionalProperties: false, properties: {text: STR, by: STR, unknown: {type: "boolean"}, near: STR}}}}},
|
|
68
|
+
studies: {type: "array", minItems: 1, maxItems: 3, items: {type: "object", additionalProperties: false, required: ["label", "chips", "result"], properties: {
|
|
69
|
+
label: STR, chips: STRS, result: STR}}},
|
|
70
|
+
self: {type: "object", additionalProperties: false, required: ["result"], properties: {dropped: STRS, kept: STRS, added: STRS, result: STR}}}},
|
|
71
|
+
example: {kind: "answers", rows: [{q: "差はどこにあるか", before: {unknown: true, near: "国の間の差は [2]"}, after: "7 割は学校の間", basis: "3 年分の全数データ"}]},
|
|
72
|
+
note: {en: "answers: rows [{\"q\", \"before\": {\"text\", \"by\"} or {\"unknown\": true, \"near\"}, \"after\", \"basis\"?}]. assumptions: studies [{\"label\", \"chips\", \"result\"}], self {\"kept\", \"dropped\", \"added\", \"result\"}",
|
|
73
|
+
ja: "answers:rows は [{\"q\", \"before\": {\"text\", \"by\"} か {\"unknown\": true, \"near\"}, \"after\", \"basis\"?}]。assumptions:studies は [{\"label\", \"chips\", \"result\"}]、self は {\"kept\", \"dropped\", \"added\", \"result\"}"},
|
|
74
|
+
};
|
|
75
|
+
static props = {
|
|
76
|
+
order: {type: "string", default: "", doc: "出し方:build(既定。answers は列ごと、assumptions は研究 → 本研究)・row(answers の行ごと)・whole"},
|
|
77
|
+
dur: {type: "number", default: 0.6, doc: "1 ステップの秒数"},
|
|
78
|
+
size: {type: "number", default: 28, doc: "字の大きさ(px、24 以上。入らなければ 24 まで縮める)"},
|
|
79
|
+
};
|
|
80
|
+
get steps(){
|
|
81
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
82
|
+
return this.plan().steps;
|
|
83
|
+
}
|
|
84
|
+
// what is drawn and when; from the data alone
|
|
85
|
+
plan(){
|
|
86
|
+
if (this._plan) return this._plan;
|
|
87
|
+
var d = this.data || {}, bad = [], lang = this.closest && this.closest("[lang]") ? this.closest("[lang]").getAttribute("lang") : "ja";
|
|
88
|
+
var L = /^en\b/i.test(lang) ? T.en : T.ja, kind = d.kind || "answers", order = this.props.order || "build", selfLabel = str(d.selfLabel) || L.self;
|
|
89
|
+
if (kind !== "answers" && kind !== "assumptions") { bad.push("kind is answers or assumptions, not " + kind); kind = "answers"; }
|
|
90
|
+
var heads = (L[kind]).map(function(h, i){ var v = Array.isArray(d.heads) ? str(d.heads[i]) : ""; return v || h || selfLabel; });
|
|
91
|
+
if (d.heads !== undefined && (!Array.isArray(d.heads) || d.heads.length !== 3)) bad.push("heads is 3 texts (" + L[kind].map(function(h){ return h || selfLabel; }).join(", ") + ")");
|
|
92
|
+
var steps = 1, rows = [];
|
|
93
|
+
if (kind === "answers") {
|
|
94
|
+
if (["build", "row", "whole"].indexOf(order) < 0) bad.push("order for answers is build, row or whole, not " + order);
|
|
95
|
+
var rs = Array.isArray(d.rows) ? d.rows : [];
|
|
96
|
+
if (rs.length < 1 || rs.length > 3) bad.push("answers needs 1 to 3 rows (a question each); split the slide for more");
|
|
97
|
+
rs.slice(0, 3).forEach(function(r, i){
|
|
98
|
+
r = r || {};
|
|
99
|
+
var b = r.before && typeof r.before === "object" ? r.before : {}, unknown = b.unknown === true;
|
|
100
|
+
if (!str(r.q)) bad.push("row " + (i + 1) + " has no question (q)");
|
|
101
|
+
if (!str(r.after)) bad.push("row " + (i + 1) + " has no answer of this work (after)");
|
|
102
|
+
if (!unknown && !str(b.text)) bad.push("row " + (i + 1) + ": before is {\"text\", \"by\"} or {\"unknown\": true, \"near\"}");
|
|
103
|
+
var at = function(col){ return order === "whole" ? 1 : order === "row" ? i + 1 : col; };
|
|
104
|
+
rows.push({q: str(r.q), before: unknown ? {unknown: true, near: str(b.near)} : {text: str(b.text), by: str(b.by)},
|
|
105
|
+
after: str(r.after), basis: str(r.basis), sQ: at(1), sB: at(2), sA: at(3)});
|
|
106
|
+
});
|
|
107
|
+
steps = order === "whole" ? 1 : order === "row" ? Math.max(1, rows.length) : 3;
|
|
108
|
+
} else {
|
|
109
|
+
if (["build", "whole"].indexOf(order) < 0) bad.push("order for assumptions is build or whole, not " + order);
|
|
110
|
+
var whole = order === "whole", ss = Array.isArray(d.studies) ? d.studies : [], me = d.self && typeof d.self === "object" ? d.self : null;
|
|
111
|
+
if (ss.length < 1 || ss.length > 3) bad.push("assumptions needs 1 to 3 near studies (studies)");
|
|
112
|
+
ss.slice(0, 3).forEach(function(s, i){
|
|
113
|
+
s = s || {};
|
|
114
|
+
if (!str(s.label) || !arr(s.chips).length) bad.push("study " + (i + 1) + " needs a label and its assumptions (chips)");
|
|
115
|
+
rows.push({label: str(s.label), chips: arr(s.chips).map(function(c){ return {text: c, step: 1}; }), result: str(s.result), sL: 1, sR: 1});
|
|
116
|
+
});
|
|
117
|
+
if (!me) bad.push("assumptions needs this work's row (self: {\"kept\", \"dropped\", \"added\", \"result\"})");
|
|
118
|
+
me = me || {};
|
|
119
|
+
var added = arr(me.added), sAdd = whole ? 1 : 3, sRes = whole ? 1 : added.length ? 4 : 3;
|
|
120
|
+
if (!arr(me.dropped).length && !added.length) bad.push("this work's row drops or adds at least one assumption (self.dropped, self.added)");
|
|
121
|
+
rows.push({self: true, label: selfLabel, result: str(me.result), sL: whole ? 1 : 2, sR: sRes,
|
|
122
|
+
chips: arr(me.kept).map(function(c){ return {text: c, step: whole ? 1 : 2}; })
|
|
123
|
+
.concat(arr(me.dropped).map(function(c){ return {text: c, step: whole ? 1 : 2, dropped: true}; }))
|
|
124
|
+
.concat(added.map(function(c){ return {text: c, step: sAdd, added: true}; }))});
|
|
125
|
+
steps = whole ? 1 : sRes;
|
|
126
|
+
}
|
|
127
|
+
return (this._plan = {kind: kind, L: L, bad: bad, heads: heads, rows: rows, steps: steps, selfLabel: selfLabel});
|
|
128
|
+
}
|
|
129
|
+
mount(ctx){
|
|
130
|
+
var self = this, P = this.props, D = base, pl = this.plan();
|
|
131
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
132
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
133
|
+
if (!(P.dur >= 0)) { ctx.report("attr", "[contrast] dur must be ≥ 0; using 0.6"); P.dur = 0.6; }
|
|
134
|
+
if (!(P.size >= 24)) { ctx.report("attr", "[contrast] size must be ≥ 24; using 28"); P.size = 28; }
|
|
135
|
+
pl.bad.forEach(function(m){ ctx.report("data", "[contrast] " + m); });
|
|
136
|
+
if (!pl.rows.length) return;
|
|
137
|
+
var fit = null;
|
|
138
|
+
for (var fs = Math.round(P.size); fs >= 24 && !fit; fs -= 2) fit = this._fit(fs, W, H);
|
|
139
|
+
if (!fit) {
|
|
140
|
+
fit = this._fit(24, W, H, true);
|
|
141
|
+
ctx.report("size", "[contrast] the figure needs " + Math.ceil(fit.needW) + " × " + Math.ceil(fit.needH) + " px at 24 px; the element is " + W + " × " + H + " px (fewer rows, shorter texts, or a larger element)");
|
|
142
|
+
}
|
|
143
|
+
var G = this.geo = fit, fsz = G.fs, lh = G.lh;
|
|
144
|
+
var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
145
|
+
var gL = D.el("g", {}, svg), gI = D.el("g", {}, svg);
|
|
146
|
+
// the header: a label over each column, a line under them
|
|
147
|
+
this.items = [];
|
|
148
|
+
var add = function(step, g){ self.items.push({step: step, g: g}); return g; };
|
|
149
|
+
var gH = add(0, D.el("g", {}, gI));
|
|
150
|
+
G.heads.forEach(function(h){
|
|
151
|
+
var t = D.el("text", {x: h.x.toFixed(1), y: h.y.toFixed(1), "font-size": fsz, "font-weight": 700, "text-anchor": "middle", fill: "var(--fg)"}, gH);
|
|
152
|
+
t.textContent = h.s;
|
|
153
|
+
});
|
|
154
|
+
D.el("line", {x1: G.x0, x2: G.x1, y1: G.headLine, y2: G.headLine, stroke: "var(--line)", "stroke-width": 2.5}, gL);
|
|
155
|
+
G.seps.forEach(function(y){ D.el("line", {x1: G.x0, x2: G.x1, y1: y, y2: y, stroke: "var(--line)", "stroke-width": 1.2}, gL); });
|
|
156
|
+
// a box with its lines of text; lines are {s, tone: fg|muted|emph, bold, strike}
|
|
157
|
+
var text = function(g, b, id){
|
|
158
|
+
var n = b.lines.length, top = b.y + b.h / 2 - (n - 1) * lh / 2 + fsz * 0.36, left = b.align === "start";
|
|
159
|
+
b.lines.forEach(function(l, i){
|
|
160
|
+
var t = D.el("text", {x: (left ? b.x + G.pad : b.x + b.w / 2).toFixed(1), y: (top + i * lh).toFixed(1), "font-size": fsz,
|
|
161
|
+
"text-anchor": left ? "start" : "middle", fill: "var(--" + (l.tone || "fg") + ")", "font-weight": l.bold ? 700 : 400,
|
|
162
|
+
"data-part": "label", "data-part-id": id, "data-part-of": "box"}, g);
|
|
163
|
+
t.textContent = l.s;
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
G.boxes.forEach(function(b, i){
|
|
167
|
+
var g = add(b.step, D.el("g", {}, gI)), id = b.id || "b" + i;
|
|
168
|
+
var r = D.el("rect", {x: b.x.toFixed(1), y: b.y.toFixed(1), width: b.w.toFixed(1), height: b.h.toFixed(1), rx: b.rx || 10,
|
|
169
|
+
fill: b.fill || "none", stroke: b.stroke || "none", "stroke-width": b.sw || 0, "data-part": "box", "data-part-id": id}, g);
|
|
170
|
+
if (b.dash) r.setAttribute("stroke-dasharray", "9 6");
|
|
171
|
+
text(g, b, id);
|
|
172
|
+
if (b.strike) D.el("line", {x1: (b.x + b.strike[0]).toFixed(1), x2: (b.x + b.w - b.strike[1]).toFixed(1), y1: (b.y + b.h / 2).toFixed(1), y2: (b.y + b.h / 2).toFixed(1),
|
|
173
|
+
stroke: "var(--fg)", "stroke-width": 2.5}, g);
|
|
174
|
+
});
|
|
175
|
+
G.arrows.forEach(function(a){
|
|
176
|
+
var g = add(a.step, D.el("g", {}, gI)), hd = fsz * 0.42;
|
|
177
|
+
D.el("line", {x1: a.x1.toFixed(1), x2: (a.x2 - hd).toFixed(1), y1: a.y.toFixed(1), y2: a.y.toFixed(1), stroke: "var(--muted)", "stroke-width": 3}, g);
|
|
178
|
+
D.el("path", {d: "M" + (a.x2 - hd).toFixed(1) + "," + (a.y - hd * 0.6).toFixed(1) + "L" + a.x2.toFixed(1) + "," + a.y.toFixed(1) + "L" + (a.x2 - hd).toFixed(1) + "," + (a.y + hd * 0.6).toFixed(1) + "Z", fill: "var(--muted)"}, g);
|
|
179
|
+
});
|
|
180
|
+
G.frames.forEach(function(f){
|
|
181
|
+
add(f.step, D.el("rect", {x: f.x.toFixed(1), y: f.y.toFixed(1), width: f.w.toFixed(1), height: f.h.toFixed(1), rx: 8, fill: "none", stroke: "var(--emph)", "stroke-width": 4}, gI));
|
|
182
|
+
});
|
|
183
|
+
// the readable table: the final state
|
|
184
|
+
var L = pl.L, tbl = document.createElement("table");
|
|
185
|
+
tbl.className = "sr-only"; tbl.setAttribute("data-readable", "");
|
|
186
|
+
tbl.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);border:0");
|
|
187
|
+
var tr = function(list, th){ var e = document.createElement("tr"); list.forEach(function(s, i){ var td = document.createElement(th || i === 0 ? "th" : "td"); td.textContent = s; e.appendChild(td); }); tbl.appendChild(e); };
|
|
188
|
+
tr(pl.heads, true);
|
|
189
|
+
pl.rows.forEach(function(r){
|
|
190
|
+
if (pl.kind === "answers") {
|
|
191
|
+
var b = r.before.unknown ? L.unknown + (r.before.near ? "(" + r.before.near + ")" : "") : r.before.text + (r.before.by ? " " + r.before.by : "");
|
|
192
|
+
tr([r.q, b, r.after + (r.basis ? "(" + r.basis + ")" : "")]);
|
|
193
|
+
} else {
|
|
194
|
+
tr([r.label, r.chips.map(function(c){ return (c.dropped ? L.dropped + L.sep : c.added ? L.added + L.sep : "") + c.text; }).join(L.list), r.result]);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
this.appendChild(tbl);
|
|
198
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
199
|
+
this.setAttribute("role", "img");
|
|
200
|
+
if (!this._aria) this.setAttribute("aria-label", L.label + pl.heads.join(" / "));
|
|
201
|
+
}
|
|
202
|
+
// the geometry at font size fs; null when it does not fit W × H (unless force)
|
|
203
|
+
_fit(fs, W, H, force){
|
|
204
|
+
var pl = this.plan(), D = base, self = this, pad = Math.round(fs * 0.5), lh = Math.ceil(fs * 1.3);
|
|
205
|
+
var tw = function(s, b){ return D.textWidth(s, fs, {font: self}) * (b ? 1.06 : 1); };
|
|
206
|
+
var m = function(t){ return tw(t); }, mb = function(t){ return tw(t, true); };
|
|
207
|
+
var lines = function(s, w, tone, bold){ return s ? balanced(s, w, bold ? mb : m).map(function(x){ return {s: x, tone: tone, bold: bold}; }) : []; };
|
|
208
|
+
var arrowW = Math.round(fs * 2.2), x0 = 2, x1 = W - 2, inner = x1 - x0, hh = Math.ceil(fs * 1.5), gap = Math.round(fs * 0.45);
|
|
209
|
+
var boxH = function(n){ return Math.ceil(n * lh + fs * 0.7); };
|
|
210
|
+
var boxes = [], arrows = [], frames = [], heads = [], seps = [], rowsH = [], cols, needW = inner;
|
|
211
|
+
if (pl.kind === "answers") {
|
|
212
|
+
var qW = Math.round((inner - arrowW) * 0.27), bW = Math.round((inner - arrowW) * 0.33), aW = inner - arrowW - qW - bW - gap;
|
|
213
|
+
cols = [x0, x0 + qW + gap, x0 + qW + gap + bW + arrowW];
|
|
214
|
+
var widths = [qW, bW, aW];
|
|
215
|
+
pl.heads.forEach(function(h, i){ heads.push({s: h, x: cols[i] + widths[i] / 2}); if (tw(h, true) > widths[i]) needW = Math.max(needW, inner * tw(h, true) / widths[i]); });
|
|
216
|
+
pl.rows.forEach(function(r, i){
|
|
217
|
+
var tw2 = function(w){ return w - 2 * pad; };
|
|
218
|
+
var q = lines(r.q, tw2(qW), "fg");
|
|
219
|
+
var b = r.before.unknown ? [{s: pl.L.unknown, tone: "muted", bold: true}].concat(lines(r.before.near, tw2(bW), "muted"))
|
|
220
|
+
: lines(r.before.text, tw2(bW), "fg").concat(lines(r.before.by, tw2(bW), "muted"));
|
|
221
|
+
var a = lines(r.after, tw2(aW), "fg").concat(lines(r.basis, tw2(aW), "muted"));
|
|
222
|
+
rowsH.push({q: q, b: b, a: a, h: boxH(Math.max(q.length, b.length, a.length))});
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
var labW = Math.max.apply(null, pl.rows.map(function(r){ return tw(r.label, true); })) + 2 * pad;
|
|
226
|
+
labW = Math.min(Math.ceil(labW), Math.round(inner * 0.22));
|
|
227
|
+
var chipH = Math.ceil(fs * 1.45), cpad = Math.round(fs * 0.45), cgap = Math.round(fs * 0.35);
|
|
228
|
+
var pre = function(c){ return c.dropped ? pl.L.dropped + " " : c.added ? pl.L.added + " " : ""; };
|
|
229
|
+
var chipW = function(c){ return Math.ceil(tw(pre(c) + c.text, !!pre(c)) + 2 * cpad); };
|
|
230
|
+
// the chips column as wide as the longest row of chips needs, leaving the result at least a quarter
|
|
231
|
+
var nat = Math.max.apply(null, pl.rows.map(function(r){ return r.chips.reduce(function(a, c){ return a + chipW(c) + cgap; }, -cgap); }));
|
|
232
|
+
var cW = Math.max(fs * 4, Math.min(nat, inner - labW - arrowW - gap - Math.round(inner * 0.24))), rW = inner - labW - gap - cW - arrowW;
|
|
233
|
+
cols = [x0, x0 + labW + gap, x0 + labW + gap + cW + arrowW];
|
|
234
|
+
[labW, cW, rW].forEach(function(w, i){ heads.push({s: pl.heads[i], x: cols[i] + w / 2}); });
|
|
235
|
+
pl.rows.forEach(function(r){
|
|
236
|
+
// chips flow into lines inside the chips column
|
|
237
|
+
var cx = 0, ln = 0, placed = [];
|
|
238
|
+
r.chips.forEach(function(c){
|
|
239
|
+
var p = pre(c), w = chipW(c);
|
|
240
|
+
if (w > cW) needW = Math.max(needW, inner + w - cW);
|
|
241
|
+
if (cx > 0 && cx + w > cW) { ln++; cx = 0; }
|
|
242
|
+
placed.push({c: c, pre: p, dx: cx, ln: ln, w: Math.min(w, cW), sx: c.dropped ? cpad + tw(p, true) : 0}); cx += w + cgap;
|
|
243
|
+
});
|
|
244
|
+
var end = placed.reduce(function(a, q){ return Math.max(a, q.dx + q.w); }, 0);
|
|
245
|
+
var nl = placed.length ? ln + 1 : 0, chipsH = nl * chipH + Math.max(0, nl - 1) * cgap;
|
|
246
|
+
var lab = lines(r.label, labW - 2 * pad, r.self ? "emph" : "fg", true), res = lines(r.result, rW - 2 * pad, "fg", !!r.self);
|
|
247
|
+
rowsH.push({placed: placed, end: end, chipsH: chipsH, lab: lab, res: res, h: Math.max(boxH(Math.max(lab.length, res.length)), chipsH + fs * 0.7)});
|
|
248
|
+
});
|
|
249
|
+
var chipGeo = {chipH: chipH, cgap: cgap, cpad: cpad, cW: cW, labW: labW, rW: rW};
|
|
250
|
+
}
|
|
251
|
+
var bodyH = rowsH.reduce(function(s, r){ return s + r.h; }, 0) + gap * 2 * rowsH.length;
|
|
252
|
+
var needH = 4 + hh + bodyH + 4;
|
|
253
|
+
if (!force && (needH > H || needW > inner + 0.5)) return null;
|
|
254
|
+
// fill the element's height: rows grow, each to at most twice its height (no wide empty band under the figure)
|
|
255
|
+
if (needH < H) { var each = Math.min((H - needH) / rowsH.length, Math.min.apply(null, rowsH.map(function(r){ return r.h; }))); rowsH.forEach(function(r){ r.h += each; }); needH += each * rowsH.length; }
|
|
256
|
+
var y = 4 + hh, headLine = y;
|
|
257
|
+
heads.forEach(function(h){ h.y = 4 + hh / 2 + fs * 0.36; });
|
|
258
|
+
rowsH.forEach(function(R, i){
|
|
259
|
+
var top = y + gap, h = R.h, mid = top + h / 2, r = pl.rows[i];
|
|
260
|
+
if (i > 0) seps.push(y);
|
|
261
|
+
if (pl.kind === "answers") {
|
|
262
|
+
var qW2 = cols[1] - gap - cols[0], bW2 = cols[2] - arrowW - cols[1], aW2 = x1 - cols[2];
|
|
263
|
+
boxes.push({id: "q" + i, x: cols[0], y: top, w: qW2, h: h, lines: R.q, align: "start", step: r.sQ});
|
|
264
|
+
boxes.push({id: "b" + i, x: cols[1], y: top, w: bW2, h: h, lines: R.b, step: r.sB, stroke: "var(--muted)", sw: 2.2, dash: !!r.before.unknown});
|
|
265
|
+
boxes.push({id: "a" + i, x: cols[2], y: top, w: aW2, h: h, lines: R.a, step: r.sA, stroke: "var(--emph)", sw: 4});
|
|
266
|
+
arrows.push({x1: cols[1] + bW2 + 8, x2: cols[2] - 8, y: mid, step: r.sA});
|
|
267
|
+
} else {
|
|
268
|
+
var g = chipGeo;
|
|
269
|
+
boxes.push({id: "l" + i, x: cols[0], y: top, w: g.labW, h: h, lines: R.lab, align: "start", step: r.sL});
|
|
270
|
+
var cy0 = mid - R.chipsH / 2;
|
|
271
|
+
R.placed.forEach(function(p, j){
|
|
272
|
+
var c = p.c, l = p.pre ? [{s: p.pre + c.text, tone: c.added ? "emph" : "muted", bold: true}] : [{s: c.text, tone: "fg"}];
|
|
273
|
+
boxes.push({id: "c" + i + "-" + j, x: cols[1] + p.dx, y: cy0 + p.ln * (g.chipH + g.cgap), w: p.w, h: g.chipH, lines: l, step: c.step, rx: g.chipH / 2,
|
|
274
|
+
stroke: c.added ? "var(--emph)" : c.dropped ? "var(--muted)" : "var(--term)", sw: c.added ? 3 : 2, dash: !!c.dropped,
|
|
275
|
+
fill: c.added ? "var(--emph-tint)" : c.dropped ? "none" : "var(--term-tint)", strike: c.dropped ? [p.sx, g.cpad] : null});
|
|
276
|
+
});
|
|
277
|
+
boxes.push({id: "r" + i, x: cols[2], y: top, w: g.rW, h: h, lines: R.res, step: r.sR});
|
|
278
|
+
arrows.push({x1: cols[1] + R.end + 10, x2: cols[2] - 8, y: mid, step: r.sR});
|
|
279
|
+
if (r.self) frames.push({x: x0, y: top - gap * 0.6, w: inner, h: h + gap * 1.2, step: r.sL});
|
|
280
|
+
}
|
|
281
|
+
y = top + h + gap;
|
|
282
|
+
});
|
|
283
|
+
return {fs: fs, pad: pad, lh: lh, x0: x0, x1: x1, heads: heads, headLine: headLine, seps: seps, boxes: boxes, arrows: arrows, frames: frames, needW: needW, needH: needH};
|
|
284
|
+
}
|
|
285
|
+
duration(k){ return k >= 1 && k <= this.plan().steps ? this.props.dur : 0; }
|
|
286
|
+
render(k, t, ctx){
|
|
287
|
+
if (!this.items) return;
|
|
288
|
+
var D = base, P = this.props, N = this.plan().steps, faint = ctx && (ctx.preview || ctx.mode === "lecture") ? base.previewOpacity(this) : 0;
|
|
289
|
+
k = Math.max(0, Math.min(k, N));
|
|
290
|
+
var e = k === 0 ? 1 : D.prog(t, 0, P.dur);
|
|
291
|
+
this.items.forEach(function(o){ var v = o.step < k ? 1 : o.step > k ? 0 : e; o.g.setAttribute("opacity", Math.max(v, o.step > k ? faint : 0).toFixed(3)); });
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Rotate validation folds
|
|
3
|
+
steps: Rows → mean (k+1)
|
|
4
|
+
props:
|
|
5
|
+
dur: Seconds
|
|
6
|
+
size: Text px
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
JSON:
|
|
10
|
+
- `k`: 2–10; k=5: ≥316px tall (264 without errors)
|
|
11
|
+
- `errors`: k errors (optional).
|
|
12
|
+
- `labels`: k names (optional).
|
|
13
|
+
|
|
14
|
+
<!-- llm: omit -->
|
|
15
|
+
Equal blocks. Row i validates block i: emph tint + outline; training: term tint. Legend explains outline. Blocks ≥40px with enough height: T/V; short rows drop letters first, retaining the legend and outlines. Names once above. Errors/mean: 2 decimals. Final rule and mean below errors; omitted errors leave completed splits at k+1.
|
|
16
|
+
|
|
17
|
+
Wrong lengths, negative errors or invalid k: report, no draw. dur 1s; size 0=26px, ≥24. Bad props default/report.
|
|
18
|
+
|
|
19
|
+
Suggested width: 1184px. Rows shrink from ~46px to 32px before reporting. At default 26px text, minimum height = ceil(99.4+32k+56.1) = **156+32k px** with errors; **104+32k px** without. k=5: 316/264px; k=10: 476/424px. Compact row numbers/errors use monospace.
|
|
20
|
+
|
|
21
|
+
General: f=text px, L=1.45f+4, R=max(32,ceil(1.2f)); minimum=ceil(2L+16+kR+footer+4), footer=L+.4f with errors, else 0. Size reports give k, required/current height and its terms; legend width needed/available; label index and width needed/available.
|
|
22
|
+
|
|
23
|
+
ctx.lang selects ja/en. Font boxes ≥1.43em plus gap. Image role, final summary; preserve author label, hide SVG. No answer preview. Fictional demo.
|
|
24
|
+
<!-- llm: end -->
|
|
25
|
+
|
|
26
|
+
<!-- llm: omit -->
|
|
27
|
+
Per-sample splits (2.1.0): `splits` (`test`, `train` indices) and `samples` (`class`, `group`, `t`) from `uv run tools/sk2ega.py model_selection`. `splitter`: KFold, StratifiedKFold, GroupKFold, TimeSeriesSplit, ShuffleSplit, holdout. Checks: KFold-type splitters test each sample once; groups stay together; time series train on the past; stratified class counts within 1; one holdout split. Class colours: `--series-1`, `--series-3`, `--fg`, `--series-4` in that order, as in m-classify2d. Up to 60 samples and 10 splits.
|
|
28
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// m-folds: the validation block advances through k train/validation splits.
|
|
2
|
+
// 2.1.0: with `splits` (and `samples`), each sample is a cell and each row is one split from scikit-learn's splitter
|
|
3
|
+
// (KFold with shuffle, StratifiedKFold = クラスの比率を保つ KFold, GroupKFold, TimeSeriesSplit, a holdout): test cells as the
|
|
4
|
+
// validation block, train cells as before, unused cells empty; class colours and names, group runs, time order. The k mode
|
|
5
|
+
// draws exactly as 2.0.1.
|
|
6
|
+
egatariParts.define({name: "folds", version: "2.1.2", requires: {base: "1.3.0"}, element: "m-folds"}, function(deps){
|
|
7
|
+
"use strict";
|
|
8
|
+
var base = deps.base;
|
|
9
|
+
var TEXT = {
|
|
10
|
+
ja: {train: "学習(学)", validate: "検証(検・枠)", t: "学", v: "検", error: "誤差", mean: "平均", fold: "分割", unused: "使わない", cls: "クラス", group: "グループ", time: "時間 →", test: "検証", trainS: "訓練"},
|
|
11
|
+
en: {train: "train (T)", validate: "validate (V, outline)", t: "T", v: "V", error: "error", mean: "mean", fold: "fold", unused: "unused", cls: "class", group: "group", time: "time →", test: "validate", trainS: "train"}
|
|
12
|
+
};
|
|
13
|
+
function set(e, a, v){ e.setAttribute(a, String(v)); }
|
|
14
|
+
function fmt(v){ return v.toFixed(2); }
|
|
15
|
+
var PAL = ["var(--series-1)", "var(--series-3)", "var(--fg)", "var(--series-4)"]; // m-classify2d の CLASS_COLORS と同じ並び
|
|
16
|
+
return class extends base.MotionElement {
|
|
17
|
+
static partName = "folds";
|
|
18
|
+
static preview = "none";
|
|
19
|
+
static shape = {schema: {type: "object", additionalProperties: false, anyOf: [{required: ["k"]}, {required: ["splits"]}], properties: {
|
|
20
|
+
k: {type: "number"}, errors: {type: "array", items: {type: "number"}}, labels: {type: "array", items: {type: "string"}},
|
|
21
|
+
samples: {type: "array", minItems: 2, maxItems: 60, items: {type: "object", additionalProperties: false, properties: {class: {type: "integer"}, group: {type: "string"}, t: {type: ["number", "string"]}}}},
|
|
22
|
+
splits: {type: "array", minItems: 1, maxItems: 10, items: {type: "object", additionalProperties: false, required: ["test"], properties: {test: {type: "array", items: {type: "integer"}}, train: {type: "array", items: {type: "integer"}}}}},
|
|
23
|
+
splitter: {type: "string", enum: ["KFold", "StratifiedKFold", "GroupKFold", "TimeSeriesSplit", "ShuffleSplit", "holdout"]},
|
|
24
|
+
classes: {type: "array", maxItems: 4, items: {type: "object", additionalProperties: false, required: ["id"], properties: {id: {type: "integer"}, label: {type: "string"}}}}
|
|
25
|
+
}}, example: {k: 5, errors: [0.21, 0.18, 0.25, 0.19, 0.22], labels: ["1", "2", "3", "4", "5"]}};
|
|
26
|
+
static props = {
|
|
27
|
+
dur: {type: "number", default: 1, doc: "ステップの秒数"},
|
|
28
|
+
size: {type: "number", default: 0, doc: "文字 px(0 は 26)"}
|
|
29
|
+
};
|
|
30
|
+
get steps(){ if (this.data.splits) return this.data.splits.length + 1; var k = this.data.k; return Number.isInteger(k) && k >= 2 && k <= 10 ? k + 1 : 0; }
|
|
31
|
+
duration(k){ return k >= 1 && k <= this.steps ? this.props.dur : 0; }
|
|
32
|
+
label(g, x, y, s, anchor){
|
|
33
|
+
var e = base.el("text", {x: x, y: y, "font-size": this.fs, "text-anchor": anchor || "start", fill: "var(--fg)"}, g);
|
|
34
|
+
e.textContent = s; return e;
|
|
35
|
+
}
|
|
36
|
+
mount(ctx){
|
|
37
|
+
var self = this, d = this.data, P = this.props;
|
|
38
|
+
this.T = /^ja\b/i.test(ctx.lang || "") ? TEXT.ja : TEXT.en;
|
|
39
|
+
var T = this.T;
|
|
40
|
+
if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[folds] dur must be positive; using 1"); P.dur = 1; }
|
|
41
|
+
if (!(P.size === 0 || Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[folds] size must be 0 or at least 24; using 26"); P.size = 0; }
|
|
42
|
+
this.fs = P.size || 26;
|
|
43
|
+
this.style.display = "block"; this.style.position = "relative"; this.style.writingMode = "horizontal-tb"; this.setAttribute("role", "img");
|
|
44
|
+
if (d.splits) return this.mountSamples(ctx);
|
|
45
|
+
if (!Number.isInteger(d.k) || d.k < 2 || d.k > 10){ ctx.report("data", "[folds] k must be an integer 2–10"); return; }
|
|
46
|
+
if (d.errors && (d.errors.length !== d.k || d.errors.some(function(v){ return v < 0; }))){ ctx.report("data", "[folds] errors must contain k non-negative numbers"); return; }
|
|
47
|
+
if (d.labels && d.labels.length !== d.k){ ctx.report("data", "[folds] labels must contain k names"); return; }
|
|
48
|
+
var labels = d.labels || Array.from({length: d.k}, function(_, i){ return String(i + 1); });
|
|
49
|
+
var errors = d.errors || null, mean = errors ? errors.reduce(function(s, v){ return s + v / d.k; }, 0) : null;
|
|
50
|
+
this.model = {k: d.k, labels: labels, errors: errors, mean: mean};
|
|
51
|
+
var summary = labels.map(function(s, i){ return T.fold + " " + (i + 1) + ": " + T.validate + " " + s + ", " + T.train + " " + labels.filter(function(_, j){ return j !== i; }).join(", ") + (errors ? "; " + T.error + " " + fmt(errors[i]) : ""); }).join("; ");
|
|
52
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", summary + (errors ? "; " + T.mean + " " + fmt(mean) : ""));
|
|
53
|
+
var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = this.fs, line = fs * 1.45 + 4;
|
|
54
|
+
var width = function(s){ return base.textWidth(s, fs, {font: self}); };
|
|
55
|
+
var errorWidth = errors ? Math.max(width(T.error), width(T.mean + " " + fmt(mean)), ...errors.map(function(v){ return Math.max(width(fmt(v)), fmt(v).length * fs * 0.62); })) + 8 : 0;
|
|
56
|
+
var left = Math.max(42, width(String(d.k)) + 16), ex = W - errorWidth - 8, right = errors ? ex - 20 : W - 8;
|
|
57
|
+
var bw = (right - left) / d.k, top = 2 * line + 16;
|
|
58
|
+
var footer = errors ? line + fs * 0.4 : 0, minRow = Math.max(32, Math.ceil(fs * 1.2));
|
|
59
|
+
var minHeight = Math.ceil(top + d.k * minRow + footer + 4);
|
|
60
|
+
var rh = Math.max(minRow, Math.min(Math.max(44, line + 4), (H - top - footer - 4) / d.k)), bh = rh - 6;
|
|
61
|
+
var letters = bh >= fs * 1.43;
|
|
62
|
+
this.geometry = {row: rh, minRow: minRow, minHeight: minHeight, letters: letters};
|
|
63
|
+
// Compact row numbers/errors use a monospace font whose box fits 32px rows.
|
|
64
|
+
function rowLabel(g, x, y, s, anchor){
|
|
65
|
+
var e = self.label(g, x, y, s, anchor);
|
|
66
|
+
if (!letters) e.setAttribute("style", "font-family:ui-monospace, Menlo, Consolas, monospace;fill:var(--fg)");
|
|
67
|
+
return e;
|
|
68
|
+
}
|
|
69
|
+
this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
|
|
70
|
+
this.header = base.el("g", {opacity: 0}, this.svg);
|
|
71
|
+
function swatch(x, validate, text){
|
|
72
|
+
base.el("rect", {x: x, y: 8, width: 32, height: fs * 1.45, fill: validate ? "var(--emph-tint)" : "var(--term-tint)", stroke: validate ? "var(--emph)" : "none", "stroke-width": 3}, self.header);
|
|
73
|
+
self.label(self.header, x + 42, fs + 4, text);
|
|
74
|
+
}
|
|
75
|
+
var legend2 = 8 + 42 + width(T.train) + 28;
|
|
76
|
+
swatch(8, false, T.train); swatch(legend2, true, T.validate);
|
|
77
|
+
var legendWidth = Math.ceil(legend2 + 42 + width(T.validate) + 8);
|
|
78
|
+
if (legendWidth > W) ctx.report("size", "[folds] legend needs " + legendWidth + " px width; element has " + W + " px");
|
|
79
|
+
if (bw < 8) ctx.report("size", "[folds] " + d.k + " blocks have " + Math.floor(bw) + " px each; allow at least 8 px per block");
|
|
80
|
+
labels.forEach(function(s, i){
|
|
81
|
+
self.label(self.header, left + (i + 0.5) * bw, 2 * line, s, "middle");
|
|
82
|
+
if (width(s) > bw - 8) ctx.report("size", "[folds] label " + (i + 1) + " needs " + Math.ceil(width(s)) + " px; block fits " + Math.max(0, Math.floor(bw - 8)) + " px (shorten the label)");
|
|
83
|
+
});
|
|
84
|
+
if (errors) this.label(this.header, ex, 2 * line, T.error);
|
|
85
|
+
this.rows = labels.map(function(_, i){
|
|
86
|
+
var g = base.el("g", {opacity: 0}, self.svg), y = top + i * rh;
|
|
87
|
+
rowLabel(g, left - 12, y + bh / 2 + fs * 0.31, String(i + 1), "end");
|
|
88
|
+
var blocks = labels.map(function(_, j){
|
|
89
|
+
var valid = i === j, x = left + j * bw + 3;
|
|
90
|
+
var rect = base.el("rect", {x: x, y: y, width: Math.max(1, bw - 6), height: bh, rx: 3, fill: valid ? "var(--emph-tint)" : "var(--term-tint)", stroke: valid ? "var(--emph)" : "none", "stroke-width": 3}, g);
|
|
91
|
+
if (letters && bw - 6 >= 40) self.label(g, x + (bw - 6) / 2, y + bh / 2 + fs * 0.31, valid ? T.v : T.t, "middle");
|
|
92
|
+
return {rect: rect, validation: valid};
|
|
93
|
+
});
|
|
94
|
+
if (errors) rowLabel(g, ex, y + bh / 2 + fs * 0.31, fmt(errors[i]));
|
|
95
|
+
return {g: g, blocks: blocks};
|
|
96
|
+
});
|
|
97
|
+
this.finalLayer = base.el("g", {opacity: 0}, this.svg);
|
|
98
|
+
var bottom = top + d.k * rh, finalY = bottom + line;
|
|
99
|
+
if (errors){
|
|
100
|
+
base.el("line", {x1: ex, x2: W - 8, y1: bottom + 6, y2: bottom + 6, stroke: "var(--muted)", "stroke-width": 2}, this.finalLayer);
|
|
101
|
+
this.label(this.finalLayer, ex, finalY, T.mean + " " + fmt(mean));
|
|
102
|
+
}
|
|
103
|
+
if (H < minHeight) ctx.report("size", "[folds] k = " + d.k + " needs at least " + minHeight + " px height (header " + top.toFixed(1) + " + " + d.k + " × " + minRow + " rows + " + (footer + 4).toFixed(1) + " footer); element has " + H + " px");
|
|
104
|
+
}
|
|
105
|
+
render(k, t){
|
|
106
|
+
if (this.sm) return this.renderSamples(k, t);
|
|
107
|
+
if (!this.model) return;
|
|
108
|
+
var dur = this.props.dur, phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, dur); };
|
|
109
|
+
set(this.header, "opacity", phase(1));
|
|
110
|
+
this.rows.forEach(function(o, i){ set(o.g, "opacity", phase(i + 1)); });
|
|
111
|
+
set(this.finalLayer, "opacity", phase(this.model.k + 1));
|
|
112
|
+
}
|
|
113
|
+
// 標本のモード(2.1.0):列が標本、行が分割。データの確かめと描き方。クラスの色は --emph(検証の枠)と同じ色にならないよう
|
|
114
|
+
// --series-2 を飛ばす(1 つの意味に 1 つの色)。m-classify2d の CLASS_COLORS と同じ並び
|
|
115
|
+
mountSamples(ctx){
|
|
116
|
+
var self = this, d = this.data, T = this.T, sp = d.splits, kind = d.splitter || "";
|
|
117
|
+
var n = d.samples ? d.samples.length : 1 + Math.max.apply(null, [].concat.apply([], sp.map(function(s){ return s.test.concat(s.train || []); })).concat([0]));
|
|
118
|
+
var samples = d.samples || Array.from({length: n}, function(){ return {}; }), bad = [];
|
|
119
|
+
if (n < 2 || n > 60) bad.push("splits cover " + n + " samples; 2–60 can be drawn");
|
|
120
|
+
var cls = {}; (d.classes || []).forEach(function(c, i){ cls[c.id] = i; });
|
|
121
|
+
samples.forEach(function(s, i){ if (s.class !== undefined && !(s.class in cls)) bad.push("samples[" + i + "].class " + s.class + " is not in classes"); });
|
|
122
|
+
var role = sp.map(function(s, r){
|
|
123
|
+
var a = Array(n).fill(0), testSet = {};
|
|
124
|
+
s.test.forEach(function(i){ if (!(i >= 0 && i < n)) bad.push("splits[" + r + "].test has " + i + " (samples 0–" + (n - 1) + ")"); else { a[i] = 2; testSet[i] = 1; } });
|
|
125
|
+
(s.train || Array.from({length: n}, function(_, i){ return i; }).filter(function(i){ return !testSet[i]; })).forEach(function(i){
|
|
126
|
+
if (!(i >= 0 && i < n)) bad.push("splits[" + r + "].train has " + i); else if (testSet[i]) bad.push("splits[" + r + "]: sample " + i + " is in both train and test"); else a[i] = 1;
|
|
127
|
+
});
|
|
128
|
+
return a;
|
|
129
|
+
});
|
|
130
|
+
// 分け方の決まり:KFold の仲間は、どの標本もちょうど 1 回だけ検証に入る
|
|
131
|
+
var kfold = !kind || kind === "KFold" || kind === "StratifiedKFold" || kind === "GroupKFold";
|
|
132
|
+
if (kfold){
|
|
133
|
+
for (var i = 0; i < n; i++){ var c = role.filter(function(a){ return a[i] === 2; }).length; if (c !== 1){ bad.push("sample " + i + " is in the test set of " + c + " splits; " + (kind || "KFold") + " uses each sample once (set splitter for TimeSeriesSplit, ShuffleSplit or holdout)"); break; } }
|
|
134
|
+
}
|
|
135
|
+
if (kind === "GroupKFold") role.forEach(function(a, r){ var tr = {}, te = {}; a.forEach(function(v, i){ var g = samples[i].group; if (v === 1) tr[g] = 1; if (v === 2) te[g] = 1; }); Object.keys(te).forEach(function(g){ if (tr[g]) bad.push("splits[" + r + "]: group \"" + g + "\" is in both train and test (GroupKFold keeps a group together)"); }); });
|
|
136
|
+
if (kind === "TimeSeriesSplit") role.forEach(function(a, r){ var lastTrain = a.lastIndexOf(1), firstTest = a.indexOf(2); if (lastTrain > firstTest && firstTest >= 0) bad.push("splits[" + r + "]: a train sample comes after a test sample (TimeSeriesSplit trains on the past)"); });
|
|
137
|
+
if (kind === "holdout" && sp.length !== 1) bad.push("holdout has one split; got " + sp.length);
|
|
138
|
+
if (kind === "StratifiedKFold") role.forEach(function(a, r){
|
|
139
|
+
// クラスの比率を保つ:検証に入る各クラスの数が、全体の数 ÷ 分割数から 1 未満しかずれない
|
|
140
|
+
Object.keys(cls).forEach(function(c){ var tot = samples.filter(function(s){ return String(s.class) === c; }).length, got = a.filter(function(v, i){ return v === 2 && String(samples[i].class) === c; }).length; if (Math.abs(got - tot / sp.length) >= 1) bad.push("splits[" + r + "]: class " + c + " has " + got + " test samples; StratifiedKFold keeps about " + +(tot / sp.length).toFixed(2)); });
|
|
141
|
+
});
|
|
142
|
+
if (d.errors && (d.errors.length !== sp.length || d.errors.some(function(v){ return v < 0; }))) bad.push("errors must contain one non-negative number per split");
|
|
143
|
+
bad.forEach(function(s){ ctx.report("data", "[folds] " + s); });
|
|
144
|
+
if (bad.length && bad.some(function(s){ return /samples 0–|2–60|errors must/.test(s); })) return;
|
|
145
|
+
var errors = d.errors && d.errors.length === sp.length ? d.errors : null, mean = errors ? errors.reduce(function(s, v){ return s + v / errors.length; }, 0) : null;
|
|
146
|
+
this.sm = {n: n, role: role, errors: errors, mean: mean};
|
|
147
|
+
var used = role.some(function(a){ return a.indexOf(0) >= 0; });
|
|
148
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", (kind ? kind + ": " : "") + role.map(function(a, r){ return T.fold + " " + (r + 1) + ": " + T.test + " " + a.map(function(v, i){ return v === 2 ? i + 1 : null; }).filter(Boolean).join(", ") + (errors ? "; " + T.error + " " + fmt(errors[r]) : ""); }).join("; ") + (errors ? "; " + T.mean + " " + fmt(mean) : ""));
|
|
149
|
+
var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = this.fs, line = Math.ceil(fs * 1.45 + 4);
|
|
150
|
+
var width = function(s){ return base.textWidth(s, fs, {font: self}); };
|
|
151
|
+
var hasCls = samples.some(function(s){ return s.class !== undefined; }), hasGrp = samples.some(function(s){ return s.group !== undefined; }), hasT = samples.some(function(s){ return s.t !== undefined; });
|
|
152
|
+
var errorWidth = errors ? Math.max(width(T.error), width(T.mean + " " + fmt(mean)), width("0.00")) + 8 : 0;
|
|
153
|
+
var stripLab = Math.max(hasCls ? width(T.cls) : 0, hasGrp ? width(T.group) : 0, width(String(sp.length))) + 16;
|
|
154
|
+
var left = Math.max(42, stripLab), ex = W - errorWidth - 8, right = errors ? ex - 20 : W - 8, cw = (right - left) / n;
|
|
155
|
+
var strips = (hasCls ? 1 : 0) + (hasGrp ? 1 : 0) + (hasT ? 1 : 0), top = line + 8 + strips * line;
|
|
156
|
+
var footer = errors ? line + 8 : 4, rh = Math.max(28, Math.min(Math.ceil(fs * 2.6), (H - top - footer) / sp.length)), bh = rh - 6;
|
|
157
|
+
if (cw < 6) ctx.report("size", "[folds] " + n + " samples have " + cw.toFixed(1) + " px each; allow at least 6 px per sample (a wider element or fewer samples)");
|
|
158
|
+
if (H < top + sp.length * 28 + footer) ctx.report("size", "[folds] " + sp.length + " splits need at least " + Math.ceil(top + sp.length * 28 + footer) + " px height; element has " + H + " px");
|
|
159
|
+
this.geometry = {cell: cw, row: rh, top: top};
|
|
160
|
+
var svg = this.svg = base.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
|
|
161
|
+
var head = this.header = base.el("g", {opacity: 0}, svg);
|
|
162
|
+
// 凡例:学習・検証(・使わない)・クラスの名前(右へ並べる)
|
|
163
|
+
var x = 8, item = function(fill, stroke, text, dash){ base.el("rect", {x: x, y: 8, width: 28, height: fs * 1.2, fill: fill, stroke: stroke || "none", "stroke-width": 3, "stroke-dasharray": dash ? "4 3" : null}, head); self.label(head, x + 36, fs + 4, text); x += 36 + width(text) + 24; };
|
|
164
|
+
item("var(--term-tint)", null, T.trainS); item("var(--emph-tint)", "var(--emph)", T.test);
|
|
165
|
+
if (used) item("var(--bg)", "var(--line)", T.unused, true);
|
|
166
|
+
(d.classes || []).forEach(function(c, i){ base.el("circle", {cx: x + 10, cy: 8 + fs * 0.6, r: 9, fill: PAL[i]}, head); self.label(head, x + 26, fs + 4, c.label || String(c.id)); x += 26 + width(c.label || String(c.id)) + 24; });
|
|
167
|
+
if (x > W) ctx.report("size", "[folds] the legend needs " + Math.ceil(x) + " px width; element has " + W + " px");
|
|
168
|
+
var sy = line + 8;
|
|
169
|
+
if (hasCls){
|
|
170
|
+
self.label(head, left - 12, sy + fs * 0.85, T.cls, "end");
|
|
171
|
+
samples.forEach(function(s, i){ if (s.class !== undefined) base.el("rect", {x: left + i * cw + 1, y: sy + 4, width: Math.max(1, cw - 2), height: line - 12, fill: PAL[cls[s.class] || 0]}, head); });
|
|
172
|
+
sy += line;
|
|
173
|
+
}
|
|
174
|
+
if (hasGrp){
|
|
175
|
+
self.label(head, left - 12, sy + fs * 0.85, T.group, "end");
|
|
176
|
+
// 同じグループの続き:枠で囲み、入れば名前
|
|
177
|
+
var i0 = 0;
|
|
178
|
+
for (var i = 1; i <= n; i++) if (i === n || samples[i].group !== samples[i0].group){
|
|
179
|
+
base.el("rect", {x: left + i0 * cw + 1, y: sy + 4, width: Math.max(1, (i - i0) * cw - 2), height: line - 12, fill: "none", stroke: "var(--muted)", "stroke-width": 2, rx: 4}, head);
|
|
180
|
+
var gname = samples[i0].group === undefined ? "" : String(samples[i0].group);
|
|
181
|
+
// 名前は枠(sy + 4 から line − 12)の縦の中ほどに:基線を sy + 0.85 字にすると、字の上が枠から 5 px 出ていた(Studio の svgTextBox、handoff #45)
|
|
182
|
+
if (gname && width(gname) <= (i - i0) * cw - 8) self.label(head, left + (i0 + (i - i0) / 2) * cw, sy + 4 + (line - 12) / 2 + fs * 0.35, gname, "middle");
|
|
183
|
+
i0 = i;
|
|
184
|
+
}
|
|
185
|
+
sy += line;
|
|
186
|
+
}
|
|
187
|
+
if (hasT){
|
|
188
|
+
self.label(head, left, sy + fs * 0.85, String(samples[0].t !== undefined ? samples[0].t : ""));
|
|
189
|
+
var tEnd = String(samples[n - 1].t !== undefined ? samples[n - 1].t : "");
|
|
190
|
+
self.label(head, right, sy + fs * 0.85, tEnd, "end");
|
|
191
|
+
var mid = left + (right - left) / 2, tw0 = width(T.time);
|
|
192
|
+
if (width(String(samples[0].t)) + width(tEnd) + tw0 + 48 <= right - left) self.label(head, mid, sy + fs * 0.85, T.time, "middle");
|
|
193
|
+
}
|
|
194
|
+
if (errors) this.label(head, ex, top - 8, T.error);
|
|
195
|
+
this.rows = role.map(function(a, r){
|
|
196
|
+
var g = base.el("g", {opacity: 0}, svg), y = top + r * rh;
|
|
197
|
+
self.label(g, left - 12, y + bh / 2 + fs * 0.31, String(r + 1), "end");
|
|
198
|
+
a.forEach(function(v, i){
|
|
199
|
+
base.el("rect", {x: left + i * cw + 1, y: y, width: Math.max(1, cw - 2), height: bh, rx: Math.max(0, Math.min(3, cw / 4)), fill: v === 2 ? "var(--emph-tint)" : v === 1 ? "var(--term-tint)" : "var(--bg)", stroke: v === 2 ? "var(--emph)" : v === 0 ? "var(--line)" : "none", "stroke-width": v === 2 ? 2.5 : 1.5, "stroke-dasharray": v === 0 ? "4 3" : null}, g);
|
|
200
|
+
});
|
|
201
|
+
if (errors) self.label(g, ex, y + bh / 2 + fs * 0.31, fmt(errors[r]));
|
|
202
|
+
return {g: g};
|
|
203
|
+
});
|
|
204
|
+
this.finalLayer = base.el("g", {opacity: 0}, svg);
|
|
205
|
+
if (errors){ var bottom = top + sp.length * rh; base.el("line", {x1: ex, x2: W - 8, y1: bottom + 2, y2: bottom + 2, stroke: "var(--muted)", "stroke-width": 2}, this.finalLayer); this.label(this.finalLayer, ex, bottom + line - 4, T.mean + " " + fmt(mean)); }
|
|
206
|
+
}
|
|
207
|
+
renderSamples(k, t){
|
|
208
|
+
var dur = this.props.dur, n = this.sm.role.length, phase = function(step){ return k > step ? 1 : k < step ? 0 : base.prog(t, 0, dur); };
|
|
209
|
+
set(this.header, "opacity", phase(1));
|
|
210
|
+
this.rows.forEach(function(o, i){ set(o.g, "opacity", phase(i + 1)); });
|
|
211
|
+
set(this.finalLayer, "opacity", phase(n + 1));
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
});
|