@campxdev/react-blueprint 1.2.14 → 1.2.16
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 +1 -1
- package/src/components/Charts/BarChart/BarChart.tsx +70 -6
- package/src/components/Charts/LineChart/LineChart.tsx +30 -2
- package/src/components/Charts/PieChart/PieChart.tsx +21 -1
- package/src/components/Charts/TreeMap/TreeMap.tsx +16 -1
- package/src/components/Charts/types/types.ts +6 -0
- package/src/stories/Charts/BarChart.stories.tsx +4 -1
package/package.json
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
Stack,
|
|
4
|
+
styled,
|
|
5
|
+
SxProps,
|
|
6
|
+
useTheme,
|
|
7
|
+
Typography,
|
|
8
|
+
} from '@mui/material';
|
|
2
9
|
import {
|
|
3
10
|
Bar,
|
|
4
11
|
CartesianGrid,
|
|
@@ -15,14 +22,18 @@ import {
|
|
|
15
22
|
CartesianGridProps,
|
|
16
23
|
LegendProps,
|
|
17
24
|
MarginProps,
|
|
25
|
+
SubTitleProps,
|
|
18
26
|
TitleProps,
|
|
19
27
|
} from '../types/types';
|
|
20
28
|
import { LayoutType } from 'recharts/types/util/types';
|
|
21
|
-
import {
|
|
29
|
+
import { StyledContainer } from '../../export';
|
|
22
30
|
|
|
23
31
|
export type BarChartProps = {
|
|
24
32
|
title?: string;
|
|
33
|
+
showSubtitle?: boolean;
|
|
34
|
+
subTitle?: string;
|
|
25
35
|
titleProps?: TitleProps;
|
|
36
|
+
subTitleProps?: SubTitleProps;
|
|
26
37
|
width?: number;
|
|
27
38
|
height?: number;
|
|
28
39
|
layout?: LayoutType;
|
|
@@ -50,6 +61,9 @@ type BarItem = {
|
|
|
50
61
|
|
|
51
62
|
export const BarChart = ({
|
|
52
63
|
title = 'Bar Chart',
|
|
64
|
+
showSubtitle = false,
|
|
65
|
+
subTitle = '',
|
|
66
|
+
subTitleProps = { variant: 'caption' },
|
|
53
67
|
titleProps = { variant: 'subtitle2' },
|
|
54
68
|
width = 700,
|
|
55
69
|
height = 500,
|
|
@@ -83,6 +97,15 @@ export const BarChart = ({
|
|
|
83
97
|
>
|
|
84
98
|
{title}
|
|
85
99
|
</Typography>
|
|
100
|
+
{showSubtitle && (
|
|
101
|
+
<Typography
|
|
102
|
+
variant={subTitleProps.variant}
|
|
103
|
+
align={'center'}
|
|
104
|
+
sx={subTitleProps.sx}
|
|
105
|
+
>
|
|
106
|
+
{title}
|
|
107
|
+
</Typography>
|
|
108
|
+
)}
|
|
86
109
|
<ReBarChart
|
|
87
110
|
width={width}
|
|
88
111
|
height={height}
|
|
@@ -97,6 +120,7 @@ export const BarChart = ({
|
|
|
97
120
|
)}
|
|
98
121
|
{showToolTip && (
|
|
99
122
|
<Tooltip
|
|
123
|
+
content={CustomTooltip}
|
|
100
124
|
cursor={{ fill: theme.palette.secondary.light, fillOpacity: '50%' }}
|
|
101
125
|
itemStyle={{
|
|
102
126
|
color: theme.palette.text.secondary,
|
|
@@ -118,7 +142,10 @@ export const BarChart = ({
|
|
|
118
142
|
type="category"
|
|
119
143
|
dataKey={dataKey}
|
|
120
144
|
stroke={theme.palette.border.primary}
|
|
121
|
-
tick={{
|
|
145
|
+
tick={{
|
|
146
|
+
fill: theme.palette.text.tertiary,
|
|
147
|
+
...baseAxisProps?.xAxis?.tick,
|
|
148
|
+
}}
|
|
122
149
|
angle={baseAxisProps?.xAxis?.angle}
|
|
123
150
|
tickMargin={baseAxisProps?.xAxis?.tickMargin}
|
|
124
151
|
>
|
|
@@ -131,7 +158,10 @@ export const BarChart = ({
|
|
|
131
158
|
<YAxis
|
|
132
159
|
type="number"
|
|
133
160
|
stroke={theme.palette.border.primary}
|
|
134
|
-
tick={{
|
|
161
|
+
tick={{
|
|
162
|
+
fill: theme.palette.text.tertiary,
|
|
163
|
+
...baseAxisProps?.yAxis?.tick,
|
|
164
|
+
}}
|
|
135
165
|
tickMargin={baseAxisProps?.yAxis?.tickMargin}
|
|
136
166
|
domain={domain}
|
|
137
167
|
>
|
|
@@ -152,7 +182,10 @@ export const BarChart = ({
|
|
|
152
182
|
<XAxis
|
|
153
183
|
type="number"
|
|
154
184
|
stroke={theme.palette.border.primary}
|
|
155
|
-
tick={{
|
|
185
|
+
tick={{
|
|
186
|
+
fill: theme.palette.text.tertiary,
|
|
187
|
+
...baseAxisProps?.xAxis?.tick,
|
|
188
|
+
}}
|
|
156
189
|
angle={baseAxisProps?.xAxis?.angle}
|
|
157
190
|
tickMargin={baseAxisProps?.xAxis?.tickMargin}
|
|
158
191
|
>
|
|
@@ -166,7 +199,10 @@ export const BarChart = ({
|
|
|
166
199
|
dataKey={dataKey}
|
|
167
200
|
type="category"
|
|
168
201
|
stroke={theme.palette.border.primary}
|
|
169
|
-
tick={{
|
|
202
|
+
tick={{
|
|
203
|
+
fill: theme.palette.text.tertiary,
|
|
204
|
+
...baseAxisProps?.yAxis?.tick,
|
|
205
|
+
}}
|
|
170
206
|
tickMargin={baseAxisProps?.yAxis?.tickMargin}
|
|
171
207
|
>
|
|
172
208
|
{yLabel && (
|
|
@@ -186,3 +222,31 @@ export const BarChart = ({
|
|
|
186
222
|
</Stack>
|
|
187
223
|
);
|
|
188
224
|
};
|
|
225
|
+
|
|
226
|
+
const CustomTooltip = ({ active, payload }: any) => {
|
|
227
|
+
const theme = useTheme();
|
|
228
|
+
if (active && payload && payload.length) {
|
|
229
|
+
return (
|
|
230
|
+
<StyledContainer>
|
|
231
|
+
<Typography variant="body2">{`${payload[0].payload.name}`}</Typography>
|
|
232
|
+
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
|
|
233
|
+
{payload.map((p: any, index: number) => (
|
|
234
|
+
<Typography variant="caption" key={index}>
|
|
235
|
+
<span>{`${p.name}`}</span>
|
|
236
|
+
<span
|
|
237
|
+
style={{
|
|
238
|
+
fontWeight: 'bold',
|
|
239
|
+
color: theme.palette.text.primary,
|
|
240
|
+
}}
|
|
241
|
+
>
|
|
242
|
+
{'\xa0\xa0' + `${p.value}`}
|
|
243
|
+
</span>
|
|
244
|
+
</Typography>
|
|
245
|
+
))}
|
|
246
|
+
</Box>
|
|
247
|
+
</StyledContainer>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return null;
|
|
252
|
+
};
|
|
@@ -12,9 +12,11 @@ import {
|
|
|
12
12
|
} from 'recharts';
|
|
13
13
|
import {
|
|
14
14
|
AxisLabelProps,
|
|
15
|
+
BaseAxisProps,
|
|
15
16
|
CartesianGridProps,
|
|
16
17
|
LegendProps,
|
|
17
18
|
MarginProps,
|
|
19
|
+
SubTitleProps,
|
|
18
20
|
TitleProps,
|
|
19
21
|
} from '../types/types';
|
|
20
22
|
import { CurveType } from 'recharts/types/shape/Curve';
|
|
@@ -22,7 +24,10 @@ import { Typography } from '../../export';
|
|
|
22
24
|
|
|
23
25
|
export type LineChartProps = {
|
|
24
26
|
title?: string;
|
|
27
|
+
showSubtitle?: boolean;
|
|
28
|
+
subTitle?: string;
|
|
25
29
|
titleProps?: TitleProps;
|
|
30
|
+
subTitleProps?: SubTitleProps;
|
|
26
31
|
width?: number;
|
|
27
32
|
height?: number;
|
|
28
33
|
dataKey: string;
|
|
@@ -32,6 +37,7 @@ export type LineChartProps = {
|
|
|
32
37
|
showLegend?: boolean;
|
|
33
38
|
cartesianGrid?: CartesianGridProps;
|
|
34
39
|
axisLabelProps?: AxisLabelProps;
|
|
40
|
+
baseAxisProps?: BaseAxisProps;
|
|
35
41
|
legendSx?: LegendProps;
|
|
36
42
|
containerSx?: SxProps;
|
|
37
43
|
margin?: MarginProps;
|
|
@@ -46,6 +52,9 @@ type LineItem = {
|
|
|
46
52
|
|
|
47
53
|
export const LineChart = ({
|
|
48
54
|
title = 'Line Chart',
|
|
55
|
+
showSubtitle = false,
|
|
56
|
+
subTitle = '',
|
|
57
|
+
subTitleProps = { variant: 'caption' },
|
|
49
58
|
titleProps = { variant: 'subtitle2' },
|
|
50
59
|
width = 700,
|
|
51
60
|
height = 500,
|
|
@@ -57,6 +66,7 @@ export const LineChart = ({
|
|
|
57
66
|
showLegend = true,
|
|
58
67
|
cartesianGrid = { showCartesianGrid: false },
|
|
59
68
|
axisLabelProps,
|
|
69
|
+
baseAxisProps,
|
|
60
70
|
legendSx,
|
|
61
71
|
containerSx,
|
|
62
72
|
}: LineChartProps) => {
|
|
@@ -73,6 +83,15 @@ export const LineChart = ({
|
|
|
73
83
|
>
|
|
74
84
|
{title}
|
|
75
85
|
</Typography>
|
|
86
|
+
{showSubtitle && (
|
|
87
|
+
<Typography
|
|
88
|
+
variant={subTitleProps.variant}
|
|
89
|
+
align={'center'}
|
|
90
|
+
sx={subTitleProps.sx}
|
|
91
|
+
>
|
|
92
|
+
{title}
|
|
93
|
+
</Typography>
|
|
94
|
+
)}
|
|
76
95
|
<ReLineChart width={width} height={height} margin={margin} data={data}>
|
|
77
96
|
{showCartesianGrid && (
|
|
78
97
|
<CartesianGrid strokeDasharray={`${size} ${size}`} />
|
|
@@ -98,7 +117,12 @@ export const LineChart = ({
|
|
|
98
117
|
type="category"
|
|
99
118
|
dataKey={dataKey}
|
|
100
119
|
stroke={theme.palette.border.primary}
|
|
101
|
-
tick={{
|
|
120
|
+
tick={{
|
|
121
|
+
fill: theme.palette.text.tertiary,
|
|
122
|
+
...baseAxisProps?.xAxis?.tick,
|
|
123
|
+
}}
|
|
124
|
+
angle={baseAxisProps?.xAxis?.angle}
|
|
125
|
+
tickMargin={baseAxisProps?.xAxis?.tickMargin}
|
|
102
126
|
>
|
|
103
127
|
<Label
|
|
104
128
|
{...xLabel}
|
|
@@ -109,7 +133,11 @@ export const LineChart = ({
|
|
|
109
133
|
<YAxis
|
|
110
134
|
type="number"
|
|
111
135
|
stroke={theme.palette.border.primary}
|
|
112
|
-
tick={{
|
|
136
|
+
tick={{
|
|
137
|
+
fill: theme.palette.text.tertiary,
|
|
138
|
+
...baseAxisProps?.yAxis?.tick,
|
|
139
|
+
}}
|
|
140
|
+
tickMargin={baseAxisProps?.yAxis?.tickMargin}
|
|
113
141
|
>
|
|
114
142
|
{yLabel && (
|
|
115
143
|
<Label
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { Stack, SxProps, useTheme } from '@mui/material';
|
|
2
2
|
import { Cell, Legend, Pie, PieChart as RePieChart, Tooltip } from 'recharts';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
LegendProps,
|
|
5
|
+
MarginProps,
|
|
6
|
+
SubTitleProps,
|
|
7
|
+
TitleProps,
|
|
8
|
+
} from '../types/types';
|
|
4
9
|
import { Typography } from '../../export';
|
|
5
10
|
|
|
6
11
|
export type PieChartProps = {
|
|
7
12
|
title?: string;
|
|
13
|
+
showSubtitle?: boolean;
|
|
14
|
+
subTitle?: string;
|
|
8
15
|
titleProps?: TitleProps;
|
|
16
|
+
subTitleProps?: SubTitleProps;
|
|
9
17
|
margin?: MarginProps;
|
|
10
18
|
width?: number;
|
|
11
19
|
height?: number;
|
|
@@ -31,6 +39,9 @@ type PieProps = {
|
|
|
31
39
|
|
|
32
40
|
export const PieChart = ({
|
|
33
41
|
title = 'Pie Chart',
|
|
42
|
+
showSubtitle = false,
|
|
43
|
+
subTitle = '',
|
|
44
|
+
subTitleProps = { variant: 'caption' },
|
|
34
45
|
titleProps = { variant: 'subtitle2' },
|
|
35
46
|
margin,
|
|
36
47
|
width = 500,
|
|
@@ -53,6 +64,15 @@ export const PieChart = ({
|
|
|
53
64
|
>
|
|
54
65
|
{title}
|
|
55
66
|
</Typography>
|
|
67
|
+
{showSubtitle && (
|
|
68
|
+
<Typography
|
|
69
|
+
variant={subTitleProps.variant}
|
|
70
|
+
align={'center'}
|
|
71
|
+
sx={subTitleProps.sx}
|
|
72
|
+
>
|
|
73
|
+
{title}
|
|
74
|
+
</Typography>
|
|
75
|
+
)}
|
|
56
76
|
<RePieChart width={width} height={height} margin={margin}>
|
|
57
77
|
{showToolTip && (
|
|
58
78
|
<Tooltip
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Box, Stack, styled, SxProps, useTheme } from '@mui/material';
|
|
2
2
|
import { Treemap as ReTreeMap, Tooltip } from 'recharts';
|
|
3
3
|
import { AnimationTiming } from 'recharts/types/util/types';
|
|
4
|
-
import { MarginProps, TitleProps } from '../types/types';
|
|
4
|
+
import { MarginProps, SubTitleProps, TitleProps } from '../types/types';
|
|
5
5
|
import { Typography } from '../../export';
|
|
6
6
|
|
|
7
7
|
interface TreeMapProps {
|
|
8
8
|
title?: string;
|
|
9
|
+
showSubtitle?: boolean;
|
|
10
|
+
subTitle?: string;
|
|
9
11
|
titleProps?: TitleProps;
|
|
12
|
+
subTitleProps?: SubTitleProps;
|
|
10
13
|
data: any;
|
|
11
14
|
dataKey: string | number;
|
|
12
15
|
width?: number;
|
|
@@ -26,6 +29,9 @@ interface TreeMapProps {
|
|
|
26
29
|
const TreeMap = ({
|
|
27
30
|
title = 'Tree Map',
|
|
28
31
|
titleProps = { variant: 'subtitle2' },
|
|
32
|
+
showSubtitle = false,
|
|
33
|
+
subTitle = '',
|
|
34
|
+
subTitleProps = { variant: 'caption' },
|
|
29
35
|
data,
|
|
30
36
|
dataKey,
|
|
31
37
|
width = 400,
|
|
@@ -49,6 +55,15 @@ const TreeMap = ({
|
|
|
49
55
|
>
|
|
50
56
|
{title}
|
|
51
57
|
</Typography>
|
|
58
|
+
{showSubtitle && (
|
|
59
|
+
<Typography
|
|
60
|
+
variant={subTitleProps.variant}
|
|
61
|
+
align={'center'}
|
|
62
|
+
sx={subTitleProps.sx}
|
|
63
|
+
>
|
|
64
|
+
{title}
|
|
65
|
+
</Typography>
|
|
66
|
+
)}
|
|
52
67
|
<ReTreeMap
|
|
53
68
|
data={data}
|
|
54
69
|
dataKey={dataKey}
|
|
@@ -22,6 +22,11 @@ export type TitleProps = {
|
|
|
22
22
|
sx?: any;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
export type SubTitleProps = {
|
|
26
|
+
variant?: Variant;
|
|
27
|
+
sx?: any;
|
|
28
|
+
};
|
|
29
|
+
|
|
25
30
|
export type MarginProps = {
|
|
26
31
|
top?: number;
|
|
27
32
|
right?: number;
|
|
@@ -44,6 +49,7 @@ export type BaseAxisProps = {
|
|
|
44
49
|
export type TickProps = {
|
|
45
50
|
angle?: number;
|
|
46
51
|
tickMargin?: number;
|
|
52
|
+
tick?: any;
|
|
47
53
|
};
|
|
48
54
|
|
|
49
55
|
export type LegendProps = {
|
|
@@ -7,18 +7,21 @@ import {
|
|
|
7
7
|
const data = [
|
|
8
8
|
{
|
|
9
9
|
name: 'Page A',
|
|
10
|
+
sub: 'PA',
|
|
10
11
|
uv: 4000,
|
|
11
12
|
pv: 2400,
|
|
12
13
|
amt: 2400,
|
|
13
14
|
},
|
|
14
15
|
{
|
|
15
16
|
name: 'Page B',
|
|
17
|
+
sub: 'PB',
|
|
16
18
|
uv: 3000,
|
|
17
19
|
pv: 1398,
|
|
18
20
|
amt: 2210,
|
|
19
21
|
},
|
|
20
22
|
{
|
|
21
23
|
name: 'Page C',
|
|
24
|
+
sub: 'PC',
|
|
22
25
|
uv: 2000,
|
|
23
26
|
pv: 9800,
|
|
24
27
|
amt: 2290,
|
|
@@ -122,7 +125,7 @@ export const Default = {
|
|
|
122
125
|
args: {
|
|
123
126
|
data: data,
|
|
124
127
|
bars: bars,
|
|
125
|
-
dataKey: '
|
|
128
|
+
dataKey: 'sub',
|
|
126
129
|
containerSx: { width: '800px', height: '800px' },
|
|
127
130
|
cartesianGrid: { showCartesianGrid: true, size: 5 },
|
|
128
131
|
axisLabelProps: {
|