@shapesos/clay 0.15.0 → 0.16.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 +14 -0
- package/dist/artifacts.cjs +85 -34
- package/dist/artifacts.cjs.map +1 -1
- package/dist/artifacts.js +2 -2
- package/dist/blocks.cjs +85 -34
- package/dist/blocks.cjs.map +1 -1
- package/dist/blocks.css +1 -1
- package/dist/blocks.js +3 -3
- package/dist/chart.cjs +85 -34
- package/dist/chart.cjs.map +1 -1
- package/dist/chart.d.cts +12 -10
- package/dist/chart.d.ts +12 -10
- package/dist/chart.js +1 -1
- package/dist/chat.cjs +85 -34
- package/dist/chat.cjs.map +1 -1
- package/dist/chat.js +4 -4
- package/dist/{chunk-XFJ6XMJZ.js → chunk-2YCBDSPK.js} +2 -2
- package/dist/{chunk-3THOTQO3.js → chunk-GAZRZZRF.js} +3 -3
- package/dist/{chunk-YZB6YXKK.js → chunk-U3IXCSV6.js} +86 -35
- package/dist/chunk-U3IXCSV6.js.map +1 -0
- package/dist/{chunk-MDAWYZBI.js → chunk-UZKNSAAD.js} +2 -2
- package/dist/index.cjs +85 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-YZB6YXKK.js.map +0 -1
- /package/dist/{chunk-XFJ6XMJZ.js.map → chunk-2YCBDSPK.js.map} +0 -0
- /package/dist/{chunk-3THOTQO3.js.map → chunk-GAZRZZRF.js.map} +0 -0
- /package/dist/{chunk-MDAWYZBI.js.map → chunk-UZKNSAAD.js.map} +0 -0
package/dist/chat.cjs
CHANGED
|
@@ -1298,6 +1298,11 @@ var CHART_PALETTE = [
|
|
|
1298
1298
|
];
|
|
1299
1299
|
var OTHERS_SLICE_COLOR = colors["brown-60"];
|
|
1300
1300
|
var DEFAULT_OTHERS_CATEGORY_LABELS = ["others", "other"];
|
|
1301
|
+
var NONE_CATEGORY_VALUES = ["", "(none)", "none", "null", "undefined", "n/a", "-"];
|
|
1302
|
+
function isNoneCategory(value) {
|
|
1303
|
+
if (value === null || value === void 0) return true;
|
|
1304
|
+
return NONE_CATEGORY_VALUES.includes(String(value).trim().toLowerCase());
|
|
1305
|
+
}
|
|
1301
1306
|
function isOthersCategory(value, labels) {
|
|
1302
1307
|
if (value === null || value === void 0) return false;
|
|
1303
1308
|
if (labels.length === 0) return false;
|
|
@@ -1353,6 +1358,13 @@ function truncateLabel(value, maxChars) {
|
|
|
1353
1358
|
if (s.length <= maxChars) return s;
|
|
1354
1359
|
return s.slice(0, Math.max(1, maxChars - 1)).trimEnd() + "\u2026";
|
|
1355
1360
|
}
|
|
1361
|
+
var compactNumberFormat = new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 });
|
|
1362
|
+
function compactNumberTickFormatter(value) {
|
|
1363
|
+
if (value === null || value === void 0) return "";
|
|
1364
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
1365
|
+
if (!Number.isFinite(n)) return String(value);
|
|
1366
|
+
return compactNumberFormat.format(n);
|
|
1367
|
+
}
|
|
1356
1368
|
function evenlyDistributedVisibleIndices(n, target) {
|
|
1357
1369
|
if (n <= target) {
|
|
1358
1370
|
return new Set(Array.from({ length: n }, (_, i) => i));
|
|
@@ -1392,6 +1404,11 @@ function coerceNumericColumns(rows, numericKeys) {
|
|
|
1392
1404
|
|
|
1393
1405
|
// src/components/chart/bar-chart/bar-chart.tsx
|
|
1394
1406
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1407
|
+
var STACK_TOTAL_KEY = "__stackTotal";
|
|
1408
|
+
var VALUE_LABEL_HEADROOM = 20;
|
|
1409
|
+
function sumSeries(row, keys) {
|
|
1410
|
+
return keys.reduce((sum, key) => sum + (Number(row[key]) || 0), 0);
|
|
1411
|
+
}
|
|
1395
1412
|
function BarChart({
|
|
1396
1413
|
data,
|
|
1397
1414
|
xKey,
|
|
@@ -1417,15 +1434,24 @@ function BarChart({
|
|
|
1417
1434
|
[data, seriesKeys]
|
|
1418
1435
|
);
|
|
1419
1436
|
const resolvedShowLegend = showLegend ?? series.length > 1;
|
|
1420
|
-
const resolvedShowValueLabels = showValueLabels ??
|
|
1437
|
+
const resolvedShowValueLabels = showValueLabels ?? true;
|
|
1438
|
+
const plotData = (0, import_react9.useMemo)(() => {
|
|
1439
|
+
if (!stacked || !resolvedShowValueLabels) return coercedData;
|
|
1440
|
+
return coercedData.map((row) => ({ ...row, [STACK_TOTAL_KEY]: sumSeries(row, seriesKeys) }));
|
|
1441
|
+
}, [coercedData, stacked, resolvedShowValueLabels, seriesKeys]);
|
|
1421
1442
|
const resolvedAngle = xAxisAngle ?? (coercedData.length >= 8 ? -30 : 0);
|
|
1422
1443
|
const resolvedTickFormatter = (0, import_react9.useMemo)(
|
|
1423
1444
|
() => xAxisTickFormatter ?? defaultBarTickFormatter(coercedData.length),
|
|
1424
1445
|
[xAxisTickFormatter, coercedData.length]
|
|
1425
1446
|
);
|
|
1426
1447
|
const angledLabelPad = resolvedAngle === 0 ? 0 : Math.min(Math.abs(resolvedAngle) * 0.7, 40);
|
|
1427
|
-
const
|
|
1428
|
-
|
|
1448
|
+
const valueLabelHeadroom = resolvedShowValueLabels ? VALUE_LABEL_HEADROOM : 0;
|
|
1449
|
+
const chartMargin = {
|
|
1450
|
+
...CHART_MARGIN,
|
|
1451
|
+
top: CHART_MARGIN.top + valueLabelHeadroom,
|
|
1452
|
+
bottom: CHART_MARGIN.bottom + angledLabelPad
|
|
1453
|
+
};
|
|
1454
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_recharts2.BarChart, { data: plotData, margin: chartMargin, barCategoryGap: "22%", children: [
|
|
1429
1455
|
showGrid ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.CartesianGrid, { ...CHART_GRID_PROPS }) : null,
|
|
1430
1456
|
showXAxis ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1431
1457
|
import_recharts2.XAxis,
|
|
@@ -1440,7 +1466,7 @@ function BarChart({
|
|
|
1440
1466
|
tickFormatter: resolvedTickFormatter
|
|
1441
1467
|
}
|
|
1442
1468
|
) : null,
|
|
1443
|
-
showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.YAxis, { ...CHART_AXIS_PROPS, width: 40 }) : null,
|
|
1469
|
+
showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.YAxis, { ...CHART_AXIS_PROPS, width: 40, tickFormatter: compactNumberTickFormatter }) : null,
|
|
1444
1470
|
showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.Tooltip, { cursor: { fill: BAR_TOOLTIP_CURSOR_FILL }, content: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartTooltipContent, {}) }) : null,
|
|
1445
1471
|
resolvedShowLegend ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1446
1472
|
import_recharts2.Legend,
|
|
@@ -1452,18 +1478,23 @@ function BarChart({
|
|
|
1452
1478
|
content: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ChartLegendContent, { iconType: "square" })
|
|
1453
1479
|
}
|
|
1454
1480
|
) : null,
|
|
1455
|
-
series.map((s, i) =>
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1481
|
+
series.map((s, i) => {
|
|
1482
|
+
const isTopSegment = i === series.length - 1;
|
|
1483
|
+
const labelDataKey = stacked ? STACK_TOTAL_KEY : s.key;
|
|
1484
|
+
const showLabel = resolvedShowValueLabels && (!stacked || isTopSegment);
|
|
1485
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1486
|
+
import_recharts2.Bar,
|
|
1487
|
+
{
|
|
1488
|
+
dataKey: s.key,
|
|
1489
|
+
name: s.label,
|
|
1490
|
+
fill: colorForSeriesIndex(i, palette),
|
|
1491
|
+
stackId: stacked ? "default" : s.key,
|
|
1492
|
+
radius: barRadius(stacked, i, series.length),
|
|
1493
|
+
children: showLabel ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_recharts2.LabelList, { dataKey: labelDataKey, position: "top", style: CHART_VALUE_LABEL_STYLE }) : null
|
|
1494
|
+
},
|
|
1495
|
+
s.key
|
|
1496
|
+
);
|
|
1497
|
+
})
|
|
1467
1498
|
] }) });
|
|
1468
1499
|
}
|
|
1469
1500
|
function barRadius(stacked, seriesIndex, seriesCount) {
|
|
@@ -1579,7 +1610,7 @@ function LineChart({
|
|
|
1579
1610
|
tickFormatter: resolvedTickFormatter
|
|
1580
1611
|
}
|
|
1581
1612
|
) : null,
|
|
1582
|
-
showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_recharts3.YAxis, { ...CHART_AXIS_PROPS, width: 40 }) : null,
|
|
1613
|
+
showYAxis ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_recharts3.YAxis, { ...CHART_AXIS_PROPS, width: 40, tickFormatter: compactNumberTickFormatter }) : null,
|
|
1583
1614
|
showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_recharts3.Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChartTooltipContent, {}) }) : null,
|
|
1584
1615
|
resolvedShowLegend ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1585
1616
|
import_recharts3.Legend,
|
|
@@ -1637,6 +1668,42 @@ var LineChartVariantService = {
|
|
|
1637
1668
|
// src/components/chart/pie-chart/pie-chart.tsx
|
|
1638
1669
|
var import_react11 = require("react");
|
|
1639
1670
|
var import_recharts4 = require("recharts");
|
|
1671
|
+
|
|
1672
|
+
// src/components/chart/pie-chart/utils.ts
|
|
1673
|
+
function mergedOthersLabel(leftoverRows, categoryKey, othersCategoryLabels) {
|
|
1674
|
+
const explicit = leftoverRows.find((row) => isOthersCategory(row[categoryKey], othersCategoryLabels));
|
|
1675
|
+
if (explicit) return String(explicit[categoryKey]);
|
|
1676
|
+
const fallback = othersCategoryLabels[0] ?? "Other";
|
|
1677
|
+
return fallback.charAt(0).toUpperCase() + fallback.slice(1);
|
|
1678
|
+
}
|
|
1679
|
+
function buildPieSlices(data, categoryKey, valueKey, othersCategoryLabels, palette) {
|
|
1680
|
+
const namedRows = [];
|
|
1681
|
+
const namedColors = [];
|
|
1682
|
+
const leftoverRows = [];
|
|
1683
|
+
for (const row of data) {
|
|
1684
|
+
const isLeftover = othersCategoryLabels.length > 0 && (isNoneCategory(row[categoryKey]) || isOthersCategory(row[categoryKey], othersCategoryLabels));
|
|
1685
|
+
if (isLeftover) {
|
|
1686
|
+
leftoverRows.push(row);
|
|
1687
|
+
} else {
|
|
1688
|
+
namedRows.push(row);
|
|
1689
|
+
namedColors.push(colorForSeriesIndex(namedRows.length - 1, palette));
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
if (leftoverRows.length === 0) {
|
|
1693
|
+
return { orderedData: namedRows, sliceColors: namedColors };
|
|
1694
|
+
}
|
|
1695
|
+
const total = leftoverRows.reduce((sum, row) => sum + (Number(row[valueKey]) || 0), 0);
|
|
1696
|
+
const mergedRow = {
|
|
1697
|
+
[categoryKey]: mergedOthersLabel(leftoverRows, categoryKey, othersCategoryLabels),
|
|
1698
|
+
[valueKey]: total
|
|
1699
|
+
};
|
|
1700
|
+
return {
|
|
1701
|
+
orderedData: [...namedRows, mergedRow],
|
|
1702
|
+
sliceColors: [...namedColors, OTHERS_SLICE_COLOR]
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
// src/components/chart/pie-chart/pie-chart.tsx
|
|
1640
1707
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1641
1708
|
function PieChart({
|
|
1642
1709
|
data,
|
|
@@ -1655,23 +1722,7 @@ function PieChart({
|
|
|
1655
1722
|
}) {
|
|
1656
1723
|
const { orderedData, sliceColors } = (0, import_react11.useMemo)(() => {
|
|
1657
1724
|
const coerced = coerceNumericColumns(data, [valueKey]);
|
|
1658
|
-
|
|
1659
|
-
const namedColors = [];
|
|
1660
|
-
const othersRows = [];
|
|
1661
|
-
const othersColors = [];
|
|
1662
|
-
for (const row of coerced) {
|
|
1663
|
-
if (isOthersCategory(row[categoryKey], othersCategoryLabels)) {
|
|
1664
|
-
othersRows.push(row);
|
|
1665
|
-
othersColors.push(OTHERS_SLICE_COLOR);
|
|
1666
|
-
} else {
|
|
1667
|
-
namedRows.push(row);
|
|
1668
|
-
namedColors.push(colorForSeriesIndex(namedRows.length - 1, palette));
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
return {
|
|
1672
|
-
orderedData: [...namedRows, ...othersRows],
|
|
1673
|
-
sliceColors: [...namedColors, ...othersColors]
|
|
1674
|
-
};
|
|
1725
|
+
return buildPieSlices(coerced, categoryKey, valueKey, othersCategoryLabels, palette);
|
|
1675
1726
|
}, [data, valueKey, categoryKey, othersCategoryLabels, palette]);
|
|
1676
1727
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ChartContainer, { height, width, className, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_recharts4.PieChart, { margin: PIE_CHART_MARGIN, children: [
|
|
1677
1728
|
showTooltip ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_recharts4.Tooltip, { content: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ChartTooltipContent, {}) }) : null,
|