@cardenelabs/cdl 0.40.9 → 0.40.10
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 +30 -1
- package/dist/index.cjs +28 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -4
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +28 -4
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +28 -4
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
- package/src/kinds/chart-stat.tsx +56 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardenelabs/cdl",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.10",
|
|
4
4
|
"description": "CDL (Chainome Diagram Language). Mermaid-like declarative DSL that compiles to animated SVG diagrams. Built for blockchain / Solidity flows, generic enough for sequence / flow / state / ER / topology diagrams.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "cardene777",
|
package/src/kinds/chart-stat.tsx
CHANGED
|
@@ -18,8 +18,13 @@ import { 実値表記, 割合表記 } from "./chart-number";
|
|
|
18
18
|
*
|
|
19
19
|
* ## 数値をいちばん大きく組む
|
|
20
20
|
*
|
|
21
|
-
* 件ごとに区画を割り、名前 / 数値 / 割合を縦に積む。 **数値の字を名前より大きくする**
|
|
22
|
-
*
|
|
21
|
+
* 件ごとに区画を割り、名前 / 数値 / 前の時点 / 割合を縦に積む。 **数値の字を名前より大きくする**
|
|
22
|
+
* のがこの種別の中身で、大小が逆転したら別の図になる。
|
|
23
|
+
*
|
|
24
|
+
* ## 前の時点は書いた図にだけ足す (cdl#763)
|
|
25
|
+
*
|
|
26
|
+
* `previous` を書いた図では数値の下に前の値を 1 行添える。 書いていない図では 1 行も足さず、
|
|
27
|
+
* 縦の位置も変えない = 前の値と関係の無い図の見た目を動かさない。
|
|
23
28
|
*
|
|
24
29
|
* ## 弧は輪郭だけの細い線にする
|
|
25
30
|
*
|
|
@@ -40,7 +45,15 @@ export function ChartStatNode({
|
|
|
40
45
|
const data = resolveChartData(node.chartData ?? [], stateValues);
|
|
41
46
|
const total = data.reduce((acc, d) => acc + d.value, 0) || 1;
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
/**
|
|
49
|
+
* 前の時点を出すか (cdl#763)。
|
|
50
|
+
*
|
|
51
|
+
* **図の単位で決める**。 件ごとに決めると、一部だけ前を持つ図で行の位置が件ごとに
|
|
52
|
+
* ずれる。 縦の位置は件数に依らないという既存の割付の考えに揃える。
|
|
53
|
+
*/
|
|
54
|
+
const 前を出す = data.some((d) => d.previous !== undefined);
|
|
55
|
+
|
|
56
|
+
const 区画 = 区画の割付(node.w, node.h, data.length, 前を出す);
|
|
44
57
|
|
|
45
58
|
/**
|
|
46
59
|
* 割合を出すか (cdl#759)。
|
|
@@ -119,6 +132,29 @@ export function ChartStatNode({
|
|
|
119
132
|
{数値}
|
|
120
133
|
</text>
|
|
121
134
|
|
|
135
|
+
{/*
|
|
136
|
+
前の時点の値 (cdl#763)。 **`0` は値なので描く** = `undefined` と区別しないと、
|
|
137
|
+
前が 0 だった件だけ黙って消える。 呼び方は積み上げの帯と揃える
|
|
138
|
+
*/}
|
|
139
|
+
{d.previous !== undefined && (
|
|
140
|
+
<text
|
|
141
|
+
data-cdl-role="chart-stat-previous"
|
|
142
|
+
data-cdl-unresolved={d.unresolved ? "true" : undefined}
|
|
143
|
+
x={枠.w / 2}
|
|
144
|
+
y={区画.前のy}
|
|
145
|
+
fontSize={収める級(
|
|
146
|
+
`前 ${実値表記(d.previous)}`,
|
|
147
|
+
枠.w - 区画.余白 * 2,
|
|
148
|
+
区画.前の級,
|
|
149
|
+
8,
|
|
150
|
+
)}
|
|
151
|
+
textAnchor="middle"
|
|
152
|
+
fill="var(--cdl-text-dim, #5a6270)"
|
|
153
|
+
>
|
|
154
|
+
{`前 ${実値表記(d.previous)}`}
|
|
155
|
+
</text>
|
|
156
|
+
)}
|
|
157
|
+
|
|
122
158
|
{/*
|
|
123
159
|
比率の弧。 **輪郭だけの細い線** で描く = 面で塗ると数値より目立ち、
|
|
124
160
|
「数値が主役」 というこの種別の中身が崩れる
|
|
@@ -171,34 +207,47 @@ export function ChartStatNode({
|
|
|
171
207
|
* 件数で横に等分する。 **縦の位置は件数に依らない** = 件数が変わると数値の高さが動く形に
|
|
172
208
|
* すると、同じ図を並べた時に数値の行が揃わない。
|
|
173
209
|
*/
|
|
174
|
-
function 区画の割付(w: number, h: number, 件数: number) {
|
|
210
|
+
function 区画の割付(w: number, h: number, 件数: number, 前を出す: boolean) {
|
|
175
211
|
const 余白 = 20;
|
|
176
212
|
const 幅 = 件数 > 0 ? w / 件数 : w;
|
|
177
213
|
const 名前の級 = 14;
|
|
178
214
|
/** 数値の級。 **名前より大きい** のがこの種別の中身 */
|
|
179
215
|
const 数値の級 = 40;
|
|
216
|
+
/** 前の時点の級。 名前と同じにする = 数値より大きくすると主役が入れ替わる (cdl#763) */
|
|
217
|
+
const 前の級 = 名前の級;
|
|
180
218
|
const 割合の級 = 12;
|
|
181
219
|
const 弧の半径 = 20;
|
|
182
220
|
const 弧の太さ = 4;
|
|
183
221
|
|
|
184
|
-
|
|
185
|
-
|
|
222
|
+
/**
|
|
223
|
+
* 前の行が使う縦の量 (cdl#763)。
|
|
224
|
+
*
|
|
225
|
+
* **前を持たない図では 0 にする**。 足すと既存の図で数値の位置が上へずれる =
|
|
226
|
+
* 前の値と関係の無い図の見た目が変わる。
|
|
227
|
+
*/
|
|
228
|
+
const 前の高さ = 前を出す ? 8 + 前の級 : 0;
|
|
229
|
+
|
|
230
|
+
// 上から 名前 / 数値 / 前 / 弧 / 割合 の順に積む。 中身の高さを出してから縦中央に寄せる
|
|
231
|
+
const 中身の高さ = 名前の級 + 12 + 数値の級 + 前の高さ + 16 + 弧の半径 * 2 + 8 + 割合の級;
|
|
186
232
|
const 上端 = Math.max(余白, (h - 中身の高さ) / 2);
|
|
187
233
|
|
|
188
234
|
const 名前のy = 上端 + 名前の級;
|
|
189
235
|
const 数値のy = 名前のy + 12 + 数値の級 * 0.78;
|
|
190
|
-
const
|
|
236
|
+
const 前のy = 数値のy + 8 + 前の級;
|
|
237
|
+
const 弧のy = 数値のy + 前の高さ + 16 + 弧の半径;
|
|
191
238
|
const 割合のy = 弧のy + 弧の半径 + 8 + 割合の級;
|
|
192
239
|
|
|
193
240
|
return {
|
|
194
241
|
余白,
|
|
195
242
|
名前の級,
|
|
196
243
|
数値の級,
|
|
244
|
+
前の級,
|
|
197
245
|
割合の級,
|
|
198
246
|
弧の半径,
|
|
199
247
|
弧の太さ,
|
|
200
248
|
名前のy,
|
|
201
249
|
数値のy,
|
|
250
|
+
前のy,
|
|
202
251
|
弧のy,
|
|
203
252
|
割合のy,
|
|
204
253
|
枠: (idx: number) => ({ x: 幅 * idx, y: 0, w: 幅, h }),
|