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.
Files changed (171) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/README.ja.md +14 -13
  3. package/README.md +2 -1
  4. package/components.lock.json +153 -54
  5. package/components2.lock.json +1001 -1
  6. package/kit/build.mjs +1 -1
  7. package/kit/check-messages.mjs +9 -0
  8. package/kit/check.mjs +8 -0
  9. package/kit/core/bookmark.mjs +28 -0
  10. package/kit/core/build-core.mjs +5 -3
  11. package/kit/core/check-parity.mjs +6 -0
  12. package/kit/core/check-rules.mjs +4 -3
  13. package/kit/core/check-source.mjs +10 -1
  14. package/kit/core/checks.mjs +79 -0
  15. package/kit/core/find-replace.mjs +170 -0
  16. package/kit/core/format.mjs +4 -1
  17. package/kit/core/image-insert.mjs +197 -0
  18. package/kit/core/image-size.mjs +1 -1
  19. package/kit/core/layout-scan.mjs +1 -1
  20. package/kit/core/llm-fix.mjs +1 -1
  21. package/kit/core/llm-pack-assemble.mjs +40 -67
  22. package/kit/core/llm-pack-data.mjs +882 -52
  23. package/kit/core/llm-pack.mjs +6 -4
  24. package/kit/core/llm-request.mjs +2 -2
  25. package/kit/core/new-deck-pack.mjs +38 -44
  26. package/kit/core/new-deck.mjs +82 -74
  27. package/kit/core/part-labels.mjs +3 -0
  28. package/kit/core/portable.mjs +5 -2
  29. package/kit/core/purposes.mjs +9 -3
  30. package/kit/core/sample-info.mjs +17 -3
  31. package/kit/core/scorm.mjs +30 -6
  32. package/kit/core/script-unclosed.mjs +49 -0
  33. package/kit/core/slide-ops.mjs +27 -1
  34. package/kit/core/tate-mix.mjs +25 -0
  35. package/kit/core/template-text.mjs +2 -0
  36. package/kit/core/theme-derive.mjs +56 -17
  37. package/kit/core/theme-shapes.mjs +15 -1
  38. package/kit/deck.js +124 -6
  39. package/kit/instruction-version.json +1 -1
  40. package/kit/layouts.css +8 -0
  41. package/kit/llm-pack.mjs +5 -7
  42. package/kit/panes.js +17 -1
  43. package/kit/player.json +1 -1
  44. package/kit/player.lock.json +2 -2
  45. package/kit/presenter.js +36 -4
  46. package/kit/tools.js +54 -2
  47. package/kit/track.js +46 -5
  48. package/package.json +1 -1
  49. package/server/editor-ui.js +21 -1
  50. package/vendor/components/CATALOG.md +25 -22
  51. package/vendor/components/sha256/038f9d32c89c8212ab25d6e3180023b6fe024a53053ab2ef1443ecab92e3ce43/index.js +205 -0
  52. package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/README.en.md +44 -0
  53. package/vendor/components/sha256/07479cb6e5194a01b2a8a9029f3646060f0dbb673f2737d2132738af2eb379e5/index.js +306 -0
  54. package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/README.en.md +54 -0
  55. package/vendor/components/sha256/077678d8b14a8065c4f74a9fe1669728c68a0f763bfdca18b304f5c3d863632a/index.js +470 -0
  56. package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/README.en.md +23 -0
  57. package/vendor/components/sha256/0840322bf51eeb3c8188ce21ad70af17c13974ac0151065a39c430a3813ee07f/index.js +289 -0
  58. package/vendor/components/sha256/0c25d49d23529879054737aa181951519fe585c4728fd505e0e3c8869953eac7/index.js +934 -0
  59. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/LICENSE-strokesvg.txt +115 -0
  60. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/OFL.txt +93 -0
  61. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/index.js +755 -0
  62. package/vendor/components/sha256/0dd302b82925f35743a893d5c271898ada3659aa0de2d3249ef45936aad10ae0/strokes-CHANGES.md +20 -0
  63. package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/README.en.md +25 -0
  64. package/vendor/components/sha256/0e9e92df8d70eb6d9fcf10916c361769c7cd37baacece8d7eb96bbbc7fbcf942/index.js +317 -0
  65. package/vendor/components/sha256/12ef6a11055407f5cddc40154a49cf2737b0786429fe0fcc94ee1d8245597b40/index.js +244 -0
  66. package/vendor/components/sha256/13c9ce43396b2f5693ce430a924dae4ddcd1e8a4ad0c9b9e724ff52acb874d0c/index.js +354 -0
  67. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/README.en.md +34 -0
  68. package/vendor/components/sha256/15306d854d67d52ca2b1d66135f0d3296882e6b21fd85c029399b8077c8a7f9d/index.js +398 -0
  69. package/vendor/components/sha256/1a0f21def0efbbdef64461cafa40f3883bc7f7122adf79d01f09ca4a245e5dcb/index.js +465 -0
  70. package/vendor/components/sha256/208175d05b37d326855fad792b10137f785e5d05d91a2cde119d0dbd69d2ed98/index.js +100 -0
  71. package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/README.en.md +34 -0
  72. package/vendor/components/sha256/218d88998b70f0732c18d91ccc238b2d63f6b0aaa483883b83685a25468f214a/index.js +246 -0
  73. package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/README.en.md +24 -0
  74. package/vendor/components/sha256/2579bcb46b6525902763cd15a2e08fc5ebd9a2695cdaba63438e5b47907a47e0/index.js +554 -0
  75. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/README.en.md +23 -0
  76. package/vendor/components/sha256/277ac772315f93737a094cd0f0842726f2435d352d9a90822aebfe0d5d7e79a1/index.js +294 -0
  77. package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/README.en.md +28 -0
  78. package/vendor/components/sha256/2787e410e533e4ad48b0a3c2b652579cf5797f9c51fcf32f5478212a7acef95f/index.js +214 -0
  79. package/vendor/components/sha256/2a011338d0fc3c77e102eaa57cde2b6e3726bc279f133174b0b8c9a654263cbc/index.js +824 -0
  80. package/vendor/components/sha256/2fce5ab0c31dca0aa1586a2c69237870a9cce46c0bc6ab7392c27968d016bd15/index.js +75 -0
  81. package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/README.en.md +23 -0
  82. package/vendor/components/sha256/3417efe4722f569690563d9abcea8b144db2f8fa97b83cf0118fb3a34cd4cb2b/index.js +150 -0
  83. package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/README.en.md +18 -0
  84. package/vendor/components/sha256/3a7962fa87c670447eed54aca08604ef03cd26bf2c334b4667190060e6a17965/index.js +279 -0
  85. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/README.en.md +47 -0
  86. package/vendor/components/sha256/3be5f64deb1951327b614b29a9b632878fab362687c76e3f48f3af1d1ebbb1cf/index.js +223 -0
  87. package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/README.en.md +42 -0
  88. package/vendor/components/sha256/42450c6b36404d66641568f6d6f55e42a4a036d4d9cdf308f709464913b32fe9/index.js +272 -0
  89. package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/README.en.md +30 -0
  90. package/vendor/components/sha256/45cea6c1abfb3467e3e3dbe7fec58647716999a0c39cf7163531ae389f898d29/index.js +305 -0
  91. package/vendor/components/sha256/4c8cae404d551a1bb021e8345af5aa45d4f412f13497aa84b142f11a29a365dc/index.js +124 -0
  92. package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/README.en.md +23 -0
  93. package/vendor/components/sha256/5521b5b40a43c48c5ae5a50ce87afb3d47bb23b133b16841086d8322364cdd5e/index.js +120 -0
  94. package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/README.en.md +18 -0
  95. package/vendor/components/sha256/5fe30fd7a84b937a1325d8af2b8e437211efae82ab46d5a433bc4ef07bcaef11/index.js +243 -0
  96. package/vendor/components/sha256/631f4c4b90c9a41c0f26c9600d5cf2d6447251d04a20f08f48a85aeb4cb0f6fb/index.js +107 -0
  97. package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/README.en.md +31 -0
  98. package/vendor/components/sha256/6749f44ed6476a05d4e3026373c188a0e1a19b77a5836579813f62a1477ac35e/index.js +271 -0
  99. package/vendor/components/sha256/701f1deef79fe05eeb18e1119e5a5c4d60a9dfe265e93a4dff79223bc598dbf0/index.js +521 -0
  100. package/vendor/components/sha256/711cf58fa946c9c0abc953b2f695d02bf5a5a7f73851b09f834e894baf88be38/index.js +122 -0
  101. package/vendor/components/sha256/728576c57a5ccb39531ad4cb8074fce95480f01603a77dbf57dca0e52199f7c4/index.js +37 -0
  102. package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/README.en.md +18 -0
  103. package/vendor/components/sha256/73edc74a2dc4a63b717106c1c1572967b6d306270574e9635d032de16c8ada72/index.js +382 -0
  104. package/vendor/components/sha256/76bdb63c3e5e14fbb4816bc9f235490817bb5d7be990a826f5077aa08226702c/index.js +162 -0
  105. package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/README.en.md +51 -0
  106. package/vendor/components/sha256/7a5adf73fc053b9f2ca56643b5683b42589edb0f63c845ecb7ae7e6b87eccc30/index.js +230 -0
  107. package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/README.en.md +26 -0
  108. package/vendor/components/sha256/7ab483e7fb05f646b062340d70f2749d070b4f64fed7acc0b8a7754d9ef9fded/index.js +322 -0
  109. package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/README.en.md +18 -0
  110. package/vendor/components/sha256/7af6e5e6dffb618b39f27d883c691ca128f3af06040ee505e75c79c678bfdcfe/index.js +103 -0
  111. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/README.en.md +44 -0
  112. package/vendor/components/sha256/7c7b0373cfd38fd5ecb4169021e0b908f0a17be1a29b14f85dd89fdb92e7bf81/index.js +306 -0
  113. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ABCJS-ADAPTER.md +101 -0
  114. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/LICENSE-abcjs.txt +21 -0
  115. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/chords.json +89 -0
  116. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/doremi.json +261 -0
  117. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/extras.json +192 -0
  118. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/kaeru.json +521 -0
  119. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/rhythm.json +248 -0
  120. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/fixtures/ties.json +360 -0
  121. package/vendor/components/sha256/7dea2c3728b85122b04515aa06ab198657529e7cd101b9ab34d4ecb2905ce94e/index.js +508 -0
  122. package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/README.en.md +22 -0
  123. package/vendor/components/sha256/832556ea9c82c292a3ba9e1b332f2405c5c2f969ff8157c91ed80226ec8ac62e/index.js +145 -0
  124. package/vendor/components/sha256/8a4b6dce84d7a69aaafeb75c1c572fe7904fd49e3169c1c85851ccaeae2a7b11/index.js +41 -0
  125. package/vendor/components/sha256/8bb511cb90902bc7721e59ca08685b26adbf33539e36a4a45172485d6d3d455b/index.js +250 -0
  126. package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/README.en.md +21 -0
  127. package/vendor/components/sha256/8db9c936c36b79b9e3b2be37639487b15502a6937f411ed714621a8091437e9b/index.js +108 -0
  128. package/vendor/components/sha256/8e5e90c90cb6b06a790b0420e43d79d7da663f1cc19ff06d381ec849b4a8fc57/index.js +312 -0
  129. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/README.en.md +34 -0
  130. package/vendor/components/sha256/939bdae590ebed3d182b0c9940a35b6c03872505bfa242341990a81cae02fd06/index.js +397 -0
  131. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/README.en.md +44 -0
  132. package/vendor/components/sha256/9c5dd0bc0c3279c5f0fea3fdb9d0735870880aef96e8bbf9ecdd77dff0f5ddc8/index.js +551 -0
  133. package/vendor/components/sha256/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -0
  134. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/README.en.md +18 -0
  135. package/vendor/components/sha256/a5b032657720d3beb64f0b3699954e13b0eb985f36161b9ae046c83fd6048ff5/index.js +382 -0
  136. package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/README.en.md +38 -0
  137. package/vendor/components/sha256/a7c4282db79d46557bdbaf84ca519606dc46f3c23455db4a26f663453f85813c/index.js +414 -0
  138. package/vendor/components/sha256/aac2f8a23cb1b606e9635061cb288f006588c80a7258540cae846ae677f55ff5/index.js +238 -0
  139. package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/README.en.md +45 -0
  140. package/vendor/components/sha256/ace7e82e866b577ad42bbc4b64e11bae18982e3236aadceb6c2e6c20f41234cf/index.js +211 -0
  141. package/vendor/components/sha256/aeb0b9b5991a5c1df7191c397780a699f2c7310123ca210a58486c0a23e44006/index.js +342 -0
  142. package/vendor/components/sha256/af3355efd6739a56c6cb53990100f41703361c475c123b9b2762421c68509036/index.js +315 -0
  143. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/LICENSE-tabler.txt +21 -0
  144. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/index.js +4868 -0
  145. package/vendor/components/sha256/b10183a66b58b827a1410cf8b0117af567647684464d5777529dc66f0cea343a/names.txt +4808 -0
  146. package/vendor/components/sha256/b348ea64cc19632df96a91dfd7c435e4a62095aede72b504d03537be70d6d930/index.js +606 -0
  147. package/vendor/components/sha256/b53bfa03d1e9feb3cb492f440bf9d100c96eb4fe6b76c42b512a56e9158829cd/index.js +351 -0
  148. package/vendor/components/sha256/b9443e1cdac4850b1ead9f8449a3061678bbb77fbc53eb9b23d01e1cf50750c3/index.js +619 -0
  149. package/vendor/components/sha256/bc1e2a02c959ac203819d03c0d25b3776a6a9a4290aae860b26cbbe3d29e876d/index.js +268 -0
  150. package/vendor/components/sha256/beeb180c0e2250bb04490b092c0a235cae47fca2ed1de2d9ef078a5c14b1a963/index.js +429 -0
  151. package/vendor/components/sha256/c5fd7713e55e96d75824a21146c0251896d7d9dd028b4d169191433135a97981/index.js +200 -0
  152. package/vendor/components/sha256/c61987e9994940fc668ed8a010e575ee52027b54ed9c5dd1cc9fdf67649092b3/index.js +404 -0
  153. package/vendor/components/sha256/ccc8bfe174b6903ec254dfef4f5d1c614271ea39963649add7fcb8d83c081eba/index.js +278 -0
  154. package/vendor/components/sha256/da267bc65fde0a9279127d5a82f6c253ad74984da6fb11391f00604ad9ffe80d/index.js +93 -0
  155. package/vendor/components/sha256/dea36cd7010991a572ef394ee32b5e17564aeff09d3ec4ed3820d7e43c9a58be/index.js +484 -0
  156. package/vendor/components/sha256/df3fdb2aed487d4f6e60a8abab1fe0d1e9fa2a4193fd162edf3c384ea8db5a1b/index.js +180 -0
  157. package/vendor/components/sha256/e27d517f39eb554c7a9ecea7b59fcf1d347c4deeb3fe2250797aa233bfb7e2b0/index.js +747 -0
  158. package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/README.en.md +20 -0
  159. package/vendor/components/sha256/e31f6b058503f7980597c89b3e964c512ee08de7cba3fa99904d499abbb5d0e8/index.js +310 -0
  160. package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/README.en.md +30 -0
  161. package/vendor/components/sha256/f4100076a37dbde6046d85969d651feffc925bd984ffe9f333ea9bd2b6816918/index.js +192 -0
  162. package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/README.en.md +24 -0
  163. package/vendor/components/sha256/fa6442fa3c5082cf161c29308fe0ecbd85fa33e8e4bad08c12e7961b46b1365b/index.js +214 -0
  164. package/vendor/components-2/manifest-2.16.0.json +2919 -0
  165. package/vendor/components-2/manifest-2.17.0.json +2852 -0
  166. package/vendor/components-2/manifest-2.18.0.json +3182 -0
  167. package/vendor/components-2/manifest-2.20.0.json +3217 -0
  168. package/vendor/components-2/manifest-2.21.0.json +3220 -0
  169. package/vendor/egatari-spec/SOURCE.json +2 -2
  170. package/vendor/egatari-spec/schema/deck-meta.schema.json +3 -0
  171. package/vendor/egatari-spec/schema/egatari-metadata.schema.json +6 -0
@@ -0,0 +1,521 @@
1
+ // m-hist:ヒストグラム(柱状グラフ)・度数折れ線・ドットプロット。生の値から部品が度数を数えるか、度数分布表を書く
2
+ // <m-hist xl="記録(m)" yl="人数(人)" polygon="on" marks="mean,median,mode" style="height:440px">
3
+ // <script type="application/json">{"values": [23, 31, 27], "bins": {"start": 15, "width": 5}}
4
+ // (JSON の終わり)</m-hist>
5
+ // 段階:分布(既定は系列 1 つ = 1 段階。build="bins" は階級 1 つ = 1 段階、build="values" は値が 1 つずつ落ちて積もる)→ 度数折れ線(polygon="on")
6
+ // → 代表値の印を 1 つずつ(marks の順)
7
+ // 軸の属性(xr yr xt yt xf yf xl yl)は m-curves と同じ名前と意味。階級は「以上・未満」(start + i·width 以上、start + (i+1)·width 未満)
8
+ // 見せ方(docs/conventions.md §1):fade(棒・点がフェードして現れる、既定)・grow(棒が下から伸びる。点は下の段から順に現れる)
9
+ // 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・variant・previewOpacity、plot の Plot、
10
+ // 代表値と度数は hist-core(1.x の static stats)を使い、プレイヤーのグローバルは使わない。書き方やデータの知らせ
11
+ // (1.x の console.warn)は mount で ctx.report に。言語は ctx.lang(mount で読む)
12
+ egatariParts.define({name: "hist", version: "2.0.7", requires: {base: "1.3.0", "hist-core": "1.0.0", plot: "1.1.3"}, element: "m-hist"}, function(deps){
13
+ "use strict";
14
+ var base = deps.base, plot = deps.plot;
15
+ // ---- 代表値と度数(hist-core。tools/test-stats.mjs が試す) ----
16
+ var STATS = deps["hist-core"];
17
+ // 印の名前の置き場所:線の頭の右(start)か左(end)。名前がほかの印の線にかからない側を選び、名前がかかる線の印は
18
+ // それより下の行に置く(線は自分の名前の行までしか伸びないので、上の名前を横切らない)。同じ行の名前は 14 px あける。
19
+ // fl:[{x, w}](x は線の位置、w は名前の幅)。各要素に a(start / end)・L・R・row を書き、行の数を返す。
20
+ // 置き場所がないときは report(code, message)(ctx.report)で知らせる
21
+ function FLAGS(fl, W, report){
22
+ var span = function(f, a){ var l = a === "start" ? f.x + 8 : f.x - 8 - f.w; return [l, l + f.w]; };
23
+ var covers = function(f, g){ return g !== f && g.x > f.L - 6 && g.x < f.R + 6; };
24
+ fl.forEach(function(f){
25
+ var best = null;
26
+ ["start", "end"].forEach(function(a){
27
+ var sp = span(f, a);
28
+ if (sp[0] < 2 || sp[1] > W - 2) return;
29
+ var n = fl.filter(function(g){ return g !== f && g.x > sp[0] - 6 && g.x < sp[1] + 6; }).length;
30
+ if (!best || n < best.n) best = {a: a, n: n};
31
+ });
32
+ f.a = best ? best.a : (f.x < W / 2 ? "start" : "end");
33
+ var sp2 = span(f, f.a); f.L = sp2[0]; f.R = sp2[1];
34
+ });
35
+ // 名前がかかる線の印が先(下の行)
36
+ var lv = fl.map(function(){ return 0; });
37
+ for (var it = 0; it < fl.length; it++) fl.forEach(function(f, i){ fl.forEach(function(g, j){ if (covers(f, g)) lv[i] = Math.max(lv[i], Math.min(fl.length, lv[j] + 1)); }); });
38
+ var order = fl.map(function(f, i){ return i; }).sort(function(a, b){ return lv[a] - lv[b] || a - b; });
39
+ var placed = [], rows = 0;
40
+ order.forEach(function(i){
41
+ var f = fl[i], row = 0;
42
+ placed.forEach(function(o){ if (covers(f, o)) row = Math.max(row, o.row + 1); });
43
+ for (;; row++){
44
+ var clash = placed.some(function(o){
45
+ return (o.row === row && f.L < o.R + 14 && o.L < f.R + 14) || (o.row < row && covers(o, f)) || (o.row > row && covers(f, o));
46
+ });
47
+ if (!clash) break;
48
+ if (row > 12){ report("layout", '[hist] no free place for the name "' + (f.text || "") + '" (it may overlap)'); break; }
49
+ }
50
+ f.row = row; placed.push(f); rows = Math.max(rows, row + 1);
51
+ });
52
+ return rows;
53
+ }
54
+ var ON = function(v){ return /^(on|true|yes)$/i.test(String(v || "").trim()); };
55
+ return class extends base.MotionElement {
56
+ static partName = "hist"; // the registry name (define meta name), for report prefixes
57
+ static variants = ["fade", "grow"];
58
+ // データの形(kit/shape.js)
59
+ static shape = (function(){
60
+ var NUMS = {type: "array", minItems: 1, items: {type: "number"}};
61
+ var TABLE = {type: "array", minItems: 1, items: {type: "object", additionalProperties: false, required: ["from", "to", "count"],
62
+ properties: {from: {type: "number"}, to: {type: "number"}, count: {type: "integer"}}}};
63
+ return {
64
+ schema: {type: "object", additionalProperties: false, anyOf: [{required: ["values"]}, {required: ["table"]}, {required: ["series"]}], properties: {
65
+ values: NUMS, table: TABLE,
66
+ bins: {type: "object", additionalProperties: false, required: ["start", "width"], properties: {start: {type: "number"}, width: {type: "number"}}},
67
+ series: {type: "array", minItems: 1, maxItems: 2, items: {type: "object", additionalProperties: false, anyOf: [{required: ["values"]}, {required: ["table"]}],
68
+ properties: {label: {type: "string"}, tone: {type: "string"}, values: NUMS, table: TABLE}}}}},
69
+ example: {values: [23, 31, 27, 18, 25, 29, 33, 22, 26, 28], bins: {start: 15, width: 5}},
70
+ note: {en: "raw values with bins {start, width} (the part counts), or a frequency table [{from, to, count}]; up to 2 series [{label, tone, values | table}]",
71
+ ja: "生の値と階級 {start, width}(パーツが数える)か、度数分布表 [{from, to, count}]。系列は 2 つまで [{label, tone, values か table}]"},
72
+ };
73
+ })();
74
+ static props = {
75
+ xr: {type: "json", default: null, doc: "横軸の範囲(書かなければ階級から)"}, yr: {type: "json", default: null, doc: "縦軸の範囲(書かなければ度数から)"},
76
+ xt: {type: "json", default: null, doc: "横軸の目盛り(書かなければ階級の境)"}, yt: {type: "json", default: null, doc: "縦軸の目盛り(書かなければ自動)"},
77
+ xf: {type: "number", default: undefined, doc: "横軸の目盛りの小数桁"}, yf: {type: "number", default: undefined, doc: "縦軸の目盛りの小数桁"},
78
+ xl: {type: "string", default: ""}, yl: {type: "string", default: ""},
79
+ unit: {type: "string", default: "", doc: "代表値の数の後ろに付ける単位"},
80
+ digits: {type: "number", default: undefined, doc: "代表値の小数桁(書かなければ値の桁+1 まで)"},
81
+ polygon: {type: "string", default: "off", doc: "on:度数折れ線"},
82
+ relative: {type: "string", default: "off", doc: "on:相対度数"},
83
+ cumulative: {type: "string", default: "off", doc: "on:累積度数"},
84
+ kind: {type: "string", default: "bars", doc: "bars(柱状グラフ)か dots(ドットプロット)"},
85
+ marks: {type: "string", default: "", doc: "代表値の印:mean,median,mode のどれか(書いた順に 1 つずつ)"},
86
+ build: {type: "string", default: "whole", doc: "whole・values(値を 1 つずつ数える)・bins(階級を 1 つずつ)"},
87
+ dur: {type: "number", default: 0.8, doc: "1 ステップの動きの秒数"},
88
+ };
89
+ get steps(){
90
+ if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
91
+ return this.plan().steps;
92
+ }
93
+ // 系列・階級・度数・代表値・段階(mount の前にも steps が要るので、データと属性だけから決める)
94
+ plan(){
95
+ if (this._plan) return this._plan;
96
+ var d = this.data || {}, P = this.props, S = STATS, notes = [];
97
+ var kind = P.kind, sa = this.getAttribute("style");
98
+ // style="dots" と書かれたとき(style は大きさに使う属性なので kind を勧める)
99
+ if (/^\s*(bars|dots)\s*$/.test(sa || "")){ kind = sa.trim(); notes.push(["attr", '[hist] write kind="' + kind + '" (style is for the size, e.g. style="height:420px")']); }
100
+ if (kind !== "bars" && kind !== "dots"){ notes.push(["attr", '[hist] kind="' + kind + '" is not bars or dots (bars is used)']); kind = "bars"; }
101
+ var src = Array.isArray(d.series) && d.series.length ? d.series : [{values: d.values, table: d.table}];
102
+ var ser = src.map(function(s, i){
103
+ return {i: i, label: s.label || "", tone: s.tone, values: Array.isArray(s.values) ? s.values.map(Number) : null,
104
+ table: Array.isArray(s.table) ? s.table.map(function(r){
105
+ // 度数は 0 以上の数:負の度数は知らせて 0 に(そのまま数えると合計・平均・中央値・相対度数が狂う)
106
+ var c = +r.count;
107
+ if (!(c >= 0)){ notes.push(["data", "[hist] " + (s.label ? s.label + ": " : "") + "the count " + r.count + " of the class " + r.from + "〜" + r.to + " is not 0 or more (0 is used)"]); c = 0; }
108
+ return {from: +r.from, to: +r.to, count: c};
109
+ }).sort(function(a, b){ return a.from - b.from; }) : null};
110
+ });
111
+ var raw = ser.every(function(s){ return s.values; });
112
+ if (kind === "dots" && !raw) throw new Error("m-hist: kind=\"dots\" needs raw values (\"values\": [...]), not a frequency table");
113
+ // 階級:度数分布表から、なければ bins から、なければ値から(柱状グラフのとき)
114
+ var bins = null, tab = ser.filter(function(s){ return s.table; });
115
+ var eq = function(a, b, w){ return Math.abs(a - b) <= Math.abs(w) * 1e-6; };
116
+ if (tab.length){
117
+ var t0 = tab[0].table, w = t0[0].to - t0[0].from;
118
+ if (!(w > 0)) throw new Error("m-hist: table rows need from < to");
119
+ t0.forEach(function(r, j){
120
+ if (!eq(r.to - r.from, w, w) || (j && !eq(r.from, t0[j - 1].to, w))) throw new Error("m-hist: the table's classes must have equal widths and follow each other (" + r.from + "〜" + r.to + ")");
121
+ });
122
+ bins = {start: t0[0].from, width: w, nb: t0.length};
123
+ tab.forEach(function(s){
124
+ if (s.table.length !== t0.length || s.table.some(function(r, j){ return !eq(r.from, t0[j].from, w) || !eq(r.to, t0[j].to, w); }))
125
+ throw new Error("m-hist: the two tables must have the same classes");
126
+ });
127
+ } else if (d.bins){
128
+ if (!(+d.bins.width > 0)) throw new Error("m-hist: bins.width must be greater than 0");
129
+ bins = {start: +d.bins.start, width: +d.bins.width, nb: 0};
130
+ }
131
+ var all = [].concat.apply([], ser.map(function(s){ return s.values || []; }));
132
+ var lo = all.length ? Math.min.apply(null, all) : 0, hi = all.length ? Math.max.apply(null, all) : 0;
133
+ var given = !!bins;
134
+ if (!bins && kind === "bars"){
135
+ // 階級を書かなければ、およそ 1 + log2(n) 個の切りのよい幅
136
+ var k0 = Math.max(1, Math.ceil(1 + Math.log2(Math.max(1, all.length)))), w0 = niceStep((hi - lo || 1) / k0);
137
+ bins = {start: S.clean(Math.floor(lo / w0 + 1e-9) * w0), width: w0, nb: 0};
138
+ notes.push(["data", "[hist] no bins were written; classes of width " + w0 + " from " + bins.start + " are used (write \"bins\": {\"start\", \"width\"})"]);
139
+ }
140
+ if (bins && all.length){
141
+ if (S.binOf(lo, bins.start, bins.width) < 0) throw new Error("m-hist: the value " + lo + " is below bins.start (" + bins.start + ")");
142
+ var need = S.binOf(hi, bins.start, bins.width) + 1;
143
+ if (tab.length && need > bins.nb) throw new Error("m-hist: the value " + hi + " is outside the table's classes");
144
+ bins.nb = Math.max(bins.nb, need);
145
+ }
146
+ if (bins){
147
+ bins.edges = []; for (var e = 0; e <= bins.nb; e++) bins.edges.push(S.clean(bins.start + e * bins.width));
148
+ bins.mids = S.mids(bins.start, bins.width, bins.nb);
149
+ }
150
+ var dec = function(v){ var s = String(v), m = s.match(/\.(\d+)$/); return m ? m[1].length : 0; };
151
+ var base = Math.max.apply(null, all.map(dec).concat(bins ? [dec(bins.start), dec(bins.width)] : []).concat([0]));
152
+ ser.forEach(function(s){
153
+ if (bins) s.counts = s.values ? S.counts(s.values, bins.start, bins.width, bins.nb) : s.table.map(function(r){ return r.count; });
154
+ s.n = s.values ? s.values.length : S.sum(s.counts);
155
+ });
156
+ // 代表値(marks の順)
157
+ var marks = [];
158
+ String(P.marks || "").split(/[\s,、]+/).filter(Boolean).forEach(function(m){
159
+ if (["mean", "median", "mode"].indexOf(m) < 0){ notes.push(["attr", '[hist] marks: "' + m + '" is not mean, median or mode (ignored)']); return; }
160
+ if (marks.some(function(x){ return x.type === m; })) return;
161
+ var per = ser.map(function(s){
162
+ if (!s.n) return null;
163
+ if (m === "mean") return {xs: [s.values ? S.mean(s.values) : S.tableMean(bins.mids, s.counts)]};
164
+ if (m === "median"){
165
+ if (s.values) return {xs: [S.median(s.values)]};
166
+ var md = S.tableMedian(bins.start, bins.width, s.counts);
167
+ return md.bin !== undefined ? {xs: [md.x], cls: [md.from, md.to]} : {xs: [md.at]};
168
+ }
169
+ // 最頻値:点を値の上に積むときは値から、階級でまとめるときは度数がいちばん多い階級の階級値
170
+ var mo = kind === "dots" && !given ? S.modes(s.values) : S.binModes(bins.mids, s.counts);
171
+ if (!mo.length){ notes.push(["data", "[hist] " + (s.label || "the data") + " has no mode (every value appears once); the mark is left out"]); return null; }
172
+ return {xs: mo, cls: kind === "dots" && !given ? null : true};
173
+ });
174
+ if (per.some(Boolean)) marks.push({type: m, per: per});
175
+ });
176
+ // 段階
177
+ var build = P.build;
178
+ if (["whole", "values", "bins"].indexOf(build) < 0){ notes.push(["attr", '[hist] build="' + build + '" is not whole, values or bins (whole is used)']); build = "whole"; }
179
+ if (build === "values" && !raw){ notes.push(["attr", '[hist] build="values" needs raw values; build="bins" is used']); build = "bins"; }
180
+ if (build === "bins" && kind === "dots"){ notes.push(["attr", '[hist] build="bins" is for bars; build="values" is used for dots']); build = "values"; }
181
+ var poly = ON(P.polygon), rel = ON(P.relative), cum = ON(P.cumulative);
182
+ if (kind === "dots" && (poly || rel || cum)){ notes.push(["attr", "[hist] polygon, relative and cumulative are for bars (ignored with kind=\"dots\")"]); poly = rel = cum = false; }
183
+ var k = 0;
184
+ if (build === "bins"){ ser.forEach(function(s){ s.step = 1; }); bins.step0 = 1; k = bins.nb; }
185
+ else ser.forEach(function(s){ s.step = ++k; });
186
+ var polyStep = poly ? ++k : 0;
187
+ marks.forEach(function(m){ m.step = ++k; });
188
+ // build="values":値が落ちる間隔。1 段階が 3 秒ほどに収まるように(9 個までは 0.3 秒おき、それより多ければ詰める)
189
+ var DROP = 0.45;
190
+ ser.forEach(function(s){
191
+ s.gap = build === "values" && s.n > 1 ? Math.min(0.3, 2.5 / (s.n - 1)) : 0;
192
+ s.len = build === "values" ? (s.n - 1) * s.gap + DROP + 0.1 : P.dur;
193
+ });
194
+ return (this._plan = {kind: kind, ser: ser, bins: bins, given: given, marks: marks, build: build, poly: poly, rel: rel, cum: cum,
195
+ polyStep: polyStep, steps: Math.max(1, k), base: base, notes: notes, DROP: DROP, lo: lo, hi: hi});
196
+ function niceStep(r){ var e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e; return S.clean((x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e); }
197
+ }
198
+ // 代表値の数の書き方:digits があればその桁、なければ値の桁+1 まで(終わりの 0 は値の桁まで落とす)
199
+ fmt(v){
200
+ var P = this.props, pl = this.plan(), s;
201
+ if (P.digits !== undefined && isFinite(P.digits)) s = Math.abs(v).toFixed(P.digits);
202
+ else { s = Math.abs(v).toFixed(pl.base + 1); if (s.indexOf(".") >= 0){ var keep = pl.base; s = s.replace(/0+$/, ""); var dd = (s.split(".")[1] || "").length; if (dd < keep) s += Array(keep - dd + 1).join("0"); s = s.replace(/\.$/, ""); } }
203
+ var p = s.split("."), i = p[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
204
+ return (v < 0 && +s !== 0 ? "−" : "") + i + (p[1] ? "." + p[1] : "");
205
+ }
206
+ // 相対度数の書き方:小数第 2 位まで、十進の四捨五入(0.175 → 0.18、0.875 → 0.88。toFixed は 2 進の値で丸めるので 0.175 が 0.17 になる)
207
+ rel2(v){ return (Math.round(v * 100 + 1e-9) / 100).toFixed(2); }
208
+ mount(ctx){
209
+ var P = this.props, D = base, self = this, pl = this.plan(), S = STATS;
210
+ this.variant = base.variant(this);
211
+ // 書き方とデータの知らせ(plan が集めた [code, message])
212
+ // ctx.report with each code as a literal (lint checks them): plan's notes (attr, data) and the flag placer's (layout)
213
+ var report = function(code, msg){ if (code === "attr") ctx.report("attr", msg); else if (code === "layout") ctx.report("layout", msg); else ctx.report("data", msg); };
214
+ pl.notes.forEach(function(n){ report(n[0], n[1]); });
215
+ this.classList.add("plot"); this.style.display = "block";
216
+ var ja = this.ja = /^ja\b/i.test(ctx.lang);
217
+ // 字の幅(base の textWidth:テーマの字で測った幅。mtext の *_^ は数えない)
218
+ var est = function(s, size){ return D.textWidth(s, size, {font: self, mark: true}); };
219
+ var colorOf = function(c, i){ return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(c || "") ? "var(--" + c + ")" : null; };
220
+ var two = pl.ser.length > 1, dots = pl.kind === "dots", bins = pl.bins;
221
+ pl.ser.forEach(function(s, i){ s.col = colorOf(s.tone) || (two ? "var(--series-" + (i + 1) + ")" : "var(--term)"); });
222
+ var W = this.clientWidth, H = this.clientHeight;
223
+ // 高さ:度数・相対度数・累積度数
224
+ var heights = function(c, n){ var h = pl.cum ? S.cumulative(c) : c.slice(); return pl.rel ? h.map(function(v){ return v / n; }) : h; };
225
+ // 横軸の範囲と目盛り
226
+ var xr = P.xr, xt = P.xt;
227
+ if (!xr){
228
+ if (bins) xr = pl.poly && !pl.cum ? [S.clean(bins.start - bins.width), S.clean(bins.edges[bins.nb] + bins.width)] : [bins.start, bins.edges[bins.nb]];
229
+ else { var st0 = dotStep(pl.hi - pl.lo); xr = [S.clean(Math.floor(pl.lo / st0 + 1e-9) * st0), S.clean(Math.ceil(pl.hi / st0 - 1e-9) * st0)]; if (xr[0] === xr[1]) xr = [xr[0] - st0, xr[1] + st0]; }
230
+ }
231
+ if (!xt){
232
+ if (bins){
233
+ // 階級の境(度数折れ線のために足した両端の階級には目盛りの数を書かない)
234
+ var ed = bins.edges.filter(function(v){ return v >= xr[0] - 1e-9 && v <= xr[1] + 1e-9; });
235
+ // 目盛りの数が重ならないように間引く(目盛りの数の幅+12 px が、境の間隔の何個分か)
236
+ var dd0 = Math.max.apply(null, ed.map(function(x){ var mm = String(x).match(/\.(\d+)$/); return mm ? mm[1].length : 0; }).concat([0]));
237
+ var lw0 = Math.max.apply(null, ed.map(function(x){ return est(x.toFixed(dd0), 24); })) + 12;
238
+ var pxBin = (W - (dots ? 56 : 130)) * bins.width / (xr[1] - xr[0]);
239
+ var every = Math.max(Math.ceil(ed.length / 13), Math.ceil(lw0 / Math.max(1, pxBin))); xt = ed.filter(function(x, j){ return j % every === 0; });
240
+ } else { var st1 = dotStep(xr[1] - xr[0]); xt = []; for (var u = Math.ceil(xr[0] / st1 - 1e-9) * st1; u <= xr[1] + st1 * 1e-6; u += st1) xt.push(S.clean(u)); }
241
+ }
242
+ var xf = P.xf !== undefined ? P.xf : Math.max.apply(null, xt.map(function(x){ var m = String(x).match(/\.(\d+)$/); return m ? m[1].length : 0; }).concat([0]));
243
+ // 縦軸(柱状グラフ)
244
+ var yr = P.yr, yt = P.yt, yf = P.yf, top = 1e-9;
245
+ if (!dots){
246
+ pl.ser.forEach(function(s){ top = Math.max(top, Math.max.apply(null, heights(s.counts, s.n))); });
247
+ if (!yr){ var ys = niceStep(top * 1.12 / 5, !pl.rel); yr = [0, S.clean(Math.ceil(top * 1.12 / ys - 1e-9) * ys)]; }
248
+ if (!yt){ var ys2 = niceStep((yr[1] - yr[0]) / 5, !pl.rel); yt = []; for (var q = Math.ceil(yr[0] / ys2 - 1e-9) * ys2; q <= yr[1] + ys2 * 1e-6; q += ys2) yt.push(S.clean(q)); }
249
+ if (yf === undefined) yf = Math.max.apply(null, yt.map(function(x){ var m = String(x).match(/\.(\d+)$/); return m ? m[1].length : 0; }).concat([0]));
250
+ } else { yr = [0, 1]; yt = []; }
251
+ var yl = dots ? "" : P.yl || (pl.cum ? (pl.rel ? (ja ? "累積相対度数" : "Cumulative relative frequency") : (ja ? "累積度数" : "Cumulative frequency")) : pl.rel ? (ja ? "相対度数" : "Relative frequency") : (ja ? "度数" : "Frequency"));
252
+ var yw = Math.max.apply(null, yt.map(function(v){ return est(v.toFixed(yf), 24); }).concat([0]));
253
+ var m = {l: dots ? 28 : Math.max(64, yw + 22 + (yl ? 40 : 0)), r: 28, t: 16, b: P.xl ? 70 : 44};
254
+ // 系列の名前(2 つのとき):図の上に右寄せで、印と一緒に
255
+ // 2 組の名前はいつも出す(label が無ければ「1 組目」「2 組目」にして知らせる)
256
+ if (two) pl.ser.forEach(function(s, i){ if (!s.label){ s.label = ja ? (i + 1) + " 組目" : "Group " + (i + 1); ctx.report("data", "[hist] series " + (i + 1) + " has no label; write \"label\" for the legend"); } });
257
+ var legendH = two ? 46 : 0;
258
+ // 代表値の名前:図の上の行に、印の線の頭の右か左に置く(ほかの名前と線に重ならない行へ)
259
+ var px0 = m.l, px1 = W - m.r, X = function(v){ return px0 + (v - xr[0]) / (xr[1] - xr[0]) * (px1 - px0); };
260
+ var NAMES = ja ? {mean: "平均値", median: "中央値", mode: "最頻値"} : {mean: "Mean", median: "Median", mode: "Mode"};
261
+ var flags = [];
262
+ pl.marks.forEach(function(mk){
263
+ mk.per.forEach(function(r, si){
264
+ if (!r) return;
265
+ var s = pl.ser[si], txt;
266
+ if (mk.type === "median" && r.cls) txt = (ja ? "中央値の階級 " : "Median class ") + self.fmt(r.cls[0]) + "〜" + self.fmt(r.cls[1]) + P.unit;
267
+ else txt = NAMES[mk.type] + " " + r.xs.map(function(x){ return self.fmt(x); }).join(", ") + P.unit;
268
+ flags.push({mk: mk, s: s, r: r, x: X(r.xs[0]), text: txt, w: est(txt, 24), col: two ? s.col : {mean: "var(--emph)", median: "var(--accent2)", mode: "var(--fg)"}[mk.type],
269
+ dash: {mean: null, median: "12 7", mode: "3 6"}[mk.type]});
270
+ });
271
+ });
272
+ var rows = FLAGS(flags, W, report);
273
+ m.t = legendH + (rows ? rows * 34 + 14 : 16);
274
+ // 数を棒の上に書く余白(系列が 1 つの柱状グラフ)
275
+ var p = this.p = plot.Plot(this, {xr: xr, yr: yr, xt: xt, yt: dots ? [] : yt, xf: xf, yf: yf, xl: P.xl, yl: yl, noY: dots, m: m});
276
+ var axl = p.svg.querySelectorAll("g.axes > line");
277
+ for (var a = 0; a < Math.min(dots ? 1 : 2, axl.length); a++) axl[a].setAttribute("class", "axis");
278
+ var x0 = m.l, x1 = W - m.r, y0 = m.t, y1 = H - m.b;
279
+ if (y1 - y0 < 60) ctx.report("size", "[hist] the element (" + W + "×" + H + " px) is too small for the figure; give it more height");
280
+ this.geo = {x0: x0, x1: x1, y0: y0, y1: y1, W: W, H: H};
281
+ var gB = D.el("g", {}, p.svg), gM = D.el("g", {}, p.svg), gP = D.el("g", {}, p.svg), gD = D.el("g", {}, p.svg), gT = D.el("g", {}, p.svg);
282
+ this.heights = heights;
283
+ // 柱状グラフ:系列ごとに階級の数だけの長方形(隙間なし)。2 系列は塗りを薄くして重ね、2 つ目は破線
284
+ if (!dots){
285
+ pl.ser.forEach(function(s, si){
286
+ s.H = heights(s.counts, s.n);
287
+ s.rects = bins.mids.map(function(mid, b){
288
+ var r = D.el("rect", {x: p.x(bins.edges[b]).toFixed(1), width: Math.max(0, p.x(bins.edges[b + 1]) - p.x(bins.edges[b])).toFixed(1), y: y1, height: 0,
289
+ fill: s.col, "fill-opacity": two ? 0.16 : 0.26, stroke: s.col, "stroke-width": two ? 3 : 2.5, opacity: 0, class: "outline"}, gB);
290
+ if (two && si === 1) r.setAttribute("stroke-dasharray", "10 6");
291
+ return r;
292
+ });
293
+ // 棒の上の数(系列が 1 つで、棒の幅に収まるとき)
294
+ var bw = p.x(bins.edges[1]) - p.x(bins.edges[0]);
295
+ s.nums = two ? [] : bins.mids.map(function(mid, b){
296
+ var txt = pl.rel ? self.rel2(s.H[b]) : String(s.H[b]);
297
+ if (est(txt, 24) > bw - 4) return null;
298
+ // 度数折れ線があれば、折れ線が棒の上を通らない側(となりの低い方)に寄せる(累積は右上がりなので左)
299
+ var x = p.x(mid), an = "middle";
300
+ if (pl.poly){
301
+ var hl = b ? s.H[b - 1] : 0, hr = b < bins.nb - 1 ? s.H[b + 1] : 0;
302
+ if (pl.cum || hl <= hr){ x = p.x(bins.edges[b]) + 6; an = "start"; } else { x = p.x(bins.edges[b + 1]) - 6; an = "end"; }
303
+ }
304
+ return D.el("text", {x: x.toFixed(1), y: y1, "font-size": 24, "text-anchor": an, fill: "var(--fg)", stroke: "var(--bg)", "stroke-width": 5,
305
+ "paint-order": "stroke", opacity: 0, style: "font-variant-numeric:tabular-nums"}, gT);
306
+ });
307
+ if (s.values){
308
+ // build="values":値ごとの階級と、その値が積もる前の高さ・後の高さ
309
+ s.drops = s.values.map(function(v, j){
310
+ var b = S.binOf(v, bins.start, bins.width), cb = s.counts.map(function(){ return 0; });
311
+ for (var i = 0; i < j; i++) cb[S.binOf(s.values[i], bins.start, bins.width)]++;
312
+ var before = heights(cb, s.n)[b]; cb[b]++; var after = heights(cb, s.n)[b];
313
+ return {v: v, b: b, before: before, after: after};
314
+ });
315
+ }
316
+ });
317
+ // 落ちる値(build="values"):1 つの箱と、間隔が広ければその値の数字
318
+ if (pl.build === "values"){
319
+ var bw2 = p.x(bins.edges[1]) - p.x(bins.edges[0]);
320
+ pl.ser.forEach(function(s){
321
+ var show = s.gap >= 0.2;
322
+ s.fall = s.drops.map(function(o){
323
+ var g = D.el("g", {opacity: 0}, gD);
324
+ D.el("rect", {x: (-bw2 / 2 + 4).toFixed(1), y: 0, width: Math.max(2, bw2 - 8).toFixed(1), height: 10, fill: s.col, "fill-opacity": 0.6, stroke: s.col, "stroke-width": 2}, g);
325
+ if (show) D.el("text", {x: 0, y: -8, "font-size": 24, "text-anchor": "middle", fill: "var(--fg)", stroke: "var(--bg)", "stroke-width": 5, "paint-order": "stroke"}, g).textContent = self.fmt(o.v);
326
+ return {g: g, rect: g.firstChild};
327
+ });
328
+ });
329
+ }
330
+ // 度数折れ線:両端に度数 0 の階級を足して階級値を結ぶ。累積度数なら階級の右の端を結ぶ
331
+ if (pl.poly){
332
+ pl.ser.forEach(function(s, si){
333
+ var pts = pl.cum ? [[bins.edges[0], 0]].concat(s.H.map(function(h, b){ return [bins.edges[b + 1], h]; }))
334
+ : [[S.clean(bins.start - bins.width / 2), 0]].concat(s.H.map(function(h, b){ return [bins.mids[b], h]; })).concat([[S.clean(bins.edges[bins.nb] + bins.width / 2), 0]]);
335
+ var P2 = pts.map(function(q){ return [p.x(q[0]), p.y(q[1])]; }), len = 0;
336
+ for (var i = 1; i < P2.length; i++) len += Math.hypot(P2[i][0] - P2[i - 1][0], P2[i][1] - P2[i - 1][1]);
337
+ var col = two ? s.col : "var(--emph)";
338
+ var path = D.el("path", {d: P2.map(function(q, i){ return (i ? "L" : "M") + q[0].toFixed(1) + "," + q[1].toFixed(1); }).join(""), fill: "none", stroke: col, "stroke-width": 3.5, "stroke-linejoin": "round", opacity: 0}, gP);
339
+ var acc = 0, vs = P2.map(function(q, i){ if (i) acc += Math.hypot(q[0] - P2[i - 1][0], q[1] - P2[i - 1][1]); return {c: D.el("circle", {cx: q[0].toFixed(1), cy: q[1].toFixed(1), r: 5.5, fill: col, opacity: 0}, gP), f: len ? acc / len : 0}; });
340
+ s.poly = {path: path, len: len, vs: vs};
341
+ });
342
+ }
343
+ } else {
344
+ // ドットプロット:値(bins を書けば階級値)の上に、出てきた順に下から積む
345
+ var pos = function(v){ return pl.given ? bins.mids[S.binOf(v, bins.start, bins.width)] : v; };
346
+ var stack = {}, maxS = 1, xs = [];
347
+ pl.ser.forEach(function(s){ s.dpos = s.values.map(function(v){ var x = pos(v), k = String(x); stack[k] = (stack[k] || 0) + 1; maxS = Math.max(maxS, stack[k]); if (xs.indexOf(x) < 0) xs.push(x); return {x: x, lv: stack[k] - 1}; }); });
348
+ xs.sort(function(a2, b2){ return a2 - b2; });
349
+ var gapPx = Infinity; for (var i2 = 1; i2 < xs.length; i2++) gapPx = Math.min(gapPx, p.x(xs[i2]) - p.x(xs[i2 - 1]));
350
+ if (pl.given) gapPx = Math.min(gapPx, p.x(bins.edges[1]) - p.x(bins.edges[0]));
351
+ var R = Math.min(15, (y1 - y0 - 8) / (2 * maxS) - 1.5, isFinite(gapPx) ? gapPx / 2 - 1.5 : 15);
352
+ if (R < 4){ ctx.report("size", "[hist] the dots are too small (" + R.toFixed(1) + " px); give the element more height or fewer values"); R = Math.max(R, 2); }
353
+ this.R = R;
354
+ var shapes = [function(r){ return "M" + r + ",0A" + r + "," + r + " 0 1,1 " + (-r) + ",0A" + r + "," + r + " 0 1,1 " + r + ",0Z"; },
355
+ function(r){ var s2 = r * 0.86; return "M" + (-s2) + "," + (-s2) + "H" + s2 + "V" + s2 + "H" + (-s2) + "Z"; }];
356
+ pl.ser.forEach(function(s, si){
357
+ s.dots = s.dpos.map(function(o){
358
+ var cx = p.x(o.x), cy = y1 - 3 - R - o.lv * (2 * R + 3);
359
+ return {cx: cx, cy: cy, lv: o.lv, g: D.el("path", {d: shapes[si](R), transform: "translate(" + cx.toFixed(1) + " " + cy.toFixed(1) + ")", fill: s.col, "fill-opacity": 0.9, opacity: 0}, gB)};
360
+ });
361
+ s.maxLv = Math.max.apply(null, s.dots.map(function(o){ return o.lv; }));
362
+ });
363
+ }
364
+ // 系列の名前(2 つのとき)
365
+ var lx = W - m.r;
366
+ pl.ser.slice().reverse().forEach(function(s, ri){
367
+ if (!legendH) return;
368
+ var si = pl.ser.length - 1 - ri, w = est(s.label, 24), sx = lx - w - 12 - 30;
369
+ var g = D.el("g", {opacity: 0}, gT);
370
+ if (dots) D.el("path", {d: si ? "M-10,-10H10V10H-10Z" : "M12,0A12,12 0 1,1 -12,0A12,12 0 1,1 12,0Z", fill: s.col, transform: "translate(" + (sx + 15) + " 24)"}, g);
371
+ else { var sw = D.el("rect", {x: sx, y: 13, width: 30, height: 22, fill: s.col, "fill-opacity": 0.16, stroke: s.col, "stroke-width": 3}, g); if (si) sw.setAttribute("stroke-dasharray", "8 5"); }
372
+ D.mtext(g, sx + 40, 33, s.label, {"font-size": 24, "font-weight": 700, fill: s.col});
373
+ s.leg = g; lx = sx - 32;
374
+ });
375
+ // 代表値の印:軸から名前の行まで伸びる線と名前
376
+ this.flags = flags.map(function(f){
377
+ var base = y0 - 14 - f.row * 34, tipY = base - 9;
378
+ var lines = f.r.xs.map(function(x, j){
379
+ var ln = D.el("line", {x1: p.x(x).toFixed(1), x2: p.x(x).toFixed(1), y1: y1, y2: j ? y0 - 4 : tipY, stroke: f.col, "stroke-width": 3.5, "stroke-linecap": "round", opacity: 0}, gM);
380
+ if (f.dash) ln.setAttribute("stroke-dasharray", f.dash);
381
+ return {el: ln, top: j ? y0 - 4 : tipY};
382
+ });
383
+ var tx = D.mtext(gT, f.a === "start" ? f.x + 8 : f.x - 8, base, f.text, {"text-anchor": f.a, "font-size": 24, "font-weight": 700, fill: f.col, opacity: 0});
384
+ return {f: f, lines: lines, text: tx};
385
+ });
386
+ // 読み上げ:最後の形(階級ごとの度数と代表値)を 1 文で。図の svg は読ませない。作者の aria-label があればそれを使う(上書きしない)
387
+ p.svg.setAttribute("aria-hidden", "true");
388
+ if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
389
+ this.setAttribute("role", "img");
390
+ if (!this._aria) this.setAttribute("aria-label", this.summary(ja, flags, heights));
391
+ function niceStep(r, whole){ var e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e, s3 = (x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e; return whole ? (s3 === 2.5 ? 2 : Math.max(1, Math.round(s3))) : S.clean(s3); }
392
+ // ドットプロットの目盛り:整数の値で幅が 24 までなら 1 ずつ
393
+ function dotStep(span){ var allInt = pl.ser.every(function(s){ return s.values.every(function(v){ return v === Math.floor(v); }); }); return allInt && span <= 24 ? 1 : niceStep(Math.max(span, 1e-9) / 8, allInt); }
394
+ }
395
+ // 最後の形を 1 文で(読み上げの名前):「ヒストグラム(記録(m)):15〜20 は 2、20〜25 は 3、…(計 10)。平均値 26.2、中央値 26.5」。
396
+ // 系列が 2 つなら系列ごとに。相対度数・累積度数のときは度数の後ろに()で。階級を書かないドットプロットは値ごとの数。
397
+ // flags は mount の代表値の名前、heights は mount の高さの関数
398
+ summary(ja, flags, heights){
399
+ var self = this, P = this.props, pl = this.plan(), bins = pl.bins, sep = ja ? "、" : ", ", MAX = 20;
400
+ var num = function(v){ return String(v).replace(/^-/, "−"); };
401
+ var head = (pl.kind === "dots" ? (ja ? "ドットプロット" : "Dot plot") : (ja ? "ヒストグラム" : "Histogram")) + (P.xl ? (ja ? "(" + P.xl + ")" : " (" + P.xl + ")") : "");
402
+ var per = pl.ser.map(function(s){
403
+ var parts;
404
+ if (bins){
405
+ var h = pl.rel || pl.cum ? heights(s.counts, s.n) : null;
406
+ parts = s.counts.map(function(c, b){
407
+ var x = h ? (ja ? "(" : " (") + (pl.cum ? (ja ? "累積 " : "cumulative ") : "") + (pl.rel ? self.rel2(h[b]) : h[b]) + (ja ? ")" : ")") : "";
408
+ return num(bins.edges[b]) + (ja ? "〜" : "–") + num(bins.edges[b + 1]) + (ja ? " は " : ": ") + c + x;
409
+ });
410
+ } else {
411
+ var cnt = {}, xs = [];
412
+ s.values.forEach(function(v){ if (!cnt[v]) xs.push(v); cnt[v] = (cnt[v] || 0) + 1; });
413
+ parts = xs.sort(function(a, b){ return a - b; }).map(function(v){ return self.fmt(v) + (ja ? " が " : ": ") + cnt[v]; });
414
+ }
415
+ var n = parts.length;
416
+ if (n > MAX){ parts = parts.slice(0, MAX); parts.push(ja ? "…(全 " + n + (bins ? " 階級)" : " 個の値)") : "… (" + n + (bins ? " classes)" : " values)")); }
417
+ return (s.label ? s.label + (ja ? " " : ": ") : "") + parts.join(sep) + (ja ? "(計 " + s.n + ")" : " (total " + s.n + ")");
418
+ });
419
+ var mk = flags.map(function(f){ return (pl.ser.length > 1 && f.s.label ? f.s.label + " " : "") + f.text; });
420
+ return head + (ja ? ":" : ": ") + per.join(ja ? "。" : "; ") + (mk.length ? (ja ? "。" : ". ") + mk.join(sep) : "");
421
+ }
422
+ duration(k){
423
+ var P = this.props, pl = this.plan(), d = 0;
424
+ if (pl.build === "bins"){ if (k >= 1 && k <= pl.bins.nb) d = P.dur * 0.75; }
425
+ else pl.ser.forEach(function(s){ if (s.step === k) d = Math.max(d, s.len); });
426
+ if (k === pl.polyStep) d = Math.max(d, P.dur);
427
+ pl.marks.forEach(function(mk){ if (mk.step === k) d = Math.max(d, 0.7); });
428
+ return d;
429
+ }
430
+ render(k, t, ctx){
431
+ var P = this.props, D = base, pl = this.plan(), self = this, vr = this.variant, lecture = !!ctx.preview, p = this.p, g = this.geo, dur = P.dur;
432
+ // 段階 st の、時刻 at から len 秒の進み(授業の表示では先の段階を薄く:-1 を返す)
433
+ var ph = function(st, at, len){ return st < k ? 1 : st > k ? (lecture ? -1 : 0) : D.prog(t, at, len); };
434
+ var FAINT = 0.45;
435
+ if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
436
+ var binStep = function(b){ return pl.build === "bins" ? b + 1 : null; };
437
+ pl.ser.forEach(function(s){
438
+ if (s.leg){ var le = ph(pl.build === "bins" ? 1 : s.step, 0, 0.4); s.leg.setAttribute("opacity", (le < 0 ? FAINT : le).toFixed(3)); }
439
+ if (pl.kind === "dots"){
440
+ // 点:values は 1 つずつ落ちる。whole の fade はそろってフェード、grow は下の段から順に
441
+ var st = s.step, tt = st < k ? Infinity : st > k ? -1 : t;
442
+ s.dots.forEach(function(o, j){
443
+ var op = 1, dy = 0;
444
+ if (st > k){ op = lecture ? FAINT : 0; }
445
+ else if (tt !== Infinity){
446
+ if (pl.build === "values"){ var e = D.prog(tt, j * s.gap, pl.DROP); op = tt >= j * s.gap ? 1 : 0; dy = (1 - e) * (o.cy - (g.y0 - 10)); }
447
+ else if (vr === "grow"){ var span = dur * 0.7, sl = s.maxLv > 0 ? (span - 0.2) / (s.maxLv) : 0; op = D.prog(tt, o.lv * sl, 0.2); }
448
+ else op = D.prog(tt, 0, dur * 0.7);
449
+ }
450
+ o.g.setAttribute("opacity", op.toFixed(3));
451
+ o.g.setAttribute("transform", "translate(" + o.cx.toFixed(1) + " " + (o.cy - dy).toFixed(1) + ")");
452
+ });
453
+ return;
454
+ }
455
+ // 柱状グラフ
456
+ var vals = pl.build === "values" ? null : s.H, cur = s.H.slice(), fall = null;
457
+ if (pl.build === "values"){
458
+ var st2 = s.step;
459
+ if (st2 < k || (st2 > k && lecture)) cur = s.H.slice();
460
+ else if (st2 > k) cur = s.H.map(function(){ return 0; });
461
+ else {
462
+ // 落ちきった値だけを数える
463
+ var cb = s.counts.map(function(){ return 0; });
464
+ s.values.forEach(function(v, j){ if (t >= j * s.gap + pl.DROP) cb[s.drops[j].b]++; });
465
+ cur = self.heights(cb, s.n);
466
+ fall = true;
467
+ }
468
+ }
469
+ s.rects.forEach(function(r, b){
470
+ var st3 = pl.build === "bins" ? binStep(b) : s.step, e = ph(st3, 0, pl.build === "bins" ? dur * 0.75 : dur), h = cur[b], op = 1;
471
+ if (pl.build === "values"){ op = st3 > k ? (lecture ? FAINT : 0) : 1; e = 1; }
472
+ else if (e < 0){ op = FAINT; e = 1; }
473
+ else if (vr === "grow"){ h = s.H[b] * e; op = e > 0 ? 1 : 0; }
474
+ else op = e;
475
+ var yy = p.y(Math.max(0, h));
476
+ r.setAttribute("y", yy.toFixed(1)); r.setAttribute("height", Math.max(0, g.y1 - yy).toFixed(1));
477
+ r.setAttribute("opacity", (h > 0 ? op : 0).toFixed(3));
478
+ var nt = s.nums[b];
479
+ if (nt){
480
+ var no = pl.build === "values" ? (st3 > k ? (lecture ? FAINT : 0) : 1) : (function(){ var e2 = ph(st3, (pl.build === "bins" ? dur * 0.75 : dur) * 0.55, (pl.build === "bins" ? dur * 0.75 : dur) * 0.45); return e2 < 0 ? FAINT : e2; })();
481
+ var hv = pl.build === "values" ? h : s.H[b];
482
+ nt.textContent = pl.rel ? self.rel2(hv) : String(Math.round(hv));
483
+ nt.setAttribute("y", (p.y(pl.build === "values" ? h : s.H[b]) - 8).toFixed(1));
484
+ nt.setAttribute("opacity", (hv > 0 ? no : 0).toFixed(3)); // 度数 0 の階級には書かない
485
+ }
486
+ });
487
+ if (s.fall) s.fall.forEach(function(f, j){
488
+ var o = s.drops[j], on = fall && t >= j * s.gap && t < j * s.gap + pl.DROP;
489
+ if (!on){ f.g.setAttribute("opacity", 0); return; }
490
+ var e = D.prog(t, j * s.gap, pl.DROP), yTop = p.y(o.after), yBot = p.y(o.before), hh = Math.max(4, yBot - yTop);
491
+ var y = D.lerp(g.y0 - hh - 6, yTop, e);
492
+ f.rect.setAttribute("height", Math.max(0, hh).toFixed(1));
493
+ f.g.setAttribute("transform", "translate(" + p.x(pl.bins.mids[o.b]).toFixed(1) + " " + y.toFixed(1) + ")");
494
+ f.g.setAttribute("opacity", 1);
495
+ });
496
+ if (s.poly){
497
+ var e3 = ph(pl.polyStep, 0, dur), po = s.poly;
498
+ if (e3 < 0){ po.path.setAttribute("opacity", FAINT); po.path.removeAttribute("stroke-dasharray"); po.path.removeAttribute("stroke-dashoffset"); po.vs.forEach(function(v){ v.c.setAttribute("opacity", FAINT); }); }
499
+ else if (vr === "grow"){
500
+ po.path.setAttribute("stroke-dasharray", po.len.toFixed(1) + " " + (po.len + 10).toFixed(1));
501
+ po.path.setAttribute("stroke-dashoffset", (po.len * (1 - e3)).toFixed(1));
502
+ po.path.setAttribute("opacity", e3 > 0 ? 1 : 0);
503
+ po.vs.forEach(function(v){ v.c.setAttribute("opacity", e3 >= v.f - 1e-6 && e3 > 0 ? 1 : 0); });
504
+ } else { po.path.removeAttribute("stroke-dasharray"); po.path.removeAttribute("stroke-dashoffset"); po.path.setAttribute("opacity", e3.toFixed(3)); po.vs.forEach(function(v){ v.c.setAttribute("opacity", e3.toFixed(3)); }); }
505
+ }
506
+ });
507
+ // 代表値の印:fade は線と名前がフェード、grow は線が軸から上へ伸びてから名前
508
+ this.flags.forEach(function(F){
509
+ var e = ph(F.f.mk.step, 0, 0.7);
510
+ F.lines.forEach(function(L){
511
+ var y2 = L.top, op = e;
512
+ if (e < 0) op = FAINT;
513
+ else if (vr === "grow"){ y2 = D.lerp(g.y1, L.top, D.prog(t === Infinity || F.f.mk.step < k ? Infinity : t, 0, 0.45)); op = e > 0 ? 1 : 0; }
514
+ L.el.setAttribute("y2", y2.toFixed(1)); L.el.setAttribute("opacity", op.toFixed(3));
515
+ });
516
+ var te = vr === "grow" ? ph(F.f.mk.step, 0.35, 0.35) : e;
517
+ F.text.setAttribute("opacity", (te < 0 ? FAINT : te).toFixed(3));
518
+ });
519
+ }
520
+ };
521
+ });