@ssa-ui-kit/core 1.0.11 → 1.0.14
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/components/PieChart/types.d.ts +3 -3
- package/dist/components/SegmentedPieChart/SegmentedPieChart.d.ts +1 -1
- package/dist/components/SegmentedPieChart/SegmentedPieChartContext.d.ts +13 -0
- package/dist/components/SegmentedPieChart/components/ChartTitle.d.ts +1 -0
- package/dist/components/SegmentedPieChart/components/ChartTooltip.d.ts +4 -0
- package/dist/components/SegmentedPieChart/components/LegendItem.d.ts +2 -0
- package/dist/components/SegmentedPieChart/components/index.d.ts +3 -0
- package/dist/components/SegmentedPieChart/hooks/index.d.ts +1 -0
- package/dist/components/SegmentedPieChart/hooks/useData.d.ts +5 -0
- package/dist/components/SegmentedPieChart/stories/fixtures.d.ts +5 -3
- package/dist/components/SegmentedPieChart/types.d.ts +41 -16
- package/dist/components/SegmentedPieChart/utils.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AccordionGroup/stories/AccordionGroup.stories.tsx +1 -1
- package/src/components/PieChart/PieChart.stories.tsx +2 -2
- package/src/components/PieChart/PieChartBases.tsx +5 -5
- package/src/components/PieChart/types.ts +3 -3
- package/src/components/SegmentedPieChart/SegmentedPieChart.spec.tsx +11 -9
- package/src/components/SegmentedPieChart/SegmentedPieChart.tsx +72 -132
- package/src/components/SegmentedPieChart/SegmentedPieChartContext.tsx +58 -0
- package/src/components/SegmentedPieChart/components/ChartTitle.tsx +91 -0
- package/src/components/SegmentedPieChart/components/ChartTooltip.tsx +87 -0
- package/src/components/SegmentedPieChart/components/LegendItem.tsx +39 -0
- package/src/components/SegmentedPieChart/components/index.ts +3 -0
- package/src/components/SegmentedPieChart/hooks/index.ts +1 -0
- package/src/components/SegmentedPieChart/hooks/useData.ts +75 -0
- package/src/components/SegmentedPieChart/stories/SegmentedPieChart.stories.tsx +67 -7
- package/src/components/SegmentedPieChart/stories/fixtures.ts +72 -45
- package/src/components/SegmentedPieChart/types.ts +43 -16
- package/src/components/SegmentedPieChart/utils.ts +2 -0
- package/tsbuildcache +1 -1
- package/webpack.config.js +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { css, useTheme } from '@emotion/react';
|
|
1
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
3
|
import { AccordionGroup } from '../index';
|
|
3
4
|
import { AccordionGroupDecorator } from './helpers';
|
|
4
|
-
import { css, useTheme } from '@emotion/react';
|
|
5
5
|
import { AccordionTemplate } from './helpers';
|
|
6
6
|
|
|
7
7
|
type Args = StoryObj<typeof AccordionGroup>;
|
|
@@ -88,7 +88,7 @@ export const AccountExample: StoryObj<typeof PieChart> = () => {
|
|
|
88
88
|
font-size: 20px;
|
|
89
89
|
line-height: 25px;
|
|
90
90
|
`}>
|
|
91
|
-
|
|
91
|
+
18183
|
|
92
92
|
<Typography
|
|
93
93
|
variant="body2"
|
|
94
94
|
weight="regular"
|
|
@@ -97,7 +97,7 @@ export const AccountExample: StoryObj<typeof PieChart> = () => {
|
|
|
97
97
|
css={css`
|
|
98
98
|
font-size: 14px;
|
|
99
99
|
`}>
|
|
100
|
-
|
|
100
|
+
USDT
|
|
101
101
|
</Typography>
|
|
102
102
|
</Typography>
|
|
103
103
|
}>
|
|
@@ -15,13 +15,13 @@ export const PieChartBase = styled.div`
|
|
|
15
15
|
|
|
16
16
|
export const PieChartTextBase = styled.div`
|
|
17
17
|
position: absolute;
|
|
18
|
-
width: 100%;
|
|
19
|
-
height: 100%;
|
|
20
|
-
pointer-events: none;
|
|
21
|
-
top: 0;
|
|
22
|
-
left: 0;
|
|
23
18
|
display: flex;
|
|
24
19
|
align-items: center;
|
|
25
20
|
justify-content: center;
|
|
26
21
|
text-align: center;
|
|
22
|
+
width: calc(100% - 34px);
|
|
23
|
+
height: calc(100% - 34px);
|
|
24
|
+
left: 17px;
|
|
25
|
+
top: 17px;
|
|
26
|
+
border-radius: 50%;
|
|
27
27
|
`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SerializedStyles } from '@emotion/react';
|
|
2
|
-
import { ResponsivePie } from '@nivo/pie';
|
|
2
|
+
import { ResponsivePie, MayHaveLabel } from '@nivo/pie';
|
|
3
3
|
import { CommonProps } from '../..';
|
|
4
4
|
|
|
5
5
|
export interface PieChartProps
|
|
@@ -9,12 +9,12 @@ export interface PieChartProps
|
|
|
9
9
|
children?: React.ReactNode;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export interface PieChartLegendItem extends MayHaveLabel {
|
|
13
13
|
id: string | number;
|
|
14
14
|
value: string | number;
|
|
15
15
|
label: string;
|
|
16
16
|
[key: string | number | symbol]: unknown;
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
export interface PieChartLegendProps {
|
|
20
20
|
data: Array<PieChartLegendItem>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SegmentedPieChart } from './index';
|
|
2
|
-
import { balanceData } from './stories/fixtures';
|
|
2
|
+
import { balanceData, balanceTotalAmount } from './stories/fixtures';
|
|
3
3
|
|
|
4
4
|
const ResponsivePieMock = () => <div data-testid="responsive-pie"></div>;
|
|
5
5
|
|
|
@@ -11,19 +11,21 @@ jest.mock('@nivo/pie', () => ({
|
|
|
11
11
|
describe('SegmentedPieChart', () => {
|
|
12
12
|
it('Renders with a Legend', () => {
|
|
13
13
|
const { getByTestId, getByRole, getByText } = render(
|
|
14
|
-
<SegmentedPieChart
|
|
14
|
+
<SegmentedPieChart
|
|
15
|
+
data={balanceData}
|
|
16
|
+
totalAmount={balanceTotalAmount}
|
|
17
|
+
totalDimension="USD"
|
|
18
|
+
/>,
|
|
15
19
|
);
|
|
16
20
|
|
|
17
21
|
getByTestId('responsive-pie');
|
|
18
|
-
getByText(
|
|
22
|
+
getByText(balanceTotalAmount);
|
|
19
23
|
|
|
20
|
-
for (const { label
|
|
24
|
+
for (const { label } of balanceData) {
|
|
21
25
|
getByRole('heading', { name: label });
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
getByRole('heading', { name: `${value} ${label} (${percentage}%)` });
|
|
26
|
-
}
|
|
26
|
+
getByRole('heading', {
|
|
27
|
+
name: `2819 USDT (16%)`,
|
|
28
|
+
});
|
|
27
29
|
}
|
|
28
30
|
});
|
|
29
31
|
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { css, useTheme } from '@emotion/react';
|
|
2
|
-
import {
|
|
3
|
-
import { Typography, Wrapper, PieChart, PieChartLegend } from '@components';
|
|
2
|
+
import { PieChart, PieChartLegend } from '@components';
|
|
4
3
|
import {
|
|
5
4
|
defaultLegendBackgrounds,
|
|
6
5
|
defaultPieChartColors,
|
|
7
6
|
} from './colorPalettes';
|
|
8
|
-
import {
|
|
7
|
+
import { SegmentedPieChartProps } from './types';
|
|
8
|
+
import { ChartTitle, ChartTooltip, LegendItem } from './components';
|
|
9
|
+
import { useData } from './hooks';
|
|
10
|
+
import { SegmentedPieChartProvider } from './SegmentedPieChartContext';
|
|
9
11
|
|
|
10
12
|
export const SegmentedPieChart = ({
|
|
11
13
|
data,
|
|
@@ -13,142 +15,80 @@ export const SegmentedPieChart = ({
|
|
|
13
15
|
pieChartLegendProps,
|
|
14
16
|
legendBackgrounds = defaultLegendBackgrounds,
|
|
15
17
|
pieChartColors = defaultPieChartColors,
|
|
16
|
-
currency = '
|
|
18
|
+
currency = 'USDT',
|
|
17
19
|
otherLabel = 'Other',
|
|
20
|
+
totalAmount,
|
|
21
|
+
totalDimension,
|
|
22
|
+
legendValueRoundingDigits = 2,
|
|
23
|
+
legendPercentageRoundingDigits = 0,
|
|
24
|
+
showDimensions = true,
|
|
25
|
+
showPercentage = true,
|
|
26
|
+
titleTooltipOptions,
|
|
27
|
+
tooltipConfig,
|
|
28
|
+
renderTitleTooltipContent,
|
|
18
29
|
}: SegmentedPieChartProps) => {
|
|
19
30
|
const theme = useTheme();
|
|
20
31
|
|
|
21
|
-
const balanceDataForTheGraph
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
item.parts?.forEach((part, partIndex) => {
|
|
26
|
-
balanceDataForTheGraph.push({
|
|
27
|
-
mainLabel: item.label,
|
|
28
|
-
mainPercentage: item.percentage,
|
|
29
|
-
partLabel: part.label,
|
|
30
|
-
partPercentage: part.percentage,
|
|
31
|
-
color: pieChartColors[itemIndex][partIndex],
|
|
32
|
-
id: `${itemIndex}${partIndex}`,
|
|
33
|
-
mainId: item.id,
|
|
34
|
-
value: part.percentage,
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
} else {
|
|
38
|
-
balanceDataForTheGraph.push({
|
|
39
|
-
mainLabel: item.label,
|
|
40
|
-
mainPercentage: item.percentage,
|
|
41
|
-
color: pieChartColors[itemIndex][0],
|
|
42
|
-
id: `${itemIndex}${0}`,
|
|
43
|
-
mainId: item.id,
|
|
44
|
-
value: item.percentage,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
balanceDataTotal += item.value;
|
|
32
|
+
const { balanceDataForTheGraph, balanceDataForTheLegend } = useData({
|
|
33
|
+
data,
|
|
34
|
+
legendValueRoundingDigits,
|
|
35
|
+
pieChartColors,
|
|
48
36
|
});
|
|
49
37
|
|
|
50
38
|
return (
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
39
|
+
<SegmentedPieChartProvider
|
|
40
|
+
legendPercentageRoundingDigits={legendPercentageRoundingDigits}
|
|
41
|
+
legendValueRoundingDigits={legendValueRoundingDigits}
|
|
42
|
+
totalAmount={totalAmount}
|
|
43
|
+
totalDimension={totalDimension}
|
|
44
|
+
titleTooltipOptions={titleTooltipOptions}
|
|
45
|
+
showDimensions={showDimensions}
|
|
46
|
+
showPercentage={showPercentage}
|
|
47
|
+
otherLabel={otherLabel}
|
|
48
|
+
currency={currency}
|
|
49
|
+
renderTitleTooltipContent={renderTitleTooltipContent}
|
|
50
|
+
tooltipConfig={tooltipConfig}>
|
|
51
|
+
<PieChart
|
|
52
|
+
data={balanceDataForTheGraph}
|
|
53
|
+
animate={true}
|
|
54
|
+
css={{
|
|
55
|
+
width: 400,
|
|
56
|
+
margin: '40px 120px',
|
|
57
|
+
}}
|
|
58
|
+
isInteractive
|
|
59
|
+
activeInnerRadiusOffset={0}
|
|
60
|
+
activeOuterRadiusOffset={0}
|
|
61
|
+
tooltip={(point) => <ChartTooltip point={point} />}
|
|
62
|
+
title={<ChartTitle />}
|
|
63
|
+
{...pieChartProps}>
|
|
64
|
+
<PieChartLegend
|
|
65
|
+
data={balanceDataForTheLegend}
|
|
66
|
+
backgroundColors={legendBackgrounds}
|
|
67
|
+
renderValue={(props) => (
|
|
68
|
+
<LegendItem
|
|
69
|
+
{...props}
|
|
70
|
+
legendValueRoundingDigits={
|
|
71
|
+
props.legendValueRoundingDigits as number
|
|
79
72
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
101
|
-
})}
|
|
102
|
-
</Wrapper>
|
|
103
|
-
);
|
|
104
|
-
}}
|
|
105
|
-
title={
|
|
106
|
-
<Typography
|
|
107
|
-
variant="body2"
|
|
108
|
-
weight="bold"
|
|
109
|
-
color={theme.colors.greyDarker}
|
|
110
|
-
css={css`
|
|
111
|
-
font-size: 20px;
|
|
112
|
-
line-height: 25px;
|
|
113
|
-
`}>
|
|
114
|
-
{balanceDataTotal}
|
|
115
|
-
<Typography
|
|
116
|
-
variant="body2"
|
|
117
|
-
weight="regular"
|
|
118
|
-
as="span"
|
|
119
|
-
color={theme.colors.greyDarker80}
|
|
120
|
-
css={css`
|
|
121
|
-
font-size: 14px;
|
|
122
|
-
`}>
|
|
123
|
-
{currency}
|
|
124
|
-
</Typography>
|
|
125
|
-
</Typography>
|
|
126
|
-
}
|
|
127
|
-
{...pieChartProps}>
|
|
128
|
-
<PieChartLegend
|
|
129
|
-
data={data}
|
|
130
|
-
backgroundColors={legendBackgrounds}
|
|
131
|
-
renderValue={({ value, label, percentage }) =>
|
|
132
|
-
label === otherLabel
|
|
133
|
-
? value + ` ${currency}` + ` (${percentage}%)`
|
|
134
|
-
: value + ' ' + label + ` (${percentage}%)`
|
|
135
|
-
}
|
|
136
|
-
markerStyles={css`
|
|
137
|
-
width: 10px;
|
|
138
|
-
height: 10px;
|
|
139
|
-
`}
|
|
140
|
-
labelListStyles={css`
|
|
141
|
-
h6 {
|
|
142
|
-
font-weight: 700;
|
|
143
|
-
}
|
|
144
|
-
`}
|
|
145
|
-
valueListStyles={css`
|
|
146
|
-
h6 {
|
|
147
|
-
color: ${theme.colors.greyDarker80};
|
|
148
|
-
}
|
|
149
|
-
`}
|
|
150
|
-
{...pieChartLegendProps}
|
|
151
|
-
/>
|
|
152
|
-
</PieChart>
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
markerStyles={css`
|
|
76
|
+
width: 10px;
|
|
77
|
+
height: 10px;
|
|
78
|
+
`}
|
|
79
|
+
labelListStyles={css`
|
|
80
|
+
h6 {
|
|
81
|
+
font-weight: 700;
|
|
82
|
+
}
|
|
83
|
+
`}
|
|
84
|
+
valueListStyles={css`
|
|
85
|
+
h6 {
|
|
86
|
+
color: ${theme.colors.greyDarker80};
|
|
87
|
+
}
|
|
88
|
+
`}
|
|
89
|
+
{...pieChartLegendProps}
|
|
90
|
+
/>
|
|
91
|
+
</PieChart>
|
|
92
|
+
</SegmentedPieChartProvider>
|
|
153
93
|
);
|
|
154
94
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
import { SegmentedPieChartProps } from './types';
|
|
3
|
+
|
|
4
|
+
type ContextType = Pick<
|
|
5
|
+
SegmentedPieChartProps,
|
|
6
|
+
| 'renderTitleTooltipContent'
|
|
7
|
+
| 'totalAmount'
|
|
8
|
+
| 'totalDimension'
|
|
9
|
+
| 'titleTooltipOptions'
|
|
10
|
+
| 'legendValueRoundingDigits'
|
|
11
|
+
| 'tooltipConfig'
|
|
12
|
+
| 'showDimensions'
|
|
13
|
+
| 'showPercentage'
|
|
14
|
+
| 'otherLabel'
|
|
15
|
+
| 'currency'
|
|
16
|
+
> & {
|
|
17
|
+
legendPercentageRoundingDigits: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const SegmentedPieChartContext = createContext<ContextType>({
|
|
21
|
+
totalAmount: 0,
|
|
22
|
+
totalDimension: '',
|
|
23
|
+
legendPercentageRoundingDigits: 0,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const SegmentedPieChartProvider = ({
|
|
27
|
+
children,
|
|
28
|
+
legendPercentageRoundingDigits,
|
|
29
|
+
totalAmount,
|
|
30
|
+
totalDimension,
|
|
31
|
+
titleTooltipOptions,
|
|
32
|
+
showDimensions,
|
|
33
|
+
showPercentage,
|
|
34
|
+
otherLabel,
|
|
35
|
+
currency,
|
|
36
|
+
renderTitleTooltipContent,
|
|
37
|
+
}: {
|
|
38
|
+
children: React.ReactNode;
|
|
39
|
+
} & ContextType) => (
|
|
40
|
+
<SegmentedPieChartContext.Provider
|
|
41
|
+
value={{
|
|
42
|
+
legendPercentageRoundingDigits,
|
|
43
|
+
totalAmount,
|
|
44
|
+
totalDimension,
|
|
45
|
+
titleTooltipOptions,
|
|
46
|
+
showDimensions,
|
|
47
|
+
showPercentage,
|
|
48
|
+
otherLabel,
|
|
49
|
+
currency,
|
|
50
|
+
renderTitleTooltipContent,
|
|
51
|
+
}}>
|
|
52
|
+
{children}
|
|
53
|
+
</SegmentedPieChartContext.Provider>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const useSegmentedPieChartContext = () => {
|
|
57
|
+
return useContext(SegmentedPieChartContext);
|
|
58
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useTheme, css } from '@emotion/react';
|
|
2
|
+
import Typography from '@components/Typography';
|
|
3
|
+
import Tooltip from '@components/Tooltip';
|
|
4
|
+
import TooltipTrigger from '@components/TooltipTrigger';
|
|
5
|
+
import TooltipContent from '@components/TooltipContent';
|
|
6
|
+
import { getRoundedNumber } from '../utils';
|
|
7
|
+
import { useSegmentedPieChartContext } from '../SegmentedPieChartContext';
|
|
8
|
+
|
|
9
|
+
export const ChartTitle = () => {
|
|
10
|
+
const {
|
|
11
|
+
totalAmount,
|
|
12
|
+
totalDimension,
|
|
13
|
+
titleTooltipOptions = [],
|
|
14
|
+
legendPercentageRoundingDigits = 0,
|
|
15
|
+
legendValueRoundingDigits = 0,
|
|
16
|
+
tooltipConfig = {},
|
|
17
|
+
showDimensions,
|
|
18
|
+
showPercentage,
|
|
19
|
+
renderTitleTooltipContent,
|
|
20
|
+
} = useSegmentedPieChartContext();
|
|
21
|
+
const theme = useTheme();
|
|
22
|
+
const tooltipContent = renderTitleTooltipContent ? (
|
|
23
|
+
renderTitleTooltipContent({ totalAmount, totalDimension })
|
|
24
|
+
) : (
|
|
25
|
+
<table
|
|
26
|
+
css={{
|
|
27
|
+
background: theme.colors.greyLighter,
|
|
28
|
+
borderRadius: 8,
|
|
29
|
+
padding: 5,
|
|
30
|
+
fontSize: 12,
|
|
31
|
+
fontWeight: 500,
|
|
32
|
+
'& td': {
|
|
33
|
+
whiteSpace: 'nowrap',
|
|
34
|
+
},
|
|
35
|
+
}}>
|
|
36
|
+
{titleTooltipOptions.map((item, index) => {
|
|
37
|
+
const percentage = (Number(item.value) * 100) / totalAmount;
|
|
38
|
+
const roundedValue = getRoundedNumber(
|
|
39
|
+
item.value,
|
|
40
|
+
item.legendValueRoundingDigits || legendValueRoundingDigits,
|
|
41
|
+
);
|
|
42
|
+
const roundedPercentage = getRoundedNumber(
|
|
43
|
+
percentage,
|
|
44
|
+
item.legendPercentageRoundingDigits || legendPercentageRoundingDigits,
|
|
45
|
+
);
|
|
46
|
+
return (
|
|
47
|
+
<tr key={`chart-title-row-${index}`}>
|
|
48
|
+
<td css={{ fontWeight: 600, padding: '0 5px' }}>{item.label}</td>
|
|
49
|
+
<td>
|
|
50
|
+
{roundedValue} {showDimensions && item.dimension}
|
|
51
|
+
</td>
|
|
52
|
+
{showPercentage && <td>({roundedPercentage}%)</td>}
|
|
53
|
+
</tr>
|
|
54
|
+
);
|
|
55
|
+
})}
|
|
56
|
+
</table>
|
|
57
|
+
);
|
|
58
|
+
return (
|
|
59
|
+
<Tooltip
|
|
60
|
+
enableHover={titleTooltipOptions?.length > 0}
|
|
61
|
+
enableClick={false}
|
|
62
|
+
{...tooltipConfig}>
|
|
63
|
+
<TooltipTrigger>
|
|
64
|
+
<Typography
|
|
65
|
+
variant="body2"
|
|
66
|
+
weight="bold"
|
|
67
|
+
color={theme.colors.greyDarker}
|
|
68
|
+
css={css`
|
|
69
|
+
font-size: 20px;
|
|
70
|
+
line-height: 25px;
|
|
71
|
+
cursor: default;
|
|
72
|
+
`}>
|
|
73
|
+
{totalAmount}
|
|
74
|
+
<Typography
|
|
75
|
+
variant="body2"
|
|
76
|
+
weight="regular"
|
|
77
|
+
as="span"
|
|
78
|
+
color={theme.colors.greyDarker80}
|
|
79
|
+
css={css`
|
|
80
|
+
font-size: 14px;
|
|
81
|
+
`}>
|
|
82
|
+
{totalDimension}
|
|
83
|
+
</Typography>
|
|
84
|
+
</Typography>
|
|
85
|
+
</TooltipTrigger>
|
|
86
|
+
<TooltipContent css={{ padding: '3px 0' }}>
|
|
87
|
+
{tooltipContent}
|
|
88
|
+
</TooltipContent>
|
|
89
|
+
</Tooltip>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useTheme } from '@emotion/react';
|
|
2
|
+
import { MayHaveLabel, PieTooltipProps } from '@nivo/pie';
|
|
3
|
+
import { pathOr } from '@ssa-ui-kit/utils';
|
|
4
|
+
import { BalanceDataForGraph } from '../types';
|
|
5
|
+
import { getRoundedNumber } from '../utils';
|
|
6
|
+
import { useSegmentedPieChartContext } from '../SegmentedPieChartContext';
|
|
7
|
+
|
|
8
|
+
export const ChartTooltip = ({
|
|
9
|
+
point,
|
|
10
|
+
}: {
|
|
11
|
+
point: PieTooltipProps<MayHaveLabel>;
|
|
12
|
+
}) => {
|
|
13
|
+
const { legendPercentageRoundingDigits, showDimensions, showPercentage } =
|
|
14
|
+
useSegmentedPieChartContext();
|
|
15
|
+
const theme = useTheme();
|
|
16
|
+
const pointData = pathOr<typeof point, BalanceDataForGraph>({}, [
|
|
17
|
+
'datum',
|
|
18
|
+
'data',
|
|
19
|
+
])(point);
|
|
20
|
+
const mainData = {
|
|
21
|
+
value:
|
|
22
|
+
typeof pointData.legendValue !== 'undefined'
|
|
23
|
+
? getRoundedNumber(
|
|
24
|
+
pointData.legendValue,
|
|
25
|
+
pointData.legendValueRoundingDigits,
|
|
26
|
+
)
|
|
27
|
+
: getRoundedNumber(
|
|
28
|
+
pointData.value,
|
|
29
|
+
pointData.legendValueRoundingDigits,
|
|
30
|
+
),
|
|
31
|
+
label: pointData.legendLabel || pointData.label,
|
|
32
|
+
percentage: getRoundedNumber(
|
|
33
|
+
pointData.percentage,
|
|
34
|
+
legendPercentageRoundingDigits,
|
|
35
|
+
),
|
|
36
|
+
};
|
|
37
|
+
const partData = {
|
|
38
|
+
value:
|
|
39
|
+
pointData.partLegendValue !== undefined
|
|
40
|
+
? getRoundedNumber(
|
|
41
|
+
pointData.partLegendValue,
|
|
42
|
+
pointData.legendValueRoundingDigits,
|
|
43
|
+
)
|
|
44
|
+
: getRoundedNumber(
|
|
45
|
+
pointData.partValue,
|
|
46
|
+
pointData.legendValueRoundingDigits,
|
|
47
|
+
),
|
|
48
|
+
label: pointData.partLabel || pointData.legendLabel || pointData.label,
|
|
49
|
+
percentage: getRoundedNumber(
|
|
50
|
+
pointData.partPercentage,
|
|
51
|
+
legendPercentageRoundingDigits,
|
|
52
|
+
),
|
|
53
|
+
};
|
|
54
|
+
return (
|
|
55
|
+
<table
|
|
56
|
+
css={{
|
|
57
|
+
background: theme.colors.greyLighter,
|
|
58
|
+
borderRadius: 8,
|
|
59
|
+
padding: 5,
|
|
60
|
+
fontSize: 12,
|
|
61
|
+
fontWeight: 500,
|
|
62
|
+
'& td': {
|
|
63
|
+
whiteSpace: 'nowrap',
|
|
64
|
+
},
|
|
65
|
+
}}>
|
|
66
|
+
<tr>
|
|
67
|
+
<td css={{ fontWeight: 600, padding: '0 5px' }}>{pointData.label}</td>
|
|
68
|
+
<td>
|
|
69
|
+
{mainData.value} {showDimensions && mainData.label}
|
|
70
|
+
</td>
|
|
71
|
+
{showPercentage && <td>({mainData.percentage}%)</td>}
|
|
72
|
+
</tr>
|
|
73
|
+
{pointData.partLabel && (
|
|
74
|
+
<tr>
|
|
75
|
+
<td css={{ fontWeight: 600, padding: '0 5px' }}>
|
|
76
|
+
{pointData.partLabel}
|
|
77
|
+
</td>
|
|
78
|
+
<td>
|
|
79
|
+
{partData.value}{' '}
|
|
80
|
+
{showDimensions && (pointData.legendLabel || pointData.label)}
|
|
81
|
+
</td>
|
|
82
|
+
{showPercentage && <td>({partData.percentage}%)</td>}
|
|
83
|
+
</tr>
|
|
84
|
+
)}
|
|
85
|
+
</table>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LegendItemProps } from '../types';
|
|
3
|
+
import { getRoundedNumber } from '../utils';
|
|
4
|
+
import { useSegmentedPieChartContext } from '../SegmentedPieChartContext';
|
|
5
|
+
|
|
6
|
+
export const LegendItem = ({
|
|
7
|
+
label,
|
|
8
|
+
legendLabel,
|
|
9
|
+
percentage,
|
|
10
|
+
legendValue,
|
|
11
|
+
legendValueRoundingDigits,
|
|
12
|
+
}: LegendItemProps) => {
|
|
13
|
+
const {
|
|
14
|
+
legendPercentageRoundingDigits,
|
|
15
|
+
showDimensions,
|
|
16
|
+
showPercentage,
|
|
17
|
+
otherLabel,
|
|
18
|
+
currency,
|
|
19
|
+
} = useSegmentedPieChartContext();
|
|
20
|
+
const legendValueLocal = getRoundedNumber(
|
|
21
|
+
legendValue,
|
|
22
|
+
legendValueRoundingDigits as number,
|
|
23
|
+
);
|
|
24
|
+
const percentageLocal = getRoundedNumber(
|
|
25
|
+
percentage,
|
|
26
|
+
legendPercentageRoundingDigits as number,
|
|
27
|
+
);
|
|
28
|
+
const dimension = showDimensions
|
|
29
|
+
? label === otherLabel
|
|
30
|
+
? (legendLabel as string | undefined) || currency
|
|
31
|
+
: (legendLabel as string | undefined) || label
|
|
32
|
+
: '';
|
|
33
|
+
return (
|
|
34
|
+
<React.Fragment>
|
|
35
|
+
{legendValueLocal} {showDimensions && dimension}
|
|
36
|
+
{showPercentage && ` (${percentageLocal}%)`}
|
|
37
|
+
</React.Fragment>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useData';
|