@shapesos/clay 0.11.0 → 0.12.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/README.md +60 -0
- package/dist/artifacts.cjs +858 -132
- package/dist/artifacts.cjs.map +1 -1
- package/dist/artifacts.d.cts +38 -5
- package/dist/artifacts.d.ts +38 -5
- package/dist/artifacts.js +13 -3
- package/dist/blocks.cjs +1185 -467
- package/dist/blocks.cjs.map +1 -1
- package/dist/blocks.css +1 -1
- package/dist/blocks.d.cts +23 -10
- package/dist/blocks.d.ts +23 -10
- package/dist/blocks.js +6 -3
- package/dist/chart.cjs +594 -0
- package/dist/chart.cjs.map +1 -0
- package/dist/chart.d.cts +439 -0
- package/dist/chart.d.ts +439 -0
- package/dist/chart.js +32 -0
- package/dist/chat.cjs +1207 -489
- package/dist/chat.cjs.map +1 -1
- package/dist/chat.d.cts +3 -2
- package/dist/chat.d.ts +3 -2
- package/dist/chat.js +7 -4
- package/dist/{chunk-MXOPG747.js → chunk-36CB624W.js} +7 -7
- package/dist/chunk-36CB624W.js.map +1 -0
- package/dist/{chunk-L35M3OD5.js → chunk-4MZZH3WX.js} +5 -11
- package/dist/chunk-4MZZH3WX.js.map +1 -0
- package/dist/chunk-AQEJRMRN.js +1 -0
- package/dist/chunk-AQEJRMRN.js.map +1 -0
- package/dist/{chunk-OUW6PUEB.js → chunk-FFX3CAOX.js} +7 -7
- package/dist/chunk-P6GUNIAE.js +11 -0
- package/dist/chunk-P6GUNIAE.js.map +1 -0
- package/dist/chunk-QXGYMDIA.js +477 -0
- package/dist/chunk-QXGYMDIA.js.map +1 -0
- package/dist/{chunk-BX5TCEPR.js → chunk-Z5JWF24N.js} +388 -105
- package/dist/chunk-Z5JWF24N.js.map +1 -0
- package/dist/index.cjs +924 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +23 -15
- package/dist/table.js +2 -1
- package/dist/types-B2aYk82c.d.cts +29 -0
- package/dist/types-B2aYk82c.d.ts +29 -0
- package/dist/types-C0BvwliI.d.cts +332 -0
- package/dist/types-C5bFH4v3.d.ts +332 -0
- package/dist/{types-DuuRI4ll.d.cts → types-DCutaXjZ.d.cts} +16 -1
- package/dist/{types-C9XX-Uhk.d.ts → types-uPfn67Dc.d.ts} +16 -1
- package/package.json +13 -1
- package/dist/chunk-BX5TCEPR.js.map +0 -1
- package/dist/chunk-L35M3OD5.js.map +0 -1
- package/dist/chunk-MEJESPTZ.js +0 -1
- package/dist/chunk-MXOPG747.js.map +0 -1
- package/dist/types-3Gzk7cRt.d.cts +0 -121
- package/dist/types-3Gzk7cRt.d.ts +0 -121
- /package/dist/{chunk-MEJESPTZ.js.map → chart.js.map} +0 -0
- /package/dist/{chunk-OUW6PUEB.js.map → chunk-FFX3CAOX.js.map} +0 -0
package/dist/chart.cjs
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/chart/index.ts
|
|
21
|
+
var chart_exports = {};
|
|
22
|
+
__export(chart_exports, {
|
|
23
|
+
BarChart: () => BarChart,
|
|
24
|
+
CHART_AXIS_PROPS: () => CHART_AXIS_PROPS,
|
|
25
|
+
CHART_GRID_PROPS: () => CHART_GRID_PROPS,
|
|
26
|
+
CHART_PALETTE: () => CHART_PALETTE,
|
|
27
|
+
ChartContainer: () => ChartContainer,
|
|
28
|
+
ChartLegendContent: () => ChartLegendContent,
|
|
29
|
+
ChartTooltipContent: () => ChartTooltipContent,
|
|
30
|
+
LineChart: () => LineChart,
|
|
31
|
+
PieChart: () => PieChart,
|
|
32
|
+
coerceNumericColumns: () => coerceNumericColumns,
|
|
33
|
+
colorForSeriesIndex: () => colorForSeriesIndex
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(chart_exports);
|
|
36
|
+
|
|
37
|
+
// src/components/chart/bar-chart/bar-chart.tsx
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_recharts2 = require("recharts");
|
|
40
|
+
|
|
41
|
+
// src/components/chart/chart-container.tsx
|
|
42
|
+
var import_recharts = require("recharts");
|
|
43
|
+
|
|
44
|
+
// src/lib/utils.ts
|
|
45
|
+
var import_clsx = require("clsx");
|
|
46
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
47
|
+
function cn(...inputs) {
|
|
48
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/components/chart/chart-container.tsx
|
|
52
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
53
|
+
function ChartContainer({
|
|
54
|
+
children,
|
|
55
|
+
height = 320,
|
|
56
|
+
width = "100%",
|
|
57
|
+
className,
|
|
58
|
+
style
|
|
59
|
+
}) {
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: cn("text-xs text-foreground", className), style: { width, height, ...style }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_recharts.ResponsiveContainer, { width: "100%", height: "100%", children }) });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/components/chart/chart-legend-content.tsx
|
|
64
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
65
|
+
function ChartLegendContent({ payload, className, iconType = "square" }) {
|
|
66
|
+
if (!payload || payload.length === 0) return null;
|
|
67
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
68
|
+
"ul",
|
|
69
|
+
{
|
|
70
|
+
className: cn("flex flex-wrap items-center justify-center gap-x-4 gap-y-2 text-xs text-brown-80", className),
|
|
71
|
+
children: payload.map((entry, i) => {
|
|
72
|
+
const swatchColor = typeof entry.color === "string" ? entry.color : "transparent";
|
|
73
|
+
const label = entry.value !== void 0 ? String(entry.value) : "";
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { className: "flex items-center gap-1.5", children: [
|
|
75
|
+
iconType === "square" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "inline-block h-2.5 w-2.5 shrink-0 rounded-sm", style: { background: swatchColor } }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "inline-block h-[3px] w-4 shrink-0 rounded-full", style: { background: swatchColor } }),
|
|
76
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label })
|
|
77
|
+
] }, `${label}-${i}`);
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/components/chart/chart-tooltip-content.tsx
|
|
84
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
85
|
+
function ChartTooltipContent({
|
|
86
|
+
active,
|
|
87
|
+
payload,
|
|
88
|
+
label,
|
|
89
|
+
className,
|
|
90
|
+
showLabel = true,
|
|
91
|
+
formatValue
|
|
92
|
+
}) {
|
|
93
|
+
if (!active || !payload || payload.length === 0) return null;
|
|
94
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
95
|
+
"div",
|
|
96
|
+
{
|
|
97
|
+
className: cn(
|
|
98
|
+
"rounded-lg border border-brown-40 bg-brown-10 px-3 py-2 text-xs shadow-sm",
|
|
99
|
+
"min-w-32 text-foreground",
|
|
100
|
+
className
|
|
101
|
+
),
|
|
102
|
+
children: [
|
|
103
|
+
showLabel && label !== void 0 && label !== null ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mb-1.5 font-medium text-brown-90", children: String(label) }) : null,
|
|
104
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("ul", { className: "space-y-1", children: payload.map((entry, i) => {
|
|
105
|
+
const name = entry.name !== void 0 ? String(entry.name) : "";
|
|
106
|
+
const rawValue = entry.value;
|
|
107
|
+
const display = formatValue ? formatValue(rawValue, name) : rawValue === void 0 ? "" : String(rawValue);
|
|
108
|
+
const swatch = typeof entry.color === "string" ? entry.color : "transparent";
|
|
109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: "flex items-center gap-2", children: [
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "inline-block h-2.5 w-2.5 shrink-0 rounded-sm", style: { background: swatch } }),
|
|
111
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-brown-70", children: name }),
|
|
112
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "ml-auto font-semibold tabular-nums text-brown-90", children: display })
|
|
113
|
+
] }, `${name}-${i}`);
|
|
114
|
+
}) })
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/tokens/colors.ts
|
|
121
|
+
var colors = {
|
|
122
|
+
// White
|
|
123
|
+
white: "#FFFFFF",
|
|
124
|
+
"white-alpha-85": "rgba(255, 255, 255, 0.85)",
|
|
125
|
+
"white-alpha-40": "rgba(255, 255, 255, 0.40)",
|
|
126
|
+
// Brown
|
|
127
|
+
"brown-10": "#FAF9F8",
|
|
128
|
+
"brown-20": "#F5F3F0",
|
|
129
|
+
"brown-30": "#EEEBE5",
|
|
130
|
+
"brown-40": "#E6E2DA",
|
|
131
|
+
"brown-50": "#CFCBC4",
|
|
132
|
+
"brown-60": "#A19E99",
|
|
133
|
+
"brown-70": "#73716D",
|
|
134
|
+
"brown-80": "#5C5A57",
|
|
135
|
+
"brown-90": "#2E2D2C",
|
|
136
|
+
"brown-100": "#171716",
|
|
137
|
+
"brown-alpha-12": "rgba(23, 23, 22, 0.12)",
|
|
138
|
+
"brown-alpha-20": "rgba(23, 23, 22, 0.20)",
|
|
139
|
+
"brown-alpha-55": "rgba(23, 23, 22, 0.55)",
|
|
140
|
+
"brown-alpha-70": "rgba(23, 23, 22, 0.70)",
|
|
141
|
+
"brown-alpha-80": "rgba(23, 23, 22, 0.80)",
|
|
142
|
+
"brown-alpha-90": "rgba(23, 23, 22, 0.90)",
|
|
143
|
+
// Fuchsia
|
|
144
|
+
"fuchsia-50": "#FAF5FF",
|
|
145
|
+
"fuchsia-300": "#F0ABFC",
|
|
146
|
+
"fuchsia-500": "#D946EF",
|
|
147
|
+
"fuchsia-600": "#C026D3",
|
|
148
|
+
"fuchsia-800": "#86198F",
|
|
149
|
+
// Pink
|
|
150
|
+
"pink-50": "#FDF2F8",
|
|
151
|
+
"pink-400": "#F472B6",
|
|
152
|
+
"pink-600": "#DB2777",
|
|
153
|
+
"pink-800": "#9D174D",
|
|
154
|
+
// Violet
|
|
155
|
+
"violet-50": "#F5F3FF",
|
|
156
|
+
"violet-400": "#A78BFA",
|
|
157
|
+
"violet-600": "#7C3AED",
|
|
158
|
+
"violet-800": "#5B21B6",
|
|
159
|
+
// Indigo
|
|
160
|
+
"indigo-50": "#EEF2FF",
|
|
161
|
+
"indigo-400": "#818CF8",
|
|
162
|
+
"indigo-500": "#6366F1",
|
|
163
|
+
"indigo-600": "#4F46E5",
|
|
164
|
+
"indigo-800": "#3730A3",
|
|
165
|
+
// Cyan
|
|
166
|
+
"cyan-50": "#E7FEFF",
|
|
167
|
+
"cyan-300": "#67E8F9",
|
|
168
|
+
"cyan-600": "#0891B2",
|
|
169
|
+
"cyan-900": "#164E63",
|
|
170
|
+
// Teal
|
|
171
|
+
"teal-50": "#EBFDF9",
|
|
172
|
+
"teal-300": "#5EEAD4",
|
|
173
|
+
"teal-600": "#0D9488",
|
|
174
|
+
// Rose
|
|
175
|
+
"rose-400": "#FB7185",
|
|
176
|
+
// Purple
|
|
177
|
+
"purple-400": "#C084FC",
|
|
178
|
+
// Blue
|
|
179
|
+
"blue-50": "#EFF6FF",
|
|
180
|
+
"blue-100": "#DBEAFE",
|
|
181
|
+
"blue-300": "#93C5FD",
|
|
182
|
+
"blue-400": "#60A5FA",
|
|
183
|
+
"blue-600": "#2563EB",
|
|
184
|
+
"blue-800": "#1E40AF",
|
|
185
|
+
// Sky
|
|
186
|
+
"sky-300": "#7DD3FC",
|
|
187
|
+
// Green
|
|
188
|
+
"green-50": "#ECF9F0",
|
|
189
|
+
"green-100": "#D4F1D9",
|
|
190
|
+
"green-400": "#3DC269",
|
|
191
|
+
"green-700": "#277C43",
|
|
192
|
+
"green-800": "#1C5930",
|
|
193
|
+
// Orange
|
|
194
|
+
"orange-50": "#FFF7ED",
|
|
195
|
+
"orange-100": "#FFEDD5",
|
|
196
|
+
"orange-200": "#FED7AA",
|
|
197
|
+
"orange-500": "#F97316",
|
|
198
|
+
"orange-600": "#EA580C",
|
|
199
|
+
// Red
|
|
200
|
+
"red-50": "#FEF2F2",
|
|
201
|
+
"red-100": "#FEE2E2",
|
|
202
|
+
"red-200": "#FECACA",
|
|
203
|
+
"red-400": "#F7776C",
|
|
204
|
+
"red-500": "#EF4444",
|
|
205
|
+
"red-600": "#DC2626"
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// src/components/chart/chart-palette.ts
|
|
209
|
+
var CHART_PALETTE = [
|
|
210
|
+
colors["blue-600"],
|
|
211
|
+
// #2563EB — primary
|
|
212
|
+
colors["blue-400"],
|
|
213
|
+
// #60A5FA — mid
|
|
214
|
+
colors["blue-300"],
|
|
215
|
+
// #93C5FD — light
|
|
216
|
+
colors["blue-100"],
|
|
217
|
+
// #DBEAFE — very light
|
|
218
|
+
colors["indigo-400"],
|
|
219
|
+
// #818CF8
|
|
220
|
+
colors["indigo-500"],
|
|
221
|
+
// #6366F1
|
|
222
|
+
colors["indigo-600"],
|
|
223
|
+
// #4F46E5
|
|
224
|
+
colors["indigo-800"],
|
|
225
|
+
// #3730A3
|
|
226
|
+
colors["blue-800"]
|
|
227
|
+
// #1E40AF — deepest
|
|
228
|
+
];
|
|
229
|
+
var OTHERS_SLICE_COLOR = colors["brown-60"];
|
|
230
|
+
var DEFAULT_OTHERS_CATEGORY_LABELS = ["others", "other"];
|
|
231
|
+
function isOthersCategory(value, labels) {
|
|
232
|
+
if (value === null || value === void 0) return false;
|
|
233
|
+
if (labels.length === 0) return false;
|
|
234
|
+
const normalized = String(value).trim().toLowerCase();
|
|
235
|
+
for (const label of labels) {
|
|
236
|
+
if (normalized === label.toLowerCase()) return true;
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
function colorForSeriesIndex(index, palette = CHART_PALETTE) {
|
|
241
|
+
return palette[index % palette.length] ?? CHART_PALETTE[0];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/components/chart/chart-styles.ts
|
|
245
|
+
var GRID_STROKE = colors["brown-40"];
|
|
246
|
+
var AXIS_STROKE = colors["brown-50"];
|
|
247
|
+
var AXIS_TICK_STYLE = {
|
|
248
|
+
fill: colors["brown-70"],
|
|
249
|
+
fontSize: 12,
|
|
250
|
+
fontWeight: 500
|
|
251
|
+
};
|
|
252
|
+
var CHART_VALUE_LABEL_STYLE = {
|
|
253
|
+
fill: colors["brown-70"],
|
|
254
|
+
fontSize: 12,
|
|
255
|
+
fontWeight: 500
|
|
256
|
+
};
|
|
257
|
+
var BAR_TOOLTIP_CURSOR_FILL = colors["brown-alpha-12"];
|
|
258
|
+
var LINE_ACTIVE_DOT_STROKE = colors["brown-10"];
|
|
259
|
+
var CHART_MARGIN = { top: 8, right: 16, left: 0, bottom: 4 };
|
|
260
|
+
var PIE_CHART_MARGIN = { top: 0, right: 24, left: 24, bottom: 4 };
|
|
261
|
+
var CHART_AXIS_PROPS = {
|
|
262
|
+
stroke: AXIS_STROKE,
|
|
263
|
+
tick: AXIS_TICK_STYLE,
|
|
264
|
+
tickLine: false,
|
|
265
|
+
axisLine: false
|
|
266
|
+
};
|
|
267
|
+
var CHART_GRID_PROPS = {
|
|
268
|
+
stroke: GRID_STROKE,
|
|
269
|
+
strokeDasharray: "3 3",
|
|
270
|
+
vertical: false
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/components/chart/chart-tick-utils.ts
|
|
274
|
+
function maxTickCharsByCategoryCount(n) {
|
|
275
|
+
if (n <= 5) return 24;
|
|
276
|
+
if (n <= 8) return 14;
|
|
277
|
+
if (n <= 12) return 10;
|
|
278
|
+
if (n <= 16) return 7;
|
|
279
|
+
return 5;
|
|
280
|
+
}
|
|
281
|
+
function truncateLabel(value, maxChars) {
|
|
282
|
+
const s = String(value ?? "");
|
|
283
|
+
if (s.length <= maxChars) return s;
|
|
284
|
+
return s.slice(0, Math.max(1, maxChars - 1)).trimEnd() + "\u2026";
|
|
285
|
+
}
|
|
286
|
+
function evenlyDistributedVisibleIndices(n, target) {
|
|
287
|
+
if (n <= target) {
|
|
288
|
+
return new Set(Array.from({ length: n }, (_, i) => i));
|
|
289
|
+
}
|
|
290
|
+
const set = /* @__PURE__ */ new Set();
|
|
291
|
+
const step = (n - 1) / (target - 1);
|
|
292
|
+
for (let i = 0; i < target; i++) {
|
|
293
|
+
set.add(Math.round(i * step));
|
|
294
|
+
}
|
|
295
|
+
return set;
|
|
296
|
+
}
|
|
297
|
+
function defaultBarTickFormatter(categoryCount) {
|
|
298
|
+
const max = maxTickCharsByCategoryCount(categoryCount);
|
|
299
|
+
return (value) => truncateLabel(value, max);
|
|
300
|
+
}
|
|
301
|
+
function defaultLineChartTickFormatter(categoryCount, visibleIndices) {
|
|
302
|
+
const max = maxTickCharsByCategoryCount(visibleIndices.size || categoryCount);
|
|
303
|
+
return (value, index) => {
|
|
304
|
+
if (!visibleIndices.has(index)) return "";
|
|
305
|
+
return truncateLabel(value, max);
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/components/chart/coerce-numeric.ts
|
|
310
|
+
function coerceNumericColumns(rows, numericKeys) {
|
|
311
|
+
return rows.map((row) => {
|
|
312
|
+
const out = { ...row };
|
|
313
|
+
for (const k of numericKeys) {
|
|
314
|
+
const v = out[k];
|
|
315
|
+
if (v == null) continue;
|
|
316
|
+
const n = Number(v);
|
|
317
|
+
out[k] = Number.isFinite(n) ? n : NaN;
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// src/components/chart/bar-chart/bar-chart.tsx
|
|
324
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
325
|
+
function BarChart({
|
|
326
|
+
data,
|
|
327
|
+
xKey,
|
|
328
|
+
series,
|
|
329
|
+
stacked = false,
|
|
330
|
+
height = 320,
|
|
331
|
+
width = "100%",
|
|
332
|
+
className,
|
|
333
|
+
palette = CHART_PALETTE,
|
|
334
|
+
showTooltip = true,
|
|
335
|
+
showLegend,
|
|
336
|
+
showGrid = true,
|
|
337
|
+
showXAxis = true,
|
|
338
|
+
showYAxis = true,
|
|
339
|
+
showValueLabels,
|
|
340
|
+
xAxisInterval = 0,
|
|
341
|
+
xAxisAngle,
|
|
342
|
+
xAxisTickFormatter
|
|
343
|
+
}) {
|
|
344
|
+
const seriesKeys = (0, import_react.useMemo)(() => series.map((s) => s.key), [series]);
|
|
345
|
+
const coercedData = (0, import_react.useMemo)(
|
|
346
|
+
() => coerceNumericColumns(data, seriesKeys),
|
|
347
|
+
[data, seriesKeys]
|
|
348
|
+
);
|
|
349
|
+
const resolvedShowLegend = showLegend ?? series.length > 1;
|
|
350
|
+
const resolvedShowValueLabels = showValueLabels ?? (!stacked && series.length === 1);
|
|
351
|
+
const resolvedAngle = xAxisAngle ?? (coercedData.length >= 8 ? -30 : 0);
|
|
352
|
+
const resolvedTickFormatter = (0, import_react.useMemo)(
|
|
353
|
+
() => xAxisTickFormatter ?? defaultBarTickFormatter(coercedData.length),
|
|
354
|
+
[xAxisTickFormatter, coercedData.length]
|
|
355
|
+
);
|
|
356
|
+
const angledLabelPad = resolvedAngle === 0 ? 0 : Math.min(Math.abs(resolvedAngle) * 0.7, 40);
|
|
357
|
+
const chartMargin = { ...CHART_MARGIN, bottom: CHART_MARGIN.bottom + angledLabelPad };
|
|
358
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_recharts2.BarChart, { data: coercedData, margin: chartMargin, barCategoryGap: "22%", children: [
|
|
359
|
+
showGrid ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_recharts2.CartesianGrid, { ...CHART_GRID_PROPS }) : null,
|
|
360
|
+
showXAxis ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
361
|
+
import_recharts2.XAxis,
|
|
362
|
+
{
|
|
363
|
+
dataKey: xKey,
|
|
364
|
+
...CHART_AXIS_PROPS,
|
|
365
|
+
interval: xAxisInterval,
|
|
366
|
+
angle: resolvedAngle,
|
|
367
|
+
textAnchor: resolvedAngle !== 0 ? "end" : "middle",
|
|
368
|
+
tickMargin: resolvedAngle === 0 ? 8 : 12,
|
|
369
|
+
height: resolvedAngle !== 0 ? 60 : void 0,
|
|
370
|
+
tickFormatter: resolvedTickFormatter
|
|
371
|
+
}
|
|
372
|
+
) : null,
|
|
373
|
+
showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_recharts2.YAxis, { ...CHART_AXIS_PROPS, width: 40 }) : null,
|
|
374
|
+
showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_recharts2.Tooltip, { cursor: { fill: BAR_TOOLTIP_CURSOR_FILL }, content: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartTooltipContent, {}) }) : null,
|
|
375
|
+
resolvedShowLegend ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
376
|
+
import_recharts2.Legend,
|
|
377
|
+
{
|
|
378
|
+
verticalAlign: "top",
|
|
379
|
+
align: "center",
|
|
380
|
+
wrapperStyle: { top: 0 },
|
|
381
|
+
itemSorter: null,
|
|
382
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartLegendContent, { iconType: "square" })
|
|
383
|
+
}
|
|
384
|
+
) : null,
|
|
385
|
+
series.map((s, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
386
|
+
import_recharts2.Bar,
|
|
387
|
+
{
|
|
388
|
+
dataKey: s.key,
|
|
389
|
+
name: s.label,
|
|
390
|
+
fill: colorForSeriesIndex(i, palette),
|
|
391
|
+
stackId: stacked ? "default" : s.key,
|
|
392
|
+
radius: barRadius(stacked, i, series.length),
|
|
393
|
+
children: resolvedShowValueLabels ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_recharts2.LabelList, { dataKey: s.key, position: "top", style: CHART_VALUE_LABEL_STYLE }) : null
|
|
394
|
+
},
|
|
395
|
+
s.key
|
|
396
|
+
))
|
|
397
|
+
] }) });
|
|
398
|
+
}
|
|
399
|
+
function barRadius(stacked, seriesIndex, seriesCount) {
|
|
400
|
+
if (!stacked) return [6, 6, 0, 0];
|
|
401
|
+
const isTopSegment = seriesIndex === seriesCount - 1;
|
|
402
|
+
return isTopSegment ? [6, 6, 0, 0] : [0, 0, 0, 0];
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/components/chart/line-chart/line-chart.tsx
|
|
406
|
+
var import_react2 = require("react");
|
|
407
|
+
var import_recharts3 = require("recharts");
|
|
408
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
409
|
+
var TARGET_VISIBLE_LABELS = 5;
|
|
410
|
+
function LineChart({
|
|
411
|
+
data,
|
|
412
|
+
xKey,
|
|
413
|
+
series,
|
|
414
|
+
smooth = true,
|
|
415
|
+
showDots = true,
|
|
416
|
+
strokeWidth = 2,
|
|
417
|
+
height = 320,
|
|
418
|
+
width = "100%",
|
|
419
|
+
className,
|
|
420
|
+
palette = CHART_PALETTE,
|
|
421
|
+
showTooltip = true,
|
|
422
|
+
showLegend,
|
|
423
|
+
showGrid = true,
|
|
424
|
+
showXAxis = true,
|
|
425
|
+
showYAxis = true,
|
|
426
|
+
showValueLabels = false,
|
|
427
|
+
xAxisInterval = 0,
|
|
428
|
+
xAxisAngle = 0,
|
|
429
|
+
xAxisTickFormatter
|
|
430
|
+
}) {
|
|
431
|
+
const seriesKeys = (0, import_react2.useMemo)(() => series.map((s) => s.key), [series]);
|
|
432
|
+
const coercedData = (0, import_react2.useMemo)(
|
|
433
|
+
() => coerceNumericColumns(data, seriesKeys),
|
|
434
|
+
[data, seriesKeys]
|
|
435
|
+
);
|
|
436
|
+
const lineType = smooth ? "monotone" : "linear";
|
|
437
|
+
const resolvedShowLegend = showLegend ?? series.length > 1;
|
|
438
|
+
const resolvedTickFormatter = (0, import_react2.useMemo)(() => {
|
|
439
|
+
if (xAxisTickFormatter) return xAxisTickFormatter;
|
|
440
|
+
const visible = evenlyDistributedVisibleIndices(coercedData.length, TARGET_VISIBLE_LABELS);
|
|
441
|
+
return defaultLineChartTickFormatter(coercedData.length, visible);
|
|
442
|
+
}, [xAxisTickFormatter, coercedData.length]);
|
|
443
|
+
const angledLabelPad = xAxisAngle === 0 ? 0 : Math.min(Math.abs(xAxisAngle) * 0.7, 40);
|
|
444
|
+
const chartMargin = { ...CHART_MARGIN, right: CHART_MARGIN.right + 16, bottom: CHART_MARGIN.bottom + angledLabelPad };
|
|
445
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_recharts3.LineChart, { data: coercedData, margin: chartMargin, children: [
|
|
446
|
+
showGrid ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts3.CartesianGrid, { ...CHART_GRID_PROPS }) : null,
|
|
447
|
+
showXAxis ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
448
|
+
import_recharts3.XAxis,
|
|
449
|
+
{
|
|
450
|
+
dataKey: xKey,
|
|
451
|
+
...CHART_AXIS_PROPS,
|
|
452
|
+
interval: xAxisInterval,
|
|
453
|
+
angle: xAxisAngle,
|
|
454
|
+
textAnchor: xAxisAngle !== 0 ? "end" : "middle",
|
|
455
|
+
tickMargin: xAxisAngle === 0 ? 8 : 12,
|
|
456
|
+
height: xAxisAngle !== 0 ? 60 : void 0,
|
|
457
|
+
tickFormatter: resolvedTickFormatter
|
|
458
|
+
}
|
|
459
|
+
) : null,
|
|
460
|
+
showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts3.YAxis, { ...CHART_AXIS_PROPS, width: 40 }) : null,
|
|
461
|
+
showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts3.Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartTooltipContent, {}) }) : null,
|
|
462
|
+
resolvedShowLegend ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
463
|
+
import_recharts3.Legend,
|
|
464
|
+
{
|
|
465
|
+
verticalAlign: "top",
|
|
466
|
+
align: "center",
|
|
467
|
+
wrapperStyle: { top: 0 },
|
|
468
|
+
itemSorter: null,
|
|
469
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChartLegendContent, { iconType: "line" })
|
|
470
|
+
}
|
|
471
|
+
) : null,
|
|
472
|
+
series.map((s, i) => {
|
|
473
|
+
const color = colorForSeriesIndex(i, palette);
|
|
474
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
475
|
+
import_recharts3.Line,
|
|
476
|
+
{
|
|
477
|
+
type: lineType,
|
|
478
|
+
dataKey: s.key,
|
|
479
|
+
name: s.label,
|
|
480
|
+
stroke: color,
|
|
481
|
+
strokeWidth,
|
|
482
|
+
dot: showDots ? { r: 3, fill: color, stroke: color, strokeWidth: 0 } : false,
|
|
483
|
+
activeDot: { r: 5, fill: color, stroke: LINE_ACTIVE_DOT_STROKE, strokeWidth: 2 },
|
|
484
|
+
children: showValueLabels ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts3.LabelList, { dataKey: s.key, position: "top", style: CHART_VALUE_LABEL_STYLE }) : null
|
|
485
|
+
},
|
|
486
|
+
s.key
|
|
487
|
+
);
|
|
488
|
+
})
|
|
489
|
+
] }) });
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/components/chart/pie-chart/pie-chart.tsx
|
|
493
|
+
var import_react3 = require("react");
|
|
494
|
+
var import_recharts4 = require("recharts");
|
|
495
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
496
|
+
function PieChart({
|
|
497
|
+
data,
|
|
498
|
+
categoryKey,
|
|
499
|
+
valueKey,
|
|
500
|
+
height = 320,
|
|
501
|
+
width = "100%",
|
|
502
|
+
className,
|
|
503
|
+
palette = CHART_PALETTE,
|
|
504
|
+
showLabels = true,
|
|
505
|
+
showTooltip = true,
|
|
506
|
+
showLegend = true,
|
|
507
|
+
innerRadius = 0,
|
|
508
|
+
outerRadius = "68%",
|
|
509
|
+
othersCategoryLabels = DEFAULT_OTHERS_CATEGORY_LABELS
|
|
510
|
+
}) {
|
|
511
|
+
const { orderedData, sliceColors } = (0, import_react3.useMemo)(() => {
|
|
512
|
+
const coerced = coerceNumericColumns(data, [valueKey]);
|
|
513
|
+
const namedRows = [];
|
|
514
|
+
const namedColors = [];
|
|
515
|
+
const othersRows = [];
|
|
516
|
+
const othersColors = [];
|
|
517
|
+
for (const row of coerced) {
|
|
518
|
+
if (isOthersCategory(row[categoryKey], othersCategoryLabels)) {
|
|
519
|
+
othersRows.push(row);
|
|
520
|
+
othersColors.push(OTHERS_SLICE_COLOR);
|
|
521
|
+
} else {
|
|
522
|
+
namedRows.push(row);
|
|
523
|
+
namedColors.push(colorForSeriesIndex(namedRows.length - 1, palette));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return {
|
|
527
|
+
orderedData: [...namedRows, ...othersRows],
|
|
528
|
+
sliceColors: [...namedColors, ...othersColors]
|
|
529
|
+
};
|
|
530
|
+
}, [data, valueKey, categoryKey, othersCategoryLabels, palette]);
|
|
531
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_recharts4.PieChart, { margin: PIE_CHART_MARGIN, children: [
|
|
532
|
+
showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_recharts4.Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartTooltipContent, {}) }) : null,
|
|
533
|
+
showLegend ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
534
|
+
import_recharts4.Legend,
|
|
535
|
+
{
|
|
536
|
+
verticalAlign: "top",
|
|
537
|
+
align: "center",
|
|
538
|
+
wrapperStyle: { top: 0 },
|
|
539
|
+
itemSorter: null,
|
|
540
|
+
content: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChartLegendContent, { iconType: "square" })
|
|
541
|
+
}
|
|
542
|
+
) : null,
|
|
543
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
544
|
+
import_recharts4.Pie,
|
|
545
|
+
{
|
|
546
|
+
data: orderedData,
|
|
547
|
+
dataKey: valueKey,
|
|
548
|
+
nameKey: categoryKey,
|
|
549
|
+
cx: "50%",
|
|
550
|
+
cy: "52%",
|
|
551
|
+
startAngle: 90,
|
|
552
|
+
endAngle: -270,
|
|
553
|
+
innerRadius,
|
|
554
|
+
outerRadius,
|
|
555
|
+
label: showLabels ? (entry) => {
|
|
556
|
+
const v = entry.value;
|
|
557
|
+
if (v === void 0 || v === null) return null;
|
|
558
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
559
|
+
"text",
|
|
560
|
+
{
|
|
561
|
+
x: entry.x,
|
|
562
|
+
y: entry.y,
|
|
563
|
+
fill: CHART_VALUE_LABEL_STYLE.fill,
|
|
564
|
+
fontSize: CHART_VALUE_LABEL_STYLE.fontSize,
|
|
565
|
+
fontWeight: CHART_VALUE_LABEL_STYLE.fontWeight,
|
|
566
|
+
textAnchor: entry.textAnchor,
|
|
567
|
+
dominantBaseline: "central",
|
|
568
|
+
children: String(v)
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
} : false,
|
|
572
|
+
labelLine: false,
|
|
573
|
+
stroke: "none",
|
|
574
|
+
strokeWidth: 0,
|
|
575
|
+
children: orderedData.map((_row, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_recharts4.Cell, { fill: sliceColors[i] }, i))
|
|
576
|
+
}
|
|
577
|
+
)
|
|
578
|
+
] }) });
|
|
579
|
+
}
|
|
580
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
581
|
+
0 && (module.exports = {
|
|
582
|
+
BarChart,
|
|
583
|
+
CHART_AXIS_PROPS,
|
|
584
|
+
CHART_GRID_PROPS,
|
|
585
|
+
CHART_PALETTE,
|
|
586
|
+
ChartContainer,
|
|
587
|
+
ChartLegendContent,
|
|
588
|
+
ChartTooltipContent,
|
|
589
|
+
LineChart,
|
|
590
|
+
PieChart,
|
|
591
|
+
coerceNumericColumns,
|
|
592
|
+
colorForSeriesIndex
|
|
593
|
+
});
|
|
594
|
+
//# sourceMappingURL=chart.cjs.map
|