@trackunit/react-chart-components 1.3.86 → 1.3.88
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 +380 -96
- package/index.esm.js +361 -97
- package/package.json +5 -4
- package/src/Chart/Chart.d.ts +16 -20
- package/src/{PieChart/PieChart.d.ts → DonutChart/DonutChart.d.ts} +23 -5
- package/src/EChart/EChart.d.ts +43 -0
- package/src/LegendItem/LegendItem.d.ts +5 -2
- package/src/index.d.ts +4 -3
- package/src/utils/useChartColor.d.ts +11 -0
- package/src/utils/useLimitDataSet.d.ts +17 -0
- package/src/Chart/index.d.ts +0 -1
- package/src/LegendItem/index.d.ts +0 -1
- package/src/PieChart/index.d.ts +0 -1
|
@@ -17,7 +17,7 @@ export interface ChartData<TProps extends object = object> {
|
|
|
17
17
|
/**
|
|
18
18
|
* The color to use in the chart and legends for this item
|
|
19
19
|
*/
|
|
20
|
-
color
|
|
20
|
+
color?: string;
|
|
21
21
|
/**
|
|
22
22
|
* If selected, it'll be highlighted
|
|
23
23
|
*/
|
|
@@ -27,7 +27,7 @@ export interface ChartData<TProps extends object = object> {
|
|
|
27
27
|
*/
|
|
28
28
|
original?: TProps;
|
|
29
29
|
}
|
|
30
|
-
export interface
|
|
30
|
+
export interface DonutChartProps<TProps extends object> extends CommonProps {
|
|
31
31
|
/**
|
|
32
32
|
* Array of data points to show
|
|
33
33
|
*/
|
|
@@ -44,12 +44,30 @@ export interface PieChartProps<TProps extends object> extends CommonProps {
|
|
|
44
44
|
* When compact, the chart is smaller and legends are hidden.
|
|
45
45
|
*/
|
|
46
46
|
size?: Size;
|
|
47
|
+
/**
|
|
48
|
+
* The position of the legend. Defaults to "Right"
|
|
49
|
+
*/
|
|
50
|
+
legendPosition?: "Right" | "Bottom";
|
|
51
|
+
/**
|
|
52
|
+
* Maximum number of data points to show in the chart.
|
|
53
|
+
* The remaining will be grouped into a catogory called "others".
|
|
54
|
+
*
|
|
55
|
+
* @default 6
|
|
56
|
+
*/
|
|
57
|
+
maxDataPoints?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Show the "others" category in the chart, if it's available.
|
|
60
|
+
* Setting this to false, will not hide it in the legend.
|
|
61
|
+
*
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
showOthers?: boolean;
|
|
47
65
|
}
|
|
48
66
|
/**
|
|
49
|
-
* Create a
|
|
67
|
+
* Create a DonutChart with legends based on our current Chart component
|
|
50
68
|
*
|
|
51
|
-
* @param {
|
|
69
|
+
* @param {DonutChartProps} props - The props for the Chart component
|
|
52
70
|
* @returns {ReactElement} Chart component
|
|
53
71
|
*/
|
|
54
|
-
export declare const
|
|
72
|
+
export declare const DonutChart: <TProps extends object>({ data, size, loading, onClick, className, dataTestId, legendPosition, maxDataPoints, showOthers, }: DonutChartProps<TProps>) => ReactElement;
|
|
55
73
|
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import type { ECElementEvent, ECharts, EChartsOption } from "echarts";
|
|
3
|
+
import { CSSProperties, ReactElement } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* https://echarts.apache.org/en/api.html#events
|
|
6
|
+
*/
|
|
7
|
+
export type EventName = "click" | "dblclick" | "mousewheel" | "mouseout" | "mouseover" | "mouseup" | "mousedown" | "mousemove" | "contextmenu" | "drag" | "dragstart" | "dragend" | "dragenter" | "dragleave" | "dragover" | "drop" | "brush" | "brushselected" | "brushend" | "globalout" | "datarangeselected" | "legendselectchanged" | "datazoom";
|
|
8
|
+
export interface EChartProps extends CommonProps {
|
|
9
|
+
/**
|
|
10
|
+
* Option values for EChart.
|
|
11
|
+
*/
|
|
12
|
+
option: EChartsOption;
|
|
13
|
+
/**
|
|
14
|
+
* CSS styles for the chart.
|
|
15
|
+
*/
|
|
16
|
+
style?: CSSProperties;
|
|
17
|
+
/**
|
|
18
|
+
* Called when the chart instance is ready.
|
|
19
|
+
*/
|
|
20
|
+
onChartReady?: (chart: ECharts) => void;
|
|
21
|
+
/**
|
|
22
|
+
* onClick event handler.
|
|
23
|
+
*/
|
|
24
|
+
onClick?: (event: ECElementEvent) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Event handlers for the chart.
|
|
27
|
+
*/
|
|
28
|
+
onEvents?: Partial<Record<EventName, (event: ECElementEvent) => void>>;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to merge with previous option.
|
|
31
|
+
*/
|
|
32
|
+
notMerge?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Type of renderer used. Either "svg" or "canvas".
|
|
35
|
+
* Default is "canvas" for better performance.
|
|
36
|
+
* Some components (like UtilizationMultiDayChart) require "svg" for specific rendering needs.
|
|
37
|
+
*/
|
|
38
|
+
renderer?: "svg" | "canvas";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A React wrapper for ECharts that handles initialization, events, and cleanup.
|
|
42
|
+
*/
|
|
43
|
+
export declare const EChart: ({ option, style, className, onChartReady, onClick, onEvents, notMerge, renderer, dataTestId, }: EChartProps) => ReactElement;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export interface LegendItemProps {
|
|
2
|
-
label
|
|
2
|
+
label: string;
|
|
3
|
+
count?: number;
|
|
3
4
|
selected?: boolean;
|
|
4
5
|
disabled?: boolean;
|
|
5
6
|
onClick?: () => void;
|
|
7
|
+
onMouseEnter?: () => void;
|
|
8
|
+
onMouseLeave?: () => void;
|
|
6
9
|
color: string;
|
|
7
10
|
className?: string;
|
|
8
11
|
dataTestId?: string;
|
|
@@ -13,4 +16,4 @@ export interface LegendItemProps {
|
|
|
13
16
|
* @param {LegendItem} props - The props for the LegendItem component
|
|
14
17
|
* @returns {ReactElement} LegendItem component
|
|
15
18
|
*/
|
|
16
|
-
export declare const LegendItem: ({ className, label, disabled, selected, onClick, color, dataTestId }: LegendItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare const LegendItem: ({ className, count, label, disabled, selected, onClick, color, dataTestId, onMouseEnter, onMouseLeave, }: LegendItemProps) => import("react/jsx-runtime").JSX.Element;
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from "./Chart";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./Chart/Chart";
|
|
2
|
+
export * from "./DonutChart/DonutChart";
|
|
3
|
+
export * from "./LegendItem/LegendItem";
|
|
4
|
+
export * from "./utils/useChartColor";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChartStatus } from "@trackunit/ui-design-tokens";
|
|
2
|
+
/**
|
|
3
|
+
* Re-ordered chart colors to ensure that adjacent colors are visually different.
|
|
4
|
+
*
|
|
5
|
+
* @returns {string[]} The reordered chart colors.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useChartColor: () => {
|
|
8
|
+
chartColor: (index: number) => string;
|
|
9
|
+
chartColorArray: (total: number) => string[];
|
|
10
|
+
chartStatusColor: (status: ChartStatus) => string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ChartData } from "../DonutChart/DonutChart";
|
|
2
|
+
type LimitDataSetReturn<TProps extends object> = {
|
|
3
|
+
limitedData: ChartData<TProps & {
|
|
4
|
+
defaultOther?: boolean;
|
|
5
|
+
}>[];
|
|
6
|
+
limitedDataWithoutOthers: ChartData<TProps>[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Limits the data set to the given limit.
|
|
10
|
+
* If the data set is larger than the limit, the data set is limited to the limit and the rest of the data is added to the "Others" group.
|
|
11
|
+
*
|
|
12
|
+
* @param data - The data set to limit.
|
|
13
|
+
* @param limit - The limit to apply to the data set.
|
|
14
|
+
* @returns {object} The limited data set with and without the "others" category.
|
|
15
|
+
*/
|
|
16
|
+
export declare const useLimitDataSet: <TProps extends object>(data: ChartData<TProps>[], limit: number) => LimitDataSetReturn<TProps>;
|
|
17
|
+
export {};
|
package/src/Chart/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./Chart";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./LegendItem";
|
package/src/PieChart/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./PieChart";
|