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