egatari 0.6.17 → 0.6.18
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 +36 -1
- package/README.ja.md +14 -13
- package/README.md +2 -1
- package/components.lock.json +119 -45
- package/components2.lock.json +639 -1
- package/kit/check-messages.mjs +5 -0
- package/kit/check.mjs +6 -0
- package/kit/core/bookmark.mjs +28 -0
- package/kit/core/build-core.mjs +4 -2
- package/kit/core/check-parity.mjs +4 -0
- package/kit/core/check-rules.mjs +3 -2
- package/kit/core/check-source.mjs +6 -0
- package/kit/core/llm-pack-assemble.mjs +37 -66
- package/kit/core/llm-pack-data.mjs +839 -45
- 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 +2 -0
- package/kit/core/purposes.mjs +9 -3
- package/kit/core/sample-info.mjs +17 -3
- package/kit/core/slide-ops.mjs +22 -0
- package/kit/core/tate-mix.mjs +25 -0
- package/kit/core/theme-derive.mjs +56 -17
- package/kit/core/theme-shapes.mjs +15 -1
- package/kit/deck.js +53 -2
- package/kit/instruction-version.json +1 -1
- package/kit/llm-pack.mjs +5 -7
- 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/package.json +1 -1
- package/vendor/components/CATALOG.md +24 -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/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/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/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/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/a1c2b2fa06e4229815ab82a9202c266ec887a67632a175854c7d136a92389ca3/index.js +69 -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/egatari-spec/SOURCE.json +2 -2
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// m-heatmap:値で塗ったセルの格子(混同行列・相関行列・注意の重みなど)。行を 1 段階ずつ、または全体を出し、強調するセルを 1 つずつ囲む
|
|
2
|
+
// <m-heatmap normalize="row" diag="on" xl="予測" yl="正解" style="height:430px">
|
|
3
|
+
// <script type="application/json">{"rows": ["ねこ", "いぬ", "うさぎ"], "cols": ["ねこ", "いぬ", "うさぎ"], "values": [[45, 3, 2], [6, 38, 6], [1, 4, 45]]}
|
|
4
|
+
// (JSON の終わり)</m-heatmap>
|
|
5
|
+
// 色(テーマの色だけ):scale="sequential"(既定)は var(--bg) から tone(var(--term))へ、scale="diverging" は center(既定 0)を地の色に、
|
|
6
|
+
// 上は tone・下は lowtone(var(--emph))へ。どれも color-mix(in oklab, …) で混ぜる。数字の色はセルごとに var(--fg) と var(--bg) の
|
|
7
|
+
// コントラストを計算して高い方(4.5:1 以上)。どちらも 4.5:1 に届かない明るさのセルは、届く所まで混ぜる割合を寄せる
|
|
8
|
+
// 段階:build="rows"(行を 1 つずつ。normalize="row" の既定)・"whole"(全体を 1 段階)・"cells"(全体、それから強調を 1 つずつ。highlight があるときの既定)
|
|
9
|
+
// 字は 24 px 以上:列の名前は長ければ縦に、それでも入らなければ k 個おきに出して知らせる。12×12 を超えるとセルの数字は自動で消える(知らせる)
|
|
10
|
+
// 見せ方(docs/conventions.md §1):fade(セルがフェード、既定)・sweep(同じ段階のセルが左上から順に)
|
|
11
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・prog・variant・previewOpacity と、計算は heatmap-core(1.x の
|
|
12
|
+
// static calc)を使い、プレイヤーのグローバルは使わない。書き方やデータの知らせ(1.x の console.warn)は mount で ctx.report に。
|
|
13
|
+
// 言語は ctx.lang(mount で読む)。凡例のグラデーションの id は heatmap-2-0-2-legend-<n>(1.x は m-heatmap-legend-<n>)
|
|
14
|
+
egatariParts.define({name: "heatmap", version: "2.1.3", requires: {base: "1.3.0", "heatmap-core": "1.0.0"}, element: "m-heatmap"}, function(deps){
|
|
15
|
+
"use strict";
|
|
16
|
+
var base = deps.base;
|
|
17
|
+
// ---- 計算(heatmap-core。tools/test-heatmap.mjs がブラウザなしで試す) ----
|
|
18
|
+
var CALC = deps["heatmap-core"];
|
|
19
|
+
// テーマの色を sRGB で読む(キャンバスに 1 点塗って読む。読めなければ null)。m-map-japan と同じ
|
|
20
|
+
function rgbOf(css){
|
|
21
|
+
try {
|
|
22
|
+
var cv = document.createElement("canvas"); cv.width = cv.height = 1;
|
|
23
|
+
var g = cv.getContext("2d", {willReadFrequently: true});
|
|
24
|
+
if (!g) return null;
|
|
25
|
+
g.fillStyle = "#010203"; g.fillStyle = css;
|
|
26
|
+
if (/^#010203$/i.test(g.fillStyle) && !/^#010203$/i.test(css)) return null;
|
|
27
|
+
g.fillRect(0, 0, 1, 1);
|
|
28
|
+
var d = g.getImageData(0, 0, 1, 1).data;
|
|
29
|
+
return [d[0], d[1], d[2]];
|
|
30
|
+
} catch (e) { return null; }
|
|
31
|
+
}
|
|
32
|
+
// 名前を幅 w(24 px の字で)に収める:入らなければ … で切る
|
|
33
|
+
function clip(s, w, C){
|
|
34
|
+
if (C.est(s, 24) <= w) return s;
|
|
35
|
+
var ch = [...s];
|
|
36
|
+
while (ch.length > 1 && C.est(ch.join("") + "…", 24) > w) ch.pop();
|
|
37
|
+
return ch.join("").replace(/\s+$/, "") + "…";
|
|
38
|
+
}
|
|
39
|
+
var ON = function(v){ return /^(on|true|yes)$/i.test(String(v || "").trim()); };
|
|
40
|
+
var TONES = ["term", "emph", "accent2"];
|
|
41
|
+
var ID = "heatmap-2-1-3-"; // name and version of this part, dots replaced (spec §6.1 Identifiers)
|
|
42
|
+
var SEQ = 0; // 凡例のグラデーションの id(ページの中で部品ごとに別。mount は 1 回だけ。このパーツだけの数え)
|
|
43
|
+
return class extends base.MotionElement {
|
|
44
|
+
static partName = "heatmap"; // the registry name (define meta name), for report prefixes
|
|
45
|
+
static variants = ["fade", "sweep"];
|
|
46
|
+
// データの形(kit/shape.js)
|
|
47
|
+
static shape = {
|
|
48
|
+
schema: {type: "object", additionalProperties: false, required: ["rows", "cols", "values"], properties: {
|
|
49
|
+
rows: {type: "array", minItems: 1, items: {type: "string"}},
|
|
50
|
+
cols: {type: "array", minItems: 1, items: {type: "string"}},
|
|
51
|
+
values: {type: "array", minItems: 1, items: {type: "array", minItems: 1, items: {type: "number"}}},
|
|
52
|
+
unit: {type: "string"}, digits: {type: "number"},
|
|
53
|
+
highlight: {type: "array", items: {type: "array", minItems: 2, maxItems: 3, items: {type: "number"}}}}},
|
|
54
|
+
example: {rows: ["ねこ", "いぬ"], cols: ["ねこ", "いぬ"], values: [[45, 5], [6, 44]]},
|
|
55
|
+
note: {en: "values[row][col], one row per label in rows and one number per label in cols; highlight [[row, col] or [row, col, step]] (0-based)",
|
|
56
|
+
ja: "values[行][列]。rows の名前ごとに 1 行、cols の名前ごとに 1 つの数。highlight は [[行, 列] か [行, 列, ステップ]](0 から数える)"},
|
|
57
|
+
};
|
|
58
|
+
static props = {
|
|
59
|
+
scale: {type: "string", default: "sequential", doc: "sequential か diverging(center を地の色に 2 色)"},
|
|
60
|
+
center: {type: "number", default: 0, doc: "diverging の真ん中の値"},
|
|
61
|
+
range: {type: "json", default: null, doc: "色の範囲 [最小, 最大]"},
|
|
62
|
+
tone: {type: "string", default: "term", doc: "濃い側の色:term・emph・accent2。書かなければテーマの色の階調(なければ term)"},
|
|
63
|
+
lowtone: {type: "string", default: "emph", doc: "diverging の center より下の色"},
|
|
64
|
+
normalize: {type: "string", default: "none", doc: "row:行ごとの割合(混同行列)"},
|
|
65
|
+
show: {type: "string", default: "percent", doc: "normalize=row の数字:percent・count・both"},
|
|
66
|
+
numbers: {type: "string", default: "auto", doc: "セルの数字:auto・on・off"},
|
|
67
|
+
diag: {type: "string", default: "off", doc: "on:対角を枠で強調"},
|
|
68
|
+
build: {type: "string", default: "", doc: "rows・whole・cells"},
|
|
69
|
+
rotate: {type: "string", default: "auto", doc: "列の名前:auto・0・90"},
|
|
70
|
+
xl: {type: "string", default: "", doc: "列の見出し"},
|
|
71
|
+
yl: {type: "string", default: "", doc: "行の見出し"},
|
|
72
|
+
unit: {type: "string", default: undefined, doc: "セルの数字の後ろに付ける単位(JSON の unit より先)"},
|
|
73
|
+
digits: {type: "number", default: undefined, doc: "セルの数字の小数桁(既定は値の桁、2 桁まで。割合は 0)"},
|
|
74
|
+
dur: {type: "number", default: 0.8, doc: "1 ステップの秒数"},
|
|
75
|
+
};
|
|
76
|
+
get steps(){
|
|
77
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
78
|
+
return this.plan().steps;
|
|
79
|
+
}
|
|
80
|
+
// データと属性だけから決まること(mount の前にも steps が要る)
|
|
81
|
+
plan(){
|
|
82
|
+
if (this._plan) return this._plan;
|
|
83
|
+
var d = this.data || {}, P = this.props, notes = [], C = CALC;
|
|
84
|
+
var rows = (d.rows || []).map(String), cols = (d.cols || []).map(String), raw = (d.values || []).map(function(r){ return r.map(Number); });
|
|
85
|
+
if (raw.length !== rows.length) throw new Error("m-heatmap: values has " + raw.length + " rows but rows has " + rows.length + " labels");
|
|
86
|
+
raw.forEach(function(r, i){ if (r.length !== cols.length) throw new Error("m-heatmap: values row " + i + " has " + r.length + " numbers but cols has " + cols.length + " labels"); });
|
|
87
|
+
var norm = P.normalize === "row";
|
|
88
|
+
if (["none", "row"].indexOf(P.normalize) < 0) notes.push(["attr", '[heatmap] normalize="' + P.normalize + '" is not row (none is used)']);
|
|
89
|
+
var kind = P.scale === "diverging" ? "diverging" : "sequential";
|
|
90
|
+
if (["sequential", "diverging"].indexOf(P.scale) < 0) notes.push(["attr", '[heatmap] scale="' + P.scale + '" is not sequential or diverging (sequential is used)']);
|
|
91
|
+
var build = P.build || (norm ? "rows" : (d.highlight || []).length ? "cells" : "whole");
|
|
92
|
+
if (["rows", "whole", "cells"].indexOf(build) < 0){ notes.push(["attr", '[heatmap] build="' + build + '" is not rows, whole or cells (whole is used)']); build = "whole"; }
|
|
93
|
+
var hl = (d.highlight || []).filter(function(h){
|
|
94
|
+
var ok = h[0] >= 0 && h[0] < rows.length && h[1] >= 0 && h[1] < cols.length && h[0] === Math.round(h[0]) && h[1] === Math.round(h[1]);
|
|
95
|
+
if (!ok) notes.push(["data", "[heatmap] highlight [" + h.join(", ") + "] is outside the " + rows.length + "×" + cols.length + " grid (0-based; ignored)"]);
|
|
96
|
+
return ok;
|
|
97
|
+
});
|
|
98
|
+
var shown = norm ? C.normalizeRows(raw) : raw;
|
|
99
|
+
var show = norm ? P.show : "count";
|
|
100
|
+
if (norm && ["count", "percent", "both"].indexOf(show) < 0){ notes.push(["attr", '[heatmap] show="' + show + '" is not count, percent or both (percent is used)']); show = "percent"; }
|
|
101
|
+
if (norm && raw.some(function(r){ return !r.reduce(function(a, v){ return a + v; }, 0); })) notes.push(["data", "[heatmap] a row sums to 0; its proportions are drawn as 0"]);
|
|
102
|
+
// range:2 つの数 [最小, 最大]、最小 < 最大。そうでなければ知らせて、データの範囲に(同じ値は 0 で割り、逆は色が反転する)
|
|
103
|
+
var range = P.range;
|
|
104
|
+
if (range !== null && range !== undefined){
|
|
105
|
+
var okR = Array.isArray(range) && range.length === 2 && typeof range[0] === "number" && typeof range[1] === "number" && isFinite(range[0]) && isFinite(range[1]);
|
|
106
|
+
if (!okR || !(range[0] < range[1])){
|
|
107
|
+
notes.push(["attr", "[heatmap] range=" + JSON.stringify(range) + " is not [min, max] with min < max; the " + (norm ? "range 0 to 1" : "data's range") + " is used"]);
|
|
108
|
+
range = null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
var dom = C.domain(shown, kind, +P.center || 0, norm && !range ? [0, 1] : range);
|
|
112
|
+
var st = C.steps(rows.length, cols.length, build, hl);
|
|
113
|
+
var dec = function(v){ var m = String(v).match(/\.(\d+)$/); return m ? m[1].length : 0; };
|
|
114
|
+
var digits = P.digits !== undefined ? P.digits : d.digits !== undefined ? d.digits : Math.min(2, Math.max.apply(null, [0].concat([].concat.apply([], raw).map(dec))));
|
|
115
|
+
var unit = P.unit !== undefined ? P.unit : d.unit || "";
|
|
116
|
+
return (this._plan = {rows: rows, cols: cols, raw: raw, val: shown, norm: norm, kind: kind, build: build, show: show, dom: dom,
|
|
117
|
+
cell: st.cell, hl: st.hl, steps: st.steps, digits: digits, unit: unit, notes: notes});
|
|
118
|
+
}
|
|
119
|
+
fmt(v, dg){
|
|
120
|
+
var s = Math.abs(v).toFixed(dg), p = s.split("."), i = p[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
121
|
+
return (v < 0 && +s !== 0 ? "−" : "") + i + (p[1] ? "." + p[1] : "");
|
|
122
|
+
}
|
|
123
|
+
// 凡例の数:終わりの 0 を落とす
|
|
124
|
+
lfmt(v){
|
|
125
|
+
var pl = this.plan();
|
|
126
|
+
if (pl.norm) return Math.round(v * 100) + "%";
|
|
127
|
+
var s = this.fmt(v, pl.digits); if (s.indexOf(".") >= 0) s = s.replace(/0+$/, "").replace(/\.$/, "");
|
|
128
|
+
return s + pl.unit;
|
|
129
|
+
}
|
|
130
|
+
// セルの字(1 行か 2 行)
|
|
131
|
+
texts(r, c){
|
|
132
|
+
var pl = this.plan(), cnt = this.fmt(pl.raw[r][c], pl.digits) + pl.unit;
|
|
133
|
+
if (!pl.norm) return [cnt];
|
|
134
|
+
var pct = this.fmt(pl.val[r][c] * 100, this.props.digits !== undefined ? this.props.digits : 0) + "%";
|
|
135
|
+
return pl.show === "count" ? [cnt] : pl.show === "both" ? [cnt, pct] : [pct];
|
|
136
|
+
}
|
|
137
|
+
mount(ctx){
|
|
138
|
+
var P = this.props, D = base, C = CALC, self = this, pl = this.plan();
|
|
139
|
+
this.variant = base.variant(this);
|
|
140
|
+
// 書き方とデータの知らせ(plan が集めた [code, message])
|
|
141
|
+
// ctx.report with each code as a literal (lint checks them): plan's notes are attr or data
|
|
142
|
+
pl.notes.forEach(function(n){ var code = n[0], msg = n[1]; if (code === "attr") ctx.report("attr", msg); else ctx.report("data", msg); });
|
|
143
|
+
this.classList.add("plot"); this.style.display = "block";
|
|
144
|
+
var ja = this.ja = /^ja\b/i.test(ctx.lang), W = this.clientWidth, H = this.clientHeight, nr = pl.rows.length, nc = pl.cols.length;
|
|
145
|
+
// ---- 色:テーマの色を読み、セルごとに混ぜる割合と字の色を決める ----
|
|
146
|
+
var tone = TONES.indexOf(P.tone) >= 0 ? P.tone : "term", low = TONES.indexOf(P.lowtone) >= 0 ? P.lowtone : "emph";
|
|
147
|
+
if (TONES.indexOf(P.tone) < 0) ctx.report("attr", '[heatmap] tone="' + P.tone + '" is not term, emph or accent2 (term is used)');
|
|
148
|
+
if (TONES.indexOf(P.lowtone) < 0) ctx.report("attr", '[heatmap] lowtone="' + P.lowtone + '" is not term, emph or accent2 (emph is used)');
|
|
149
|
+
if (pl.kind === "diverging" && tone === low) ctx.report("attr", "[heatmap] tone and lowtone are the same colour; the two sides cannot be told apart");
|
|
150
|
+
var cs0 = getComputedStyle(this), get = function(v){ return rgbOf(cs0.getPropertyValue(v).trim()); };
|
|
151
|
+
var RGB = {bg: get("--bg"), fg: get("--fg"), term: get("--term"), emph: get("--emph"), accent2: get("--accent2")};
|
|
152
|
+
// 色の段階(spec §8.4 --ramp-1…5):sequential で tone を書いていないときだけ。tone を書けばその役割の色(段階は使わない)。
|
|
153
|
+
// diverging は役割の 2 色のまま。段階のないテーマでは、どの段も 2.6.2 までの色(old)に戻るので同じ色になる
|
|
154
|
+
var useRamp = pl.kind === "sequential" && !this.hasAttribute("tone");
|
|
155
|
+
var stops = useRamp ? D.rampStops(this) : null, SRGB = stops ? stops.map(rgbOf) : null;
|
|
156
|
+
if (SRGB && SRGB.some(function(c){ return !c; })) SRGB = null;
|
|
157
|
+
var oldFill = function(side, pc){ return pc <= 0 ? "var(--bg)" : pc >= 100 ? "var(--" + side + ")" : "color-mix(in oklab, var(--" + side + ") " + pc + "%, var(--bg))"; };
|
|
158
|
+
// 段階の色(解いた RGB):t の両隣の段を oklab で混ぜる(base.ramp と同じ割合)
|
|
159
|
+
var rampRGB = function(t){ var x = Math.max(0, Math.min(1, t)) * 4, k = Math.min(3, Math.floor(x + 1e-9)); return C.mix(SRGB[k], SRGB[k + 1], 1 - (x - k)); };
|
|
160
|
+
var paint = function(f){
|
|
161
|
+
var side = f < 0 ? low : tone, p = Math.abs(f), o;
|
|
162
|
+
if (useRamp && stops && SRGB && RGB.bg && RGB.fg){ o = C.pick(rampRGB(p), RGB.bg, RGB.fg, 1); o.p = p; }
|
|
163
|
+
else if (useRamp && stops) o = {p: p, text: p > 0.55 ? "bg" : "fg", halo: true}; // 段階の色が読めなければ、いつも縁を付ける
|
|
164
|
+
else if (RGB.bg && RGB.fg && RGB[side]) o = C.pick(RGB[side], RGB.bg, RGB.fg, p);
|
|
165
|
+
else o = {p: p, text: p > 0.55 ? "bg" : "fg", halo: true}; // テーマの色が読めなければ、いつも縁を付ける
|
|
166
|
+
var pc = Math.round(o.p * 10000) / 100, old = oldFill(side, pc);
|
|
167
|
+
return {fill: useRamp ? D.ramp(pc / 100, old) : old, text: "var(--" + o.text + ")",
|
|
168
|
+
halo: o.halo ? "var(--" + (o.text === "fg" ? "bg" : "fg") + ")" : null};
|
|
169
|
+
};
|
|
170
|
+
// ---- 配置 ----
|
|
171
|
+
var dm = pl.dom, legend = [this.lfmt(dm.hi), this.lfmt(dm.c), this.lfmt(dm.lo)];
|
|
172
|
+
var lay = function(cols){ return C.layout({W: W, H: H, rows: pl.rows, cols: cols, legend: legend, xl: P.xl, yl: P.yl, rotate: P.rotate}); };
|
|
173
|
+
var cols = pl.cols, L = lay(cols);
|
|
174
|
+
// 長い列の名前:core は名前の幅で列を k 個おきに間引く(数が多いのではないのに「多すぎる」と知らせる)。名前を … で切って
|
|
175
|
+
// どの列にも名前が出る幅を探す(セルがいちばん大きくなる幅のうち、いちばん長い名前)。切っても間引くなら(列の数が多い)元の名前のまま
|
|
176
|
+
if (L.kc > 1){
|
|
177
|
+
var colW0 = Math.max.apply(null, pl.cols.map(function(s){ return C.est(s, 24); })), tries = [];
|
|
178
|
+
for (var cap = colW0 * 0.9; cap >= 24 * 3; cap *= 0.9){
|
|
179
|
+
var cut = pl.cols.map(function(s){ return clip(s, cap, C); }), L2 = lay(cut);
|
|
180
|
+
if (L2.kc === 1) tries.push({L: L2, cols: cut});
|
|
181
|
+
}
|
|
182
|
+
var big = Math.max.apply(null, [0].concat(tries.map(function(o){ return o.L.cs; })));
|
|
183
|
+
var pick = tries.filter(function(o){ return o.L.cs >= big * 0.95; })[0];
|
|
184
|
+
if (pick){
|
|
185
|
+
L = pick.L; cols = pick.cols;
|
|
186
|
+
ctx.report("size", "[heatmap] the column labels are too long for the cells; they are cut with … (shorten them, or give the element more room)");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
L.notes.forEach(function(n){ ctx.report("size", "[heatmap] " + n); });
|
|
190
|
+
var cs = L.cs, fs = L.fs;
|
|
191
|
+
// セルの数字:12×12 を超えたら自動で消す。24 px で入らなければ消す(both は割合だけに)
|
|
192
|
+
var mode = ["auto", "on", "off"].indexOf(P.numbers) >= 0 ? P.numbers : (ctx.report("attr", '[heatmap] numbers="' + P.numbers + '" is not auto, on or off (auto is used)'), "auto");
|
|
193
|
+
var nf = 0, lines = pl.show === "both" ? 2 : 1, all = [];
|
|
194
|
+
for (var r0 = 0; r0 < nr; r0++) for (var c0 = 0; c0 < nc; c0++) all = all.concat(this.texts(r0, c0));
|
|
195
|
+
if (mode === "auto" && (nr > 12 || nc > 12)){ mode = "off"; ctx.report("size", "[heatmap] " + nr + "×" + nc + " cells is more than 12×12; the numbers in the cells are turned off (numbers=\"on\" to keep them where they fit)"); }
|
|
196
|
+
if (mode !== "off"){
|
|
197
|
+
nf = C.numberSize(cs, all, lines);
|
|
198
|
+
if (!nf && lines === 2){
|
|
199
|
+
lines = 1; all = []; for (var r1 = 0; r1 < nr; r1++) for (var c1 = 0; c1 < nc; c1++) all.push(this.texts(r1, c1)[1]);
|
|
200
|
+
nf = C.numberSize(cs, all, 1);
|
|
201
|
+
if (nf) ctx.report("size", '[heatmap] the cells (' + Math.round(cs) + ' px) are too small for two lines at 24 px; show="both" shows the percentages only');
|
|
202
|
+
}
|
|
203
|
+
if (!nf) ctx.report("size", "[heatmap] the cells (" + Math.round(cs) + " px) are too small for numbers at 24 px; the numbers are turned off");
|
|
204
|
+
}
|
|
205
|
+
this.lines = lines;
|
|
206
|
+
var svg = D.el("svg", {width: W, height: H, viewBox: "0 0 " + W + " " + H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
207
|
+
var gGrid = D.el("g", {}, svg), gCell = D.el("g", {}, svg), gOut = D.el("g", {}, svg), gLab = D.el("g", {}, svg);
|
|
208
|
+
var X = function(c){ return L.gx + c * cs; }, Y = function(r){ return L.gy + r * cs; }, f1 = function(v){ return (+v).toFixed(1); };
|
|
209
|
+
var items = this.items = [], dur = P.dur, sweep = this.variant === "sweep";
|
|
210
|
+
// 空の格子(段階 0 から)
|
|
211
|
+
D.el("rect", {x: f1(L.gx), y: f1(L.gy), width: f1(L.gw), height: f1(L.gh), fill: "none", stroke: "var(--line)", "stroke-width": 1.5}, gGrid);
|
|
212
|
+
for (var i = 1; i < nc; i++) D.el("line", {x1: f1(X(i)), y1: f1(L.gy), x2: f1(X(i)), y2: f1(L.gy + L.gh), stroke: "var(--line)", "stroke-width": 1}, gGrid);
|
|
213
|
+
for (i = 1; i < nr; i++) D.el("line", {x1: f1(L.gx), y1: f1(Y(i)), x2: f1(L.gx + L.gw), y2: f1(Y(i)), stroke: "var(--line)", "stroke-width": 1}, gGrid);
|
|
214
|
+
// セル:段階ごとに、見せ方 sweep は左上から順に(同じ段階の中の順番)
|
|
215
|
+
var order = {}, gap = cs >= 16 ? 0.75 : 0; // セルの間の細い隙間(小さいセルでは網目に見えるので付けない)
|
|
216
|
+
for (var r = 0; r < nr; r++) for (var c = 0; c < nc; c++){
|
|
217
|
+
var k = pl.cell[r][c]; (order[k] = order[k] || []).push([r, c]);
|
|
218
|
+
}
|
|
219
|
+
Object.keys(order).forEach(function(k){ order[k].sort(function(a, b){ return (a[0] + a[1]) - (b[0] + b[1]) || a[0] - b[0]; }); });
|
|
220
|
+
for (r = 0; r < nr; r++) for (c = 0; c < nc; c++){
|
|
221
|
+
var st = pl.cell[r][c], pos = order[st].findIndex(function(o){ return o[0] === r && o[1] === c; }), n = order[st].length;
|
|
222
|
+
var pt = paint(C.frac(pl.val[r][c], pl.kind, pl.dom));
|
|
223
|
+
var g = D.el("g", {opacity: 0}, gCell);
|
|
224
|
+
D.el("rect", {x: f1(X(c) + gap), y: f1(Y(r) + gap), width: f1(Math.max(0, cs - 2 * gap)), height: f1(Math.max(0, cs - 2 * gap)), fill: pt.fill}, g);
|
|
225
|
+
if (nf){
|
|
226
|
+
var tx = this.texts(r, c); if (lines === 1 && tx.length === 2) tx = [tx[1]];
|
|
227
|
+
tx.forEach(function(s, j){
|
|
228
|
+
var y = Y(r) + cs / 2 + nf * 0.36 + (tx.length === 2 ? (j ? 0.62 : -0.62) * nf : 0);
|
|
229
|
+
var ta = {x: f1(X(c) + cs / 2), y: f1(y), "font-size": j ? Math.max(24, nf - 4) : nf, "text-anchor": "middle", fill: pt.text, "font-weight": j || tx.length === 1 ? 700 : 400, style: "font-variant-numeric:tabular-nums"};
|
|
230
|
+
// 縁(halo):セルの色に対してどちらの字の色も 4.5:1 に届かないとき、反対の色の 3 px の線を字の下に
|
|
231
|
+
if (pt.halo) Object.assign(ta, {stroke: pt.halo, "stroke-width": 3, "stroke-linejoin": "round", "paint-order": "stroke"});
|
|
232
|
+
D.el("text", ta, g).textContent = s;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
var at = sweep && n > 1 ? dur * 0.6 * pos / (n - 1) : 0, len = sweep ? dur * 0.4 : dur;
|
|
236
|
+
items.push({el: g, st: st, at: at, len: len});
|
|
237
|
+
}
|
|
238
|
+
// 枠(対角は --fg、強調は --emph):地の色の太い線の上に色の線(濃いセルの上でも明るいセルの上でも見える)
|
|
239
|
+
var frame = function(r, c, col, st, at){
|
|
240
|
+
var g = D.el("g", {opacity: 0}, gOut), a = {x: f1(X(c) + 1), y: f1(Y(r) + 1), width: f1(Math.max(0, cs - 2)), height: f1(Math.max(0, cs - 2)), fill: "none"};
|
|
241
|
+
D.el("rect", Object.assign({stroke: "var(--bg)", "stroke-width": 8}, a), g);
|
|
242
|
+
D.el("rect", Object.assign({stroke: col, "stroke-width": 4}, a), g);
|
|
243
|
+
items.push({el: g, st: st, at: at, len: dur * 0.5});
|
|
244
|
+
};
|
|
245
|
+
if (ON(P.diag)) for (i = 0; i < Math.min(nr, nc); i++) frame(i, i, "var(--fg)", pl.cell[i][i], dur * 0.5);
|
|
246
|
+
else if (P.diag !== "off") ctx.report("attr", '[heatmap] diag="' + P.diag + '" is not on or off (off is used)');
|
|
247
|
+
pl.hl.forEach(function(h){ frame(h.r, h.c, "var(--emph)", h.st, h.st === pl.cell[h.r][h.c] ? dur * 0.5 : 0); });
|
|
248
|
+
// ---- 名前(段階 0 から) ----
|
|
249
|
+
var lab = function(x, y, s, a){ return D.el("text", Object.assign({x: f1(x), y: f1(y), "font-size": fs, fill: "var(--fg)"}, a || {}), gLab); };
|
|
250
|
+
C.shown(nr, L.kr).forEach(function(r){ lab(L.gx - 12, Y(r) + cs / 2 + fs * 0.36, pl.rows[r], {"text-anchor": "end"}).textContent = pl.rows[r]; });
|
|
251
|
+
C.shown(nc, L.kc).forEach(function(c){
|
|
252
|
+
var x = X(c) + cs / 2, t;
|
|
253
|
+
if (L.orient === "h") t = lab(x, L.gy - 10, "", {"text-anchor": "middle"});
|
|
254
|
+
else t = lab(x + fs * 0.36, L.gy - 10, "", {"text-anchor": "start", transform: "rotate(-90 " + f1(x + fs * 0.36) + " " + f1(L.gy - 10) + ")"});
|
|
255
|
+
t.textContent = cols[c];
|
|
256
|
+
});
|
|
257
|
+
if (P.xl){ var tl = lab(L.gx + L.gw / 2, L.gy - (L.top - (P.xl ? 40 : 0)) - 12, "", {"text-anchor": "middle", "font-weight": 700, "font-size": 26}); tl.textContent = P.xl; }
|
|
258
|
+
if (P.yl){ var yx = L.x0 + 26, yy = L.gy + L.gh / 2, ty = lab(yx, yy, "", {"text-anchor": "middle", "font-weight": 700, "font-size": 26, transform: "rotate(-90 " + f1(yx) + " " + f1(yy) + ")"}); ty.textContent = P.yl; }
|
|
259
|
+
// ---- 凡例の帯:上が最大、真ん中が center(sequential は真ん中の値)、下が最小 ----
|
|
260
|
+
var bx = L.gx + L.gw + 22, bh = L.gh, gid = ID + "legend-" + (++SEQ);
|
|
261
|
+
// 帯は混ぜる割合をそのまま(セルの字のために寄せた割合ではなく、尺度そのもの)
|
|
262
|
+
var grad = D.el("linearGradient", {id: gid, x1: 0, y1: 0, x2: 0, y2: 1}, D.el("defs", {}, svg));
|
|
263
|
+
for (i = 0; i <= 20; i++){
|
|
264
|
+
var f = C.frac(dm.hi - (dm.hi - dm.lo) * i / 20, pl.kind, dm), pc = Math.round(Math.abs(f) * 10000) / 100, side = f < 0 ? low : tone;
|
|
265
|
+
D.el("stop", {offset: (i / 20).toFixed(3), "stop-color": useRamp ? D.ramp(pc / 100, oldFill(side, pc)) : pc <= 0 ? "var(--bg)" : "color-mix(in oklab, var(--" + side + ") " + pc + "%, var(--bg))"}, grad);
|
|
266
|
+
}
|
|
267
|
+
D.el("rect", {x: f1(bx), y: f1(L.gy), width: 24, height: f1(bh), fill: "url(#" + gid + ")", stroke: "var(--line)", "stroke-width": 1.5}, gGrid);
|
|
268
|
+
var marks = bh >= 3 * 30 ? [[0, legend[0]], [0.5, legend[1]], [1, legend[2]]] : [[0, legend[0]], [1, legend[2]]];
|
|
269
|
+
marks.forEach(function(m){
|
|
270
|
+
var y = L.gy + bh * m[0];
|
|
271
|
+
D.el("line", {x1: f1(bx + 24), y1: f1(y), x2: f1(bx + 30), y2: f1(y), stroke: "var(--muted)", "stroke-width": 1.5}, gGrid);
|
|
272
|
+
lab(bx + 34, Math.max(L.gy + 20, Math.min(L.gy + bh - 2, y + 8)), "", {"font-size": 24, "text-anchor": "start"}).textContent = m[1];
|
|
273
|
+
});
|
|
274
|
+
// ---- 読める層(画面にも印刷にも出ない):値の表 ----
|
|
275
|
+
var wrap = document.createElement("div");
|
|
276
|
+
wrap.className = "sr-only";
|
|
277
|
+
wrap.setAttribute("style", "position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0");
|
|
278
|
+
var tbl = document.createElement("table");
|
|
279
|
+
tbl.setAttribute("style", "font-size:24px");
|
|
280
|
+
var cap = document.createElement("caption"); cap.textContent = this.getAttribute("aria-label") || (P.xl || P.yl ? [P.yl, P.xl].filter(Boolean).join(ja ? " × " : " by ") : (ja ? "ヒートマップ" : "Heat map")); tbl.appendChild(cap);
|
|
281
|
+
var tr = document.createElement("tr"), th = document.createElement("th"); th.textContent = ja ? "行\列" : "row \\ column"; tr.appendChild(th);
|
|
282
|
+
pl.cols.forEach(function(s){ var x = document.createElement("th"); x.setAttribute("scope", "col"); x.textContent = s; tr.appendChild(x); });
|
|
283
|
+
tbl.appendChild(tr);
|
|
284
|
+
pl.rows.forEach(function(s, r){
|
|
285
|
+
var row = document.createElement("tr"), h = document.createElement("th"); h.setAttribute("scope", "row"); h.textContent = s; row.appendChild(h);
|
|
286
|
+
pl.cols.forEach(function(_, c){
|
|
287
|
+
var x = document.createElement("td"), t = self.texts(r, c);
|
|
288
|
+
var hit = pl.hl.some(function(o){ return o.r === r && o.c === c; });
|
|
289
|
+
x.textContent = (t.length === 2 ? t[0] + "(" + t[1] + ")" : t[0]) + (hit ? (ja ? "(強調)" : " (highlighted)") : "");
|
|
290
|
+
row.appendChild(x);
|
|
291
|
+
});
|
|
292
|
+
tbl.appendChild(row);
|
|
293
|
+
});
|
|
294
|
+
wrap.appendChild(tbl); this.appendChild(wrap);
|
|
295
|
+
if (!this.getAttribute("aria-label")) this.setAttribute("aria-label", (ja ? "ヒートマップ:" : "Heat map: ") + nr + " × " + nc);
|
|
296
|
+
}
|
|
297
|
+
duration(k){
|
|
298
|
+
var pl = this.plan();
|
|
299
|
+
if (k < 1) return 0;
|
|
300
|
+
var any = pl.cell.some(function(row){ return row.indexOf(k) >= 0; }) || pl.hl.some(function(h){ return h.st === k; });
|
|
301
|
+
return any ? this.props.dur : 0;
|
|
302
|
+
}
|
|
303
|
+
render(k, t, ctx){
|
|
304
|
+
var D = base, lecture = !!ctx.preview, FAINT = 0.45;
|
|
305
|
+
if (lecture) FAINT = base.previewOpacity(this); // 先の段階の薄さ:テーマの --preview-opacity(ないときは 0.45)
|
|
306
|
+
this.items.forEach(function(it){
|
|
307
|
+
var op = it.st < k ? 1 : it.st > k ? (lecture ? FAINT : 0) : D.prog(t, it.at, it.len);
|
|
308
|
+
it.el.setAttribute("opacity", op.toFixed(3));
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// contour-core 1.0.0: contour lines of a field sampled on a grid (a library part, Egatari spec §6.1), by marching squares.
|
|
2
|
+
// Pure functions of their arguments: no DOM, no state. m-classify2d requires it now and m-contour will. The values come from
|
|
3
|
+
// the author's script; this only draws where a level crosses them (linear interpolation along each cell edge).
|
|
4
|
+
// values: ny rows of nx numbers; values[j][i] is the field at column i, row j. Coordinates out are in grid units:
|
|
5
|
+
// x = i (0 … nx−1), y = j (0 … ny−1). The caller maps them to its axes.
|
|
6
|
+
// returns {segments, lines, labelAt, rangeOf}
|
|
7
|
+
egatariParts.define({name: "contour-core", version: "1.0.0", requires: {}}, function(){
|
|
8
|
+
"use strict";
|
|
9
|
+
// Each cell's crossing segments. Saddle cells (two opposite corners above) are split by the cell's mean, the usual rule.
|
|
10
|
+
function segments(values, level){
|
|
11
|
+
var out = [], ny = values.length, nx = ny ? values[0].length : 0;
|
|
12
|
+
for (var j = 0; j + 1 < ny; j++) for (var i = 0; i + 1 < nx; i++){
|
|
13
|
+
var a = values[j][i], b = values[j][i + 1], c = values[j + 1][i + 1], d = values[j + 1][i];
|
|
14
|
+
if (![a, b, c, d].every(Number.isFinite)) continue;
|
|
15
|
+
var k = (a >= level ? 1 : 0) | (b >= level ? 2 : 0) | (c >= level ? 4 : 0) | (d >= level ? 8 : 0);
|
|
16
|
+
if (k === 0 || k === 15) continue;
|
|
17
|
+
var t = function(p, q){ return q === p ? 0.5 : (level - p) / (q - p); };
|
|
18
|
+
var top = [i + t(a, b), j], right = [i + 1, j + t(b, c)], bottom = [i + t(d, c), j + 1], left = [i, j + t(a, d)];
|
|
19
|
+
var mid = (a + b + c + d) / 4 >= level;
|
|
20
|
+
switch (k){
|
|
21
|
+
case 1: case 14: out.push([left, top]); break;
|
|
22
|
+
case 2: case 13: out.push([top, right]); break;
|
|
23
|
+
case 3: case 12: out.push([left, right]); break;
|
|
24
|
+
case 4: case 11: out.push([right, bottom]); break;
|
|
25
|
+
case 6: case 9: out.push([top, bottom]); break;
|
|
26
|
+
case 7: case 8: out.push([left, bottom]); break;
|
|
27
|
+
case 5: if (mid){ out.push([left, bottom], [top, right]); } else { out.push([left, top], [right, bottom]); } break;
|
|
28
|
+
case 10: if (mid){ out.push([left, top], [right, bottom]); } else { out.push([left, bottom], [top, right]); } break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
// Join segments that share an end into polylines (ends are compared after rounding to 1e-9 grid units).
|
|
34
|
+
function lines(values, level){
|
|
35
|
+
var segs = segments(values, level), key = function(p){ return Math.round(p[0] * 1e9) + "," + Math.round(p[1] * 1e9); };
|
|
36
|
+
var ends = {}, used = new Array(segs.length).fill(false), out = [];
|
|
37
|
+
segs.forEach(function(s, n){ [0, 1].forEach(function(e){ var k = key(s[e]); (ends[k] = ends[k] || []).push([n, e]); }); });
|
|
38
|
+
var next = function(p){ var list = ends[key(p)] || []; for (var m = 0; m < list.length; m++) if (!used[list[m][0]]) return list[m]; return null; };
|
|
39
|
+
for (var n = 0; n < segs.length; n++){
|
|
40
|
+
if (used[n]) continue;
|
|
41
|
+
used[n] = true;
|
|
42
|
+
var line = [segs[n][0], segs[n][1]], h;
|
|
43
|
+
while ((h = next(line[line.length - 1]))){ used[h[0]] = true; line.push(segs[h[0]][1 - h[1]]); }
|
|
44
|
+
while ((h = next(line[0]))){ used[h[0]] = true; line.unshift(segs[h[0]][1 - h[1]]); }
|
|
45
|
+
out.push(line);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
// The point at a fraction f (default ½) of a polyline's length, with the angle (radians) of the segment there.
|
|
50
|
+
function labelAt(line, f){
|
|
51
|
+
var L = 0, i, seg = [];
|
|
52
|
+
for (i = 1; i < line.length; i++){ var d = Math.hypot(line[i][0] - line[i - 1][0], line[i][1] - line[i - 1][1]); seg.push(d); L += d; }
|
|
53
|
+
var want = L * (f === undefined ? 0.5 : f);
|
|
54
|
+
for (i = 0; i < seg.length; i++){
|
|
55
|
+
if (want <= seg[i] || i === seg.length - 1){
|
|
56
|
+
var u = seg[i] ? Math.min(1, want / seg[i]) : 0, p = line[i], q = line[i + 1];
|
|
57
|
+
return {x: p[0] + (q[0] - p[0]) * u, y: p[1] + (q[1] - p[1]) * u, angle: Math.atan2(q[1] - p[1], q[0] - p[0]), length: L};
|
|
58
|
+
}
|
|
59
|
+
want -= seg[i];
|
|
60
|
+
}
|
|
61
|
+
return {x: line[0][0], y: line[0][1], angle: 0, length: 0};
|
|
62
|
+
}
|
|
63
|
+
function rangeOf(values){
|
|
64
|
+
var lo = Infinity, hi = -Infinity;
|
|
65
|
+
values.forEach(function(r){ r.forEach(function(v){ if (Number.isFinite(v)){ if (v < lo) lo = v; if (v > hi) hi = v; } }); });
|
|
66
|
+
return [lo, hi];
|
|
67
|
+
}
|
|
68
|
+
return {segments: segments, lines: lines, labelAt: labelAt, rangeOf: rangeOf};
|
|
69
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Code notes
|
|
3
|
+
steps: Code → notes → output (n+1/+2)
|
|
4
|
+
props:
|
|
5
|
+
dur: Seconds
|
|
6
|
+
size: Text px
|
|
7
|
+
outputPos: Output
|
|
8
|
+
example: {"lang":"python","code":"import pandas as pd\ndf = pd.read_csv(\"sales.csv\")\ndf.groupby(\"store\")[\"sales\"].mean()","steps":[{"lines":[1],"note":"Load pandas"},{"lines":[2],"note":"Read CSV"},{"lines":[3],"note":"Mean"}],"output":"store\nA 120.5\nB 98.0"}
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`<m-code>` child JSON.
|
|
12
|
+
|
|
13
|
+
- `code`: 440px shows 9 lines of 76 chars; longer lines wrap, more scroll in a window (≤16; else split).
|
|
14
|
+
- `lang`; `steps[{lines,note}]`: `[3]`, range `[3,4]`, or 3+ lines `[2,5,9]`; notes ≤30 chars.
|
|
15
|
+
- `output`: ≤8 lines.
|
|
16
|
+
|
|
17
|
+
Script: explain each line; never read code aloud.
|
|
18
|
+
|
|
19
|
+
<!-- llm: omit -->
|
|
20
|
+
Displays supplied text; never runs code. Code first, then highlights and notes. Beside: natural code width ≤55% and every note fits; earlier notes stay muted, all shown at completion. Otherwise band: only the current note, prefixed “lines 3–4”. Final/print: numbered compact list, no code highlight. If the list needs more height, report and keep the last numbered note. Deterministic seeking. Fit layout (2.2.0), only when the 2.1.0 layout would not fit (same pixels otherwise): band notes up to 2 rows; long lines wrap after a space, comma or opening bracket under a "↪" gutter; a window per step centred on its lines, "⋮ n" for hidden rows (it changes in the step's first half, then shows in the second); a final list that does not fit keeps the last note with `data-fit="last-note"` (no report); a window under 3 rows reports size. Full source and output in `pre[data-readable]`. Preview uses --preview-opacity; the final list previews before notes begin.
|
|
21
|
+
|
|
22
|
+
dur .6s; size 0=24px code/26px notes, otherwise ≥24. outputPos auto/below/right. Beside auto: right for ≤8 lines when columns fit. Band auto: right when natural code width ≤70% and output fits, else below the band. Explicit right/below retained. Bad props report/default.
|
|
23
|
+
|
|
24
|
+
Colours are theme roles: for Python, R, shell and JavaScript (js), keywords term, strings accent2 (Python triple quotes and JS templates span lines), # (JS //) comments outside strings muted, the rest fg; other languages stay fg. Code reads the same without colour. `[[3,4]]` reads as `[3,4]`; two ranges in one step report range. Tabs: four spaces. Monospace width .6em, wide characters 1em. Full-width band mode at 1184px/24px fits 77 ASCII characters with single-digit line numbers, 76 with two digits. Beside notes/right output reduce this. Beside notes wrap/stack with connectors; each band note is one truncated row.
|
|
25
|
+
|
|
26
|
+
Default height, one band row, right/no output: header 50 + n × row 34 + padding 16 + gap 8 + band 58 = **132 + 34n px**. General: r=ceil(1.4×size), header=r+16, b=ceil(1.45×note px+4)+16; H=header+n×r+16+8+b. No notes: omit 8+b. Below output adds 16+header+output rows×r+16. Final list (24px, 35px rows) packs “3–4: note” items; each row beyond one adds 35px. Auto output that would go below sits beside the band when its natural width ≤45%; the zone is then max(band, output). Every “give the element about H px” uses this formula; above 440px (body under a heading) reports give lines that fit at 440px and say fewer lines/shorter notes/split instead. If only the list misses, all code stays and the final state keeps the last note.
|
|
27
|
+
|
|
28
|
+
| Height | Code lines (one band row) |
|
|
29
|
+
|---|---|
|
|
30
|
+
| 380px | 7 (needs 370px) |
|
|
31
|
+
| 440px | 9 (438px) |
|
|
32
|
+
| 540px | 12 (540px) |
|
|
33
|
+
| 680px | 16 (676px) |
|
|
34
|
+
|
|
35
|
+
A 59-character line exceeds 70% width: auto output goes below. Seven lines + band + one output row need 486px; two output rows need 520px. Without output, 380px fits. Separate layout reports give line count/capacity/needed height, longest line/character capacity, or note index/width/capacity/target length. Oversize text truncates with …; tiny elements retain clipped content and numeric size reports. Code ≤16 lines, output ≤8. Invalid ranges report; no highlight/connector, notes/steps preserved.
|
|
36
|
+
|
|
37
|
+
ctx.lang ja/en. Figure role; author label preserved; SVG hidden. Full source/output in non-focusable sr-only pre. All notes remain in the accessible summary. Fictional sales data.
|
|
38
|
+
<!-- llm: end -->
|