egatari 0.6.10 → 0.6.11-rc.1
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/README.ja.md +22 -22
- package/README.md +1 -1
- package/bin/egatari.mjs +1 -1
- package/components.lock.json +288 -144
- package/components2.lock.json +657 -1
- package/kit/build.mjs +3 -2
- package/kit/check-messages.mjs +46 -12
- package/kit/check.mjs +54 -19
- package/kit/core/article-messages.mjs +5 -4
- package/kit/core/attachments.mjs +2 -1
- package/kit/core/build-core.mjs +2 -1
- package/kit/core/check-parity.mjs +3 -1
- package/kit/core/check-result.mjs +2 -1
- package/kit/core/check-rules.mjs +132 -0
- package/kit/core/colab-core.mjs +2 -2
- package/kit/core/geometry-check.mjs +302 -0
- package/kit/core/layout-scan.mjs +9 -2
- package/kit/core/live-results.mjs +1 -1
- package/kit/core/llm-fix.mjs +3 -2
- package/kit/core/llm-outline.mjs +3 -2
- package/kit/core/llm-pack-data.mjs +114 -114
- package/kit/core/narration-lint.mjs +37 -0
- package/kit/core/new-deck-pack.mjs +2 -1
- package/kit/core/new-deck.mjs +1 -1
- package/kit/core/plural.mjs +5 -0
- package/kit/core/portable.mjs +6 -5
- package/kit/core/sample-layout.mjs +14 -0
- package/kit/core/text-band.mjs +37 -0
- package/kit/core/tier-a.mjs +2 -1
- package/kit/instruction-version.json +1 -1
- package/kit/player.json +1 -1
- package/kit/player.lock.json +2 -2
- package/kit/render-compare.mjs +5 -4
- package/kit/tools.js +2 -2
- package/package.json +3 -2
- package/server/editor-ui.js +2 -2
- package/vendor/components/CATALOG.md +12 -12
- package/vendor/components/sha256/00d9072cb279a1a68166787f53395c747072388971d916c082a106844dbf888f/index.js +315 -0
- package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/README.en.md +23 -0
- package/vendor/components/sha256/03e20fb6803de0d94e93de7c01d7d00cede57b0b2604b449daa4cb156367500d/index.js +289 -0
- package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/README.en.md +40 -0
- package/vendor/components/sha256/0e5458deb63e32aefdbf8722fa156fd44cd90d5d8f9d6a25a636007b4b599450/index.js +341 -0
- package/vendor/components/sha256/1073e03374f0fe65d2691f160bfd8c092986c168d0bd6a6094ebd444d4b89c27/index.js +592 -0
- package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/README.en.md +48 -0
- package/vendor/components/sha256/12b1b32eb3a75e9f11eff407b7876473674ae996d7ce276e2ab6ffaf41ad4376/index.js +384 -0
- package/vendor/components/sha256/147987bd84722249dab609293d4fafa93f0a2aac25b8517fda1710840b575d00/index.js +341 -0
- package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/README.en.md +23 -0
- package/vendor/components/sha256/170e9072285213a2b4e79d7c2e4ddb882d1501e60b5da63c59b1679643163005/index.js +120 -0
- package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/README.en.md +32 -0
- package/vendor/components/sha256/17da8ef5ce58354df54ebb52c8a9b0726e69d06ac28cc8e78f807ec338002782/index.js +222 -0
- package/vendor/components/sha256/1b30dfd9b366ff07556024eb8ce75cca2eac8001fa392eed4e1232047001ec74/index.js +404 -0
- package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/README.en.md +66 -0
- package/vendor/components/sha256/37846655693f8dd869d11d3d4cddb43be57f848037d0e49564b2250401448ab5/index.js +920 -0
- package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/README.en.md +50 -0
- package/vendor/components/sha256/3fdd15756f779a16362dd854f143ca4343154059882d88d44adf64745c7876e3/index.js +171 -0
- package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/README.en.md +31 -0
- package/vendor/components/sha256/435c3f8e0c0abc123866e57ae2c7f3409e19d14a2eb67b1fde84c4da5d95f14c/index.js +232 -0
- package/vendor/components/sha256/43740da51de85c1b7ec1eaf688f93fd9ea25b15977ab075e6abac196f08643a6/index.js +122 -0
- package/vendor/components/sha256/4817f77bd021ec5c77d5a15ee56e2e34d31d1d98630e86225eb20f2f9bf095e9/index.js +812 -0
- package/vendor/components/sha256/4e4bf3b2968c36a334dc997e32e36f22ecbc4f5dfe1c76bb7a5beef002fe8899/index.js +228 -0
- package/vendor/components/sha256/553e132d1f84caad648bb7175a206d4c5d18c005b5ca17989f5e8a5e3f5cdfa1/index.js +75 -0
- package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/README.en.md +34 -0
- package/vendor/components/sha256/5b02d8a81a41f4d1658f1972f3fc91de3cc431b2c71bb6b92601d58f734de9ec/index.js +244 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/LICENSE-tabler.txt +21 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/index.js +4868 -0
- package/vendor/components/sha256/5c72414df5a948a7cbb882be1e5bdd4113d188e357d4a0f01fabda15781417eb/names.txt +4808 -0
- package/vendor/components/sha256/636f47e955f5550f046cfc7a3de8de70c4b97aa77771bde2ee0e31d706bb032e/index.js +278 -0
- package/vendor/components/sha256/65ddc34bd9c75e073f4c2cd283369417fe88769521809670c6b8730852d4f647/index.js +97 -0
- package/vendor/components/sha256/6b0c75b0f697fe451197301de82a113f1c2548b67f7a8d2b56576d2bae8e240c/index.js +607 -0
- package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/README.en.md +33 -0
- package/vendor/components/sha256/6cdf432d3e61be3ff15e80910369324ac7ea0e8b9f62c32ef37bf09a5bfe93b9/index.js +390 -0
- package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/README.en.md +31 -0
- package/vendor/components/sha256/6d648d0e5c96ec680c04a14b7c3d672010d3b9f101197689e9672ec00174383d/index.js +267 -0
- package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/README.en.md +22 -0
- package/vendor/components/sha256/71208afc5c8ea1ed6d2180f46de7385e43990cfb046ba350eefb917eca5d92fe/index.js +145 -0
- package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/README.en.md +44 -0
- package/vendor/components/sha256/7552a029f30f9c2f2ec8c5af4f144b63eeffc9172b53e35a925821f69a738b64/index.js +203 -0
- package/vendor/components/sha256/781a45d97f1325cfb40aa98d00e1db9600949158fdb2749b0223b019c67a80f2/index.js +919 -0
- package/vendor/components/sha256/850944419734168be3dc202057de128131869c471cb8ab3baec2cfe789d56493/index.js +465 -0
- package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/README.en.md +37 -0
- package/vendor/components/sha256/863d4d42075fbae1084089730f10da943c88d3e3e655235f28c24b9a3cf95c88/index.js +424 -0
- package/vendor/components/sha256/8a892d25d0bb6105ba31ea690b465876ce3af1fbaf18e2a9ce44ad2fee81260e/index.js +162 -0
- package/vendor/components/sha256/8acec8f299510287fbad6a69311ec58a39b0e99647dd03609c818e053b3b6087/index.js +484 -0
- package/vendor/components/sha256/8ef66bd1e800bcbedef436585469d308665aaa1ab6011aee699544302d0a8ad0/index.js +312 -0
- package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/README.en.md +40 -0
- package/vendor/components/sha256/8fa5ed6ab12a27542e077ff965bea626ff9450b330609304dc1148fc8dbb68b0/index.js +348 -0
- package/vendor/components/sha256/a0c71874d83045baaef70285bd00d87a7c6c43219fa5630dfff60d5cb08509be/index.js +250 -0
- package/vendor/components/sha256/a31f39625d7d1087d06a72b644cec417372f98add940288257ef07f812d8395a/index.js +747 -0
- package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/README.en.md +38 -0
- package/vendor/components/sha256/ae04a57be4a26b7443796a93c58adcf1cbcf746120eba619bf9c2bcdce53c640/index.js +289 -0
- package/vendor/components/sha256/ae06622a328da2a01260bc68b28bb632c391e8d62a4e8387638e5a944525a418/index.js +521 -0
- package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/README.en.md +24 -0
- package/vendor/components/sha256/b490139e9afa84164054738532d5ec4985bf071e40791d903012fe3b850bae43/index.js +103 -0
- package/vendor/components/sha256/b756c66d5c6e6ace90912ab467dea3031f2c9b291d8b2a786ca660faa0e8ac84/index.js +121 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ABCJS-ADAPTER.md +101 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/LICENSE-abcjs.txt +21 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/chords.json +89 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/doremi.json +261 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/extras.json +192 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/kaeru.json +521 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/rhythm.json +248 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/fixtures/ties.json +360 -0
- package/vendor/components/sha256/babd98da50ea334b63f79c66be436d092e8aea32654e011a6444667abb882e77/index.js +508 -0
- package/vendor/components/sha256/bea7cb344f55677d5756c9711b90cc971126830ec5f66a03f71f13dbfadc401e/index.js +351 -0
- package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/README.en.md +42 -0
- package/vendor/components/sha256/c08b25a2f7be68c36634cdee180aa617fd018d80b7ddf2a484a2edb4acffdbe0/index.js +268 -0
- package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/README.en.md +51 -0
- package/vendor/components/sha256/cbe8bb4b2fd0845a9333bc2064d86758ea6465992ad86a99167ba17f57f3e382/index.js +228 -0
- package/vendor/components/sha256/d2df3d70fc7c6e07e3cad7332a7e5501e84abeb24653786e567f57046adebcba/index.js +268 -0
- package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/README.en.md +35 -0
- package/vendor/components/sha256/d386f2b94cd9fbed765ad301aa7009228599edb2859efe7f37a98d7aaa44b9bb/index.js +179 -0
- package/vendor/components/sha256/e6d219f67d241fdf00a40d4cec261d9dd3c09ad3110d3418d4e843d0f2b8c196/index.js +429 -0
- package/vendor/components/sha256/ef60e6c089f5f6e909f439af8fc0c9c0a2d7a1aafad5e65be6328ba993b990a0/index.js +354 -0
- package/vendor/components/sha256/f6f47601c90f0195353e94b76d57499591d6330a7e35714958a2c41229f70da2/index.js +198 -0
- package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/README.en.md +44 -0
- package/vendor/components/sha256/f9159c87fa998487787f738fdfab52aa2483f52f170fc258840b127f6ed06051/index.js +304 -0
- package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/README.en.md +42 -0
- package/vendor/components/sha256/fb482cbe2ca1da07d08f41880e03fe75ff3f1d29842ff40946541e63030219b8/index.js +481 -0
- package/vendor/components/sha256/fdcea28e27638d8bfe234016672375e14de8bb97c32f7b6840d1b7b10ac4b1cd/index.js +233 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/LICENSE-strokesvg.txt +115 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/OFL.txt +93 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/index.js +749 -0
- package/vendor/components/sha256/ff5eaa083a46db6aefc13d97b27c9487f9fc318805f5c89b05a12e63703b7a72/strokes-CHANGES.md +20 -0
- package/vendor/components-2/manifest-2.7.0.json +2118 -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
|
+
});
|