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,322 @@
|
|
|
1
|
+
// m-classify2d:2 次元の分類の図を、scikit-learn が出した値のとおりに描く。点・領域(格子の上の predict)・境界・
|
|
2
|
+
// 確率や決定関数の等高線(contour-core)・サポートベクトル・ボロノイ図(パーツが種の点から計算)・決定木の分割・k 平均法。
|
|
3
|
+
// 値は tools/sk2ega.py の出力を書く。パーツはモデルの計算をしない(k 平均法の割り当てと重心だけ確かめる)。
|
|
4
|
+
// <m-classify2d style="height:440px"><script type="application/json">
|
|
5
|
+
// {"axes": {"x": {"label": "x₁", "range": [-3, 3]}, "y": {"label": "x₂", "range": [-2, 2]}},
|
|
6
|
+
// "classes": [{"id": 0, "label": "A"}, {"id": 1, "label": "B"}], "points": [[0.4, 1.2, 1], [-1.1, 0.3, 0]],
|
|
7
|
+
// "grid": {"nx": 60, "ny": 40, "labels": "0*35 1*25 …"}}
|
|
8
|
+
// (JSON の終わり)</m-classify2d>
|
|
9
|
+
// 格子:x は range を nx 点、y は ny 点に等分した点(両端を含む。numpy の linspace と meshgrid)。labels と fields の値は行ごと
|
|
10
|
+
// (行 0 が y の最小)。labels は 2 次元の配列か「クラス*個数」を空白で区切った行の順の続け書き。
|
|
11
|
+
// 色:クラスごとに CLASS_COLORS(--series-1・--series-3・--fg・--series-4)と点の形(○・□・△・◇。色だけに頼らない)、領域はその色の薄い塗り、境界と等高線 --fg、
|
|
12
|
+
// サポートベクトルの輪 --fg(クラスの色と --emph が近いテーマでも紛れない)、k 平均法の重心は × の印。
|
|
13
|
+
egatariParts.define({name: "classify2d", version: "2.0.1", requires: {base: "1.3.0", "contour-core": "1.0.0"}, element: "m-classify2d"}, function(deps){
|
|
14
|
+
"use strict";
|
|
15
|
+
var base = deps.base, D = base, K = deps["contour-core"], clipN = 0;
|
|
16
|
+
var NUM = {type: "number"}, PT = {type: "array", minItems: 2, maxItems: 3, items: {type: ["number", "null"]}};
|
|
17
|
+
var CAP = {classes: 4, points: 300, nx: 160, ny: 120, seeds: 40, nodes: 31, iters: 10, levels: 5};
|
|
18
|
+
var SHAPES = ["circle", "square", "triangle", "diamond"];
|
|
19
|
+
// クラスの色の並び(m-folds の classes と同じ。1 つの意味に 1 つの色):--series-2 は印の色 --emph と同じテーマがあるので使わない。
|
|
20
|
+
// 既定のテーマでは --series-3 = --accent2、--series-4 = --muted なので、3 つ目は --fg(4 つ目の --muted は、k 平均法のまだ割り当てていない点と同じ色)
|
|
21
|
+
var CLASS_COLORS = ["var(--series-1)", "var(--series-3)", "var(--fg)", "var(--series-4)"];
|
|
22
|
+
var T = {
|
|
23
|
+
ja: {summary: function(c, n){ return "分類の図:クラス " + c.join("・") + "、点 " + n + " 個"; }, regions: "領域", tree: "決定木の分割", kmeans: function(n){ return "k 平均法(" + n + " 回の繰り返し)"; }, sv: "サポートベクトル"},
|
|
24
|
+
en: {summary: function(c, n){ return "Classification: classes " + c.join(", ") + "; " + n + " points"; }, regions: "regions", tree: "decision tree splits", kmeans: function(n){ return "k-means (" + n + " iterations)"; }, sv: "support vectors"}
|
|
25
|
+
};
|
|
26
|
+
function nice(lo, hi, n){
|
|
27
|
+
var span = hi - lo, raw = span / Math.max(1, n), p = Math.pow(10, Math.floor(Math.log10(raw))), m = raw / p, st = (m < 1.5 ? 1 : m < 3 ? 2 : m < 7 ? 5 : 10) * p, out = [];
|
|
28
|
+
for (var v = Math.ceil(lo / st - 1e-9) * st; v <= hi + 1e-9 * span; v += st) out.push(Math.abs(v) < st * 1e-9 ? 0 : v);
|
|
29
|
+
return {ticks: out, step: st};
|
|
30
|
+
}
|
|
31
|
+
function fmt(v, st){ var d = Math.max(0, -Math.floor(Math.log10(st) + 1e-9)); var s = v.toFixed(Math.min(4, d)); return s.indexOf("-") === 0 ? "−" + s.slice(1) : s; }
|
|
32
|
+
function rle(s){ var out = []; String(s).trim().split(/\s+/).forEach(function(tok){ var m = /^(-?\d+)\*(\d+)$/.exec(tok); if (m){ for (var i = 0; i < +m[2]; i++) out.push(+m[1]); } else if (/^-?\d+$/.test(tok)) out.push(+tok); else out.push(NaN); }); return out; }
|
|
33
|
+
// 種の点 s のボロノイ領域:長方形を、ほかの種との垂直二等分線で切っていく(半平面の切り取り)
|
|
34
|
+
function cell(seeds, s, rect){
|
|
35
|
+
var poly = [[rect[0], rect[2]], [rect[1], rect[2]], [rect[1], rect[3]], [rect[0], rect[3]]], p = seeds[s];
|
|
36
|
+
for (var o = 0; o < seeds.length && poly.length; o++){
|
|
37
|
+
if (o === s) continue;
|
|
38
|
+
var q = seeds[o], nx = q[0] - p[0], ny = q[1] - p[1], c = (q[0] * q[0] + q[1] * q[1] - p[0] * p[0] - p[1] * p[1]) / 2;
|
|
39
|
+
if (!nx && !ny) continue;
|
|
40
|
+
var inside = function(v){ return v[0] * nx + v[1] * ny <= c + 1e-12; }, out = [];
|
|
41
|
+
for (var i = 0; i < poly.length; i++){
|
|
42
|
+
var a = poly[i], b = poly[(i + 1) % poly.length], ia = inside(a), ib = inside(b);
|
|
43
|
+
if (ia) out.push(a);
|
|
44
|
+
if (ia !== ib){ var da = a[0] * nx + a[1] * ny - c, db = b[0] * nx + b[1] * ny - c, u = da / (da - db); out.push([a[0] + (b[0] - a[0]) * u, a[1] + (b[1] - a[1]) * u]); }
|
|
45
|
+
}
|
|
46
|
+
poly = out;
|
|
47
|
+
}
|
|
48
|
+
return poly;
|
|
49
|
+
}
|
|
50
|
+
return class extends base.MotionElement {
|
|
51
|
+
static partName = "classify2d";
|
|
52
|
+
static preview = "none";
|
|
53
|
+
static shape = {schema: {type: "object", additionalProperties: false, required: ["axes", "points"], properties: {
|
|
54
|
+
axes: {type: "object", additionalProperties: false, required: ["x", "y"], properties: {
|
|
55
|
+
x: {type: "object", additionalProperties: false, required: ["range"], properties: {label: {type: "string"}, range: {type: "array", minItems: 2, maxItems: 2, items: NUM}}},
|
|
56
|
+
y: {type: "object", additionalProperties: false, required: ["range"], properties: {label: {type: "string"}, range: {type: "array", minItems: 2, maxItems: 2, items: NUM}}}}},
|
|
57
|
+
classes: {type: "array", minItems: 1, maxItems: 4, items: {type: "object", additionalProperties: false, required: ["id"], properties: {id: {type: "integer"}, label: {type: "string"}}}},
|
|
58
|
+
points: {type: "array", minItems: 1, maxItems: 300, items: PT},
|
|
59
|
+
grid: {type: "object", additionalProperties: false, required: ["nx", "ny"], properties: {nx: {type: "integer"}, ny: {type: "integer"}, labels: {type: ["string", "array"]}}},
|
|
60
|
+
fields: {type: "array", maxItems: 2, items: {type: "object", additionalProperties: false, required: ["values", "levels"], properties: {
|
|
61
|
+
name: {type: "string"}, class: {type: "integer"}, values: {type: "array"}, levels: {type: "array", minItems: 1, maxItems: 5, items: NUM}, style: {type: "array", items: {type: "string", enum: ["solid", "dash"]}}, labels: {type: "boolean"}}}},
|
|
62
|
+
sv: {type: "array", items: {type: "integer"}},
|
|
63
|
+
voronoi: {type: "object", additionalProperties: false, required: ["seeds"], properties: {seeds: {type: "array", minItems: 1, maxItems: 40, items: PT}}},
|
|
64
|
+
tree: {type: "object", additionalProperties: false, required: ["nodes"], properties: {nodes: {type: "array", minItems: 1, maxItems: 31, items: {type: "object", additionalProperties: false, required: ["id"], properties: {
|
|
65
|
+
id: {type: "string"}, feature: {type: "integer", enum: [0, 1]}, threshold: NUM, left: {type: "string"}, right: {type: "string"}, class: {type: "integer"}}}}}},
|
|
66
|
+
kmeans: {type: "object", additionalProperties: false, required: ["iters"], properties: {iters: {type: "array", minItems: 1, maxItems: 10, items: {type: "object", additionalProperties: false, required: ["centroids", "assign"], properties: {
|
|
67
|
+
centroids: {type: "array", minItems: 1, maxItems: 4, items: {type: "array", minItems: 2, maxItems: 2, items: NUM}}, assign: {type: "array", items: {type: "integer"}}}}}}}
|
|
68
|
+
}}, example: /*@egatari-block example*/{"axes":{"x":{"label":"x₁","range":[0,4]},"y":{"label":"x₂","range":[0,3]}},"classes":[{"id":0,"label":"A"},{"id":1,"label":"B"}],"points":[[1,1,0],[1.2,2,0],[2.8,1.1,1],[3.1,2.4,1]],"grid":{"nx":5,"ny":4,"labels":"0*2 1*3 0*2 1*3 0*2 1*3 0*3 1*2"}}/*@egatari-block-end*/};
|
|
69
|
+
static props = {
|
|
70
|
+
dur: {type: "number", default: 0.9, doc: "1 ステップの秒数"},
|
|
71
|
+
size: {type: "number", default: 24, doc: "字の大きさ(px、24 以上)"},
|
|
72
|
+
marker: {type: "number", default: 8, doc: "点の印の半径(px)"}
|
|
73
|
+
};
|
|
74
|
+
get steps(){ return this.plan().steps.length; }
|
|
75
|
+
duration(k){ return k >= 1 && k <= this.plan().steps.length ? this.props.dur : 0; }
|
|
76
|
+
// データだけから決まること:ステップの並びと、確かめ(bad)
|
|
77
|
+
plan(){
|
|
78
|
+
if (this._plan) return this._plan;
|
|
79
|
+
var d = this.data || {}, bad = [], steps = [], pts = d.points || [], classes = d.classes || [], cls = {};
|
|
80
|
+
classes.forEach(function(c, i){ cls[c.id] = i; });
|
|
81
|
+
var known = function(c){ return c === null || c === undefined || c in cls; };
|
|
82
|
+
pts.forEach(function(p, i){ if (!known(p[2])) bad.push("points[" + i + "]: class " + p[2] + " is not in classes"); });
|
|
83
|
+
var rx = d.axes && d.axes.x.range, ry = d.axes && d.axes.y.range;
|
|
84
|
+
if (rx && !(rx[1] > rx[0])) bad.push("axes.x.range must be [min, max] with min < max");
|
|
85
|
+
if (ry && !(ry[1] > ry[0])) bad.push("axes.y.range must be [min, max] with min < max");
|
|
86
|
+
var labels = null;
|
|
87
|
+
if (d.grid){
|
|
88
|
+
var g = d.grid;
|
|
89
|
+
if (!(g.nx >= 2 && g.nx <= CAP.nx && g.ny >= 2 && g.ny <= CAP.ny)) bad.push("grid: nx 2–" + CAP.nx + " and ny 2–" + CAP.ny + " (got " + g.nx + " × " + g.ny + ")");
|
|
90
|
+
if (g.labels !== undefined){
|
|
91
|
+
var flat = typeof g.labels === "string" ? rle(g.labels) : [].concat.apply([], g.labels);
|
|
92
|
+
if (flat.length !== g.nx * g.ny) bad.push("grid.labels has " + flat.length + " values; nx × ny = " + g.nx * g.ny);
|
|
93
|
+
else if (flat.some(function(v){ return !(v in cls); })) bad.push("grid.labels has a class that is not in classes");
|
|
94
|
+
else { labels = []; for (var j = 0; j < g.ny; j++) labels.push(flat.slice(j * g.nx, (j + 1) * g.nx)); }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
var fields = (d.fields || []).map(function(f, i){
|
|
98
|
+
var ok = d.grid && Array.isArray(f.values) && f.values.length === d.grid.ny && f.values.every(function(r){ return Array.isArray(r) && r.length === d.grid.nx && r.every(function(v){ return typeof v === "number"; }); });
|
|
99
|
+
if (!ok) bad.push("fields[" + i + "].values must be ny × nx numbers (a grid is needed)");
|
|
100
|
+
if (f.class !== undefined && !known(f.class)) bad.push("fields[" + i + "].class: " + f.class + " is not in classes");
|
|
101
|
+
return ok ? f : null;
|
|
102
|
+
}).filter(Boolean);
|
|
103
|
+
(d.sv || []).forEach(function(n){ if (!(n >= 0 && n < pts.length)) bad.push("sv: " + n + " is not a point index (0–" + (pts.length - 1) + ")"); });
|
|
104
|
+
(d.voronoi ? d.voronoi.seeds : []).forEach(function(s, i){ if (!known(s[2])) bad.push("voronoi.seeds[" + i + "]: class " + s[2] + " is not in classes"); });
|
|
105
|
+
// 決定木:根から幅優先で分割を並べ、節ごとに長方形を持たせる
|
|
106
|
+
var splits = [], leaves = [];
|
|
107
|
+
if (d.tree && rx && ry){
|
|
108
|
+
var byId = {}; d.tree.nodes.forEach(function(n){ byId[n.id] = n; });
|
|
109
|
+
var queue = [{n: d.tree.nodes[0], r: [rx[0], rx[1], ry[0], ry[1]]}], seen = {};
|
|
110
|
+
while (queue.length){
|
|
111
|
+
var q = queue.shift(), n = q.n;
|
|
112
|
+
if (seen[n.id]){ bad.push("tree: node \"" + n.id + "\" is reached twice"); continue; }
|
|
113
|
+
seen[n.id] = true;
|
|
114
|
+
if (n.left !== undefined || n.right !== undefined){
|
|
115
|
+
var L = byId[n.left], R = byId[n.right];
|
|
116
|
+
if (!L || !R){ bad.push("tree: node \"" + n.id + "\" needs left and right that exist"); continue; }
|
|
117
|
+
var lo = n.feature === 0 ? q.r[0] : q.r[2], hi = n.feature === 0 ? q.r[1] : q.r[3];
|
|
118
|
+
if (!(n.feature === 0 || n.feature === 1) || !(n.threshold > lo && n.threshold < hi)) bad.push("tree: node \"" + n.id + "\" threshold " + n.threshold + " is not inside its cell (" + lo + " to " + hi + " on feature " + n.feature + ")");
|
|
119
|
+
var rl = q.r.slice(), rr = q.r.slice();
|
|
120
|
+
if (n.feature === 0){ rl[1] = n.threshold; rr[0] = n.threshold; } else { rl[3] = n.threshold; rr[2] = n.threshold; }
|
|
121
|
+
splits.push({id: n.id, feature: n.feature, t: n.threshold, r: q.r});
|
|
122
|
+
queue.push({n: L, r: rl}, {n: R, r: rr});
|
|
123
|
+
} else {
|
|
124
|
+
if (!(n.class in cls)) bad.push("tree: leaf \"" + n.id + "\" needs a class from classes");
|
|
125
|
+
leaves.push({id: n.id, cls: n.class, r: q.r});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// k 平均法:割り当ては最も近い重心か(同じ距離は許す)、次の重心は割り当てた点の平均か
|
|
130
|
+
var km = d.kmeans ? d.kmeans.iters : null;
|
|
131
|
+
if (km) km.forEach(function(it, i){
|
|
132
|
+
if (it.assign.length !== pts.length){ bad.push("kmeans.iters[" + i + "].assign has " + it.assign.length + " entries; points has " + pts.length); return; }
|
|
133
|
+
var C = it.centroids, d2 = function(p, c){ return (p[0] - c[0]) * (p[0] - c[0]) + (p[1] - c[1]) * (p[1] - c[1]); };
|
|
134
|
+
it.assign.forEach(function(a, n){
|
|
135
|
+
if (!(a >= 0 && a < C.length)){ bad.push("kmeans.iters[" + i + "].assign[" + n + "] is not a centroid index"); return; }
|
|
136
|
+
var best = Math.min.apply(null, C.map(function(c){ return d2(pts[n], c); }));
|
|
137
|
+
if (d2(pts[n], C[a]) > best * (1 + 1e-9) + 1e-12) bad.push("kmeans.iters[" + i + "].assign[" + n + "] = " + a + " is not the nearest centroid");
|
|
138
|
+
});
|
|
139
|
+
if (km[i + 1]){
|
|
140
|
+
C.forEach(function(_, c){
|
|
141
|
+
var m = [0, 0], cnt = 0; it.assign.forEach(function(a, n){ if (a === c){ m[0] += pts[n][0]; m[1] += pts[n][1]; cnt++; } });
|
|
142
|
+
if (!cnt) return;
|
|
143
|
+
var want = [m[0] / cnt, m[1] / cnt], got = km[i + 1].centroids[c];
|
|
144
|
+
if (!got || Math.abs(got[0] - want[0]) > 1e-6 * Math.max(1, Math.abs(want[0])) + 0.51 * Math.pow(10, -dec(got[0])) || Math.abs(got[1] - want[1]) > 1e-6 * Math.max(1, Math.abs(want[1])) + 0.51 * Math.pow(10, -dec(got[1])))
|
|
145
|
+
bad.push("kmeans.iters[" + (i + 1) + "].centroids[" + c + "] should be the mean of the points assigned in iteration " + i + ": (" + +want[0].toFixed(6) + ", " + +want[1].toFixed(6) + ")");
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
function dec(v){ var s = String(v).split(".")[1]; return s ? Math.min(s.length, 12) : 12; }
|
|
150
|
+
// ステップ
|
|
151
|
+
steps.push({kind: "points"});
|
|
152
|
+
if (km){ km.forEach(function(_, i){ steps.push({kind: "assign", i: i}); if (i + 1 < km.length) steps.push({kind: "update", i: i}); }); }
|
|
153
|
+
else if (d.tree){ splits.forEach(function(s, i){ steps.push({kind: "split", i: i}); }); steps.push({kind: "leaves"}); }
|
|
154
|
+
else {
|
|
155
|
+
if (labels || d.voronoi) steps.push({kind: "regions"});
|
|
156
|
+
fields.forEach(function(f, i){ steps.push({kind: "field", i: i}); });
|
|
157
|
+
if ((d.sv || []).length) steps.push({kind: "sv"});
|
|
158
|
+
}
|
|
159
|
+
if (d.tree && (labels || d.voronoi || fields.length)) bad.push("tree mode draws its own regions: leave out grid, fields and voronoi");
|
|
160
|
+
if (km && (d.tree || labels || d.voronoi)) bad.push("kmeans mode draws its own cells: leave out grid, voronoi and tree");
|
|
161
|
+
return (this._plan = {d: d, bad: bad, steps: steps, cls: cls, classes: classes, labels: labels, fields: fields, splits: splits, leaves: leaves, km: km});
|
|
162
|
+
}
|
|
163
|
+
mount(ctx){
|
|
164
|
+
var self = this, P = this.props, pl = this.plan(), d = pl.d, ja = /^ja\b/i.test(ctx.lang || "ja"), L = ja ? T.ja : T.en;
|
|
165
|
+
if (!(Number.isFinite(P.dur) && P.dur > 0)){ ctx.report("attr", "[classify2d] dur must be positive; using 0.9"); P.dur = 0.9; }
|
|
166
|
+
if (!(Number.isFinite(P.size) && P.size >= 24)){ ctx.report("attr", "[classify2d] size must be at least 24; using 24"); P.size = 24; }
|
|
167
|
+
if (!(Number.isFinite(P.marker) && P.marker >= 4)){ ctx.report("attr", "[classify2d] marker must be at least 4; using 8"); P.marker = 8; }
|
|
168
|
+
pl.bad.forEach(function(s){ ctx.report("data", "[classify2d] " + s); });
|
|
169
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
170
|
+
var W = Math.max(1, this.clientWidth), H = Math.max(1, this.clientHeight), fs = P.size, mr = P.marker;
|
|
171
|
+
var rx = d.axes.x.range, ry = d.axes.y.range, tx = nice(rx[0], rx[1], 6), ty = nice(ry[0], ry[1], 5);
|
|
172
|
+
var tw = function(s){ return base.textWidth(s, fs, {font: self}); };
|
|
173
|
+
var yTickW = Math.max.apply(null, ty.ticks.map(function(v){ return tw(fmt(v, ty.step)); }).concat([0]));
|
|
174
|
+
// 上:凡例の行(クラスの印と名前)と y 軸の名前。下:x の目盛りと x 軸の名前
|
|
175
|
+
var legendH = Math.ceil(fs * 1.7), m = {l: Math.ceil(yTickW) + 14, r: 12, t: legendH + 6, b: Math.ceil(fs * 1.3) + 6};
|
|
176
|
+
var px = m.l, py = m.t, pw = Math.max(1, W - m.l - m.r), ph = Math.max(1, H - m.t - m.b);
|
|
177
|
+
if (pw < 200 || ph < 150) ctx.report("size", "[classify2d] element is " + W + " × " + H + " px; allow at least " + Math.ceil(m.l + m.r + 200) + " × " + Math.ceil(m.t + m.b + 150) + " px");
|
|
178
|
+
var X = function(x){ return px + (x - rx[0]) / (rx[1] - rx[0]) * pw; }, Y = function(y){ return py + (ry[1] - y) / (ry[1] - ry[0]) * ph; };
|
|
179
|
+
this.geo = {X: X, Y: Y, px: px, py: py, pw: pw, ph: ph, rect: [rx[0], rx[1], ry[0], ry[1]]};
|
|
180
|
+
var colOf = function(c){ var i = pl.cls[c]; return i === undefined ? "var(--muted)" : CLASS_COLORS[i]; };
|
|
181
|
+
this.colOf = colOf;
|
|
182
|
+
this.setAttribute("role", "img");
|
|
183
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
184
|
+
var names = pl.classes.map(function(c){ return c.label || String(c.id); });
|
|
185
|
+
if (!this._aria) this.setAttribute("aria-label", L.summary(names, d.points.length) + (pl.km ? "; " + L.kmeans(pl.km.length) : d.tree ? "; " + L.tree : pl.labels || d.voronoi ? "; " + L.regions : "") + ((d.sv || []).length ? "; " + L.sv + " " + d.sv.length : ""));
|
|
186
|
+
var svg = this.svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true"}, this);
|
|
187
|
+
var cid = "classify2d-2-0-0-clip" + (++clipN);
|
|
188
|
+
D.el("rect", {x: px, y: py, width: pw, height: ph}, D.el("clipPath", {id: cid}, D.el("defs", {}, svg)));
|
|
189
|
+
var plot = D.el("g", {"clip-path": "url(#" + cid + ")"}, svg);
|
|
190
|
+
// 層:領域 → ボロノイ → 決定木の葉 → 格子線 → 等高線 → 分割の線 → 点 → 輪 → 重心
|
|
191
|
+
this.regionG = D.el("g", {opacity: 0, "shape-rendering": "crispEdges"}, plot);
|
|
192
|
+
this.vorG = D.el("g", {opacity: 0}, plot);
|
|
193
|
+
this.leafG = D.el("g", {opacity: 0}, plot);
|
|
194
|
+
this.kmG = D.el("g", {}, plot);
|
|
195
|
+
var gridG = D.el("g", {}, plot);
|
|
196
|
+
tx.ticks.forEach(function(v){ D.el("line", {x1: X(v), y1: py, x2: X(v), y2: py + ph, stroke: "var(--line)", "stroke-width": 1, opacity: 0.6}, gridG); });
|
|
197
|
+
ty.ticks.forEach(function(v){ D.el("line", {x1: px, y1: Y(v), x2: px + pw, y2: Y(v), stroke: "var(--line)", "stroke-width": 1, opacity: 0.6}, gridG); });
|
|
198
|
+
this.boundaryG = D.el("g", {opacity: 0}, plot);
|
|
199
|
+
this.fieldG = pl.fields.map(function(){ return D.el("g", {opacity: 0}, plot); });
|
|
200
|
+
this.splitEls = [];
|
|
201
|
+
var splitG = D.el("g", {}, plot);
|
|
202
|
+
D.el("rect", {x: px, y: py, width: pw, height: ph, fill: "none", stroke: "var(--muted)", "stroke-width": 2}, svg);
|
|
203
|
+
// 目盛りと軸の名前
|
|
204
|
+
// x の目盛りの数は、右端の x 軸の名前と重ならないものだけ
|
|
205
|
+
var xLabW = d.axes.x.label ? tw(d.axes.x.label.replace(/[*_]/g, "")) + 12 : 0;
|
|
206
|
+
tx.ticks.forEach(function(v){ var s = fmt(v, tx.step); if (X(v) + tw(s) / 2 > px + pw - xLabW) return; D.el("text", {x: X(v), y: py + ph + fs + 2, "font-size": fs, "text-anchor": "middle", fill: "var(--muted)"}, svg).textContent = s; });
|
|
207
|
+
ty.ticks.forEach(function(v){ D.el("text", {x: px - 8, y: Y(v) + fs * 0.35, "font-size": fs, "text-anchor": "end", fill: "var(--muted)"}, svg).textContent = fmt(v, ty.step); });
|
|
208
|
+
if (d.axes.y.label) D.mtext(svg, px, legendH - fs * 0.45, d.axes.y.label, {"font-size": fs, fill: "var(--fg)"});
|
|
209
|
+
// 凡例:右上にクラスの印と名前(k 平均法はクラスターなので書かない)
|
|
210
|
+
var legW = 0, legend = pl.km ? [] : pl.classes.map(function(c, i){ var t = c.label || String(c.id), w = 2 * mr + 10 + tw(t) + 20; legW += w; return {t: t, w: w, i: i, id: c.id}; });
|
|
211
|
+
var lx = W - m.r - legW, yLabW = d.axes.y.label ? tw(d.axes.y.label.replace(/[*_]/g, "")) + 16 : 0;
|
|
212
|
+
if (lx < px + yLabW) ctx.report("layout", "[classify2d] the class names need " + Math.ceil(legW) + " px beside the y-axis name; shorten them");
|
|
213
|
+
legend.forEach(function(o){ self.marker(svg, lx + mr, legendH / 2 + 2, o.i, colOf(o.id), mr); D.el("text", {x: lx + 2 * mr + 10, y: legendH / 2 + 2 + fs * 0.35, "font-size": fs, fill: "var(--fg)"}, svg).textContent = o.t; lx += o.w; });
|
|
214
|
+
// x 軸の名前:目盛りの右端の数の左に入らなければ、目盛りの行の右に
|
|
215
|
+
if (d.axes.x.label) D.mtext(svg, px + pw, py + ph + fs + 2, d.axes.x.label, {"font-size": fs, "text-anchor": "end", fill: "var(--fg)", "data-xlabel": ""});
|
|
216
|
+
// 領域(格子の上の predict):行ごとに同じクラスの続きを 1 つの長方形に。境界は違うクラスの間のセルの辺(階段)
|
|
217
|
+
if (pl.labels){
|
|
218
|
+
var g = d.grid, dx = (rx[1] - rx[0]) / (g.nx - 1), dy = (ry[1] - ry[0]) / (g.ny - 1), lab = pl.labels;
|
|
219
|
+
var cx = function(i){ return Math.max(rx[0], Math.min(rx[1], rx[0] + (i - 0.5) * dx)); }, cy = function(j){ return Math.max(ry[0], Math.min(ry[1], ry[0] + (j - 0.5) * dy)); };
|
|
220
|
+
lab.forEach(function(row, j){
|
|
221
|
+
var i0 = 0;
|
|
222
|
+
for (var i = 1; i <= row.length; i++) if (i === row.length || row[i] !== row[i0]){
|
|
223
|
+
D.el("rect", {x: X(cx(i0)).toFixed(1), y: Y(cy(j + 1)).toFixed(1), width: (X(cx(i)) - X(cx(i0))).toFixed(1), height: (Y(cy(j)) - Y(cy(j + 1))).toFixed(1), fill: colOf(row[i0]), "fill-opacity": 0.2}, self.regionG);
|
|
224
|
+
i0 = i;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
var path = "";
|
|
228
|
+
for (var j = 0; j < g.ny; j++) for (var i = 0; i < g.nx; i++){
|
|
229
|
+
if (i + 1 < g.nx && lab[j][i] !== lab[j][i + 1]) path += "M" + X(cx(i + 1)).toFixed(1) + " " + Y(cy(j)).toFixed(1) + "V" + Y(cy(j + 1)).toFixed(1);
|
|
230
|
+
if (j + 1 < g.ny && lab[j][i] !== lab[j + 1][i]) path += "M" + X(cx(i)).toFixed(1) + " " + Y(cy(j + 1)).toFixed(1) + "H" + X(cx(i + 1)).toFixed(1);
|
|
231
|
+
}
|
|
232
|
+
// 確率や決定関数の等高線があれば、境界はそちらの滑らかな線で見せる(階段は描かない)
|
|
233
|
+
if (path && !pl.fields.length) D.el("path", {d: path, fill: "none", stroke: "var(--fg)", "stroke-width": 2.5, "stroke-linecap": "square"}, this.boundaryG);
|
|
234
|
+
}
|
|
235
|
+
// ボロノイ図(種の点から計算)
|
|
236
|
+
if (d.voronoi){
|
|
237
|
+
var seeds = d.voronoi.seeds, rect = this.geo.rect;
|
|
238
|
+
seeds.forEach(function(sd, s){
|
|
239
|
+
var poly = cell(seeds, s, rect);
|
|
240
|
+
if (poly.length < 3) return;
|
|
241
|
+
D.el("path", {d: "M" + poly.map(function(v){ return X(v[0]).toFixed(1) + " " + Y(v[1]).toFixed(1); }).join("L") + "Z", fill: sd[2] === null || sd[2] === undefined ? "none" : colOf(sd[2]), "fill-opacity": 0.2, stroke: "var(--fg)", "stroke-width": 2}, self.vorG);
|
|
242
|
+
});
|
|
243
|
+
seeds.forEach(function(sd){ D.el("circle", {cx: X(sd[0]), cy: Y(sd[1]), r: 4, fill: "var(--fg)"}, self.vorG); });
|
|
244
|
+
}
|
|
245
|
+
// 等高線(確率・決定関数)と、その値の名前(線の上、地の色の縁取り)
|
|
246
|
+
pl.fields.forEach(function(f, n){
|
|
247
|
+
var g = d.grid, dx = (rx[1] - rx[0]) / (g.nx - 1), dy = (ry[1] - ry[0]) / (g.ny - 1);
|
|
248
|
+
var gxp = function(p){ return X(rx[0] + p[0] * dx); }, gyp = function(p){ return Y(ry[0] + p[1] * dy); };
|
|
249
|
+
f.levels.forEach(function(lv, li){
|
|
250
|
+
var dash = (f.style || [])[li] === "dash";
|
|
251
|
+
K.lines(f.values, lv).forEach(function(line){
|
|
252
|
+
if (line.length < 2) return;
|
|
253
|
+
D.el("path", {d: "M" + line.map(function(p){ return gxp(p).toFixed(1) + " " + gyp(p).toFixed(1); }).join("L"), fill: "none", stroke: "var(--fg)", "stroke-width": dash ? 2 : 3, "stroke-dasharray": dash ? "10 8" : null}, self.fieldG[n]);
|
|
254
|
+
if (f.labels !== false){
|
|
255
|
+
var at = K.labelAt(line), x = gxp([at.x, at.y]), y = gyp([at.x, at.y]), len = Math.hypot(gxp(line[line.length - 1]) - gxp(line[0]), gyp(line[line.length - 1]) - gyp(line[0]));
|
|
256
|
+
if (at.length && (len > 3 * fs || line.length > 8)){
|
|
257
|
+
var t = D.el("text", {x: x.toFixed(1), y: (y + fs * 0.35).toFixed(1), "font-size": fs, "text-anchor": "middle", fill: "var(--fg)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "stroke-linejoin": "round"}, self.fieldG[n]);
|
|
258
|
+
t.textContent = (lv < 0 ? "−" : "") + String(Math.abs(lv));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
// 決定木の分割(親のセルの中の線)と葉
|
|
265
|
+
pl.splits.forEach(function(s){
|
|
266
|
+
var e = s.feature === 0 ? D.el("line", {x1: X(s.t), y1: Y(s.r[3]), x2: X(s.t), y2: Y(s.r[3]), stroke: "var(--fg)", "stroke-width": 3}, splitG) : D.el("line", {x1: X(s.r[0]), y1: Y(s.t), x2: X(s.r[0]), y2: Y(s.t), stroke: "var(--fg)", "stroke-width": 3}, splitG);
|
|
267
|
+
self.splitEls.push(e);
|
|
268
|
+
});
|
|
269
|
+
pl.leaves.forEach(function(lf){ D.el("rect", {x: X(lf.r[0]), y: Y(lf.r[3]), width: X(lf.r[1]) - X(lf.r[0]), height: Y(lf.r[2]) - Y(lf.r[3]), fill: colOf(lf.cls), "fill-opacity": 0.2}, self.leafG); });
|
|
270
|
+
// k 平均法のセル(重心のボロノイ図。描くたびに重心から計算)
|
|
271
|
+
if (pl.km){ this.kmCells = pl.km[0].centroids.map(function(_, c){ return D.el("path", {fill: CLASS_COLORS[c], "fill-opacity": 0.18, stroke: "var(--fg)", "stroke-width": 2, opacity: 0}, self.kmG); }); }
|
|
272
|
+
// 点
|
|
273
|
+
var ptG = this.ptG = D.el("g", {opacity: 0}, svg);
|
|
274
|
+
this.ptEls = d.points.map(function(p){ return self.marker(ptG, X(p[0]), Y(p[1]), pl.km ? -1 : pl.cls[p[2]], pl.km ? "var(--muted)" : colOf(p[2]), mr); });
|
|
275
|
+
this.svG = D.el("g", {opacity: 0}, svg);
|
|
276
|
+
(d.sv || []).forEach(function(n){ var p = d.points[n]; if (p) D.el("circle", {cx: X(p[0]), cy: Y(p[1]), r: mr + 7, fill: "none", stroke: "var(--fg)", "stroke-width": 3}, self.svG); });
|
|
277
|
+
if (pl.km) this.cEls = pl.km[0].centroids.map(function(_, c){ var g = D.el("g", {opacity: 0}, svg); D.el("path", {d: "M-12 -12L12 12M-12 12L12 -12", stroke: "var(--bg)", "stroke-width": 9, "stroke-linecap": "round"}, g); D.el("path", {d: "M-12 -12L12 12M-12 12L12 -12", stroke: CLASS_COLORS[c], "stroke-width": 5, "stroke-linecap": "round"}, g); return g; });
|
|
278
|
+
if (d.points.length * Math.PI * mr * mr > pw * ph * 0.35) ctx.report("layout", "[classify2d] " + d.points.length + " points cover more than a third of the plot at marker " + mr + " px; use a smaller marker or fewer points");
|
|
279
|
+
}
|
|
280
|
+
// クラスの印:○・□・△・◇(クラスの順)。i < 0 は印なしの○
|
|
281
|
+
marker(g, x, y, i, col, r){
|
|
282
|
+
var s = SHAPES[i] || "circle", e;
|
|
283
|
+
if (s === "circle") e = D.el("circle", {cx: x.toFixed(1), cy: y.toFixed(1), r: r, fill: col, stroke: "var(--bg)", "stroke-width": 1.5}, g);
|
|
284
|
+
else if (s === "square") e = D.el("rect", {x: (x - r * 0.9).toFixed(1), y: (y - r * 0.9).toFixed(1), width: (1.8 * r).toFixed(1), height: (1.8 * r).toFixed(1), fill: col, stroke: "var(--bg)", "stroke-width": 1.5}, g);
|
|
285
|
+
else if (s === "triangle") e = D.el("path", {d: "M" + x.toFixed(1) + " " + (y - 1.2 * r).toFixed(1) + "L" + (x + 1.1 * r).toFixed(1) + " " + (y + 0.8 * r).toFixed(1) + "L" + (x - 1.1 * r).toFixed(1) + " " + (y + 0.8 * r).toFixed(1) + "Z", fill: col, stroke: "var(--bg)", "stroke-width": 1.5}, g);
|
|
286
|
+
else e = D.el("path", {d: "M" + x.toFixed(1) + " " + (y - 1.25 * r).toFixed(1) + "L" + (x + 1.1 * r).toFixed(1) + " " + y.toFixed(1) + "L" + x.toFixed(1) + " " + (y + 1.25 * r).toFixed(1) + "L" + (x - 1.1 * r).toFixed(1) + " " + y.toFixed(1) + "Z", fill: col, stroke: "var(--bg)", "stroke-width": 1.5}, g);
|
|
287
|
+
return e;
|
|
288
|
+
}
|
|
289
|
+
render(k, t){
|
|
290
|
+
if (!this.svg) return;
|
|
291
|
+
var self = this, pl = this.plan(), G = this.geo, dur = this.props.dur, steps = pl.steps;
|
|
292
|
+
var ph = function(i){ return k > i + 1 ? 1 : k < i + 1 ? 0 : base.prog(t, 0, dur); };
|
|
293
|
+
var at = function(kind, i){ for (var n = 0; n < steps.length; n++) if (steps[n].kind === kind && (i === undefined || steps[n].i === i)) return n; return -1; };
|
|
294
|
+
this.ptG.setAttribute("opacity", ph(0).toFixed(3));
|
|
295
|
+
var r = at("regions"); this.regionG.setAttribute("opacity", r >= 0 ? ph(r).toFixed(3) : 0); this.vorG.setAttribute("opacity", r >= 0 ? ph(r).toFixed(3) : 0); this.boundaryG.setAttribute("opacity", r >= 0 ? ph(r).toFixed(3) : 0);
|
|
296
|
+
this.fieldG.forEach(function(g, n){ var s = at("field", n); g.setAttribute("opacity", ph(s).toFixed(3)); });
|
|
297
|
+
var sv = at("sv"); this.svG.setAttribute("opacity", sv >= 0 ? ph(sv).toFixed(3) : 0);
|
|
298
|
+
// 決定木:分割の線が親のセルの端から端へ伸びる
|
|
299
|
+
pl.splits.forEach(function(s, n){
|
|
300
|
+
var e = ph(at("split", n)), el = self.splitEls[n];
|
|
301
|
+
if (s.feature === 0){ el.setAttribute("y1", G.Y(s.r[3]).toFixed(1)); el.setAttribute("y2", G.Y(s.r[3] + (s.r[2] - s.r[3]) * e).toFixed(1)); }
|
|
302
|
+
else { el.setAttribute("x1", G.X(s.r[0]).toFixed(1)); el.setAttribute("x2", G.X(s.r[0] + (s.r[1] - s.r[0]) * e).toFixed(1)); }
|
|
303
|
+
el.setAttribute("opacity", e > 0 ? 1 : 0);
|
|
304
|
+
});
|
|
305
|
+
var lv = at("leaves"); this.leafG.setAttribute("opacity", lv >= 0 ? ph(lv).toFixed(3) : 0);
|
|
306
|
+
// k 平均法:割り当て(点の色とセル)、更新(重心が動き、セルが付いていく)
|
|
307
|
+
if (pl.km){
|
|
308
|
+
var km = pl.km, cur = -1, cs = km[0].centroids, assign = null, showCells = 0;
|
|
309
|
+
steps.forEach(function(s, n){
|
|
310
|
+
var e = ph(n);
|
|
311
|
+
if (e <= 0) return;
|
|
312
|
+
if (s.kind === "assign"){ cur = s.i; cs = km[s.i].centroids; assign = km[s.i].assign; showCells = e; }
|
|
313
|
+
if (s.kind === "update"){ var a = km[s.i].centroids, b = km[s.i + 1].centroids; cs = a.map(function(c, j){ return [c[0] + (b[j][0] - c[0]) * e, c[1] + (b[j][1] - c[1]) * e]; }); showCells = 1; }
|
|
314
|
+
});
|
|
315
|
+
var first = ph(0) > 0 ? 1 : 0;
|
|
316
|
+
this.cEls.forEach(function(g, j){ var c = cs[j]; g.setAttribute("transform", "translate(" + G.X(c[0]).toFixed(1) + " " + G.Y(c[1]).toFixed(1) + ")"); g.setAttribute("opacity", first); });
|
|
317
|
+
this.kmCells.forEach(function(p, j){ var poly = cell(cs, j, G.rect); p.setAttribute("d", poly.length > 2 ? "M" + poly.map(function(v){ return G.X(v[0]).toFixed(1) + " " + G.Y(v[1]).toFixed(1); }).join("L") + "Z" : ""); p.setAttribute("opacity", showCells.toFixed(3)); });
|
|
318
|
+
this.ptEls.forEach(function(e, n){ e.setAttribute("style", "fill:" + (assign ? CLASS_COLORS[assign[n]] : "var(--muted)")); });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: A tall figure (SVG, HTML) in a fixed-height frame, scrolled to set places by step; viewers may scroll it
|
|
3
|
+
steps: largest child data-scroll-step
|
|
4
|
+
props:
|
|
5
|
+
dur: scroll seconds
|
|
6
|
+
margin: px above target
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
For a tall timeline, flow or code shown without splitting it.
|
|
10
|
+
|
|
11
|
+
Child of `<m-scroll style="height:440px" aria-label="name">`: the figure.
|
|
12
|
+
|
|
13
|
+
- `data-scroll-step="k"` on a child: step k scrolls it to the top
|
|
14
|
+
- Wheel, touch, ↑ ↓, PageUp/Down scroll the frame; ← → and Space move slides
|
|
15
|
+
- A hand-scrolled place stays until the next step
|
|
16
|
+
<!-- llm: omit -->
|
|
17
|
+
- `--line` border; outside is cut on purpose (`data-clip`). Video and print show the author's place.
|
|
18
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// m-scroll 2.0.0: puts a tall figure (inline SVG, HTML) in a frame of fixed height and moves it with the steps.
|
|
2
|
+
// <m-scroll style="height:440px"> … children … </m-scroll>: the children go into the frame as they are. A child with
|
|
3
|
+
// data-scroll-step="k" is the place the frame shows from step k on (k = 1, 2, …); steps = the largest k (the steps attribute
|
|
4
|
+
// wins). Inside the frame the wheel, touch, ↑ ↓ and PageUp / PageDown scroll the frame and do not move the slides; ← → and
|
|
5
|
+
// Space stay the player's. A viewer who scrolled by hand keeps their place until the next step (viewer input, spec §8.4);
|
|
6
|
+
// entering the slide again (ctx.entered) or a reset (ctx.reset) gives the frame back to the steps.
|
|
7
|
+
// Video (ctx.mode "video") and print show the author's place for the step. Under prefers-reduced-motion the player gives
|
|
8
|
+
// t = Infinity, so the frame jumps. The frame is cut on purpose (data-clip); the part draws nothing of its own.
|
|
9
|
+
// Origin: a student of the lab made it inside a progress-report file (scroll 0.1.0); taken in for 2.17 (handoff #66).
|
|
10
|
+
egatariParts.define({name: "scroll", version: "2.0.0", requires: {base: "1.3.0"}, element: "m-scroll"}, function(deps){
|
|
11
|
+
"use strict";
|
|
12
|
+
var base = deps.base;
|
|
13
|
+
var LINE = 40; // px per ↑ ↓; PageUp / PageDown move 0.9 of the frame
|
|
14
|
+
var CSS_ID = "scroll-2-0-0-css";
|
|
15
|
+
var CSS = [
|
|
16
|
+
"m-scroll{display:block;position:relative;overflow:hidden}",
|
|
17
|
+
"m-scroll .sc-frame{position:relative;height:100%;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;border:2px solid var(--line);border-radius:6px;box-sizing:border-box}",
|
|
18
|
+
"m-scroll .sc-frame:focus-visible{outline:3px solid var(--emph);outline-offset:-3px}",
|
|
19
|
+
"@media print{m-scroll .sc-frame{scrollbar-width:none}}",
|
|
20
|
+
].join("\n");
|
|
21
|
+
return class extends base.MotionElement {
|
|
22
|
+
static partName = "scroll";
|
|
23
|
+
static interactive = true; // the viewer can scroll the frame (docs/conventions.md §6)
|
|
24
|
+
static preview = "none"; // nothing lies ahead to show faint: the figure is all there, only its place changes
|
|
25
|
+
static viewerInput = true; // a place scrolled by hand is the viewer's state until the next step (spec §8.4)
|
|
26
|
+
// no JSON: the children are the figure. The example is how to write it (as m-sweep's attribute-only shape)
|
|
27
|
+
static shape = {schema: null, example: '<m-scroll style="height:440px" aria-label="年表"><svg viewBox="0 0 1000 1300" width="1000" height="1300">… <g data-scroll-step="1">…</g> …</svg></m-scroll>'};
|
|
28
|
+
static props = {
|
|
29
|
+
dur: {type: "number", default: 0.8, doc: "秒数:ステップが変わったときに枠が動く時間"},
|
|
30
|
+
margin: {type: "number", default: 12, doc: "px:data-scroll-step の要素の上に空ける余白"},
|
|
31
|
+
};
|
|
32
|
+
get steps(){
|
|
33
|
+
var a = this.getAttribute("steps");
|
|
34
|
+
if (a !== null) return +a;
|
|
35
|
+
var n = 0;
|
|
36
|
+
[].forEach.call(this.querySelectorAll("[data-scroll-step]"), function(e){
|
|
37
|
+
var k = parseInt(e.getAttribute("data-scroll-step"), 10);
|
|
38
|
+
if (k > n) n = k;
|
|
39
|
+
});
|
|
40
|
+
return n;
|
|
41
|
+
}
|
|
42
|
+
mount(ctx){
|
|
43
|
+
var doc = this.ownerDocument, self = this;
|
|
44
|
+
if (!doc.getElementById(CSS_ID)) {
|
|
45
|
+
var st = doc.createElement("style");
|
|
46
|
+
st.id = CSS_ID; st.textContent = CSS;
|
|
47
|
+
(doc.head || doc.documentElement).appendChild(st);
|
|
48
|
+
}
|
|
49
|
+
this.video = ctx.mode === "video";
|
|
50
|
+
var ja = /^ja\b/i.test(ctx.lang || "");
|
|
51
|
+
this.setAttribute("data-clip", ""); // what lies outside the frame is shown by scrolling (cut on purpose)
|
|
52
|
+
var fr = this._fr = doc.createElement("div");
|
|
53
|
+
fr.className = "sc-frame";
|
|
54
|
+
fr.setAttribute("data-clip", "");
|
|
55
|
+
fr.setAttribute("tabindex", "0");
|
|
56
|
+
fr.setAttribute("role", "region");
|
|
57
|
+
fr.setAttribute("aria-label", this.getAttribute("aria-label") || (ja ? "縦に送る図" : "Scrolling figure"));
|
|
58
|
+
[].slice.call(this.childNodes).forEach(function(n){ if (!(n.nodeType === 1 && n.localName === "script")) fr.appendChild(n); });
|
|
59
|
+
this.appendChild(fr);
|
|
60
|
+
var stop = function(e){ e.stopPropagation(); };
|
|
61
|
+
["wheel", "touchstart", "touchmove", "pointerdown", "click", "dblclick"].forEach(function(n){ fr.addEventListener(n, stop, {passive: true}); });
|
|
62
|
+
fr.addEventListener("keydown", function(e){
|
|
63
|
+
var d = e.key === "ArrowUp" ? -LINE : e.key === "ArrowDown" ? LINE
|
|
64
|
+
: e.key === "PageUp" ? -fr.clientHeight * 0.9 : e.key === "PageDown" ? fr.clientHeight * 0.9 : null;
|
|
65
|
+
if (d === null) return;
|
|
66
|
+
e.preventDefault(); e.stopPropagation();
|
|
67
|
+
fr.scrollBy({top: d, behavior: "auto"});
|
|
68
|
+
});
|
|
69
|
+
// scroll events come later than the write, so a flag cannot tell the steps' scroll from the viewer's:
|
|
70
|
+
// a place more than 2 px from the one the steps wrote is the viewer's
|
|
71
|
+
fr.addEventListener("scroll", function(){
|
|
72
|
+
if (!self.video && (self._expect === undefined || Math.abs(fr.scrollTop - self._expect) > 2)) self._user = true;
|
|
73
|
+
}, {passive: true});
|
|
74
|
+
var view = doc.defaultView;
|
|
75
|
+
if (view) view.addEventListener("beforeprint", function(){ self._user = false; if (self._k !== undefined) self.place(self._at(self._k)); });
|
|
76
|
+
}
|
|
77
|
+
// the scrollTop that shows the element of step k, or null when no child has data-scroll-step="k"
|
|
78
|
+
_target(k){
|
|
79
|
+
var fr = this._fr, a = fr.querySelector('[data-scroll-step="' + k + '"]');
|
|
80
|
+
if (!a) return null;
|
|
81
|
+
// the slide's scale from the border box (getBoundingClientRect and offsetHeight both include the border)
|
|
82
|
+
var r = fr.getBoundingClientRect(), s = fr.offsetHeight ? r.height / fr.offsetHeight : 1;
|
|
83
|
+
var top = (a.getBoundingClientRect().top - r.top) / (s || 1) - fr.clientTop + fr.scrollTop - this.props.margin;
|
|
84
|
+
return Math.round(Math.max(0, Math.min(top, fr.scrollHeight - fr.clientHeight)));
|
|
85
|
+
}
|
|
86
|
+
// the place for step k: the element of the largest step ≤ k, else the top (so the result does not depend on the call order)
|
|
87
|
+
_at(k){
|
|
88
|
+
for (var j = k; j >= 1; j--) { var y = this._target(j); if (y !== null) return y; }
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
place(y){ this._expect = y; this._fr.scrollTop = y; }
|
|
92
|
+
duration(k){ return k >= 1 ? this.props.dur : 0; }
|
|
93
|
+
render(k, t, ctx){
|
|
94
|
+
if (!this._fr) return;
|
|
95
|
+
if (ctx && (ctx.entered === true || ctx.reset)) this._user = false;
|
|
96
|
+
if (this._k !== k) { this._k = k; this._user = false; } // a new step takes the frame back
|
|
97
|
+
if (this._user) return;
|
|
98
|
+
var to = this._at(k), from = k >= 1 ? this._at(k - 1) : to;
|
|
99
|
+
// whole pixels: a fractional scrollTop can land a few px apart depending on the call order
|
|
100
|
+
this.place(Math.round(base.lerp(from, to, base.prog(t, 0, this.props.dur))));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Scatter plot; point series by step, then a trend line (least squares or 2 points)
|
|
3
|
+
steps: series + trend (default 1 series = 1 step, lines 1 step)
|
|
4
|
+
props:
|
|
5
|
+
xr: x range
|
|
6
|
+
yr: y range
|
|
7
|
+
xt: x ticks
|
|
8
|
+
yt: y ticks
|
|
9
|
+
xf: x tick decimals
|
|
10
|
+
yf: y tick decimals
|
|
11
|
+
xl: x title
|
|
12
|
+
yl: y title
|
|
13
|
+
r: point radius px
|
|
14
|
+
dur: step seconds
|
|
15
|
+
example: {"series": [{"label": "Sunny", "points": [[24, 210], [28, 380], [31, 560], {"x": 34, "y": 690, "label": "Heatwave"}]}], "trend": "linear"}
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
Relation of two quantities (heat vs sales). Points, then trend.
|
|
19
|
+
|
|
20
|
+
Child JSON: `{"series": [...], "trend": ...}`.
|
|
21
|
+
|
|
22
|
+
- series: `points` (`[x, y]` or `{"x", "y", "label", "anchor", "tone"}`), `label` (series name, top with marker), `tone` (`term` `emph` `accent2` `muted` `fg` `series-1..4`), `step` (1 series = 1 step; same = together), `at` (start s)
|
|
23
|
+
- Point `label` placed clear of overlaps (`anchor` = first try: `right` `left` `above` `below`); outliers only
|
|
24
|
+
- Marker shape per series; repeats after 4, so ≤ 4 series
|
|
25
|
+
- trend: `"linear"` (least squares on all points), or `{"fit": "linear", "series": 0, "label", "tone", "dash", "step", "at", "digits"}`, or `{"pts": [[x0, y0], [x1, y1]]}` (segment; exactly 2 points; vertical OK); several = array
|
|
26
|
+
- `series`: fitted series index from 0, or array (default all)
|
|
27
|
+
- `label`: `{r}` correlation, `{a}` slope, `{b}` intercept (`digits`, default 2), e.g. `"Trend (r = {r})"`
|
|
28
|
+
- `step`: default after the last series
|
|
29
|
+
- Clipped to the plot; lines outside reported. Vertical `pts`: `{a}` `{b}` empty; `{r}` only for fits
|
|
30
|
+
- Axes: `xr` `yr` range, `xt` `yt` ticks, `xf` `yf` decimals, `xl` `yl` titles; range/ticks auto if omitted
|
|
31
|
+
- `variant`: `fade`, `sweep`, `grow`
|
|
32
|
+
- Show later steps faintly (`ctx.preview`): later points and lines faint
|
|
33
|
+
|
|
34
|
+
The demo is `demo.html`. All numbers are fictional.
|
|
35
|
+
|
|
36
|
+
<!-- llm: omit -->
|
|
37
|
+
Notes
|
|
38
|
+
|
|
39
|
+
- Marker shapes: circle, square, triangle, diamond (colour not relied on); repeat after 4. Point labels try right → left → above → below
|
|
40
|
+
- Fits span the fitted x range, `pts` the 2 points
|
|
41
|
+
- Step length `dur` (default 1 s): points in 0.7 s, then point and series names; line names after the line is drawn
|
|
42
|
+
- `sweep` only orders points; `grow` only scales them; nothing moves (conventions §1.2). No rise-from-below variant: it would move more than variant 0
|
|
43
|
+
- Text width estimated from characters; no room for a name is reported (`ctx.report`)
|
|
44
|
+
<!-- llm: end -->
|