@trackunit/react-chart-components 2.10.16 → 2.12.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/index.cjs.js +5 -4
- package/index.esm.js +6 -5
- package/package.json +7 -7
- package/src/EChart/EChart.d.ts +3 -3
- package/src/LegendItem/LegendItem.d.ts +3 -5
package/index.cjs.js
CHANGED
|
@@ -41,8 +41,9 @@ function isECElementEvent(value) {
|
|
|
41
41
|
/**
|
|
42
42
|
* A React wrapper for ECharts that handles initialization, events, and cleanup.
|
|
43
43
|
*/
|
|
44
|
-
const EChart = ({ option, style, className, onChartReady, onClick, onEvents, notMerge = false, renderer = "canvas", "data-testid": dataTestId, }) => {
|
|
44
|
+
const EChart = ({ option, style, className, onChartReady, onClick, onEvents, notMerge = false, renderer = "canvas", "data-testid": dataTestId, ref, }) => {
|
|
45
45
|
const containerRef = react.useRef(null);
|
|
46
|
+
const mergedRef = reactComponents.useMergeRefs([containerRef, ref]);
|
|
46
47
|
const internalChartRef = react.useRef(undefined);
|
|
47
48
|
const isInitialRender = react.useRef(true);
|
|
48
49
|
const setupEventHandlers = react.useCallback((chart) => {
|
|
@@ -172,7 +173,7 @@ const EChart = ({ option, style, className, onChartReady, onClick, onEvents, not
|
|
|
172
173
|
isInitialRender.current = false;
|
|
173
174
|
}
|
|
174
175
|
}, [option, notMerge]);
|
|
175
|
-
return jsxRuntime.jsx("div", { className: cvaEChart({ className }), "data-testid": dataTestId, ref:
|
|
176
|
+
return jsxRuntime.jsx("div", { className: cvaEChart({ className }), "data-testid": dataTestId, ref: mergedRef, style: style });
|
|
176
177
|
};
|
|
177
178
|
const cvaEChart = cssClassVarianceUtilities.cva({ base: ["w-full", "h-full"] });
|
|
178
179
|
|
|
@@ -300,7 +301,7 @@ const LegendItemSwatch = ({ color, dataTestId, indicator, symbol }) => {
|
|
|
300
301
|
* @param {LegendItem} props - The props for the LegendItem component
|
|
301
302
|
* @returns {ReactElement} LegendItem component
|
|
302
303
|
*/
|
|
303
|
-
const LegendItem = ({ className, style, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, ...indicatorProps }) => {
|
|
304
|
+
const LegendItem = ({ className, style, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, ref, ...indicatorProps }) => {
|
|
304
305
|
const handleOnClick = onClick && !disabled ? e => onClick(e) : undefined;
|
|
305
306
|
const handleOnKeyDown = handleOnClick
|
|
306
307
|
? event => {
|
|
@@ -313,7 +314,7 @@ const LegendItem = ({ className, style, count, label, disabled = false, selected
|
|
|
313
314
|
const indicator = indicatorProps.indicator ?? "fill";
|
|
314
315
|
const symbol = indicatorProps.indicator === "solid line" ? (indicatorProps.symbol ?? "emptyCircle") : "none";
|
|
315
316
|
const isSwitch = handleOnClick !== undefined;
|
|
316
|
-
return (jsxRuntime.jsxs("div", { "aria-checked": isSwitch ? selected : undefined, className: cvaLegendItem({ disabled, selected, isClickable: isSwitch, className }), "data-testid": dataTestId, onClick: handleOnClick, onKeyDown: handleOnKeyDown, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, role: isSwitch ? "switch" : undefined, style: style, tabIndex: isSwitch ? 0 : undefined, children: [jsxRuntime.jsx(LegendItemSwatch, { color: color, dataTestId: dataTestId, indicator: indicator, symbol: symbol }), jsxRuntime.jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : jsxRuntime.jsx("p", { className: "text-xs", children: `(${count ?? 0}${unit ?? ""})` })] }));
|
|
317
|
+
return (jsxRuntime.jsxs("div", { "aria-checked": isSwitch ? selected : undefined, className: cvaLegendItem({ disabled, selected, isClickable: isSwitch, className }), "data-testid": dataTestId, onClick: handleOnClick, onKeyDown: handleOnKeyDown, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, ref: ref, role: isSwitch ? "switch" : undefined, style: style, tabIndex: isSwitch ? 0 : undefined, children: [jsxRuntime.jsx(LegendItemSwatch, { color: color, dataTestId: dataTestId, indicator: indicator, symbol: symbol }), jsxRuntime.jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : jsxRuntime.jsx("p", { className: "text-xs", children: `(${count ?? 0}${unit ?? ""})` })] }));
|
|
317
318
|
};
|
|
318
319
|
|
|
319
320
|
/**
|
package/index.esm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { toDateUtil } from '@trackunit/date-and-time-utils';
|
|
|
4
4
|
import { useLocale, useDateAndTime } from '@trackunit/react-date-and-time-hooks';
|
|
5
5
|
import { DEFAULT_CHART_COLORS, CHART_STATUS_COLORS, fontFamily, DEFAULT_CHART_OTHER } from '@trackunit/ui-design-tokens';
|
|
6
6
|
import { useRef, useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
|
-
import { Spinner, Text
|
|
7
|
+
import { useMergeRefs, Spinner, Text } from '@trackunit/react-components';
|
|
8
8
|
import { objectKeys, exhaustiveCheck } from '@trackunit/shared-utils';
|
|
9
9
|
import * as echarts from 'echarts';
|
|
10
10
|
|
|
@@ -20,8 +20,9 @@ function isECElementEvent(value) {
|
|
|
20
20
|
/**
|
|
21
21
|
* A React wrapper for ECharts that handles initialization, events, and cleanup.
|
|
22
22
|
*/
|
|
23
|
-
const EChart = ({ option, style, className, onChartReady, onClick, onEvents, notMerge = false, renderer = "canvas", "data-testid": dataTestId, }) => {
|
|
23
|
+
const EChart = ({ option, style, className, onChartReady, onClick, onEvents, notMerge = false, renderer = "canvas", "data-testid": dataTestId, ref, }) => {
|
|
24
24
|
const containerRef = useRef(null);
|
|
25
|
+
const mergedRef = useMergeRefs([containerRef, ref]);
|
|
25
26
|
const internalChartRef = useRef(undefined);
|
|
26
27
|
const isInitialRender = useRef(true);
|
|
27
28
|
const setupEventHandlers = useCallback((chart) => {
|
|
@@ -151,7 +152,7 @@ const EChart = ({ option, style, className, onChartReady, onClick, onEvents, not
|
|
|
151
152
|
isInitialRender.current = false;
|
|
152
153
|
}
|
|
153
154
|
}, [option, notMerge]);
|
|
154
|
-
return jsx("div", { className: cvaEChart({ className }), "data-testid": dataTestId, ref:
|
|
155
|
+
return jsx("div", { className: cvaEChart({ className }), "data-testid": dataTestId, ref: mergedRef, style: style });
|
|
155
156
|
};
|
|
156
157
|
const cvaEChart = cva({ base: ["w-full", "h-full"] });
|
|
157
158
|
|
|
@@ -279,7 +280,7 @@ const LegendItemSwatch = ({ color, dataTestId, indicator, symbol }) => {
|
|
|
279
280
|
* @param {LegendItem} props - The props for the LegendItem component
|
|
280
281
|
* @returns {ReactElement} LegendItem component
|
|
281
282
|
*/
|
|
282
|
-
const LegendItem = ({ className, style, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, ...indicatorProps }) => {
|
|
283
|
+
const LegendItem = ({ className, style, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, ref, ...indicatorProps }) => {
|
|
283
284
|
const handleOnClick = onClick && !disabled ? e => onClick(e) : undefined;
|
|
284
285
|
const handleOnKeyDown = handleOnClick
|
|
285
286
|
? event => {
|
|
@@ -292,7 +293,7 @@ const LegendItem = ({ className, style, count, label, disabled = false, selected
|
|
|
292
293
|
const indicator = indicatorProps.indicator ?? "fill";
|
|
293
294
|
const symbol = indicatorProps.indicator === "solid line" ? (indicatorProps.symbol ?? "emptyCircle") : "none";
|
|
294
295
|
const isSwitch = handleOnClick !== undefined;
|
|
295
|
-
return (jsxs("div", { "aria-checked": isSwitch ? selected : undefined, className: cvaLegendItem({ disabled, selected, isClickable: isSwitch, className }), "data-testid": dataTestId, onClick: handleOnClick, onKeyDown: handleOnKeyDown, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, role: isSwitch ? "switch" : undefined, style: style, tabIndex: isSwitch ? 0 : undefined, children: [jsx(LegendItemSwatch, { color: color, dataTestId: dataTestId, indicator: indicator, symbol: symbol }), jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : jsx("p", { className: "text-xs", children: `(${count ?? 0}${unit ?? ""})` })] }));
|
|
296
|
+
return (jsxs("div", { "aria-checked": isSwitch ? selected : undefined, className: cvaLegendItem({ disabled, selected, isClickable: isSwitch, className }), "data-testid": dataTestId, onClick: handleOnClick, onKeyDown: handleOnKeyDown, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, ref: ref, role: isSwitch ? "switch" : undefined, style: style, tabIndex: isSwitch ? 0 : undefined, children: [jsx(LegendItemSwatch, { color: color, dataTestId: dataTestId, indicator: indicator, symbol: symbol }), jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : jsx("p", { className: "text-xs", children: `(${count ?? 0}${unit ?? ""})` })] }));
|
|
296
297
|
};
|
|
297
298
|
|
|
298
299
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-chart-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"migrations": "./migrations.json",
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"echarts": "5.6.0",
|
|
12
|
-
"@trackunit/date-and-time-utils": "1.
|
|
13
|
-
"@trackunit/react-date-and-time-hooks": "2.
|
|
14
|
-
"@trackunit/ui-design-tokens": "1.
|
|
15
|
-
"@trackunit/shared-utils": "1.
|
|
16
|
-
"@trackunit/css-class-variance-utilities": "2.
|
|
17
|
-
"@trackunit/react-components": "3.
|
|
12
|
+
"@trackunit/date-and-time-utils": "1.19.0",
|
|
13
|
+
"@trackunit/react-date-and-time-hooks": "2.12.0",
|
|
14
|
+
"@trackunit/ui-design-tokens": "1.20.0",
|
|
15
|
+
"@trackunit/shared-utils": "1.21.0",
|
|
16
|
+
"@trackunit/css-class-variance-utilities": "2.5.0",
|
|
17
|
+
"@trackunit/react-components": "3.10.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@apollo/client": "^3.13.8",
|
package/src/EChart/EChart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonProps, type Styleable } from "@trackunit/react-components";
|
|
1
|
+
import { CommonProps, Refable, type Styleable } from "@trackunit/react-components";
|
|
2
2
|
import type { ECElementEvent, ECharts, EChartsOption } from "echarts";
|
|
3
3
|
import { ReactElement } from "react";
|
|
4
4
|
/**
|
|
@@ -15,7 +15,7 @@ export type BrushEvent = {
|
|
|
15
15
|
areas: Array<BrushArea>;
|
|
16
16
|
};
|
|
17
17
|
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";
|
|
18
|
-
export interface EChartProps extends CommonProps, Styleable {
|
|
18
|
+
export interface EChartProps extends CommonProps, Styleable, Refable<HTMLDivElement> {
|
|
19
19
|
/**
|
|
20
20
|
* Option values for EChart.
|
|
21
21
|
*/
|
|
@@ -49,4 +49,4 @@ export interface EChartProps extends CommonProps, Styleable {
|
|
|
49
49
|
/**
|
|
50
50
|
* A React wrapper for ECharts that handles initialization, events, and cleanup.
|
|
51
51
|
*/
|
|
52
|
-
export declare const EChart: ({ option, style, className, onChartReady, onClick, onEvents, notMerge, renderer, "data-testid": dataTestId, }: EChartProps) => ReactElement;
|
|
52
|
+
export declare const EChart: ({ option, style, className, onChartReady, onClick, onEvents, notMerge, renderer, "data-testid": dataTestId, ref, }: EChartProps) => ReactElement;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Refable, type Styleable } from "@trackunit/react-components";
|
|
1
|
+
import { CommonProps, Refable, type Styleable } from "@trackunit/react-components";
|
|
2
2
|
import { MouseEventHandler, ReactElement } from "react";
|
|
3
3
|
/**
|
|
4
4
|
* Shape of the colour indicator. `fill` is a solid circle for a block of colour. `solid line` is a
|
|
@@ -11,7 +11,7 @@ export type LegendItemIndicator = "fill" | "solid line" | "dashed line";
|
|
|
11
11
|
* the reader should follow the trend rather than each sample. Dashed lines cannot take a symbol.
|
|
12
12
|
*/
|
|
13
13
|
export type LegendItemSymbol = "none" | "emptyCircle";
|
|
14
|
-
interface LegendItemBaseProps extends Refable<HTMLDivElement>, Styleable {
|
|
14
|
+
interface LegendItemBaseProps extends CommonProps, Refable<HTMLDivElement>, Styleable {
|
|
15
15
|
label: string;
|
|
16
16
|
count?: number;
|
|
17
17
|
selected?: boolean;
|
|
@@ -20,8 +20,6 @@ interface LegendItemBaseProps extends Refable<HTMLDivElement>, Styleable {
|
|
|
20
20
|
onMouseEnter?: () => void;
|
|
21
21
|
onMouseLeave?: () => void;
|
|
22
22
|
color: string;
|
|
23
|
-
className?: string;
|
|
24
|
-
"data-testid"?: string;
|
|
25
23
|
unit?: "%";
|
|
26
24
|
hideValue?: boolean;
|
|
27
25
|
}
|
|
@@ -71,5 +69,5 @@ export type LegendItemProps = LegendItemFillProps | LegendItemSolidLineProps | L
|
|
|
71
69
|
* @param {LegendItem} props - The props for the LegendItem component
|
|
72
70
|
* @returns {ReactElement} LegendItem component
|
|
73
71
|
*/
|
|
74
|
-
export declare const LegendItem: ({ className, style, count, label, disabled, selected, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit, hideValue, ...indicatorProps }: LegendItemProps) => ReactElement;
|
|
72
|
+
export declare const LegendItem: ({ className, style, count, label, disabled, selected, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit, hideValue, ref, ...indicatorProps }: LegendItemProps) => ReactElement;
|
|
75
73
|
export {};
|