@react-fabric/chart 1.0.0-beta.6 → 1.0.0-beta.61
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/{src/wrapper/Chart.module.css → css/_chart.css} +7 -7
- package/css/styles.css +24 -0
- package/dist/cjs/charts/ActivityMap.js +61 -30
- package/dist/cjs/charts/CountSeries.js +56 -26
- package/dist/cjs/charts/DataSeries.js +64 -36
- package/dist/cjs/charts/Generic.js +29 -5
- package/dist/cjs/charts/MapSeries.js +35 -11
- package/dist/cjs/charts/TimeSeries.js +60 -34
- package/dist/cjs/charts/TimeSlider.js +30 -10
- package/dist/cjs/charts/WordBubble.js +37 -7
- package/dist/cjs/theme/darkBase.js +13 -10
- package/dist/cjs/theme/index.js +38 -18
- package/dist/cjs/theme/lightBase.js +18 -15
- package/dist/cjs/theme/palettes.js +27 -27
- package/dist/cjs/types/charts.js +2 -2
- package/dist/cjs/types/utils.js +1 -4
- package/dist/cjs/wrapper/ChartContainer.js +12 -9
- package/dist/cjs/wrapper/ChartToolbar.js +1 -2
- package/dist/cjs/wrapper/PaletteSelect.js +1 -1
- package/dist/esm/charts/ActivityMap.js +62 -31
- package/dist/esm/charts/CountSeries.js +57 -27
- package/dist/esm/charts/DataSeries.js +65 -37
- package/dist/esm/charts/Generic.js +31 -7
- package/dist/esm/charts/MapSeries.js +36 -12
- package/dist/esm/charts/TimeSeries.js +61 -35
- package/dist/esm/charts/TimeSlider.js +30 -10
- package/dist/esm/charts/WordBubble.js +38 -8
- package/dist/esm/theme/darkBase.js +13 -10
- package/dist/esm/theme/index.js +38 -18
- package/dist/esm/theme/lightBase.js +18 -15
- package/dist/esm/theme/palettes.js +27 -27
- package/dist/esm/types/charts.js +2 -2
- package/dist/esm/types/utils.js +1 -4
- package/dist/esm/wrapper/ChartContainer.js +13 -10
- package/dist/esm/wrapper/ChartToolbar.js +1 -2
- package/dist/esm/wrapper/PaletteSelect.js +2 -2
- package/dist/types/charts/ActivityMap.d.ts +23 -2
- package/dist/types/charts/CountSeries.d.ts +28 -1
- package/dist/types/charts/DataSeries.d.ts +26 -1
- package/dist/types/charts/Generic.d.ts +29 -41
- package/dist/types/charts/MapSeries.d.ts +31 -3
- package/dist/types/charts/TimeSeries.d.ts +24 -1
- package/dist/types/charts/TimeSlider.d.ts +22 -2
- package/dist/types/charts/WordBubble.d.ts +32 -3
- package/dist/types/theme/darkBase.d.ts +8 -5
- package/dist/types/theme/index.d.ts +1 -1
- package/dist/types/theme/lightBase.d.ts +8 -5
- package/dist/types/types/charts.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -12
- package/dist/types/types/world.svg.d.ts +1 -1
- package/dist/types/wrapper/ChartContainer.d.ts +4 -4
- package/dist/types/wrapper/ChartWrapper.d.ts +0 -1
- package/package.json +15 -16
- package/src/charts/ActivityMap.tsx +104 -60
- package/src/charts/CountSeries.tsx +89 -50
- package/src/charts/DataSeries.tsx +127 -78
- package/src/charts/Generic.tsx +43 -51
- package/src/charts/MapSeries.tsx +61 -33
- package/src/charts/TimeSeries.tsx +116 -79
- package/src/charts/TimeSlider.tsx +38 -15
- package/src/charts/WordBubble.tsx +43 -12
- package/src/theme/darkBase.ts +12 -9
- package/src/theme/index.ts +94 -20
- package/src/theme/lightBase.ts +17 -14
- package/src/theme/palettes.ts +1 -52
- package/src/types/charts.ts +6 -2
- package/src/types/index.ts +40 -4
- package/src/types/utils.ts +0 -1
- package/src/wrapper/ChartContainer.tsx +17 -12
- package/src/wrapper/ChartToolbar.tsx +1 -2
- package/src/wrapper/PaletteSelect.tsx +2 -8
- package/dist/cjs/wrapper/Chart.module.css +0 -1
- package/dist/esm/wrapper/Chart.module.css +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
2
2
|
import "echarts-wordcloud";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Ref } from "react";
|
|
4
4
|
import { type Theme } from "../types";
|
|
5
5
|
export declare const ChartContainer: import("react").MemoExoticComponent<({ theme, title, options, children, onResize, onClick, onExport, isEmpty, emptyIcon, chartRef: _ref, dataTableRenderer, }: {
|
|
6
6
|
title?: string;
|
|
7
7
|
theme?: Theme;
|
|
8
8
|
isEmpty?: boolean;
|
|
9
9
|
emptyIcon?: string;
|
|
10
|
-
options:
|
|
10
|
+
options: EChartsOption;
|
|
11
11
|
children?: AnyObject;
|
|
12
|
-
chartRef?:
|
|
12
|
+
chartRef?: Ref<EChartsType>;
|
|
13
13
|
onClick?: (event: AnyObject) => void;
|
|
14
14
|
onExport?: (event: AnyObject) => void;
|
|
15
15
|
dataTableRenderer?: (opt: KeyValue) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/chart",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.61",
|
|
4
4
|
"description": "RUF: Charting package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
"types": "dist/types/index.d.ts",
|
|
12
12
|
"directories": {
|
|
13
13
|
"src": "src",
|
|
14
|
+
"styles": "css",
|
|
14
15
|
"test": "tests"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
18
|
+
"css",
|
|
17
19
|
"src",
|
|
18
20
|
"dist"
|
|
19
21
|
],
|
|
@@ -33,26 +35,23 @@
|
|
|
33
35
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
37
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
38
|
-
"classnames": "
|
|
39
|
-
"color": "
|
|
40
|
-
"date-fns": "
|
|
41
|
-
"echarts": "
|
|
42
|
-
"echarts-wordcloud": "
|
|
38
|
+
"@react-fabric/core": "^1.0.0-beta.61",
|
|
39
|
+
"@react-fabric/utilities": "^1.0.0-beta.61",
|
|
40
|
+
"classnames": "~2.5.1",
|
|
41
|
+
"color": "~5.0.2",
|
|
42
|
+
"date-fns": "~4.1.0",
|
|
43
|
+
"echarts": "~6.0.0",
|
|
44
|
+
"echarts-wordcloud": "~2.1.0"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
|
-
"i18next": "
|
|
46
|
-
"react": "
|
|
47
|
-
"react-dom": "
|
|
48
|
-
"react-i18next": "
|
|
49
|
-
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@types/echarts": "^4.9.22"
|
|
47
|
+
"i18next": "~25.6.0",
|
|
48
|
+
"react": "~19.2.0",
|
|
49
|
+
"react-dom": "~19.2.0",
|
|
50
|
+
"react-i18next": "~16.2.1"
|
|
52
51
|
},
|
|
53
52
|
"engines": {
|
|
54
53
|
"node": ">=18.12.0",
|
|
55
54
|
"npm": ">=8.19.0"
|
|
56
55
|
},
|
|
57
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "a0b0c571bf9c189fa3355bbc3b896ecc4b9d6a04"
|
|
58
57
|
}
|
|
@@ -23,15 +23,17 @@
|
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
Button,
|
|
26
|
-
CoreIcons,
|
|
27
26
|
Divider,
|
|
28
27
|
ToggleButtonGroup,
|
|
29
28
|
useMemoDebugger,
|
|
30
29
|
} from "@react-fabric/core";
|
|
31
30
|
import { isArray, isEmpty } from "@react-fabric/utilities";
|
|
32
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
type EChartsOption,
|
|
33
|
+
type EChartsType,
|
|
34
|
+
type ScatterSeriesOption,
|
|
35
|
+
} from "echarts";
|
|
33
36
|
import { memo, useEffect, useRef, useState, type FC } from "react";
|
|
34
|
-
import { ChartPalette } from "../theme/palettes";
|
|
35
37
|
import { type BaseChart } from "../types";
|
|
36
38
|
import { activityRenderer } from "../types/utils";
|
|
37
39
|
import { ChartContainer } from "../wrapper/ChartContainer";
|
|
@@ -40,7 +42,7 @@ import { PaletteSelect } from "../wrapper/PaletteSelect";
|
|
|
40
42
|
|
|
41
43
|
export interface ActivityMapProps extends BaseChart {
|
|
42
44
|
heatmapPalette?: string[];
|
|
43
|
-
|
|
45
|
+
series: Array<Array<[low: number, high: number, count: number]>>;
|
|
44
46
|
time?: "day-hour" | "month-day";
|
|
45
47
|
type?: "scatter" | "heatmap";
|
|
46
48
|
/**
|
|
@@ -135,13 +137,16 @@ const MONTH_DAY = {
|
|
|
135
137
|
|
|
136
138
|
const ActivityMapChart = memo(
|
|
137
139
|
({
|
|
138
|
-
|
|
140
|
+
series = [],
|
|
139
141
|
title,
|
|
140
142
|
onExport,
|
|
143
|
+
options: optionOverride,
|
|
141
144
|
theme: chartTheme = "activity",
|
|
142
145
|
heatmapPalette,
|
|
143
146
|
highLabels,
|
|
144
147
|
lowLabels,
|
|
148
|
+
showThemeSelector,
|
|
149
|
+
showTypeSelector,
|
|
145
150
|
time = "day-hour",
|
|
146
151
|
type: chartType = "scatter",
|
|
147
152
|
onClick,
|
|
@@ -157,17 +162,17 @@ const ActivityMapChart = memo(
|
|
|
157
162
|
setTheme(chartTheme);
|
|
158
163
|
}, [chartTheme]);
|
|
159
164
|
|
|
160
|
-
const options = useMemoDebugger<
|
|
165
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
161
166
|
() => {
|
|
162
167
|
const defaultMap = time === "day-hour" ? DAY_HOUR : MONTH_DAY;
|
|
163
168
|
|
|
164
|
-
const options:
|
|
169
|
+
const options: EChartsOption = {
|
|
165
170
|
series: [],
|
|
166
171
|
};
|
|
167
172
|
|
|
168
|
-
if (isEmpty(
|
|
173
|
+
if (isEmpty(series)) return {};
|
|
169
174
|
|
|
170
|
-
options.xAxis = {
|
|
175
|
+
options.xAxis = Object.assign({}, optionOverride?.xAxis, {
|
|
171
176
|
type: "category",
|
|
172
177
|
data: lowLabels ?? defaultMap.low,
|
|
173
178
|
boundaryGap: type === "heatmap",
|
|
@@ -177,8 +182,8 @@ const ActivityMapChart = memo(
|
|
|
177
182
|
axisLine: {
|
|
178
183
|
show: false,
|
|
179
184
|
},
|
|
180
|
-
};
|
|
181
|
-
options.yAxis = {
|
|
185
|
+
});
|
|
186
|
+
options.yAxis = Object.assign({}, optionOverride?.yAxis, {
|
|
182
187
|
type: "category",
|
|
183
188
|
axisLabel: {
|
|
184
189
|
margin: 16,
|
|
@@ -187,11 +192,11 @@ const ActivityMapChart = memo(
|
|
|
187
192
|
axisLine: {
|
|
188
193
|
show: false,
|
|
189
194
|
},
|
|
190
|
-
};
|
|
191
|
-
options.series =
|
|
195
|
+
});
|
|
196
|
+
options.series = series.map((points, index) => {
|
|
192
197
|
const total = points.reduce((t, p) => t + p[2], 0);
|
|
193
198
|
return {
|
|
194
|
-
id: index
|
|
199
|
+
id: `${index}`,
|
|
195
200
|
name: defaultMap.high[index],
|
|
196
201
|
type,
|
|
197
202
|
symbolSize: function (dataItem: number[]) {
|
|
@@ -201,28 +206,37 @@ const ActivityMapChart = memo(
|
|
|
201
206
|
},
|
|
202
207
|
data: points,
|
|
203
208
|
universalTransition: true,
|
|
204
|
-
};
|
|
209
|
+
} as ScatterSeriesOption;
|
|
205
210
|
});
|
|
206
211
|
|
|
207
212
|
if (type === "heatmap") {
|
|
208
|
-
const dataPoints =
|
|
213
|
+
const dataPoints = series.map((points) =>
|
|
209
214
|
Math.max(...points.map((pt) => pt[2])),
|
|
210
215
|
);
|
|
211
216
|
options.grid = {
|
|
212
217
|
top: 32,
|
|
213
|
-
bottom:
|
|
218
|
+
bottom: 64,
|
|
214
219
|
};
|
|
215
|
-
options.
|
|
216
|
-
|
|
217
|
-
min: 1,
|
|
218
|
-
show: type === "heatmap",
|
|
219
|
-
color: heatmapPalette ?? [...ChartPalette.Heatmap],
|
|
220
|
-
max: Math.max(...dataPoints),
|
|
221
|
-
calculable: true,
|
|
222
|
-
orient: "horizontal",
|
|
223
|
-
left: "center",
|
|
224
|
-
bottom: 48,
|
|
220
|
+
options.legend = {
|
|
221
|
+
show: false,
|
|
225
222
|
};
|
|
223
|
+
options.visualMap = [
|
|
224
|
+
{
|
|
225
|
+
type: "piecewise",
|
|
226
|
+
min: 1,
|
|
227
|
+
show: type === "heatmap",
|
|
228
|
+
max: Math.max(...dataPoints),
|
|
229
|
+
// calculable: true,inRange:
|
|
230
|
+
orient: "horizontal",
|
|
231
|
+
left: "center",
|
|
232
|
+
bottom: 4,
|
|
233
|
+
},
|
|
234
|
+
];
|
|
235
|
+
if (heatmapPalette) {
|
|
236
|
+
options.visualMap[0].inRange = {
|
|
237
|
+
color: heatmapPalette,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
226
240
|
}
|
|
227
241
|
|
|
228
242
|
return {
|
|
@@ -230,18 +244,23 @@ const ActivityMapChart = memo(
|
|
|
230
244
|
top: 32,
|
|
231
245
|
bottom: 64,
|
|
232
246
|
},
|
|
233
|
-
tooltip:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
247
|
+
tooltip: Object.assign(
|
|
248
|
+
{
|
|
249
|
+
trigger: "item",
|
|
250
|
+
confine: true,
|
|
251
|
+
position: "top",
|
|
252
|
+
appendToBody: true,
|
|
253
|
+
valueFormatter: (c: AnyObject) => {
|
|
254
|
+
return isArray(c) ? c[2] : c;
|
|
255
|
+
},
|
|
256
|
+
} as AnyObject,
|
|
257
|
+
optionOverride?.tooltip,
|
|
258
|
+
),
|
|
259
|
+
...optionOverride,
|
|
241
260
|
...options,
|
|
242
261
|
};
|
|
243
262
|
},
|
|
244
|
-
[
|
|
263
|
+
[series, title, type, heatmapPalette, optionOverride],
|
|
245
264
|
"ActivityChart options",
|
|
246
265
|
);
|
|
247
266
|
|
|
@@ -252,33 +271,37 @@ const ActivityMapChart = memo(
|
|
|
252
271
|
theme={theme}
|
|
253
272
|
options={options}
|
|
254
273
|
chartRef={chartRef}
|
|
255
|
-
isEmpty={isEmpty(
|
|
256
|
-
emptyIcon=
|
|
274
|
+
isEmpty={isEmpty(series)}
|
|
275
|
+
emptyIcon="icon-[mdi--chart-scatter-plot]"
|
|
257
276
|
dataTableRenderer={activityRenderer}
|
|
258
277
|
onClick={(e) => onClick?.(e.seriesIndex, e.dataIndex)}
|
|
259
278
|
>
|
|
260
|
-
|
|
261
|
-
<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
279
|
+
{showTypeSelector && (
|
|
280
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
281
|
+
<Button
|
|
282
|
+
size="sm"
|
|
283
|
+
variant="link"
|
|
284
|
+
value="scatter"
|
|
285
|
+
aria-label="scatter"
|
|
286
|
+
icon="icon-[mdi--chart-scatter-plot]"
|
|
287
|
+
/>
|
|
288
|
+
<Button
|
|
289
|
+
size="sm"
|
|
290
|
+
variant="link"
|
|
291
|
+
value="heatmap"
|
|
292
|
+
aria-label="heatmap"
|
|
293
|
+
icon="icon-[mdi--checkerboard]"
|
|
294
|
+
/>
|
|
295
|
+
</ToggleButtonGroup>
|
|
296
|
+
)}
|
|
297
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
298
|
+
{showThemeSelector && (
|
|
299
|
+
<PaletteSelect
|
|
300
|
+
theme={theme}
|
|
301
|
+
onClick={setTheme}
|
|
302
|
+
defaultTheme="activity"
|
|
267
303
|
/>
|
|
268
|
-
|
|
269
|
-
size="sm"
|
|
270
|
-
variant="link"
|
|
271
|
-
value="heatmap"
|
|
272
|
-
aria-label="heatmap"
|
|
273
|
-
icon={CoreIcons.chartActivityCalendar}
|
|
274
|
-
/>
|
|
275
|
-
</ToggleButtonGroup>
|
|
276
|
-
<Divider vertical />
|
|
277
|
-
<PaletteSelect
|
|
278
|
-
theme={theme}
|
|
279
|
-
onClick={setTheme}
|
|
280
|
-
defaultTheme="activity"
|
|
281
|
-
/>
|
|
304
|
+
)}
|
|
282
305
|
</ChartContainer>
|
|
283
306
|
);
|
|
284
307
|
},
|
|
@@ -286,7 +309,28 @@ const ActivityMapChart = memo(
|
|
|
286
309
|
ActivityMapChart.displayName = "ActivityMapChart";
|
|
287
310
|
|
|
288
311
|
/**
|
|
289
|
-
*
|
|
312
|
+
* ActivityMap component renders a chart that visualizes activity data
|
|
313
|
+
* over time, using either a scatter plot or a heatmap.
|
|
314
|
+
* It allows users to switch between different types of visualizations
|
|
315
|
+
* and customize the color palette used in the chart.
|
|
316
|
+
*
|
|
317
|
+
* @param {ActivityMapProps} props - The properties for the ActivityMap component.
|
|
318
|
+
* @returns {JSX.Element} The rendered ActivityMap component.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```jsx
|
|
322
|
+
* <ActivityMap
|
|
323
|
+
* data={activityData}
|
|
324
|
+
* time="day-hour"
|
|
325
|
+
* type="heatmap"
|
|
326
|
+
* heatmapPalette={["#f0f8ff", "#faebd7", "#00ffff", "#7fffd4"]}
|
|
327
|
+
* highLabels={["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]}
|
|
328
|
+
* lowLabels={["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a", "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"]}
|
|
329
|
+
* onClick={(highIndex, lowIndex) => console.log(`Clicked on: ${highIndex}, ${lowIndex}`)}
|
|
330
|
+
* />
|
|
331
|
+
* ```
|
|
332
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-activitymap--docs} for more details on the properties.
|
|
333
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-scatter} for more details on the ECharts scatter series.
|
|
290
334
|
*/
|
|
291
335
|
export const ActivityMap: FC<ActivityMapProps> = (props) => (
|
|
292
336
|
<ChartWrapper>
|
|
@@ -23,13 +23,12 @@
|
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
Button,
|
|
26
|
-
CoreIcons,
|
|
27
26
|
Divider,
|
|
28
27
|
ToggleButtonGroup,
|
|
29
28
|
useMemoDebugger,
|
|
30
29
|
} from "@react-fabric/core";
|
|
31
30
|
import { compareValues, Format, isEmpty } from "@react-fabric/utilities";
|
|
32
|
-
import { type
|
|
31
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
33
32
|
import { memo, useEffect, useRef, useState, type FC } from "react";
|
|
34
33
|
import { type BaseChart, type CountType } from "../types";
|
|
35
34
|
import { countRenderer } from "../types/utils";
|
|
@@ -38,17 +37,22 @@ import { ChartWrapper } from "../wrapper/ChartWrapper";
|
|
|
38
37
|
import { PaletteSelect } from "../wrapper/PaletteSelect";
|
|
39
38
|
|
|
40
39
|
export interface CountSeriesProps extends BaseChart, CountType {
|
|
40
|
+
seriesName?: string;
|
|
41
41
|
type?: "pie" | "bar" | "column";
|
|
42
42
|
onClick?: (key: string) => void;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const CountSeriesChart: FC<CountSeriesProps> = memo(
|
|
46
46
|
({
|
|
47
|
-
|
|
47
|
+
series: _series,
|
|
48
48
|
title,
|
|
49
|
+
seriesName,
|
|
49
50
|
onExport,
|
|
50
51
|
theme: chartTheme,
|
|
51
52
|
type: chartType = "pie",
|
|
53
|
+
options: optionOverride,
|
|
54
|
+
showThemeSelector,
|
|
55
|
+
showTypeSelector,
|
|
52
56
|
onClick,
|
|
53
57
|
}: CountSeriesProps) => {
|
|
54
58
|
const chartRef = useRef<EChartsType>(null);
|
|
@@ -62,41 +66,45 @@ const CountSeriesChart: FC<CountSeriesProps> = memo(
|
|
|
62
66
|
setTheme(chartTheme);
|
|
63
67
|
}, [chartTheme]);
|
|
64
68
|
|
|
65
|
-
const options = useMemoDebugger<
|
|
69
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
66
70
|
() => {
|
|
67
|
-
if (isEmpty(
|
|
71
|
+
if (isEmpty(_series)) {
|
|
68
72
|
chartRef.current?.clear();
|
|
69
73
|
return {};
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
const sorted =
|
|
76
|
+
const sorted = _series?.sort(compareValues("desc", "count"));
|
|
73
77
|
|
|
74
|
-
const categoryAxis: AnyObject =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
const categoryAxis: AnyObject = Object.assign(
|
|
79
|
+
{},
|
|
80
|
+
optionOverride?.xAxis,
|
|
81
|
+
{
|
|
82
|
+
type: "category",
|
|
83
|
+
name: seriesName ?? "Count Series",
|
|
84
|
+
nameLocation: "center",
|
|
85
|
+
axisTick: {
|
|
86
|
+
show: false,
|
|
87
|
+
},
|
|
88
|
+
data: [],
|
|
89
|
+
} as EChartsOption["xAxis"],
|
|
90
|
+
);
|
|
91
|
+
const valueAxis: AnyObject = Object.assign({}, optionOverride?.yAxis, {
|
|
84
92
|
type: "value",
|
|
85
93
|
axisLabel: {
|
|
86
94
|
formatter: (val: AnyObject) => Format.number(val),
|
|
87
95
|
},
|
|
88
|
-
} as
|
|
96
|
+
} as EChartsOption["yAxis"]);
|
|
89
97
|
|
|
90
98
|
const series =
|
|
91
99
|
type === "pie"
|
|
92
100
|
? [
|
|
93
101
|
{
|
|
94
102
|
type: "pie",
|
|
95
|
-
name:
|
|
103
|
+
name: seriesName ?? "Count Series",
|
|
96
104
|
data: sorted.map((item, index) => ({
|
|
97
105
|
id: item.id,
|
|
98
106
|
value: item.count,
|
|
99
|
-
name: item.
|
|
107
|
+
name: item.name ?? item.id,
|
|
100
108
|
})),
|
|
101
109
|
universalTransition: true,
|
|
102
110
|
},
|
|
@@ -113,14 +121,15 @@ const CountSeriesChart: FC<CountSeriesProps> = memo(
|
|
|
113
121
|
},
|
|
114
122
|
data: [
|
|
115
123
|
{
|
|
116
|
-
name:
|
|
124
|
+
name: seriesName ?? "Count Series",
|
|
117
125
|
value: item.count,
|
|
118
126
|
},
|
|
119
127
|
],
|
|
120
|
-
name: item.
|
|
128
|
+
name: item.name ?? item.id,
|
|
121
129
|
universalTransition: true,
|
|
122
130
|
}));
|
|
123
131
|
return {
|
|
132
|
+
...optionOverride,
|
|
124
133
|
series,
|
|
125
134
|
countSeries: true,
|
|
126
135
|
xAxis:
|
|
@@ -129,7 +138,7 @@ const CountSeriesChart: FC<CountSeriesProps> = memo(
|
|
|
129
138
|
type === "pie" ? null : type === "bar" ? categoryAxis : valueAxis,
|
|
130
139
|
};
|
|
131
140
|
},
|
|
132
|
-
[
|
|
141
|
+
[_series, seriesName, type, optionOverride],
|
|
133
142
|
"CountChart options",
|
|
134
143
|
);
|
|
135
144
|
|
|
@@ -140,36 +149,40 @@ const CountSeriesChart: FC<CountSeriesProps> = memo(
|
|
|
140
149
|
theme={theme}
|
|
141
150
|
options={options}
|
|
142
151
|
chartRef={chartRef}
|
|
143
|
-
isEmpty={isEmpty(
|
|
144
|
-
emptyIcon=
|
|
152
|
+
isEmpty={isEmpty(_series)}
|
|
153
|
+
emptyIcon="icon-[mdi--chart-pie]"
|
|
145
154
|
dataTableRenderer={countRenderer}
|
|
146
155
|
onClick={(e) => onClick?.(e.data.id ?? e.seriesId)}
|
|
147
156
|
>
|
|
148
|
-
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
157
|
+
{showTypeSelector && (
|
|
158
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
159
|
+
<Button
|
|
160
|
+
size="sm"
|
|
161
|
+
variant="link"
|
|
162
|
+
value="pie"
|
|
163
|
+
aria-label="pie"
|
|
164
|
+
icon="icon-[mdi--chart-pie]"
|
|
165
|
+
/>
|
|
166
|
+
<Button
|
|
167
|
+
size="sm"
|
|
168
|
+
variant="link"
|
|
169
|
+
value="column"
|
|
170
|
+
aria-label="column"
|
|
171
|
+
icon="icon-[mdi--chart-bar]"
|
|
172
|
+
/>
|
|
173
|
+
<Button
|
|
174
|
+
size="sm"
|
|
175
|
+
variant="link"
|
|
176
|
+
value="bar"
|
|
177
|
+
aria-label="bar"
|
|
178
|
+
icon="icon-[mdi--chart-bar] rotate-90 -scale-x-100"
|
|
179
|
+
/>
|
|
180
|
+
</ToggleButtonGroup>
|
|
181
|
+
)}
|
|
182
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
183
|
+
{showThemeSelector && (
|
|
184
|
+
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
185
|
+
)}
|
|
173
186
|
</ChartContainer>
|
|
174
187
|
);
|
|
175
188
|
},
|
|
@@ -177,7 +190,33 @@ const CountSeriesChart: FC<CountSeriesProps> = memo(
|
|
|
177
190
|
CountSeriesChart.displayName = "CountSeriesChart";
|
|
178
191
|
|
|
179
192
|
/**
|
|
180
|
-
*
|
|
193
|
+
* CountSeries component renders a chart that displays counts of items in various formats.
|
|
194
|
+
* It supports pie, bar, and column charts.
|
|
195
|
+
* It can be used to visualize the distribution of counts across different categories.
|
|
196
|
+
* It allows users to switch between different types of visualizations and customize the color palette used in the chart.
|
|
197
|
+
*
|
|
198
|
+
* @param {CountSeriesProps} props - The properties for the CountSeries component.
|
|
199
|
+
* @returns {JSX.Element} The rendered CountSeries component.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```jsx
|
|
203
|
+
* <CountSeries
|
|
204
|
+
* data={[
|
|
205
|
+
* { id: "A", label: "Category A", count: 10 },
|
|
206
|
+
* { id: "B", label: "Category B", count: 20 },
|
|
207
|
+
* { id: "C", label: "Category C", count: 30 },
|
|
208
|
+
* ]}
|
|
209
|
+
* title="Count Distribution"
|
|
210
|
+
* onExport={() => console.log("Exporting chart data")}
|
|
211
|
+
* theme="light"
|
|
212
|
+
* type="pie"
|
|
213
|
+
* onClick={(key) => console.log("Clicked on:", key)}
|
|
214
|
+
* />
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-countseries--docs} for more details on the properties.
|
|
218
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-pie} for more details on the ECharts pie series options.
|
|
219
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-bar} for more details on the ECharts bar series options.
|
|
181
220
|
*/
|
|
182
221
|
export const CountSeries: FC<CountSeriesProps> = (props) => (
|
|
183
222
|
<ChartWrapper>
|