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,205 @@
|
|
|
1
|
+
// m-sweep:パラメータを動かして関数の形の変化を見せる。前の形は灰色で残す
|
|
2
|
+
// <m-sweep f="u*u + c*u*u*u + c*c*u**4" values="[0,0.5,1]" xr="[-3,3]" yr="[0,16]" xt="[-2,0,2]" yt="[0,5,10,15]"
|
|
3
|
+
// xl="*u*" yl="損失" param="c" style="height:380px"></m-sweep>
|
|
4
|
+
// 段階 k(1〜values.length-1)で、値を values[k-1] から values[k] へ動かす。at="[0.5, 3]" なら変化をすべて段階 1 に入れ、
|
|
5
|
+
// i 番目の変化を at[i] 秒から始める。point='{"u": 9.8, "label": "平均待ち {y} 日"}' は u の所の曲線の上の点(値の変化について動く)
|
|
6
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity、plot の Plot、expr の compile を使い、
|
|
7
|
+
// プレイヤーのグローバルは使わない(1.x は式の評価器 egatari-expr を写して持っていた)
|
|
8
|
+
egatariParts.define({name: "sweep", version: "2.2.0", requires: {base: "1.3.0", expr: "1.0.0", plot: "1.1.3"}, element: "m-sweep"}, function(deps){
|
|
9
|
+
"use strict";
|
|
10
|
+
var base = deps.base, plot = deps.plot, expr = deps.expr;
|
|
11
|
+
// 関数 f を [a, b] で n 分割した点列(px)。有限でない値(NaN・±Infinity)の点は null
|
|
12
|
+
function samples(p, f, a, b, n){
|
|
13
|
+
var out = [];
|
|
14
|
+
for (var i = 0; i <= n; i++){ var v = a + (b - a) * i / n, x = p.x(v), y = p.y(f(v)); out.push(isFinite(x) && isFinite(y) ? [x, y] : null); }
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
// 点列の d。null の所で線を切り、次の有限な点から M で引き直す(plot の p.d と同じ字。切れ目がなければ同じ d)
|
|
18
|
+
function pathOf(pts){
|
|
19
|
+
var d = "", pen = false;
|
|
20
|
+
pts.forEach(function(q){ if (q){ d += (pen ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); pen = true; } else pen = false; });
|
|
21
|
+
return d;
|
|
22
|
+
}
|
|
23
|
+
// 線分 s = [[x, y], [x, y]] が箱 r = [x0, y0, x1, y1] にかかるか(Liang–Barsky)
|
|
24
|
+
function segHitsBox(s, r){
|
|
25
|
+
var x = s[0][0], y = s[0][1], dx = s[1][0] - x, dy = s[1][1] - y, t0 = 0, t1 = 1;
|
|
26
|
+
var pp = [-dx, dx, -dy, dy], qq = [x - r[0], r[2] - x, y - r[1], r[3] - y];
|
|
27
|
+
for (var i = 0; i < 4; i++){
|
|
28
|
+
if (pp[i] === 0){ if (qq[i] < 0) return false; continue; }
|
|
29
|
+
var u = qq[i] / pp[i];
|
|
30
|
+
if (pp[i] < 0){ if (u > t1) return false; if (u > t0) t0 = u; }
|
|
31
|
+
else { if (u < t0) return false; if (u < t1) t1 = u; }
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
// 灰色の線の名前の置き場所:その線のすぐ上か下に、どの線(自分の線も)にもかからないように置く(線の上に字を重ねない)。
|
|
36
|
+
// 候補は自分の線の描かれている点ごとに、字の箱を点の上・下(6 px 離す)、点を中心・左端・右端にした 6 通り。
|
|
37
|
+
// bd(字を置ける範囲)の中で、置いた字(boxes)に重ならず、線にかかる数が最も少なく(1 本 1000)、自分の線に近く、
|
|
38
|
+
// ほかの線から離れている所(40 px まで)。w は字の幅の見積もり、fs は字の大きさ。置けなければ null
|
|
39
|
+
function placeOn(own, w, fs, lines, boxes, bd, cl){
|
|
40
|
+
var best = null, bc = Infinity;
|
|
41
|
+
var hits = function(L, r){
|
|
42
|
+
var q = [Math.max(r[0], cl[0]), Math.max(r[1], cl[1]), Math.min(r[2], cl[2]), Math.min(r[3], cl[3])];
|
|
43
|
+
if (q[0] >= q[2] || q[1] >= q[3]) return false;
|
|
44
|
+
for (var i = 1; i < L.length; i++) if (L[i - 1] && L[i] && segHitsBox([L[i - 1], L[i]], q)) return true;
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
var near = function(L, r){
|
|
48
|
+
var g = 40;
|
|
49
|
+
L.forEach(function(z){ if (z && z[0] >= cl[0] && z[0] <= cl[2] && z[1] >= cl[1] && z[1] <= cl[3]) g = Math.min(g, Math.hypot(Math.max(r[0] - z[0], 0, z[0] - r[2]), Math.max(r[1] - z[1], 0, z[1] - r[3]))); });
|
|
50
|
+
return g;
|
|
51
|
+
};
|
|
52
|
+
for (var j = 0; j < own.length; j += 3){
|
|
53
|
+
var q = own[j];
|
|
54
|
+
if (!q || q[0] < cl[0] || q[0] > cl[2] || q[1] < cl[1] || q[1] > cl[3]) continue; // 描かれている点だけ
|
|
55
|
+
[-1, 1].forEach(function(side){
|
|
56
|
+
[0.5, 0, 1].forEach(function(f){
|
|
57
|
+
// side −1:箱の下の端が点の 6 px 上。+1:箱の上の端が点の 6 px 下。f:点が箱の横の何割の所か
|
|
58
|
+
var y = side < 0 ? q[1] - 6 - fs * 0.22 : q[1] + 6 + fs * 0.88, x0 = q[0] - w * f;
|
|
59
|
+
var r = [x0, y - fs * 0.88, x0 + w, y + fs * 0.22];
|
|
60
|
+
if (r[0] < bd[0] || r[2] > bd[2] || r[1] < bd[1] || r[3] > bd[3]) return;
|
|
61
|
+
if (boxes.some(function(b){ return r[0] < b[2] + 6 && b[0] < r[2] + 6 && r[1] < b[3] + 4 && b[1] < r[3] + 4; })) return;
|
|
62
|
+
var c = 0, r3 = [r[0] - 3, r[1] - 3, r[2] + 3, r[3] + 3], gap = 40;
|
|
63
|
+
lines.forEach(function(L){ if (hits(L, r3)) c += 1000; else if (L !== own) gap = Math.min(gap, near(L, r)); });
|
|
64
|
+
if (hits(own, r3) && lines.indexOf(own) < 0) c += 1000;
|
|
65
|
+
c += 40 - gap + (f === 0.5 ? 0 : 2);
|
|
66
|
+
if (c < bc){ bc = c; best = {x: x0 + w / 2, y: y, box: r, hits: Math.floor(c / 1000)}; }
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return best;
|
|
71
|
+
}
|
|
72
|
+
return class extends base.MotionElement {
|
|
73
|
+
static partName = "sweep"; // the registry name (define meta name), for report prefixes
|
|
74
|
+
// データの形(kit/shape.js):JSON の子はなく、属性で書く(values は数の配列、2 つ以上)
|
|
75
|
+
static shape = {schema: null, example: '<m-sweep f="u*u + c*u" values="[0,0.5,1]" xr="[-3,3]" yr="[0,10]"></m-sweep>'};
|
|
76
|
+
static props = {
|
|
77
|
+
f: {type: "string", default: "u*u", doc: "関数の式(算術の式。変数は横軸 u とパラメータ c。Math.exp(…) などの Math の関数と定数、+ - * / % **、比較と ? : が使える)"},
|
|
78
|
+
values: {type: "json", default: [0, 1], doc: "パラメータの値の列。ステップごとに次の値へ動く", shape: {type: "array", items: {type: "number"}, minItems: 2}, example: [0, 0.5, 1]},
|
|
79
|
+
param: {type: "string", default: "c", doc: "表示するパラメータの名前"},
|
|
80
|
+
xr: {type: "json", default: [-3, 3]}, yr: {type: "json", default: [0, 10]},
|
|
81
|
+
xt: {type: "json", default: []}, yt: {type: "json", default: []},
|
|
82
|
+
xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
|
|
83
|
+
digits: {type: "number", default: 2, doc: "表示する値の小数の桁数"},
|
|
84
|
+
at: {type: "json", default: null, doc: "変化ごとの開始秒(増える順)。あれば全部をステップ 1 で", shape: {type: "array", items: {type: "number"}}, example: [0.5, 3]},
|
|
85
|
+
point: {type: "json", default: null, doc: "曲線上の点 {u, label({y} = 値), digits}", shape: {type: "object", properties: {u: {type: "number"}, label: {type: "string"}, digits: {type: "number"}}, required: ["u"]}, example: {u: 9.8, label: "平均待ち {y} 日", digits: 1}},
|
|
86
|
+
dur: {type: "number", default: 1.2, doc: "1 ステップの動きの秒数"},
|
|
87
|
+
size: {type: "number", default: 0, doc: "字の大きさ(24 以上。0 = 既定)"},
|
|
88
|
+
};
|
|
89
|
+
get steps(){ return this.getAttribute("steps") !== null ? +this.getAttribute("steps") : this.ats ? 1 : this.props.values.length - 1; }
|
|
90
|
+
// at のときの変化の開始秒(なければ null)。数でない・数が合わない・減る列は知らせて、段階ごとの動きに戻す
|
|
91
|
+
get ats(){
|
|
92
|
+
var A = this.props.at, n = this.props.values.length - 1;
|
|
93
|
+
if (A === null || A === undefined) return null;
|
|
94
|
+
if (!Array.isArray(A) || A.length !== n || A.some(function(x, i){ return typeof x !== "number" || !isFinite(x) || x < 0 || (i > 0 && x < A[i - 1]); })) return null;
|
|
95
|
+
return A;
|
|
96
|
+
}
|
|
97
|
+
mount(ctx){
|
|
98
|
+
var P = this.props, D = base, self = this;
|
|
99
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
100
|
+
// 式は木にしてから計算する(コードとしては実行しない。Egatari spec §6)。書けない式は SyntaxError で、base が受け止めて札を出す(spec §6.1 Containment)
|
|
101
|
+
var g = expr.compile(P.f, {name: "f", vars: ["u", "c"]});
|
|
102
|
+
this.g = function(c){ return function(u){ return g(u, c); }; };
|
|
103
|
+
// size:字の大きさ(24 未満は 24 にして知らせる)。0 なら 2.0 と同じ大きさと余白
|
|
104
|
+
var S = P.size > 0 ? Math.max(24, P.size) : 0, k = S ? S / 26 : 1;
|
|
105
|
+
if (P.size > 0 && P.size < 24) ctx.report("attr", "[sweep] size " + P.size + " is under 24 px; 24 is used");
|
|
106
|
+
this.fs = {lab: S ? Math.round(S * 1.04) : 27, ghost: S ? Math.max(24, Math.round(S * 0.92)) : 24, pt: S || 26};
|
|
107
|
+
var p = this.p = plot.Plot(this, {xr: P.xr, yr: P.yr, xt: P.xt, yt: P.yt, xl: P.xl, yl: P.yl, fs: S || undefined, m: {l: Math.round(86 * k), r: 10, t: Math.round(40 * k), b: Math.round(64 * k)}});
|
|
108
|
+
this.ghosts = P.values.map(function(){ return D.el("path", {fill: "none", stroke: "var(--line)", "stroke-width": 2.5, "clip-path": p.clip, opacity: 0}, p.svg); });
|
|
109
|
+
// 有限でない値のある線は、その所で切って引き、値ごとに 1 回知らせる
|
|
110
|
+
var pts = P.values.map(function(v, i){
|
|
111
|
+
var q = samples(p, self.g(v), P.xr[0], P.xr[1], 300);
|
|
112
|
+
self.ghosts[i].setAttribute("d", pathOf(q));
|
|
113
|
+
if (q.indexOf(null) >= 0) ctx.report("data", "[sweep] f is not a finite number (NaN or ±Infinity) at some u for " + P.param + " = " + v + "; the line is broken there");
|
|
114
|
+
return q;
|
|
115
|
+
});
|
|
116
|
+
this.cur = D.el("path", {fill: "none", stroke: "var(--emph)", "stroke-width": 3.5, "clip-path": p.clip}, p.svg);
|
|
117
|
+
// 縦軸の範囲を書かなかったとき(既定の [0, 10])に線が範囲の外に出るなら、値ごとに知らせる(m-curves 2.3.1 と同じ。書いた範囲で切るのは意図とみなし、知らせない)
|
|
118
|
+
if (!this.hasAttribute("yr")) P.values.forEach(function(v){
|
|
119
|
+
var lo = Math.min(P.yr[0], P.yr[1]), hi = Math.max(P.yr[0], P.yr[1]), tol = (hi - lo) * 1e-9, vs = [];
|
|
120
|
+
for (var j = 0; j <= 300; j++){ var y = self.g(v)(P.xr[0] + (P.xr[1] - P.xr[0]) * j / 300); if (typeof y === "number" && isFinite(y)) vs.push(y); }
|
|
121
|
+
var out = vs.filter(function(y){ return y < lo - tol || y > hi + tol; });
|
|
122
|
+
if (out.length) ctx.report("range", "[sweep] " + P.param + " = " + v + ": " + out.length + " of " + vs.length + " points are outside yr " + JSON.stringify(P.yr) + " (the default; values from " + +Math.min.apply(null, vs).toPrecision(4) + " to " + +Math.max.apply(null, vs).toPrecision(4) + "), so the line is cut at the edge. Write yr to cover them");
|
|
123
|
+
});
|
|
124
|
+
if (P.at !== null && P.at !== undefined && !this.ats) ctx.report("attr", "[sweep] at must be " + (P.values.length - 1) + " non-negative seconds in increasing order (one per change); each change gets its own step instead");
|
|
125
|
+
var A = this.ats; if (A) for (var j = 1; j < A.length; j++) if (A[j] < A[j - 1] + P.dur) { ctx.report("attr", "[sweep] change " + (j + 1) + " starts at " + A[j] + " s, before change " + j + " ends (" + (A[j - 1] + P.dur) + " s); it takes over from there"); break; }
|
|
126
|
+
// 曲線の上の点:u の所の f。値ごとに図の中にあるか確かめる(外なら知らせて、その間は点と字を隠す)
|
|
127
|
+
this.pt = null;
|
|
128
|
+
if (P.point !== null && P.point !== undefined){
|
|
129
|
+
var pt = P.point;
|
|
130
|
+
if (!pt || typeof pt !== "object" || typeof pt.u !== "number" || !isFinite(pt.u)) ctx.report("attr", "[sweep] point needs a number u (where on the curve)");
|
|
131
|
+
else {
|
|
132
|
+
if (pt.u < Math.min(P.xr[0], P.xr[1]) || pt.u > Math.max(P.xr[0], P.xr[1])) ctx.report("range", "[sweep] point.u = " + pt.u + " is outside xr");
|
|
133
|
+
P.values.forEach(function(v){ var y = self.g(v)(pt.u); if (!isFinite(y) || y < Math.min(P.yr[0], P.yr[1]) || y > Math.max(P.yr[0], P.yr[1])) ctx.report("range", "[sweep] the point at u = " + pt.u + " is " + (isFinite(y) ? y : "not a number") + " for " + P.param + " = " + v + ", outside yr (hidden there)"); });
|
|
134
|
+
this.pt = {u: pt.u, label: typeof pt.label === "string" ? pt.label : "", digits: typeof pt.digits === "number" ? pt.digits : P.digits,
|
|
135
|
+
dot: D.el("circle", {r: 9, fill: "var(--emph)", stroke: "var(--bg)", "stroke-width": 3}, p.svg),
|
|
136
|
+
text: D.el("text", {fill: "var(--emph)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": this.fs.pt}, p.svg)};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.lab = D.mtext(p.svg, p.m.l + 10, Math.round(30 * k), "", {fill: "var(--emph)", "font-size": this.fs.lab});
|
|
140
|
+
// 灰色の線の名前(「σ = 0.5」):最後の段階で残る線(最後の値と違う値。同じ値は最初の 1 本)に、--muted の 24px で線の上に(背景色で縁取って)書く。
|
|
141
|
+
// 5 本以上なら最初と最後だけ。置き場所は最後の段階の形(今の線と灰色の線)で決め、灰色の線が見えている間だけ出す
|
|
142
|
+
var V = P.values, L = V.length - 1, fs = this.fs.ghost, wOf = function(str){ return D.textWidth(str, fs, {font: self, mark: true}); }; // base の textWidth(記法の * _ ^ を除く)
|
|
143
|
+
var shown = [];
|
|
144
|
+
V.forEach(function(v, i){ if (i < L && v !== V[L] && V.indexOf(v) === i) shown.push(i); });
|
|
145
|
+
if (shown.length > 4) shown = [shown[0], shown[shown.length - 1]];
|
|
146
|
+
var LS = this.fs.lab, LY = Math.round(30 * k), lw = 0; V.forEach(function(v){ lw = Math.max(lw, wOf(P.param + " = " + v.toFixed(P.digits)) * LS / fs); });
|
|
147
|
+
var boxes = [[p.m.l + 10, LY - LS * 0.88, p.m.l + 10 + lw, LY + LS * 0.22]];
|
|
148
|
+
// 曲線の上の点の字(最後の値の所)にも灰色の線の名前をかけない
|
|
149
|
+
if (this.pt){ var fa = this.ptAt(V[L]); if (fa.inside && fa.str) boxes.push(fa.box); }
|
|
150
|
+
var lines = [pts[L]].concat(V.map(function(v, i){ return i < L && v !== V[L] ? pts[i] : null; }).filter(Boolean));
|
|
151
|
+
// 字は図の中か上の余白に(横軸の目盛りの数字にはかからない)。線は clip の中だけ描かれる
|
|
152
|
+
var bd = [p.m.l + 4, 4, p.W - p.m.r, p.H - p.m.b - 2], cl = [p.m.l, p.m.t - 4, p.W - p.m.r, p.H - p.m.b];
|
|
153
|
+
this.glabs = [];
|
|
154
|
+
shown.forEach(function(i){
|
|
155
|
+
var str = P.param + " = " + V[i].toFixed(P.digits), at = placeOn(pts[i], wOf(str), fs, lines, boxes, bd, cl);
|
|
156
|
+
if (!at){ ctx.report("layout", "[sweep] no free place for the name of the grey line " + JSON.stringify(str) + " (not drawn)"); return; }
|
|
157
|
+
if (at.hits) ctx.report("layout", "[sweep] the name of the grey line " + JSON.stringify(str) + " crosses a line (no free place beside it); give the element more room or a shorter param");
|
|
158
|
+
boxes.push(at.box);
|
|
159
|
+
self.glabs.push({i: i, el: D.mtext(p.svg, +at.x.toFixed(1), +at.y.toFixed(1), str, {"text-anchor": "middle", fill: "var(--muted)", stroke: "var(--bg)", "stroke-width": 6, "paint-order": "stroke", "font-size": fs, opacity: 0})});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
// 曲線の上の点の置き場所(値 c のとき):点、字({y} を今の値に)、字の箱。字は点の右上、図の右端に近ければ左上。図の外なら inside = false
|
|
163
|
+
ptAt(c){
|
|
164
|
+
var q = this.pt, P = this.props, p = this.p, y = this.g(c)(q.u), inside = isFinite(y) && y >= Math.min(P.yr[0], P.yr[1]) && y <= Math.max(P.yr[0], P.yr[1]);
|
|
165
|
+
var X = p.x(q.u), Y = inside ? p.y(y) : 0, str = q.label.replace(/\{y\}/g, inside ? y.toFixed(q.digits) : "");
|
|
166
|
+
var F = this.fs.pt, w = base.textWidth(str, F, {font: this}), right = X + 14 + w <= p.W - p.m.r, tx = right ? X + 14 : X - 14, ty = Math.max(p.m.t + F * 0.8, Y - 14);
|
|
167
|
+
return {inside: inside, X: X, Y: Y, str: str, tx: tx, ty: ty, anchor: right ? "start" : "end", box: [right ? tx : tx - w, ty - F * 0.88, right ? tx + w : tx, ty + F * 0.22]};
|
|
168
|
+
}
|
|
169
|
+
duration(k){ var A = this.ats; return k >= 1 ? (A ? A[A.length - 1] + this.props.dur : this.props.dur) : 0; }
|
|
170
|
+
// 変化の始まり(at のとき):口述原稿の {cue} に合わせる同期点
|
|
171
|
+
cues(k){ var A = this.ats; return A && k === 1 ? A.slice() : null; }
|
|
172
|
+
render(k, t, ctx){
|
|
173
|
+
var P = this.props, V = P.values, preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 0;
|
|
174
|
+
// 先を薄く見せる表示:後の段階で動いていく先の値の線を、強調の色でテーマの --preview-opacity(なければ 0.45)で描く
|
|
175
|
+
// pos:始まった変化の数(灰色の線と先を見せる線の境)。at なら段階 1 の中の秒で、なければ段階で決まる
|
|
176
|
+
var A = this.ats, c, pos;
|
|
177
|
+
if (A){
|
|
178
|
+
pos = 0; c = V[0];
|
|
179
|
+
if (k >= 1) for (var i = 0; i < A.length; i++) if (t >= A[i]){ pos = i + 1; c = base.lerp(V[i], V[i + 1], base.prog(t, A[i], P.dur)); }
|
|
180
|
+
} else {
|
|
181
|
+
var to = V[Math.min(k, V.length - 1)], from = k >= 1 ? V[k - 1] : to;
|
|
182
|
+
c = base.lerp(from, to, base.prog(t, 0, P.dur)); pos = Math.min(k, V.length - 1);
|
|
183
|
+
}
|
|
184
|
+
this.cur.setAttribute("d", pathOf(samples(this.p, this.g(c), P.xr[0], P.xr[1], 300)));
|
|
185
|
+
this.lab.textContent = P.param + " = " + c.toFixed(P.digits);
|
|
186
|
+
V.forEach(function(v, i){
|
|
187
|
+
var e = this.ghosts[i], ahead = preview && i > pos && v !== c, col = ahead ? "var(--emph)" : "var(--line)";
|
|
188
|
+
// style は base.el と同じ書き方で書く(style.stroke に代入すると "stroke: var(--x);" になり、作った直後と字が変わる)
|
|
189
|
+
e.setAttribute("style", "stroke:" + col + ";");
|
|
190
|
+
e.setAttribute("opacity", ahead ? PV : i < pos && v !== c ? 1 : 0);
|
|
191
|
+
}, this);
|
|
192
|
+
// 灰色の線の名前は、その線が灰色で見えている間だけ
|
|
193
|
+
this.glabs.forEach(function(o){ o.el.setAttribute("opacity", o.i < pos && V[o.i] !== c ? 1 : 0); });
|
|
194
|
+
// 曲線の上の点と、その字({y} は今の値)。字は点の右上、図の右端に近ければ左上。図の外の値なら隠す
|
|
195
|
+
var q = this.pt;
|
|
196
|
+
if (q){
|
|
197
|
+
var a = this.ptAt(c);
|
|
198
|
+
q.dot.setAttribute("cx", a.X.toFixed(1)); q.dot.setAttribute("cy", a.Y.toFixed(1)); q.dot.setAttribute("opacity", a.inside ? 1 : 0);
|
|
199
|
+
q.text.setAttribute("x", a.tx.toFixed(1)); q.text.setAttribute("y", a.ty.toFixed(1)); q.text.setAttribute("text-anchor", a.anchor);
|
|
200
|
+
if (q.text.textContent !== a.str) q.text.textContent = a.str;
|
|
201
|
+
q.text.setAttribute("opacity", a.inside && a.str ? 1 : 0);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Scatter plot; point series by step, then a trend line (least squares or 2 points)
|
|
3
|
+
steps: series + trend (default 1 series = 1 step, lines 1 step)
|
|
4
|
+
props:
|
|
5
|
+
xr: x range
|
|
6
|
+
yr: y range
|
|
7
|
+
xt: x ticks
|
|
8
|
+
yt: y ticks
|
|
9
|
+
xf: x tick decimals
|
|
10
|
+
yf: y tick decimals
|
|
11
|
+
xl: x title
|
|
12
|
+
yl: y title
|
|
13
|
+
r: point radius px
|
|
14
|
+
dur: step seconds
|
|
15
|
+
example: {"series": [{"label": "Sunny", "points": [[24, 210], [28, 380], [31, 560], {"x": 34, "y": 690, "label": "Heatwave"}]}], "trend": "linear"}
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
Relation of two quantities (heat vs sales). Points, then trend.
|
|
19
|
+
|
|
20
|
+
Child JSON: `{"series": [...], "trend": ...}`.
|
|
21
|
+
|
|
22
|
+
- series: `points` (`[x, y]` or `{"x", "y", "label", "anchor", "tone"}`), `label` (series name, top with marker), `tone` (`term` `emph` `accent2` `muted` `fg` `series-1..4`), `step` (1 series = 1 step; same = together), `at` (start s)
|
|
23
|
+
- Point `label` placed clear of overlaps (`anchor` = first try: `right` `left` `above` `below`); outliers only
|
|
24
|
+
- Marker shape per series; repeats after 4, so ≤ 4 series
|
|
25
|
+
- trend: `"linear"` (least squares on all points), or `{"fit": "linear", "series": 0, "label", "tone", "dash", "step", "at", "digits"}`, or `{"pts": [[x0, y0], [x1, y1]]}` (segment; exactly 2 points; vertical OK); several = array
|
|
26
|
+
- `series`: fitted series index from 0, or array (default all)
|
|
27
|
+
- `label`: `{r}` correlation, `{a}` slope, `{b}` intercept (`digits`, default 2), e.g. `"Trend (r = {r})"`
|
|
28
|
+
- `step`: default after the last series
|
|
29
|
+
- Clipped to the plot; lines outside reported. Vertical `pts`: `{a}` `{b}` empty; `{r}` only for fits
|
|
30
|
+
- Axes: `xr` `yr` range, `xt` `yt` ticks, `xf` `yf` decimals, `xl` `yl` titles; range/ticks auto if omitted
|
|
31
|
+
- `variant`: `fade` (default), `sweep` (left to right), `grow` (points grow, line from the middle)
|
|
32
|
+
- Show later steps faintly (`ctx.preview`): later points and lines faint
|
|
33
|
+
|
|
34
|
+
The demo is `demo.html`. All numbers are fictional.
|
|
35
|
+
|
|
36
|
+
<!-- llm: omit -->
|
|
37
|
+
Notes
|
|
38
|
+
|
|
39
|
+
- Marker shapes: circle, square, triangle, diamond (colour not relied on); repeat after 4. Point labels try right → left → above → below
|
|
40
|
+
- Fits span the fitted x range, `pts` the 2 points
|
|
41
|
+
- Step length `dur` (default 1 s): points in 0.7 s, then point and series names; line names after the line is drawn
|
|
42
|
+
- `sweep` only orders points; `grow` only scales them; nothing moves (conventions §1.2). No rise-from-below variant: it would move more than variant 0
|
|
43
|
+
- Text width estimated from characters; no room for a name is reported (`ctx.report`)
|
|
44
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// m-scatter:散布図。点の組(系列)を段階ごとに出し、そのあと傾向の線を引く
|
|
2
|
+
// <m-scatter xr="[20,36]" yr="[0,800]" xl="最高気温(℃)" yl="売上(個)" style="height:420px">
|
|
3
|
+
// <script type="application/json">{"series": [{"label": "晴れ", "points": [[24, 210], [31, 560]]}], "trend": "linear"}
|
|
4
|
+
// (JSON の終わり)</m-scatter>
|
|
5
|
+
// 段階:既定は系列 1 つ = 1 段階、そのあと傾向の線(全部で 1 段階)。系列・線の step で直接
|
|
6
|
+
// 軸の属性(xr yr xt yt xf yf xl yl)は m-curves と同じ名前と意味。xr / yr を書かなければデータから切りのよい範囲を決め、
|
|
7
|
+
// xt / yt を書かなければ目盛りも決める
|
|
8
|
+
// 見せ方(docs/conventions.md §1):fade(点がフェードして現れる、既定)・sweep(左から右へ順に現れる)・grow(点が小さい点から
|
|
9
|
+
// 大きくなる)。傾向の線は fade では薄く現れ、sweep では左から引き、grow では真ん中から両側へ伸びる。段階の数・長さ・最後の中身は同じ
|
|
10
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity と plot の Plot を使い、
|
|
11
|
+
// プレイヤーのグローバルは使わない。名前の置き場がない・傾向の線が軸の外・上の名前が図より広い、は ctx.report で知らせる
|
|
12
|
+
// (1.x は console.warn)
|
|
13
|
+
egatariParts.define({name: "scatter", version: "2.1.0", requires: {base: "1.3.0", plot: "1.1.3"}, element: "m-scatter"}, function(deps){
|
|
14
|
+
"use strict";
|
|
15
|
+
var base = deps.base, plot = deps.plot;
|
|
16
|
+
return class extends base.MotionElement {
|
|
17
|
+
static partName = "scatter"; // the registry name (define meta name), for report prefixes
|
|
18
|
+
static variants = ["fade", "sweep", "grow"];
|
|
19
|
+
// データの形(kit/shape.js)
|
|
20
|
+
static shape = (function(){
|
|
21
|
+
// 傾向の線の 2 点:ちょうど 2 つの [x, y]
|
|
22
|
+
var PTS = {type: "array", minItems: 2, maxItems: 2, items: {type: "array", minItems: 2, maxItems: 2, items: {type: "number"}}};
|
|
23
|
+
return {
|
|
24
|
+
schema: {type: "object", additionalProperties: false, required: ["series"], properties: {
|
|
25
|
+
series: {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["points"], properties: {
|
|
26
|
+
label: {type: "string"}, tone: {type: "string"}, step: {type: "integer"}, at: {type: "number"},
|
|
27
|
+
points: {type: "array", items: {type: ["array", "object"], items: {type: "number"}, minItems: 2, maxItems: 2, required: ["x", "y"],
|
|
28
|
+
properties: {x: {type: "number"}, y: {type: "number"}, label: {type: "string"}, anchor: {enum: ["right", "left", "above", "below", "top", "bottom"]}, tone: {type: "string"}}}}}}},
|
|
29
|
+
trend: {type: ["string", "object", "array"], properties: {fit: {enum: ["linear"]}, pts: PTS, series: {type: ["integer", "array"]},
|
|
30
|
+
label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"}, step: {type: "integer"}, at: {type: "number"}, digits: {type: "integer"}},
|
|
31
|
+
items: {type: "object", properties: {fit: {enum: ["linear"]}, pts: PTS, series: {type: ["integer", "array"]},
|
|
32
|
+
label: {type: "string"}, tone: {type: "string"}, dash: {type: "boolean"}, step: {type: "integer"}, at: {type: "number"}, digits: {type: "integer"}}}}}},
|
|
33
|
+
example: {series: [{label: "晴れ", points: [[24, 210], [28, 380], [31, 560], {x: 34, y: 690, label: "猛暑日"}]}], trend: "linear"},
|
|
34
|
+
note: {en: "points are [x, y] or {\"x\", \"y\", \"label\"}; axes go in attributes (xr=\"[0,10]\" xl=\"…\"); trend is \"linear\" or {\"fit\": \"linear\", \"label\": \"…\"} or {\"pts\": [[x0, y0], [x1, y1]]}",
|
|
35
|
+
ja: "点は [x, y] か {\"x\", \"y\", \"label\"}。軸は属性に書く(xr=\"[0,10]\" xl=\"…\")。trend は \"linear\" か {\"fit\": \"linear\", \"label\": \"…\"} か {\"pts\": [[x0, y0], [x1, y1]]}"},
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
static props = {
|
|
39
|
+
xr: {type: "json", default: null, doc: "横軸の範囲(書かなければデータから)"}, yr: {type: "json", default: null, doc: "縦軸の範囲(書かなければデータから)"},
|
|
40
|
+
xt: {type: "json", default: null, doc: "横軸の目盛り(書かなければ自動)"}, yt: {type: "json", default: null, doc: "縦軸の目盛り(書かなければ自動)"},
|
|
41
|
+
xf: {type: "number", default: undefined, doc: "横軸の目盛りの小数桁"}, yf: {type: "number", default: undefined, doc: "縦軸の目盛りの小数桁"},
|
|
42
|
+
xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
|
|
43
|
+
r: {type: "number", default: 9, doc: "点の半径(px)"},
|
|
44
|
+
dur: {type: "number", default: 1.0, doc: "1 ステップの動きの秒数"},
|
|
45
|
+
};
|
|
46
|
+
get steps(){
|
|
47
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
48
|
+
var m = 0, pl = this.plan();
|
|
49
|
+
pl.series.forEach(function(s){ m = Math.max(m, s.step); });
|
|
50
|
+
pl.trends.forEach(function(s){ m = Math.max(m, s.step); });
|
|
51
|
+
return m;
|
|
52
|
+
}
|
|
53
|
+
// 系列と傾向の線の段階(mount の前にも steps が要るので、データだけから決める)
|
|
54
|
+
plan(){
|
|
55
|
+
if (this._plan) return this._plan;
|
|
56
|
+
var d = this.data || {}, last = 0;
|
|
57
|
+
var series = (d.series || []).map(function(s, i){
|
|
58
|
+
var step = s.step !== undefined ? s.step : i + 1;
|
|
59
|
+
last = Math.max(last, step);
|
|
60
|
+
return {s: s, i: i, step: step, at: s.at || 0};
|
|
61
|
+
});
|
|
62
|
+
var tr = d.trend === undefined || d.trend === null || d.trend === false ? [] : Array.isArray(d.trend) ? d.trend : [d.trend];
|
|
63
|
+
var trends = tr.map(function(t, i){
|
|
64
|
+
if (typeof t === "string") t = {fit: t}; // "linear" のほかは mount で知らせる(steps の計算では投げない)
|
|
65
|
+
return {t: t, i: i, step: t.step !== undefined ? t.step : last + 1, at: t.at || 0};
|
|
66
|
+
});
|
|
67
|
+
return (this._plan = {series: series, trends: trends});
|
|
68
|
+
}
|
|
69
|
+
mount(ctx){
|
|
70
|
+
var P = this.props, D = base, self = this, pl = this.plan();
|
|
71
|
+
this.variant = base.variant(this);
|
|
72
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
73
|
+
// 字の幅(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
|
|
74
|
+
var est = function(s, size){ return D.textWidth(s, size, {font: self, mark: true}); };
|
|
75
|
+
var colorOf = function(c, i){
|
|
76
|
+
if (!c) return "var(--series-" + (i % 4 + 1) + ")";
|
|
77
|
+
return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(c) ? "var(--" + c + ")" : "var(--series-" + (i % 4 + 1) + ")";
|
|
78
|
+
};
|
|
79
|
+
// 点を {x, y, label, anchor, tone} にそろえる
|
|
80
|
+
var all = [];
|
|
81
|
+
pl.series.forEach(function(o){
|
|
82
|
+
o.pts = (o.s.points || []).map(function(q){ var p = Array.isArray(q) ? {x: +q[0], y: +q[1]} : {x: +q.x, y: +q.y, label: q.label, anchor: q.anchor, tone: q.tone}; all.push(p); return p; });
|
|
83
|
+
});
|
|
84
|
+
// 軸の範囲と目盛り:書かれていなければデータから切りのよい数に
|
|
85
|
+
var auto = function(vals, pad){
|
|
86
|
+
var lo = Math.min.apply(null, vals), hi = Math.max.apply(null, vals);
|
|
87
|
+
if (!isFinite(lo)) return [0, 1];
|
|
88
|
+
if (hi === lo){ hi += 1; lo -= 1; }
|
|
89
|
+
var st = tickStep((hi - lo) * (1 + 2 * pad)), a = Math.floor((lo - (hi - lo) * pad) / st) * st, b = Math.ceil((hi + (hi - lo) * pad) / st) * st;
|
|
90
|
+
if (lo >= 0 && a < 0) a = 0;
|
|
91
|
+
return [+a.toFixed(10), +b.toFixed(10)];
|
|
92
|
+
};
|
|
93
|
+
// 書かれた範囲は [小, 大] の 2 つの数のときだけ使う(1 つの数・逆向き・数でない、は知らせてデータから決める)
|
|
94
|
+
var range = function(name){
|
|
95
|
+
var v = P[name];
|
|
96
|
+
if (v === null || v === undefined) return null;
|
|
97
|
+
if (Array.isArray(v) && v.length === 2 && v.every(function(x){ return typeof x === "number" && isFinite(x); }) && v[0] < v[1]) return v;
|
|
98
|
+
ctx.report("attr", "[scatter] " + name + "=\"" + self.getAttribute(name) + "\" is not a range [low, high] of two numbers with low < high (the range is taken from the data)");
|
|
99
|
+
return null;
|
|
100
|
+
};
|
|
101
|
+
var xr = range("xr") || auto(all.map(function(p){ return p.x; }), 0.04), yr = range("yr") || auto(all.map(function(p){ return p.y; }), 0.06);
|
|
102
|
+
// 範囲の外の点は描かない(軸の外や枠の外に出さない)。系列ごとにまとめて知らせる
|
|
103
|
+
pl.series.forEach(function(o){
|
|
104
|
+
var outs = o.pts.filter(function(q){ return !(q.x >= xr[0] && q.x <= xr[1] && q.y >= yr[0] && q.y <= yr[1]); });
|
|
105
|
+
outs.forEach(function(q){ q.out = true; });
|
|
106
|
+
if (outs.length) ctx.report("data", "[scatter] " + outs.length + " point" + (outs.length > 1 ? "s" : "") + (o.s.label ? " of \"" + o.s.label + "\"" : " of series " + (o.i + 1)) + " lie outside xr/yr and are not drawn: " +
|
|
107
|
+
outs.slice(0, 3).map(function(q){ return "(" + q.x + ", " + q.y + ")"; }).join(", ") + (outs.length > 3 ? ", …" : "") + " (widen xr/yr or leave them out)");
|
|
108
|
+
});
|
|
109
|
+
var ticks = function(r){ var st = tickStep(r[1] - r[0]), out = []; for (var v = Math.ceil(r[0] / st - 1e-9) * st; v <= r[1] + st * 1e-6; v += st) out.push(+v.toFixed(10)); return out; };
|
|
110
|
+
var xt = P.xt || ticks(xr), yt = P.yt || ticks(yr);
|
|
111
|
+
var fmt = function(v, f){ return f !== undefined ? v.toFixed(f) : String(v); };
|
|
112
|
+
var named = pl.series.some(function(o){ return o.s.label; }) || pl.trends.some(function(o){ return o.t.label; });
|
|
113
|
+
var yw = Math.max.apply(null, yt.map(function(v){ return est(fmt(v, P.yf), 24); }).concat([0]));
|
|
114
|
+
var m = {l: Math.max(64, yw + 22 + (P.yl ? 40 : 0)), r: 24, t: named ? 72 : 20, b: P.xl ? 66 : 42};
|
|
115
|
+
var p = this.p = plot.Plot(this, {xr: xr, yr: yr, xt: xt, yt: yt, xf: P.xf, yf: P.yf, xl: P.xl, yl: P.yl, m: m});
|
|
116
|
+
p.svg.setAttribute("aria-hidden", "true");
|
|
117
|
+
// 軸の線(横軸と縦軸。目盛りの短い線は除く)に印を付ける(tools/test-components.mjs が字との交差を見る)
|
|
118
|
+
var axl = p.svg.querySelectorAll("g.axes > line");
|
|
119
|
+
for (var a = 0; a < Math.min(2, axl.length); a++) axl[a].setAttribute("class", "axis");
|
|
120
|
+
var W = p.W, H = p.H, x0 = m.l, x1 = W - m.r, y0 = m.t, y1 = H - m.b;
|
|
121
|
+
var gT = D.el("g", {}, p.svg), gP = D.el("g", {}, p.svg), gL = D.el("g", {}, p.svg);
|
|
122
|
+
var R = P.r;
|
|
123
|
+
if (!(typeof R === "number" && isFinite(R) && R > 0)){
|
|
124
|
+
ctx.report("attr", "[scatter] r=\"" + this.getAttribute("r") + "\" is not a positive number (the default radius 9 is used)");
|
|
125
|
+
R = 9;
|
|
126
|
+
}
|
|
127
|
+
// 系列の印の形:丸・四角・三角・ひし形(色だけに頼らない)
|
|
128
|
+
var shapes = [
|
|
129
|
+
function(r){ return "M" + r + ",0A" + r + "," + r + " 0 1,1 " + (-r) + ",0A" + r + "," + r + " 0 1,1 " + r + ",0Z"; },
|
|
130
|
+
function(r){ var s = r * 0.86; return "M" + (-s) + "," + (-s) + "H" + s + "V" + s + "H" + (-s) + "Z"; },
|
|
131
|
+
function(r){ var s = r * 1.2; return "M0," + (-s) + "L" + (s * 0.95).toFixed(2) + "," + (s * 0.62).toFixed(2) + "H" + (-s * 0.95).toFixed(2) + "Z"; },
|
|
132
|
+
function(r){ var s = r * 1.2; return "M0," + (-s) + "L" + s + ",0L0," + s + "L" + (-s) + ",0Z"; }];
|
|
133
|
+
// 置いた字と点の箱(重なりを避ける)
|
|
134
|
+
var boxes = [];
|
|
135
|
+
all.forEach(function(q){ if (!q.out) boxes.push({l: p.x(q.x) - R - 2, r: p.x(q.x) + R + 2, t: p.y(q.y) - R - 2, b: p.y(q.y) + R + 2, pt: q}); });
|
|
136
|
+
var hits = function(b, self2){ return boxes.some(function(o){ return o.pt !== self2 && b.l < o.r && o.l < b.r && b.t < o.b && o.t < b.b; }); };
|
|
137
|
+
this.series = pl.series.map(function(o){
|
|
138
|
+
var col = colorOf(o.s.tone, o.i), path = shapes[o.i % 4](R);
|
|
139
|
+
// marks for the geometry check (spec §8.4): each point is a mark, its name a label outside it; a trend line is an edge
|
|
140
|
+
var marks = o.pts.filter(function(q){ return !q.out; }).map(function(q, j){
|
|
141
|
+
var g = D.el("g", {"data-part": "mark", "data-part-id": "@s" + (o.i + 1) + "p" + (j + 1), transform: "translate(" + p.x(q.x).toFixed(1) + " " + p.y(q.y).toFixed(1) + ")", opacity: 0}, gP);
|
|
142
|
+
var c = q.tone ? colorOf(q.tone, o.i) : col;
|
|
143
|
+
var sh = D.el("path", {d: path, fill: c, "fill-opacity": 0.85, stroke: "var(--bg)", "stroke-width": 1.5}, g);
|
|
144
|
+
return {q: q, g: g, sh: sh, cx: p.x(q.x), cy: p.y(q.y)};
|
|
145
|
+
});
|
|
146
|
+
// 左から右の順(sweep)
|
|
147
|
+
var order = marks.slice().sort(function(u, v){ return u.cx - v.cx; });
|
|
148
|
+
order.forEach(function(mk, j){ mk.rank = order.length > 1 ? j / (order.length - 1) : 0; });
|
|
149
|
+
// 名前のある点:右 → 左 → 上 → 下(anchor があればそれを先に)の順に、点・字・軸と重ならず枠に収まる所へ
|
|
150
|
+
var labels = marks.filter(function(mk){ return mk.q.label; }).map(function(mk){
|
|
151
|
+
var w = est(mk.q.label, 24), cands = {
|
|
152
|
+
right: {x: mk.cx + R + 8, y: mk.cy + 8, a: "start", b: {l: mk.cx + R + 6, r: mk.cx + R + 10 + w, t: mk.cy - 14, b: mk.cy + 12}},
|
|
153
|
+
left: {x: mk.cx - R - 8, y: mk.cy + 8, a: "end", b: {l: mk.cx - R - 10 - w, r: mk.cx - R - 6, t: mk.cy - 14, b: mk.cy + 12}},
|
|
154
|
+
above: {x: mk.cx, y: mk.cy - R - 10, a: "middle", b: {l: mk.cx - w / 2 - 2, r: mk.cx + w / 2 + 2, t: mk.cy - R - 34, b: mk.cy - R - 4}},
|
|
155
|
+
below: {x: mk.cx, y: mk.cy + R + 28, a: "middle", b: {l: mk.cx - w / 2 - 2, r: mk.cx + w / 2 + 2, t: mk.cy + R + 4, b: mk.cy + R + 34}}};
|
|
156
|
+
var pref = ["right", "left", "above", "below"];
|
|
157
|
+
var an = {top: "above", bottom: "below"}[mk.q.anchor] || mk.q.anchor; // top / bottom は above / below の別名
|
|
158
|
+
if (an) pref = [an].concat(pref.filter(function(x){ return x !== an; }));
|
|
159
|
+
var inPlot = function(b){ return b.l >= x0 + 4 && b.r <= x1 && b.t >= y0 && b.b <= y1 - 4; };
|
|
160
|
+
var inBox = function(b){ return b.l >= 0 && b.r <= W && b.t >= 0 && b.b <= H; };
|
|
161
|
+
var pick = pref.filter(function(k){ return inPlot(cands[k].b) && !hits(cands[k].b, mk.q); })[0]
|
|
162
|
+
|| pref.filter(function(k){ return inBox(cands[k].b) && !hits(cands[k].b, mk.q); })[0];
|
|
163
|
+
if (!pick){ pick = pref.filter(function(k){ return inBox(cands[k].b); })[0] || pref[0]; ctx.report("layout", "[scatter] the label \"" + mk.q.label + "\" has no free place (it may overlap)"); }
|
|
164
|
+
var c = cands[pick];
|
|
165
|
+
boxes.push({l: c.b.l, r: c.b.r, t: c.b.t, b: c.b.b, pt: mk.q});
|
|
166
|
+
return D.mtext(gL, c.x, c.y, mk.q.label, {"data-part": "label", "data-part-id": mk.g.getAttribute("data-part-id"), "data-part-of": "mark", "data-part-at": "outside", "text-anchor": c.a, "font-size": 24, fill: mk.q.tone ? colorOf(mk.q.tone, o.i) : "var(--fg)", opacity: 0});
|
|
167
|
+
});
|
|
168
|
+
return {o: o, col: col, path: path, marks: marks, labels: labels};
|
|
169
|
+
});
|
|
170
|
+
// 傾向の線:最小二乗の直線(fit: "linear")か、2 点(pts)
|
|
171
|
+
this.trends = pl.trends.map(function(o, ti){
|
|
172
|
+
var t = o.t, a, b, r = null, xa, xb;
|
|
173
|
+
var ya, yb;
|
|
174
|
+
if (t.pts){
|
|
175
|
+
if (t.pts.length !== 2 || !t.pts.every(function(q){ return Array.isArray(q) && q.length === 2 && q.every(isFinite); }))
|
|
176
|
+
throw new Error("trend.pts: write two points [[x0, y0], [x1, y1]]");
|
|
177
|
+
xa = +t.pts[0][0]; xb = +t.pts[1][0]; ya = +t.pts[0][1]; yb = +t.pts[1][1];
|
|
178
|
+
if (xa === xb && ya === yb) throw new Error("trend.pts: the two points are the same (write two different points)");
|
|
179
|
+
// 書いた 2 点をそのまま端にする(縦の線なら傾きと切片はない)
|
|
180
|
+
if (xb !== xa){ a = (yb - ya) / (xb - xa); b = ya - a * xa; } else { a = null; b = null; }
|
|
181
|
+
} else {
|
|
182
|
+
if (t.fit !== undefined && t.fit !== "linear") throw new Error('trend: "' + t.fit + '" is not "linear" (write "linear", {"fit": "linear"} or {"pts": [[x0, y0], [x1, y1]]})');
|
|
183
|
+
var use = t.series === undefined ? pl.series : [].concat(t.series).map(function(i){ return pl.series[i]; }).filter(Boolean);
|
|
184
|
+
var q = [].concat.apply([], use.map(function(s){ return s.pts; }));
|
|
185
|
+
if (q.length < 2) throw new Error("trend: a linear fit needs two or more points");
|
|
186
|
+
var n = q.length, sx = 0, sy = 0;
|
|
187
|
+
q.forEach(function(v){ sx += v.x; sy += v.y; });
|
|
188
|
+
var mx = sx / n, my = sy / n, sxx = 0, sxy = 0, syy = 0;
|
|
189
|
+
q.forEach(function(v){ sxx += (v.x - mx) * (v.x - mx); sxy += (v.x - mx) * (v.y - my); syy += (v.y - my) * (v.y - my); });
|
|
190
|
+
a = sxx ? sxy / sxx : 0; b = my - a * mx;
|
|
191
|
+
r = sxx && syy ? sxy / Math.sqrt(sxx * syy) : 0;
|
|
192
|
+
xa = Math.min.apply(null, q.map(function(v){ return v.x; })); xb = Math.max.apply(null, q.map(function(v){ return v.x; }));
|
|
193
|
+
ya = a * xa + b; yb = a * xb + b;
|
|
194
|
+
}
|
|
195
|
+
var col = t.tone ? colorOf(t.tone, 0) : "var(--fg)";
|
|
196
|
+
var A = [p.x(xa), p.y(ya)], B = [p.x(xb), p.y(yb)], out = false;
|
|
197
|
+
// 図の枠の中に切る(Liang–Barsky。clip-path は使わない)
|
|
198
|
+
var u0 = 0, u1 = 1, dx = B[0] - A[0], dy = B[1] - A[1];
|
|
199
|
+
[[-dx, A[0] - x0], [dx, x1 - A[0]], [-dy, A[1] - y0], [dy, y1 - A[1]]].forEach(function(c){
|
|
200
|
+
if (c[0] === 0){ if (c[1] < 0) u1 = -1; return; }
|
|
201
|
+
var u = c[1] / c[0];
|
|
202
|
+
if (c[0] < 0) u0 = Math.max(u0, u); else u1 = Math.min(u1, u);
|
|
203
|
+
});
|
|
204
|
+
// 枠の外の線は描かない(名前も図の上に出さない)
|
|
205
|
+
if (u1 <= u0){ out = true; ctx.report("range", "[scatter] the trend line is outside the axes (it is not drawn)"); }
|
|
206
|
+
else { B = [A[0] + dx * u1, A[1] + dy * u1]; A = [A[0] + dx * u0, A[1] + dy * u0]; }
|
|
207
|
+
var line = D.el("path", {"data-part-line": "", d: "M0,0", fill: "none", stroke: col, "stroke-width": 3.5, "stroke-linecap": "round", opacity: 0},
|
|
208
|
+
D.el("g", {"data-part": "edge", "data-part-id": "trend" + (ti + 1), "data-part-from": "@trend", "data-part-to": "@trend"}, gT));
|
|
209
|
+
if (t.dash) line.setAttribute("stroke-dasharray", "12 9");
|
|
210
|
+
// 名前:{r} {a} {b} を相関係数・傾き・切片に置き換える(digits 桁、既定 2)
|
|
211
|
+
var dg = t.digits !== undefined ? t.digits : 2, num = function(v){ return v === null ? "" : (v < 0 ? "−" : "") + Math.abs(v).toFixed(dg); };
|
|
212
|
+
var text = String(t.label || "").replace(/\{r\}/g, num(r)).replace(/\{a\}/g, num(a)).replace(/\{b\}/g, num(b));
|
|
213
|
+
var len = Math.hypot(B[0] - A[0], B[1] - A[1]);
|
|
214
|
+
return {o: o, line: line, text: out ? "" : text, col: col, A: A, B: B, len: len, dash: !!t.dash, out: out, a: a};
|
|
215
|
+
});
|
|
216
|
+
// 系列と傾向の線の名前:図の上(右寄せ)に印と一緒に並べる(凡例の箱は作らない。点や線と重ならない)
|
|
217
|
+
var lx = x1, entries = this.series.filter(function(se){ return se.o.s.label; }).map(function(se){ return {it: se, text: se.o.s.label, col: se.col, path: se.path}; })
|
|
218
|
+
.concat(this.trends.filter(function(tr){ return tr.text; }).map(function(tr){ return {it: tr, text: tr.text, col: tr.col, line: true, dash: tr.dash}; }));
|
|
219
|
+
// 印を左、字をその右に置く(字の幅は見積もりなので、ずれは右端に出る)
|
|
220
|
+
entries.reverse().forEach(function(en){
|
|
221
|
+
var w = est(en.text, 24), sw = en.line ? 40 : 2 * R, sx = lx - w - 10 - sw;
|
|
222
|
+
var g = D.el("g", {opacity: 0}, gL);
|
|
223
|
+
if (en.line){
|
|
224
|
+
var ln = D.el("line", {x1: sx, x2: sx + sw, y1: 26, y2: 26, stroke: en.col, "stroke-width": 3.5, "stroke-linecap": "round"}, g);
|
|
225
|
+
if (en.dash) ln.setAttribute("stroke-dasharray", "10 7");
|
|
226
|
+
} else D.el("path", {d: en.path, fill: en.col, "fill-opacity": 0.85, transform: "translate(" + (sx + R).toFixed(1) + " 26)"}, g);
|
|
227
|
+
D.mtext(g, sx + sw + 10, 34, en.text, {"font-size": 24, "font-weight": 700, fill: en.col});
|
|
228
|
+
en.it.leg = g;
|
|
229
|
+
lx = sx - 32;
|
|
230
|
+
});
|
|
231
|
+
if (lx + 32 < 0) ctx.report("size", "[scatter] the names above the figure are wider than the figure");
|
|
232
|
+
// 読み上げ:最後の形(描いた点と傾向の線)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
233
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
234
|
+
this.setAttribute("role", "img");
|
|
235
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja")));
|
|
236
|
+
function tickStep(span){ var r = span / 5, e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e;
|
|
237
|
+
return (x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e; }
|
|
238
|
+
}
|
|
239
|
+
// 最後の形を 1 文で(読み上げの名前):「散布図(横:最高気温、縦:売上):12 点(晴れ 8 点、雨 4 点)、横 24〜34、縦 210〜690、
|
|
240
|
+
// 猛暑日 (34, 690)、傾向の線は右上がり(r = 0.93)」。範囲の外で描かない点は数えない
|
|
241
|
+
summary(ja){
|
|
242
|
+
var P = this.props, self = this, one = function(s){ return String(s || "").replace(/\s*\n\s*/g, " ").replace(/[*_^]/g, ""); };
|
|
243
|
+
var ax = [P.xl ? (ja ? "横:" : "x: ") + one(P.xl) : "", P.yl ? (ja ? "縦:" : "y: ") + one(P.yl) : ""].filter(Boolean).join(ja ? "、" : ", ");
|
|
244
|
+
var pts = [], ss = this.series.map(function(se){ se.marks.forEach(function(mk){ pts.push(mk.q); }); return {l: se.o.s.label, n: se.marks.length}; });
|
|
245
|
+
var cnt = function(n){ return ja ? n + " 点" : n + (n === 1 ? " point" : " points"); };
|
|
246
|
+
var out = [cnt(pts.length) + (ss.length > 1 && ss.some(function(x){ return x.l; }) ? (ja ? "(" : " (") + ss.map(function(x){ return (x.l ? one(x.l) + " " : "") + cnt(x.n); }).join(ja ? "、" : ", ") + (ja ? ")" : ")") : "")];
|
|
247
|
+
if (pts.length){
|
|
248
|
+
var mm = function(f){ var v = pts.map(f), lo = Math.min.apply(null, v), hi = Math.max.apply(null, v); return lo === hi ? String(lo) : lo + (ja ? "〜" : " to ") + hi; };
|
|
249
|
+
out.push((ja ? "横 " : "x ") + mm(function(q){ return q.x; }), (ja ? "縦 " : "y ") + mm(function(q){ return q.y; }));
|
|
250
|
+
}
|
|
251
|
+
pts.filter(function(q){ return q.label; }).slice(0, 6).forEach(function(q){ out.push(one(q.label) + " (" + q.x + ", " + q.y + ")"); });
|
|
252
|
+
this.trends.forEach(function(tr){
|
|
253
|
+
if (tr.out) return;
|
|
254
|
+
var dir = tr.a === null ? (ja ? "垂直" : "vertical") : tr.a > 0 ? (ja ? "右上がり" : "rising") : tr.a < 0 ? (ja ? "右下がり" : "falling") : (ja ? "水平" : "flat");
|
|
255
|
+
var ts = tr.o.t.series, sn = !tr.o.t.pts && ts !== undefined && [].concat(ts).length === 1 && self.series[[].concat(ts)[0]] ? self.series[[].concat(ts)[0]].o.s.label : "";
|
|
256
|
+
out.push((sn ? one(sn) + (ja ? "の" : ": ") : "") + (ja ? "傾向の線は" : "the trend line is ") + dir + (tr.text ? (ja ? "(" : " (") + one(tr.text) + (ja ? ")" : ")") : ""));
|
|
257
|
+
});
|
|
258
|
+
return (ja ? "散布図" : "Scatter plot") + (ax ? (ja ? "(" + ax + ")" : " (" + ax + ")") : "") + (ja ? ":" : ": ") + out.join(ja ? "、" : ", ");
|
|
259
|
+
}
|
|
260
|
+
duration(k){
|
|
261
|
+
var P = this.props, d = 0, pl = this.plan();
|
|
262
|
+
pl.series.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + P.dur); });
|
|
263
|
+
pl.trends.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + P.dur); });
|
|
264
|
+
return d;
|
|
265
|
+
}
|
|
266
|
+
cues(k){
|
|
267
|
+
var c = [], pl = this.plan();
|
|
268
|
+
pl.series.concat(pl.trends).forEach(function(o){ if (o.step === k && o.at > 0 && c.indexOf(o.at) < 0) c.push(o.at); });
|
|
269
|
+
return c.length ? c.sort(function(a, b){ return a - b; }) : null;
|
|
270
|
+
}
|
|
271
|
+
render(k, t, ctx){
|
|
272
|
+
var P = this.props, D = base, vr = this.variant, dur = P.dur, lecture = !!ctx.preview, FAINT = 0.45;
|
|
273
|
+
if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
274
|
+
// この部品の段階の中の時刻(-1 = まだ。授業の表示では先の段階を薄く見せる)
|
|
275
|
+
var local = function(o){ return o.step < k ? Infinity : o.step > k ? -1 : t - o.at; };
|
|
276
|
+
var faint = function(o){ return lecture && o.step > k; };
|
|
277
|
+
this.series.forEach(function(se){
|
|
278
|
+
var o = se.o, tt = local(o), f = faint(o), span = dur * 0.7;
|
|
279
|
+
se.marks.forEach(function(mk){
|
|
280
|
+
var op, sc = 1;
|
|
281
|
+
if (f){ op = FAINT; }
|
|
282
|
+
else if (tt < 0){ op = 0; }
|
|
283
|
+
else if (vr === "sweep"){ op = D.prog(tt, mk.rank * (span - 0.2), 0.2); }
|
|
284
|
+
else if (vr === "grow"){ sc = D.prog(tt, 0, span); op = sc > 0 ? Math.min(1, sc * 3) : 0; }
|
|
285
|
+
else { op = D.prog(tt, 0, span); }
|
|
286
|
+
mk.g.setAttribute("opacity", op.toFixed(3));
|
|
287
|
+
mk.g.setAttribute("transform", "translate(" + mk.cx.toFixed(1) + " " + mk.cy.toFixed(1) + ")" + (sc < 1 ? " scale(" + Math.max(0.001, sc).toFixed(4) + ")" : ""));
|
|
288
|
+
});
|
|
289
|
+
var lo = f ? FAINT : tt < 0 ? 0 : D.prog(tt, dur * 0.6, dur * 0.4);
|
|
290
|
+
se.labels.forEach(function(l){ l.setAttribute("opacity", lo.toFixed(3)); });
|
|
291
|
+
if (se.leg) se.leg.setAttribute("opacity", (f ? FAINT : tt < 0 ? 0 : D.prog(tt, 0, dur * 0.5)).toFixed(3));
|
|
292
|
+
});
|
|
293
|
+
this.trends.forEach(function(tr){
|
|
294
|
+
var o = tr.o, tt = local(o), f = faint(o), span = dur * 0.7, A = tr.A, B = tr.B, e = f ? 1 : tt < 0 ? 0 : D.prog(tt, 0, span);
|
|
295
|
+
var s0 = 0, s1 = 1, op = e > 0 ? 1 : 0;
|
|
296
|
+
if (!f && vr === "sweep"){ s1 = e; }
|
|
297
|
+
else if (!f && vr === "grow"){ s0 = 0.5 - e / 2; s1 = 0.5 + e / 2; }
|
|
298
|
+
else op = e;
|
|
299
|
+
tr.line.setAttribute("d", "M" + D.lerp(A[0], B[0], s0).toFixed(1) + "," + D.lerp(A[1], B[1], s0).toFixed(1) + "L" + D.lerp(A[0], B[0], s1).toFixed(1) + "," + D.lerp(A[1], B[1], s1).toFixed(1));
|
|
300
|
+
if (tr.dash) tr.line.setAttribute("stroke-dashoffset", (s0 * tr.len).toFixed(1));
|
|
301
|
+
tr.line.setAttribute("opacity", (tr.out ? 0 : f ? FAINT : op).toFixed(3));
|
|
302
|
+
if (tr.leg) tr.leg.setAttribute("opacity", (f ? FAINT : tt < 0 ? 0 : D.prog(tt, span, dur * 0.3)).toFixed(3));
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Bars grow from 0 by step (vertical, horizontal, grouped, stacked); the axis max can widen by step
|
|
3
|
+
steps: max group/scale step (default 1 group = 1 step)
|
|
4
|
+
props:
|
|
5
|
+
orient: v or h
|
|
6
|
+
max: axis max (0 = auto)
|
|
7
|
+
unit: value unit
|
|
8
|
+
digits: decimals
|
|
9
|
+
per-step: groups per step (0 = all)
|
|
10
|
+
dur: grow seconds
|
|
11
|
+
stagger: group offset (s)
|
|
12
|
+
count: count values up
|
|
13
|
+
ticks: ticks and grid
|
|
14
|
+
zoom: scale-change seconds
|
|
15
|
+
al: axis title
|
|
16
|
+
stack: stack values; "percent" = 100 %
|
|
17
|
+
mark: bar or dot (a point with its error bar)
|
|
18
|
+
example: {"series": [{"label": "Sales"}], "groups": [{"label": "Year 1", "value": 1.2}, {"label": "Year 2", "value": 3.4}]}
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
For quantities shown and compared one at a time: yearly sales, ranked answers, before/after.
|
|
22
|
+
|
|
23
|
+
Child JSON: `{"series": [...], "groups": [...], "scale": [...], "sig": [...]}`.
|
|
24
|
+
|
|
25
|
+
- group: `label` (`\n` = 2 lines), `value` or `values` (one per series), `step`, `at` (start s), `tone` (bar and value colour)
|
|
26
|
+
- err: ± number or `[low, high]`; per series for `values`
|
|
27
|
+
- sig: `[{"from": 0, "to": 2, "label": "**"}]` brackets groups 0 and 2 (`group`: series in a group); vertical, unstacked only
|
|
28
|
+
<!-- llm: omit -->
|
|
29
|
+
- Error bars and values appear once a bar is grown; values sit beyond the error bar's end. `mark="dot"` points appear without growing. Brackets stack from the shortest
|
|
30
|
+
<!-- llm: end -->
|
|
31
|
+
- series: `label` (2+ series: on the first group's bars; no legend), `tone` (default `--series-1..4`)
|
|
32
|
+
- scale: `[{"step": 3, "max": 27, "at": 0.4}]`: the max moves to `max` over `zoom` s; the old range stays as a faint band; taller bars stop at the top and grow as it widens
|
|
33
|
+
<!-- llm: omit -->
|
|
34
|
+
- Auto max: 1.12 × the largest value (before the first scale), rounded
|
|
35
|
+
<!-- llm: end -->
|
|
36
|
+
- `orient="h"`: names left, values right; `ticks="false"` for ranks
|
|
37
|
+
- `stack="true"` (`"percent"` = 100 %): a group's `values` in one bar; total at the end, values inside segments; values ≥ 0
|
|
38
|
+
<!-- llm: omit -->
|
|
39
|
+
- Values: `digits` decimals, thousands separators, `unit` appended
|
|
40
|
+
- Negatives (not stacked): the axis includes 0; bars grow down/left from a `--fg` baseline; values outside the bar end
|
|
41
|
+
- `stack="percent"`: axis 0–100 %, no `max`/`scale`, segment values in % when they fit, no total
|
|
42
|
+
- Show later steps faintly (`ctx.preview`): later bars fully grown at `--preview-opacity`; no axis change or over-max bar shown ahead
|
|
43
|
+
<!-- llm: end -->
|
|
44
|
+
|
|
45
|
+
The demo is `demo.html`. All numbers are fictional.
|
|
46
|
+
|
|
47
|
+
Notes
|
|
48
|
+
|
|
49
|
+
- Values appear once a bar is fully grown; `count="true"` counts them up
|
|
50
|
+
- Series names sit on the first group's bars: keep to 2–3 series
|
|
51
|
+
|
|
52
|
+
<!-- llm: omit -->
|
|
53
|
+
- `examples/tmlr2026-calibration` keeps its own deck-local `components/bars/`
|
|
54
|
+
<!-- llm: end -->
|