@cardenelabs/cdl 0.10.0 → 0.11.0
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 +20 -1
- package/SPEC.md +15 -3
- package/dist/index.cjs +71 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +72 -26
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +71 -25
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +72 -26
- package/dist/react.js.map +1 -1
- package/dist/{render-CH1Qn3Jv.d.cts → render-DwH8v5Mb.d.cts} +9 -2
- package/dist/{render-CH1Qn3Jv.d.ts → render-DwH8v5Mb.d.ts} +9 -2
- package/package.json +1 -1
- package/src/kinds/chart-bar.tsx +49 -12
- package/src/kinds/chart-pie.tsx +80 -15
- package/src/render/nodes.tsx +18 -2
- package/src/types.ts +9 -2
- package/src/validate.ts +18 -2
package/dist/react.cjs
CHANGED
|
@@ -4886,6 +4886,7 @@ function nodeTemplateTexts(node) {
|
|
|
4886
4886
|
|
|
4887
4887
|
// src/validate.ts
|
|
4888
4888
|
var TONES2 = new Set(TONES);
|
|
4889
|
+
var DRAW_KINDS = /* @__PURE__ */ new Set(["chart-line", "chart-bar", "chart-pie"]);
|
|
4889
4890
|
var KINDS = new Set(NODE_KINDS);
|
|
4890
4891
|
var ENG_BANNED = /\b(FUNCTION|STORAGE|EVENT LOG|BALANCES MAPPING|READ|WRITE|EMIT|CALL)\b/;
|
|
4891
4892
|
function validate(diag) {
|
|
@@ -5003,8 +5004,10 @@ function validate(diag) {
|
|
|
5003
5004
|
continue;
|
|
5004
5005
|
}
|
|
5005
5006
|
const kind = diag.nodes.find((n) => n.id === id)?.kind;
|
|
5006
|
-
if (kind
|
|
5007
|
-
warnings.push(
|
|
5007
|
+
if (!DRAW_KINDS.has(String(kind))) {
|
|
5008
|
+
warnings.push(
|
|
5009
|
+
`phase "${p.id}" \u306E draw "${id}" \u306F kind "${kind}" \u3067\u3001 \u8D77\u70B9\u304B\u3089\u63CF\u304F\u52D5\u304D\u3092\u6301\u305F\u306A\u3044 (\u5BFE\u8C61\u306F ${[...DRAW_KINDS].join(" / ")})`
|
|
5010
|
+
);
|
|
5008
5011
|
}
|
|
5009
5012
|
}
|
|
5010
5013
|
for (const t of p.tweens) {
|
|
@@ -6769,8 +6772,11 @@ function ChartLineNode({
|
|
|
6769
6772
|
function ChartPieNode({
|
|
6770
6773
|
node,
|
|
6771
6774
|
active,
|
|
6772
|
-
stateValues = {}
|
|
6775
|
+
stateValues = {},
|
|
6776
|
+
drawing = false,
|
|
6777
|
+
progress = 1
|
|
6773
6778
|
}) {
|
|
6779
|
+
const instanceId = react.useId().replace(/[^A-Za-z0-9_-]/g, "");
|
|
6774
6780
|
const x0 = node.cx - node.w / 2;
|
|
6775
6781
|
const y0 = node.cy - node.h / 2;
|
|
6776
6782
|
const data = resolveChartData(node.chartData ?? [], stateValues);
|
|
@@ -6783,20 +6789,26 @@ function ChartPieNode({
|
|
|
6783
6789
|
const cx = pieAreaW / 2;
|
|
6784
6790
|
const cy = PAD_TOP + chartAreaH / 2;
|
|
6785
6791
|
let cumAngle = -Math.PI / 2;
|
|
6792
|
+
let cumFrac = 0;
|
|
6786
6793
|
const slices = data.map((d) => {
|
|
6787
6794
|
const frac = d.value / total;
|
|
6788
6795
|
const angle = frac * Math.PI * 2;
|
|
6789
6796
|
const a0 = cumAngle;
|
|
6790
6797
|
const a1 = cumAngle + angle;
|
|
6791
6798
|
cumAngle = a1;
|
|
6799
|
+
const startFrac = cumFrac;
|
|
6800
|
+
cumFrac += frac;
|
|
6792
6801
|
const x1 = cx + radius * Math.cos(a0);
|
|
6793
6802
|
const y1 = cy + radius * Math.sin(a0);
|
|
6794
6803
|
const x2 = cx + radius * Math.cos(a1);
|
|
6795
6804
|
const y2 = cy + radius * Math.sin(a1);
|
|
6796
6805
|
const large = angle > Math.PI ? 1 : 0;
|
|
6797
6806
|
const path = `M ${cx} ${cy} L ${x1} ${y1} A ${radius} ${radius} 0 ${large} 1 ${x2} ${y2} Z`;
|
|
6798
|
-
return { d, frac, path };
|
|
6807
|
+
return { d, frac, path, startFrac };
|
|
6799
6808
|
});
|
|
6809
|
+
const \u958B\u304D = drawing ? Math.min(1, Math.max(0, Number.isFinite(progress) ? progress : 1)) : 1;
|
|
6810
|
+
const \u5207\u308A\u629C\u304Did = `cdl-pie-draw-${instanceId}`;
|
|
6811
|
+
const \u958B\u304D\u59CB\u3081\u305F = (startFrac) => !drawing || \u958B\u304D > startFrac;
|
|
6800
6812
|
const legendX = pieAreaW + 8;
|
|
6801
6813
|
const legendGap = Math.min(28, chartAreaH / Math.max(data.length, 1));
|
|
6802
6814
|
const legendStartY = PAD_TOP + (chartAreaH - legendGap * data.length) / 2 + legendGap / 2;
|
|
@@ -6815,7 +6827,8 @@ function ChartPieNode({
|
|
|
6815
6827
|
strokeWidth: active ? 3 : 1.25
|
|
6816
6828
|
}
|
|
6817
6829
|
),
|
|
6818
|
-
|
|
6830
|
+
drawing && /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: \u5207\u308A\u629C\u304Did, children: \u6247\u5F62\u306E\u5207\u308A\u629C\u304D(cx, cy, radius + 2, \u958B\u304D) }) }),
|
|
6831
|
+
/* @__PURE__ */ jsxRuntime.jsx("g", { ...drawing ? { clipPath: `url(#${\u5207\u308A\u629C\u304Did})` } : {}, children: slices.map((s, idx) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
6819
6832
|
"path",
|
|
6820
6833
|
{
|
|
6821
6834
|
"data-cdl-role": "chart-pie-slice",
|
|
@@ -6827,8 +6840,8 @@ function ChartPieNode({
|
|
|
6827
6840
|
strokeWidth: 1.5
|
|
6828
6841
|
},
|
|
6829
6842
|
`slice-${idx}`
|
|
6830
|
-
)),
|
|
6831
|
-
slices.map((s, idx) => /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${legendX} ${legendStartY + idx * legendGap})`, children: [
|
|
6843
|
+
)) }),
|
|
6844
|
+
slices.map((s, idx) => !\u958B\u304D\u59CB\u3081\u305F(s.startFrac) ? null : /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${legendX} ${legendStartY + idx * legendGap})`, children: [
|
|
6832
6845
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6833
6846
|
"rect",
|
|
6834
6847
|
{
|
|
@@ -6866,6 +6879,15 @@ function ChartPieNode({
|
|
|
6866
6879
|
] }, `legend-${idx}`))
|
|
6867
6880
|
] });
|
|
6868
6881
|
}
|
|
6882
|
+
function \u6247\u5F62\u306E\u5207\u308A\u629C\u304D(cx, cy, r, \u958B\u304D) {
|
|
6883
|
+
if (\u958B\u304D <= 0) return null;
|
|
6884
|
+
if (\u958B\u304D >= 1) return /* @__PURE__ */ jsxRuntime.jsx("circle", { cx, cy, r });
|
|
6885
|
+
const a0 = -Math.PI / 2;
|
|
6886
|
+
const a1 = a0 + \u958B\u304D * Math.PI * 2;
|
|
6887
|
+
const large = \u958B\u304D > 0.5 ? 1 : 0;
|
|
6888
|
+
const d = `M ${cx} ${cy} L ${cx + r * Math.cos(a0)} ${cy + r * Math.sin(a0)} A ${r} ${r} 0 ${large} 1 ${cx + r * Math.cos(a1)} ${cy + r * Math.sin(a1)} Z`;
|
|
6889
|
+
return /* @__PURE__ */ jsxRuntime.jsx("path", { d });
|
|
6890
|
+
}
|
|
6869
6891
|
var FALLBACK_ORDER = ["accent", "teal", "warning", "success", "info", "error"];
|
|
6870
6892
|
function sliceColor(tone, idx) {
|
|
6871
6893
|
if (tone) return TONE[tone];
|
|
@@ -6874,7 +6896,9 @@ function sliceColor(tone, idx) {
|
|
|
6874
6896
|
function ChartBarNode({
|
|
6875
6897
|
node,
|
|
6876
6898
|
active,
|
|
6877
|
-
stateValues = {}
|
|
6899
|
+
stateValues = {},
|
|
6900
|
+
drawing = false,
|
|
6901
|
+
progress = 1
|
|
6878
6902
|
}) {
|
|
6879
6903
|
const x0 = node.cx - node.w / 2;
|
|
6880
6904
|
const y0 = node.cy - node.h / 2;
|
|
@@ -6897,6 +6921,8 @@ function ChartBarNode({
|
|
|
6897
6921
|
const v = vMax * i / gridCount;
|
|
6898
6922
|
return { y: yAt(v), value: v };
|
|
6899
6923
|
});
|
|
6924
|
+
const \u4F38\u3073 = drawing ? Math.min(1, Math.max(0, Number.isFinite(progress) ? progress : 1)) : 1;
|
|
6925
|
+
const \u6A2A\u8EF8\u306Ey = PAD_TOP + canvasH;
|
|
6900
6926
|
return /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${x0} ${y0})`, children: [
|
|
6901
6927
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6902
6928
|
"rect",
|
|
@@ -6953,26 +6979,28 @@ function ChartBarNode({
|
|
|
6953
6979
|
const bx = xAt(idx);
|
|
6954
6980
|
const by = yAt(d.value);
|
|
6955
6981
|
const bh = PAD_TOP + canvasH - by;
|
|
6982
|
+
const \u898B\u3048\u3066\u3044\u308B\u982D = \u6A2A\u8EF8\u306Ey - (\u6A2A\u8EF8\u306Ey - by) * \u4F38\u3073;
|
|
6983
|
+
const \u68D2 = /* @__PURE__ */ jsxRuntime.jsx(
|
|
6984
|
+
"rect",
|
|
6985
|
+
{
|
|
6986
|
+
"data-cdl-role": "chart-bar",
|
|
6987
|
+
"data-cdl-unresolved": d.unresolved ? "true" : void 0,
|
|
6988
|
+
x: bx,
|
|
6989
|
+
y: by,
|
|
6990
|
+
width: barW,
|
|
6991
|
+
height: bh,
|
|
6992
|
+
rx: 2,
|
|
6993
|
+
fill: "var(--cdl-tone-accent, #2d6a8f)",
|
|
6994
|
+
fillOpacity: 0.9
|
|
6995
|
+
}
|
|
6996
|
+
);
|
|
6956
6997
|
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
6957
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6958
|
-
"rect",
|
|
6959
|
-
{
|
|
6960
|
-
"data-cdl-role": "chart-bar",
|
|
6961
|
-
"data-cdl-unresolved": d.unresolved ? "true" : void 0,
|
|
6962
|
-
x: bx,
|
|
6963
|
-
y: by,
|
|
6964
|
-
width: barW,
|
|
6965
|
-
height: bh,
|
|
6966
|
-
rx: 2,
|
|
6967
|
-
fill: "var(--cdl-tone-accent, #2d6a8f)",
|
|
6968
|
-
fillOpacity: 0.9
|
|
6969
|
-
}
|
|
6970
|
-
),
|
|
6998
|
+
drawing ? /* @__PURE__ */ jsxRuntime.jsx("g", { transform: `translate(0 ${\u6A2A\u8EF8\u306Ey}) scale(1 ${\u4F38\u3073}) translate(0 ${-\u6A2A\u8EF8\u306Ey})`, children: \u68D2 }) : \u68D2,
|
|
6971
6999
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6972
7000
|
"text",
|
|
6973
7001
|
{
|
|
6974
7002
|
x: bx + barW / 2,
|
|
6975
|
-
y:
|
|
7003
|
+
y: \u898B\u3048\u3066\u3044\u308B\u982D - 6,
|
|
6976
7004
|
fontSize: 11,
|
|
6977
7005
|
textAnchor: "middle",
|
|
6978
7006
|
fill: "var(--cdl-text, #1a1f2a)",
|
|
@@ -12287,9 +12315,27 @@ function CdlNodeView({
|
|
|
12287
12315
|
}
|
|
12288
12316
|
);
|
|
12289
12317
|
case "chart-pie":
|
|
12290
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12318
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12319
|
+
ChartPieNode,
|
|
12320
|
+
{
|
|
12321
|
+
node: resolvedNode,
|
|
12322
|
+
active,
|
|
12323
|
+
stateValues,
|
|
12324
|
+
drawing,
|
|
12325
|
+
progress
|
|
12326
|
+
}
|
|
12327
|
+
);
|
|
12291
12328
|
case "chart-bar":
|
|
12292
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12329
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12330
|
+
ChartBarNode,
|
|
12331
|
+
{
|
|
12332
|
+
node: resolvedNode,
|
|
12333
|
+
active,
|
|
12334
|
+
stateValues,
|
|
12335
|
+
drawing,
|
|
12336
|
+
progress
|
|
12337
|
+
}
|
|
12338
|
+
);
|
|
12293
12339
|
case "gantt-timeline":
|
|
12294
12340
|
return /* @__PURE__ */ jsxRuntime.jsx(GanttNode, { node: resolvedNode, active, stateValues });
|
|
12295
12341
|
case "mind-map":
|