@trackunit/react-chart-components 0.0.177 → 0.0.178

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
@@ -6,31 +6,12 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities');
7
7
  var reactComponents = require('@trackunit/react-components');
8
8
  var EChart = require('echarts-for-react');
9
- var React = require('react');
9
+ var react = require('react');
10
10
  var uiDesignTokens = require('@trackunit/ui-design-tokens');
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
14
- function _interopNamespace(e) {
15
- if (e && e.__esModule) return e;
16
- var n = Object.create(null);
17
- if (e) {
18
- Object.keys(e).forEach(function (k) {
19
- if (k !== 'default') {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
24
- });
25
- }
26
- });
27
- }
28
- n["default"] = e;
29
- return Object.freeze(n);
30
- }
31
-
32
14
  var EChart__default = /*#__PURE__*/_interopDefaultLegacy(EChart);
33
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
34
15
 
35
16
  /**
36
17
  * The Chart component is a wrapper component for ECharts.
@@ -42,10 +23,10 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
42
23
  * @param {ChartProps} props - The props for the Chart component
43
24
  * @returns {JSX.Element} Chart component
44
25
  */
45
- const Chart = ({ options, showLoading, className, style, onChartReady, onClick, onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOverChart, mouseOutChart, merge = true, loadingOption, timezoneLabel, renderer = "canvas", dataTestId, }) => {
26
+ const Chart = ({ options, unsafeOptions, showLoading, className, style, onChartReady, onClick, onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOverChart, mouseOutChart, merge = true, loadingOption, timezoneLabel, renderer = "canvas", dataTestId, }) => {
46
27
  var _a, _b;
47
- const echartsRef = React__namespace.useRef(null);
48
- const eventHandlers = React__namespace.useMemo(() => {
28
+ const echartsRef = react.useRef(null);
29
+ const eventHandlers = react.useMemo(() => {
49
30
  const values = {};
50
31
  if (onDataZoom !== undefined) {
51
32
  values.dataZoom = onDataZoom;
@@ -79,7 +60,7 @@ const Chart = ({ options, showLoading, className, style, onChartReady, onClick,
79
60
  }
80
61
  return values;
81
62
  }, [onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOutChart, mouseOverChart]);
82
- React__namespace.useEffect(() => {
63
+ react.useEffect(() => {
83
64
  var _a;
84
65
  const instance = (_a = echartsRef === null || echartsRef === void 0 ? void 0 : echartsRef.current) === null || _a === void 0 ? void 0 : _a.getEchartsInstance();
85
66
  if (instance && onClick) {
@@ -91,7 +72,7 @@ const Chart = ({ options, showLoading, className, style, onChartReady, onClick,
91
72
  }
92
73
  };
93
74
  }, [onClick, echartsRef]);
94
- return (jsxRuntime.jsx("div", { className: cvaChartContainer(), style: { height: (_a = style === null || style === void 0 ? void 0 : style.height) !== null && _a !== void 0 ? _a : "300px", width: (_b = style === null || style === void 0 ? void 0 : style.width) !== null && _b !== void 0 ? _b : "100%" }, "data-testid": dataTestId, children: showLoading ? (jsxRuntime.jsxs("div", { className: cvaChartSpinnerContainer(), "data-testid": `${dataTestId}-loading`, children: [jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered" }), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, children: loadingOption.text }))] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(EChart__default["default"], { ref: echartsRef, option: options, opts: { width: "auto", height: "auto", renderer: renderer }, notMerge: !merge, onEvents: eventHandlers, className: className, style: style, onChartReady: onChartReady }), timezoneLabel] })) }));
75
+ return (jsxRuntime.jsx("div", { className: cvaChartContainer(), style: { height: (_a = style === null || style === void 0 ? void 0 : style.height) !== null && _a !== void 0 ? _a : "300px", width: (_b = style === null || style === void 0 ? void 0 : style.width) !== null && _b !== void 0 ? _b : "100%" }, "data-testid": dataTestId, children: showLoading ? (jsxRuntime.jsxs("div", { className: cvaChartSpinnerContainer(), "data-testid": `${dataTestId}-loading`, children: [jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered" }), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && (jsxRuntime.jsx(reactComponents.Text, { align: "center", subtle: true, children: loadingOption.text }))] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(EChart__default["default"], { ref: echartsRef, option: options !== null && options !== void 0 ? options : unsafeOptions, opts: { width: "auto", height: "auto", renderer: renderer }, notMerge: !merge, onEvents: eventHandlers, className: className, style: style, onChartReady: onChartReady }), timezoneLabel] })) }));
95
76
  };
96
77
  const cvaChartContainer = cssClassVarianceUtilities.cvaMerge(["grid", "gap-1", "grid-rows-1", "grid-cols-1", "h-full", "w-full", "items-center"]);
97
78
  const cvaChartSpinnerContainer = cssClassVarianceUtilities.cvaMerge(["grid", "place-items-center", "overflow-y-auto"]);
@@ -124,15 +105,15 @@ const KPIDonutChart = ({ dataTestId, loading, countColor, totalCountColor, count
124
105
  labelLine: {
125
106
  show: false,
126
107
  },
127
- emphasis: false,
108
+ emphasis: { disabled: true },
128
109
  type: "pie",
129
110
  data: [
130
111
  {
131
- key: "Value",
112
+ name: "Value",
132
113
  value: count,
133
114
  },
134
115
  {
135
- key: "Total",
116
+ name: "Total",
136
117
  value: totalCount - count,
137
118
  },
138
119
  ],
package/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { cvaMerge } from '@trackunit/css-class-variance-utilities';
3
3
  import { Spinner, Text, SkeletonLines, useHover } from '@trackunit/react-components';
4
4
  import EChart from 'echarts-for-react';
5
- import * as React from 'react';
5
+ import { useRef, useMemo, useEffect } from 'react';
6
6
  import { DEFAULT_CHART_COLORS } from '@trackunit/ui-design-tokens';
7
7
 
8
8
  /**
@@ -15,10 +15,10 @@ import { DEFAULT_CHART_COLORS } from '@trackunit/ui-design-tokens';
15
15
  * @param {ChartProps} props - The props for the Chart component
16
16
  * @returns {JSX.Element} Chart component
17
17
  */
18
- const Chart = ({ options, showLoading, className, style, onChartReady, onClick, onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOverChart, mouseOutChart, merge = true, loadingOption, timezoneLabel, renderer = "canvas", dataTestId, }) => {
18
+ const Chart = ({ options, unsafeOptions, showLoading, className, style, onChartReady, onClick, onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOverChart, mouseOutChart, merge = true, loadingOption, timezoneLabel, renderer = "canvas", dataTestId, }) => {
19
19
  var _a, _b;
20
- const echartsRef = React.useRef(null);
21
- const eventHandlers = React.useMemo(() => {
20
+ const echartsRef = useRef(null);
21
+ const eventHandlers = useMemo(() => {
22
22
  const values = {};
23
23
  if (onDataZoom !== undefined) {
24
24
  values.dataZoom = onDataZoom;
@@ -52,7 +52,7 @@ const Chart = ({ options, showLoading, className, style, onChartReady, onClick,
52
52
  }
53
53
  return values;
54
54
  }, [onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOutChart, mouseOverChart]);
55
- React.useEffect(() => {
55
+ useEffect(() => {
56
56
  var _a;
57
57
  const instance = (_a = echartsRef === null || echartsRef === void 0 ? void 0 : echartsRef.current) === null || _a === void 0 ? void 0 : _a.getEchartsInstance();
58
58
  if (instance && onClick) {
@@ -64,7 +64,7 @@ const Chart = ({ options, showLoading, className, style, onChartReady, onClick,
64
64
  }
65
65
  };
66
66
  }, [onClick, echartsRef]);
67
- return (jsx("div", { className: cvaChartContainer(), style: { height: (_a = style === null || style === void 0 ? void 0 : style.height) !== null && _a !== void 0 ? _a : "300px", width: (_b = style === null || style === void 0 ? void 0 : style.width) !== null && _b !== void 0 ? _b : "100%" }, "data-testid": dataTestId, children: showLoading ? (jsxs("div", { className: cvaChartSpinnerContainer(), "data-testid": `${dataTestId}-loading`, children: [jsx(Spinner, { centering: "centered" }), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && (jsx(Text, { align: "center", subtle: true, children: loadingOption.text }))] })) : (jsxs(Fragment, { children: [jsx(EChart, { ref: echartsRef, option: options, opts: { width: "auto", height: "auto", renderer: renderer }, notMerge: !merge, onEvents: eventHandlers, className: className, style: style, onChartReady: onChartReady }), timezoneLabel] })) }));
67
+ return (jsx("div", { className: cvaChartContainer(), style: { height: (_a = style === null || style === void 0 ? void 0 : style.height) !== null && _a !== void 0 ? _a : "300px", width: (_b = style === null || style === void 0 ? void 0 : style.width) !== null && _b !== void 0 ? _b : "100%" }, "data-testid": dataTestId, children: showLoading ? (jsxs("div", { className: cvaChartSpinnerContainer(), "data-testid": `${dataTestId}-loading`, children: [jsx(Spinner, { centering: "centered" }), (loadingOption === null || loadingOption === void 0 ? void 0 : loadingOption.text) && (jsx(Text, { align: "center", subtle: true, children: loadingOption.text }))] })) : (jsxs(Fragment, { children: [jsx(EChart, { ref: echartsRef, option: options !== null && options !== void 0 ? options : unsafeOptions, opts: { width: "auto", height: "auto", renderer: renderer }, notMerge: !merge, onEvents: eventHandlers, className: className, style: style, onChartReady: onChartReady }), timezoneLabel] })) }));
68
68
  };
69
69
  const cvaChartContainer = cvaMerge(["grid", "gap-1", "grid-rows-1", "grid-cols-1", "h-full", "w-full", "items-center"]);
70
70
  const cvaChartSpinnerContainer = cvaMerge(["grid", "place-items-center", "overflow-y-auto"]);
@@ -97,15 +97,15 @@ const KPIDonutChart = ({ dataTestId, loading, countColor, totalCountColor, count
97
97
  labelLine: {
98
98
  show: false,
99
99
  },
100
- emphasis: false,
100
+ emphasis: { disabled: true },
101
101
  type: "pie",
102
102
  data: [
103
103
  {
104
- key: "Value",
104
+ name: "Value",
105
105
  value: count,
106
106
  },
107
107
  {
108
- key: "Total",
108
+ name: "Total",
109
109
  value: totalCount - count,
110
110
  },
111
111
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-chart-components",
3
- "version": "0.0.177",
3
+ "version": "0.0.178",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,14 +1,35 @@
1
1
  import { CommonProps } from "@trackunit/react-components";
2
- import { EChartsType } from "echarts";
3
- import * as React from "react";
4
- export interface IOptionsType {
2
+ import { EChartsOption, EChartsType } from "echarts";
3
+ import { CSSProperties, ReactNode } from "react";
4
+ interface UnsafeOptions {
5
5
  [key: string]: any;
6
6
  }
7
- export interface ChartProps extends CommonProps {
7
+ type UnsafeOptionsCondition = {
8
8
  /**
9
9
  * Option values for EChart.
10
10
  */
11
- options: IOptionsType;
11
+ options?: never;
12
+ /**
13
+ * Option values for EChart. Not typed.
14
+ *
15
+ * @deprecated Use options instead.
16
+ */
17
+ unsafeOptions: UnsafeOptions;
18
+ };
19
+ type SafeOptionsCondition = {
20
+ /**
21
+ * Option values for EChart.
22
+ */
23
+ options: EChartsOption;
24
+ /**
25
+ * Option values for EChart. Not typed.
26
+ *
27
+ * @deprecated Use options instead.
28
+ */
29
+ unsafeOptions?: never;
30
+ };
31
+ type ConditionalChartOptions = UnsafeOptionsCondition | SafeOptionsCondition;
32
+ export type ChartProps = CommonProps & ConditionalChartOptions & {
12
33
  /**
13
34
  * Whether or not to low the preloader.
14
35
  */
@@ -48,7 +69,7 @@ export interface ChartProps extends CommonProps {
48
69
  /**
49
70
  * CSS styles for the chart.
50
71
  */
51
- style?: Record<string, string | number>;
72
+ style?: CSSProperties;
52
73
  /**
53
74
  * To denote of chart is ready or not.
54
75
  */
@@ -66,7 +87,7 @@ export interface ChartProps extends CommonProps {
66
87
  /**
67
88
  * Time-zone label.
68
89
  */
69
- timezoneLabel?: React.ReactNode;
90
+ timezoneLabel?: ReactNode;
70
91
  /**
71
92
  * Type of rendered used. Either "svg" or "canvas".
72
93
  */
@@ -75,7 +96,7 @@ export interface ChartProps extends CommonProps {
75
96
  * Value used to find element by `data-testid` attribute.
76
97
  */
77
98
  dataTestId?: string;
78
- }
99
+ };
79
100
  /**
80
101
  * The Chart component is a wrapper component for ECharts.
81
102
  *
@@ -86,4 +107,5 @@ export interface ChartProps extends CommonProps {
86
107
  * @param {ChartProps} props - The props for the Chart component
87
108
  * @returns {JSX.Element} Chart component
88
109
  */
89
- export declare const Chart: ({ options, showLoading, className, style, onChartReady, onClick, onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOverChart, mouseOutChart, merge, loadingOption, timezoneLabel, renderer, dataTestId, }: ChartProps) => JSX.Element;
110
+ export declare const Chart: ({ options, unsafeOptions, showLoading, className, style, onChartReady, onClick, onDataZoom, onBrush, onBrushSelected, mouseLeaveChart, mouseMoveChart, mouseOverChart, mouseOutChart, merge, loadingOption, timezoneLabel, renderer, dataTestId, }: ChartProps) => JSX.Element;
111
+ export {};