@trackunit/react-chart-components 1.24.1 → 1.25.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 CHANGED
@@ -276,9 +276,9 @@ const cvaLegendItemIndicator = cssClassVarianceUtilities.cvaMerge(["w-3", "mr-1"
276
276
  * @param {LegendItem} props - The props for the LegendItem component
277
277
  * @returns {ReactElement} LegendItem component
278
278
  */
279
- const LegendItem = ({ className, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, }) => {
279
+ const LegendItem = ({ className, style, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, }) => {
280
280
  const handleOnClick = onClick && !disabled ? e => onClick(e) : undefined;
281
- return (jsxRuntime.jsxs("div", { className: cvaLegendItem({ disabled, selected, isClickable: !disabled && onClick !== undefined, className }), "data-testid": dataTestId, onClick: handleOnClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, children: [jsxRuntime.jsx("div", { className: cvaLegendItemIndicator({ selected }), "data-testid": dataTestId ? `${dataTestId}-indicator` : null, style: { backgroundColor: color } }), jsxRuntime.jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : (jsxRuntime.jsxs("p", { className: "text-xs", children: ["(", count ?? 0, ")", unit ?? ""] }))] }));
281
+ return (jsxRuntime.jsxs("div", { className: cvaLegendItem({ disabled, selected, isClickable: !disabled && onClick !== undefined, className }), "data-testid": dataTestId, onClick: handleOnClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, style: style, children: [jsxRuntime.jsx("div", { className: cvaLegendItemIndicator({ selected }), "data-testid": dataTestId ? `${dataTestId}-indicator` : null, style: { backgroundColor: color } }), jsxRuntime.jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : (jsxRuntime.jsxs("p", { className: "text-xs", children: ["(", count ?? 0, ")", unit ?? ""] }))] }));
282
282
  };
283
283
 
284
284
  /**
@@ -381,7 +381,7 @@ 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 = undefined, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, ref, }) => {
384
+ const DonutChart = ({ data, size = "full", loading = false, onClick, className, style, "data-testid": dataTestId, maxDataPoints = 6, showOthers = true, unit = undefined, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, ref, }) => {
385
385
  const containerRef = react.useRef(null);
386
386
  const mergedRef = reactComponents.useMergeRefs([containerRef, ref]);
387
387
  const chartRef = react.useRef(null);
@@ -508,7 +508,7 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
508
508
  if (loading) {
509
509
  return jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", "data-testid": dataTestId ? `${dataTestId}-loading` : "donut-chart-loading" });
510
510
  }
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
+ return (jsxRuntime.jsxs("div", { className: cvaChartRoot$1({ className }), "data-testid": dataTestId, ref: mergedRef, style: style, 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))) }))] }));
512
512
  };
513
513
  const cvaChartRoot$1 = cssClassVarianceUtilities.cvaMerge([
514
514
  "flex",
@@ -579,7 +579,7 @@ const cvaLegend = cssClassVarianceUtilities.cvaMerge(["flex", "overflow-auto", "
579
579
  * @param {BarChartProps} props - The props for the Chart component
580
580
  * @returns {ReactElement} Chart component
581
581
  */
582
- const BarChart = ({ series, loading = false, onClick, className, "data-testid": dataTestId, units, showDataZoom = false, ref, }) => {
582
+ const BarChart = ({ series, loading = false, onClick, className, style, "data-testid": dataTestId, units, showDataZoom = false, ref, }) => {
583
583
  const { formatDate } = reactDateAndTimeHooks.useDateAndTime();
584
584
  const { chartColor } = useChartColor();
585
585
  const seriesData = react.useMemo(() => {
@@ -596,7 +596,7 @@ const BarChart = ({ series, loading = false, onClick, className, "data-testid":
596
596
  }));
597
597
  }, [series, chartColor]);
598
598
  const isDateData = (data) => !!data && "date" in data;
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
+ return (jsxRuntime.jsxs("div", { className: cvaChartRoot({ className }), "data-testid": dataTestId, ref: ref, style: style, 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 w-full flex-1", children: jsxRuntime.jsx(Chart, { "data-testid": "bar-chart", onClick: onClick
600
600
  ? (e) => {
601
601
  onClick(e);
602
602
  }
@@ -659,7 +659,7 @@ const BarChart = ({ series, loading = false, onClick, className, "data-testid":
659
659
  },
660
660
  ],
661
661
  series: seriesData,
662
- }, showLoading: loading, style: { height: "360px", width: "100%" } }) })] }));
662
+ }, showLoading: loading, style: { height: "100%", minHeight: "150px", width: "100%" } }) })] }));
663
663
  };
664
664
  const cvaChartRoot = cssClassVarianceUtilities.cvaMerge(["flex", "flex-col", "items-center", "h-full"]);
665
665
 
package/index.esm.js CHANGED
@@ -255,9 +255,9 @@ const cvaLegendItemIndicator = cvaMerge(["w-3", "mr-1", "h-3", "rounded-[50%]",
255
255
  * @param {LegendItem} props - The props for the LegendItem component
256
256
  * @returns {ReactElement} LegendItem component
257
257
  */
258
- const LegendItem = ({ className, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, }) => {
258
+ const LegendItem = ({ className, style, count, label, disabled = false, selected = false, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit = undefined, hideValue = false, }) => {
259
259
  const handleOnClick = onClick && !disabled ? e => onClick(e) : undefined;
260
- return (jsxs("div", { className: cvaLegendItem({ disabled, selected, isClickable: !disabled && onClick !== undefined, className }), "data-testid": dataTestId, onClick: handleOnClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, children: [jsx("div", { className: cvaLegendItemIndicator({ selected }), "data-testid": dataTestId ? `${dataTestId}-indicator` : null, style: { backgroundColor: color } }), jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : (jsxs("p", { className: "text-xs", children: ["(", count ?? 0, ")", unit ?? ""] }))] }));
260
+ return (jsxs("div", { className: cvaLegendItem({ disabled, selected, isClickable: !disabled && onClick !== undefined, className }), "data-testid": dataTestId, onClick: handleOnClick, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, style: style, children: [jsx("div", { className: cvaLegendItemIndicator({ selected }), "data-testid": dataTestId ? `${dataTestId}-indicator` : null, style: { backgroundColor: color } }), jsxs("p", { className: "truncate text-xs", children: [label, "\u00A0"] }), hideValue ? null : (jsxs("p", { className: "text-xs", children: ["(", count ?? 0, ")", unit ?? ""] }))] }));
261
261
  };
262
262
 
263
263
  /**
@@ -360,7 +360,7 @@ 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 = undefined, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, ref, }) => {
363
+ const DonutChart = ({ data, size = "full", loading = false, onClick, className, style, "data-testid": dataTestId, maxDataPoints = 6, showOthers = true, unit = undefined, overrideTotal, autoSortData = true, hideLegendValues = false, othersName, ref, }) => {
364
364
  const containerRef = useRef(null);
365
365
  const mergedRef = useMergeRefs([containerRef, ref]);
366
366
  const chartRef = useRef(null);
@@ -487,7 +487,7 @@ const DonutChart = ({ data, size = "full", loading = false, onClick, className,
487
487
  if (loading) {
488
488
  return jsx(Spinner, { centering: "centered", "data-testid": dataTestId ? `${dataTestId}-loading` : "donut-chart-loading" });
489
489
  }
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
+ return (jsxs("div", { className: cvaChartRoot$1({ className }), "data-testid": dataTestId, ref: mergedRef, style: style, 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))) }))] }));
491
491
  };
492
492
  const cvaChartRoot$1 = cvaMerge([
493
493
  "flex",
@@ -558,7 +558,7 @@ const cvaLegend = cvaMerge(["flex", "overflow-auto", "justify-start", "flex-col"
558
558
  * @param {BarChartProps} props - The props for the Chart component
559
559
  * @returns {ReactElement} Chart component
560
560
  */
561
- const BarChart = ({ series, loading = false, onClick, className, "data-testid": dataTestId, units, showDataZoom = false, ref, }) => {
561
+ const BarChart = ({ series, loading = false, onClick, className, style, "data-testid": dataTestId, units, showDataZoom = false, ref, }) => {
562
562
  const { formatDate } = useDateAndTime();
563
563
  const { chartColor } = useChartColor();
564
564
  const seriesData = useMemo(() => {
@@ -575,7 +575,7 @@ const BarChart = ({ series, loading = false, onClick, className, "data-testid":
575
575
  }));
576
576
  }, [series, chartColor]);
577
577
  const isDateData = (data) => !!data && "date" in data;
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
+ return (jsxs("div", { className: cvaChartRoot({ className }), "data-testid": dataTestId, ref: ref, style: style, 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 w-full flex-1", children: jsx(Chart, { "data-testid": "bar-chart", onClick: onClick
579
579
  ? (e) => {
580
580
  onClick(e);
581
581
  }
@@ -638,7 +638,7 @@ const BarChart = ({ series, loading = false, onClick, className, "data-testid":
638
638
  },
639
639
  ],
640
640
  series: seriesData,
641
- }, showLoading: loading, style: { height: "360px", width: "100%" } }) })] }));
641
+ }, showLoading: loading, style: { height: "100%", minHeight: "150px", width: "100%" } }) })] }));
642
642
  };
643
643
  const cvaChartRoot = cvaMerge(["flex", "flex-col", "items-center", "h-full"]);
644
644
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-chart-components",
3
- "version": "1.24.1",
3
+ "version": "1.25.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -1,4 +1,4 @@
1
- import { CommonProps, Refable } from "@trackunit/react-components";
1
+ import { CommonProps, Refable, type Styleable } 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, Refable<HTMLDivElement> {
35
+ export interface BarChartProps<TProps extends object> extends CommonProps, Refable<HTMLDivElement>, Styleable {
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, Refab
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, ref, }: BarChartProps<TProps>) => ReactElement;
103
+ export declare const BarChart: <TProps extends object>({ series, loading, onClick, className, style, "data-testid": dataTestId, units, showDataZoom, ref, }: BarChartProps<TProps>) => ReactElement;
@@ -1,8 +1,8 @@
1
- import { CommonProps, Refable } from "@trackunit/react-components";
1
+ import { CommonProps, Refable, type Styleable } from "@trackunit/react-components";
2
2
  import type { ECElementEvent, ECharts, EChartsOption } from "echarts";
3
- import { CSSProperties, ReactElement, ReactNode } from "react";
3
+ import { ReactElement, ReactNode } from "react";
4
4
  import { BrushEvent, type EventName } from "../EChart/EChart";
5
- export type ChartProps = CommonProps & Refable<HTMLDivElement> & {
5
+ export type ChartProps = CommonProps & Refable<HTMLDivElement> & Styleable & {
6
6
  /**
7
7
  * Option values for EChart.
8
8
  */
@@ -15,10 +15,6 @@ export type ChartProps = CommonProps & Refable<HTMLDivElement> & {
15
15
  * onClick event handler.
16
16
  */
17
17
  onClick?: (event: ECElementEvent) => void;
18
- /**
19
- * CSS styles for the chart.
20
- */
21
- style?: CSSProperties;
22
18
  /**
23
19
  * Called when the chart instance is ready.
24
20
  */
@@ -1,4 +1,4 @@
1
- import { CommonProps, Refable } from "@trackunit/react-components";
1
+ import { CommonProps, Refable, type Styleable } 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, Refable<HTMLDivElement> {
30
+ export interface DonutChartProps<TProps extends object> extends CommonProps, Refable<HTMLDivElement>, Styleable {
31
31
  /**
32
32
  * Array of data points to show
33
33
  */
@@ -137,5 +137,5 @@ export interface DonutChartProps<TProps extends object> extends CommonProps, Ref
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, ref, }: DonutChartProps<TProps>) => ReactElement;
140
+ export declare const DonutChart: <TProps extends object>({ data, size, loading, onClick, className, style, "data-testid": dataTestId, maxDataPoints, showOthers, unit, overrideTotal, autoSortData, hideLegendValues, othersName, ref, }: DonutChartProps<TProps>) => ReactElement;
141
141
  export {};
@@ -1,6 +1,6 @@
1
- import { CommonProps } from "@trackunit/react-components";
1
+ import { CommonProps, type Styleable } from "@trackunit/react-components";
2
2
  import type { ECElementEvent, ECharts, EChartsOption } from "echarts";
3
- import { CSSProperties, ReactElement } from "react";
3
+ import { ReactElement } from "react";
4
4
  /**
5
5
  * https://echarts.apache.org/en/api.html#events
6
6
  */
@@ -15,15 +15,11 @@ 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 {
18
+ export interface EChartProps extends CommonProps, Styleable {
19
19
  /**
20
20
  * Option values for EChart.
21
21
  */
22
22
  option: EChartsOption;
23
- /**
24
- * CSS styles for the chart.
25
- */
26
- style?: CSSProperties;
27
23
  /**
28
24
  * Called when the chart instance is ready.
29
25
  */
@@ -1,6 +1,6 @@
1
- import { Refable } from "@trackunit/react-components";
1
+ import { Refable, type Styleable } from "@trackunit/react-components";
2
2
  import { MouseEventHandler } from "react";
3
- export interface LegendItemProps extends Refable<HTMLDivElement> {
3
+ export interface LegendItemProps extends Refable<HTMLDivElement>, Styleable {
4
4
  label: string;
5
5
  count?: number;
6
6
  selected?: boolean;
@@ -20,4 +20,4 @@ export interface LegendItemProps extends Refable<HTMLDivElement> {
20
20
  * @param {LegendItem} props - The props for the LegendItem component
21
21
  * @returns {ReactElement} LegendItem component
22
22
  */
23
- export declare const LegendItem: ({ className, count, label, disabled, selected, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit, hideValue, }: LegendItemProps) => import("react/jsx-runtime").JSX.Element;
23
+ export declare const LegendItem: ({ className, style, count, label, disabled, selected, onClick, color, "data-testid": dataTestId, onMouseEnter, onMouseLeave, unit, hideValue, }: LegendItemProps) => import("react/jsx-runtime").JSX.Element;