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,75 @@
|
|
|
1
|
+
// plot 1.0.0: axes for figures of Egatari components 2.0 (a library part, Egatari spec §6.1). It requires base (el, mtext)
|
|
2
|
+
// and returns {Plot}: Plot(box, o) draws the axes into box (an element or its id) and returns
|
|
3
|
+
// {svg, W, H, m, x(v), y(v), clip, d(f, a, b, n), poly(pts)}. Plot.n counts the clip paths of this copy; their ids are
|
|
4
|
+
// prefixed with this part's name and version (plot-1-1-2-clip1, plot-1-1-2-clip2, …), so that they are unique across parts
|
|
5
|
+
// and part versions in one file and deterministic (spec §6.1 Identifiers: a counter, no randomness, no timing). This is the
|
|
6
|
+
// one deliberate difference from DECK.Plot, whose ids are clip1, clip2, … (CHANGELOG; tools/test-part-plot.mjs allows it).
|
|
7
|
+
//
|
|
8
|
+
// Provenance: Plot is copied verbatim from Egatari Studio's kit/deck.js (https://github.com/egatari/egatari-studio, commit
|
|
9
|
+
// 03eaf0607598b993eb020f8e619caa53526bc771, DECK.Plot there), MIT License, Copyright (c) 2026 Gendo Kumoi, the same owner
|
|
10
|
+
// and licence as this repository; el and mtext come from base instead of deck.js's closure.
|
|
11
|
+
// tools/test-part-plot.mjs compares it with the pinned Studio's DECK.Plot.
|
|
12
|
+
egatariParts.define({name: "plot", version: "1.1.3", requires: {base: "1.3.0"}}, function(deps){
|
|
13
|
+
"use strict";
|
|
14
|
+
var el = deps.base.el, mtext = deps.base.mtext, textWidth = deps.base.textWidth;
|
|
15
|
+
var ID = "plot-1-1-3-"; // name and version of this part, dots replaced (spec §6.1 Identifiers)
|
|
16
|
+
|
|
17
|
+
// 座標軸つきの図(キットの Plot。色はテーマの変数)
|
|
18
|
+
// o = {xr:[min,max], yr:[min,max], xt:[目盛り], yt:[目盛り], xf:小数桁, yf:小数桁, xl:"横軸名", xl2:"横軸の補足", yl:"縦軸名", noY:true, m:{l,r,t,b},
|
|
19
|
+
// fs:目盛りと軸の名前の字の大きさ(px。なければ要素から受け継ぎ、位置は 1.0 と同じ。余白 m は呼ぶ側が字に合わせる)}
|
|
20
|
+
function Plot(box, o){
|
|
21
|
+
if (typeof box === "string") box = document.getElementById(box);
|
|
22
|
+
var W = box.clientWidth, H = box.clientHeight, m = o.m || {l: 86, r: 20, t: 16, b: 64};
|
|
23
|
+
var fs = o.fs > 0 ? o.fs : 0, gY = fs ? Math.round(fs * 0.45) : 10, yX = fs ? Math.round(fs * 0.85) : 22, tf = fs || 24;
|
|
24
|
+
var fmt = function(v, f){ return (f !== undefined ? v.toFixed(f) : String(v)).replace("-", "−"); };
|
|
25
|
+
// 縦軸の名前は目盛りの数字の外に:いちばん幅の広い目盛りの字(テーマの字で測る)にかかるなら、名前をその左へ出し、
|
|
26
|
+
// 入らなければ左の余白を広げる(かからなければ 1.1.0 と同じ位置)
|
|
27
|
+
if (o.yl && !o.noY){
|
|
28
|
+
var tw = 0; (o.yt || []).forEach(function(v){ tw = Math.max(tw, textWidth(fmt(v, o.yf), tf, {font: box})); });
|
|
29
|
+
var right = m.l - gY - tw - 4; // 名前(-90° 回して、基線が x)の右の端(字の下がり 0.22 字ぶん)がここまで
|
|
30
|
+
if (yX + tf * 0.22 > right){
|
|
31
|
+
yX = Math.round(right - tf * 0.22);
|
|
32
|
+
if (yX - tf * 0.9 < 2){ var add = Math.ceil(2 - (yX - tf * 0.9)); m = {l: m.l + add, r: m.r, t: m.t, b: m.b}; yX += add; }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var svg = el("svg", {viewBox: "0 0 " + W + " " + H, class: "plotsvg"}, box);
|
|
36
|
+
var p = {svg: svg, W: W, H: H, m: m,
|
|
37
|
+
x: function(v){ return m.l + (v - o.xr[0]) / (o.xr[1] - o.xr[0]) * (W - m.l - m.r); },
|
|
38
|
+
y: function(v){ return H - m.b - (v - o.yr[0]) / (o.yr[1] - o.yr[0]) * (H - m.t - m.b); }};
|
|
39
|
+
var cid = ID + "clip" + (++Plot.n);
|
|
40
|
+
var cp = el("clipPath", {id: cid}, el("defs", {}, svg));
|
|
41
|
+
// 要素が狭すぎても負の大きさは書かない(部品は "size" で知らせる)
|
|
42
|
+
el("rect", {x: m.l, y: m.t - 4, width: Math.max(0, W - m.l - m.r), height: Math.max(0, H - m.t - m.b + 4)}, cp);
|
|
43
|
+
p.clip = "url(#" + cid + ")";
|
|
44
|
+
var ax = el("g", {class: "axes"}, svg);
|
|
45
|
+
// 字の位置:1.0 の値(30・8・38・22)は mtext の既定の 24 px のとき。fs があれば字をその大きさにし、位置を比で広げる
|
|
46
|
+
var T = function(a){ if (fs) a["font-size"] = fs; return a; };
|
|
47
|
+
var dX = fs ? 6 + fs : 30, dY = fs ? Math.round(fs * 0.31) : 8, dL = fs ? Math.round(fs * 1.46) : 38;
|
|
48
|
+
var K = "var(--fg)";
|
|
49
|
+
el("line", {x1: m.l, y1: H - m.b, x2: W - m.r, y2: H - m.b, stroke: K, "stroke-width": 1.5}, ax);
|
|
50
|
+
if (!o.noY) el("line", {x1: m.l, y1: m.t, x2: m.l, y2: H - m.b, stroke: K, "stroke-width": 1.5}, ax);
|
|
51
|
+
(o.xt || []).forEach(function(v){
|
|
52
|
+
el("line", {x1: p.x(v), y1: H - m.b, x2: p.x(v), y2: H - m.b + 6, stroke: K, "stroke-width": 1.5}, ax);
|
|
53
|
+
mtext(ax, p.x(v), H - m.b + dX, fmt(v, o.xf), T({"text-anchor": "middle"}));
|
|
54
|
+
});
|
|
55
|
+
(o.yt || []).forEach(function(v){
|
|
56
|
+
el("line", {x1: m.l - 6, y1: p.y(v), x2: m.l, y2: p.y(v), stroke: K, "stroke-width": 1.5}, ax);
|
|
57
|
+
mtext(ax, m.l - gY, p.y(v) + dY, fmt(v, o.yf), T({"text-anchor": "end"}));
|
|
58
|
+
});
|
|
59
|
+
if (o.xl) mtext(ax, (m.l + W - m.r) / 2, H - (o.xl2 ? dL : 6), o.xl, T({"text-anchor": "middle"}));
|
|
60
|
+
if (o.xl2) mtext(ax, (m.l + W - m.r) / 2, H - 6, o.xl2, T({"text-anchor": "middle", fill: "var(--muted)"}));
|
|
61
|
+
if (o.yl) mtext(ax, yX, (m.t + H - m.b) / 2, o.yl, T({"text-anchor": "middle", transform: "rotate(-90 " + yX + " " + (m.t + H - m.b) / 2 + ")"}));
|
|
62
|
+
// 関数 f を [a,b] で n 分割した折れ線の d 属性
|
|
63
|
+
p.d = function(f, a, b, n){
|
|
64
|
+
var s = "";
|
|
65
|
+
for (var i = 0; i <= n; i++){ var v = a + (b - a) * i / n; s += (i ? "L" : "M") + p.x(v).toFixed(1) + "," + p.y(f(v)).toFixed(1); }
|
|
66
|
+
return s;
|
|
67
|
+
};
|
|
68
|
+
// 点列 [[x,y],…] の折れ線
|
|
69
|
+
p.poly = function(pts){ return pts.map(function(q, i){ return (i ? "L" : "M") + p.x(q[0]).toFixed(1) + "," + p.y(q[1]).toFixed(1); }).join(""); };
|
|
70
|
+
return p;
|
|
71
|
+
}
|
|
72
|
+
Plot.n = 0;
|
|
73
|
+
|
|
74
|
+
return {Plot: Plot};
|
|
75
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Screen steps: numbered circles on a screenshot, joined by leader lines to labels beside it, one per step
|
|
3
|
+
steps: max callout step (default 1 callout = 1 step)
|
|
4
|
+
props:
|
|
5
|
+
side: labels on right, left or both
|
|
6
|
+
label-width: label column (share of width)
|
|
7
|
+
per-step: callouts per step (0 = all)
|
|
8
|
+
dur: seconds per callout
|
|
9
|
+
size: label px (≥ 24)
|
|
10
|
+
example: {"callouts": [{"x": 0.12, "y": 0.08, "text": "Open the menu"}, {"x": 0.7, "y": 0.62, "text": "Press Send"}]}
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
For training and how-to guides: where to click, in order.
|
|
14
|
+
|
|
15
|
+
The screenshot is a child `<img src alt width height>` (the build inlines it).
|
|
16
|
+
|
|
17
|
+
- **Never show real personal data on a screenshot** (names, ID numbers, resident or patient records). Use made-up data, or blur it.
|
|
18
|
+
- `alt`, `width` and `height` (px) are required (else data); an image over 1 MiB is size.
|
|
19
|
+
|
|
20
|
+
Child JSON: `{"callouts": [...]}`; callout: `x`, `y` (0–1 of the image), `text`, `box` (`[x, y, w, h]`, highlighted during its step), `step`, `at`.
|
|
21
|
+
<!-- llm: omit -->
|
|
22
|
+
- Labels follow the circles' vertical order, so leader lines never cross.
|
|
23
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// m-callout:画面の手順。画面の画像の上に番号の丸を置き、引き出し線で横の説明につなぐ。ステップごとに 1 つずつ
|
|
2
|
+
// <m-callout style="height:460px">
|
|
3
|
+
// <img src="screens/apply.png" alt="申請の画面" width="1280" height="800">
|
|
4
|
+
// <script type="application/json">{"callouts": [{"x": 0.12, "y": 0.08, "text": "メニューを開く"},
|
|
5
|
+
// {"x": 0.70, "y": 0.62, "text": "「送る」を押す", "box": [0.62, 0.57, 0.16, 0.1]}]}</script>
|
|
6
|
+
// (JSON の終わり)</m-callout>
|
|
7
|
+
// 画像は子の <img>(src・alt・width・height)。組み立てが作業フォルダの画像を教材に埋め込む。alt がなければ data で知らせる。
|
|
8
|
+
// width と height は画像の縦横比(px の数。なければ data で知らせて 16:10 で描く)。x・y・box は画像の幅と高さに対する割合(0〜1)
|
|
9
|
+
// 説明は画像の横(side:right(既定)・left・both)に、丸と同じ上下の順に並べ、重ならないようにずらす。
|
|
10
|
+
// 引き出し線は丸から画像の端まで水平に、そこから説明まで斜めにつなぐ。説明の順が丸の上下の順と同じなので、線どうしは交わらない
|
|
11
|
+
// ステップ k で k 番目の丸・線・説明が出る(今の丸は --emph、前の丸は --term)
|
|
12
|
+
egatariParts.define({name: "callout", version: "2.1.0", requires: {base: "1.3.0"}, element: "m-callout"}, function(deps){
|
|
13
|
+
"use strict";
|
|
14
|
+
var base = deps.base;
|
|
15
|
+
var BIG = 1048576; // 埋め込んだ画像がこれ(1 MiB)より大きければ size で知らせる
|
|
16
|
+
function imgOf(el){ return [].filter.call(el.children, function(x){ return x.localName === "img"; })[0] || null; }
|
|
17
|
+
return class extends base.MotionElement {
|
|
18
|
+
static partName = "callout";
|
|
19
|
+
static shape = {
|
|
20
|
+
schema: {type: "object", additionalProperties: false, required: ["callouts"], properties: {
|
|
21
|
+
callouts: {type: "array", minItems: 1, items: {type: "object", required: ["x", "y", "text"], properties: {
|
|
22
|
+
x: {type: "number"}, y: {type: "number"}, text: {type: "string"}, box: {type: "array", items: {type: "number"}, minItems: 4, maxItems: 4}, step: {type: "integer"}, at: {type: "number"}}}}}},
|
|
23
|
+
example: {callouts: [{x: 0.12, y: 0.08, text: "メニューを開く"}, {x: 0.7, y: 0.62, text: "「送る」を押す"}]},
|
|
24
|
+
};
|
|
25
|
+
static props = {
|
|
26
|
+
side: {type: "string", default: "right", doc: "説明を置く側:right・left・both(both は画像の左半分の丸を左に、右半分の丸を右に)"},
|
|
27
|
+
"label-width": {type: "number", default: 0.32, doc: "説明の列の幅(要素の幅に対する割合。both なら片側の幅)"},
|
|
28
|
+
"per-step": {type: "number", default: 1, doc: "1 ステップに出す説明の数(0 = 全部をステップ 1 で)"},
|
|
29
|
+
dur: {type: "number", default: 0.7, doc: "1 つの説明が出る秒数(丸、線、説明の順)"},
|
|
30
|
+
size: {type: "number", default: 28, doc: "説明の字の大きさ(px、24 以上)"},
|
|
31
|
+
};
|
|
32
|
+
get steps(){
|
|
33
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
34
|
+
var m = 0;
|
|
35
|
+
this.plan().forEach(function(p){ m = Math.max(m, p.step); });
|
|
36
|
+
return m;
|
|
37
|
+
}
|
|
38
|
+
plan(){
|
|
39
|
+
if (this._plan) return this._plan;
|
|
40
|
+
var d = this.data || {}, per = this.props["per-step"], seen = {};
|
|
41
|
+
return (this._plan = (d.callouts || []).map(function(c, i){
|
|
42
|
+
var step = c.step !== undefined ? c.step : per > 0 ? Math.floor(i / per) + 1 : 1;
|
|
43
|
+
var j = seen[step] = (seen[step] || 0) + 1;
|
|
44
|
+
return {c: c, n: i + 1, step: step, at: c.at !== undefined ? c.at : +((j - 1) * 0.2).toFixed(3)};
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
mount(ctx){
|
|
48
|
+
var P = this.props, D = base, self = this, pl = this.plan();
|
|
49
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
50
|
+
var W = this.clientWidth, H = this.clientHeight, img = imgOf(this);
|
|
51
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
52
|
+
if (!img){ ctx.report("data", "[callout] put the screenshot in as a child <img src alt width height>"); return; }
|
|
53
|
+
img.style.display = "none";
|
|
54
|
+
var src = img.getAttribute("src") || "", alt = (img.getAttribute("alt") || "").trim();
|
|
55
|
+
if (!alt) ctx.report("data", "[callout] the <img> needs alt: say what the screen is (it is read aloud and shown when the image cannot be)");
|
|
56
|
+
// 埋め込んだ画像(data:)の大きさ。base64 なら 4 字で 3 バイト。知らせの終わりの [image bytes=N] は、Studio の教材全体の画像の
|
|
57
|
+
// 確かめ(backlog #207)が同じ画像を 2 度知らせないための目印(ctx.report には文しか渡せない)
|
|
58
|
+
var m = /^data:[^,]*?(;base64)?,/i.exec(src);
|
|
59
|
+
if (m){
|
|
60
|
+
var bytes = m[1] ? Math.floor((src.length - m[0].length) * 3 / 4) : src.length - m[0].length;
|
|
61
|
+
if (bytes > BIG) ctx.report("size", "[callout] the screenshot is " + (bytes / BIG).toFixed(1) + " MiB inside the lesson file; crop it to the part that matters, or save it smaller (JPEG or WebP, about 1600 px wide) [image bytes=" + bytes + "]");
|
|
62
|
+
}
|
|
63
|
+
var iw = +img.getAttribute("width"), ih = +img.getAttribute("height");
|
|
64
|
+
if (!(iw > 0 && ih > 0)){ ctx.report("data", "[callout] the <img> needs width and height (the screenshot's pixel size), so the callouts land in the right place"); iw = 16; ih = 10; }
|
|
65
|
+
var fs = Math.max(24, P.size), lh = fs * 1.3;
|
|
66
|
+
var est = function(s){ return D.textWidth(s, fs, {font: self, mark: true}); };
|
|
67
|
+
var both = P.side === "both", left = P.side === "left";
|
|
68
|
+
var lw = Math.max(200, W * Math.min(0.45, Math.max(0.15, P["label-width"]))), gut = 48;
|
|
69
|
+
// 画像の場所:説明の列とすきま(gut)を除いた範囲に、縦横比を保って入れる
|
|
70
|
+
var ax0 = both ? lw + gut : left ? lw + gut : 0, ax1 = both ? W - lw - gut : left ? W : W - lw - gut;
|
|
71
|
+
var aw = Math.max(0, ax1 - ax0), sc = Math.min(aw / iw, H / ih), dw = iw * sc, dh = ih * sc;
|
|
72
|
+
var ix = both ? (W - dw) / 2 : left ? W - dw : 0, iy = (H - dh) / 2;
|
|
73
|
+
var gI = D.el("g", {}, svg);
|
|
74
|
+
D.el("image", {href: src, x: ix.toFixed(1), y: iy.toFixed(1), width: dw.toFixed(1), height: dh.toFixed(1), preserveAspectRatio: "none"}, gI);
|
|
75
|
+
D.el("rect", {x: ix.toFixed(1), y: iy.toFixed(1), width: dw.toFixed(1), height: dh.toFixed(1), fill: "none", stroke: "var(--line)", "stroke-width": 2}, gI);
|
|
76
|
+
var gB = D.el("g", {}, svg), gK = D.el("g", {}, svg), gN = D.el("g", {}, svg), gL = D.el("g", {}, svg);
|
|
77
|
+
// 説明の位置:側ごとに丸の上下の順に並べ、丸の高さを目安に置いて、重なれば下へ、はみ出せば上へずらす
|
|
78
|
+
var items = pl.map(function(p){
|
|
79
|
+
var c = p.c, tx = ix + Math.max(0, Math.min(1, c.x)) * dw, ty = iy + Math.max(0, Math.min(1, c.y)) * dh;
|
|
80
|
+
var lines = String(c.text).split("\n"), h = lines.length * lh + 12;
|
|
81
|
+
var onLeft = both ? c.x < 0.5 : left;
|
|
82
|
+
lines.forEach(function(s){ if (est(s) > lw - 16) ctx.report("size", "[callout] \"" + s + "\" is wider than the label column; break it with \\n or widen label-width"); });
|
|
83
|
+
return {p: p, tx: tx, ty: ty, lines: lines, h: h, left: onLeft};
|
|
84
|
+
});
|
|
85
|
+
[true, false].forEach(function(sideLeft){
|
|
86
|
+
var col = items.filter(function(o){ return o.left === sideLeft; }).sort(function(a, b){ return a.ty - b.ty || a.tx - b.tx; });
|
|
87
|
+
var y = 0;
|
|
88
|
+
col.forEach(function(o){ o.ly = Math.max(y, o.ty - o.h / 2); y = o.ly + o.h + 12; });
|
|
89
|
+
var over = y - 12 - H;
|
|
90
|
+
for (var i = col.length - 1; i >= 0 && over > 0; i--){
|
|
91
|
+
var lim = i === 0 ? 0 : col[i - 1].ly + col[i - 1].h + 12, room = col[i].ly - lim;
|
|
92
|
+
var mv = Math.min(over, room);
|
|
93
|
+
for (var j = i; j < col.length; j++) col[j].ly -= mv;
|
|
94
|
+
over -= mv;
|
|
95
|
+
}
|
|
96
|
+
if (over > 0) ctx.report("size", "[callout] the labels on the " + (sideLeft ? "left" : "right") + " need " + Math.round(y - 12) + " px of height; the element is " + H + " px");
|
|
97
|
+
// 線の折れ目:画像の端の外。丸の上下の順と説明の順が同じなので、折れ目から説明までの線は交わらない
|
|
98
|
+
col.forEach(function(o){ o.gx = sideLeft ? ix - 14 : ix + dw + 14; o.lx = sideLeft ? lw : W - lw; });
|
|
99
|
+
});
|
|
100
|
+
this.items = items.map(function(o){
|
|
101
|
+
var c = o.p.c, r = 20, mid = "@n" + o.p.n;
|
|
102
|
+
// marks for the geometry check (spec §8.4): the numbered circle is a mark, the leader an edge from it to its text,
|
|
103
|
+
// the number and the text its labels (the text outside), the highlight a box
|
|
104
|
+
if (Array.isArray(c.box) && c.box.length === 4)
|
|
105
|
+
o.box = D.el("rect", {"data-part": "box", "data-part-id": "box" + o.p.n, x: (ix + c.box[0] * dw).toFixed(1), y: (iy + c.box[1] * dh).toFixed(1), width: (c.box[2] * dw).toFixed(1), height: (c.box[3] * dh).toFixed(1), rx: 6, fill: "none", stroke: "var(--emph)", "stroke-width": 4}, gB);
|
|
106
|
+
var gk = D.el("g", {"data-part": "edge", "data-part-id": "lead" + o.p.n, "data-part-from": mid, "data-part-to": mid}, gK);
|
|
107
|
+
o.line = D.el("path", {"data-part-line": "", d: "M" + o.tx.toFixed(1) + "," + o.ty.toFixed(1) + "H" + o.gx.toFixed(1) + "L" + o.lx.toFixed(1) + "," + (o.ly + o.h / 2).toFixed(1),
|
|
108
|
+
fill: "none", stroke: "var(--fg)", "stroke-width": 2.5, "stroke-linejoin": "round"}, gk);
|
|
109
|
+
o.len = Math.abs(o.gx - o.tx) + Math.hypot(o.lx - o.gx, o.ly + o.h / 2 - o.ty);
|
|
110
|
+
o.line.setAttribute("stroke-dasharray", o.len.toFixed(1) + " " + o.len.toFixed(1));
|
|
111
|
+
o.dot = D.el("circle", {"data-part": "mark", "data-part-id": mid, cx: o.tx.toFixed(1), cy: o.ty.toFixed(1), r: r, stroke: "var(--bg)", "stroke-width": 3}, gN);
|
|
112
|
+
o.num = D.el("text", {"data-part": "label", "data-part-id": mid, "data-part-of": "mark", x: o.tx.toFixed(1), y: (o.ty + 8.5).toFixed(1), "font-size": 24, "font-weight": 700, "text-anchor": "middle", fill: "var(--bg)"}, gN);
|
|
113
|
+
o.num.textContent = String(o.p.n);
|
|
114
|
+
// 説明:番号と文。左の列は右寄せ(線の側)
|
|
115
|
+
var g = D.el("g", {}, gL), ax = o.left ? lw - 8 : W - lw + 8;
|
|
116
|
+
o.lines.forEach(function(s, j){ D.mtext(g, ax, (o.ly + 6 + fs * 0.95 + j * lh).toFixed(1), (j === 0 ? o.p.n + ". " : "") + s, {"data-part": "label", "data-part-id": mid, "data-part-of": "mark", "data-part-at": "outside", "font-size": fs, "text-anchor": o.left ? "end" : "start"}); });
|
|
117
|
+
o.label = g;
|
|
118
|
+
return o;
|
|
119
|
+
});
|
|
120
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
121
|
+
this.setAttribute("role", "img");
|
|
122
|
+
if (!this._aria){
|
|
123
|
+
var ja = /^ja\b/i.test(ctx.lang || "ja");
|
|
124
|
+
this.setAttribute("aria-label", (alt || (ja ? "画面" : "Screen")) + (ja ? ":" : ": ") + pl.map(function(p){ return p.n + ". " + String(p.c.text).replace(/\s*\n\s*/g, " "); }).join(ja ? "、" : "; "));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
duration(k){
|
|
128
|
+
var P = this.props, d = 0;
|
|
129
|
+
this.plan().forEach(function(p){ if (p.step === k) d = Math.max(d, p.at + P.dur); });
|
|
130
|
+
return d;
|
|
131
|
+
}
|
|
132
|
+
render(k, t, ctx){
|
|
133
|
+
if (!this.items) return;
|
|
134
|
+
var P = this.props, D = base, preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
135
|
+
this.items.forEach(function(o){
|
|
136
|
+
var p = o.p, ahead = preview && p.step > k, now = p.step === k;
|
|
137
|
+
var e = ahead || p.step < k ? 1 : p.step > k ? 0 : D.prog(t, p.at, P.dur);
|
|
138
|
+
// 丸(最初の 3 割)→ 線(次の 4 割)→ 説明(残り)
|
|
139
|
+
var a = Math.min(1, e / 0.3), b = Math.max(0, Math.min(1, (e - 0.3) / 0.4)), c = Math.max(0, Math.min(1, (e - 0.7) / 0.3));
|
|
140
|
+
var op = function(x){ return ahead ? PV : x > 0 ? x : 0; };
|
|
141
|
+
o.dot.setAttribute("fill", now ? "var(--emph)" : "var(--term)");
|
|
142
|
+
o.dot.setAttribute("opacity", op(a).toFixed(3)); o.num.setAttribute("opacity", op(a).toFixed(3));
|
|
143
|
+
if (o.box){ o.box.setAttribute("opacity", (ahead ? PV : now ? a : 0).toFixed(3)); }
|
|
144
|
+
o.line.setAttribute("stroke-dashoffset", (o.len * (1 - (ahead ? 1 : b))).toFixed(1));
|
|
145
|
+
o.line.setAttribute("opacity", (ahead ? PV : b > 0 ? 1 : 0).toFixed(3));
|
|
146
|
+
o.label.setAttribute("opacity", op(c).toFixed(3));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: ANOVA, contingency and potential-outcome tables filled by step; sources, results and a formula line; arithmetic checked
|
|
3
|
+
steps: fill stages
|
|
4
|
+
props:
|
|
5
|
+
dur: s per step
|
|
6
|
+
digits: decimals
|
|
7
|
+
size: text px
|
|
8
|
+
example: {"kind": "anova", "rows": [{"name": "A", "ss": 120, "df": 2, "ms": 60, "f": 7.5}, {"name": "E", "ss": 96, "df": 12, "ms": 8}, {"name": "T", "ss": 216, "df": 14}]}
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
From a script; arithmetic checked. `kind`: anova, contingency, po, table.
|
|
12
|
+
<!-- llm: omit -->
|
|
13
|
+
- `anova`: rows `{name, ss, df, ms, f, p}`; the last row is the total, the one before it the error (`role` overrides); columns filled SS → df → MS → F → p. `contingency`: `rows`, `cols`, `n`; `margins` (default true), `expected`, `chi2` (no continuity correction), `or` (2 × 2). `po`: units `{id, t, y0, y1}`; the unobserved side is "?" on a light ground; steps reveal it, then Y(1) − Y(0), then the ATE and the naive difference (`ate`, `naive` checked). `table`: `header` and `rows`, one row per step.
|
|
14
|
+
- Checks (data) within the rounding written; p is not checked. Source cells `--accent2`, filled cells `--emph` during their step. The whole table is in `table[data-readable]`. No answer preview.
|
|
15
|
+
<!-- llm: end -->
|
|
16
|
+
<!-- llm: omit -->
|
|
17
|
+
Notes: keep decimals consistent per column; say in the script that real data shows only one of the two potential outcomes.
|
|
18
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// m-ctable:計算して埋まる表。分散分析表・分割表(周辺の計・期待度数・χ²・オッズ比)・潜在結果の表を、ステップごとに埋め、
|
|
2
|
+
// 使ったセルと埋めたセルを示し、表の下に式の行を出す。値は計算を走らせたスクリプトの出力を書き、パーツは計算を確かめる(合わなければ data)。
|
|
3
|
+
// <m-ctable style="height:440px"><script type="application/json">
|
|
4
|
+
// {"kind": "anova", "rows": [{"name": "要因 A", "ss": 120, "df": 2, "ms": 60, "f": 7.5}, {"name": "誤差", "ss": 96, "df": 12, "ms": 8},
|
|
5
|
+
// {"name": "全体", "ss": 216, "df": 14}]}
|
|
6
|
+
// (JSON の終わり)</m-ctable>
|
|
7
|
+
// kind:anova(最後の行が全体、その前が誤差。role で変えられる)・contingency(rows・cols・n、margins、expected・chi2・or)・
|
|
8
|
+
// po(units の t・y0・y1。見えない半分は「?」、ステップで開き、個人の効果と平均処置効果)・table(header と rows を行ごとに出す)
|
|
9
|
+
// 色:使ったセル --accent2 の枠、埋めたセル --emph の枠、見えない値の地 --muted の薄い塗り(字の色だけに頼らず「?」と地で示す)。
|
|
10
|
+
egatariParts.define({name: "ctable", version: "2.0.1", requires: {base: "1.3.0"}, element: "m-ctable"}, function(deps){
|
|
11
|
+
"use strict";
|
|
12
|
+
var base = deps.base;
|
|
13
|
+
var NUM = {type: "number"};
|
|
14
|
+
var T = {
|
|
15
|
+
ja: {source: "要因", ss: "平方和", df: "自由度", ms: "平均平方", f: "F", p: "p", total: "計", unit: "ID", t: "処置", y0: "Y(0)", y1: "Y(1)", ite: "Y(1) − Y(0)",
|
|
16
|
+
ssF: function(t, ps, v){ return "平方和:" + t + " = " + ps + " = " + v; }, dfF: function(t, ps, v){ return "自由度:" + t + " = " + ps + " = " + v; },
|
|
17
|
+
msF: "平均平方 = 平方和 ÷ 自由度", fF: "F = 要因の平均平方 ÷ 誤差の平均平方", pF: "p は F 分布から(スクリプトの値)",
|
|
18
|
+
margins: "周辺の計 = 行と列の和", exp: "期待度数 = 行の計 × 列の計 ÷ 総数", chi2: "χ² = Σ(観測 − 期待)² ÷ 期待", or: "オッズ比 = (a × d) ÷ (b × c)",
|
|
19
|
+
reveal: "見えない側の値(仮に分かったとして)", iteF: "個人の効果 = Y(1) − Y(0)", ate: "平均処置効果 = 個人の効果の平均", naive: "単純な差 = 処置群の Y の平均 − 対照群の Y の平均"},
|
|
20
|
+
en: {source: "Source", ss: "SS", df: "df", ms: "MS", f: "F", p: "p", total: "Total", unit: "Unit", t: "t", y0: "Y(0)", y1: "Y(1)", ite: "Y(1) − Y(0)",
|
|
21
|
+
ssF: function(t, ps, v){ return "SS: " + t + " = " + ps + " = " + v; }, dfF: function(t, ps, v){ return "df: " + t + " = " + ps + " = " + v; },
|
|
22
|
+
msF: "MS = SS ÷ df", fF: "F = MS(factor) ÷ MS(error)", pF: "p from the F distribution (script value)",
|
|
23
|
+
margins: "Margins = row and column sums", exp: "Expected = row total × column total ÷ N", chi2: "χ² = Σ (observed − expected)² ÷ expected", or: "Odds ratio = (a × d) ÷ (b × c)",
|
|
24
|
+
reveal: "The unobserved side (as if we knew it)", iteF: "Individual effect = Y(1) − Y(0)", ate: "ATE = mean of the individual effects", naive: "Naive difference = mean Y (treated) − mean Y (control)"},
|
|
25
|
+
};
|
|
26
|
+
function dec(v){ var s = String(v).split(".")[1]; return s ? s.length : 0; }
|
|
27
|
+
function fmt(v, dg){ if (typeof v !== "number") return String(v); var s = Math.abs(v).toFixed(dg); return (v < 0 && +s !== 0 ? "−" : "") + s; }
|
|
28
|
+
return class extends base.MotionElement {
|
|
29
|
+
static partName = "ctable";
|
|
30
|
+
static preview = "none";
|
|
31
|
+
static shape = {
|
|
32
|
+
schema: {type: "object", additionalProperties: false, required: ["kind"], properties: {
|
|
33
|
+
kind: {type: "string", enum: ["anova", "contingency", "po", "table"]},
|
|
34
|
+
rows: {type: "array", maxItems: 12, items: {type: ["object", "string", "array"]}},
|
|
35
|
+
cols: {type: "array", maxItems: 8, items: {type: "string"}},
|
|
36
|
+
n: {type: "array", items: {type: "array", items: NUM}},
|
|
37
|
+
margins: {type: "boolean"},
|
|
38
|
+
expected: {type: "array", items: {type: "array", items: NUM}},
|
|
39
|
+
chi2: NUM, or: NUM,
|
|
40
|
+
units: {type: "array", maxItems: 12, items: {type: "object", additionalProperties: false, required: ["t", "y0", "y1"], properties: {
|
|
41
|
+
id: {type: "string"}, t: {type: "integer", enum: [0, 1]}, y0: NUM, y1: NUM}}},
|
|
42
|
+
ate: NUM, naive: NUM,
|
|
43
|
+
header: {type: "array", maxItems: 8, items: {type: "string"}},
|
|
44
|
+
note: {type: "string"}}},
|
|
45
|
+
example: {kind: "anova", rows: [{name: "要因 A", ss: 120, df: 2, ms: 60, f: 7.5}, {name: "誤差", ss: 96, df: 12, ms: 8}, {name: "全体", ss: 216, df: 14}]},
|
|
46
|
+
};
|
|
47
|
+
static props = {
|
|
48
|
+
dur: {type: "number", default: 0.7, doc: "1 ステップの秒数"},
|
|
49
|
+
digits: {type: "number", default: -1, doc: "値の小数の桁(−1 は書いた値の桁のまま)"},
|
|
50
|
+
size: {type: "number", default: 26, doc: "字の大きさ(px、24 以上)"},
|
|
51
|
+
};
|
|
52
|
+
get steps(){
|
|
53
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
54
|
+
return this.plan().steps.length;
|
|
55
|
+
}
|
|
56
|
+
// 表のセル(文字・いつ埋まるか・見えない値か)とステップ(埋めるセル・使うセル・式の行)。データだけから決まる
|
|
57
|
+
plan(){
|
|
58
|
+
if (this._plan) return this._plan;
|
|
59
|
+
var d = this.data || {}, bad = [], ja = !/^en\b/i.test(this.getAttribute("lang") || (this.closest && this.closest("[lang]") ? this.closest("[lang]").getAttribute("lang") : "ja") || "ja");
|
|
60
|
+
var L = ja ? T.ja : T.en, P = this.props, cells = [], steps = [], cols = [], nr = 0;
|
|
61
|
+
var cell = function(r, c, text, o){ var x = Object.assign({r: r, c: c, text: text, step: 0}, o || {}); cells.push(x); return x; };
|
|
62
|
+
var dgOf = function(vals){ return P.digits >= 0 ? Math.min(6, Math.round(P.digits)) : Math.min(4, Math.max.apply(null, vals.filter(function(v){ return typeof v === "number"; }).map(dec).concat([0]))); };
|
|
63
|
+
var close = function(a, b, dg){ return Math.abs(a - b) <= 1e-9 * Math.max(1, Math.abs(b)) + (dg ? 0.51 * Math.pow(10, -dg) : 0); };
|
|
64
|
+
// 丸めの幅:書いた桁の半分(整数なら 0)。式を通した許し:入力の丸めを式に沿って足す
|
|
65
|
+
var hu = function(v){ var q = dec(v); return q ? 0.51 * Math.pow(10, -q) : 0; };
|
|
66
|
+
var near = function(a, b, tol){ return Math.abs(a - b) <= 1e-9 * Math.max(1, Math.abs(b)) + tol; };
|
|
67
|
+
var kind = d.kind;
|
|
68
|
+
if (kind === "anova"){
|
|
69
|
+
var rows = (d.rows || []).filter(function(r){ return r && typeof r === "object" && !Array.isArray(r); });
|
|
70
|
+
if (rows.length < 2) bad.push("anova needs at least a factor row and a total row");
|
|
71
|
+
var role = rows.map(function(r, i){ return r.role || (i === rows.length - 1 ? "total" : i === rows.length - 2 ? "error" : "factor"); });
|
|
72
|
+
var keys = ["ss", "df", "ms", "f", "p"].filter(function(k){ return rows.some(function(r){ return typeof r[k] === "number"; }); });
|
|
73
|
+
cols = [L.source].concat(keys.map(function(k){ return L[k]; }));
|
|
74
|
+
nr = rows.length + 1;
|
|
75
|
+
cols.forEach(function(h, c){ cell(0, c, h, {head: true}); });
|
|
76
|
+
var dgK = {}; keys.forEach(function(k){ dgK[k] = dgOf(rows.map(function(r){ return r[k]; })); });
|
|
77
|
+
rows.forEach(function(r, i){
|
|
78
|
+
cell(i + 1, 0, r.name || "", {head: true});
|
|
79
|
+
keys.forEach(function(k, j){ if (typeof r[k] === "number") cell(i + 1, j + 1, fmt(r[k], dgK[k]), {key: k, row: i, q: true}); });
|
|
80
|
+
});
|
|
81
|
+
var tot = rows[role.indexOf("total")], err = rows[role.indexOf("error")], fac = rows.filter(function(r, i){ return role[i] !== "total"; });
|
|
82
|
+
var colOf = function(k){ return keys.indexOf(k) + 1; }, idx = function(r){ return rows.indexOf(r) + 1; };
|
|
83
|
+
keys.forEach(function(k){
|
|
84
|
+
var fill = cells.filter(function(x){ return x.key === k; }), src = [], text = "";
|
|
85
|
+
if ((k === "ss" || k === "df") && tot && typeof tot[k] === "number"){
|
|
86
|
+
var sum = fac.reduce(function(a, r){ return a + (r[k] || 0); }, 0);
|
|
87
|
+
if (!near(sum, tot[k], fac.reduce(function(a, r){ return a + hu(r[k] || 0); }, hu(tot[k])))) bad.push(tot.name + " " + k + " is " + tot[k] + " but the rows above sum to " + +sum.toFixed(6));
|
|
88
|
+
text = L[k + "F"](tot.name, fac.map(function(r){ return fmt(r[k], dgK[k]); }).join(" + "), fmt(tot[k], dgK[k]));
|
|
89
|
+
} else if (k === "ms"){
|
|
90
|
+
fac.forEach(function(r){ if (typeof r.ms === "number" && typeof r.ss === "number" && r.df){ if (!near(r.ss / r.df, r.ms, hu(r.ms) + hu(r.ss) / r.df)) bad.push(r.name + ": ms is " + r.ms + " but ss ÷ df = " + +(r.ss / r.df).toFixed(6)); src.push([idx(r), colOf("ss")], [idx(r), colOf("df")]); } });
|
|
91
|
+
text = L.msF;
|
|
92
|
+
} else if (k === "f"){
|
|
93
|
+
var f1 = fac.filter(function(r){ return r !== err && typeof r.f === "number"; });
|
|
94
|
+
f1.forEach(function(r){ if (err && err.ms && typeof r.ms === "number" && !near(r.ms / err.ms, r.f, hu(r.f) + hu(r.ms) / err.ms + r.ms * hu(err.ms) / (err.ms * err.ms))) bad.push(r.name + ": F is " + r.f + " but ms ÷ ms(" + err.name + ") = " + +(r.ms / err.ms).toFixed(6)); src.push([idx(r), colOf("ms")]); });
|
|
95
|
+
if (err) src.push([idx(err), colOf("ms")]);
|
|
96
|
+
text = L.fF + (f1.length && err && err.ms ? " = " + fmt(f1[0].ms, dgK.ms) + " ÷ " + fmt(err.ms, dgK.ms) + " = " + fmt(f1[0].f, dgK.f) : "");
|
|
97
|
+
} else if (k === "p") text = L.pF;
|
|
98
|
+
if (k === "ss" || k === "df") fac.forEach(function(r){ if (typeof r[k] === "number") src.push([idx(r), colOf(k)]); });
|
|
99
|
+
steps.push({fill: fill, src: src, line: [text]});
|
|
100
|
+
});
|
|
101
|
+
} else if (kind === "contingency"){
|
|
102
|
+
var R = (d.rows || []).map(String), Cn = d.cols || [], n = d.n || [], mg = d.margins !== false;
|
|
103
|
+
if (!R.length || !Cn.length || n.length !== R.length || n.some(function(row){ return row.length !== Cn.length; })) bad.push("contingency needs rows, cols and n with rows × cols counts");
|
|
104
|
+
else {
|
|
105
|
+
var rs = n.map(function(row){ return row.reduce(function(a, b){ return a + b; }, 0); }), cs = Cn.map(function(_, j){ return n.reduce(function(a, row){ return a + row[j]; }, 0); }), N = rs.reduce(function(a, b){ return a + b; }, 0);
|
|
106
|
+
var dgN = dgOf([].concat.apply([], n)), ex = d.expected, dgE = ex ? dgOf([].concat.apply([], ex)) : 0;
|
|
107
|
+
cols = [""].concat(Cn, mg ? [L.total] : []); nr = R.length + 1 + (mg ? 1 : 0);
|
|
108
|
+
cols.forEach(function(h, c){ if (h) cell(0, c, h, {head: true}); });
|
|
109
|
+
R.forEach(function(r, i){ cell(i + 1, 0, r, {head: true}); });
|
|
110
|
+
if (mg) cell(R.length + 1, 0, L.total, {head: true});
|
|
111
|
+
var counts = [];
|
|
112
|
+
n.forEach(function(row, i){ row.forEach(function(v, j){ counts.push(cell(i + 1, j + 1, fmt(v, dgN), {q: false, val: v})); }); });
|
|
113
|
+
var mcells = [];
|
|
114
|
+
if (mg){
|
|
115
|
+
rs.forEach(function(v, i){ mcells.push(cell(i + 1, Cn.length + 1, fmt(v, dgN), {q: true})); });
|
|
116
|
+
cs.forEach(function(v, j){ mcells.push(cell(R.length + 1, j + 1, fmt(v, dgN), {q: true})); });
|
|
117
|
+
mcells.push(cell(R.length + 1, Cn.length + 1, fmt(N, dgN), {q: true}));
|
|
118
|
+
steps.push({fill: mcells, src: counts.map(function(x){ return [x.r, x.c]; }), line: [L.margins]});
|
|
119
|
+
}
|
|
120
|
+
if (ex){
|
|
121
|
+
if (ex.length !== R.length || ex.some(function(row){ return row.length !== Cn.length; })) bad.push("expected must have rows × cols numbers");
|
|
122
|
+
else {
|
|
123
|
+
var ecells = [];
|
|
124
|
+
ex.forEach(function(row, i){ row.forEach(function(v, j){
|
|
125
|
+
var want = rs[i] * cs[j] / N;
|
|
126
|
+
if (!close(want, v, dgE)) bad.push("expected[" + i + "][" + j + "] is " + v + " but row × column ÷ N = " + +want.toFixed(6));
|
|
127
|
+
ecells.push(cell(i + 1, j + 1, "(" + fmt(v, dgE) + ")", {q: true, sub: true}));
|
|
128
|
+
}); });
|
|
129
|
+
steps.push({fill: ecells, src: mcells.map(function(x){ return [x.r, x.c]; }), line: [L.exp]});
|
|
130
|
+
if (typeof d.chi2 === "number"){
|
|
131
|
+
var chi = 0; n.forEach(function(row, i){ row.forEach(function(o, j){ var e = rs[i] * cs[j] / N; chi += (o - e) * (o - e) / e; }); });
|
|
132
|
+
if (!close(chi, d.chi2, dec(d.chi2))) bad.push("chi2 is " + d.chi2 + " but Σ (o − e)² ÷ e = " + +chi.toFixed(6));
|
|
133
|
+
steps.push({fill: [], src: counts.concat(ecells).map(function(x){ return [x.r, x.c]; }), line: [L.chi2 + " = " + fmt(d.chi2, dec(d.chi2))]});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} else if (typeof d.chi2 === "number") bad.push("chi2 needs expected");
|
|
137
|
+
if (typeof d.or === "number"){
|
|
138
|
+
if (R.length !== 2 || Cn.length !== 2) bad.push("or (odds ratio) needs a 2 × 2 table");
|
|
139
|
+
else {
|
|
140
|
+
var a = n[0][0], b = n[0][1], c2 = n[1][0], dd = n[1][1], orv = a * dd / (b * c2);
|
|
141
|
+
if (!close(orv, d.or, dec(d.or))) bad.push("or is " + d.or + " but (a × d) ÷ (b × c) = " + +orv.toFixed(6));
|
|
142
|
+
steps.push({fill: [], src: counts.map(function(x){ return [x.r, x.c]; }), line: [L.or + " = (" + a + " × " + dd + ") ÷ (" + b + " × " + c2 + ") = " + fmt(d.or, dec(d.or))]});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} else if (kind === "po"){
|
|
147
|
+
var U = d.units || [];
|
|
148
|
+
if (U.length < 2) bad.push("po needs at least 2 units");
|
|
149
|
+
var dgY = dgOf([].concat.apply([], U.map(function(u){ return [u.y0, u.y1]; })));
|
|
150
|
+
cols = [L.unit, L.t, L.y0, L.y1, L.ite]; nr = U.length + 1;
|
|
151
|
+
cols.forEach(function(h, c){ cell(0, c, h, {head: true}); });
|
|
152
|
+
var hidden = [], ite = [];
|
|
153
|
+
U.forEach(function(u, i){
|
|
154
|
+
cell(i + 1, 0, u.id || String(i + 1), {head: true});
|
|
155
|
+
cell(i + 1, 1, String(u.t));
|
|
156
|
+
var obs0 = u.t === 0;
|
|
157
|
+
cell(i + 1, 2, fmt(u.y0, dgY), obs0 ? {} : {q: true, hidden: true});
|
|
158
|
+
cell(i + 1, 3, fmt(u.y1, dgY), obs0 ? {q: true, hidden: true} : {});
|
|
159
|
+
hidden.push(cells[cells.length - (obs0 ? 1 : 2)]);
|
|
160
|
+
ite.push(cell(i + 1, 4, fmt(u.y1 - u.y0, dgY), {q: true}));
|
|
161
|
+
});
|
|
162
|
+
steps.push({fill: hidden, src: [], line: [L.reveal]});
|
|
163
|
+
steps.push({fill: ite, src: [].concat.apply([], U.map(function(u, i){ return [[i + 1, 2], [i + 1, 3]]; })), line: [L.iteF]});
|
|
164
|
+
var ateV = U.reduce(function(a, u){ return a + (u.y1 - u.y0); }, 0) / (U.length || 1);
|
|
165
|
+
var tr = U.filter(function(u){ return u.t === 1; }), co = U.filter(function(u){ return u.t === 0; });
|
|
166
|
+
var naiveV = tr.length && co.length ? tr.reduce(function(a, u){ return a + u.y1; }, 0) / tr.length - co.reduce(function(a, u){ return a + u.y0; }, 0) / co.length : NaN;
|
|
167
|
+
if (typeof d.ate === "number" && !close(ateV, d.ate, dec(d.ate))) bad.push("ate is " + d.ate + " but the mean of y1 − y0 = " + +ateV.toFixed(6));
|
|
168
|
+
if (typeof d.naive === "number" && !close(naiveV, d.naive, dec(d.naive))) bad.push("naive is " + d.naive + " but mean y1 (t = 1) − mean y0 (t = 0) = " + +naiveV.toFixed(6));
|
|
169
|
+
var dgA = Math.max(dgY, typeof d.ate === "number" ? dec(d.ate) : 2);
|
|
170
|
+
steps.push({fill: [], src: ite.map(function(x){ return [x.r, x.c]; }), line: [L.ate + " = " + fmt(typeof d.ate === "number" ? d.ate : ateV, dgA),
|
|
171
|
+
isFinite(naiveV) ? L.naive + " = " + fmt(typeof d.naive === "number" ? d.naive : naiveV, dgA) : ""].filter(Boolean)});
|
|
172
|
+
} else if (kind === "table"){
|
|
173
|
+
var H = d.header || [], TR = (d.rows || []).filter(Array.isArray);
|
|
174
|
+
cols = H.slice(); nr = TR.length + 1;
|
|
175
|
+
H.forEach(function(h, c){ cell(0, c, h, {head: true}); });
|
|
176
|
+
TR.forEach(function(row, i){
|
|
177
|
+
if (row.length !== H.length) bad.push("rows[" + i + "] has " + row.length + " cells, header has " + H.length);
|
|
178
|
+
var fill = row.map(function(v, j){ return cell(i + 1, j, typeof v === "number" ? String(v) : String(v), {q: true}); });
|
|
179
|
+
steps.push({fill: fill, src: [], line: []});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
// 埋まるステップ
|
|
183
|
+
steps.forEach(function(s, k){ s.fill.forEach(function(x){ x.step = k + 1; }); });
|
|
184
|
+
// anova:値のセルは列のステップで埋まる(ステップのないセル(p の列の要因以外など)は初めから出す)
|
|
185
|
+
return (this._plan = {cells: cells, steps: steps, bad: bad, cols: cols, nr: nr, L: L, lines: Math.max(1, ...steps.map(function(s){ return s.line.length; }))});
|
|
186
|
+
}
|
|
187
|
+
mount(ctx){
|
|
188
|
+
var self = this, P = this.props, D = base, pl = this.plan(), d = this.data;
|
|
189
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
190
|
+
var W = this.clientWidth, H = this.clientHeight;
|
|
191
|
+
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);
|
|
192
|
+
if (!(P.dur >= 0)){ ctx.report("attr", "[ctable] dur must be ≥ 0; using 0.7"); P.dur = 0.7; }
|
|
193
|
+
if (!(P.size >= 24)){ ctx.report("attr", "[ctable] size must be ≥ 24; using 26"); P.size = 26; }
|
|
194
|
+
pl.bad.forEach(function(m){ ctx.report("data", "[ctable] " + m); });
|
|
195
|
+
var fs = P.size, tw = function(s, b){ return D.textWidth(s, fs, {font: self}) * (b ? 1.06 : 1); };
|
|
196
|
+
var hasSub = pl.cells.some(function(x){ return x.sub; }), rh = Math.ceil(fs * 1.7) * (hasSub ? 2 : 1), pad = 14;
|
|
197
|
+
var nc = pl.cols.length, cw = [];
|
|
198
|
+
for (var c = 0; c < nc; c++) cw[c] = Math.ceil(Math.max(fs * 1.4, ...pl.cells.filter(function(x){ return x.c === c; }).map(function(x){ return tw(x.text, x.head); })) + 2 * pad);
|
|
199
|
+
var tableW = cw.reduce(function(a, b){ return a + b; }, 0), tableH = pl.nr * rh, lineH = Math.ceil(fs * 1.6), formH = pl.steps.some(function(s){ return s.line.length; }) ? pl.lines * lineH + 12 : 0;
|
|
200
|
+
var needH = tableH + formH + 8;
|
|
201
|
+
var need = "[ctable] the table needs " + Math.ceil(tableW) + " × " + Math.ceil(needH) + " px; the element is " + W + " × " + H + " px (fewer rows or columns, shorter names, or a larger element)";
|
|
202
|
+
if (tableW > W || needH > H) ctx.report("size", need);
|
|
203
|
+
var x0 = Math.max(0, (W - tableW) / 2), y0 = 4, xs = [x0];
|
|
204
|
+
cw.forEach(function(w, i){ xs.push(xs[i] + w); });
|
|
205
|
+
this.geo = {x0: x0, y0: y0, xs: xs, rh: rh, W: W, tableW: tableW, tableH: tableH};
|
|
206
|
+
var gB = D.el("g", {}, svg), gL = D.el("g", {}, svg), gT = D.el("g", {}, svg), gH = D.el("g", {}, svg);
|
|
207
|
+
// 表の線:見出しの行の下と見出しの列の右は太く、ほかは細く
|
|
208
|
+
for (var r = 0; r <= pl.nr; r++){ var y = y0 + r * rh; D.el("line", {x1: x0, x2: x0 + tableW, y1: y, y2: y, stroke: "var(--line)", "stroke-width": r === 1 ? 2.5 : 1.2}, gL); }
|
|
209
|
+
for (var c2 = 0; c2 <= nc; c2++) D.el("line", {x1: xs[c2], x2: xs[c2], y1: y0, y2: y0 + tableH, stroke: "var(--line)", "stroke-width": c2 === 1 ? 2.5 : 1.2}, gL);
|
|
210
|
+
this.cellEls = pl.cells.map(function(x){
|
|
211
|
+
var cx0 = xs[x.c], cy0 = y0 + x.r * rh, num = !x.head && /^[−\-]?[\d.]+$|^(/.test(x.text);
|
|
212
|
+
var o = {x: x};
|
|
213
|
+
if (x.hidden) o.bg = D.el("rect", {x: cx0 + 1, y: cy0 + 1, width: cw[x.c] - 2, height: rh - 2, fill: "var(--muted)", opacity: 0.18}, gB);
|
|
214
|
+
var ty = x.sub ? cy0 + rh * 0.75 + fs * 0.36 : hasSub && !x.head && x.r > 0 && !x.sub ? cy0 + rh * 0.3 + fs * 0.36 : cy0 + rh / 2 + fs * 0.36;
|
|
215
|
+
var tx = num ? xs[x.c + 1] - pad : x.head && x.c === 0 ? cx0 + pad : cx0 + cw[x.c] / 2;
|
|
216
|
+
o.t = D.el("text", {x: tx.toFixed(1), y: ty.toFixed(1), "font-size": fs, "text-anchor": num ? "end" : x.head && x.c === 0 ? "start" : "middle",
|
|
217
|
+
fill: x.sub || x.hidden ? "var(--muted)" : "var(--fg)", "font-weight": x.head ? 700 : 400, style: "font-variant-numeric:tabular-nums"}, gT);
|
|
218
|
+
o.t.textContent = x.text;
|
|
219
|
+
if (x.q && !x.sub){ o.qm = D.el("text", {x: (cx0 + cw[x.c] / 2).toFixed(1), y: ty.toFixed(1), "font-size": fs, "text-anchor": "middle", fill: "var(--muted)"}, gT); o.qm.textContent = "?"; }
|
|
220
|
+
o.box = [cx0, cy0, cw[x.c], rh];
|
|
221
|
+
return o;
|
|
222
|
+
});
|
|
223
|
+
// 使ったセル・埋めたセルの枠(ステップごと)
|
|
224
|
+
this.hl = pl.steps.map(function(s){
|
|
225
|
+
var g = D.el("g", {opacity: 0}, gH);
|
|
226
|
+
s.src.forEach(function(rc){ D.el("rect", {x: xs[rc[1]] + 3, y: y0 + rc[0] * rh + 3, width: cw[rc[1]] - 6, height: rh - 6, rx: 4, fill: "none", stroke: "var(--accent2)", "stroke-width": 3}, g); });
|
|
227
|
+
s.fill.forEach(function(x){ D.el("rect", {x: xs[x.c] + 3, y: y0 + x.r * rh + 3, width: cw[x.c] - 6, height: rh - 6, rx: 4, fill: "none", stroke: "var(--emph)", "stroke-width": 3}, g); });
|
|
228
|
+
return g;
|
|
229
|
+
});
|
|
230
|
+
// 式の行(表の下)
|
|
231
|
+
var fy = y0 + tableH + 12 + fs * 0.9;
|
|
232
|
+
this.lines = pl.steps.map(function(s){
|
|
233
|
+
var g = D.el("g", {opacity: 0}, gT);
|
|
234
|
+
s.line.forEach(function(t, i){
|
|
235
|
+
var room = W - 8, txt = t;
|
|
236
|
+
if (tw(txt) > room){ ctx.report("layout", "[ctable] the formula line \"" + t.slice(0, 30) + "…\" is wider than the element; it is cut"); var a = Array.from(txt); while (a.length && tw(a.join("") + "…") > room) a.pop(); txt = a.join("") + "…"; }
|
|
237
|
+
var e = D.el("text", {x: (W / 2).toFixed(1), y: (fy + i * lineH).toFixed(1), "font-size": fs, "text-anchor": "middle", fill: "var(--fg)", style: "font-variant-numeric:tabular-nums"}, g);
|
|
238
|
+
e.textContent = txt;
|
|
239
|
+
});
|
|
240
|
+
return g;
|
|
241
|
+
});
|
|
242
|
+
// 読める表(data-readable):最後の状態の表をそのまま
|
|
243
|
+
var tbl = document.createElement("table");
|
|
244
|
+
tbl.className = "sr-only"; tbl.setAttribute("data-readable", "");
|
|
245
|
+
tbl.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);border:0");
|
|
246
|
+
for (var rr = 0; rr < pl.nr; rr++){
|
|
247
|
+
var tr = document.createElement("tr");
|
|
248
|
+
for (var cc = 0; cc < nc; cc++){
|
|
249
|
+
var x = pl.cells.filter(function(q){ return q.r === rr && q.c === cc; }), td = document.createElement(rr === 0 || cc === 0 ? "th" : "td");
|
|
250
|
+
td.textContent = x.map(function(q){ return q.text; }).join(" ");
|
|
251
|
+
tr.appendChild(td);
|
|
252
|
+
}
|
|
253
|
+
tbl.appendChild(tr);
|
|
254
|
+
}
|
|
255
|
+
this.appendChild(tbl);
|
|
256
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
257
|
+
this.setAttribute("role", "img");
|
|
258
|
+
if (!this._aria) this.setAttribute("aria-label", (pl.L === T.ja ? "表:" : "Table: ") + pl.cols.filter(Boolean).join(pl.L === T.ja ? "、" : ", ") + "; " + pl.steps.map(function(s){ return s.line.join(" "); }).filter(Boolean).join("; "));
|
|
259
|
+
this.model = {cols: pl.cols, nr: pl.nr, steps: pl.steps.length};
|
|
260
|
+
}
|
|
261
|
+
duration(k){ return k >= 1 && k <= this.plan().steps.length ? this.props.dur : 0; }
|
|
262
|
+
render(k, t, ctx){
|
|
263
|
+
if (!this.cellEls) return;
|
|
264
|
+
var pl = this.plan(), D = base, P = this.props, N = pl.steps.length;
|
|
265
|
+
k = Math.max(0, Math.min(k, N));
|
|
266
|
+
var e = k === 0 ? 1 : D.prog(t, 0, P.dur), fin = k === N && (t === Infinity || t >= P.dur);
|
|
267
|
+
this.cellEls.forEach(function(o){
|
|
268
|
+
var st = o.x.step, shown = st === 0 ? 1 : st < k ? 1 : st > k ? 0 : e;
|
|
269
|
+
// 埋まる前は「?」、埋まるステップの前半で「?」が消え、後半で値が出る(同じ場所の字は重ねない)
|
|
270
|
+
var vis = st === 0 || !o.x.q ? shown : Math.max(0, 2 * shown - 1);
|
|
271
|
+
o.t.setAttribute("opacity", vis.toFixed(3));
|
|
272
|
+
if (o.qm) o.qm.setAttribute("opacity", (st === 0 ? 0 : st < k ? 0 : st > k ? 1 : Math.max(0, 1 - 2 * e)).toFixed(3));
|
|
273
|
+
if (o.bg) o.bg.setAttribute("opacity", (0.18).toFixed(3));
|
|
274
|
+
});
|
|
275
|
+
this.hl.forEach(function(g, i){ g.setAttribute("opacity", (i + 1 === k && !fin ? e : 0).toFixed(3)); });
|
|
276
|
+
this.lines.forEach(function(g, i){ g.setAttribute("opacity", (i + 1 === k ? e : 0).toFixed(3)); });
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
Text ticks: `xt='["Apr","May"]'` (x = 1, 2) or `[[0, "FY2023"], …]`.
|
|
35
|
+
|
|
36
|
+
`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.
|
|
37
|
+
|
|
38
|
+
<!-- llm: omit -->
|
|
39
|
+
- `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.
|
|
40
|
+
- `area`: shades to y = 0; several spans; rejection regions, p-values; `areaLabel` per span
|
|
41
|
+
Older forms (still work; not described to the AI)
|
|
42
|
+
|
|
43
|
+
- `color` = `tone`; `at` = `labelAt` (only without `labelAt`)
|
|
44
|
+
- `anchor` `start` `middle` `end`: raw text-anchor
|
|
45
|
+
- Without `step`, series i is step i + 1. Showing later steps faintly draws later lines at `--preview-opacity`
|
|
46
|
+
- The demo is `demo.html`. Series fields match `m-scatter` (conventions §3)
|
|
47
|
+
<!-- llm: end -->
|