@ssa-ui-kit/core 1.0.12 → 1.0.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/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 -4
- package/dist/components/SegmentedPieChart/components/ChartTooltip.d.ts +1 -2
- package/dist/components/SegmentedPieChart/components/LegendItem.d.ts +1 -1
- package/dist/components/SegmentedPieChart/stories/fixtures.d.ts +1 -0
- package/dist/components/SegmentedPieChart/types.d.ts +13 -1
- 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/Indicator/Indicator.tsx +13 -6
- package/src/components/PieChart/PieChartBases.tsx +5 -5
- package/src/components/SegmentedPieChart/SegmentedPieChart.tsx +57 -52
- package/src/components/SegmentedPieChart/SegmentedPieChartContext.tsx +58 -0
- package/src/components/SegmentedPieChart/components/ChartTitle.tsx +84 -27
- package/src/components/SegmentedPieChart/components/ChartTooltip.tsx +9 -7
- package/src/components/SegmentedPieChart/components/LegendItem.tsx +8 -5
- package/src/components/SegmentedPieChart/hooks/useData.ts +32 -24
- package/src/components/SegmentedPieChart/stories/SegmentedPieChart.stories.tsx +23 -0
- package/src/components/SegmentedPieChart/stories/fixtures.ts +83 -0
- package/src/components/SegmentedPieChart/types.ts +14 -8
- 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>;
|
|
@@ -15,9 +15,7 @@ const Indicator = ({
|
|
|
15
15
|
const indicatorRef = useRef<HTMLDivElement>(null);
|
|
16
16
|
const childrenRef = useRef<HTMLDivElement | null>(null);
|
|
17
17
|
const [width, setWidth] = useState<number>(0);
|
|
18
|
-
const [childrenData, setChildrenData] = useState<ChildrenDataProps
|
|
19
|
-
{} || null,
|
|
20
|
-
);
|
|
18
|
+
const [childrenData, setChildrenData] = useState<ChildrenDataProps>({});
|
|
21
19
|
const { width: windowWidth } = useWindowSize();
|
|
22
20
|
const theme = useTheme();
|
|
23
21
|
|
|
@@ -32,8 +30,17 @@ const Indicator = ({
|
|
|
32
30
|
width: childrenRef.current.offsetWidth,
|
|
33
31
|
right: childrenRef.current.offsetWidth + childrenRef.current.offsetLeft,
|
|
34
32
|
};
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (refValue !== width) {
|
|
34
|
+
setWidth(refValue);
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
37
|
+
childrenData.top !== refData.top ||
|
|
38
|
+
childrenData.left !== refData.left ||
|
|
39
|
+
childrenData.width !== refData.width ||
|
|
40
|
+
childrenData.right !== refData.right
|
|
41
|
+
) {
|
|
42
|
+
setChildrenData(refData);
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
}, [width, childrenRef.current, windowWidth]);
|
|
39
46
|
|
|
@@ -44,7 +51,7 @@ const Indicator = ({
|
|
|
44
51
|
data-testid={`indicator-${position}`}
|
|
45
52
|
ref={indicatorRef}
|
|
46
53
|
css={
|
|
47
|
-
childrenData && [
|
|
54
|
+
Object.keys(childrenData).length > 0 && [
|
|
48
55
|
css`
|
|
49
56
|
top: ${childrenData.top + 2}px;
|
|
50
57
|
left: ${isRight ? '-6px' : '1px'};
|
|
@@ -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
|
`;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { SegmentedPieChartProps } from './types';
|
|
8
8
|
import { ChartTitle, ChartTooltip, LegendItem } from './components';
|
|
9
9
|
import { useData } from './hooks';
|
|
10
|
+
import { SegmentedPieChartProvider } from './SegmentedPieChartContext';
|
|
10
11
|
|
|
11
12
|
export const SegmentedPieChart = ({
|
|
12
13
|
data,
|
|
@@ -22,6 +23,9 @@ export const SegmentedPieChart = ({
|
|
|
22
23
|
legendPercentageRoundingDigits = 0,
|
|
23
24
|
showDimensions = true,
|
|
24
25
|
showPercentage = true,
|
|
26
|
+
titleTooltipOptions,
|
|
27
|
+
tooltipConfig,
|
|
28
|
+
renderTitleTooltipContent,
|
|
25
29
|
}: SegmentedPieChartProps) => {
|
|
26
30
|
const theme = useTheme();
|
|
27
31
|
|
|
@@ -32,58 +36,59 @@ export const SegmentedPieChart = ({
|
|
|
32
36
|
});
|
|
33
37
|
|
|
34
38
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
72
|
+
}
|
|
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};
|
|
63
87
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/>
|
|
70
|
-
)}
|
|
71
|
-
markerStyles={css`
|
|
72
|
-
width: 10px;
|
|
73
|
-
height: 10px;
|
|
74
|
-
`}
|
|
75
|
-
labelListStyles={css`
|
|
76
|
-
h6 {
|
|
77
|
-
font-weight: 700;
|
|
78
|
-
}
|
|
79
|
-
`}
|
|
80
|
-
valueListStyles={css`
|
|
81
|
-
h6 {
|
|
82
|
-
color: ${theme.colors.greyDarker80};
|
|
83
|
-
}
|
|
84
|
-
`}
|
|
85
|
-
{...pieChartLegendProps}
|
|
86
|
-
/>
|
|
87
|
-
</PieChart>
|
|
88
|
+
`}
|
|
89
|
+
{...pieChartLegendProps}
|
|
90
|
+
/>
|
|
91
|
+
</PieChart>
|
|
92
|
+
</SegmentedPieChartProvider>
|
|
88
93
|
);
|
|
89
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
|
+
};
|
|
@@ -1,34 +1,91 @@
|
|
|
1
1
|
import { useTheme, css } from '@emotion/react';
|
|
2
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';
|
|
3
8
|
|
|
4
|
-
export const ChartTitle = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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();
|
|
11
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
|
+
);
|
|
12
58
|
return (
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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>
|
|
33
90
|
);
|
|
34
91
|
};
|
|
@@ -3,14 +3,15 @@ import { MayHaveLabel, PieTooltipProps } from '@nivo/pie';
|
|
|
3
3
|
import { pathOr } from '@ssa-ui-kit/utils';
|
|
4
4
|
import { BalanceDataForGraph } from '../types';
|
|
5
5
|
import { getRoundedNumber } from '../utils';
|
|
6
|
+
import { useSegmentedPieChartContext } from '../SegmentedPieChartContext';
|
|
6
7
|
|
|
7
8
|
export const ChartTooltip = ({
|
|
8
9
|
point,
|
|
9
|
-
legendPercentageRoundingDigits,
|
|
10
10
|
}: {
|
|
11
11
|
point: PieTooltipProps<MayHaveLabel>;
|
|
12
|
-
legendPercentageRoundingDigits: number;
|
|
13
12
|
}) => {
|
|
13
|
+
const { legendPercentageRoundingDigits, showDimensions, showPercentage } =
|
|
14
|
+
useSegmentedPieChartContext();
|
|
14
15
|
const theme = useTheme();
|
|
15
16
|
const pointData = pathOr<typeof point, BalanceDataForGraph>({}, [
|
|
16
17
|
'datum',
|
|
@@ -24,7 +25,7 @@ export const ChartTooltip = ({
|
|
|
24
25
|
pointData.legendValueRoundingDigits,
|
|
25
26
|
)
|
|
26
27
|
: getRoundedNumber(
|
|
27
|
-
pointData.
|
|
28
|
+
pointData.mainValue,
|
|
28
29
|
pointData.legendValueRoundingDigits,
|
|
29
30
|
),
|
|
30
31
|
label: pointData.legendLabel || pointData.label,
|
|
@@ -65,9 +66,9 @@ export const ChartTooltip = ({
|
|
|
65
66
|
<tr>
|
|
66
67
|
<td css={{ fontWeight: 600, padding: '0 5px' }}>{pointData.label}</td>
|
|
67
68
|
<td>
|
|
68
|
-
{mainData.value} {mainData.label}
|
|
69
|
+
{mainData.value} {showDimensions && mainData.label}
|
|
69
70
|
</td>
|
|
70
|
-
<td>({mainData.percentage}%)</td>
|
|
71
|
+
{showPercentage && <td>({mainData.percentage}%)</td>}
|
|
71
72
|
</tr>
|
|
72
73
|
{pointData.partLabel && (
|
|
73
74
|
<tr>
|
|
@@ -75,9 +76,10 @@ export const ChartTooltip = ({
|
|
|
75
76
|
{pointData.partLabel}
|
|
76
77
|
</td>
|
|
77
78
|
<td>
|
|
78
|
-
{partData.value}
|
|
79
|
+
{partData.value}{' '}
|
|
80
|
+
{showDimensions && (pointData.legendLabel || pointData.label)}
|
|
79
81
|
</td>
|
|
80
|
-
<td>({partData.percentage}%)</td>
|
|
82
|
+
{showPercentage && <td>({partData.percentage}%)</td>}
|
|
81
83
|
</tr>
|
|
82
84
|
)}
|
|
83
85
|
</table>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { LegendItemProps } from '../types';
|
|
3
3
|
import { getRoundedNumber } from '../utils';
|
|
4
|
+
import { useSegmentedPieChartContext } from '../SegmentedPieChartContext';
|
|
4
5
|
|
|
5
6
|
export const LegendItem = ({
|
|
6
7
|
label,
|
|
@@ -8,12 +9,14 @@ export const LegendItem = ({
|
|
|
8
9
|
percentage,
|
|
9
10
|
legendValue,
|
|
10
11
|
legendValueRoundingDigits,
|
|
11
|
-
legendPercentageRoundingDigits,
|
|
12
|
-
showDimensions,
|
|
13
|
-
showPercentage,
|
|
14
|
-
otherLabel,
|
|
15
|
-
currency,
|
|
16
12
|
}: LegendItemProps) => {
|
|
13
|
+
const {
|
|
14
|
+
legendPercentageRoundingDigits,
|
|
15
|
+
showDimensions,
|
|
16
|
+
showPercentage,
|
|
17
|
+
otherLabel,
|
|
18
|
+
currency,
|
|
19
|
+
} = useSegmentedPieChartContext();
|
|
17
20
|
const legendValueLocal = getRoundedNumber(
|
|
18
21
|
legendValue,
|
|
19
22
|
legendValueRoundingDigits as number,
|
|
@@ -15,51 +15,59 @@ export const useData = ({
|
|
|
15
15
|
'data' | 'pieChartColors' | 'legendValueRoundingDigits'
|
|
16
16
|
>) => {
|
|
17
17
|
let calculatedTotalAmount = 0;
|
|
18
|
-
|
|
18
|
+
const dataLocal = Array.isArray(data) ? data : [];
|
|
19
|
+
const pieChartColorsLocal = Array.isArray(pieChartColors)
|
|
20
|
+
? pieChartColors
|
|
21
|
+
: [[]];
|
|
22
|
+
dataLocal?.forEach((item) => {
|
|
19
23
|
calculatedTotalAmount += Number(item.value);
|
|
20
24
|
});
|
|
21
25
|
const balanceDataForTheGraph: BalanceDataForGraph[] = [];
|
|
22
26
|
const balanceDataForTheLegend: BalanceDataForGraph[] = [];
|
|
23
|
-
|
|
27
|
+
dataLocal?.forEach((item, itemIndex) => {
|
|
24
28
|
const mainPercentage = (Number(item.value) * 100) / calculatedTotalAmount;
|
|
25
29
|
const newMainItem = {
|
|
26
30
|
value: item.value,
|
|
27
31
|
label: item.label,
|
|
28
32
|
percentage: mainPercentage,
|
|
29
33
|
mainId: Number(item.id),
|
|
34
|
+
mainValue: item.value,
|
|
30
35
|
legendLabel: item.legendLabel,
|
|
31
36
|
legendValue: item.legendValue,
|
|
32
37
|
legendValueRoundingDigits: propOr<SegmentedDataItem, number>(
|
|
33
38
|
legendValueRoundingDigits,
|
|
34
39
|
'legendValueRoundingDigits',
|
|
35
40
|
)(item),
|
|
36
|
-
color:
|
|
41
|
+
color: pieChartColorsLocal?.[itemIndex]?.[0],
|
|
37
42
|
id: `${itemIndex}0`,
|
|
38
43
|
};
|
|
39
44
|
balanceDataForTheLegend.push(newMainItem);
|
|
40
45
|
if (item.parts?.length) {
|
|
41
|
-
item.parts
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
item.parts
|
|
47
|
+
?.filter((part) => !!part.value)
|
|
48
|
+
.forEach((part, partIndex) => {
|
|
49
|
+
const partPercentage = (part.value * 100) / calculatedTotalAmount;
|
|
50
|
+
balanceDataForTheGraph.push({
|
|
51
|
+
value: part.value,
|
|
52
|
+
label: item.label,
|
|
53
|
+
percentage: mainPercentage,
|
|
54
|
+
mainId: Number(item.id),
|
|
55
|
+
mainValue: item.value,
|
|
56
|
+
legendLabel: item.legendLabel,
|
|
57
|
+
legendValue: item.legendValue,
|
|
58
|
+
legendValueRoundingDigits: propOr<SegmentedDataItem, number>(
|
|
59
|
+
legendValueRoundingDigits,
|
|
60
|
+
'legendValueRoundingDigits',
|
|
61
|
+
)(item),
|
|
62
|
+
color: pieChartColorsLocal?.[itemIndex]?.[partIndex],
|
|
63
|
+
id: `${itemIndex}${partIndex}`,
|
|
64
|
+
partIndex,
|
|
65
|
+
partLabel: part.label,
|
|
66
|
+
partPercentage: Number(partPercentage),
|
|
67
|
+
partValue: part.value,
|
|
68
|
+
partLegendValue: part.legendValue,
|
|
69
|
+
});
|
|
61
70
|
});
|
|
62
|
-
});
|
|
63
71
|
} else {
|
|
64
72
|
balanceDataForTheGraph.push(newMainItem);
|
|
65
73
|
}
|
|
@@ -98,3 +98,26 @@ export const WithoutDimensions = {
|
|
|
98
98
|
showDimensions: false,
|
|
99
99
|
},
|
|
100
100
|
};
|
|
101
|
+
|
|
102
|
+
export const WithTotalTooltip = {
|
|
103
|
+
...StoryTemplate,
|
|
104
|
+
args: {
|
|
105
|
+
titleTooltipOptions: [
|
|
106
|
+
{
|
|
107
|
+
value: 10500,
|
|
108
|
+
label: 'Option 1',
|
|
109
|
+
dimension: 'USDT',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
value: 5000,
|
|
113
|
+
label: 'Option 2',
|
|
114
|
+
dimension: 'USDT',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
value: 2237,
|
|
118
|
+
label: 'Option 3',
|
|
119
|
+
dimension: 'USDT',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
};
|
|
@@ -100,6 +100,89 @@ export const balanceData: SegmentedDataSet = [
|
|
|
100
100
|
},
|
|
101
101
|
];
|
|
102
102
|
|
|
103
|
+
export const balanceDataNullable: SegmentedDataSet = [
|
|
104
|
+
{
|
|
105
|
+
id: 1,
|
|
106
|
+
value: 5843.37,
|
|
107
|
+
legendValue: 5843.37 / RATE.BTC,
|
|
108
|
+
legendLabel: 'BTC',
|
|
109
|
+
label: 'BTC',
|
|
110
|
+
legendValueRoundingDigits: 6,
|
|
111
|
+
parts: [
|
|
112
|
+
{
|
|
113
|
+
label: 'Option 1',
|
|
114
|
+
value: 5843.37,
|
|
115
|
+
legendValue: 5843.37 / RATE.BTC,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
label: 'Option 2',
|
|
119
|
+
value: 0,
|
|
120
|
+
legendValue: 0,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: 2,
|
|
126
|
+
value: 5249.25,
|
|
127
|
+
legendValue: 5249.25 / RATE.ETH,
|
|
128
|
+
legendLabel: 'ETH',
|
|
129
|
+
label: 'ETH',
|
|
130
|
+
legendValueRoundingDigits: 2,
|
|
131
|
+
parts: [
|
|
132
|
+
{
|
|
133
|
+
label: 'Option 1',
|
|
134
|
+
value: 2800,
|
|
135
|
+
legendValue: 2800 / RATE.ETH,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
label: 'Option 2',
|
|
139
|
+
value: 2449.25,
|
|
140
|
+
legendValue: 2449.25 / RATE.ETH,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
id: 3,
|
|
146
|
+
value: 3825.55,
|
|
147
|
+
legendValue: 3825.55 / RATE.FDUSD,
|
|
148
|
+
legendLabel: 'FDUSD',
|
|
149
|
+
label: 'FDUSD',
|
|
150
|
+
legendValueRoundingDigits: 2,
|
|
151
|
+
parts: [
|
|
152
|
+
{
|
|
153
|
+
label: 'Option 1',
|
|
154
|
+
value: 3825.55,
|
|
155
|
+
legendValue: 3825.55 / RATE.FDUSD,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
label: 'Option 2',
|
|
159
|
+
value: 0,
|
|
160
|
+
legendValue: 0,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: 4,
|
|
166
|
+
value: 2818.83,
|
|
167
|
+
legendValue: 2818.83 / RATE.USDT,
|
|
168
|
+
label: 'Other',
|
|
169
|
+
legendLabel: 'USDT',
|
|
170
|
+
legendValueRoundingDigits: 0,
|
|
171
|
+
parts: [
|
|
172
|
+
{
|
|
173
|
+
label: 'Option 1',
|
|
174
|
+
value: 2818.83,
|
|
175
|
+
legendValue: 2818.83 / RATE.USDT,
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
label: 'Option 2',
|
|
179
|
+
value: 0,
|
|
180
|
+
legendValue: 0,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
|
|
103
186
|
export const balanceTotalAmount = balanceData
|
|
104
187
|
.map((item) => Number(item.value))
|
|
105
188
|
.reduce((acc, currentValue) => acc + currentValue, 0);
|