@trackunit/react-chart-components 1.7.84 → 1.7.89
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/index.cjs.js +6 -5
- package/index.esm.js +6 -5
- package/package.json +8 -8
- package/src/DonutChart/DonutChart.d.ts +7 -1
- package/src/utils/useLimitDataSet.d.ts +2 -1
package/index.cjs.js
CHANGED
|
@@ -270,16 +270,17 @@ const useChartColor = () => {
|
|
|
270
270
|
* @param data - The data set to limit.
|
|
271
271
|
* @param limit - The limit to apply to the data set.
|
|
272
272
|
* @param autoSortData - If true, the data will be sorted by value in descending order.
|
|
273
|
+
* @param othersName - The name to use for the "others" category. If not provided, the default name "Others" will be used. Main use if you want to translate the "others" category.
|
|
273
274
|
* @returns {object} The limited data set with and without the "others" category.
|
|
274
275
|
*/
|
|
275
|
-
const useLimitDataSet = (data, limit, autoSortData = true) => {
|
|
276
|
+
const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
|
|
276
277
|
const limitedData = react.useMemo(() => {
|
|
277
278
|
const sortedData = autoSortData ? data.toSorted((a, b) => (b.value ?? 0) - (a.value ?? 0)) : data;
|
|
278
279
|
if (sortedData.length > limit) {
|
|
279
280
|
const result = sortedData.slice(0, limit);
|
|
280
281
|
result.push({
|
|
281
282
|
id: "defaultOther",
|
|
282
|
-
name: "Others",
|
|
283
|
+
name: othersName ?? "Others",
|
|
283
284
|
selected: false,
|
|
284
285
|
value: sortedData.slice(limit).reduce((acc, curr) => acc + (curr.value ?? 0), 0),
|
|
285
286
|
color: uiDesignTokens.DEFAULT_CHART_OTHER,
|
|
@@ -288,7 +289,7 @@ const useLimitDataSet = (data, limit, autoSortData = true) => {
|
|
|
288
289
|
return result;
|
|
289
290
|
}
|
|
290
291
|
return sortedData;
|
|
291
|
-
}, [data, limit, autoSortData]);
|
|
292
|
+
}, [data, limit, autoSortData, othersName]);
|
|
292
293
|
const limitedDataWithoutOthers = react.useMemo(() => limitedData.filter(item => !item.original?.defaultOther), [limitedData]);
|
|
293
294
|
return { limitedData, limitedDataWithoutOthers };
|
|
294
295
|
};
|
|
@@ -299,12 +300,12 @@ const useLimitDataSet = (data, limit, autoSortData = true) => {
|
|
|
299
300
|
* @param {DonutChartProps} props - The props for the Chart component
|
|
300
301
|
* @returns {ReactElement} Chart component
|
|
301
302
|
*/
|
|
302
|
-
const DonutChart = ({ data, size = "full", loading = false, onClick, className, dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, }) => {
|
|
303
|
+
const DonutChart = ({ data, size = "full", loading = false, onClick, className, dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, }) => {
|
|
303
304
|
const containerRef = react.useRef(null);
|
|
304
305
|
const chartRef = react.useRef(null);
|
|
305
306
|
const totalValue = react.useMemo(() => overrideTotal ?? data?.map(item => item.value ?? 0).reduce((a, b) => a + b, 0) ?? 0, [data, overrideTotal]);
|
|
306
307
|
const [isHovering, setIsHovering] = react.useState(false);
|
|
307
|
-
const { limitedData, limitedDataWithoutOthers } = useLimitDataSet(data ?? [], maxDataPoints, autoSortData);
|
|
308
|
+
const { limitedData, limitedDataWithoutOthers } = useLimitDataSet(data ?? [], maxDataPoints, autoSortData, othersName);
|
|
308
309
|
const { chartColor } = useChartColor();
|
|
309
310
|
const handleChartReady = react.useCallback((chart) => {
|
|
310
311
|
chartRef.current = chart;
|
package/index.esm.js
CHANGED
|
@@ -249,16 +249,17 @@ const useChartColor = () => {
|
|
|
249
249
|
* @param data - The data set to limit.
|
|
250
250
|
* @param limit - The limit to apply to the data set.
|
|
251
251
|
* @param autoSortData - If true, the data will be sorted by value in descending order.
|
|
252
|
+
* @param othersName - The name to use for the "others" category. If not provided, the default name "Others" will be used. Main use if you want to translate the "others" category.
|
|
252
253
|
* @returns {object} The limited data set with and without the "others" category.
|
|
253
254
|
*/
|
|
254
|
-
const useLimitDataSet = (data, limit, autoSortData = true) => {
|
|
255
|
+
const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
|
|
255
256
|
const limitedData = useMemo(() => {
|
|
256
257
|
const sortedData = autoSortData ? data.toSorted((a, b) => (b.value ?? 0) - (a.value ?? 0)) : data;
|
|
257
258
|
if (sortedData.length > limit) {
|
|
258
259
|
const result = sortedData.slice(0, limit);
|
|
259
260
|
result.push({
|
|
260
261
|
id: "defaultOther",
|
|
261
|
-
name: "Others",
|
|
262
|
+
name: othersName ?? "Others",
|
|
262
263
|
selected: false,
|
|
263
264
|
value: sortedData.slice(limit).reduce((acc, curr) => acc + (curr.value ?? 0), 0),
|
|
264
265
|
color: DEFAULT_CHART_OTHER,
|
|
@@ -267,7 +268,7 @@ const useLimitDataSet = (data, limit, autoSortData = true) => {
|
|
|
267
268
|
return result;
|
|
268
269
|
}
|
|
269
270
|
return sortedData;
|
|
270
|
-
}, [data, limit, autoSortData]);
|
|
271
|
+
}, [data, limit, autoSortData, othersName]);
|
|
271
272
|
const limitedDataWithoutOthers = useMemo(() => limitedData.filter(item => !item.original?.defaultOther), [limitedData]);
|
|
272
273
|
return { limitedData, limitedDataWithoutOthers };
|
|
273
274
|
};
|
|
@@ -278,12 +279,12 @@ const useLimitDataSet = (data, limit, autoSortData = true) => {
|
|
|
278
279
|
* @param {DonutChartProps} props - The props for the Chart component
|
|
279
280
|
* @returns {ReactElement} Chart component
|
|
280
281
|
*/
|
|
281
|
-
const DonutChart = ({ data, size = "full", loading = false, onClick, className, dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, }) => {
|
|
282
|
+
const DonutChart = ({ data, size = "full", loading = false, onClick, className, dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, }) => {
|
|
282
283
|
const containerRef = useRef(null);
|
|
283
284
|
const chartRef = useRef(null);
|
|
284
285
|
const totalValue = useMemo(() => overrideTotal ?? data?.map(item => item.value ?? 0).reduce((a, b) => a + b, 0) ?? 0, [data, overrideTotal]);
|
|
285
286
|
const [isHovering, setIsHovering] = useState(false);
|
|
286
|
-
const { limitedData, limitedDataWithoutOthers } = useLimitDataSet(data ?? [], maxDataPoints, autoSortData);
|
|
287
|
+
const { limitedData, limitedDataWithoutOthers } = useLimitDataSet(data ?? [], maxDataPoints, autoSortData, othersName);
|
|
287
288
|
const { chartColor } = useChartColor();
|
|
288
289
|
const handleChartReady = useCallback((chart) => {
|
|
289
290
|
chartRef.current = chart;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-chart-components",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.89",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"echarts": "5.6.0",
|
|
11
11
|
"react": "19.0.0",
|
|
12
|
-
"@trackunit/date-and-time-utils": "1.7.
|
|
13
|
-
"@trackunit/react-date-and-time-hooks": "1.7.
|
|
14
|
-
"@trackunit/ui-design-tokens": "1.7.
|
|
15
|
-
"@trackunit/shared-utils": "1.9.
|
|
16
|
-
"@trackunit/css-class-variance-utilities": "1.7.
|
|
17
|
-
"@trackunit/react-components": "1.10.
|
|
18
|
-
"@trackunit/react-test-setup": "1.4.
|
|
12
|
+
"@trackunit/date-and-time-utils": "1.7.57",
|
|
13
|
+
"@trackunit/react-date-and-time-hooks": "1.7.80",
|
|
14
|
+
"@trackunit/ui-design-tokens": "1.7.57",
|
|
15
|
+
"@trackunit/shared-utils": "1.9.57",
|
|
16
|
+
"@trackunit/css-class-variance-utilities": "1.7.57",
|
|
17
|
+
"@trackunit/react-components": "1.10.25",
|
|
18
|
+
"@trackunit/react-test-setup": "1.4.57"
|
|
19
19
|
},
|
|
20
20
|
"module": "./index.esm.js",
|
|
21
21
|
"main": "./index.cjs.js",
|
|
@@ -83,6 +83,12 @@ export interface DonutChartProps<TProps extends object> extends CommonProps {
|
|
|
83
83
|
* @default false
|
|
84
84
|
*/
|
|
85
85
|
hideLegendValues?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* The name to use for the "others" category. If not provided, the default name "Others" will be used. Main use if you want to translate the "others" category.
|
|
88
|
+
*
|
|
89
|
+
* @default "Others"
|
|
90
|
+
*/
|
|
91
|
+
othersName?: string;
|
|
86
92
|
}
|
|
87
93
|
/**
|
|
88
94
|
* Create a DonutChart with legends based on our current Chart component
|
|
@@ -90,5 +96,5 @@ export interface DonutChartProps<TProps extends object> extends CommonProps {
|
|
|
90
96
|
* @param {DonutChartProps} props - The props for the Chart component
|
|
91
97
|
* @returns {ReactElement} Chart component
|
|
92
98
|
*/
|
|
93
|
-
export declare const DonutChart: <TProps extends object>({ data, size, loading, onClick, className, dataTestId, maxDataPoints, showOthers, unit, overrideTotal, autoSortData, hideLegendValues, }: DonutChartProps<TProps>) => ReactElement;
|
|
99
|
+
export declare const DonutChart: <TProps extends object>({ data, size, loading, onClick, className, dataTestId, maxDataPoints, showOthers, unit, overrideTotal, autoSortData, hideLegendValues, othersName, }: DonutChartProps<TProps>) => ReactElement;
|
|
94
100
|
export {};
|
|
@@ -12,7 +12,8 @@ type LimitDataSetReturn<TProps extends object> = {
|
|
|
12
12
|
* @param data - The data set to limit.
|
|
13
13
|
* @param limit - The limit to apply to the data set.
|
|
14
14
|
* @param autoSortData - If true, the data will be sorted by value in descending order.
|
|
15
|
+
* @param othersName - The name to use for the "others" category. If not provided, the default name "Others" will be used. Main use if you want to translate the "others" category.
|
|
15
16
|
* @returns {object} The limited data set with and without the "others" category.
|
|
16
17
|
*/
|
|
17
|
-
export declare const useLimitDataSet: <TProps extends object>(data: Array<ChartData<TProps>>, limit: number, autoSortData?: boolean) => LimitDataSetReturn<TProps>;
|
|
18
|
+
export declare const useLimitDataSet: <TProps extends object>(data: Array<ChartData<TProps>>, limit: number, autoSortData?: boolean, othersName?: string | undefined) => LimitDataSetReturn<TProps>;
|
|
18
19
|
export {};
|