egatari 0.6.11 → 0.6.12
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 +33 -1
- package/bin/egatari.mjs +4 -3
- package/components.lock.json +30 -15
- package/components2.lock.json +201 -1
- package/fonts/@fontsource/fraunces/400.css +29 -0
- package/fonts/@fontsource/fraunces/700.css +29 -0
- package/fonts/@fontsource/fraunces/LICENSE +93 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-400-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-700-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-400-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-latin-ext-700-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-400-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/files/fraunces-vietnamese-700-normal.woff2 +0 -0
- package/fonts/@fontsource/fraunces/package.json +6 -0
- package/kit/check-messages.mjs +18 -7
- package/kit/check.mjs +12 -4
- package/kit/core/article-render.mjs +5 -5
- package/kit/core/build-core.mjs +25 -9
- package/kit/core/check-parity.mjs +1 -1
- package/kit/core/check-rules.mjs +2 -2
- package/kit/core/check-source.mjs +3 -0
- package/kit/core/colab-core.mjs +1 -1
- package/kit/core/kicker.mjs +42 -0
- package/kit/core/layout-scan.mjs +19 -7
- package/kit/core/llm-pack-data.mjs +8 -8
- package/kit/core/llm-pack.mjs +2 -2
- package/kit/core/theme-shapes.mjs +3 -1
- package/kit/core/themes-list.mjs +2 -0
- package/kit/instruction-version.json +1 -1
- package/kit/layouts.css +8 -0
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/package.json +2 -1
- package/themes/asagi/theme.json +1 -1
- package/themes/asagi/tokens.css +6 -0
- package/themes/bengara/theme.json +13 -0
- package/themes/bengara/tokens.css +66 -0
- package/themes/business/theme.json +1 -1
- package/themes/business/tokens.css +6 -0
- package/themes/default/theme.json +1 -1
- package/themes/default/tokens.css +9 -0
- package/themes/kogecha/theme.json +1 -1
- package/themes/kogecha/tokens.css +6 -0
- package/themes/kokugo/theme.json +1 -1
- package/themes/kokugo/tokens.css +6 -0
- package/themes/murasaki/theme.json +1 -1
- package/themes/murasaki/tokens.css +6 -0
- package/themes/sumi/theme.json +1 -1
- package/themes/sumi/tokens.css +8 -0
- package/themes/tokiwa/theme.json +1 -1
- package/themes/tokiwa/tokens.css +6 -0
- package/themes.lock.json +90 -24
- package/vendor/components/CATALOG.md +11 -11
- package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/README.en.md +38 -0
- package/vendor/components/sha256/04626b77b3c683fd4c8e549339eca153615e021eb0e649c31291deb2dab30667/index.js +289 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/chords.json +89 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/extras.json +192 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/fixtures/ties.json +360 -0
- package/vendor/components/sha256/0c4eb83646ab8027d40697db161eb952425db78c42b36291626214d5064b9498/index.js +508 -0
- package/vendor/components/sha256/0dc2a0945e7a4004278fcc9b8f02223bbb87f6269bffe3dd3ebeb3a78ce23d34/index.js +404 -0
- package/vendor/components/sha256/0e2e45b024bb2f37e82c83a4d9cd9f9c16b5dc4924dde81735c268a3d49f9d7f/index.js +97 -0
- package/vendor/components/sha256/0ef62e33d330f8e31ccb1f480b5e3b349769a142cc2737a9e6583d5eff9f56ca/index.js +919 -0
- package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/README.en.md +48 -0
- package/vendor/components/sha256/1b33a252d51091e2d8cdea176f10268f128640bed3aa46da88d7de31ced59b44/index.js +384 -0
- package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/README.en.md +34 -0
- package/vendor/components/sha256/1b767b6cf1855156872f87981a7c99f0161013499d6c4b21785624435db92078/index.js +244 -0
- package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/README.en.md +44 -0
- package/vendor/components/sha256/3ace61e46a4555eab46ca8053db2fb76a874d4d5409bc5891cc449f43ef7e0bd/index.js +304 -0
- package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/README.en.md +44 -0
- package/vendor/components/sha256/4079077e03343995edc5e34b8bda0cf200dc6d854a52486fe0a6a4ceaf0d4b6f/index.js +203 -0
- package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/README.en.md +37 -0
- package/vendor/components/sha256/40aaaaf988e7c32460ffaf5f18b5690ee28fd1fe7e879d8434d58283992bc554/index.js +438 -0
- package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/README.en.md +24 -0
- package/vendor/components/sha256/442be174439d106ef462c19d598c407e86d5de3fcd4700ed54ae4147c4b9969c/index.js +103 -0
- package/vendor/components/sha256/48a776e7683e1aba8cad5aa4067914c017681efaa74f175066e0ab081bf3d013/index.js +351 -0
- package/vendor/components/sha256/4a9331635c2dd28e4b46108eaffe49c6d29cf626ecb900ac6e9029552be0cf49/index.js +607 -0
- package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/README.en.md +23 -0
- package/vendor/components/sha256/5458baef7a30298cf4b0029331f13233d162403e686f9c20085dd2104cad7141/index.js +120 -0
- package/vendor/components/sha256/586063d3a4e24e2995923811b2b9466bde86dbaafb3bcf103546d3f28159205a/index.js +812 -0
- package/vendor/components/sha256/5acc5f87e29f1170bc35dbee08087d0d03c1023969c6c1b1367a0f559d60e5ee/index.js +198 -0
- package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/README.en.md +32 -0
- package/vendor/components/sha256/5c032594230fe688f661b6ccf27070c84f8c0e38611186280fb9c56d89ac3319/index.js +222 -0
- package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/README.en.md +50 -0
- package/vendor/components/sha256/603de10f0ee50d07ec610e21b45b9db78d69376b4dfd2baba78595c1002e27ec/index.js +171 -0
- package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/README.en.md +51 -0
- package/vendor/components/sha256/609e45a826d07a54cbbcbf4ce2ad6b5474dca1d0be394eb9fad895db4a73422f/index.js +228 -0
- package/vendor/components/sha256/6364043cb31bbd86aacb7432af1a8affef8cae5c6efdbe13fbebd116fd51b91f/index.js +233 -0
- package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/README.en.md +66 -0
- package/vendor/components/sha256/6f9f7283226d3534aa1cb4a47ba258204aa286ead01b25cdbde14119260bc702/index.js +920 -0
- package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/README.en.md +35 -0
- package/vendor/components/sha256/72edfd6678b22be0bb3e32b0d8cb0dfee403767e1eacac354d278d7318d03826/index.js +179 -0
- package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/index.js +4868 -0
- package/vendor/components/sha256/7482c50bea5ef7d72dc5d4afaddb8c4e725b5a83fa0c6175f9a9c556f23a4e10/names.txt +4808 -0
- package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/README.en.md +40 -0
- package/vendor/components/sha256/7cb8948c550b66bf4b34a62e7b61385aaa79896e09d82ccb1846c0ac499ad352/index.js +348 -0
- package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/README.en.md +42 -0
- package/vendor/components/sha256/87cc60da38d209cda449dd7c24171e287ac8184c5036ca04548ef9e2015c2d9e/index.js +268 -0
- package/vendor/components/sha256/8cb367c71c002c689defddc6f075be911d5485421715119b5515181e962a2401/index.js +121 -0
- package/vendor/components/sha256/97bfd6e79c7278c55153bf4c2330da0432cf0ee312baa11650e07cdd7912831d/index.js +354 -0
- package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/README.en.md +40 -0
- package/vendor/components/sha256/a426e6a3f8f4593403ba63ecc4a3f1f41064f4016fd9fb8d51e7876bf8c6f573/index.js +348 -0
- package/vendor/components/sha256/c108119117042cacc65a35ec73fcab95a2a92b2a2797129f66e326783f8db178/index.js +465 -0
- package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/README.en.md +23 -0
- package/vendor/components/sha256/c3fad2047cec6a2bd8a5b907f752e2addeeea2f373fd8115914552dcee0b2f6f/index.js +289 -0
- package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/README.en.md +31 -0
- package/vendor/components/sha256/c59f1ac3132fdf6f56e8880c866570cd7443f09eb8802b6e7af32675ad358edf/index.js +236 -0
- package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/README.en.md +42 -0
- package/vendor/components/sha256/d3a75f67160490db1831aaa8ac58ebc5f7ffb6a6fd21e2bdeaa6fe979bfaff7f/index.js +488 -0
- package/vendor/components/sha256/d998b5db828427505e39cdae67676dc6480c791d6037152dec222ae81cdbba1f/index.js +484 -0
- package/vendor/components/sha256/ea17602aaecca64b672b3bc827965ff378cb460250177f7b66f73081a48d4e81/index.js +278 -0
- package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/README.en.md +22 -0
- package/vendor/components/sha256/f9cef6dd9580a4f19aa09d47f736ab2391f5f585b20b16a62bd781398cb6b8ac/index.js +145 -0
- package/vendor/components-2/manifest-2.8.0.json +2199 -0
- package/vendor/themes/asagi/1.2.0/theme.json +14 -0
- package/vendor/themes/asagi/1.2.0/tokens.css +30 -0
- package/vendor/themes/business/1.2.0/theme.json +5 -0
- package/vendor/themes/business/1.2.0/tokens.css +41 -0
- package/vendor/themes/default/1.4.0/theme.json +4 -0
- package/vendor/themes/default/1.4.0/tokens.css +86 -0
- package/vendor/themes/kogecha/1.2.0/theme.json +10 -0
- package/vendor/themes/kogecha/1.2.0/tokens.css +29 -0
- package/vendor/themes/kokugo/1.2.0/theme.json +5 -0
- package/vendor/themes/kokugo/1.2.0/tokens.css +25 -0
- package/vendor/themes/murasaki/1.2.0/theme.json +10 -0
- package/vendor/themes/murasaki/1.2.0/tokens.css +25 -0
- package/vendor/themes/sumi/1.2.0/theme.json +10 -0
- package/vendor/themes/sumi/1.2.0/tokens.css +49 -0
- package/vendor/themes/tokiwa/1.2.0/theme.json +10 -0
- package/vendor/themes/tokiwa/1.2.0/tokens.css +27 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Bars grow from 0 by step (vertical, horizontal, grouped, stacked); the axis max can widen by step
|
|
3
|
+
steps: max group/scale step (default 1 group = 1 step)
|
|
4
|
+
props:
|
|
5
|
+
orient: v or h
|
|
6
|
+
max: axis max (0 = auto)
|
|
7
|
+
unit: value unit
|
|
8
|
+
digits: decimals
|
|
9
|
+
per-step: groups per step (0 = all)
|
|
10
|
+
dur: grow seconds
|
|
11
|
+
stagger: group offset (s)
|
|
12
|
+
count: count values up
|
|
13
|
+
ticks: ticks and grid
|
|
14
|
+
zoom: scale-change seconds
|
|
15
|
+
al: axis title
|
|
16
|
+
stack: stack values; "percent" = 100 %
|
|
17
|
+
example: {"series": [{"label": "Sales"}], "groups": [{"label": "Year 1", "value": 1.2}, {"label": "Year 2", "value": 3.4}]}
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
For quantities shown and compared one at a time: yearly sales, ranked answers, before/after.
|
|
21
|
+
|
|
22
|
+
Child JSON: `{"series": [...], "groups": [...], "scale": [...]}`.
|
|
23
|
+
|
|
24
|
+
- group: `label` (`\n` = 2 lines), `value` or `values` (one per series), `step`, `at` (start s), `tone` (bar and value colour)
|
|
25
|
+
- series: `label` (2+ series: on the first group's bars; no legend), `tone` (default `--series-1..4`)
|
|
26
|
+
- scale: `[{"step": 3, "max": 27, "at": 0.4}]`: the max moves to `max` over `zoom` s; the old range stays as a faint band; taller bars stop at the top and grow as it widens
|
|
27
|
+
<!-- llm: omit -->
|
|
28
|
+
- Auto max: 1.12 × the largest value (before the first scale), rounded
|
|
29
|
+
<!-- llm: end -->
|
|
30
|
+
- `orient="h"`: names left, values right; `ticks="false"` for ranks
|
|
31
|
+
- `stack="true"` (`"percent"` = 100 %): a group's `values` in one bar; total at the end, values inside segments; values ≥ 0
|
|
32
|
+
<!-- llm: omit -->
|
|
33
|
+
- Values: `digits` decimals, thousands separators, `unit` appended
|
|
34
|
+
- Negatives (not stacked): the axis includes 0; bars grow down/left from a `--fg` baseline; values outside the bar end
|
|
35
|
+
- `stack="percent"`: axis 0–100 %, no `max`/`scale`, segment values in % when they fit, no total
|
|
36
|
+
- Show later steps faintly (`ctx.preview`): later bars fully grown at `--preview-opacity`; no axis change or over-max bar shown ahead
|
|
37
|
+
<!-- llm: end -->
|
|
38
|
+
|
|
39
|
+
The demo is `demo.html`. All numbers are fictional.
|
|
40
|
+
|
|
41
|
+
Notes
|
|
42
|
+
|
|
43
|
+
- Values appear once a bar is fully grown; `count="true"` counts them up
|
|
44
|
+
- Series names sit on the first group's bars: keep to 2–3 series
|
|
45
|
+
|
|
46
|
+
<!-- llm: omit -->
|
|
47
|
+
- `examples/tmlr2026-calibration` keeps its own deck-local `components/bars/`
|
|
48
|
+
<!-- llm: end -->
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// m-bars:棒を段階ごとに 0 から伸ばす(縦棒・横棒。系列が 2 つ以上なら組の棒)。値の数字は棒の端に直接書く
|
|
2
|
+
// <m-bars unit="億円" style="height:400px"><script type="application/json">
|
|
3
|
+
// {"series": [{"label": "売上"}],
|
|
4
|
+
// "groups": [{"label": "1 年目", "value": 1.2}, {"label": "3 年目", "values": [9.8], "tone": "emph"}]}
|
|
5
|
+
// (JSON の終わり)</m-bars>
|
|
6
|
+
// 段階:既定は組 1 つ = 1 段階(per-step で n 組ずつ、組の step で直接)。軸・目盛り・組の名前は段階 0 から見える
|
|
7
|
+
// scale:[{"step": 3, "max": 200}] で、その段階の始めに値の軸の上限を動かす(対数で補間。前の上限までの範囲は薄い帯で残す)。
|
|
8
|
+
// 上限を超える棒は軸の上端で止まり、上限が広がるにつれて伸びる(「軸を突き抜ける」見せ方)
|
|
9
|
+
// 値の数字は伸びきってから出す(途中の値を読ませない)。count="true" なら伸びに合わせて数え上げる
|
|
10
|
+
// stack="true":組の値を横に並べず 1 本に積み上げる(積み上げ棒)。下の系列から順に色が満ちていき、合計を棒の端に、
|
|
11
|
+
// それぞれの値を単位なしで区切りの中に(入るときだけ)書く。系列の名前は最後の組の棒の右(横棒なら最初の組の棒の上)に書く
|
|
12
|
+
// stack="percent":積み上げ棒の各組を 100 % にそろえ、区切りの中に % を書く(軸は 0〜100 %、端の合計は書かない)
|
|
13
|
+
// 負の値(積み上げでない棒):値の軸に 0 を含め、0 の基線から下(横棒は左)へ伸ばす。値の数字は棒の端の外側(下・左)に書く
|
|
14
|
+
// 2.0(Egatari spec §6.1 の部品):base の MotionElement・el・mtext・prog・lerp・previewOpacity を使い、プレイヤーのグローバルは使わない。
|
|
15
|
+
// 要素が小さすぎるときは ctx.report で知らせる(1.x の console.warn("m-bars: …") の代わり)
|
|
16
|
+
egatariParts.define({name: "bars", version: "2.0.3", requires: {base: "1.2.0"}, element: "m-bars"}, function(deps){
|
|
17
|
+
"use strict";
|
|
18
|
+
var base = deps.base;
|
|
19
|
+
return class extends base.MotionElement {
|
|
20
|
+
static partName = "bars"; // the registry name (define meta name), for report prefixes
|
|
21
|
+
// データの形(kit/shape.js)
|
|
22
|
+
static shape = {
|
|
23
|
+
schema: {type: "object", additionalProperties: false, required: ["groups"], properties: {
|
|
24
|
+
groups: {type: "array", minItems: 1, items: {type: "object", anyOf: [{required: ["value"]}, {required: ["values"]}], properties: {
|
|
25
|
+
label: {type: "string"}, value: {type: "number"}, values: {type: "array", items: {type: "number"}}, step: {type: "integer"}, at: {type: "number"}, tone: {type: "string"}}}},
|
|
26
|
+
series: {type: "array", items: {type: "object", properties: {label: {type: "string"}, tone: {type: "string"}}}},
|
|
27
|
+
scale: {type: "array", items: {type: "object", required: ["step"], properties: {step: {type: "integer"}, max: {type: "number"}, at: {type: "number"}}}},
|
|
28
|
+
max: {type: "number"}}},
|
|
29
|
+
example: {series: [{label: "売上"}], groups: [{label: "1 年目", value: 1.2}, {label: "2 年目", value: 3.4}]},
|
|
30
|
+
};
|
|
31
|
+
static props = {
|
|
32
|
+
orient: {type: "string", default: "v", doc: "v(縦棒)か h(横棒。順位や比較に)"},
|
|
33
|
+
max: {type: "number", default: 0, doc: "値の軸の上限(0 = 自動。scale があれば最初の上限)"},
|
|
34
|
+
unit: {type: "string", default: "", doc: "値の単位(数字の後ろに付ける。億円、%、社 など)"},
|
|
35
|
+
digits: {type: "number", default: 0, doc: "値の小数桁"},
|
|
36
|
+
"per-step": {type: "number", default: 1, doc: "1 ステップに出す組の数(0 = 全部をステップ 1 で)"},
|
|
37
|
+
dur: {type: "number", default: 0.8, doc: "1 本が伸びる秒数"},
|
|
38
|
+
stagger: {type: "number", default: 0.15, doc: "同じステップの組の出だしのずれ(秒)"},
|
|
39
|
+
count: {type: "bool", default: false, doc: "値の数字を伸びに合わせて数え上げる"},
|
|
40
|
+
ticks: {type: "bool", default: true, doc: "値の軸の目盛りと格子"},
|
|
41
|
+
zoom: {type: "number", default: 1.6, doc: "scale で上限を動かす秒数"},
|
|
42
|
+
al: {type: "string", default: "", doc: "値の軸の名前"},
|
|
43
|
+
stack: {type: "bool", default: false, doc: "組の値を 1 本に積み上げる(積み上げ棒)。\"percent\" なら各組を 100 % にそろえる"},
|
|
44
|
+
};
|
|
45
|
+
get steps(){
|
|
46
|
+
if (this.getAttribute("steps") !== null) return +this.getAttribute("steps");
|
|
47
|
+
var m = 0;
|
|
48
|
+
this.plan().groups.forEach(function(g){ m = Math.max(m, g.step); });
|
|
49
|
+
(this.plan().scale).forEach(function(s){ m = Math.max(m, s.step); });
|
|
50
|
+
return m;
|
|
51
|
+
}
|
|
52
|
+
// 組の段階と開始時刻、上限の動き(mount の前にも steps が要るので、データだけから決める)
|
|
53
|
+
plan(){
|
|
54
|
+
if (this._plan) return this._plan;
|
|
55
|
+
var d = this.data || {}, P = this.props, per = P["per-step"], seen = {};
|
|
56
|
+
var groups = (d.groups || []).map(function(g, i){
|
|
57
|
+
var vals = Array.isArray(g.values) ? g.values : [g.value];
|
|
58
|
+
var step = g.step !== undefined ? g.step : per > 0 ? Math.floor(i / per) + 1 : 1;
|
|
59
|
+
var j = seen[step] = (seen[step] || 0) + 1;
|
|
60
|
+
return {g: g, vals: vals.map(Number), step: step, at: g.at !== undefined ? g.at : +((j - 1) * P.stagger).toFixed(3)};
|
|
61
|
+
});
|
|
62
|
+
var scale = (d.scale || []).map(function(s){ return {step: s.step, max: +s.max, at: s.at || 0}; })
|
|
63
|
+
.sort(function(a, b){ return a.step - b.step; });
|
|
64
|
+
return (this._plan = {groups: groups, scale: scale});
|
|
65
|
+
}
|
|
66
|
+
mount(ctx){
|
|
67
|
+
var P = this.props, D = base, self = this, d = this.data || {}, pl = this.plan();
|
|
68
|
+
this.style.display = "block"; this.style.position = "relative";
|
|
69
|
+
var W = this.clientWidth, H = this.clientHeight, hor = P.orient === "h";
|
|
70
|
+
var svg = D.el("svg", {viewBox: "0 0 " + W + " " + H, width: W, height: H, "aria-hidden": "true", style: "display:block;overflow:visible"}, this);
|
|
71
|
+
var series = d.series && d.series.length ? d.series : [{}];
|
|
72
|
+
var ns = Math.max(series.length, Math.max.apply(null, pl.groups.map(function(g){ return g.vals.length; }).concat([1])));
|
|
73
|
+
// 積み上げ棒では、軸と端の数字は組の合計で決める
|
|
74
|
+
var st = P.stack, sum = function(g){ return g.vals.reduce(function(a, v){ return a + Math.max(0, v); }, 0); };
|
|
75
|
+
// stack="percent":各組を 100 % にそろえる
|
|
76
|
+
var pct = this.pct = st && this.getAttribute("stack") === "percent";
|
|
77
|
+
var tops = function(g){ return pct ? [100] : st ? [sum(g)] : g.vals; };
|
|
78
|
+
var all = [].concat.apply([], pl.groups.map(tops));
|
|
79
|
+
// 軸の上限:scale の最初の段階より前に出る棒が収まるように
|
|
80
|
+
var first = pl.scale.length ? pl.scale[0].step : Infinity;
|
|
81
|
+
var early = [].concat.apply([], pl.groups.filter(function(g){ return g.step < first; }).map(tops));
|
|
82
|
+
// 負の値があれば(積み上げでない棒)、軸は 0 を含み、0 より下の範囲 N をとる(N は下で枠の大きさから決める)
|
|
83
|
+
var mn = st ? 0 : Math.min.apply(null, all.concat([0]));
|
|
84
|
+
this.neg = mn < 0; this.N = 0;
|
|
85
|
+
if (this.neg){
|
|
86
|
+
var pmax = Math.max.apply(null, (early.length ? early : all).concat([0]));
|
|
87
|
+
this.M0 = P.max || d.max || (pmax > 0 ? nice(pmax * 1.12) : 0);
|
|
88
|
+
this.levels = [this.M0].concat(pl.scale.map(function(s){ return s.max || nice(Math.max(Math.max.apply(null, all), 1e-9) * 1.12); }));
|
|
89
|
+
} else {
|
|
90
|
+
this.M0 = pct ? 100 : P.max || d.max || nice(Math.max.apply(null, (early.length ? early : all).concat([1e-9])) * 1.12);
|
|
91
|
+
this.levels = [this.M0].concat(pl.scale.map(function(s){ return s.max || nice(Math.max.apply(null, all) * 1.12); }));
|
|
92
|
+
}
|
|
93
|
+
pl.scale.forEach(function(s, i){ s.max = self.levels[i + 1]; });
|
|
94
|
+
// 余白:横棒は組の名前の幅、縦棒は値の軸の目盛り(字の幅は base の textWidth:テーマの字で測った幅。mk は mtext で書く字)
|
|
95
|
+
var est = function(s, size, mk){ return D.textWidth(s, size, {font: self, mark: !!mk}); };
|
|
96
|
+
var longest = Math.max.apply(null, pl.groups.map(function(g){ return Math.max.apply(null, String(g.g.label || "").split("\n").map(function(s){ return est(s, 26, true); })); }).concat([0]));
|
|
97
|
+
var valW = Math.max.apply(null, all.map(function(v){ return est(self.fmt(v), 26); }).concat([0]));
|
|
98
|
+
var lines = Math.max.apply(null, pl.groups.map(function(g){ return String(g.g.label || "").split("\n").length; }).concat([1]));
|
|
99
|
+
var m = this.m = hor ? {l: Math.min(W * 0.42, longest + 24), r: valW + 24, t: P.al ? 40 : 8, b: P.ticks ? 44 : 8}
|
|
100
|
+
: {l: P.ticks ? 24 + est(this.fmtTick(this.levels[this.levels.length - 1], 1), 24) + (P.al ? 36 : 0) : 16, r: 16, t: ns > 1 ? 80 : 44, b: 18 + 30 * lines};
|
|
101
|
+
// 積み上げ棒:系列の名前を縦棒は右に、横棒は最初の棒の上に書くので、その分をあける
|
|
102
|
+
var serW = Math.max.apply(null, series.map(function(sr){ return est(sr.label || "", 24, true); }).concat([0]));
|
|
103
|
+
if (st && hor && ns > 1) m.t = Math.max(m.t, P.al ? 40 : 36);
|
|
104
|
+
if (st && !hor){ m.t = 44; if (ns > 1 && serW) m.r = serW + 30; }
|
|
105
|
+
this.x0 = m.l; this.x1 = W - m.r; this.y0 = m.t; this.y1 = H - m.b;
|
|
106
|
+
// 要素が小さすぎる(高さを書き忘れて 0 px など):大きさが負にならないように、枠を 0 にして知らせる
|
|
107
|
+
if (this.x1 < this.x0 || this.y1 < this.y0){
|
|
108
|
+
ctx.report("size", "[bars] the element (" + W + "×" + H + " px) is too small for the bars; give it a size, e.g. style=\"height:380px\"");
|
|
109
|
+
this.x1 = Math.max(this.x0, this.x1); this.y1 = Math.max(this.y0, this.y1);
|
|
110
|
+
}
|
|
111
|
+
this.len = hor ? this.x1 - this.x0 : this.y1 - this.y0;
|
|
112
|
+
if (this.neg){
|
|
113
|
+
// 0 より下の範囲:いちばん下の棒の端の外に値の数字が入るだけあける(縦棒 40 px、横棒は数字の幅 + 24 px)
|
|
114
|
+
var room = hor ? valW + 24 : 40, fr = Math.min(0.6, room / Math.max(1, this.len));
|
|
115
|
+
this.N = nice((-mn + fr * this.M0) / (1 - fr));
|
|
116
|
+
// 縦棒:負の目盛りの字の幅だけ左をあける
|
|
117
|
+
if (!hor && P.ticks){
|
|
118
|
+
var nl = 24 + est(this.fmtTick(-this.N, decs(tickStep(this.M0 + this.N))), 24) + (P.al ? 36 : 0);
|
|
119
|
+
if (nl > m.l){ m.l = nl; this.x0 = m.l; if (this.x1 < this.x0) this.x1 = this.x0; }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// 前の上限までの範囲(上限を動かす間だけ)
|
|
123
|
+
this.band = D.el("rect", {fill: "var(--term-tint)", opacity: 0}, svg);
|
|
124
|
+
// 目盛り:上限ごとに 1 組。上限が動く間は前の組を薄くし、次の組を濃くする
|
|
125
|
+
var gT = D.el("g", {}, svg);
|
|
126
|
+
this.tickSets = !P.ticks ? [] : this.levels.map(function(M){
|
|
127
|
+
var st = tickStep(self.neg ? M + self.N : M), dec = decs(st);
|
|
128
|
+
var out = [];
|
|
129
|
+
for (var i = 1; i * st <= M * 1.0001; i++){
|
|
130
|
+
var v = +(i * st).toFixed(8);
|
|
131
|
+
out.push({v: v, grid: D.el("line", {stroke: "var(--line)", "stroke-width": 1.2}, gT),
|
|
132
|
+
text: D.el("text", {"font-size": 24, "text-anchor": hor ? "middle" : "end", style: "font-variant-numeric:tabular-nums"}, gT), label: self.fmtTick(v, dec)});
|
|
133
|
+
}
|
|
134
|
+
// 負の側の目盛り(負の値があるときだけ)
|
|
135
|
+
if (self.neg) for (var i2 = 1; i2 * st <= self.N * 1.0001; i2++){
|
|
136
|
+
var v2 = -(+(i2 * st).toFixed(8));
|
|
137
|
+
out.push({v: v2, grid: D.el("line", {stroke: "var(--line)", "stroke-width": 1.2}, gT),
|
|
138
|
+
text: D.el("text", {"font-size": 24, "text-anchor": hor ? "middle" : "end", style: "font-variant-numeric:tabular-nums"}, gT), label: self.fmtTick(v2, dec)});
|
|
139
|
+
}
|
|
140
|
+
out.forEach(function(o){ o.text.textContent = o.label; });
|
|
141
|
+
return out;
|
|
142
|
+
});
|
|
143
|
+
// 0 の目盛りと基線(いつも出す)
|
|
144
|
+
if (P.ticks){
|
|
145
|
+
var z = D.el("text", {"font-size": 24, "text-anchor": hor ? "middle" : "end"}, gT);
|
|
146
|
+
z.textContent = pct ? "0%" : "0";
|
|
147
|
+
this.zeroT = z;
|
|
148
|
+
if (hor){ z.setAttribute("x", this.x0); z.setAttribute("y", this.y1 + 32); } else { z.setAttribute("x", this.x0 - 10); z.setAttribute("y", this.y1 + 8); }
|
|
149
|
+
}
|
|
150
|
+
if (P.al){
|
|
151
|
+
if (hor) D.mtext(svg, this.x1, this.y0 - 14, P.al, {"text-anchor": "end", fill: "var(--muted)"});
|
|
152
|
+
else D.mtext(svg, 20, (this.y0 + this.y1) / 2, P.al, {"text-anchor": "middle", fill: "var(--muted)", transform: "rotate(-90 20 " + (this.y0 + this.y1) / 2 + ")"});
|
|
153
|
+
}
|
|
154
|
+
var gB = D.el("g", {}, svg), gL = D.el("g", {}, svg);
|
|
155
|
+
if (hor) this.baseL = D.el("line", {x1: this.x0, y1: this.y0, x2: this.x0, y2: this.y1, stroke: "var(--fg)", "stroke-width": 1.5}, svg);
|
|
156
|
+
else this.baseL = D.el("line", {x1: this.x0, y1: this.y1, x2: this.x1, y2: this.y1, stroke: "var(--fg)", "stroke-width": 1.5}, svg);
|
|
157
|
+
// 組と棒の位置(組の幅は枠の 64%、棒は組の幅を系列で分ける)
|
|
158
|
+
var n = pl.groups.length || 1, cross = hor ? this.y1 - this.y0 : this.x1 - this.x0, slot = cross / n;
|
|
159
|
+
var bw = Math.min(hor ? 56 : 96, slot * 0.64 / (st ? 1 : ns));
|
|
160
|
+
this.bars = [];
|
|
161
|
+
this.stacks = null;
|
|
162
|
+
if (st) this.stacks = pl.groups.map(function(o, i){
|
|
163
|
+
var c = (hor ? self.y0 : self.x0) + slot * (i + 0.5), cum = 0, raw = sum(o);
|
|
164
|
+
String(o.g.label || "").split("\n").forEach(function(s, j, a){
|
|
165
|
+
if (hor) D.mtext(gL, self.x0 - 12, c + 8 + (j - (a.length - 1) / 2) * 30, s, {"text-anchor": "end", "font-size": 26});
|
|
166
|
+
else D.mtext(gL, c, self.y1 + 34 + j * 30, s, {"text-anchor": "middle", "font-size": 26});
|
|
167
|
+
});
|
|
168
|
+
var segs = o.vals.map(function(v, j){
|
|
169
|
+
v = Math.max(0, v);
|
|
170
|
+
if (pct) v = raw > 0 ? v / raw * 100 : 0;
|
|
171
|
+
var col = tone(series[j] && series[j].tone || (ns > 1 ? "series-" + (j % 4 + 1) : "term"));
|
|
172
|
+
var sg = {v: v, j: j, from: cum, col: col, rect: D.el("rect", {rx: 3, fill: col, opacity: 0}, gB),
|
|
173
|
+
val: D.el("text", {"font-size": 24, "font-weight": 700, "text-anchor": "middle", fill: "var(--bg)", opacity: 0, style: "font-variant-numeric:tabular-nums"}, gL)};
|
|
174
|
+
// 区切りの中の値は単位を付けない(単位は端の合計に付く)
|
|
175
|
+
sg.val.textContent = self.fmt(v, undefined, pct ? "%" : "");
|
|
176
|
+
// 太字 24 px の数字の幅(base の textWidth。字の読み込みを待たない)
|
|
177
|
+
sg.vw = est(sg.val.textContent, 24);
|
|
178
|
+
cum += v;
|
|
179
|
+
return sg;
|
|
180
|
+
});
|
|
181
|
+
var tot = D.el("text", {"font-size": 26, "font-weight": 700, "text-anchor": hor ? "start" : "middle", fill: o.g.tone ? tone(o.g.tone) : "var(--fg)", opacity: 0, style: "font-variant-numeric:tabular-nums"}, gL);
|
|
182
|
+
return {o: o, c: c, segs: segs, total: cum, tot: tot};
|
|
183
|
+
});
|
|
184
|
+
// 系列の名前:縦棒は最後の組の棒の右、横棒は最初の組の棒の上に、区切りの真ん中にそろえて書く(重なれば離す)
|
|
185
|
+
this.serLabs = [];
|
|
186
|
+
if (st && ns > 1){
|
|
187
|
+
var ref = hor ? this.stacks[0] : this.stacks[this.stacks.length - 1];
|
|
188
|
+
ref.segs.forEach(function(sg){
|
|
189
|
+
if (!series[sg.j] || !series[sg.j].label) return;
|
|
190
|
+
self.serLabs.push({sg: sg, ref: ref, el: D.mtext(gL, 0, 0, series[sg.j].label, {"text-anchor": hor ? "middle" : "start", "font-size": 24, "font-weight": 700, fill: sg.col, opacity: 0}), w: est(series[sg.j].label, 24, true)});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (!st) this.groups = pl.groups.map(function(o, i){
|
|
194
|
+
var c = (hor ? self.y0 : self.x0) + slot * (i + 0.5);
|
|
195
|
+
var lab = String(o.g.label || "").split("\n").map(function(s, j, a){
|
|
196
|
+
return hor ? D.mtext(gL, self.x0 - 12, c + 8 + (j - (a.length - 1) / 2) * 30, s, {"text-anchor": "end", "font-size": 26})
|
|
197
|
+
: D.mtext(gL, c, self.y1 + 34 + j * 30, s, {"text-anchor": "middle", "font-size": 26});
|
|
198
|
+
});
|
|
199
|
+
o.vals.forEach(function(v, j){
|
|
200
|
+
var col = tone(o.g.tone || series[j] && series[j].tone || (ns > 1 ? "series-" + (j % 4 + 1) : "term"));
|
|
201
|
+
var off = (j - (ns - 1) / 2) * (bw + 4);
|
|
202
|
+
var b = {o: o, v: v, j: j, c: c + off, col: col,
|
|
203
|
+
rect: D.el("rect", {rx: 3, fill: col}, gB),
|
|
204
|
+
val: D.el("text", {"font-size": 26, "font-weight": 700, "text-anchor": hor ? (v < 0 ? "end" : "start") : "middle", fill: o.g.tone ? col : "var(--fg)", style: "font-variant-numeric:tabular-nums"}, gL)};
|
|
205
|
+
// 系列の名前は最初の組の棒の上(横棒なら右)に直接書く(凡例は作らない)
|
|
206
|
+
if (i === 0 && ns > 1 && series[j] && series[j].label) b.ser = D.mtext(gL, 0, 0, series[j].label, {"text-anchor": hor ? (v < 0 ? "end" : "start") : "middle", "font-size": 24, "font-weight": 700, fill: col});
|
|
207
|
+
self.bars.push(b);
|
|
208
|
+
});
|
|
209
|
+
return {o: o, lab: lab};
|
|
210
|
+
});
|
|
211
|
+
this.bw = bw;
|
|
212
|
+
this.hor = hor;
|
|
213
|
+
// 読み上げ:最後の形(すべての組の値)を 1 文で。作者の aria-label があればそれを使う(上書きしない)
|
|
214
|
+
if (this._aria === undefined) this._aria = this.getAttribute("aria-label");
|
|
215
|
+
this.setAttribute("role", "img");
|
|
216
|
+
if (!this._aria) this.setAttribute("aria-label", this.summary(/^ja\b/i.test(ctx.lang || "ja"), series));
|
|
217
|
+
function nice(v){ var e = Math.pow(10, Math.floor(Math.log10(v))), x = v / e;
|
|
218
|
+
return [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10].filter(function(s){ return s >= x - 1e-9; })[0] * e; }
|
|
219
|
+
function tickStep(M){ var r = M / 4.5, e = Math.pow(10, Math.floor(Math.log10(r))), x = r / e;
|
|
220
|
+
return (x <= 1 ? 1 : x <= 2 ? 2 : x <= 2.5 ? 2.5 : x <= 5 ? 5 : 10) * e; }
|
|
221
|
+
function decs(s){ var k = 0; while (Math.abs(s * Math.pow(10, k) - Math.round(s * Math.pow(10, k))) > 1e-6 && k < 6) k++; return k; }
|
|
222
|
+
function tone(t){ return /^(term|emph|muted|accent2|fg|series-[1-4])$/.test(t) ? "var(--" + t + ")" : "var(--term)"; }
|
|
223
|
+
}
|
|
224
|
+
// 最後の形を 1 文で(読み上げの名前):「売上(億円):1 年目 1.2億円、3 年目 9.8億円」。系列が 2 つ以上なら組ごとに「系列 値」を並べ、
|
|
225
|
+
// 積み上げ棒は合計も、100 % の積み上げ棒は % を書く。組が 12 より多ければ初めの 12 組と組の数
|
|
226
|
+
summary(ja, series){
|
|
227
|
+
var self = this, P = this.props, pl = this.plan(), pct = this.pct, st = P.stack;
|
|
228
|
+
var names = series.map(function(sr){ return sr.label || ""; }).filter(Boolean);
|
|
229
|
+
var head = P.al || names.join(ja ? "・" : ", ") || (ja ? "棒グラフ" : "Bar chart");
|
|
230
|
+
if (P.unit && !pct) head += ja ? "(" + P.unit + ")" : " (" + P.unit + ")";
|
|
231
|
+
var one = function(o){
|
|
232
|
+
var raw = o.vals.reduce(function(a, v){ return a + Math.max(0, v); }, 0);
|
|
233
|
+
var vs = o.vals.map(function(v, j){
|
|
234
|
+
var x = pct ? self.fmt(raw > 0 ? Math.max(0, v) / raw * 100 : 0, undefined, "%") : self.fmt(st ? Math.max(0, v) : v);
|
|
235
|
+
return (o.vals.length > 1 && series[j] && series[j].label ? series[j].label + " " : "") + x;
|
|
236
|
+
});
|
|
237
|
+
var lab = String(o.g.label || "").replace(/\s*\n\s*/g, " ");
|
|
238
|
+
return (lab ? lab + " " : "") + vs.join(ja ? "・" : ", ") + (st && !pct && o.vals.length > 1 ? (ja ? "(計 " : " (total ") + self.fmt(raw) + (ja ? ")" : ")") : "");
|
|
239
|
+
};
|
|
240
|
+
var gs = pl.groups.slice(0, 12).map(one);
|
|
241
|
+
if (pl.groups.length > 12) gs.push(ja ? "…(全 " + pl.groups.length + " 組)" : "… (" + pl.groups.length + " groups)");
|
|
242
|
+
return head + (ja ? ":" : ": ") + gs.join(ja ? "、" : "; ");
|
|
243
|
+
}
|
|
244
|
+
// 数の書き方:3 桁ごとのカンマ、小数桁、単位
|
|
245
|
+
fmt(v, digits, unit){
|
|
246
|
+
var dg = digits !== undefined ? digits : this.props.digits;
|
|
247
|
+
var s = Math.abs(v).toFixed(dg).split("."), i = s[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
248
|
+
return (v < 0 ? "−" : "") + i + (s[1] ? "." + s[1] : "") + (unit !== undefined ? unit : this.props.unit);
|
|
249
|
+
}
|
|
250
|
+
fmtTick(v, dec){ return this.fmt(v, dec, this.pct ? "%" : ""); }
|
|
251
|
+
// 段階 k、時刻 t の上限
|
|
252
|
+
maxAt(k, t){
|
|
253
|
+
var P = this.props, m = this.M0, from = 0, e = 1, lv = 0;
|
|
254
|
+
for (var i = 0; i < this.plan().scale.length; i++){
|
|
255
|
+
var s = this.plan().scale[i];
|
|
256
|
+
if (s.step < k){ m = s.max; lv = i + 1; continue; }
|
|
257
|
+
if (s.step === k){ e = base.prog(t, s.at, P.zoom); from = m; m = Math.exp(base.lerp(Math.log(m), Math.log(s.max), e)); return {m: m, lv: i + 1, e: e, from: from}; }
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
return {m: m, lv: lv, e: 1, from: null};
|
|
261
|
+
}
|
|
262
|
+
duration(k){
|
|
263
|
+
var P = this.props, d = 0;
|
|
264
|
+
// 積み上げ棒の区切りの値と系列の名前は count でも伸びきってから 0.35 秒で出るので、その分も段階に含める
|
|
265
|
+
this.plan().groups.forEach(function(o){ if (o.step === k) d = Math.max(d, o.at + (P.stack ? 0 : 0.1 * (o.vals.length - 1)) + P.dur + (P.count && !P.stack ? 0 : 0.35)); });
|
|
266
|
+
this.plan().scale.forEach(function(s){ if (s.step === k) d = Math.max(d, s.at + P.zoom + 0.3); });
|
|
267
|
+
return d;
|
|
268
|
+
}
|
|
269
|
+
render(k, t, ctx){
|
|
270
|
+
var P = this.props, D = base, self = this, hor = this.hor;
|
|
271
|
+
// 先の段階を薄く見せる表示(授業の表示):後の段階の棒と数字を、伸びきった形でテーマの --preview-opacity の濃さに。
|
|
272
|
+
// 軸の上限は今の段階のまま。今の上限に収まらない棒(後で上限が動いてから入る棒)は先に見せない(上限で切ると値を読み違える)
|
|
273
|
+
var preview = !!ctx.preview, PV = preview ? base.previewOpacity(this) : 1;
|
|
274
|
+
var sc = this.maxAt(k, t), M = sc.m;
|
|
275
|
+
var ahead = function(o, v){ return preview && o.step > k && !(v > M * 1.04); };
|
|
276
|
+
var pos = function(v){ var r = Math.min(v, M * 1.04) / M * self.len; return hor ? self.x0 + r : self.y1 - r; };
|
|
277
|
+
// 負の値があるとき:値の軸は -N から M。棒は 0 の基線から伸びる
|
|
278
|
+
var N = this.N;
|
|
279
|
+
if (this.neg){
|
|
280
|
+
pos = function(v){ var r = (Math.max(-N * 1.04, Math.min(v, M * 1.04)) + N) / (M + N) * self.len; return hor ? self.x0 + r : self.y1 - r; };
|
|
281
|
+
var z0 = pos(0);
|
|
282
|
+
if (hor){ this.baseL.setAttribute("x1", z0.toFixed(1)); this.baseL.setAttribute("x2", z0.toFixed(1)); if (this.zeroT) this.zeroT.setAttribute("x", z0.toFixed(1)); }
|
|
283
|
+
else { this.baseL.setAttribute("y1", z0.toFixed(1)); this.baseL.setAttribute("y2", z0.toFixed(1)); if (this.zeroT) this.zeroT.setAttribute("y", (z0 + 8).toFixed(1)); }
|
|
284
|
+
}
|
|
285
|
+
// 目盛り:今の上限の組を濃く、動いている間は前の組を薄く
|
|
286
|
+
// 前の組と次の組に同じ値の目盛りがあれば、重ねずに次の組のものだけを濃く出す
|
|
287
|
+
var moving = sc.from !== null, has = function(li, v){ return (self.tickSets[li] || []).some(function(o){ return Math.abs(o.v - v) < 1e-9; }); };
|
|
288
|
+
this.tickSets.forEach(function(set, li){
|
|
289
|
+
var op = li === sc.lv ? sc.e : li === sc.lv - 1 && moving ? 1 - sc.e : 0;
|
|
290
|
+
set.forEach(function(o){
|
|
291
|
+
var b = op;
|
|
292
|
+
if (moving && li === sc.lv - 1 && has(sc.lv, o.v)) b = 0;
|
|
293
|
+
if (moving && li === sc.lv && has(sc.lv - 1, o.v)) b = 1;
|
|
294
|
+
var p = pos(o.v), a = o.v > M * 1.001 || (self.neg && o.v < -N * 1.001) ? 0 : b;
|
|
295
|
+
if (hor){ o.grid.setAttribute("x1", p.toFixed(1)); o.grid.setAttribute("x2", p.toFixed(1)); o.grid.setAttribute("y1", self.y0); o.grid.setAttribute("y2", self.y1);
|
|
296
|
+
o.text.setAttribute("x", p.toFixed(1)); o.text.setAttribute("y", self.y1 + 32); }
|
|
297
|
+
else { o.grid.setAttribute("y1", p.toFixed(1)); o.grid.setAttribute("y2", p.toFixed(1)); o.grid.setAttribute("x1", self.x0); o.grid.setAttribute("x2", self.x1);
|
|
298
|
+
o.text.setAttribute("x", self.x0 - 10); o.text.setAttribute("y", (p + 8).toFixed(1)); }
|
|
299
|
+
o.grid.setAttribute("opacity", (0.8 * a).toFixed(3)); o.text.setAttribute("opacity", a.toFixed(3));
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
// 前の上限までの帯(上限が動く間だけ)
|
|
303
|
+
var bo = sc.from === null ? 0 : 0.6 * Math.min(1, sc.e * 4) * (1 - D.prog(t, P.zoom * 0.8, P.zoom * 0.4));
|
|
304
|
+
var pb = pos(Math.min(sc.from || 0, M));
|
|
305
|
+
if (hor){ this.band.setAttribute("x", this.x0); this.band.setAttribute("width", Math.max(0, pb - this.x0).toFixed(1)); this.band.setAttribute("y", this.y0); this.band.setAttribute("height", this.y1 - this.y0); }
|
|
306
|
+
else { this.band.setAttribute("x", this.x0); this.band.setAttribute("width", this.x1 - this.x0); this.band.setAttribute("y", pb.toFixed(1)); this.band.setAttribute("height", Math.max(0, this.y1 - pb).toFixed(1)); }
|
|
307
|
+
this.band.setAttribute("opacity", bo.toFixed(3));
|
|
308
|
+
if (this.stacks) return this.renderStack(k, t, pos, ahead, PV);
|
|
309
|
+
this.bars.forEach(function(b){
|
|
310
|
+
var o = b.o, at = o.at + 0.1 * b.j;
|
|
311
|
+
var e = o.step < k || ahead(o, b.v) ? 1 : o.step > k ? 0 : D.prog(t, at, P.dur);
|
|
312
|
+
var v = b.v * e, p = pos(v), w = self.bw;
|
|
313
|
+
if (self.neg){
|
|
314
|
+
// 0 の基線から値まで(負なら下・左へ)
|
|
315
|
+
var zb = pos(0);
|
|
316
|
+
if (hor){ b.rect.setAttribute("x", Math.min(p, zb).toFixed(1)); b.rect.setAttribute("width", Math.abs(p - zb).toFixed(1)); b.rect.setAttribute("y", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("height", w.toFixed(1)); }
|
|
317
|
+
else { b.rect.setAttribute("x", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("width", w.toFixed(1)); b.rect.setAttribute("y", Math.min(p, zb).toFixed(1)); b.rect.setAttribute("height", Math.abs(zb - p).toFixed(1)); }
|
|
318
|
+
} else if (hor){ b.rect.setAttribute("x", self.x0); b.rect.setAttribute("width", Math.max(0, p - self.x0).toFixed(1)); b.rect.setAttribute("y", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("height", w.toFixed(1)); }
|
|
319
|
+
else { b.rect.setAttribute("x", (b.c - w / 2).toFixed(1)); b.rect.setAttribute("width", w.toFixed(1)); b.rect.setAttribute("y", p.toFixed(1)); b.rect.setAttribute("height", Math.max(0, self.y1 - p).toFixed(1)); }
|
|
320
|
+
b.rect.setAttribute("opacity", ahead(o, b.v) ? PV : e > 0 ? 1 : 0);
|
|
321
|
+
// 値の数字:既定は伸びきってから。count なら伸びに合わせて
|
|
322
|
+
var vo = ahead(o, b.v) ? PV : P.count ? (e > 0 ? 1 : 0) : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, at + P.dur, 0.35);
|
|
323
|
+
b.val.textContent = self.fmt(P.count ? v : b.v);
|
|
324
|
+
var pe = P.count ? p : pos(b.v), dn = b.v < 0;
|
|
325
|
+
// 値の数字は棒の端の外側:正なら上(右)、負なら下(左)
|
|
326
|
+
if (hor){ b.val.setAttribute("x", (dn ? pe - 10 : pe + 10).toFixed(1)); b.val.setAttribute("y", (b.c + 9).toFixed(1)); }
|
|
327
|
+
else { b.val.setAttribute("x", b.c.toFixed(1)); b.val.setAttribute("y", (dn ? pe + 32 : pe - 12).toFixed(1)); }
|
|
328
|
+
b.val.setAttribute("opacity", vo.toFixed(3));
|
|
329
|
+
if (b.ser){
|
|
330
|
+
if (hor){ b.ser.setAttribute("x", (dn ? pos(b.v) - 24 - self.fmt(b.v).length * 15 : pos(b.v) + 24 + self.fmt(b.v).length * 15).toFixed(1)); b.ser.setAttribute("y", (b.c + 8).toFixed(1)); }
|
|
331
|
+
else { b.ser.setAttribute("x", b.c.toFixed(1)); b.ser.setAttribute("y", (dn ? pos(b.v) + 62 : pos(b.v) - 44).toFixed(1)); }
|
|
332
|
+
b.ser.setAttribute("opacity", vo.toFixed(3));
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
// 積み上げ棒:棒の先が 0 から合計まで伸び、下の系列から順に色が満ちる。値の数字は伸びきってから
|
|
337
|
+
renderStack(k, t, pos, ahead, PV){
|
|
338
|
+
var P = this.props, D = base, self = this, hor = this.hor, w = this.bw;
|
|
339
|
+
var len = function(a, b){ return Math.abs(pos(b) - pos(a)); };
|
|
340
|
+
this.stacks.forEach(function(sk){
|
|
341
|
+
var o = sk.o, f = ahead(o, sk.total), e = o.step < k || f ? 1 : o.step > k ? 0 : D.prog(t, o.at, P.dur), top = sk.total * e;
|
|
342
|
+
var vo = f ? PV : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, o.at + P.dur, 0.35);
|
|
343
|
+
sk.segs.forEach(function(sg, j){
|
|
344
|
+
var a = Math.min(sg.from, top), b = Math.min(sg.from + sg.v, top), pa = pos(a), pb = pos(b), gap = j > 0 && b > a ? 2 : 0;
|
|
345
|
+
var px = Math.max(0, Math.abs(pb - pa) - gap);
|
|
346
|
+
if (hor){ sg.rect.setAttribute("x", (pa + gap).toFixed(1)); sg.rect.setAttribute("width", px.toFixed(1)); sg.rect.setAttribute("y", (sk.c - w / 2).toFixed(1)); sg.rect.setAttribute("height", w.toFixed(1)); }
|
|
347
|
+
else { sg.rect.setAttribute("x", (sk.c - w / 2).toFixed(1)); sg.rect.setAttribute("width", w.toFixed(1)); sg.rect.setAttribute("y", pb.toFixed(1)); sg.rect.setAttribute("height", px.toFixed(1)); }
|
|
348
|
+
sg.rect.setAttribute("opacity", px > 0 ? (f ? PV : 1) : 0);
|
|
349
|
+
// 区切りの中の値:伸びきった区切りに字が収まるときだけ。100 % の積み上げ棒では、字の箱(幅の見積もり × 24 px)が
|
|
350
|
+
// 四方に 6 px 以上の余白をもって入るときだけ
|
|
351
|
+
var full = len(sg.from, sg.from + sg.v) - gap, mid = (pos(sg.from) + pos(sg.from + sg.v)) / 2;
|
|
352
|
+
var room = self.pct ? (hor ? full >= sg.vw + 12 && w >= 36 : full >= 36 && w >= sg.vw + 12)
|
|
353
|
+
: hor ? full >= sg.vw + 12 && w >= 30 : full >= 30 && w >= sg.vw + 8;
|
|
354
|
+
if (hor){ sg.val.setAttribute("x", mid.toFixed(1)); sg.val.setAttribute("y", (sk.c + 8).toFixed(1)); }
|
|
355
|
+
else { sg.val.setAttribute("x", sk.c.toFixed(1)); sg.val.setAttribute("y", (mid + 8).toFixed(1)); }
|
|
356
|
+
sg.val.setAttribute("opacity", (room ? vo : 0).toFixed(3));
|
|
357
|
+
});
|
|
358
|
+
// 合計:棒の端(count なら伸びに合わせて数え上げる)
|
|
359
|
+
sk.tot.textContent = self.fmt(P.count ? top : sk.total);
|
|
360
|
+
var pe = P.count ? pos(top) : pos(sk.total);
|
|
361
|
+
if (hor){ sk.tot.setAttribute("x", (pe + 10).toFixed(1)); sk.tot.setAttribute("y", (sk.c + 9).toFixed(1)); }
|
|
362
|
+
else { sk.tot.setAttribute("x", sk.c.toFixed(1)); sk.tot.setAttribute("y", (pe - 12).toFixed(1)); }
|
|
363
|
+
// 100 % の積み上げ棒は端がどれも 100 % なので、合計は書かない
|
|
364
|
+
sk.tot.setAttribute("opacity", (self.pct ? 0 : f ? PV : P.count ? (e > 0 ? 1 : 0) : vo).toFixed(3));
|
|
365
|
+
});
|
|
366
|
+
// 系列の名前:区切りの真ん中。縦に並ぶ名前(縦棒)は 28 px、横に並ぶ名前(横棒)は字の幅より近づけない
|
|
367
|
+
var prev = null;
|
|
368
|
+
this.serLabs.forEach(function(sl){
|
|
369
|
+
var sk = sl.ref, o = sk.o, sg = sl.sg, mid = (pos(sg.from) + pos(sg.from + sg.v)) / 2;
|
|
370
|
+
var vo = ahead(o, sk.total) ? PV : o.step < k ? 1 : o.step > k ? 0 : D.prog(t, o.at + P.dur, 0.35);
|
|
371
|
+
if (hor){
|
|
372
|
+
var x = prev ? Math.max(mid, prev.x + (prev.w + sl.w) / 2 + 12) : mid;
|
|
373
|
+
sl.el.setAttribute("x", x.toFixed(1)); sl.el.setAttribute("y", (sk.c - w / 2 - 10).toFixed(1));
|
|
374
|
+
prev = {x: x, w: sl.w};
|
|
375
|
+
} else {
|
|
376
|
+
var y = prev ? Math.min(mid + 8, prev.y - 28) : mid + 8;
|
|
377
|
+
sl.el.setAttribute("x", (sk.c + w / 2 + 12).toFixed(1)); sl.el.setAttribute("y", y.toFixed(1));
|
|
378
|
+
prev = {y: y};
|
|
379
|
+
}
|
|
380
|
+
sl.el.setAttribute("opacity", vo.toFixed(3));
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
summary: Venn of 2–3 sets, one by one; then overlaps with items
|
|
3
|
+
steps: sets + 1 (overlaps="each": sets + overlaps with items, or all overlaps if none)
|
|
4
|
+
props:
|
|
5
|
+
size: item text px (shrinks to 24)
|
|
6
|
+
dur: set appear (s)
|
|
7
|
+
spread: centre distance ÷ radius (0.7–1.3)
|
|
8
|
+
overlaps: together or each
|
|
9
|
+
example: {"sets": [{"label": "Mammals"}, {"label": "Sea animals"}], "regions": {"A": ["Lion"], "B": ["Tuna"], "AB": ["Whale", "Dolphin"]}}
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Shared and distinct traits. Per-point values: `m-compare`.
|
|
13
|
+
|
|
14
|
+
Child JSON: `{"sets": [{"label", "tone"}, …], "regions": {"A": [...], "B": [...], "AB": [...], …}}`.
|
|
15
|
+
|
|
16
|
+
- `sets`: 2 or 3; `label` outside; `tone` (`term`, `emph`, `muted`, `accent2`, `series-1..4`; default `term`, `accent2`, `series-4`). Avoid `emph` (used for overlaps)
|
|
17
|
+
- `regions`: items per region (array or `\n` text). Keys: letters in alphabetical order, A B C = `sets` order:
|
|
18
|
+
- `A`: only A; `AB`: A and B (with 3 sets, not C); `ABC`: all three
|
|
19
|
+
- 2 sets: `A` `B` `AB`; 3: `A` `B` `C` `AB` `AC` `BC` `ABC`; all optional. C keys with 2 sets: error card
|
|
20
|
+
- Area not to scale. `spread` (default 1): smaller = more overlap
|
|
21
|
+
- Overlap items bold; 1–2 words with 3 sets
|
|
22
|
+
- Steps: each set with its own items → overlaps (those with items tinted `--emph`, outlined, items shown; if none have items, all). `overlaps="each"`: one by one (`AB`, `AC`, `BC`, `ABC`)
|
|
23
|
+
- `variant`: `fade` (default), `draw` (outlines first)
|
|
24
|
+
|
|
25
|
+
The demo is `demo.html` (skills example fictional).
|
|
26
|
+
|
|
27
|
+
<!-- llm: omit -->
|
|
28
|
+
Notes
|
|
29
|
+
|
|
30
|
+
- Layout: 2 sets left/right; 3 top-left, top-right, bottom. Items placed farthest from circle lines
|
|
31
|
+
- Item width estimated from characters (CJK 1, Latin 0.6). 3-set overlaps are small: 1–2 words. Shrinks to 24 px, then ctx.report
|
|
32
|
+
- Overlaps are clipPath cut-outs; theme variables only
|
|
33
|
+
- Show later steps faintly (`ctx.preview`): later circles and overlaps at `--preview-opacity` (default 0.45)
|
|
34
|
+
<!-- llm: end -->
|