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