@umituz/web-design-system 6.4.0 → 6.5.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-design-system",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Web Design System - Tailwind v4 authored, precompiled CSS shipped. Atomic Design components (Atoms, Molecules, Organisms, Templates) for React applications.",
|
|
@@ -80,6 +80,24 @@ describe("BarChart", () => {
|
|
|
80
80
|
expect(goal.textContent).toContain("Hedef");
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
it("renders a band via goalLines with each line placed independently", () => {
|
|
84
|
+
const { container } = render(
|
|
85
|
+
<BarChart
|
|
86
|
+
labels={labels}
|
|
87
|
+
goalLines={[
|
|
88
|
+
{ value: 1, label: "Alt", tone: "#65c99a" },
|
|
89
|
+
{ value: 3, label: "Üst", tone: "#65c99a" },
|
|
90
|
+
]}
|
|
91
|
+
series={[{ label: "A", values: [4, 4, 4] }]}
|
|
92
|
+
/>,
|
|
93
|
+
);
|
|
94
|
+
const goals = container.querySelectorAll(".udb-barchart__goal");
|
|
95
|
+
expect(goals).toHaveLength(2);
|
|
96
|
+
expect((goals[0] as HTMLElement).style.bottom).toBe("25%");
|
|
97
|
+
expect((goals[1] as HTMLElement).style.bottom).toBe("75%");
|
|
98
|
+
expect(goals[1]!.textContent).toContain("Üst");
|
|
99
|
+
});
|
|
100
|
+
|
|
83
101
|
it("colors series through the --udb-chart tokens by default", () => {
|
|
84
102
|
const { container } = render(
|
|
85
103
|
<BarChart labels={labels} series={[{ label: "A", values: [1, 2, 3] }]} />,
|
|
@@ -26,6 +26,7 @@ export interface BarChartProps {
|
|
|
26
26
|
formatValue?: (v: number) => string;
|
|
27
27
|
formatLabel?: (l: string) => string;
|
|
28
28
|
goalLine?: BarChartGoalLine;
|
|
29
|
+
goalLines?: readonly BarChartGoalLine[];
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export function BarChart({
|
|
@@ -37,43 +38,45 @@ export function BarChart({
|
|
|
37
38
|
formatValue = (v: number) => String(v),
|
|
38
39
|
formatLabel = (l: string) => l,
|
|
39
40
|
goalLine,
|
|
41
|
+
goalLines,
|
|
40
42
|
}: BarChartProps) {
|
|
41
43
|
const [hover, setHover] = useState<number | null>(null);
|
|
42
44
|
const vals = (s: BarSeries) => s.values ?? s.data ?? [];
|
|
45
|
+
const goals = goalLines ?? (goalLine !== undefined ? [goalLine] : []);
|
|
43
46
|
const columnTotals = labels.map((_, i) => series.reduce((sum, s) => sum + (vals(s)[i] ?? 0), 0));
|
|
44
47
|
const max =
|
|
45
48
|
stacking === 'stacked'
|
|
46
|
-
? Math.max(1, ...columnTotals,
|
|
47
|
-
: Math.max(1, ...series.flatMap((s) => vals(s)),
|
|
49
|
+
? Math.max(1, ...columnTotals, ...goals.map((g) => g.value))
|
|
50
|
+
: Math.max(1, ...series.flatMap((s) => vals(s)), ...goals.map((g) => g.value));
|
|
48
51
|
const toneOf = (s: BarSeries, i: number) => s.tone ?? s.color ?? seriesColor(i);
|
|
49
52
|
const accentOf = (s: BarSeries, si: number, i: number) => s.accents?.[i] ?? toneOf(s, si);
|
|
50
|
-
const goalPct = goalLine !== undefined ? Math.min(100, (goalLine.value / max) * 100) : null;
|
|
51
53
|
return (
|
|
52
54
|
<div className="udb-barchart" style={{ height }}>
|
|
53
|
-
{
|
|
55
|
+
{goals.map((goal) => (
|
|
54
56
|
<div
|
|
57
|
+
key={`${goal.value}-${goal.label ?? ''}`}
|
|
55
58
|
className="udb-barchart__goal"
|
|
56
59
|
style={{
|
|
57
|
-
bottom: `${
|
|
58
|
-
...(
|
|
60
|
+
bottom: `${Math.min(100, (goal.value / max) * 100)}%`,
|
|
61
|
+
...(goal.tone !== undefined ? { borderTopColor: goal.tone } : {}),
|
|
59
62
|
}}
|
|
60
|
-
title={
|
|
63
|
+
title={goal.label ?? formatValue(goal.value)}
|
|
61
64
|
aria-hidden="true"
|
|
62
65
|
>
|
|
63
|
-
{
|
|
66
|
+
{goal.label !== undefined && (
|
|
64
67
|
<span
|
|
65
68
|
className="udb-barchart__goallabel"
|
|
66
69
|
style={
|
|
67
|
-
|
|
68
|
-
? { color:
|
|
70
|
+
goal.tone !== undefined
|
|
71
|
+
? { color: goal.tone, borderColor: goal.tone }
|
|
69
72
|
: undefined
|
|
70
73
|
}
|
|
71
74
|
>
|
|
72
|
-
{
|
|
75
|
+
{goal.label}
|
|
73
76
|
</span>
|
|
74
77
|
)}
|
|
75
78
|
</div>
|
|
76
|
-
)}
|
|
79
|
+
))}
|
|
77
80
|
{labels.map((label, i) => (
|
|
78
81
|
<div
|
|
79
82
|
key={label}
|