@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
|
@@ -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 { 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 SeriesType } from "../types";
|
|
35
34
|
import { seriesRenderer } from "../types/utils";
|
|
@@ -51,12 +50,15 @@ export interface DataSeriesProps extends BaseChart, SeriesType {
|
|
|
51
50
|
|
|
52
51
|
const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
53
52
|
({
|
|
54
|
-
|
|
53
|
+
series: _series,
|
|
55
54
|
onExport,
|
|
56
55
|
categories,
|
|
57
56
|
categoryAxisName,
|
|
58
57
|
valueAxisName,
|
|
59
58
|
title,
|
|
59
|
+
options: optionOverride,
|
|
60
|
+
showThemeSelector,
|
|
61
|
+
showTypeSelector,
|
|
60
62
|
theme: chartTheme,
|
|
61
63
|
type: chartType = "column",
|
|
62
64
|
onClick,
|
|
@@ -72,9 +74,9 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
72
74
|
setTheme(chartTheme);
|
|
73
75
|
}, [chartTheme]);
|
|
74
76
|
|
|
75
|
-
const options = useMemoDebugger<
|
|
77
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
76
78
|
() => {
|
|
77
|
-
if (isEmpty(
|
|
79
|
+
if (isEmpty(_series)) {
|
|
78
80
|
chartRef.current?.clear();
|
|
79
81
|
return {};
|
|
80
82
|
}
|
|
@@ -82,7 +84,9 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
82
84
|
const stack = type.includes("stacked") ? "stack" : undefined;
|
|
83
85
|
|
|
84
86
|
const [_type, stacked] = type.split("-");
|
|
85
|
-
const categoryAxis: AnyObject =
|
|
87
|
+
const categoryAxis: AnyObject = Object.assign(
|
|
88
|
+
{},
|
|
89
|
+
optionOverride?.xAxis,
|
|
86
90
|
_type === "radar"
|
|
87
91
|
? undefined
|
|
88
92
|
: ({
|
|
@@ -94,8 +98,11 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
94
98
|
show: false,
|
|
95
99
|
},
|
|
96
100
|
data: categories,
|
|
97
|
-
} as
|
|
98
|
-
|
|
101
|
+
} as EChartsOption["xAxis"]),
|
|
102
|
+
);
|
|
103
|
+
const valueAxis: AnyObject = Object.assign(
|
|
104
|
+
{},
|
|
105
|
+
optionOverride?.yAxis,
|
|
99
106
|
_type === "radar"
|
|
100
107
|
? undefined
|
|
101
108
|
: ({
|
|
@@ -103,18 +110,19 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
103
110
|
type: "value",
|
|
104
111
|
nameGap: 32,
|
|
105
112
|
nameLocation: "center",
|
|
106
|
-
} as
|
|
113
|
+
} as EChartsOption["yAxis"]),
|
|
114
|
+
);
|
|
107
115
|
const radar =
|
|
108
116
|
_type !== "radar"
|
|
109
117
|
? undefined
|
|
110
|
-
: ({
|
|
118
|
+
: Object.assign({}, optionOverride?.radar, {
|
|
111
119
|
shape: "circle",
|
|
112
120
|
indicator: categories?.map((c) => ({ name: c })),
|
|
113
121
|
} as AnyObject);
|
|
114
122
|
|
|
115
|
-
const series =
|
|
116
|
-
|
|
117
|
-
stack,
|
|
123
|
+
const series = _series?.map((item, index) => ({
|
|
124
|
+
...item,
|
|
125
|
+
stack: item.stack ?? stack,
|
|
118
126
|
areaStyle: stacked ? {} : undefined,
|
|
119
127
|
type: _type === "column" ? "bar" : _type,
|
|
120
128
|
name: item.label ?? item.id,
|
|
@@ -123,27 +131,39 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
123
131
|
_type === "radar"
|
|
124
132
|
? [
|
|
125
133
|
{
|
|
126
|
-
value: item.
|
|
134
|
+
value: item.data,
|
|
127
135
|
id: item.id,
|
|
128
|
-
name: item.
|
|
136
|
+
name: item.name ?? item.id,
|
|
129
137
|
},
|
|
130
138
|
]
|
|
131
|
-
: item.
|
|
139
|
+
: item.data,
|
|
132
140
|
}));
|
|
133
141
|
|
|
134
142
|
return {
|
|
143
|
+
...optionOverride,
|
|
135
144
|
xAxis: type.startsWith("bar") ? valueAxis : categoryAxis,
|
|
136
145
|
yAxis: type.startsWith("bar") ? categoryAxis : valueAxis,
|
|
137
146
|
radar,
|
|
138
147
|
series,
|
|
139
|
-
tooltip:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
tooltip: Object.assign(
|
|
149
|
+
{
|
|
150
|
+
trigger: _type === "radar" ? "item" : "axis",
|
|
151
|
+
confine: true,
|
|
152
|
+
position: "top",
|
|
153
|
+
appendToBody: true,
|
|
154
|
+
} as AnyObject,
|
|
155
|
+
optionOverride?.tooltip,
|
|
156
|
+
),
|
|
144
157
|
};
|
|
145
158
|
},
|
|
146
|
-
[
|
|
159
|
+
[
|
|
160
|
+
_series,
|
|
161
|
+
type,
|
|
162
|
+
categories,
|
|
163
|
+
categoryAxisName,
|
|
164
|
+
valueAxisName,
|
|
165
|
+
optionOverride,
|
|
166
|
+
],
|
|
147
167
|
"DataChart options",
|
|
148
168
|
);
|
|
149
169
|
|
|
@@ -154,64 +174,68 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
154
174
|
theme={theme}
|
|
155
175
|
options={options}
|
|
156
176
|
chartRef={chartRef}
|
|
157
|
-
isEmpty={isEmpty(
|
|
158
|
-
emptyIcon=
|
|
177
|
+
isEmpty={isEmpty(_series)}
|
|
178
|
+
emptyIcon="icon-[mdi--chart-bar]"
|
|
159
179
|
dataTableRenderer={seriesRenderer}
|
|
160
180
|
onClick={(e) => onClick?.({ category: e.name, series: e.seriesId })}
|
|
161
181
|
>
|
|
162
|
-
|
|
163
|
-
<
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
182
|
+
{showTypeSelector && (
|
|
183
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
184
|
+
<Button
|
|
185
|
+
size="sm"
|
|
186
|
+
variant="link"
|
|
187
|
+
icon="icon-[mdi--chart-line]"
|
|
188
|
+
aria-label="line"
|
|
189
|
+
value="line"
|
|
190
|
+
/>
|
|
191
|
+
<Button
|
|
192
|
+
size="sm"
|
|
193
|
+
variant="link"
|
|
194
|
+
icon="icon-[mdi--chart-bar]"
|
|
195
|
+
aria-label="column"
|
|
196
|
+
value="column"
|
|
197
|
+
/>
|
|
198
|
+
<Button
|
|
199
|
+
size="sm"
|
|
200
|
+
variant="link"
|
|
201
|
+
icon="icon-[mdi--chart-bar] rotate-90 -scale-x-100"
|
|
202
|
+
aria-label="bar"
|
|
203
|
+
value="bar"
|
|
204
|
+
/>
|
|
205
|
+
<Button
|
|
206
|
+
size="sm"
|
|
207
|
+
variant="link"
|
|
208
|
+
icon="icon-[mdi--radar]"
|
|
209
|
+
aria-label="radar"
|
|
210
|
+
value="radar"
|
|
211
|
+
/>
|
|
212
|
+
<Button
|
|
213
|
+
size="sm"
|
|
214
|
+
variant="link"
|
|
215
|
+
icon="icon-[mdi--chart-line-stacked]"
|
|
216
|
+
aria-label="line-stacked"
|
|
217
|
+
value="line-stacked"
|
|
218
|
+
/>
|
|
219
|
+
<Button
|
|
220
|
+
size="sm"
|
|
221
|
+
variant="link"
|
|
222
|
+
icon="icon-[mdi--chart-bar-stacked]"
|
|
223
|
+
aria-label="column-stacked"
|
|
224
|
+
value="column-stacked"
|
|
225
|
+
/>
|
|
226
|
+
<Button
|
|
227
|
+
size="sm"
|
|
228
|
+
variant="link"
|
|
229
|
+
icon="icon-[mdi--chart-bar-stacked] rotate-90 -scale-x-100"
|
|
230
|
+
aria-label="bar-stacked"
|
|
231
|
+
value="bar-stacked"
|
|
232
|
+
/>
|
|
233
|
+
</ToggleButtonGroup>
|
|
234
|
+
)}
|
|
235
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
236
|
+
{showThemeSelector && (
|
|
237
|
+
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
238
|
+
)}
|
|
215
239
|
</ChartContainer>
|
|
216
240
|
);
|
|
217
241
|
},
|
|
@@ -219,7 +243,32 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
219
243
|
DataSeriesChart.displayName = "DataSeriesChart";
|
|
220
244
|
|
|
221
245
|
/**
|
|
222
|
-
*
|
|
246
|
+
* DataSeries component renders a chart for visualizing data series.
|
|
247
|
+
* It supports various chart types such as column, line, bar, radar, and stacked variants.
|
|
248
|
+
* It allows users to click on data points to trigger custom actions.
|
|
249
|
+
*
|
|
250
|
+
* @param {DataSeriesProps} props - The properties for the DataSeries component.
|
|
251
|
+
* @returns {JSX.Element} The rendered DataSeries component.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```jsx
|
|
255
|
+
* <DataSeries
|
|
256
|
+
* data={[{ id: "1", label: "Series 1", values: [10, 20, 30] }]}
|
|
257
|
+
* categories={["Category 1", "Category 2", "Category 3"]}
|
|
258
|
+
* categoryAxisName="Categories"
|
|
259
|
+
* valueAxisName="Values"
|
|
260
|
+
* title="Data Series Example"
|
|
261
|
+
* type="column"
|
|
262
|
+
* onClick={(data) => console.log("Clicked data:", data)}
|
|
263
|
+
* onExport={() => console.log("Exporting chart data")}
|
|
264
|
+
* theme="light"
|
|
265
|
+
* />
|
|
266
|
+
* ```
|
|
267
|
+
*
|
|
268
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-dataseries--docs} for more details on the properties.
|
|
269
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-bar} for ECharts bar series options.
|
|
270
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-line} for ECharts line series options.
|
|
271
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-radar} for ECharts radar series options.
|
|
223
272
|
*/
|
|
224
273
|
export const DataSeries: FC<DataSeriesProps> = (props) => (
|
|
225
274
|
<ChartWrapper>
|
package/src/charts/Generic.tsx
CHANGED
|
@@ -21,67 +21,41 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { type
|
|
24
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
25
25
|
import {
|
|
26
26
|
memo,
|
|
27
27
|
useEffect,
|
|
28
28
|
useImperativeHandle,
|
|
29
29
|
useRef,
|
|
30
|
+
useState,
|
|
30
31
|
type FC,
|
|
31
|
-
type
|
|
32
|
+
type Ref,
|
|
32
33
|
} from "react";
|
|
33
|
-
import { type
|
|
34
|
+
import { type Theme } from "../types";
|
|
34
35
|
import { ChartContainer } from "../wrapper/ChartContainer";
|
|
35
36
|
import { ChartWrapper } from "../wrapper/ChartWrapper";
|
|
37
|
+
import { PaletteSelect } from "../wrapper/PaletteSelect";
|
|
36
38
|
|
|
37
|
-
export interface GenericProps extends
|
|
38
|
-
chartRef?:
|
|
39
|
+
export interface GenericProps extends Omit<EChartsOption, "title"> {
|
|
40
|
+
chartRef?: Ref<EChartsType>;
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
toolbox?: EChartOption["toolbox"];
|
|
42
|
-
tooltip?: EChartOption["tooltip"];
|
|
42
|
+
title?: string;
|
|
43
43
|
|
|
44
44
|
actions?: JSX.Element;
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* The theme to be applied to the chart.
|
|
48
|
+
* This can be one of the predefined themes or a custom theme object.
|
|
49
|
+
* Predefined themes include "default", "activity", "cloud", "qualitative", "diverging", "sequential",
|
|
50
|
+
* "spectral", "uber", "fireice", "warming", "sunrise", "ocean", "wine", "red", "green", and "blue".
|
|
48
51
|
*/
|
|
49
|
-
|
|
52
|
+
theme?: Theme;
|
|
50
53
|
/**
|
|
51
|
-
*
|
|
54
|
+
* Whether to show the theme selector in the chart.
|
|
55
|
+
* This is useful for allowing users to switch between different themes.
|
|
56
|
+
* If set to true, the chart will render a toggle button group to select the theme.
|
|
52
57
|
*/
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* chart series
|
|
56
|
-
*/
|
|
57
|
-
series?: EChartOption["series"];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* polar series
|
|
61
|
-
*/
|
|
62
|
-
polar?: EChartOption["polar"];
|
|
63
|
-
/**
|
|
64
|
-
* polar axis
|
|
65
|
-
*/
|
|
66
|
-
angleAxis?: EChartOption["angleAxis"];
|
|
67
|
-
/**
|
|
68
|
-
* polar axis
|
|
69
|
-
*/
|
|
70
|
-
radiusAxis?: EChartOption["radiusAxis"];
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* radar series
|
|
74
|
-
*/
|
|
75
|
-
radar?: EChartOption["radar"];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* paarllel series
|
|
79
|
-
*/
|
|
80
|
-
parallel?: EChartOption["parallel"];
|
|
81
|
-
/**
|
|
82
|
-
* parallel axis
|
|
83
|
-
*/
|
|
84
|
-
parallelAxis?: EChartOption["parallelAxis"];
|
|
58
|
+
showThemeSelector?: boolean;
|
|
85
59
|
|
|
86
60
|
onClick?: (e: KeyValue) => void;
|
|
87
61
|
onRendered?: (e: KeyValue) => void;
|
|
@@ -93,10 +67,10 @@ export interface GenericProps extends BaseChart {
|
|
|
93
67
|
/**
|
|
94
68
|
* Data table renderer that returns HTML string
|
|
95
69
|
*/
|
|
96
|
-
dataTableRenderer?: (chartOption:
|
|
70
|
+
dataTableRenderer?: (chartOption: EChartsOption) => string;
|
|
97
71
|
}
|
|
98
72
|
|
|
99
|
-
const GenericChartBase
|
|
73
|
+
const GenericChartBase = memo(
|
|
100
74
|
({
|
|
101
75
|
chartRef: _ref,
|
|
102
76
|
onBrush,
|
|
@@ -105,12 +79,14 @@ const GenericChartBase: FC<GenericProps> = memo(
|
|
|
105
79
|
dataTableRenderer,
|
|
106
80
|
onClick,
|
|
107
81
|
onRendered,
|
|
82
|
+
showThemeSelector,
|
|
108
83
|
actions,
|
|
109
84
|
title,
|
|
110
|
-
theme,
|
|
85
|
+
theme: chartTheme,
|
|
111
86
|
...options
|
|
112
87
|
}: GenericProps) => {
|
|
113
88
|
const chartRef = useRef<EChartsType>(null);
|
|
89
|
+
const [theme, setTheme] = useState(chartTheme);
|
|
114
90
|
|
|
115
91
|
useImperativeHandle<EChartsType | null, EChartsType | null>(
|
|
116
92
|
_ref,
|
|
@@ -121,7 +97,7 @@ const GenericChartBase: FC<GenericProps> = memo(
|
|
|
121
97
|
useEffect(() => {
|
|
122
98
|
const chart = chartRef.current;
|
|
123
99
|
if (chart && onRendered) {
|
|
124
|
-
chart.on("finished", onRendered);
|
|
100
|
+
chart.on("finished", onRendered as any);
|
|
125
101
|
return () => {
|
|
126
102
|
!chart.isDisposed() && chart.off("finished");
|
|
127
103
|
};
|
|
@@ -141,7 +117,7 @@ const GenericChartBase: FC<GenericProps> = memo(
|
|
|
141
117
|
useEffect(() => {
|
|
142
118
|
const chart = chartRef.current;
|
|
143
119
|
if (chart && onBrush) {
|
|
144
|
-
chart.on("brush", onBrush);
|
|
120
|
+
chart.on("brush", onBrush as any);
|
|
145
121
|
return () => {
|
|
146
122
|
!chart.isDisposed() && chart.off("brush");
|
|
147
123
|
};
|
|
@@ -151,7 +127,7 @@ const GenericChartBase: FC<GenericProps> = memo(
|
|
|
151
127
|
useEffect(() => {
|
|
152
128
|
const chart = chartRef.current;
|
|
153
129
|
if (chart && onBrushEnd) {
|
|
154
|
-
chart.on("brushend", onBrushEnd);
|
|
130
|
+
chart.on("brushend", onBrushEnd as any);
|
|
155
131
|
return () => {
|
|
156
132
|
!chart.isDisposed() && chart.off("brushend");
|
|
157
133
|
};
|
|
@@ -161,7 +137,7 @@ const GenericChartBase: FC<GenericProps> = memo(
|
|
|
161
137
|
useEffect(() => {
|
|
162
138
|
const chart = chartRef.current;
|
|
163
139
|
if (chart && onBrushSelected) {
|
|
164
|
-
chart.on("brushselected", onBrushSelected);
|
|
140
|
+
chart.on("brushselected", onBrushSelected as any);
|
|
165
141
|
return () => {
|
|
166
142
|
!chart.isDisposed() && chart.off("brushselected");
|
|
167
143
|
};
|
|
@@ -170,19 +146,35 @@ const GenericChartBase: FC<GenericProps> = memo(
|
|
|
170
146
|
|
|
171
147
|
return (
|
|
172
148
|
<ChartContainer
|
|
173
|
-
theme={theme}
|
|
174
149
|
options={options}
|
|
175
150
|
chartRef={chartRef}
|
|
151
|
+
theme={theme}
|
|
176
152
|
title={title}
|
|
177
153
|
dataTableRenderer={dataTableRenderer}
|
|
178
154
|
>
|
|
179
155
|
{actions}
|
|
156
|
+
{showThemeSelector && (
|
|
157
|
+
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
158
|
+
)}
|
|
180
159
|
</ChartContainer>
|
|
181
160
|
);
|
|
182
161
|
},
|
|
183
162
|
);
|
|
184
163
|
GenericChartBase.displayName = "GenericChart";
|
|
185
164
|
|
|
165
|
+
/**
|
|
166
|
+
* GenericChart component renders a generic chart using ECharts.
|
|
167
|
+
* It accepts various chart options and configurations, allowing for flexible chart rendering.
|
|
168
|
+
* It supports click events, brush events, and custom actions.
|
|
169
|
+
* It can be used to create a wide range of chart types by passing the appropriate ECharts options.
|
|
170
|
+
*
|
|
171
|
+
* @param props - The properties for the GenericChart component, including chart options, event handlers, and custom actions.
|
|
172
|
+
* @returns A React functional component that renders the chart within a ChartWrapper.
|
|
173
|
+
*
|
|
174
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-genericchart--docs} for more details on the properties.
|
|
175
|
+
* @see {@link https://echarts.apache.org/en/option.html} for ECharts options documentation.
|
|
176
|
+
* @see {@link https://echarts.apache.org/en/api.html#echartsInstance} for ECharts instance methods and properties.
|
|
177
|
+
*/
|
|
186
178
|
export const GenericChart: FC<GenericProps> = (props) => (
|
|
187
179
|
<ChartWrapper>
|
|
188
180
|
<GenericChartBase {...props} />
|
package/src/charts/MapSeries.tsx
CHANGED
|
@@ -28,44 +28,47 @@ import {
|
|
|
28
28
|
isEmpty,
|
|
29
29
|
} from "@react-fabric/utilities";
|
|
30
30
|
import * as echarts from "echarts";
|
|
31
|
-
import { type
|
|
31
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
32
32
|
import { memo, useEffect, useRef, useState, type FC } from "react";
|
|
33
33
|
import { ChartPalette } from "../theme/palettes";
|
|
34
|
-
import { type BaseChart
|
|
34
|
+
import { type BaseChart } from "../types";
|
|
35
35
|
import { countRenderer } from "../types/utils";
|
|
36
36
|
import { ChartContainer } from "../wrapper/ChartContainer";
|
|
37
37
|
import { ChartWrapper } from "../wrapper/ChartWrapper";
|
|
38
38
|
|
|
39
|
-
import {
|
|
40
|
-
Button,
|
|
41
|
-
CoreIcons,
|
|
42
|
-
ToggleButtonGroup,
|
|
43
|
-
useMemoDebugger,
|
|
44
|
-
} from "@react-fabric/core";
|
|
39
|
+
import { Button, ToggleButtonGroup, useMemoDebugger } from "@react-fabric/core";
|
|
45
40
|
import WorldMap from "../types/world.svg";
|
|
46
41
|
echarts.registerMap("world", { svg: WorldMap });
|
|
47
42
|
|
|
48
|
-
export interface MapSeriesProps extends BaseChart
|
|
43
|
+
export interface MapSeriesProps extends BaseChart {
|
|
44
|
+
series: Array<{ id: string; label?: string; count: number }>;
|
|
49
45
|
onClick?: (key: string) => void;
|
|
50
46
|
}
|
|
51
47
|
|
|
52
48
|
const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
53
|
-
({
|
|
49
|
+
({
|
|
50
|
+
series,
|
|
51
|
+
onExport,
|
|
52
|
+
theme: chartTheme,
|
|
53
|
+
showTypeSelector,
|
|
54
|
+
title,
|
|
55
|
+
onClick,
|
|
56
|
+
}: MapSeriesProps) => {
|
|
54
57
|
const chartRef = useRef<EChartsType>(null);
|
|
55
58
|
const [type, setType] = useState("map");
|
|
56
59
|
const [zoom, setZoom] = useState(1.25);
|
|
57
60
|
|
|
58
|
-
const options = useMemoDebugger<
|
|
61
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
59
62
|
() => {
|
|
60
|
-
if (isEmpty(
|
|
63
|
+
if (isEmpty(series)) return {};
|
|
61
64
|
|
|
62
|
-
const sorted =
|
|
65
|
+
const sorted = series
|
|
63
66
|
.map((d) => ({
|
|
64
67
|
...d,
|
|
65
68
|
label: d.label ?? Countries.name(d.id),
|
|
66
69
|
}))
|
|
67
70
|
.sort(compareValues("desc", "count"));
|
|
68
|
-
const valueMap =
|
|
71
|
+
const valueMap = series.map((d) => d.count);
|
|
69
72
|
|
|
70
73
|
if (type === "column") {
|
|
71
74
|
return {
|
|
@@ -148,13 +151,13 @@ const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
|
148
151
|
],
|
|
149
152
|
};
|
|
150
153
|
},
|
|
151
|
-
[
|
|
154
|
+
[series, title, type],
|
|
152
155
|
"MapChart options",
|
|
153
156
|
);
|
|
154
157
|
|
|
155
158
|
useEffect(() => {
|
|
156
159
|
setZoom(1.25);
|
|
157
|
-
}, [
|
|
160
|
+
}, [series, type]);
|
|
158
161
|
|
|
159
162
|
useEffect(() => {
|
|
160
163
|
chartRef.current?.setOption({
|
|
@@ -185,22 +188,24 @@ const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
|
185
188
|
onChange={(e) => setZoom(e.target.valueAsNumber)}
|
|
186
189
|
/>
|
|
187
190
|
)}
|
|
188
|
-
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
{showTypeSelector && (
|
|
192
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
193
|
+
<Button
|
|
194
|
+
size="sm"
|
|
195
|
+
variant="link"
|
|
196
|
+
icon="icon-[mdi--map]"
|
|
197
|
+
aria-label="map"
|
|
198
|
+
value="map"
|
|
199
|
+
/>
|
|
200
|
+
<Button
|
|
201
|
+
size="sm"
|
|
202
|
+
variant="link"
|
|
203
|
+
icon="icon-[mdi--chart-bar] rotate-90 -scale-x-100"
|
|
204
|
+
aria-label="column"
|
|
205
|
+
value="column"
|
|
206
|
+
/>
|
|
207
|
+
</ToggleButtonGroup>
|
|
208
|
+
)}
|
|
204
209
|
</ChartContainer>
|
|
205
210
|
);
|
|
206
211
|
},
|
|
@@ -208,7 +213,30 @@ const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
|
208
213
|
MapSeriesChart.displayName = "MapSeriesChart";
|
|
209
214
|
|
|
210
215
|
/**
|
|
211
|
-
*
|
|
216
|
+
* MapSeries component renders a map chart using ECharts.
|
|
217
|
+
* It displays data on a world map, allowing users to visualize counts or other metrics by country.
|
|
218
|
+
* It supports zooming and switching between map and column views.
|
|
219
|
+
*
|
|
220
|
+
* @param {MapSeriesProps} props - The properties for the MapSeries component.
|
|
221
|
+
* @returns {JSX.Element} The rendered MapSeries component.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```jsx
|
|
225
|
+
* <MapSeries
|
|
226
|
+
* data={[
|
|
227
|
+
* { id: "US", label: "United States", count: 100 },
|
|
228
|
+
* { id: "IN", label: "India", count: 200 },
|
|
229
|
+
* { id: "CN", label: "China", count: 300 },
|
|
230
|
+
* ]}
|
|
231
|
+
* onExport={() => console.log("Exporting chart")}
|
|
232
|
+
* title="World Map Series"
|
|
233
|
+
* onClick={(key) => console.log("Clicked country:", key)}
|
|
234
|
+
* theme="light"
|
|
235
|
+
* />
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-mapseries--docs} for more details on the properties.
|
|
239
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-map} for ECharts map series options documentation.
|
|
212
240
|
*/
|
|
213
241
|
export const MapSeries: FC<MapSeriesProps> = (props) => (
|
|
214
242
|
<ChartWrapper>
|