@quillsql/react 1.0.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/.eslintrc.json +19 -0
- package/.prettierrc +11 -0
- package/example/README.md +46 -0
- package/example/package-lock.json +12111 -0
- package/example/package.json +43 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/index.html +43 -0
- package/example/public/logo192.png +0 -0
- package/example/public/logo512.png +0 -0
- package/example/public/manifest.json +25 -0
- package/example/public/robots.txt +3 -0
- package/example/src/App.css +38 -0
- package/example/src/App.test.tsx +9 -0
- package/example/src/App.tsx +46 -0
- package/example/src/index.css +13 -0
- package/example/src/index.tsx +19 -0
- package/example/src/logo.svg +1 -0
- package/example/src/react-app-env.d.ts +1 -0
- package/example/src/reportWebVitals.ts +15 -0
- package/example/src/setupTests.ts +5 -0
- package/example/tsconfig.json +26 -0
- package/lib/AppContext.d.ts +29 -0
- package/lib/AppContext.js +94 -0
- package/lib/AppContext.js.map +1 -0
- package/lib/BarList.d.ts +17 -0
- package/lib/BarList.js +81 -0
- package/lib/BarList.js.map +1 -0
- package/lib/Button.d.ts +26 -0
- package/lib/Button.js +151 -0
- package/lib/Button.js.map +1 -0
- package/lib/Chart.d.ts +26 -0
- package/lib/Chart.js +532 -0
- package/lib/Chart.js.map +1 -0
- package/lib/Context.d.ts +28 -0
- package/lib/Context.js +126 -0
- package/lib/Context.js.map +1 -0
- package/lib/ContextProvider.d.ts +28 -0
- package/lib/ContextProvider.js +93 -0
- package/lib/ContextProvider.js.map +1 -0
- package/lib/Dashboard.d.ts +9 -0
- package/lib/Dashboard.js +271 -0
- package/lib/Dashboard.js.map +1 -0
- package/lib/DateRangePicker/Calendar.d.ts +15 -0
- package/lib/DateRangePicker/Calendar.js +94 -0
- package/lib/DateRangePicker/Calendar.js.map +1 -0
- package/lib/DateRangePicker/DateRangePicker.d.ts +31 -0
- package/lib/DateRangePicker/DateRangePicker.js +105 -0
- package/lib/DateRangePicker/DateRangePicker.js.map +1 -0
- package/lib/DateRangePicker/DateRangePickerButton.d.ts +21 -0
- package/lib/DateRangePicker/DateRangePickerButton.js +39 -0
- package/lib/DateRangePicker/DateRangePickerButton.js.map +1 -0
- package/lib/DateRangePicker/dateRangePickerUtils.d.ts +13 -0
- package/lib/DateRangePicker/dateRangePickerUtils.js +313 -0
- package/lib/DateRangePicker/dateRangePickerUtils.js.map +1 -0
- package/lib/DateRangePicker/index.d.ts +2 -0
- package/lib/DateRangePicker/index.js +2 -0
- package/lib/DateRangePicker/index.js.map +1 -0
- package/lib/DateRangePicker.d.ts +32 -0
- package/lib/DateRangePicker.js +105 -0
- package/lib/DateRangePicker.js.map +1 -0
- package/lib/PieChart.d.ts +63 -0
- package/lib/PieChart.js +589 -0
- package/lib/PieChart.js.map +1 -0
- package/lib/QuillProvider.d.ts +13 -0
- package/lib/QuillProvider.js +19 -0
- package/lib/QuillProvider.js.map +1 -0
- package/lib/assets/ArrowDownHeadIcon.d.ts +5 -0
- package/lib/assets/ArrowDownHeadIcon.js +29 -0
- package/lib/assets/ArrowDownHeadIcon.js.map +1 -0
- package/lib/assets/ArrowDownIcon.d.ts +5 -0
- package/lib/assets/ArrowDownIcon.js +29 -0
- package/lib/assets/ArrowDownIcon.js.map +1 -0
- package/lib/assets/ArrowDownRightIcon.d.ts +5 -0
- package/lib/assets/ArrowDownRightIcon.js +29 -0
- package/lib/assets/ArrowDownRightIcon.js.map +1 -0
- package/lib/assets/ArrowLeftHeadIcon.d.ts +5 -0
- package/lib/assets/ArrowLeftHeadIcon.js +29 -0
- package/lib/assets/ArrowLeftHeadIcon.js.map +1 -0
- package/lib/assets/ArrowRightHeadIcon.d.ts +5 -0
- package/lib/assets/ArrowRightHeadIcon.js +29 -0
- package/lib/assets/ArrowRightHeadIcon.js.map +1 -0
- package/lib/assets/ArrowRightIcon.d.ts +5 -0
- package/lib/assets/ArrowRightIcon.js +29 -0
- package/lib/assets/ArrowRightIcon.js.map +1 -0
- package/lib/assets/ArrowUpHeadIcon.d.ts +5 -0
- package/lib/assets/ArrowUpHeadIcon.js +29 -0
- package/lib/assets/ArrowUpHeadIcon.js.map +1 -0
- package/lib/assets/ArrowUpIcon.d.ts +5 -0
- package/lib/assets/ArrowUpIcon.js +29 -0
- package/lib/assets/ArrowUpIcon.js.map +1 -0
- package/lib/assets/ArrowUpRightIcon.d.ts +5 -0
- package/lib/assets/ArrowUpRightIcon.js +29 -0
- package/lib/assets/ArrowUpRightIcon.js.map +1 -0
- package/lib/assets/CalendarIcon.d.ts +5 -0
- package/lib/assets/CalendarIcon.js +29 -0
- package/lib/assets/CalendarIcon.js.map +1 -0
- package/lib/assets/DoubleArrowLeftHeadIcon.d.ts +5 -0
- package/lib/assets/DoubleArrowLeftHeadIcon.js +29 -0
- package/lib/assets/DoubleArrowLeftHeadIcon.js.map +1 -0
- package/lib/assets/DoubleArrowRightHeadIcon.d.ts +5 -0
- package/lib/assets/DoubleArrowRightHeadIcon.js +29 -0
- package/lib/assets/DoubleArrowRightHeadIcon.js.map +1 -0
- package/lib/assets/ExclamationFilledIcon.d.ts +5 -0
- package/lib/assets/ExclamationFilledIcon.js +29 -0
- package/lib/assets/ExclamationFilledIcon.js.map +1 -0
- package/lib/assets/LoadingSpinner.d.ts +5 -0
- package/lib/assets/LoadingSpinner.js +29 -0
- package/lib/assets/LoadingSpinner.js.map +1 -0
- package/lib/assets/SearchIcon.d.ts +5 -0
- package/lib/assets/SearchIcon.js +29 -0
- package/lib/assets/SearchIcon.js.map +1 -0
- package/lib/assets/XCircleIcon.d.ts +5 -0
- package/lib/assets/XCircleIcon.js +29 -0
- package/lib/assets/XCircleIcon.js.map +1 -0
- package/lib/assets/index.d.ts +16 -0
- package/lib/assets/index.js +17 -0
- package/lib/assets/index.js.map +1 -0
- package/lib/components/Dropdown/Dropdown.d.ts +12 -0
- package/lib/components/Dropdown/Dropdown.js +60 -0
- package/lib/components/Dropdown/Dropdown.js.map +1 -0
- package/lib/components/Dropdown/DropdownItem.d.ts +8 -0
- package/lib/components/Dropdown/DropdownItem.js +54 -0
- package/lib/components/Dropdown/DropdownItem.js.map +1 -0
- package/lib/components/Dropdown/index.d.ts +2 -0
- package/lib/components/Dropdown/index.js +3 -0
- package/lib/components/Dropdown/index.js.map +1 -0
- package/lib/components/Modal/Dropdown/Dropdown.d.ts +12 -0
- package/lib/components/Modal/Dropdown/Dropdown.js +52 -0
- package/lib/components/Modal/Dropdown/Dropdown.js.map +1 -0
- package/lib/components/Modal/Dropdown/DropdownItem.d.ts +8 -0
- package/lib/components/Modal/Dropdown/DropdownItem.js +51 -0
- package/lib/components/Modal/Dropdown/DropdownItem.js.map +1 -0
- package/lib/components/Modal/Dropdown/index.d.ts +2 -0
- package/lib/components/Modal/Dropdown/index.js +3 -0
- package/lib/components/Modal/Dropdown/index.js.map +1 -0
- package/lib/components/Modal/Modal.d.ts +13 -0
- package/lib/components/Modal/Modal.js +71 -0
- package/lib/components/Modal/Modal.js.map +1 -0
- package/lib/components/Modal/index.d.ts +1 -0
- package/lib/components/Modal/index.js +2 -0
- package/lib/components/Modal/index.js.map +1 -0
- package/lib/components/selectUtils.d.ts +9 -0
- package/lib/components/selectUtils.js +37 -0
- package/lib/components/selectUtils.js.map +1 -0
- package/lib/contexts/BaseColorContext.d.ts +3 -0
- package/lib/contexts/BaseColorContext.js +5 -0
- package/lib/contexts/BaseColorContext.js.map +1 -0
- package/lib/contexts/HoveredValueContext.d.ts +7 -0
- package/lib/contexts/HoveredValueContext.js +6 -0
- package/lib/contexts/HoveredValueContext.js.map +1 -0
- package/lib/contexts/RootStylesContext.d.ts +3 -0
- package/lib/contexts/RootStylesContext.js +4 -0
- package/lib/contexts/RootStylesContext.js.map +1 -0
- package/lib/contexts/SelectedValueContext.d.ts +7 -0
- package/lib/contexts/SelectedValueContext.js +7 -0
- package/lib/contexts/SelectedValueContext.js.map +1 -0
- package/lib/contexts/index.d.ts +4 -0
- package/lib/contexts/index.js +5 -0
- package/lib/contexts/index.js.map +1 -0
- package/lib/hooks/index.d.ts +4 -0
- package/lib/hooks/index.js +5 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useInternalState.d.ts +3 -0
- package/lib/hooks/useInternalState.js +15 -0
- package/lib/hooks/useInternalState.js.map +1 -0
- package/lib/hooks/useOnClickOutside.d.ts +2 -0
- package/lib/hooks/useOnClickOutside.js +19 -0
- package/lib/hooks/useOnClickOutside.js.map +1 -0
- package/lib/hooks/useOnWindowResize.d.ts +4 -0
- package/lib/hooks/useOnWindowResize.js +15 -0
- package/lib/hooks/useOnWindowResize.js.map +1 -0
- package/lib/hooks/useSelectOnKeyDown.d.ts +2 -0
- package/lib/hooks/useSelectOnKeyDown.js +64 -0
- package/lib/hooks/useSelectOnKeyDown.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/lib/colorClassNames.d.ts +19 -0
- package/lib/lib/colorClassNames.js +3175 -0
- package/lib/lib/colorClassNames.js.map +1 -0
- package/lib/lib/constants.d.ts +16 -0
- package/lib/lib/constants.js +47 -0
- package/lib/lib/constants.js.map +1 -0
- package/lib/lib/font.d.ts +13 -0
- package/lib/lib/font.js +14 -0
- package/lib/lib/font.js.map +1 -0
- package/lib/lib/hexColors.d.ts +3 -0
- package/lib/lib/hexColors.js +29 -0
- package/lib/lib/hexColors.js.map +1 -0
- package/lib/lib/index.d.ts +10 -0
- package/lib/lib/index.js +11 -0
- package/lib/lib/index.js.map +1 -0
- package/lib/lib/inputTypes.d.ts +20 -0
- package/lib/lib/inputTypes.js +37 -0
- package/lib/lib/inputTypes.js.map +1 -0
- package/lib/lib/shape.d.ts +73 -0
- package/lib/lib/shape.js +74 -0
- package/lib/lib/shape.js.map +1 -0
- package/lib/lib/sizing.d.ts +46 -0
- package/lib/lib/sizing.js +43 -0
- package/lib/lib/sizing.js.map +1 -0
- package/lib/lib/spacing.d.ts +264 -0
- package/lib/lib/spacing.js +265 -0
- package/lib/lib/spacing.js.map +1 -0
- package/lib/lib/theme.d.ts +22 -0
- package/lib/lib/theme.js +46 -0
- package/lib/lib/theme.js.map +1 -0
- package/lib/lib/utils.d.ts +12 -0
- package/lib/lib/utils.js +69 -0
- package/lib/lib/utils.js.map +1 -0
- package/lib/styles.css +12019 -0
- package/package.json +48 -0
- package/postcss.config.js +6 -0
- package/src/BarList.tsx +236 -0
- package/src/Chart.tsx +934 -0
- package/src/Context.tsx +204 -0
- package/src/Dashboard.tsx +379 -0
- package/src/DateRangePicker/Calendar.tsx +425 -0
- package/src/DateRangePicker/DateRangePicker.tsx +251 -0
- package/src/DateRangePicker/DateRangePickerButton.tsx +176 -0
- package/src/DateRangePicker/dateRangePickerUtils.tsx +460 -0
- package/src/DateRangePicker/index.ts +3 -0
- package/src/PieChart.tsx +838 -0
- package/src/QuillProvider.tsx +28 -0
- package/src/assets/ArrowDownHeadIcon.tsx +11 -0
- package/src/assets/ArrowDownIcon.tsx +14 -0
- package/src/assets/ArrowDownRightIcon.tsx +14 -0
- package/src/assets/ArrowLeftHeadIcon.tsx +11 -0
- package/src/assets/ArrowRightHeadIcon.tsx +11 -0
- package/src/assets/ArrowRightIcon.tsx +14 -0
- package/src/assets/ArrowUpHeadIcon.tsx +11 -0
- package/src/assets/ArrowUpIcon.tsx +14 -0
- package/src/assets/ArrowUpRightIcon.tsx +14 -0
- package/src/assets/CalendarIcon.tsx +14 -0
- package/src/assets/DoubleArrowLeftHeadIcon.tsx +18 -0
- package/src/assets/DoubleArrowRightHeadIcon.tsx +20 -0
- package/src/assets/ExclamationFilledIcon.tsx +14 -0
- package/src/assets/LoadingSpinner.tsx +11 -0
- package/src/assets/SearchIcon.tsx +14 -0
- package/src/assets/XCircleIcon.tsx +14 -0
- package/src/assets/index.ts +16 -0
- package/src/components/Dropdown/Dropdown.tsx +179 -0
- package/src/components/Dropdown/DropdownItem.tsx +86 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/Modal/Modal.tsx +113 -0
- package/src/components/Modal/index.ts +1 -0
- package/src/components/selectUtils.ts +67 -0
- package/src/contexts/BaseColorContext.tsx +8 -0
- package/src/contexts/HoveredValueContext.tsx +12 -0
- package/src/contexts/RootStylesContext.tsx +5 -0
- package/src/contexts/SelectedValueContext.tsx +13 -0
- package/src/contexts/index.ts +4 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useInternalState.tsx +18 -0
- package/src/hooks/useOnClickOutside.tsx +23 -0
- package/src/hooks/useOnWindowResize.tsx +17 -0
- package/src/hooks/useSelectOnKeyDown.tsx +80 -0
- package/src/index.ts +4 -0
- package/src/lib/colorClassNames.ts +3191 -0
- package/src/lib/constants.ts +52 -0
- package/src/lib/font.ts +14 -0
- package/src/lib/hexColors.ts +28 -0
- package/src/lib/index.ts +10 -0
- package/src/lib/inputTypes.ts +62 -0
- package/src/lib/shape.ts +75 -0
- package/src/lib/sizing.ts +47 -0
- package/src/lib/spacing.ts +264 -0
- package/src/lib/theme.ts +49 -0
- package/src/lib/utils.tsx +81 -0
- package/src/styles.css +5 -0
- package/tailwind.config.js +16 -0
- package/tsconfig.json +22 -0
package/src/PieChart.tsx
ADDED
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
/* eslint-disable react/display-name */
|
|
3
|
+
import React, { useRef, useState, useEffect, CSSProperties } from 'react';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
import { Pie, PieChart, ResponsiveContainer, Tooltip, Legend } from 'recharts';
|
|
6
|
+
|
|
7
|
+
// const data = [
|
|
8
|
+
// {
|
|
9
|
+
// name: 'Project Nile',
|
|
10
|
+
// pct_of_the_total: 0.208266213458027,
|
|
11
|
+
// },
|
|
12
|
+
// {
|
|
13
|
+
// name: 'GA_Columbus',
|
|
14
|
+
// pct_of_the_total: 0.102192710707096,
|
|
15
|
+
// },
|
|
16
|
+
// {
|
|
17
|
+
// name: 'IN_Indianapolis',
|
|
18
|
+
// pct_of_the_total: 0.0965229750772778,
|
|
19
|
+
// },
|
|
20
|
+
// {
|
|
21
|
+
// name: 'MO_St Louis',
|
|
22
|
+
// pct_of_the_total: 0.0732235559304729,
|
|
23
|
+
// },
|
|
24
|
+
// {
|
|
25
|
+
// name: 'AL_Birmingham',
|
|
26
|
+
// pct_of_the_total: 0.0555956813239389,
|
|
27
|
+
// },
|
|
28
|
+
// {
|
|
29
|
+
// name: 'FL_Fort Myers',
|
|
30
|
+
// pct_of_the_total: 0.0479532568651074,
|
|
31
|
+
// },
|
|
32
|
+
// {
|
|
33
|
+
// name: 'GA_Macon',
|
|
34
|
+
// pct_of_the_total: 0.0431507654834117,
|
|
35
|
+
// },
|
|
36
|
+
// {
|
|
37
|
+
// name: 'NC_Charlotte',
|
|
38
|
+
// pct_of_the_total: 0.034166792944838,
|
|
39
|
+
// },
|
|
40
|
+
// {
|
|
41
|
+
// name: 'AL_Montgomery',
|
|
42
|
+
// pct_of_the_total: 0.0298663023800594,
|
|
43
|
+
// },
|
|
44
|
+
// {
|
|
45
|
+
// name: 'TN_Memphis',
|
|
46
|
+
// pct_of_the_total: 0.0292140477651036,
|
|
47
|
+
// },
|
|
48
|
+
// {
|
|
49
|
+
// name: 'SC_Greenville',
|
|
50
|
+
// pct_of_the_total: 0.0288115667542858,
|
|
51
|
+
// },
|
|
52
|
+
// {
|
|
53
|
+
// name: 'SC_Columbia',
|
|
54
|
+
// pct_of_the_total: 0.0285805316472631,
|
|
55
|
+
// },
|
|
56
|
+
// {
|
|
57
|
+
// name: 'NC_Fayetteville',
|
|
58
|
+
// pct_of_the_total: 0.0279000448849207,
|
|
59
|
+
// },
|
|
60
|
+
// {
|
|
61
|
+
// name: 'SC_Spartanburg',
|
|
62
|
+
// pct_of_the_total: 0.0260196308313896,
|
|
63
|
+
// },
|
|
64
|
+
// {
|
|
65
|
+
// name: 'NC_Greensboro',
|
|
66
|
+
// pct_of_the_total: 0.0169521323221251,
|
|
67
|
+
// },
|
|
68
|
+
// {
|
|
69
|
+
// name: 'FL_Orlando',
|
|
70
|
+
// pct_of_the_total: 0.0167433815522564,
|
|
71
|
+
// },
|
|
72
|
+
// {
|
|
73
|
+
// name: 'FL_Tampa',
|
|
74
|
+
// pct_of_the_total: 0.0155513189530513,
|
|
75
|
+
// },
|
|
76
|
+
// {
|
|
77
|
+
// name: 'NC_Raleigh',
|
|
78
|
+
// pct_of_the_total: 0.0154308010765727,
|
|
79
|
+
// },
|
|
80
|
+
// {
|
|
81
|
+
// name: 'FL_Jacksonville',
|
|
82
|
+
// pct_of_the_total: 0.0152275224173022,
|
|
83
|
+
// },
|
|
84
|
+
// {
|
|
85
|
+
// name: 'GA_LaGrange',
|
|
86
|
+
// pct_of_the_total: 0.00867900369362145,
|
|
87
|
+
// },
|
|
88
|
+
// {
|
|
89
|
+
// name: 'GA_Augusta',
|
|
90
|
+
// pct_of_the_total: 0.0084582649800033,
|
|
91
|
+
// },
|
|
92
|
+
// {
|
|
93
|
+
// name: 'TX_San Antonio',
|
|
94
|
+
// pct_of_the_total: 0.00682971823492258,
|
|
95
|
+
// },
|
|
96
|
+
// {
|
|
97
|
+
// name: 'FL_North Port',
|
|
98
|
+
// pct_of_the_total: 0.00637954051173961,
|
|
99
|
+
// },
|
|
100
|
+
// {
|
|
101
|
+
// name: 'No Portfolio',
|
|
102
|
+
// pct_of_the_total: 0.00522734435854761,
|
|
103
|
+
// },
|
|
104
|
+
// ];
|
|
105
|
+
|
|
106
|
+
const useOnWindowResize = (
|
|
107
|
+
handler: { (): void },
|
|
108
|
+
initialWindowSize?: number
|
|
109
|
+
) => {
|
|
110
|
+
const [windowSize, setWindowSize] = useState<undefined | number>(
|
|
111
|
+
initialWindowSize
|
|
112
|
+
);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const handleResize = () => {
|
|
115
|
+
setWindowSize(window.innerWidth);
|
|
116
|
+
handler();
|
|
117
|
+
};
|
|
118
|
+
handleResize();
|
|
119
|
+
window.addEventListener('resize', handleResize);
|
|
120
|
+
|
|
121
|
+
return () => window.removeEventListener('resize', handleResize);
|
|
122
|
+
}, [handler, windowSize]);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const ChartLegend = (categories: string[], colors: string[]) => {
|
|
126
|
+
const legendRef = useRef<HTMLDivElement>(null);
|
|
127
|
+
|
|
128
|
+
// useOnWindowResize(() => {
|
|
129
|
+
// const calculateHeight = (height: number | undefined) =>
|
|
130
|
+
// height
|
|
131
|
+
// ? Number(height) + 20 // 20px extra padding
|
|
132
|
+
// : 60; // default height
|
|
133
|
+
// setLegendHeight(calculateHeight(legendRef.current?.clientHeight));
|
|
134
|
+
// });
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div ref={legendRef} className="flex items-center justify-end">
|
|
138
|
+
<Legend
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
categories={categories}
|
|
141
|
+
colors={colors}
|
|
142
|
+
/>
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export type ValueFormatter = {
|
|
148
|
+
(value: number): string;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const iconVariantValues = [
|
|
152
|
+
'simple',
|
|
153
|
+
'light',
|
|
154
|
+
'shadow',
|
|
155
|
+
'solid',
|
|
156
|
+
'outlined',
|
|
157
|
+
] as const;
|
|
158
|
+
|
|
159
|
+
export type IconVariant = (typeof iconVariantValues)[number];
|
|
160
|
+
|
|
161
|
+
export type HorizontalPosition = 'left' | 'right';
|
|
162
|
+
|
|
163
|
+
export type VerticalPosition = 'top' | 'bottom';
|
|
164
|
+
|
|
165
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'light';
|
|
166
|
+
|
|
167
|
+
const deltaTypeValues = [
|
|
168
|
+
'increase',
|
|
169
|
+
'moderateIncrease',
|
|
170
|
+
'decrease',
|
|
171
|
+
'moderateDecrease',
|
|
172
|
+
'unchanged',
|
|
173
|
+
] as const;
|
|
174
|
+
|
|
175
|
+
export type DeltaType = (typeof deltaTypeValues)[number];
|
|
176
|
+
|
|
177
|
+
const sizeValues = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
|
|
178
|
+
|
|
179
|
+
export type Size = (typeof sizeValues)[number];
|
|
180
|
+
|
|
181
|
+
const colorValues = [
|
|
182
|
+
'slate',
|
|
183
|
+
'gray',
|
|
184
|
+
'zinc',
|
|
185
|
+
'neutral',
|
|
186
|
+
'stone',
|
|
187
|
+
'red',
|
|
188
|
+
'orange',
|
|
189
|
+
'amber',
|
|
190
|
+
'yellow',
|
|
191
|
+
'lime',
|
|
192
|
+
'green',
|
|
193
|
+
'emerald',
|
|
194
|
+
'teal',
|
|
195
|
+
'cyan',
|
|
196
|
+
'sky',
|
|
197
|
+
'blue',
|
|
198
|
+
'indigo',
|
|
199
|
+
'violet',
|
|
200
|
+
'purple',
|
|
201
|
+
'fuchsia',
|
|
202
|
+
'pink',
|
|
203
|
+
'rose',
|
|
204
|
+
] as const;
|
|
205
|
+
|
|
206
|
+
export type Color = (typeof colorValues)[number];
|
|
207
|
+
|
|
208
|
+
const justifyContentValues = [
|
|
209
|
+
'start',
|
|
210
|
+
'end',
|
|
211
|
+
'center',
|
|
212
|
+
'between',
|
|
213
|
+
'around',
|
|
214
|
+
'evenly',
|
|
215
|
+
] as const;
|
|
216
|
+
export type JustifyContent = (typeof justifyContentValues)[number];
|
|
217
|
+
|
|
218
|
+
const alignItemsValues = [
|
|
219
|
+
'start',
|
|
220
|
+
'end',
|
|
221
|
+
'center',
|
|
222
|
+
'baseline',
|
|
223
|
+
'stretch',
|
|
224
|
+
] as const;
|
|
225
|
+
export type AlignItems = (typeof alignItemsValues)[number];
|
|
226
|
+
|
|
227
|
+
export type FlexDirection = 'row' | 'col' | 'row-reverse' | 'col-reverse';
|
|
228
|
+
|
|
229
|
+
export const defaultValueFormatter: ValueFormatter = (value: number) =>
|
|
230
|
+
(value * 1).toFixed(1) + '%';
|
|
231
|
+
|
|
232
|
+
export const BaseColors: { [key: string]: Color } = {
|
|
233
|
+
Slate: 'slate',
|
|
234
|
+
Gray: 'gray',
|
|
235
|
+
Zinc: 'zinc',
|
|
236
|
+
Neutral: 'neutral',
|
|
237
|
+
Stone: 'stone',
|
|
238
|
+
Red: 'red',
|
|
239
|
+
Orange: 'orange',
|
|
240
|
+
Amber: 'amber',
|
|
241
|
+
Yellow: 'yellow',
|
|
242
|
+
Lime: 'lime',
|
|
243
|
+
Green: 'green',
|
|
244
|
+
Emerald: 'emerald',
|
|
245
|
+
Teal: 'teal',
|
|
246
|
+
Cyan: 'cyan',
|
|
247
|
+
Sky: 'sky',
|
|
248
|
+
Blue: 'blue',
|
|
249
|
+
Indigo: 'indigo',
|
|
250
|
+
Violet: 'violet',
|
|
251
|
+
Purple: 'purple',
|
|
252
|
+
Fuchsia: 'fuchsia',
|
|
253
|
+
Pink: 'pink',
|
|
254
|
+
Rose: 'rose',
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const hexColors: { [color: string]: string } = {
|
|
258
|
+
[BaseColors.Slate]: '#64748b',
|
|
259
|
+
[BaseColors.Gray]: '#6b7280',
|
|
260
|
+
[BaseColors.Zinc]: '#71717a',
|
|
261
|
+
[BaseColors.Neutral]: '#737373',
|
|
262
|
+
[BaseColors.Stone]: '#78716c',
|
|
263
|
+
[BaseColors.Red]: '#ef4444',
|
|
264
|
+
[BaseColors.Orange]: '#f97316',
|
|
265
|
+
[BaseColors.Amber]: '#f59e0b',
|
|
266
|
+
[BaseColors.Yellow]: '#eab308',
|
|
267
|
+
[BaseColors.Lime]: '#84cc16',
|
|
268
|
+
[BaseColors.Green]: '#22c55e',
|
|
269
|
+
[BaseColors.Emerald]: '#10b981',
|
|
270
|
+
[BaseColors.Teal]: '#14b8a6',
|
|
271
|
+
[BaseColors.Cyan]: '#06b6d4',
|
|
272
|
+
[BaseColors.Sky]: '#0ea5e9',
|
|
273
|
+
[BaseColors.Blue]: '#3b82f6',
|
|
274
|
+
[BaseColors.Indigo]: '#6366f1',
|
|
275
|
+
[BaseColors.Violet]: '#8b5cf6',
|
|
276
|
+
[BaseColors.Purple]: '#a855f7',
|
|
277
|
+
[BaseColors.Fuchsia]: '#d946ef',
|
|
278
|
+
[BaseColors.Pink]: '#ec4899',
|
|
279
|
+
[BaseColors.Rose]: '#f43f5e',
|
|
280
|
+
[BaseColors.Black]: '#000000',
|
|
281
|
+
[BaseColors.White]: '#ffffff',
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export const themeColorRange: Color[] = [
|
|
285
|
+
BaseColors.Cyan,
|
|
286
|
+
BaseColors.Sky,
|
|
287
|
+
BaseColors.Blue,
|
|
288
|
+
BaseColors.Indigo,
|
|
289
|
+
BaseColors.Violet,
|
|
290
|
+
BaseColors.Purple,
|
|
291
|
+
BaseColors.Fuchsia,
|
|
292
|
+
BaseColors.Slate,
|
|
293
|
+
BaseColors.Gray,
|
|
294
|
+
BaseColors.Zinc,
|
|
295
|
+
BaseColors.Neutral,
|
|
296
|
+
BaseColors.Stone,
|
|
297
|
+
BaseColors.Red,
|
|
298
|
+
BaseColors.Orange,
|
|
299
|
+
BaseColors.Amber,
|
|
300
|
+
BaseColors.Yellow,
|
|
301
|
+
BaseColors.Lime,
|
|
302
|
+
BaseColors.Green,
|
|
303
|
+
BaseColors.Emerald,
|
|
304
|
+
BaseColors.Teal,
|
|
305
|
+
BaseColors.Pink,
|
|
306
|
+
BaseColors.Rose,
|
|
307
|
+
];
|
|
308
|
+
|
|
309
|
+
export const sumNumericArray = (arr: number[]) =>
|
|
310
|
+
arr.reduce((prefixSum, num) => prefixSum + num, 0);
|
|
311
|
+
|
|
312
|
+
// export const parseData = (data: any[], colors: any[]) =>
|
|
313
|
+
// data.map((dataPoint: any, idx: number) => {
|
|
314
|
+
// const baseColor = idx < colors.length ? colors[idx] : BaseColors.Gray;
|
|
315
|
+
// const hexCode = hexColors[baseColor ?? BaseColors.Gray];
|
|
316
|
+
// return {
|
|
317
|
+
// ...dataPoint,
|
|
318
|
+
// color: colors[idx],
|
|
319
|
+
// fill: colors[idx],
|
|
320
|
+
// };
|
|
321
|
+
// });
|
|
322
|
+
|
|
323
|
+
// @ts-ignore
|
|
324
|
+
export const parseData = (data, colors, categoryKey, valueKey) => {
|
|
325
|
+
const maxItems = 20;
|
|
326
|
+
const slicedData = data.slice(0, maxItems);
|
|
327
|
+
|
|
328
|
+
let totalValue = slicedData.reduce(
|
|
329
|
+
(acc, dataPoint) => acc + Number(dataPoint[valueKey]),
|
|
330
|
+
0
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
if (totalValue !== 100) {
|
|
334
|
+
slicedData.forEach(dataPoint => {
|
|
335
|
+
dataPoint[valueKey] = (Number(dataPoint[valueKey]) * 100) / totalValue;
|
|
336
|
+
});
|
|
337
|
+
totalValue = 100;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const parsedData = slicedData.map((dataPoint, idx) => {
|
|
341
|
+
const baseColor =
|
|
342
|
+
idx < colors.length ? colors[idx] : colors[colors.length - 1];
|
|
343
|
+
return {
|
|
344
|
+
...dataPoint,
|
|
345
|
+
color: baseColor,
|
|
346
|
+
fill: baseColor,
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
if (data.length > maxItems) {
|
|
351
|
+
const otherData = data.slice(maxItems);
|
|
352
|
+
const otherSum = otherData.reduce(
|
|
353
|
+
(acc, dataPoint) => acc + Number(dataPoint[valueKey]),
|
|
354
|
+
0
|
|
355
|
+
);
|
|
356
|
+
const otherColor = colors[colors.length - 1];
|
|
357
|
+
const normalizedOtherSum = (otherSum * 100) / totalValue;
|
|
358
|
+
parsedData.push({
|
|
359
|
+
[categoryKey]: 'Other',
|
|
360
|
+
[valueKey]: normalizedOtherSum,
|
|
361
|
+
color: otherColor,
|
|
362
|
+
fill: otherColor,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return parsedData;
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const calculateDefaultLabel = (data: any[], category: string) =>
|
|
370
|
+
sumNumericArray(data.map(dataPoint => dataPoint[category]));
|
|
371
|
+
|
|
372
|
+
export const parseLabelInput = (
|
|
373
|
+
labelInput: string | undefined,
|
|
374
|
+
valueFormatter: ValueFormatter,
|
|
375
|
+
data: any[],
|
|
376
|
+
category: string
|
|
377
|
+
) =>
|
|
378
|
+
labelInput
|
|
379
|
+
? labelInput
|
|
380
|
+
: valueFormatter(calculateDefaultLabel(data, category));
|
|
381
|
+
|
|
382
|
+
export const ChartTooltipFrame = ({
|
|
383
|
+
children,
|
|
384
|
+
}: {
|
|
385
|
+
children: React.ReactNode;
|
|
386
|
+
}) => (
|
|
387
|
+
<div
|
|
388
|
+
// style={{ transform: 'translateX(-120px)' }}
|
|
389
|
+
className="bg-white text-sm rounded-md border shadow-lg"
|
|
390
|
+
// className={twMerge(
|
|
391
|
+
// 'bg-white',
|
|
392
|
+
// 'font-normal',
|
|
393
|
+
// 'border-[12px]',
|
|
394
|
+
// 'border-[1px]',
|
|
395
|
+
// 'text-[#212121]'
|
|
396
|
+
// // boxShadow.lg
|
|
397
|
+
// )}
|
|
398
|
+
>
|
|
399
|
+
{children}
|
|
400
|
+
</div>
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
export interface ChartTooltipRowProps {
|
|
404
|
+
value: string;
|
|
405
|
+
name: string;
|
|
406
|
+
color: Color;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export const ChartTooltipRow = ({
|
|
410
|
+
value,
|
|
411
|
+
name,
|
|
412
|
+
color,
|
|
413
|
+
}: ChartTooltipRowProps) => (
|
|
414
|
+
<div className="flex items-center justify-between space-x-8">
|
|
415
|
+
<div className="flex items-center space-x-2">
|
|
416
|
+
<span
|
|
417
|
+
style={{ background: color, borderWidth: 2, borderColor: 'white' }}
|
|
418
|
+
className={twMerge(
|
|
419
|
+
// 'shrink-0',
|
|
420
|
+
// 'bg-black',
|
|
421
|
+
// 'bg-white',
|
|
422
|
+
// 'border-black',
|
|
423
|
+
// sizing.sm.height,
|
|
424
|
+
// sizing.sm.width,
|
|
425
|
+
'h-3',
|
|
426
|
+
'w-3',
|
|
427
|
+
'shadow',
|
|
428
|
+
'rounded-full'
|
|
429
|
+
// border.md.all,
|
|
430
|
+
// boxShadow.md
|
|
431
|
+
)}
|
|
432
|
+
/>
|
|
433
|
+
<p
|
|
434
|
+
// className={twMerge(
|
|
435
|
+
// 'font-medium tabular-nums text-right whitespace-nowrap',
|
|
436
|
+
// 'text-[#212121] !important'
|
|
437
|
+
// )}
|
|
438
|
+
className="font-medium tabular-nums text-right whitespace-nowrap text-black"
|
|
439
|
+
>
|
|
440
|
+
{value}
|
|
441
|
+
</p>
|
|
442
|
+
</div>
|
|
443
|
+
<p
|
|
444
|
+
className={twMerge(
|
|
445
|
+
'text-right whitespace-nowrap',
|
|
446
|
+
// getColorClassNames(DEFAULT_COLOR, colorPalette.text).textColor,
|
|
447
|
+
'text-gray-500'
|
|
448
|
+
// fontWeight.sm
|
|
449
|
+
)}
|
|
450
|
+
>
|
|
451
|
+
{name}
|
|
452
|
+
</p>
|
|
453
|
+
</div>
|
|
454
|
+
);
|
|
455
|
+
|
|
456
|
+
export interface DonutChartTooltipProps {
|
|
457
|
+
active: boolean | undefined;
|
|
458
|
+
payload: any;
|
|
459
|
+
valueFormatter: ValueFormatter;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export const DonutChartTooltip = ({
|
|
463
|
+
active,
|
|
464
|
+
payload,
|
|
465
|
+
valueFormatter,
|
|
466
|
+
}: DonutChartTooltipProps) => {
|
|
467
|
+
if (active && payload[0]) {
|
|
468
|
+
const payloadRow = payload[0];
|
|
469
|
+
return (
|
|
470
|
+
<ChartTooltipFrame>
|
|
471
|
+
<div
|
|
472
|
+
// style={{ transform: 'translateX(-120px)' }}
|
|
473
|
+
className={twMerge('px-4', 'py-2')}
|
|
474
|
+
>
|
|
475
|
+
<ChartTooltipRow
|
|
476
|
+
value={valueFormatter(payloadRow.value)}
|
|
477
|
+
name={payloadRow.name}
|
|
478
|
+
color={payloadRow.payload.color}
|
|
479
|
+
/>
|
|
480
|
+
</div>
|
|
481
|
+
</ChartTooltipFrame>
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
return null;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
type DonutChartVariant = 'donut' | 'pie';
|
|
488
|
+
|
|
489
|
+
export interface DonutChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
490
|
+
category?: string;
|
|
491
|
+
index?: string;
|
|
492
|
+
colors?: any[];
|
|
493
|
+
data: any[];
|
|
494
|
+
variant?: DonutChartVariant;
|
|
495
|
+
valueFormatter?: ValueFormatter;
|
|
496
|
+
label?: string;
|
|
497
|
+
showLabel?: boolean;
|
|
498
|
+
showAnimation?: boolean;
|
|
499
|
+
showTooltip?: boolean;
|
|
500
|
+
containerStyle?: CSSProperties;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// @ts-ignore
|
|
504
|
+
export function findComplementaryAndAnalogousColors(color1, color2) {
|
|
505
|
+
// Calculate the hue of the first color
|
|
506
|
+
const color1HSL = rgbToHsl(hexToRgb(color1));
|
|
507
|
+
const color2HSL = rgbToHsl(hexToRgb(color2));
|
|
508
|
+
const color1Hue = color1HSL.h;
|
|
509
|
+
|
|
510
|
+
// Calculate the complementary color of the first color
|
|
511
|
+
const complementaryHue = (color1Hue + 180) % 360;
|
|
512
|
+
const complementaryColor = hslToRgb({
|
|
513
|
+
h: complementaryHue,
|
|
514
|
+
s: color1HSL.s,
|
|
515
|
+
l: color1HSL.l,
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// Find an analogous hue to the first color
|
|
519
|
+
const analogousHue1 = (color1Hue + 30) % 360;
|
|
520
|
+
const analogousHue2 = (color1Hue - 30 + 360) % 360;
|
|
521
|
+
|
|
522
|
+
// Convert the analogous hues back to RGB colors
|
|
523
|
+
const analogousColor1 = hslToRgb({
|
|
524
|
+
h: analogousHue1,
|
|
525
|
+
s: color1HSL.s,
|
|
526
|
+
l: color1HSL.l,
|
|
527
|
+
});
|
|
528
|
+
const analogousColor2 = hslToRgb({
|
|
529
|
+
h: analogousHue2,
|
|
530
|
+
s: color1HSL.s,
|
|
531
|
+
l: color1HSL.l,
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
// Calculate the average hue between the two colors
|
|
535
|
+
const avgHue = (color1HSL.h + color2HSL.h) / 2;
|
|
536
|
+
|
|
537
|
+
// Generate a new HSL object with the average hue and the same saturation and lightness as color1
|
|
538
|
+
const analogousHsl = { h: avgHue, s: color1HSL.s, l: color1HSL.l };
|
|
539
|
+
|
|
540
|
+
return [
|
|
541
|
+
color1,
|
|
542
|
+
color2,
|
|
543
|
+
rgbToHex(hslToRgb(analogousHsl)),
|
|
544
|
+
// rgbToHex(complementaryColor),
|
|
545
|
+
// rgbToHex(analogousColor1),
|
|
546
|
+
// rgbToHex(analogousColor2),
|
|
547
|
+
];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// @ts-ignore
|
|
551
|
+
function hexToRgb(hex) {
|
|
552
|
+
const r = parseInt(hex.substring(1, 3), 16);
|
|
553
|
+
const g = parseInt(hex.substring(3, 5), 16);
|
|
554
|
+
const b = parseInt(hex.substring(5, 7), 16);
|
|
555
|
+
return { r, g, b };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// @ts-ignore
|
|
559
|
+
function rgbToHex(rgb) {
|
|
560
|
+
const rHex = rgb.r.toString(16).padStart(2, '0');
|
|
561
|
+
const gHex = rgb.g.toString(16).padStart(2, '0');
|
|
562
|
+
const bHex = rgb.b.toString(16).padStart(2, '0');
|
|
563
|
+
return `#${rHex}${gHex}${bHex}`;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// @ts-ignore
|
|
567
|
+
function rgbToHsl(rgb) {
|
|
568
|
+
const r = rgb.r / 255;
|
|
569
|
+
const g = rgb.g / 255;
|
|
570
|
+
const b = rgb.b / 255;
|
|
571
|
+
|
|
572
|
+
const max = Math.max(r, g, b);
|
|
573
|
+
const min = Math.min(r, g, b);
|
|
574
|
+
|
|
575
|
+
let h = 0,
|
|
576
|
+
s = 0,
|
|
577
|
+
l = (max + min) / 2;
|
|
578
|
+
|
|
579
|
+
if (max !== min) {
|
|
580
|
+
const d = max - min;
|
|
581
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
582
|
+
|
|
583
|
+
switch (max) {
|
|
584
|
+
case r:
|
|
585
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
586
|
+
break;
|
|
587
|
+
case g:
|
|
588
|
+
h = (b - r) / d + 2;
|
|
589
|
+
break;
|
|
590
|
+
case b:
|
|
591
|
+
h = (r - g) / d + 4;
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
h /= 6;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return { h: h * 360, s: s * 100, l: l * 100 };
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// @ts-ignore
|
|
602
|
+
function hslToRgb(hsl) {
|
|
603
|
+
const h = hsl.h / 360;
|
|
604
|
+
const s = hsl.s / 100;
|
|
605
|
+
const l = hsl.l / 100;
|
|
606
|
+
|
|
607
|
+
let r, g, b;
|
|
608
|
+
|
|
609
|
+
if (s === 0) {
|
|
610
|
+
r = g = b = l;
|
|
611
|
+
} else {
|
|
612
|
+
// @ts-ignore
|
|
613
|
+
const hue2rgb = (p, q, t) => {
|
|
614
|
+
if (t < 0) t += 1;
|
|
615
|
+
if (t > 1) t -= 1;
|
|
616
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
617
|
+
if (t < 1 / 2) return q;
|
|
618
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
619
|
+
return p;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
623
|
+
const p = 2 * l - q;
|
|
624
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
625
|
+
g = hue2rgb(p, q, h);
|
|
626
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return {
|
|
630
|
+
r: Math.round(r * 255),
|
|
631
|
+
g: Math.round(g * 255),
|
|
632
|
+
b: Math.round(b * 255),
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// @ts-ignore
|
|
637
|
+
function generateColorGradientSteps(n, colors) {
|
|
638
|
+
const numColors = colors.length;
|
|
639
|
+
|
|
640
|
+
// If there are fewer than two colors, return the original array
|
|
641
|
+
if (numColors < 2) {
|
|
642
|
+
return colors;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Initialize the output array with the first color
|
|
646
|
+
const output = [colors[0]];
|
|
647
|
+
|
|
648
|
+
// Calculate the number of gradient steps between each pair of colors
|
|
649
|
+
const stepsPerPair = Math.floor(n / (numColors - 1));
|
|
650
|
+
|
|
651
|
+
// Generate the gradient steps for each pair of colors
|
|
652
|
+
for (let i = 1; i < numColors; i++) {
|
|
653
|
+
const color1 = colors[i - 1];
|
|
654
|
+
const color2 = colors[i];
|
|
655
|
+
const gradientSteps = generateGradientSteps(color1, color2, stepsPerPair);
|
|
656
|
+
output.push(...gradientSteps);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// If there are remaining steps, add the last color as a stopgap measure
|
|
660
|
+
while (output.length < n) {
|
|
661
|
+
output.push(colors[numColors - 1]);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return output;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
//@ts-ignore
|
|
668
|
+
function generateGradientSteps(color1, color2, n) {
|
|
669
|
+
// Convert the colors to RGB objects
|
|
670
|
+
const rgb1 = hexToRgb(color1);
|
|
671
|
+
const rgb2 = hexToRgb(color2);
|
|
672
|
+
|
|
673
|
+
// Calculate the RGB color difference between the two colors
|
|
674
|
+
const diffR = rgb2.r - rgb1.r;
|
|
675
|
+
const diffG = rgb2.g - rgb1.g;
|
|
676
|
+
const diffB = rgb2.b - rgb1.b;
|
|
677
|
+
|
|
678
|
+
// Calculate the RGB gradient step size between the two colors
|
|
679
|
+
const stepR = diffR / (n + 1);
|
|
680
|
+
const stepG = diffG / (n + 1);
|
|
681
|
+
const stepB = diffB / (n + 1);
|
|
682
|
+
|
|
683
|
+
// Generate the RGB gradient steps
|
|
684
|
+
const gradientSteps = [];
|
|
685
|
+
for (let i = 1; i <= n; i++) {
|
|
686
|
+
const r = Math.round(rgb1.r + stepR * i);
|
|
687
|
+
const g = Math.round(rgb1.g + stepG * i);
|
|
688
|
+
const b = Math.round(rgb1.b + stepB * i);
|
|
689
|
+
gradientSteps.push(rgbToHex({ r, g, b }));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
return gradientSteps;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
const PieChartWrapper = React.forwardRef<HTMLDivElement, DonutChartProps>(
|
|
696
|
+
(props, ref) => {
|
|
697
|
+
const {
|
|
698
|
+
category = 'pct_of_the_total',
|
|
699
|
+
index = 'status',
|
|
700
|
+
data,
|
|
701
|
+
colors = [],
|
|
702
|
+
variant = 'donut',
|
|
703
|
+
valueFormatter = defaultValueFormatter,
|
|
704
|
+
label,
|
|
705
|
+
showLabel = true,
|
|
706
|
+
showAnimation = true,
|
|
707
|
+
showTooltip = true,
|
|
708
|
+
className,
|
|
709
|
+
containerStyle,
|
|
710
|
+
...other
|
|
711
|
+
} = props;
|
|
712
|
+
const isDonut = variant == 'donut';
|
|
713
|
+
|
|
714
|
+
const parsedLabelInput = parseLabelInput(
|
|
715
|
+
label,
|
|
716
|
+
valueFormatter,
|
|
717
|
+
data,
|
|
718
|
+
category
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
const newColors = generateColorGradientSteps(
|
|
722
|
+
data.length,
|
|
723
|
+
findComplementaryAndAnalogousColors(colors[0], colors[1])
|
|
724
|
+
);
|
|
725
|
+
|
|
726
|
+
return (
|
|
727
|
+
<div
|
|
728
|
+
ref={ref}
|
|
729
|
+
style={containerStyle}
|
|
730
|
+
className={twMerge(
|
|
731
|
+
'w-full h-full flex flex-row items-center',
|
|
732
|
+
className
|
|
733
|
+
)}
|
|
734
|
+
{...other}
|
|
735
|
+
>
|
|
736
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
737
|
+
<PieChart>
|
|
738
|
+
<Pie
|
|
739
|
+
// style={{ transform: 'translateX(-120px)' }}
|
|
740
|
+
data={parseData(
|
|
741
|
+
data,
|
|
742
|
+
colors.length >= data.length
|
|
743
|
+
? colors
|
|
744
|
+
: generateColorGradientSteps(Math.min(21, data.length), [
|
|
745
|
+
...findComplementaryAndAnalogousColors(
|
|
746
|
+
colors[0],
|
|
747
|
+
colors[1]
|
|
748
|
+
),
|
|
749
|
+
...colors.slice(2),
|
|
750
|
+
]),
|
|
751
|
+
index,
|
|
752
|
+
category
|
|
753
|
+
)}
|
|
754
|
+
cx="50%"
|
|
755
|
+
cy="50%"
|
|
756
|
+
startAngle={90}
|
|
757
|
+
endAngle={-270}
|
|
758
|
+
innerRadius={isDonut ? '70%' : '0%'}
|
|
759
|
+
outerRadius="100%"
|
|
760
|
+
paddingAngle={0}
|
|
761
|
+
dataKey={category}
|
|
762
|
+
nameKey={index}
|
|
763
|
+
isAnimationActive={true}
|
|
764
|
+
/>
|
|
765
|
+
{/* <Legend
|
|
766
|
+
layout="vertical"
|
|
767
|
+
align="center"
|
|
768
|
+
verticalAlign="middle"
|
|
769
|
+
wrapperStyle={{
|
|
770
|
+
paddingLeft: '20px',
|
|
771
|
+
transform: 'translateX(120px)',
|
|
772
|
+
}}
|
|
773
|
+
content={({ payload }) => (
|
|
774
|
+
<Legend2 payload={payload} colors={newColors} />
|
|
775
|
+
)}
|
|
776
|
+
/> */}
|
|
777
|
+
<Tooltip
|
|
778
|
+
wrapperStyle={{
|
|
779
|
+
outline: 'none',
|
|
780
|
+
}}
|
|
781
|
+
content={({ active, payload }) => (
|
|
782
|
+
<DonutChartTooltip
|
|
783
|
+
active={active}
|
|
784
|
+
payload={payload}
|
|
785
|
+
valueFormatter={valueFormatter}
|
|
786
|
+
/>
|
|
787
|
+
)}
|
|
788
|
+
/>
|
|
789
|
+
</PieChart>
|
|
790
|
+
</ResponsiveContainer>
|
|
791
|
+
</div>
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
);
|
|
795
|
+
|
|
796
|
+
function Legend2({ payload, colors }: { payload: any; colors: string[] }) {
|
|
797
|
+
return (
|
|
798
|
+
<div className="flex flex-col min-w-[130px] max-w-[130px] w-full">
|
|
799
|
+
{/* @ts-ignore */}
|
|
800
|
+
{payload.map((item, idx) => {
|
|
801
|
+
if (idx > 9) {
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
return (
|
|
805
|
+
<div
|
|
806
|
+
key={item.value}
|
|
807
|
+
className="flex flex-row items-center min-w-[130px] max-w-[130px]"
|
|
808
|
+
>
|
|
809
|
+
<div
|
|
810
|
+
style={{
|
|
811
|
+
height: 8,
|
|
812
|
+
width: 8,
|
|
813
|
+
borderRadius: 8,
|
|
814
|
+
background: colors[idx],
|
|
815
|
+
marginRight: 8,
|
|
816
|
+
marginTop: 2,
|
|
817
|
+
}}
|
|
818
|
+
/>
|
|
819
|
+
<div
|
|
820
|
+
style={{
|
|
821
|
+
whiteSpace: 'nowrap',
|
|
822
|
+
overflow: 'hidden',
|
|
823
|
+
textOverflow: 'ellipsis',
|
|
824
|
+
display: 'block',
|
|
825
|
+
maxWidth: 120,
|
|
826
|
+
}}
|
|
827
|
+
className="text-sm text-gray-600 whitespace-nowrap overflow-hidden overflow-ellipsis text-sm font-normal"
|
|
828
|
+
>
|
|
829
|
+
{item.value}
|
|
830
|
+
</div>
|
|
831
|
+
</div>
|
|
832
|
+
);
|
|
833
|
+
})}
|
|
834
|
+
</div>
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
export default PieChartWrapper;
|