@trackunit/react-chart-components 1.10.19 → 1.10.21

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
@@ -177,8 +177,48 @@ const EChart = ({ option, style, className, onChartReady, onClick, onEvents, not
177
177
  const cvaEChart = cssClassVarianceUtilities.cvaMerge(["w-full", "h-full"]);
178
178
 
179
179
  /**
180
- * The Chart component is a wrapper component for ECharts.
181
- * Handles events and click functionality.
180
+ * The Chart component is a wrapper component for ECharts, providing a simplified API for rendering interactive charts.
181
+ * It handles loading states, event callbacks, and timezone labels out of the box.
182
+ *
183
+ * ### When to use
184
+ * - When you need full control over ECharts configuration options
185
+ * - For custom or complex chart types not covered by specialized components (BarChart, DonutChart)
186
+ *
187
+ * ### When not to use
188
+ * - For standard bar or donut charts, use the dedicated BarChart or DonutChart components
189
+ *
190
+ * @example Basic line chart
191
+ * ```tsx
192
+ * import { Chart } from "@trackunit/react-chart-components";
193
+ *
194
+ * const LineChart = () => (
195
+ * <Chart
196
+ * options={{
197
+ * xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri"] },
198
+ * yAxis: { type: "value" },
199
+ * series: [{ data: [150, 230, 224, 218, 135], type: "line" }],
200
+ * }}
201
+ * style={{ height: "300px" }}
202
+ * />
203
+ * );
204
+ * ```
205
+ * @example Chart with loading state and click handler
206
+ * ```tsx
207
+ * import { Chart } from "@trackunit/react-chart-components";
208
+ *
209
+ * const InteractiveChart = ({ loading, data }) => (
210
+ * <Chart
211
+ * showLoading={loading}
212
+ * loadingOption={{ text: "Loading chart data..." }}
213
+ * onClick={(event) => console.log("Clicked:", event.data)}
214
+ * options={{
215
+ * xAxis: { type: "category", data: data.labels },
216
+ * yAxis: { type: "value" },
217
+ * series: [{ data: data.values, type: "bar" }],
218
+ * }}
219
+ * />
220
+ * );
221
+ * ```
182
222
  */
183
223
  const Chart = ({ options, showLoading = false, className, style, onChartReady, onClick, onEvents, merge = true, loadingOption, timezoneLabel, renderer = "canvas", "data-testid": dataTestId, }) => {
184
224
  const containerStyle = {
@@ -295,8 +335,49 @@ const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
295
335
  };
296
336
 
297
337
  /**
298
- * Create a DonutChart with legends based on our current Chart component
338
+ * Create a DonutChart with interactive legends. Shows proportional data with a center total
339
+ * and hover-to-highlight interactions between chart segments and legend items.
340
+ *
341
+ * ### When to use
342
+ * - To show parts of a whole (percentages, distributions)
343
+ * - When you have a limited number of categories (ideally 6 or fewer)
344
+ * - To display summary metrics with categorical breakdowns
299
345
  *
346
+ * ### When not to use
347
+ * - For comparing values across many categories (use BarChart)
348
+ * - For time-series data (use line or bar charts)
349
+ *
350
+ * @example Basic donut chart with categories
351
+ * ```tsx
352
+ * import { DonutChart } from "@trackunit/react-chart-components";
353
+ *
354
+ * const AssetDistribution = () => (
355
+ * <DonutChart
356
+ * data={[
357
+ * { id: "excavators", name: "Excavators", value: 45, color: "#3b82f6" },
358
+ * { id: "loaders", name: "Loaders", value: 30, color: "#10b981" },
359
+ * { id: "trucks", name: "Trucks", value: 25, color: "#f59e0b" },
360
+ * ]}
361
+ * onClick={(item) => console.log("Selected:", item.name)}
362
+ * />
363
+ * );
364
+ * ```
365
+ * @example Compact donut chart for dashboards
366
+ * ```tsx
367
+ * import { DonutChart } from "@trackunit/react-chart-components";
368
+ *
369
+ * const UtilizationDonut = () => (
370
+ * <DonutChart
371
+ * data={[
372
+ * { id: "active", name: "Active", value: 75 },
373
+ * { id: "idle", name: "Idle", value: 25 },
374
+ * ]}
375
+ * size="compact"
376
+ * unit="%"
377
+ * overrideTotal={75}
378
+ * />
379
+ * );
380
+ * ```
300
381
  * @param {DonutChartProps} props - The props for the Chart component
301
382
  * @returns {ReactElement} Chart component
302
383
  */
@@ -452,8 +533,48 @@ const cvaChart = cssClassVarianceUtilities.cvaMerge(["flex-0", "max-w-[200px]",
452
533
  const cvaLegend = cssClassVarianceUtilities.cvaMerge(["flex", "overflow-auto", "justify-start", "flex-col", "flex-1"]);
453
534
 
454
535
  /**
455
- * Create a BarChart with legends. Based on Chart component
536
+ * Create a BarChart with automatic legends and formatting. Built on top of the Chart component
537
+ * with sensible defaults for displaying categorical or time-series data.
538
+ *
539
+ * ### When to use
540
+ * - To compare values across categories
541
+ * - To show trends over time with discrete intervals
542
+ * - When you need multiple series displayed side by side
543
+ *
544
+ * @example Bar chart with date-based data
545
+ * ```tsx
546
+ * import { BarChart } from "@trackunit/react-chart-components";
547
+ *
548
+ * const UtilizationChart = () => (
549
+ * <BarChart
550
+ * series={{
551
+ * name: "Utilization",
552
+ * data: [
553
+ * { date: "2024-01-01", value: 85 },
554
+ * { date: "2024-01-02", value: 72 },
555
+ * { date: "2024-01-03", value: 91 },
556
+ * ],
557
+ * }}
558
+ * units="%"
559
+ * onClick={(event) => console.log("Clicked bar:", event.data)}
560
+ * />
561
+ * );
562
+ * ```
563
+ * @example Multi-series bar chart with data zoom
564
+ * ```tsx
565
+ * import { BarChart } from "@trackunit/react-chart-components";
456
566
  *
567
+ * const ComparisonChart = () => (
568
+ * <BarChart
569
+ * series={[
570
+ * { name: "2023", color: "#3b82f6", data: [{ key: "Q1", value: 100 }, { key: "Q2", value: 120 }] },
571
+ * { name: "2024", color: "#10b981", data: [{ key: "Q1", value: 130 }, { key: "Q2", value: 145 }] },
572
+ * ]}
573
+ * units="units"
574
+ * showDataZoom={true}
575
+ * />
576
+ * );
577
+ * ```
457
578
  * @param {BarChartProps} props - The props for the Chart component
458
579
  * @returns {ReactElement} Chart component
459
580
  */
package/index.esm.js CHANGED
@@ -156,8 +156,48 @@ const EChart = ({ option, style, className, onChartReady, onClick, onEvents, not
156
156
  const cvaEChart = cvaMerge(["w-full", "h-full"]);
157
157
 
158
158
  /**
159
- * The Chart component is a wrapper component for ECharts.
160
- * Handles events and click functionality.
159
+ * The Chart component is a wrapper component for ECharts, providing a simplified API for rendering interactive charts.
160
+ * It handles loading states, event callbacks, and timezone labels out of the box.
161
+ *
162
+ * ### When to use
163
+ * - When you need full control over ECharts configuration options
164
+ * - For custom or complex chart types not covered by specialized components (BarChart, DonutChart)
165
+ *
166
+ * ### When not to use
167
+ * - For standard bar or donut charts, use the dedicated BarChart or DonutChart components
168
+ *
169
+ * @example Basic line chart
170
+ * ```tsx
171
+ * import { Chart } from "@trackunit/react-chart-components";
172
+ *
173
+ * const LineChart = () => (
174
+ * <Chart
175
+ * options={{
176
+ * xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri"] },
177
+ * yAxis: { type: "value" },
178
+ * series: [{ data: [150, 230, 224, 218, 135], type: "line" }],
179
+ * }}
180
+ * style={{ height: "300px" }}
181
+ * />
182
+ * );
183
+ * ```
184
+ * @example Chart with loading state and click handler
185
+ * ```tsx
186
+ * import { Chart } from "@trackunit/react-chart-components";
187
+ *
188
+ * const InteractiveChart = ({ loading, data }) => (
189
+ * <Chart
190
+ * showLoading={loading}
191
+ * loadingOption={{ text: "Loading chart data..." }}
192
+ * onClick={(event) => console.log("Clicked:", event.data)}
193
+ * options={{
194
+ * xAxis: { type: "category", data: data.labels },
195
+ * yAxis: { type: "value" },
196
+ * series: [{ data: data.values, type: "bar" }],
197
+ * }}
198
+ * />
199
+ * );
200
+ * ```
161
201
  */
162
202
  const Chart = ({ options, showLoading = false, className, style, onChartReady, onClick, onEvents, merge = true, loadingOption, timezoneLabel, renderer = "canvas", "data-testid": dataTestId, }) => {
163
203
  const containerStyle = {
@@ -274,8 +314,49 @@ const useLimitDataSet = (data, limit, autoSortData = true, othersName) => {
274
314
  };
275
315
 
276
316
  /**
277
- * Create a DonutChart with legends based on our current Chart component
317
+ * Create a DonutChart with interactive legends. Shows proportional data with a center total
318
+ * and hover-to-highlight interactions between chart segments and legend items.
319
+ *
320
+ * ### When to use
321
+ * - To show parts of a whole (percentages, distributions)
322
+ * - When you have a limited number of categories (ideally 6 or fewer)
323
+ * - To display summary metrics with categorical breakdowns
278
324
  *
325
+ * ### When not to use
326
+ * - For comparing values across many categories (use BarChart)
327
+ * - For time-series data (use line or bar charts)
328
+ *
329
+ * @example Basic donut chart with categories
330
+ * ```tsx
331
+ * import { DonutChart } from "@trackunit/react-chart-components";
332
+ *
333
+ * const AssetDistribution = () => (
334
+ * <DonutChart
335
+ * data={[
336
+ * { id: "excavators", name: "Excavators", value: 45, color: "#3b82f6" },
337
+ * { id: "loaders", name: "Loaders", value: 30, color: "#10b981" },
338
+ * { id: "trucks", name: "Trucks", value: 25, color: "#f59e0b" },
339
+ * ]}
340
+ * onClick={(item) => console.log("Selected:", item.name)}
341
+ * />
342
+ * );
343
+ * ```
344
+ * @example Compact donut chart for dashboards
345
+ * ```tsx
346
+ * import { DonutChart } from "@trackunit/react-chart-components";
347
+ *
348
+ * const UtilizationDonut = () => (
349
+ * <DonutChart
350
+ * data={[
351
+ * { id: "active", name: "Active", value: 75 },
352
+ * { id: "idle", name: "Idle", value: 25 },
353
+ * ]}
354
+ * size="compact"
355
+ * unit="%"
356
+ * overrideTotal={75}
357
+ * />
358
+ * );
359
+ * ```
279
360
  * @param {DonutChartProps} props - The props for the Chart component
280
361
  * @returns {ReactElement} Chart component
281
362
  */
@@ -431,8 +512,48 @@ const cvaChart = cvaMerge(["flex-0", "max-w-[200px]", "max-h-[200px]", "place-se
431
512
  const cvaLegend = cvaMerge(["flex", "overflow-auto", "justify-start", "flex-col", "flex-1"]);
432
513
 
433
514
  /**
434
- * Create a BarChart with legends. Based on Chart component
515
+ * Create a BarChart with automatic legends and formatting. Built on top of the Chart component
516
+ * with sensible defaults for displaying categorical or time-series data.
517
+ *
518
+ * ### When to use
519
+ * - To compare values across categories
520
+ * - To show trends over time with discrete intervals
521
+ * - When you need multiple series displayed side by side
522
+ *
523
+ * @example Bar chart with date-based data
524
+ * ```tsx
525
+ * import { BarChart } from "@trackunit/react-chart-components";
526
+ *
527
+ * const UtilizationChart = () => (
528
+ * <BarChart
529
+ * series={{
530
+ * name: "Utilization",
531
+ * data: [
532
+ * { date: "2024-01-01", value: 85 },
533
+ * { date: "2024-01-02", value: 72 },
534
+ * { date: "2024-01-03", value: 91 },
535
+ * ],
536
+ * }}
537
+ * units="%"
538
+ * onClick={(event) => console.log("Clicked bar:", event.data)}
539
+ * />
540
+ * );
541
+ * ```
542
+ * @example Multi-series bar chart with data zoom
543
+ * ```tsx
544
+ * import { BarChart } from "@trackunit/react-chart-components";
435
545
  *
546
+ * const ComparisonChart = () => (
547
+ * <BarChart
548
+ * series={[
549
+ * { name: "2023", color: "#3b82f6", data: [{ key: "Q1", value: 100 }, { key: "Q2", value: 120 }] },
550
+ * { name: "2024", color: "#10b981", data: [{ key: "Q1", value: 130 }, { key: "Q2", value: 145 }] },
551
+ * ]}
552
+ * units="units"
553
+ * showDataZoom={true}
554
+ * />
555
+ * );
556
+ * ```
436
557
  * @param {BarChartProps} props - The props for the Chart component
437
558
  * @returns {ReactElement} Chart component
438
559
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-chart-components",
3
- "version": "1.10.19",
3
+ "version": "1.10.21",
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.10.15",
13
- "@trackunit/react-date-and-time-hooks": "1.10.19",
14
- "@trackunit/ui-design-tokens": "1.10.15",
15
- "@trackunit/shared-utils": "1.12.15",
16
- "@trackunit/css-class-variance-utilities": "1.10.15",
17
- "@trackunit/react-components": "1.14.18"
12
+ "@trackunit/date-and-time-utils": "1.10.16",
13
+ "@trackunit/react-date-and-time-hooks": "1.10.21",
14
+ "@trackunit/ui-design-tokens": "1.10.16",
15
+ "@trackunit/shared-utils": "1.12.16",
16
+ "@trackunit/css-class-variance-utilities": "1.10.16",
17
+ "@trackunit/react-components": "1.14.20"
18
18
  },
19
19
  "module": "./index.esm.js",
20
20
  "main": "./index.cjs.js",
@@ -55,8 +55,48 @@ export interface BarChartProps<TProps extends object> extends CommonProps {
55
55
  showDataZoom?: boolean;
56
56
  }
57
57
  /**
58
- * Create a BarChart with legends. Based on Chart component
58
+ * Create a BarChart with automatic legends and formatting. Built on top of the Chart component
59
+ * with sensible defaults for displaying categorical or time-series data.
59
60
  *
61
+ * ### When to use
62
+ * - To compare values across categories
63
+ * - To show trends over time with discrete intervals
64
+ * - When you need multiple series displayed side by side
65
+ *
66
+ * @example Bar chart with date-based data
67
+ * ```tsx
68
+ * import { BarChart } from "@trackunit/react-chart-components";
69
+ *
70
+ * const UtilizationChart = () => (
71
+ * <BarChart
72
+ * series={{
73
+ * name: "Utilization",
74
+ * data: [
75
+ * { date: "2024-01-01", value: 85 },
76
+ * { date: "2024-01-02", value: 72 },
77
+ * { date: "2024-01-03", value: 91 },
78
+ * ],
79
+ * }}
80
+ * units="%"
81
+ * onClick={(event) => console.log("Clicked bar:", event.data)}
82
+ * />
83
+ * );
84
+ * ```
85
+ * @example Multi-series bar chart with data zoom
86
+ * ```tsx
87
+ * import { BarChart } from "@trackunit/react-chart-components";
88
+ *
89
+ * const ComparisonChart = () => (
90
+ * <BarChart
91
+ * series={[
92
+ * { name: "2023", color: "#3b82f6", data: [{ key: "Q1", value: 100 }, { key: "Q2", value: 120 }] },
93
+ * { name: "2024", color: "#10b981", data: [{ key: "Q1", value: 130 }, { key: "Q2", value: 145 }] },
94
+ * ]}
95
+ * units="units"
96
+ * showDataZoom={true}
97
+ * />
98
+ * );
99
+ * ```
60
100
  * @param {BarChartProps} props - The props for the Chart component
61
101
  * @returns {ReactElement} Chart component
62
102
  */
@@ -59,7 +59,47 @@ export type ChartProps = CommonProps & {
59
59
  "data-testid"?: string;
60
60
  };
61
61
  /**
62
- * The Chart component is a wrapper component for ECharts.
63
- * Handles events and click functionality.
62
+ * The Chart component is a wrapper component for ECharts, providing a simplified API for rendering interactive charts.
63
+ * It handles loading states, event callbacks, and timezone labels out of the box.
64
+ *
65
+ * ### When to use
66
+ * - When you need full control over ECharts configuration options
67
+ * - For custom or complex chart types not covered by specialized components (BarChart, DonutChart)
68
+ *
69
+ * ### When not to use
70
+ * - For standard bar or donut charts, use the dedicated BarChart or DonutChart components
71
+ *
72
+ * @example Basic line chart
73
+ * ```tsx
74
+ * import { Chart } from "@trackunit/react-chart-components";
75
+ *
76
+ * const LineChart = () => (
77
+ * <Chart
78
+ * options={{
79
+ * xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri"] },
80
+ * yAxis: { type: "value" },
81
+ * series: [{ data: [150, 230, 224, 218, 135], type: "line" }],
82
+ * }}
83
+ * style={{ height: "300px" }}
84
+ * />
85
+ * );
86
+ * ```
87
+ * @example Chart with loading state and click handler
88
+ * ```tsx
89
+ * import { Chart } from "@trackunit/react-chart-components";
90
+ *
91
+ * const InteractiveChart = ({ loading, data }) => (
92
+ * <Chart
93
+ * showLoading={loading}
94
+ * loadingOption={{ text: "Loading chart data..." }}
95
+ * onClick={(event) => console.log("Clicked:", event.data)}
96
+ * options={{
97
+ * xAxis: { type: "category", data: data.labels },
98
+ * yAxis: { type: "value" },
99
+ * series: [{ data: data.values, type: "bar" }],
100
+ * }}
101
+ * />
102
+ * );
103
+ * ```
64
104
  */
65
105
  export declare const Chart: ({ options, showLoading, className, style, onChartReady, onClick, onEvents, merge, loadingOption, timezoneLabel, renderer, "data-testid": dataTestId, }: ChartProps) => ReactElement;
@@ -91,8 +91,49 @@ export interface DonutChartProps<TProps extends object> extends CommonProps {
91
91
  othersName?: string;
92
92
  }
93
93
  /**
94
- * Create a DonutChart with legends based on our current Chart component
94
+ * Create a DonutChart with interactive legends. Shows proportional data with a center total
95
+ * and hover-to-highlight interactions between chart segments and legend items.
95
96
  *
97
+ * ### When to use
98
+ * - To show parts of a whole (percentages, distributions)
99
+ * - When you have a limited number of categories (ideally 6 or fewer)
100
+ * - To display summary metrics with categorical breakdowns
101
+ *
102
+ * ### When not to use
103
+ * - For comparing values across many categories (use BarChart)
104
+ * - For time-series data (use line or bar charts)
105
+ *
106
+ * @example Basic donut chart with categories
107
+ * ```tsx
108
+ * import { DonutChart } from "@trackunit/react-chart-components";
109
+ *
110
+ * const AssetDistribution = () => (
111
+ * <DonutChart
112
+ * data={[
113
+ * { id: "excavators", name: "Excavators", value: 45, color: "#3b82f6" },
114
+ * { id: "loaders", name: "Loaders", value: 30, color: "#10b981" },
115
+ * { id: "trucks", name: "Trucks", value: 25, color: "#f59e0b" },
116
+ * ]}
117
+ * onClick={(item) => console.log("Selected:", item.name)}
118
+ * />
119
+ * );
120
+ * ```
121
+ * @example Compact donut chart for dashboards
122
+ * ```tsx
123
+ * import { DonutChart } from "@trackunit/react-chart-components";
124
+ *
125
+ * const UtilizationDonut = () => (
126
+ * <DonutChart
127
+ * data={[
128
+ * { id: "active", name: "Active", value: 75 },
129
+ * { id: "idle", name: "Idle", value: 25 },
130
+ * ]}
131
+ * size="compact"
132
+ * unit="%"
133
+ * overrideTotal={75}
134
+ * />
135
+ * );
136
+ * ```
96
137
  * @param {DonutChartProps} props - The props for the Chart component
97
138
  * @returns {ReactElement} Chart component
98
139
  */