@mbao01/common 0.0.44 → 0.0.46
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/types/components/Chart/Chart.d.ts +2 -0
- package/dist/types/components/Chart/ChartContext.d.ts +2 -0
- package/dist/types/components/Chart/components/ChartLegend.d.ts +4 -0
- package/dist/types/components/Chart/components/ChartStyle.d.ts +2 -0
- package/dist/types/components/Chart/components/ChartTooltip.d.ts +4 -0
- package/dist/types/components/Chart/components/index.d.ts +3 -0
- package/dist/types/components/Chart/constants.d.ts +22 -0
- package/dist/types/components/Chart/helpers.d.ts +11 -0
- package/dist/types/components/Chart/hooks/index.d.ts +1 -0
- package/dist/types/components/Chart/hooks/useChart/index.d.ts +1 -0
- package/dist/types/components/Chart/hooks/useChart/useChart.d.ts +1 -0
- package/dist/types/components/Chart/index.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/activeShapeArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/animationArgs.d.ts +12 -0
- package/dist/types/components/Chart/stories/args/areaArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/areaChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/barArgs.d.ts +5 -0
- package/dist/types/components/Chart/stories/args/barChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/cartesianChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/cartesianSharedArgs.d.ts +11 -0
- package/dist/types/components/Chart/stories/args/chartArgs.d.ts +6 -0
- package/dist/types/components/Chart/stories/args/dotArgs.d.ts +10 -0
- package/dist/types/components/Chart/stories/args/events.d.ts +804 -0
- package/dist/types/components/Chart/stories/args/labelListArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/legendArgs.d.ts +3 -0
- package/dist/types/components/Chart/stories/args/lineArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/lineChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/pieArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/pieChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/polarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/polarSharedArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radarArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radialBarArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radialBarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/rectangleArgs.d.ts +9 -0
- package/dist/types/components/Chart/stories/args/referenceSharedArgs.d.ts +4 -0
- package/dist/types/components/Chart/stories/args/sectorArgs.d.ts +7 -0
- package/dist/types/components/Chart/stories/args/sharedAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/stylesArgs.d.ts +6 -0
- package/dist/types/components/Chart/stories/args/textArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/tooltipArgs.d.ts +4 -0
- package/dist/types/components/Chart/stories/args/types.d.ts +13 -0
- package/dist/types/components/Chart/stories/args/xAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/yAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/examples/AreaChart.d.ts +16 -0
- package/dist/types/components/Chart/stories/examples/BarChart.d.ts +20 -0
- package/dist/types/components/Chart/stories/examples/LineChart.d.ts +16 -0
- package/dist/types/components/Chart/stories/examples/PieChart.d.ts +19 -0
- package/dist/types/components/Chart/stories/examples/RadarChart.d.ts +24 -0
- package/dist/types/components/Chart/stories/examples/RadialChart.d.ts +17 -0
- package/dist/types/components/Chart/stories/examples/Tooltip.d.ts +15 -0
- package/dist/types/components/Chart/stories/helpers/index.d.ts +9 -0
- package/dist/types/components/Chart/types.d.ts +37 -0
- package/dist/types/components/DragAndDrop/Draggable/Draggable.d.ts +29 -0
- package/dist/types/components/DragAndDrop/Draggable/Draggable.example.d.ts +24 -0
- package/dist/types/components/DragAndDrop/Draggable/constants.d.ts +9 -0
- package/dist/types/components/DragAndDrop/Draggable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Draggable/types.d.ts +41 -0
- package/dist/types/components/DragAndDrop/Droppable/Droppable.d.ts +2 -0
- package/dist/types/components/DragAndDrop/Droppable/Droppable.example.d.ts +10 -0
- package/dist/types/components/DragAndDrop/Droppable/constants.d.ts +5 -0
- package/dist/types/components/DragAndDrop/Droppable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Droppable/types.d.ts +4 -0
- package/dist/types/components/DragAndDrop/Sortable/Sortable.d.ts +2 -0
- package/dist/types/components/DragAndDrop/Sortable/Sortable.example.d.ts +6 -0
- package/dist/types/components/DragAndDrop/Sortable/constants.d.ts +4 -0
- package/dist/types/components/DragAndDrop/Sortable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Sortable/types.d.ts +7 -0
- package/dist/types/components/DragAndDrop/index.d.ts +3 -0
- package/dist/types/components/Widget/InternalWidgetsContext.d.ts +2 -0
- package/dist/types/components/Widget/Widget.d.ts +2 -0
- package/dist/types/components/Widget/Widgets.example.d.ts +1 -0
- package/dist/types/components/Widget/WidgetsContext.d.ts +2 -0
- package/dist/types/components/Widget/hooks/index.d.ts +2 -0
- package/dist/types/components/Widget/hooks/useWidget/index.d.ts +1 -0
- package/dist/types/components/Widget/hooks/useWidget/useWidget.d.ts +7 -0
- package/dist/types/components/Widget/hooks/useWidgets/index.d.ts +1 -0
- package/dist/types/components/Widget/hooks/useWidgets/useWidgets.d.ts +1 -0
- package/dist/types/components/Widget/index.d.ts +3 -0
- package/dist/types/components/Widget/modifiers/index.d.ts +1 -0
- package/dist/types/components/Widget/modifiers/restrictToElement.d.ts +2 -0
- package/dist/types/components/Widget/types.d.ts +28 -0
- package/package.json +9 -3
- package/src/components/Chart/Chart.tsx +26 -0
- package/src/components/Chart/ChartContext.tsx +4 -0
- package/src/components/Chart/components/ChartLegend.tsx +52 -0
- package/src/components/Chart/components/ChartStyle.tsx +32 -0
- package/src/components/Chart/components/ChartTooltip.tsx +126 -0
- package/src/components/Chart/components/index.ts +3 -0
- package/src/components/Chart/constants.ts +78 -0
- package/src/components/Chart/helpers.ts +27 -0
- package/src/components/Chart/hooks/index.ts +1 -0
- package/src/components/Chart/hooks/useChart/index.ts +1 -0
- package/src/components/Chart/hooks/useChart/useChart.ts +12 -0
- package/src/components/Chart/index.ts +2 -0
- package/src/components/Chart/stories/args/activeShapeArgs.ts +34 -0
- package/src/components/Chart/stories/args/animationArgs.ts +67 -0
- package/src/components/Chart/stories/args/areaArgs.ts +16 -0
- package/src/components/Chart/stories/args/areaChartArgs.ts +19 -0
- package/src/components/Chart/stories/args/barArgs.ts +123 -0
- package/src/components/Chart/stories/args/barChartArgs.ts +65 -0
- package/src/components/Chart/stories/args/cartesianChartArgs.ts +42 -0
- package/src/components/Chart/stories/args/cartesianSharedArgs.ts +136 -0
- package/src/components/Chart/stories/args/chartArgs.ts +244 -0
- package/src/components/Chart/stories/args/dotArgs.ts +46 -0
- package/src/components/Chart/stories/args/events.ts +343 -0
- package/src/components/Chart/stories/args/index.ts +178 -0
- package/src/components/Chart/stories/args/labelListArgs.ts +124 -0
- package/src/components/Chart/stories/args/legendArgs.ts +205 -0
- package/src/components/Chart/stories/args/lineArgs.ts +87 -0
- package/src/components/Chart/stories/args/lineChartArgs.ts +17 -0
- package/src/components/Chart/stories/args/pieArgs.ts +18 -0
- package/src/components/Chart/stories/args/pieChartArgs.ts +7 -0
- package/src/components/Chart/stories/args/polarChartArgs.ts +86 -0
- package/src/components/Chart/stories/args/polarSharedArgs.ts +42 -0
- package/src/components/Chart/stories/args/radarArgs.ts +26 -0
- package/src/components/Chart/stories/args/radarChartArgs.ts +26 -0
- package/src/components/Chart/stories/args/radialBarArgs.ts +36 -0
- package/src/components/Chart/stories/args/radialBarChartArgs.ts +16 -0
- package/src/components/Chart/stories/args/rectangleArgs.ts +35 -0
- package/src/components/Chart/stories/args/referenceSharedArgs.ts +75 -0
- package/src/components/Chart/stories/args/sectorArgs.ts +106 -0
- package/src/components/Chart/stories/args/sharedAxisArgs.ts +332 -0
- package/src/components/Chart/stories/args/stylesArgs.ts +258 -0
- package/src/components/Chart/stories/args/textArgs.ts +97 -0
- package/src/components/Chart/stories/args/tooltipArgs.ts +41 -0
- package/src/components/Chart/stories/args/types.ts +23 -0
- package/src/components/Chart/stories/args/xAxisArgs.ts +109 -0
- package/src/components/Chart/stories/args/yAxisArgs.ts +73 -0
- package/src/components/Chart/stories/examples/AreaChart.tsx +156 -0
- package/src/components/Chart/stories/examples/BarChart.tsx +425 -0
- package/src/components/Chart/stories/examples/LineChart.tsx +144 -0
- package/src/components/Chart/stories/examples/PieChart.tsx +238 -0
- package/src/components/Chart/stories/examples/RadarChart.tsx +261 -0
- package/src/components/Chart/stories/examples/RadialChart.tsx +239 -0
- package/src/components/Chart/stories/examples/Tooltip.tsx +68 -0
- package/src/components/Chart/stories/helpers/index.tsx +75 -0
- package/src/components/Chart/types.ts +39 -0
- package/src/components/DragAndDrop/Draggable/Draggable.example.tsx +147 -0
- package/src/components/DragAndDrop/Draggable/Draggable.tsx +161 -0
- package/src/components/DragAndDrop/Draggable/constants.ts +47 -0
- package/src/components/DragAndDrop/Draggable/index.ts +1 -0
- package/src/components/DragAndDrop/Draggable/types.ts +56 -0
- package/src/components/DragAndDrop/Droppable/Droppable.example.tsx +86 -0
- package/src/components/DragAndDrop/Droppable/Droppable.tsx +38 -0
- package/src/components/DragAndDrop/Droppable/constants.ts +15 -0
- package/src/components/DragAndDrop/Droppable/index.ts +1 -0
- package/src/components/DragAndDrop/Droppable/types.ts +7 -0
- package/src/components/DragAndDrop/Sortable/Sortable.example.tsx +61 -0
- package/src/components/DragAndDrop/Sortable/Sortable.tsx +65 -0
- package/src/components/DragAndDrop/Sortable/constants.ts +12 -0
- package/src/components/DragAndDrop/Sortable/index.ts +1 -0
- package/src/components/DragAndDrop/Sortable/types.ts +11 -0
- package/src/components/DragAndDrop/index.ts +3 -0
- package/src/components/Widget/InternalWidgetsContext.tsx +4 -0
- package/src/components/Widget/Widget.tsx +17 -0
- package/src/components/Widget/Widgets.example.tsx +118 -0
- package/src/components/Widget/WidgetsContext.tsx +97 -0
- package/src/components/Widget/hooks/index.ts +2 -0
- package/src/components/Widget/hooks/useWidget/index.ts +1 -0
- package/src/components/Widget/hooks/useWidget/useWidget.ts +21 -0
- package/src/components/Widget/hooks/useWidgets/index.ts +1 -0
- package/src/components/Widget/hooks/useWidgets/useWidgets.ts +12 -0
- package/src/components/Widget/index.ts +3 -0
- package/src/components/Widget/modifiers/index.ts +1 -0
- package/src/components/Widget/modifiers/restrictToElement.ts +8 -0
- package/src/components/Widget/types.ts +30 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Bar,
|
|
3
|
+
BarChart,
|
|
4
|
+
CartesianGrid,
|
|
5
|
+
Cell,
|
|
6
|
+
LabelList,
|
|
7
|
+
Rectangle,
|
|
8
|
+
RectangleProps,
|
|
9
|
+
XAxis,
|
|
10
|
+
YAxis,
|
|
11
|
+
} from "recharts";
|
|
12
|
+
import { Chart } from "../../Chart";
|
|
13
|
+
import {
|
|
14
|
+
ChartLegend,
|
|
15
|
+
ChartLegendContent,
|
|
16
|
+
ChartTooltip,
|
|
17
|
+
ChartTooltipContent,
|
|
18
|
+
} from "../../components";
|
|
19
|
+
import { type ChartConfig } from "../../types";
|
|
20
|
+
import { type BarChartProps } from "../args";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* ## Parent
|
|
24
|
+
*
|
|
25
|
+
* The BarChart can be used within: `<Chart />`
|
|
26
|
+
*
|
|
27
|
+
* ## Children
|
|
28
|
+
*
|
|
29
|
+
* The BarChart can be used with the following child components: `<XAxis />`, `<YAxis />`, `<ReferenceArea />`, `<ReferenceDot />`, `<ReferenceLine />`,
|
|
30
|
+
* `<Brush />`, `<CartesianGrid />`, `<ChartLegend />`, `<ChartTooltip />`, `<Bar />`, `<Customized />` or valid svg elements.
|
|
31
|
+
*/
|
|
32
|
+
export const BarChartExample = (props: Partial<BarChartProps>) => {
|
|
33
|
+
const chartData = [
|
|
34
|
+
{ date: "2024-04-01", desktop: 222 },
|
|
35
|
+
{ date: "2024-04-02", desktop: 97 },
|
|
36
|
+
{ date: "2024-04-03", desktop: 167 },
|
|
37
|
+
{ date: "2024-04-04", desktop: 242 },
|
|
38
|
+
{ date: "2024-04-05", desktop: 373 },
|
|
39
|
+
{ date: "2024-04-06", desktop: 301 },
|
|
40
|
+
{ date: "2024-04-07", desktop: 245 },
|
|
41
|
+
{ date: "2024-04-08", desktop: 409 },
|
|
42
|
+
{ date: "2024-04-09", desktop: 59 },
|
|
43
|
+
{ date: "2024-04-10", desktop: 261 },
|
|
44
|
+
{ date: "2024-04-11", desktop: 327 },
|
|
45
|
+
{ date: "2024-04-12", desktop: 292 },
|
|
46
|
+
{ date: "2024-04-13", desktop: 342 },
|
|
47
|
+
{ date: "2024-04-14", desktop: 137 },
|
|
48
|
+
{ date: "2024-04-15", desktop: 120 },
|
|
49
|
+
{ date: "2024-04-16", desktop: 138 },
|
|
50
|
+
{ date: "2024-04-17", desktop: 446 },
|
|
51
|
+
{ date: "2024-04-18", desktop: 364 },
|
|
52
|
+
{ date: "2024-04-19", desktop: 243 },
|
|
53
|
+
{ date: "2024-04-20", desktop: 89 },
|
|
54
|
+
{ date: "2024-04-21", desktop: 137 },
|
|
55
|
+
{ date: "2024-04-22", desktop: 224 },
|
|
56
|
+
{ date: "2024-04-23", desktop: 138 },
|
|
57
|
+
{ date: "2024-04-24", desktop: 387 },
|
|
58
|
+
{ date: "2024-04-25", desktop: 215 },
|
|
59
|
+
{ date: "2024-04-26", desktop: 75 },
|
|
60
|
+
{ date: "2024-04-27", desktop: 383 },
|
|
61
|
+
{ date: "2024-04-28", desktop: 122 },
|
|
62
|
+
{ date: "2024-04-29", desktop: 315 },
|
|
63
|
+
{ date: "2024-04-30", desktop: 454 },
|
|
64
|
+
{ date: "2024-05-01", desktop: 165 },
|
|
65
|
+
{ date: "2024-05-02", desktop: 293 },
|
|
66
|
+
{ date: "2024-05-03", desktop: 247 },
|
|
67
|
+
{ date: "2024-05-04", desktop: 385 },
|
|
68
|
+
{ date: "2024-05-05", desktop: 481 },
|
|
69
|
+
{ date: "2024-05-06", desktop: 498 },
|
|
70
|
+
{ date: "2024-05-07", desktop: 388 },
|
|
71
|
+
{ date: "2024-05-08", desktop: 149 },
|
|
72
|
+
{ date: "2024-05-09", desktop: 227 },
|
|
73
|
+
{ date: "2024-05-10", desktop: 293 },
|
|
74
|
+
{ date: "2024-05-11", desktop: 335 },
|
|
75
|
+
{ date: "2024-05-12", desktop: 197 },
|
|
76
|
+
{ date: "2024-05-13", desktop: 197 },
|
|
77
|
+
{ date: "2024-05-14", desktop: 448 },
|
|
78
|
+
{ date: "2024-05-15", desktop: 473 },
|
|
79
|
+
{ date: "2024-05-16", desktop: 338 },
|
|
80
|
+
{ date: "2024-05-17", desktop: 499 },
|
|
81
|
+
{ date: "2024-05-18", desktop: 315 },
|
|
82
|
+
{ date: "2024-05-19", desktop: 235 },
|
|
83
|
+
{ date: "2024-05-20", desktop: 177 },
|
|
84
|
+
{ date: "2024-05-21", desktop: 82 },
|
|
85
|
+
{ date: "2024-05-22", desktop: 81 },
|
|
86
|
+
{ date: "2024-05-23", desktop: 252 },
|
|
87
|
+
{ date: "2024-05-24", desktop: 294 },
|
|
88
|
+
{ date: "2024-05-25", desktop: 201 },
|
|
89
|
+
{ date: "2024-05-26", desktop: 213 },
|
|
90
|
+
{ date: "2024-05-27", desktop: 420 },
|
|
91
|
+
{ date: "2024-05-28", desktop: 233 },
|
|
92
|
+
{ date: "2024-05-29", desktop: 78 },
|
|
93
|
+
{ date: "2024-05-30", desktop: 340 },
|
|
94
|
+
{ date: "2024-05-31", desktop: 178 },
|
|
95
|
+
{ date: "2024-06-01", desktop: 178 },
|
|
96
|
+
{ date: "2024-06-02", desktop: 470 },
|
|
97
|
+
{ date: "2024-06-03", desktop: 103 },
|
|
98
|
+
{ date: "2024-06-04", desktop: 439 },
|
|
99
|
+
{ date: "2024-06-05", desktop: 88 },
|
|
100
|
+
{ date: "2024-06-06", desktop: 294 },
|
|
101
|
+
{ date: "2024-06-07", desktop: 323 },
|
|
102
|
+
{ date: "2024-06-08", desktop: 385 },
|
|
103
|
+
{ date: "2024-06-09", desktop: 438 },
|
|
104
|
+
{ date: "2024-06-10", desktop: 155 },
|
|
105
|
+
{ date: "2024-06-11", desktop: 92 },
|
|
106
|
+
{ date: "2024-06-12", desktop: 492 },
|
|
107
|
+
{ date: "2024-06-13", desktop: 81 },
|
|
108
|
+
{ date: "2024-06-14", desktop: 426 },
|
|
109
|
+
{ date: "2024-06-15", desktop: 307 },
|
|
110
|
+
{ date: "2024-06-16", desktop: 371 },
|
|
111
|
+
{ date: "2024-06-17", desktop: 475 },
|
|
112
|
+
{ date: "2024-06-18", desktop: 107 },
|
|
113
|
+
{ date: "2024-06-19", desktop: 341 },
|
|
114
|
+
{ date: "2024-06-20", desktop: 408 },
|
|
115
|
+
{ date: "2024-06-21", desktop: 169 },
|
|
116
|
+
{ date: "2024-06-22", desktop: 317 },
|
|
117
|
+
{ date: "2024-06-23", desktop: 480 },
|
|
118
|
+
{ date: "2024-06-24", desktop: 132 },
|
|
119
|
+
{ date: "2024-06-25", desktop: 141 },
|
|
120
|
+
{ date: "2024-06-26", desktop: 434 },
|
|
121
|
+
{ date: "2024-06-27", desktop: 448 },
|
|
122
|
+
{ date: "2024-06-28", desktop: 149 },
|
|
123
|
+
{ date: "2024-06-29", desktop: 103 },
|
|
124
|
+
{ date: "2024-06-30", desktop: 446 },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const chartConfig = {
|
|
128
|
+
views: {
|
|
129
|
+
label: "Page Views",
|
|
130
|
+
},
|
|
131
|
+
desktop: {
|
|
132
|
+
label: "Desktop",
|
|
133
|
+
color: "#2563eb",
|
|
134
|
+
},
|
|
135
|
+
} satisfies ChartConfig;
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Chart config={chartConfig} className="h-[250px] w-full">
|
|
139
|
+
<BarChart
|
|
140
|
+
accessibilityLayer
|
|
141
|
+
data={chartData}
|
|
142
|
+
margin={{
|
|
143
|
+
left: 12,
|
|
144
|
+
right: 12,
|
|
145
|
+
}}
|
|
146
|
+
{...props.barChart}
|
|
147
|
+
>
|
|
148
|
+
<CartesianGrid vertical={false} />
|
|
149
|
+
<XAxis
|
|
150
|
+
{...props.xAxis}
|
|
151
|
+
dataKey="date"
|
|
152
|
+
tickLine={false}
|
|
153
|
+
axisLine={false}
|
|
154
|
+
tickMargin={8}
|
|
155
|
+
minTickGap={32}
|
|
156
|
+
tickFormatter={(value: string) => {
|
|
157
|
+
const date = new Date(value);
|
|
158
|
+
return date.toLocaleDateString("en-US", {
|
|
159
|
+
month: "short",
|
|
160
|
+
day: "numeric",
|
|
161
|
+
});
|
|
162
|
+
}}
|
|
163
|
+
/>
|
|
164
|
+
<ChartTooltip
|
|
165
|
+
content={
|
|
166
|
+
<ChartTooltipContent
|
|
167
|
+
className="w-[150px]"
|
|
168
|
+
nameKey="views"
|
|
169
|
+
labelFormatter={(value: string) => {
|
|
170
|
+
return new Date(value).toLocaleDateString("en-US", {
|
|
171
|
+
month: "short",
|
|
172
|
+
day: "numeric",
|
|
173
|
+
year: "numeric",
|
|
174
|
+
});
|
|
175
|
+
}}
|
|
176
|
+
/>
|
|
177
|
+
}
|
|
178
|
+
/>
|
|
179
|
+
<Bar {...props.bar} dataKey="desktop" fill="var(--color-desktop)" />
|
|
180
|
+
</BarChart>
|
|
181
|
+
</Chart>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const chartConfig = {
|
|
186
|
+
desktop: {
|
|
187
|
+
label: "Desktop",
|
|
188
|
+
color: "hsl(var(--chart-1))",
|
|
189
|
+
},
|
|
190
|
+
mobile: {
|
|
191
|
+
label: "Mobile",
|
|
192
|
+
color: "hsl(var(--chart-2))",
|
|
193
|
+
},
|
|
194
|
+
} satisfies ChartConfig;
|
|
195
|
+
|
|
196
|
+
export const MultipleBarChartExample = (props: Partial<BarChartProps>) => {
|
|
197
|
+
return (
|
|
198
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
199
|
+
<BarChart {...props.barChart}>
|
|
200
|
+
<CartesianGrid vertical={false} />
|
|
201
|
+
<XAxis {...props.xAxis} />
|
|
202
|
+
<ChartTooltip content={<ChartTooltipContent indicator="dashed" />} />
|
|
203
|
+
<Bar {...props.bar} dataKey="desktop" fill="var(--color-desktop)" radius={4} />
|
|
204
|
+
<Bar {...props.bar} dataKey="mobile" fill="var(--color-mobile)" radius={4} />
|
|
205
|
+
</BarChart>
|
|
206
|
+
</Chart>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export const HorizontalBarChartExample = (props: Partial<BarChartProps>) => {
|
|
211
|
+
return (
|
|
212
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
213
|
+
<BarChart {...props.barChart}>
|
|
214
|
+
<XAxis type="number" dataKey="desktop" hide {...props.xAxis} />
|
|
215
|
+
<YAxis {...props.yAxis} />
|
|
216
|
+
<ChartTooltip content={<ChartTooltipContent hideLabel />} />
|
|
217
|
+
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={5} {...props.bar} />
|
|
218
|
+
</BarChart>
|
|
219
|
+
</Chart>
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const LabelBarChartExample = (props: Partial<BarChartProps>) => {
|
|
224
|
+
return (
|
|
225
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
226
|
+
<BarChart {...props.barChart}>
|
|
227
|
+
<CartesianGrid vertical={false} />
|
|
228
|
+
<XAxis {...props.xAxis} />
|
|
229
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
|
|
230
|
+
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={8} {...props.bar}>
|
|
231
|
+
<LabelList position="top" offset={12} className="fill-foreground" fontSize={12} />
|
|
232
|
+
</Bar>
|
|
233
|
+
</BarChart>
|
|
234
|
+
</Chart>
|
|
235
|
+
);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export const CustomLabelBarChartExample = (props: Partial<BarChartProps>) => {
|
|
239
|
+
return (
|
|
240
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
241
|
+
<BarChart {...props.barChart}>
|
|
242
|
+
<CartesianGrid horizontal={false} />
|
|
243
|
+
<YAxis {...props.yAxis} />
|
|
244
|
+
<XAxis {...props.xAxis} />
|
|
245
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent indicator="line" />} />
|
|
246
|
+
<Bar
|
|
247
|
+
dataKey="desktop"
|
|
248
|
+
layout="vertical"
|
|
249
|
+
fill="var(--color-desktop)"
|
|
250
|
+
radius={4}
|
|
251
|
+
{...props.bar}
|
|
252
|
+
>
|
|
253
|
+
<LabelList
|
|
254
|
+
dataKey="month"
|
|
255
|
+
position="insideLeft"
|
|
256
|
+
offset={8}
|
|
257
|
+
className="fill-black"
|
|
258
|
+
fontSize={12}
|
|
259
|
+
/>
|
|
260
|
+
<LabelList
|
|
261
|
+
dataKey="desktop"
|
|
262
|
+
position="right"
|
|
263
|
+
offset={8}
|
|
264
|
+
className="fill-base-content"
|
|
265
|
+
fontSize={12}
|
|
266
|
+
/>
|
|
267
|
+
</Bar>
|
|
268
|
+
</BarChart>
|
|
269
|
+
</Chart>
|
|
270
|
+
);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export const MixedBarChartExample = (props: Partial<BarChartProps>) => {
|
|
274
|
+
const chartConfig = {
|
|
275
|
+
visitors: {
|
|
276
|
+
label: "Visitors",
|
|
277
|
+
},
|
|
278
|
+
chrome: {
|
|
279
|
+
label: "Chrome",
|
|
280
|
+
color: "hsl(var(--chart-1))",
|
|
281
|
+
},
|
|
282
|
+
safari: {
|
|
283
|
+
label: "Safari",
|
|
284
|
+
color: "hsl(var(--chart-2))",
|
|
285
|
+
},
|
|
286
|
+
firefox: {
|
|
287
|
+
label: "Firefox",
|
|
288
|
+
color: "hsl(var(--chart-3))",
|
|
289
|
+
},
|
|
290
|
+
edge: {
|
|
291
|
+
label: "Edge",
|
|
292
|
+
color: "hsl(var(--chart-4))",
|
|
293
|
+
},
|
|
294
|
+
other: {
|
|
295
|
+
label: "Other",
|
|
296
|
+
color: "hsl(var(--chart-5))",
|
|
297
|
+
},
|
|
298
|
+
} satisfies ChartConfig;
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
302
|
+
<BarChart {...props.barChart}>
|
|
303
|
+
<YAxis
|
|
304
|
+
tickFormatter={(value) => chartConfig[value as keyof typeof chartConfig]?.label}
|
|
305
|
+
{...props.yAxis}
|
|
306
|
+
/>
|
|
307
|
+
<XAxis {...props.xAxis} />
|
|
308
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
|
|
309
|
+
<Bar dataKey="visitors" layout="vertical" radius={5} {...props.bar} />
|
|
310
|
+
</BarChart>
|
|
311
|
+
</Chart>
|
|
312
|
+
);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export const StackedBarChartExample = (props: Partial<BarChartProps>) => {
|
|
316
|
+
return (
|
|
317
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
318
|
+
<BarChart {...props.barChart}>
|
|
319
|
+
<CartesianGrid vertical={false} />
|
|
320
|
+
<XAxis {...props.xAxis} />
|
|
321
|
+
<ChartTooltip content={<ChartTooltipContent hideLabel />} />
|
|
322
|
+
<ChartLegend content={<ChartLegendContent />} />
|
|
323
|
+
<Bar
|
|
324
|
+
{...props.bar}
|
|
325
|
+
dataKey="desktop"
|
|
326
|
+
stackId="a"
|
|
327
|
+
fill="var(--color-desktop)"
|
|
328
|
+
radius={[0, 0, 4, 4]}
|
|
329
|
+
/>
|
|
330
|
+
<Bar
|
|
331
|
+
{...props.bar}
|
|
332
|
+
dataKey="mobile"
|
|
333
|
+
stackId="a"
|
|
334
|
+
fill="var(--color-mobile)"
|
|
335
|
+
radius={[4, 4, 0, 0]}
|
|
336
|
+
/>
|
|
337
|
+
</BarChart>
|
|
338
|
+
</Chart>
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export const ActiveBarChartExample = (props: Partial<BarChartProps>) => {
|
|
343
|
+
const chartConfig = {
|
|
344
|
+
visitors: {
|
|
345
|
+
label: "Visitors",
|
|
346
|
+
},
|
|
347
|
+
chrome: {
|
|
348
|
+
label: "Chrome",
|
|
349
|
+
color: "hsl(var(--chart-1))",
|
|
350
|
+
},
|
|
351
|
+
safari: {
|
|
352
|
+
label: "Safari",
|
|
353
|
+
color: "hsl(var(--chart-2))",
|
|
354
|
+
},
|
|
355
|
+
firefox: {
|
|
356
|
+
label: "Firefox",
|
|
357
|
+
color: "hsl(var(--chart-3))",
|
|
358
|
+
},
|
|
359
|
+
edge: {
|
|
360
|
+
label: "Edge",
|
|
361
|
+
color: "hsl(var(--chart-4))",
|
|
362
|
+
},
|
|
363
|
+
other: {
|
|
364
|
+
label: "Other",
|
|
365
|
+
color: "hsl(var(--chart-5))",
|
|
366
|
+
},
|
|
367
|
+
} satisfies ChartConfig;
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
371
|
+
<BarChart {...props.barChart}>
|
|
372
|
+
<CartesianGrid vertical={false} />
|
|
373
|
+
<XAxis
|
|
374
|
+
tickFormatter={(value) => chartConfig[value as keyof typeof chartConfig]?.label}
|
|
375
|
+
{...props.xAxis}
|
|
376
|
+
/>
|
|
377
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
|
|
378
|
+
<Bar
|
|
379
|
+
dataKey="visitors"
|
|
380
|
+
strokeWidth={2}
|
|
381
|
+
radius={8}
|
|
382
|
+
activeIndex={2}
|
|
383
|
+
activeBar={(p: unknown) => {
|
|
384
|
+
return (
|
|
385
|
+
<Rectangle
|
|
386
|
+
{...(p as RectangleProps)}
|
|
387
|
+
fillOpacity={0.8}
|
|
388
|
+
stroke={(p as RectangleProps).fill}
|
|
389
|
+
strokeDasharray={4}
|
|
390
|
+
strokeDashoffset={4}
|
|
391
|
+
/>
|
|
392
|
+
);
|
|
393
|
+
}}
|
|
394
|
+
{...props.bar}
|
|
395
|
+
/>
|
|
396
|
+
</BarChart>
|
|
397
|
+
</Chart>
|
|
398
|
+
);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
export const NegativeBarChartExample = (props: Partial<BarChartProps>) => {
|
|
402
|
+
const chartConfig = {
|
|
403
|
+
visitors: {
|
|
404
|
+
label: "Visitors",
|
|
405
|
+
},
|
|
406
|
+
} satisfies ChartConfig;
|
|
407
|
+
|
|
408
|
+
return (
|
|
409
|
+
<Chart config={chartConfig} className="h-[200px] w-full">
|
|
410
|
+
<BarChart {...props.barChart}>
|
|
411
|
+
<CartesianGrid vertical={false} />
|
|
412
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel hideIndicator />} />
|
|
413
|
+
<Bar dataKey="visitors" {...props.bar}>
|
|
414
|
+
<LabelList position="top" dataKey="month" fillOpacity={1} />
|
|
415
|
+
{(props.barChart as { data: { month: string; visitors: number }[] }).data?.map((item) => (
|
|
416
|
+
<Cell
|
|
417
|
+
key={item.month}
|
|
418
|
+
fill={item.visitors > 0 ? "hsl(var(--chart-1))" : "hsl(var(--chart-2))"}
|
|
419
|
+
/>
|
|
420
|
+
))}
|
|
421
|
+
</Bar>
|
|
422
|
+
</BarChart>
|
|
423
|
+
</Chart>
|
|
424
|
+
);
|
|
425
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { type SVGProps } from "react";
|
|
2
|
+
import { DrawingPinIcon } from "@radix-ui/react-icons";
|
|
3
|
+
import { CartesianGrid, LabelList, Line, LineChart, XAxis, YAxis } from "recharts";
|
|
4
|
+
import { Chart } from "../../Chart";
|
|
5
|
+
import {
|
|
6
|
+
ChartLegend,
|
|
7
|
+
ChartLegendContent,
|
|
8
|
+
ChartTooltip,
|
|
9
|
+
ChartTooltipContent,
|
|
10
|
+
} from "../../components";
|
|
11
|
+
import { type ChartConfig } from "../../types";
|
|
12
|
+
import { LineChartProps } from "../args";
|
|
13
|
+
|
|
14
|
+
const chartConfig = {
|
|
15
|
+
desktop: {
|
|
16
|
+
label: "Desktop",
|
|
17
|
+
color: "hsl(var(--chart-1))",
|
|
18
|
+
},
|
|
19
|
+
mobile: {
|
|
20
|
+
label: "Mobile",
|
|
21
|
+
color: "hsl(var(--chart-2))",
|
|
22
|
+
},
|
|
23
|
+
} satisfies ChartConfig;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ## Parent
|
|
27
|
+
*
|
|
28
|
+
* The LineChart can be used within: `<Chart />`
|
|
29
|
+
*
|
|
30
|
+
* ## Children
|
|
31
|
+
*
|
|
32
|
+
* The LineChart can be used with the following child components: `<XAxis />`, `<YAxis />`, `<ReferenceArea />`, `<ReferenceDot />`, `<ReferenceLine />`,
|
|
33
|
+
* `<Brush />`, `<CartesianGrid />`, `<ChartLegend />`, `<ChartTooltip />`, `<Line />`, `<Customized />` or valid svg elements.
|
|
34
|
+
*/
|
|
35
|
+
export const LineChartExample = (props: LineChartProps) => {
|
|
36
|
+
return (
|
|
37
|
+
<Chart config={chartConfig} className="h-[250px] w-full">
|
|
38
|
+
<LineChart {...props.lineChart}>
|
|
39
|
+
<CartesianGrid vertical={false} />
|
|
40
|
+
<XAxis {...props.xAxis} />
|
|
41
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
|
|
42
|
+
<Line {...props.line} />
|
|
43
|
+
</LineChart>
|
|
44
|
+
</Chart>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const StackedLineChartExample = (props: LineChartProps) => {
|
|
49
|
+
return (
|
|
50
|
+
<Chart config={chartConfig} className="h-[250px] w-full">
|
|
51
|
+
<LineChart {...props.lineChart}>
|
|
52
|
+
<CartesianGrid vertical={false} />
|
|
53
|
+
<XAxis {...props.xAxis} />
|
|
54
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent indicator="dot" />} />
|
|
55
|
+
<Line
|
|
56
|
+
{...props.line}
|
|
57
|
+
dataKey="mobile"
|
|
58
|
+
fill="var(--color-mobile)"
|
|
59
|
+
stroke="var(--color-mobile)"
|
|
60
|
+
/>
|
|
61
|
+
<Line
|
|
62
|
+
{...props.line}
|
|
63
|
+
dataKey="desktop"
|
|
64
|
+
fill="var(--color-desktop)"
|
|
65
|
+
stroke="var(--color-desktop)"
|
|
66
|
+
/>
|
|
67
|
+
</LineChart>
|
|
68
|
+
</Chart>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const CustomDotLineChartExample = (props: LineChartProps) => {
|
|
73
|
+
return (
|
|
74
|
+
<Chart config={chartConfig} className="h-[250px] w-full">
|
|
75
|
+
<LineChart {...props.lineChart}>
|
|
76
|
+
<CartesianGrid vertical={false} />
|
|
77
|
+
<XAxis {...props.xAxis} />
|
|
78
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
|
|
79
|
+
<Line
|
|
80
|
+
{...props.line}
|
|
81
|
+
dot={({
|
|
82
|
+
cx,
|
|
83
|
+
cy,
|
|
84
|
+
payload,
|
|
85
|
+
}: SVGProps<SVGSVGElement> & { payload: Record<string, string> }) => {
|
|
86
|
+
const r = 24;
|
|
87
|
+
return (
|
|
88
|
+
<DrawingPinIcon
|
|
89
|
+
key={payload.month}
|
|
90
|
+
x={Number(cx) - r / 4}
|
|
91
|
+
y={Number(cy) - r / 4}
|
|
92
|
+
width={r / 2}
|
|
93
|
+
height={r / 2}
|
|
94
|
+
fill="hsl(var(--background))"
|
|
95
|
+
stroke="var(--color-desktop)"
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
</LineChart>
|
|
101
|
+
</Chart>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const LabeledLineChartExample = (props: LineChartProps) => {
|
|
106
|
+
return (
|
|
107
|
+
<Chart config={chartConfig} className="h-[250px] w-full">
|
|
108
|
+
<LineChart {...props.lineChart}>
|
|
109
|
+
<CartesianGrid vertical={false} />
|
|
110
|
+
<XAxis {...props.xAxis} />
|
|
111
|
+
<YAxis {...props.yAxis} />
|
|
112
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent indicator="line" />} />
|
|
113
|
+
<Line {...props.line}>
|
|
114
|
+
<LabelList position="top" offset={12} className="fill-foreground" fontSize={12} />
|
|
115
|
+
</Line>
|
|
116
|
+
</LineChart>
|
|
117
|
+
</Chart>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const WithLegendLineChartExample = (props: LineChartProps) => {
|
|
122
|
+
return (
|
|
123
|
+
<Chart config={chartConfig} className="h-[250px] w-full">
|
|
124
|
+
<LineChart {...props.lineChart}>
|
|
125
|
+
<CartesianGrid vertical={false} />
|
|
126
|
+
<XAxis {...props.xAxis} />
|
|
127
|
+
<ChartTooltip cursor={false} content={<ChartTooltipContent indicator="line" />} />
|
|
128
|
+
<Line
|
|
129
|
+
{...props.line}
|
|
130
|
+
dataKey="mobile"
|
|
131
|
+
fill="var(--color-mobile)"
|
|
132
|
+
stroke="var(--color-mobile)"
|
|
133
|
+
/>
|
|
134
|
+
<Line
|
|
135
|
+
{...props.line}
|
|
136
|
+
dataKey="desktop"
|
|
137
|
+
fill="var(--color-desktop)"
|
|
138
|
+
stroke="var(--color-desktop)"
|
|
139
|
+
/>
|
|
140
|
+
<ChartLegend content={<ChartLegendContent />} />
|
|
141
|
+
</LineChart>
|
|
142
|
+
</Chart>
|
|
143
|
+
);
|
|
144
|
+
};
|