@platned/ui 0.10.1 → 0.10.2
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/dist/index.cjs +99 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +99 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11043,6 +11043,7 @@ function BarChart({
|
|
|
11043
11043
|
length = 240,
|
|
11044
11044
|
showLabels = true,
|
|
11045
11045
|
showValues = false,
|
|
11046
|
+
reference,
|
|
11046
11047
|
radius = 3,
|
|
11047
11048
|
label,
|
|
11048
11049
|
className
|
|
@@ -11053,73 +11054,111 @@ function BarChart({
|
|
|
11053
11054
|
const categoryTotals = categories.map(
|
|
11054
11055
|
(_, ci) => stacked ? series.reduce((sum, s) => sum + Math.max(0, s.values[ci] ?? 0), 0) : Math.max(...series.map((s) => Math.max(0, s.values[ci] ?? 0)))
|
|
11055
11056
|
);
|
|
11056
|
-
const
|
|
11057
|
+
const referenceValue = reference ? Math.max(0, reference.value) : 0;
|
|
11058
|
+
const max = Math.max(...categoryTotals, referenceValue, 1);
|
|
11057
11059
|
const horizontal = orientation === "horizontal";
|
|
11058
|
-
|
|
11060
|
+
const referenceColor = reference ? resolveChartColor(reference.color, reference.tone ?? "warning") : void 0;
|
|
11061
|
+
const referenceAt = `${referenceValue / max * 100}%`;
|
|
11062
|
+
const accessibleName = label && reference?.label ? `${label}. ${reference.label}` : label;
|
|
11063
|
+
return /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)(
|
|
11059
11064
|
"div",
|
|
11060
11065
|
{
|
|
11061
|
-
className: (0, import_clsx74.default)(
|
|
11066
|
+
className: (0, import_clsx74.default)(
|
|
11067
|
+
"flex w-full min-w-0",
|
|
11068
|
+
horizontal ? "flex-col gap-2" : "flex-row items-end gap-3",
|
|
11069
|
+
reference && "relative",
|
|
11070
|
+
className
|
|
11071
|
+
),
|
|
11062
11072
|
role: label ? "img" : void 0,
|
|
11063
|
-
"aria-label":
|
|
11073
|
+
"aria-label": accessibleName,
|
|
11064
11074
|
"aria-hidden": label ? void 0 : true,
|
|
11065
|
-
children:
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
|
-
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
|
|
11075
|
+
children: [
|
|
11076
|
+
categories.map((category, ci) => {
|
|
11077
|
+
const bars = series.map((s, si) => ({
|
|
11078
|
+
key: s.label,
|
|
11079
|
+
value: Math.max(0, s.values[ci] ?? 0),
|
|
11080
|
+
color: resolveChartColor(s.color, s.tone, si)
|
|
11081
|
+
}));
|
|
11082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)(
|
|
11083
|
+
"div",
|
|
11084
|
+
{
|
|
11085
|
+
className: (0, import_clsx74.default)("flex min-w-0", horizontal ? "flex-col gap-1" : "h-full flex-col justify-end gap-1.5"),
|
|
11086
|
+
style: horizontal ? void 0 : { width: perCategory },
|
|
11087
|
+
children: [
|
|
11088
|
+
showLabels && horizontal && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: (0, import_clsx74.default)("truncate text-default-secondary", labelClass2), children: category }),
|
|
11089
|
+
/* @__PURE__ */ (0, import_jsx_runtime96.jsxs)(
|
|
11090
|
+
"div",
|
|
11091
|
+
{
|
|
11092
|
+
className: (0, import_clsx74.default)("flex", horizontal ? "items-center gap-2" : "w-full flex-1 items-end justify-center"),
|
|
11093
|
+
style: horizontal ? void 0 : { height: length },
|
|
11094
|
+
children: [
|
|
11095
|
+
/* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
|
|
11096
|
+
"div",
|
|
11097
|
+
{
|
|
11098
|
+
className: (0, import_clsx74.default)("flex min-w-0", stacked ? "gap-0" : ""),
|
|
11099
|
+
style: horizontal ? { width: length, flexDirection: stacked ? "row" : "column", gap: stacked ? 0 : gap } : {
|
|
11100
|
+
height: "100%",
|
|
11101
|
+
width: perCategory,
|
|
11102
|
+
flexDirection: stacked ? "column-reverse" : "row",
|
|
11103
|
+
alignItems: "flex-end",
|
|
11104
|
+
gap: stacked ? 0 : gap
|
|
11105
|
+
},
|
|
11106
|
+
children: bars.map((bar) => {
|
|
11107
|
+
const extent = `${bar.value / max * 100}%`;
|
|
11108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
|
|
11109
|
+
"div",
|
|
11110
|
+
{
|
|
11111
|
+
title: `${category} \xB7 ${bar.key}: ${bar.value}`,
|
|
11112
|
+
className: "transition-all motion-reduce:transition-none",
|
|
11113
|
+
style: {
|
|
11114
|
+
backgroundColor: bar.color,
|
|
11115
|
+
borderRadius: radius,
|
|
11116
|
+
...horizontal ? { width: extent, height: stacked ? band : band } : { height: extent, width: stacked ? perCategory : band }
|
|
11117
|
+
}
|
|
11118
|
+
},
|
|
11119
|
+
bar.key
|
|
11120
|
+
);
|
|
11121
|
+
})
|
|
11122
|
+
}
|
|
11123
|
+
),
|
|
11124
|
+
showValues && horizontal && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: (0, import_clsx74.default)("shrink-0 tabular-nums text-default-secondary", labelClass2), children: categoryTotals[ci] })
|
|
11125
|
+
]
|
|
11126
|
+
}
|
|
11127
|
+
),
|
|
11128
|
+
showLabels && !horizontal && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: (0, import_clsx74.default)("truncate text-center text-default-secondary", labelClass2), children: category })
|
|
11129
|
+
]
|
|
11130
|
+
},
|
|
11131
|
+
category
|
|
11132
|
+
);
|
|
11133
|
+
}),
|
|
11134
|
+
reference && // Laid over the bar area only. Vertical bars all start at the top of their column
|
|
11135
|
+
// (the labels sit below), so the band is the top `length` px; horizontal tracks all
|
|
11136
|
+
// start at the left edge, so the line sits `referenceAt` of `length` from it.
|
|
11137
|
+
/* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
|
|
11072
11138
|
"div",
|
|
11073
11139
|
{
|
|
11074
|
-
|
|
11075
|
-
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
const extent = `${bar.value / max * 100}%`;
|
|
11097
|
-
return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
|
|
11098
|
-
"div",
|
|
11099
|
-
{
|
|
11100
|
-
title: `${category} \xB7 ${bar.key}: ${bar.value}`,
|
|
11101
|
-
className: "transition-all motion-reduce:transition-none",
|
|
11102
|
-
style: {
|
|
11103
|
-
backgroundColor: bar.color,
|
|
11104
|
-
borderRadius: radius,
|
|
11105
|
-
...horizontal ? { width: extent, height: stacked ? band : band } : { height: extent, width: stacked ? perCategory : band }
|
|
11106
|
-
}
|
|
11107
|
-
},
|
|
11108
|
-
bar.key
|
|
11109
|
-
);
|
|
11110
|
-
})
|
|
11111
|
-
}
|
|
11112
|
-
),
|
|
11113
|
-
showValues && horizontal && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: (0, import_clsx74.default)("shrink-0 tabular-nums text-default-secondary", labelClass2), children: categoryTotals[ci] })
|
|
11114
|
-
]
|
|
11115
|
-
}
|
|
11116
|
-
),
|
|
11117
|
-
showLabels && !horizontal && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("span", { className: (0, import_clsx74.default)("truncate text-center text-default-secondary", labelClass2), children: category })
|
|
11118
|
-
]
|
|
11119
|
-
},
|
|
11120
|
-
category
|
|
11121
|
-
);
|
|
11122
|
-
})
|
|
11140
|
+
"data-chart-reference": "",
|
|
11141
|
+
"aria-hidden": true,
|
|
11142
|
+
className: "pointer-events-none absolute",
|
|
11143
|
+
style: horizontal ? { top: 0, bottom: 0, left: 0, width: length } : { top: 0, left: 0, right: 0, height: length },
|
|
11144
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
|
|
11145
|
+
"div",
|
|
11146
|
+
{
|
|
11147
|
+
className: "absolute",
|
|
11148
|
+
style: horizontal ? { top: 0, bottom: 0, left: referenceAt, borderLeft: `2px dashed ${referenceColor}` } : { left: 0, right: 0, bottom: referenceAt, borderTop: `2px dashed ${referenceColor}` },
|
|
11149
|
+
children: reference.label && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
|
|
11150
|
+
"span",
|
|
11151
|
+
{
|
|
11152
|
+
className: (0, import_clsx74.default)("absolute whitespace-nowrap", labelClass2),
|
|
11153
|
+
style: horizontal ? { top: 0, left: 4, color: referenceColor } : { right: 0, bottom: 2, color: referenceColor },
|
|
11154
|
+
children: reference.label
|
|
11155
|
+
}
|
|
11156
|
+
)
|
|
11157
|
+
}
|
|
11158
|
+
)
|
|
11159
|
+
}
|
|
11160
|
+
)
|
|
11161
|
+
]
|
|
11123
11162
|
}
|
|
11124
11163
|
);
|
|
11125
11164
|
}
|