@cardenelabs/cdl 0.40.8 → 0.40.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardenelabs/cdl",
3
- "version": "0.40.8",
3
+ "version": "0.40.9",
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",
@@ -42,6 +42,18 @@ export function ChartStatNode({
42
42
 
43
43
  const 区画 = 区画の割付(node.w, node.h, data.length);
44
44
 
45
+ /**
46
+ * 割合を出すか (cdl#759)。
47
+ *
48
+ * 割合は **この図に載っている全件の合計に対する取り分** なので、件が 1 つだと分母が
49
+ * 自分自身になり必ず `100%` になる。 値が動いても割合は動かない。 数値を主役にする
50
+ * 種別で、主役の隣に何も伝えない数と輪を常に出すことになる。
51
+ *
52
+ * **判定は件数で行う**。 `割合 === 1` で判定すると、件が 2 つ以上でも片方が 0 の図まで
53
+ * 消える。 その図の `100%` は「他が 0 で自分が全部」 という読みが成立する。
54
+ */
55
+ const 割合を出す = data.length > 1;
56
+
45
57
  return (
46
58
  <g transform={`translate(${x0} ${y0})`}>
47
59
  <rect
@@ -64,7 +76,11 @@ export function ChartStatNode({
64
76
  // 数値は区画に収まるまで小さくする。 収まらないまま描くと隣の区画へはみ出す
65
77
  const 数値の級 = 収める級(数値, 枠.w - 区画.余白 * 2, 区画.数値の級, 区画.名前の級 + 1);
66
78
  return (
67
- <g key={`stat-${idx}`} data-cdl-role="chart-stat-item" transform={`translate(${枠.x} ${枠.y})`}>
79
+ <g
80
+ key={`stat-${idx}`}
81
+ data-cdl-role="chart-stat-item"
82
+ transform={`translate(${枠.x} ${枠.y})`}
83
+ >
68
84
  {/* 仕切り。 1 件だけの図では引かない (仕切る相手がいない) */}
69
85
  {idx > 0 && (
70
86
  <line
@@ -107,17 +123,19 @@ export function ChartStatNode({
107
123
  比率の弧。 **輪郭だけの細い線** で描く = 面で塗ると数値より目立ち、
108
124
  「数値が主役」 というこの種別の中身が崩れる
109
125
  */}
110
- <circle
111
- data-cdl-role="chart-stat-track"
112
- cx={枠.w / 2}
113
- cy={区画.弧のy}
114
- r={区画.弧の半径}
115
- fill="none"
116
- stroke="var(--cdl-divider, #d4d4d8)"
117
- strokeWidth={区画.弧の太さ}
118
- strokeOpacity={0.5}
119
- />
120
- {frac > 0 && (
126
+ {割合を出す && (
127
+ <circle
128
+ data-cdl-role="chart-stat-track"
129
+ cx={枠.w / 2}
130
+ cy={区画.弧のy}
131
+ r={区画.弧の半径}
132
+ fill="none"
133
+ stroke="var(--cdl-divider, #d4d4d8)"
134
+ strokeWidth={区画.弧の太さ}
135
+ strokeOpacity={0.5}
136
+ />
137
+ )}
138
+ {割合を出す && frac > 0 && (
121
139
  <path
122
140
  data-cdl-role="chart-stat-arc"
123
141
  d={弧の道(枠.w / 2, 区画.弧のy, 区画.弧の半径, Math.min(frac, 0.9999))}
@@ -128,16 +146,18 @@ export function ChartStatNode({
128
146
  />
129
147
  )}
130
148
 
131
- <text
132
- data-cdl-role="chart-stat-share"
133
- x={枠.w / 2}
134
- y={区画.割合のy}
135
- fontSize={区画.割合の級}
136
- textAnchor="middle"
137
- fill="var(--cdl-text-dim, #5a6270)"
138
- >
139
- {割合表記(frac)}
140
- </text>
149
+ {割合を出す && (
150
+ <text
151
+ data-cdl-role="chart-stat-share"
152
+ x={枠.w / 2}
153
+ y={区画.割合のy}
154
+ fontSize={区画.割合の級}
155
+ textAnchor="middle"
156
+ fill="var(--cdl-text-dim, #5a6270)"
157
+ >
158
+ {割合表記(frac)}
159
+ </text>
160
+ )}
141
161
  </g>
142
162
  );
143
163
  })}