@trackunit/react-chart-components 1.13.22 → 1.13.25
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
CHANGED
|
@@ -220,13 +220,13 @@ const cvaEChart = cssClassVarianceUtilities.cvaMerge(["w-full", "h-full"]);
|
|
|
220
220
|
* );
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
|
-
const Chart = ({ options, showLoading = false, className, style, onChartReady, onClick, onEvents, merge = true, loadingOption, timezoneLabel, renderer = "canvas", "data-testid": dataTestId, }) => {
|
|
223
|
+
const Chart = ({ options, showLoading = false, className, style, onChartReady, onClick, onEvents, merge = true, loadingOption, timezoneLabel, renderer = "canvas", "data-testid": dataTestId, ref, }) => {
|
|
224
224
|
const containerStyle = {
|
|
225
225
|
height: style?.height ?? "300px",
|
|
226
226
|
width: style?.width ?? "100%",
|
|
227
227
|
...style,
|
|
228
228
|
};
|
|
229
|
-
return (jsxRuntime.jsx("div", { className: "grid h-full w-full grid-cols-1 grid-rows-1 items-center gap-1", "data-testid": dataTestId, style: containerStyle, children: showLoading ? (jsxRuntime.jsxs("div", { className: "grid place-items-center overflow-y-auto", "data-testid": `${dataTestId}-loading`, children: [jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered" }), loadingOption?.text ? (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, children: loadingOption.text })) : null] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(EChart, { className: className, "data-testid": `${dataTestId}-chart`, notMerge: !merge, onChartReady: onChartReady, onClick: onClick, onEvents: onEvents, option: options, renderer: renderer, style: style }), timezoneLabel] })) }));
|
|
229
|
+
return (jsxRuntime.jsx("div", { className: "grid h-full w-full grid-cols-1 grid-rows-1 items-center gap-1", "data-testid": dataTestId, ref: ref, style: containerStyle, children: showLoading ? (jsxRuntime.jsxs("div", { className: "grid place-items-center overflow-y-auto", "data-testid": `${dataTestId}-loading`, children: [jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered" }), loadingOption?.text ? (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, children: loadingOption.text })) : null] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(EChart, { className: className, "data-testid": `${dataTestId}-chart`, notMerge: !merge, onChartReady: onChartReady, onClick: onClick, onEvents: onEvents, option: options, renderer: renderer, style: style }), timezoneLabel] })) }));
|
|
230
230
|
};
|
|
231
231
|
|
|
232
232
|
const cvaLegendItem = cssClassVarianceUtilities.cvaMerge([
|
|
@@ -381,8 +381,9 @@ const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
|
|
|
381
381
|
* @param {DonutChartProps} props - The props for the Chart component
|
|
382
382
|
* @returns {ReactElement} Chart component
|
|
383
383
|
*/
|
|
384
|
-
const DonutChart = ({ data, size = "full", loading = false, onClick, className, "data-testid": dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, }) => {
|
|
384
|
+
const DonutChart = ({ data, size = "full", loading = false, onClick, className, "data-testid": dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, ref, }) => {
|
|
385
385
|
const containerRef = react.useRef(null);
|
|
386
|
+
const mergedRef = reactComponents.useMergeRefs([containerRef, ref]);
|
|
386
387
|
const chartRef = react.useRef(null);
|
|
387
388
|
const totalValue = react.useMemo(() => overrideTotal ?? data?.map(item => item.value ?? 0).reduce((a, b) => a + b, 0) ?? 0, [data, overrideTotal]);
|
|
388
389
|
const [isHovering, setIsHovering] = react.useState(false);
|
|
@@ -507,7 +508,7 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
|
|
|
507
508
|
if (loading) {
|
|
508
509
|
return jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", "data-testid": dataTestId ? `${dataTestId}-loading` : "donut-chart-loading" });
|
|
509
510
|
}
|
|
510
|
-
return (jsxRuntime.jsxs("div", { className: cvaChartRoot$1({ className }), "data-testid": dataTestId, ref:
|
|
511
|
+
return (jsxRuntime.jsxs("div", { className: cvaChartRoot$1({ className }), "data-testid": dataTestId, ref: mergedRef, children: [jsxRuntime.jsx("div", { className: cvaChartContainer(), children: jsxRuntime.jsx(Chart, { className: cvaChart({ size }), "data-testid": dataTestId ? `chart-${dataTestId}` : undefined, onChartReady: handleChartReady, onClick: handleChartClick, onEvents: handleChartEvents, options: chartOptions, style: { width: "100%", height: "100%" } }) }), size === "full" && (jsxRuntime.jsx("div", { className: cvaLegend(), "data-testid": "legend", children: limitedData.map((item, index) => (jsxRuntime.jsx(LegendItem, { className: "p-1.5 py-0.5", color: item.color ?? chartColor(index), count: item.value, "data-testid": `legend-${item.id}`, disabled: (item.value ?? 0) === 0, hideValue: hideLegendValues, label: item.name, onClick: onClick ? () => onClick(item) : undefined, onMouseEnter: () => handleLegendMouseEnter(item), onMouseLeave: handleLegendMouseLeave, selected: item.selected, unit: unit }, item.id))) }))] }));
|
|
511
512
|
};
|
|
512
513
|
const cvaChartRoot$1 = cssClassVarianceUtilities.cvaMerge([
|
|
513
514
|
"flex",
|
|
@@ -578,7 +579,7 @@ const cvaLegend = cssClassVarianceUtilities.cvaMerge(["flex", "overflow-auto", "
|
|
|
578
579
|
* @param {BarChartProps} props - The props for the Chart component
|
|
579
580
|
* @returns {ReactElement} Chart component
|
|
580
581
|
*/
|
|
581
|
-
const BarChart = ({ series, loading = false, onClick, className, "data-testid": dataTestId, units, showDataZoom = false, }) => {
|
|
582
|
+
const BarChart = ({ series, loading = false, onClick, className, "data-testid": dataTestId, units, showDataZoom = false, ref, }) => {
|
|
582
583
|
const { formatDate } = reactDateAndTimeHooks.useDateAndTime();
|
|
583
584
|
const { chartColor } = useChartColor();
|
|
584
585
|
const seriesData = react.useMemo(() => {
|
|
@@ -595,7 +596,7 @@ const BarChart = ({ series, loading = false, onClick, className, "data-testid":
|
|
|
595
596
|
}));
|
|
596
597
|
}, [series, chartColor]);
|
|
597
598
|
const isDateData = (data) => !!data && "date" in data;
|
|
598
|
-
return (jsxRuntime.jsxs("div", { className: cvaChartRoot({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsx("div", { className: "flex-0 flex flex-row gap-2 place-self-end pr-8", "data-testid": "legend", children: seriesData.map((item, index) => (jsxRuntime.jsx(LegendItem, { color: item.color || chartColor(index), "data-testid": `legend-${item.name}`, label: item.name }, item.name))) }), jsxRuntime.jsx("div", { className: "flex min-h-[260px] w-full flex-1", children: jsxRuntime.jsx(Chart, { "data-testid": "bar-chart", onClick: onClick
|
|
599
|
+
return (jsxRuntime.jsxs("div", { className: cvaChartRoot({ className }), "data-testid": dataTestId, ref: ref, children: [jsxRuntime.jsx("div", { className: "flex-0 flex flex-row gap-2 place-self-end pr-8", "data-testid": "legend", children: seriesData.map((item, index) => (jsxRuntime.jsx(LegendItem, { color: item.color || chartColor(index), "data-testid": `legend-${item.name}`, label: item.name }, item.name))) }), jsxRuntime.jsx("div", { className: "flex min-h-[260px] w-full flex-1", children: jsxRuntime.jsx(Chart, { "data-testid": "bar-chart", onClick: onClick
|
|
599
600
|
? (e) => {
|
|
600
601
|
onClick(e);
|
|
601
602
|
}
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Spinner, Text } from '@trackunit/react-components';
|
|
2
|
+
import { Spinner, Text, useMergeRefs } from '@trackunit/react-components';
|
|
3
3
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
4
4
|
import { objectKeys } from '@trackunit/shared-utils';
|
|
5
5
|
import * as echarts from 'echarts';
|
|
@@ -199,13 +199,13 @@ const cvaEChart = cvaMerge(["w-full", "h-full"]);
|
|
|
199
199
|
* );
|
|
200
200
|
* ```
|
|
201
201
|
*/
|
|
202
|
-
const Chart = ({ options, showLoading = false, className, style, onChartReady, onClick, onEvents, merge = true, loadingOption, timezoneLabel, renderer = "canvas", "data-testid": dataTestId, }) => {
|
|
202
|
+
const Chart = ({ options, showLoading = false, className, style, onChartReady, onClick, onEvents, merge = true, loadingOption, timezoneLabel, renderer = "canvas", "data-testid": dataTestId, ref, }) => {
|
|
203
203
|
const containerStyle = {
|
|
204
204
|
height: style?.height ?? "300px",
|
|
205
205
|
width: style?.width ?? "100%",
|
|
206
206
|
...style,
|
|
207
207
|
};
|
|
208
|
-
return (jsx("div", { className: "grid h-full w-full grid-cols-1 grid-rows-1 items-center gap-1", "data-testid": dataTestId, style: containerStyle, children: showLoading ? (jsxs("div", { className: "grid place-items-center overflow-y-auto", "data-testid": `${dataTestId}-loading`, children: [jsx(Spinner, { centering: "centered" }), loadingOption?.text ? (jsx(Text, { align: "center", subtle: true, children: loadingOption.text })) : null] })) : (jsxs(Fragment, { children: [jsx(EChart, { className: className, "data-testid": `${dataTestId}-chart`, notMerge: !merge, onChartReady: onChartReady, onClick: onClick, onEvents: onEvents, option: options, renderer: renderer, style: style }), timezoneLabel] })) }));
|
|
208
|
+
return (jsx("div", { className: "grid h-full w-full grid-cols-1 grid-rows-1 items-center gap-1", "data-testid": dataTestId, ref: ref, style: containerStyle, children: showLoading ? (jsxs("div", { className: "grid place-items-center overflow-y-auto", "data-testid": `${dataTestId}-loading`, children: [jsx(Spinner, { centering: "centered" }), loadingOption?.text ? (jsx(Text, { align: "center", subtle: true, children: loadingOption.text })) : null] })) : (jsxs(Fragment, { children: [jsx(EChart, { className: className, "data-testid": `${dataTestId}-chart`, notMerge: !merge, onChartReady: onChartReady, onClick: onClick, onEvents: onEvents, option: options, renderer: renderer, style: style }), timezoneLabel] })) }));
|
|
209
209
|
};
|
|
210
210
|
|
|
211
211
|
const cvaLegendItem = cvaMerge([
|
|
@@ -360,8 +360,9 @@ const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
|
|
|
360
360
|
* @param {DonutChartProps} props - The props for the Chart component
|
|
361
361
|
* @returns {ReactElement} Chart component
|
|
362
362
|
*/
|
|
363
|
-
const DonutChart = ({ data, size = "full", loading = false, onClick, className, "data-testid": dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, }) => {
|
|
363
|
+
const DonutChart = ({ data, size = "full", loading = false, onClick, className, "data-testid": dataTestId, maxDataPoints = 6, showOthers = true, unit, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, ref, }) => {
|
|
364
364
|
const containerRef = useRef(null);
|
|
365
|
+
const mergedRef = useMergeRefs([containerRef, ref]);
|
|
365
366
|
const chartRef = useRef(null);
|
|
366
367
|
const totalValue = useMemo(() => overrideTotal ?? data?.map(item => item.value ?? 0).reduce((a, b) => a + b, 0) ?? 0, [data, overrideTotal]);
|
|
367
368
|
const [isHovering, setIsHovering] = useState(false);
|
|
@@ -486,7 +487,7 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
|
|
|
486
487
|
if (loading) {
|
|
487
488
|
return jsx(Spinner, { centering: "centered", "data-testid": dataTestId ? `${dataTestId}-loading` : "donut-chart-loading" });
|
|
488
489
|
}
|
|
489
|
-
return (jsxs("div", { className: cvaChartRoot$1({ className }), "data-testid": dataTestId, ref:
|
|
490
|
+
return (jsxs("div", { className: cvaChartRoot$1({ className }), "data-testid": dataTestId, ref: mergedRef, children: [jsx("div", { className: cvaChartContainer(), children: jsx(Chart, { className: cvaChart({ size }), "data-testid": dataTestId ? `chart-${dataTestId}` : undefined, onChartReady: handleChartReady, onClick: handleChartClick, onEvents: handleChartEvents, options: chartOptions, style: { width: "100%", height: "100%" } }) }), size === "full" && (jsx("div", { className: cvaLegend(), "data-testid": "legend", children: limitedData.map((item, index) => (jsx(LegendItem, { className: "p-1.5 py-0.5", color: item.color ?? chartColor(index), count: item.value, "data-testid": `legend-${item.id}`, disabled: (item.value ?? 0) === 0, hideValue: hideLegendValues, label: item.name, onClick: onClick ? () => onClick(item) : undefined, onMouseEnter: () => handleLegendMouseEnter(item), onMouseLeave: handleLegendMouseLeave, selected: item.selected, unit: unit }, item.id))) }))] }));
|
|
490
491
|
};
|
|
491
492
|
const cvaChartRoot$1 = cvaMerge([
|
|
492
493
|
"flex",
|
|
@@ -557,7 +558,7 @@ const cvaLegend = cvaMerge(["flex", "overflow-auto", "justify-start", "flex-col"
|
|
|
557
558
|
* @param {BarChartProps} props - The props for the Chart component
|
|
558
559
|
* @returns {ReactElement} Chart component
|
|
559
560
|
*/
|
|
560
|
-
const BarChart = ({ series, loading = false, onClick, className, "data-testid": dataTestId, units, showDataZoom = false, }) => {
|
|
561
|
+
const BarChart = ({ series, loading = false, onClick, className, "data-testid": dataTestId, units, showDataZoom = false, ref, }) => {
|
|
561
562
|
const { formatDate } = useDateAndTime();
|
|
562
563
|
const { chartColor } = useChartColor();
|
|
563
564
|
const seriesData = useMemo(() => {
|
|
@@ -574,7 +575,7 @@ const BarChart = ({ series, loading = false, onClick, className, "data-testid":
|
|
|
574
575
|
}));
|
|
575
576
|
}, [series, chartColor]);
|
|
576
577
|
const isDateData = (data) => !!data && "date" in data;
|
|
577
|
-
return (jsxs("div", { className: cvaChartRoot({ className }), "data-testid": dataTestId, children: [jsx("div", { className: "flex-0 flex flex-row gap-2 place-self-end pr-8", "data-testid": "legend", children: seriesData.map((item, index) => (jsx(LegendItem, { color: item.color || chartColor(index), "data-testid": `legend-${item.name}`, label: item.name }, item.name))) }), jsx("div", { className: "flex min-h-[260px] w-full flex-1", children: jsx(Chart, { "data-testid": "bar-chart", onClick: onClick
|
|
578
|
+
return (jsxs("div", { className: cvaChartRoot({ className }), "data-testid": dataTestId, ref: ref, children: [jsx("div", { className: "flex-0 flex flex-row gap-2 place-self-end pr-8", "data-testid": "legend", children: seriesData.map((item, index) => (jsx(LegendItem, { color: item.color || chartColor(index), "data-testid": `legend-${item.name}`, label: item.name }, item.name))) }), jsx("div", { className: "flex min-h-[260px] w-full flex-1", children: jsx(Chart, { "data-testid": "bar-chart", onClick: onClick
|
|
578
579
|
? (e) => {
|
|
579
580
|
onClick(e);
|
|
580
581
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-chart-components",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.25",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"echarts": "5.6.0",
|
|
11
11
|
"react": "19.0.0",
|
|
12
|
-
"@trackunit/date-and-time-utils": "1.11.
|
|
13
|
-
"@trackunit/react-date-and-time-hooks": "1.13.
|
|
14
|
-
"@trackunit/ui-design-tokens": "1.11.
|
|
15
|
-
"@trackunit/shared-utils": "1.13.
|
|
16
|
-
"@trackunit/css-class-variance-utilities": "1.11.
|
|
17
|
-
"@trackunit/react-components": "1.17.
|
|
12
|
+
"@trackunit/date-and-time-utils": "1.11.44",
|
|
13
|
+
"@trackunit/react-date-and-time-hooks": "1.13.25",
|
|
14
|
+
"@trackunit/ui-design-tokens": "1.11.43",
|
|
15
|
+
"@trackunit/shared-utils": "1.13.43",
|
|
16
|
+
"@trackunit/css-class-variance-utilities": "1.11.43",
|
|
17
|
+
"@trackunit/react-components": "1.17.20"
|
|
18
18
|
},
|
|
19
19
|
"module": "./index.esm.js",
|
|
20
20
|
"main": "./index.cjs.js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonProps } from "@trackunit/react-components";
|
|
1
|
+
import { CommonProps, Refable } from "@trackunit/react-components";
|
|
2
2
|
import { ECElementEvent } from "echarts";
|
|
3
3
|
import { ReactElement } from "react";
|
|
4
4
|
export interface BarChartData<TProps extends object = object> {
|
|
@@ -32,7 +32,7 @@ export interface SeriesData<TProps extends object> {
|
|
|
32
32
|
color?: string;
|
|
33
33
|
data: Array<BarChartGenericData<TProps>> | Array<BarChartDateData<TProps>>;
|
|
34
34
|
}
|
|
35
|
-
export interface BarChartProps<TProps extends object> extends CommonProps {
|
|
35
|
+
export interface BarChartProps<TProps extends object> extends CommonProps, Refable<HTMLDivElement> {
|
|
36
36
|
/**
|
|
37
37
|
* Array of series of data points to show
|
|
38
38
|
*/
|
|
@@ -100,4 +100,4 @@ export interface BarChartProps<TProps extends object> extends CommonProps {
|
|
|
100
100
|
* @param {BarChartProps} props - The props for the Chart component
|
|
101
101
|
* @returns {ReactElement} Chart component
|
|
102
102
|
*/
|
|
103
|
-
export declare const BarChart: <TProps extends object>({ series, loading, onClick, className, "data-testid": dataTestId, units, showDataZoom, }: BarChartProps<TProps>) => ReactElement;
|
|
103
|
+
export declare const BarChart: <TProps extends object>({ series, loading, onClick, className, "data-testid": dataTestId, units, showDataZoom, ref, }: BarChartProps<TProps>) => ReactElement;
|
package/src/Chart/Chart.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommonProps } from "@trackunit/react-components";
|
|
1
|
+
import { CommonProps, Refable } from "@trackunit/react-components";
|
|
2
2
|
import type { ECElementEvent, ECharts, EChartsOption } from "echarts";
|
|
3
3
|
import { CSSProperties, ReactElement, ReactNode } from "react";
|
|
4
4
|
import { BrushEvent, type EventName } from "../EChart/EChart";
|
|
5
|
-
export type ChartProps = CommonProps & {
|
|
5
|
+
export type ChartProps = CommonProps & Refable<HTMLDivElement> & {
|
|
6
6
|
/**
|
|
7
7
|
* Option values for EChart.
|
|
8
8
|
*/
|
|
@@ -102,4 +102,4 @@ export type ChartProps = CommonProps & {
|
|
|
102
102
|
* );
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
|
-
export declare const Chart: ({ options, showLoading, className, style, onChartReady, onClick, onEvents, merge, loadingOption, timezoneLabel, renderer, "data-testid": dataTestId, }: ChartProps) => ReactElement;
|
|
105
|
+
export declare const Chart: ({ options, showLoading, className, style, onChartReady, onClick, onEvents, merge, loadingOption, timezoneLabel, renderer, "data-testid": dataTestId, ref, }: ChartProps) => ReactElement;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonProps } from "@trackunit/react-components";
|
|
1
|
+
import { CommonProps, Refable } from "@trackunit/react-components";
|
|
2
2
|
import { ReactElement } from "react";
|
|
3
3
|
type Size = "compact" | "full";
|
|
4
4
|
export interface ChartData<TProps extends object = object> {
|
|
@@ -27,7 +27,7 @@ export interface ChartData<TProps extends object = object> {
|
|
|
27
27
|
*/
|
|
28
28
|
original?: TProps;
|
|
29
29
|
}
|
|
30
|
-
export interface DonutChartProps<TProps extends object> extends CommonProps {
|
|
30
|
+
export interface DonutChartProps<TProps extends object> extends CommonProps, Refable<HTMLDivElement> {
|
|
31
31
|
/**
|
|
32
32
|
* Array of data points to show
|
|
33
33
|
*/
|
|
@@ -137,5 +137,5 @@ export interface DonutChartProps<TProps extends object> extends CommonProps {
|
|
|
137
137
|
* @param {DonutChartProps} props - The props for the Chart component
|
|
138
138
|
* @returns {ReactElement} Chart component
|
|
139
139
|
*/
|
|
140
|
-
export declare const DonutChart: <TProps extends object>({ data, size, loading, onClick, className, "data-testid": dataTestId, maxDataPoints, showOthers, unit, overrideTotal, autoSortData, hideLegendValues, othersName, }: DonutChartProps<TProps>) => ReactElement;
|
|
140
|
+
export declare const DonutChart: <TProps extends object>({ data, size, loading, onClick, className, "data-testid": dataTestId, maxDataPoints, showOthers, unit, overrideTotal, autoSortData, hideLegendValues, othersName, ref, }: DonutChartProps<TProps>) => ReactElement;
|
|
141
141
|
export {};
|