@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
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
useMemoDebugger,
|
|
30
30
|
} from "@react-fabric/core";
|
|
31
31
|
import { 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 SeriesType } from "../types";
|
|
35
35
|
import { seriesRenderer } from "../types/utils";
|
|
@@ -51,12 +51,15 @@ export interface DataSeriesProps extends BaseChart, SeriesType {
|
|
|
51
51
|
|
|
52
52
|
const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
53
53
|
({
|
|
54
|
-
|
|
54
|
+
series: _series,
|
|
55
55
|
onExport,
|
|
56
56
|
categories,
|
|
57
57
|
categoryAxisName,
|
|
58
58
|
valueAxisName,
|
|
59
59
|
title,
|
|
60
|
+
options: optionOverride,
|
|
61
|
+
showThemeSelector,
|
|
62
|
+
showTypeSelector,
|
|
60
63
|
theme: chartTheme,
|
|
61
64
|
type: chartType = "column",
|
|
62
65
|
onClick,
|
|
@@ -72,9 +75,9 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
72
75
|
setTheme(chartTheme);
|
|
73
76
|
}, [chartTheme]);
|
|
74
77
|
|
|
75
|
-
const options = useMemoDebugger<
|
|
78
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
76
79
|
() => {
|
|
77
|
-
if (isEmpty(
|
|
80
|
+
if (isEmpty(_series)) {
|
|
78
81
|
chartRef.current?.clear();
|
|
79
82
|
return {};
|
|
80
83
|
}
|
|
@@ -82,7 +85,9 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
82
85
|
const stack = type.includes("stacked") ? "stack" : undefined;
|
|
83
86
|
|
|
84
87
|
const [_type, stacked] = type.split("-");
|
|
85
|
-
const categoryAxis: AnyObject =
|
|
88
|
+
const categoryAxis: AnyObject = Object.assign(
|
|
89
|
+
{},
|
|
90
|
+
optionOverride?.xAxis,
|
|
86
91
|
_type === "radar"
|
|
87
92
|
? undefined
|
|
88
93
|
: ({
|
|
@@ -94,8 +99,11 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
94
99
|
show: false,
|
|
95
100
|
},
|
|
96
101
|
data: categories,
|
|
97
|
-
} as
|
|
98
|
-
|
|
102
|
+
} as EChartsOption["xAxis"]),
|
|
103
|
+
);
|
|
104
|
+
const valueAxis: AnyObject = Object.assign(
|
|
105
|
+
{},
|
|
106
|
+
optionOverride?.yAxis,
|
|
99
107
|
_type === "radar"
|
|
100
108
|
? undefined
|
|
101
109
|
: ({
|
|
@@ -103,18 +111,19 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
103
111
|
type: "value",
|
|
104
112
|
nameGap: 32,
|
|
105
113
|
nameLocation: "center",
|
|
106
|
-
} as
|
|
114
|
+
} as EChartsOption["yAxis"]),
|
|
115
|
+
);
|
|
107
116
|
const radar =
|
|
108
117
|
_type !== "radar"
|
|
109
118
|
? undefined
|
|
110
|
-
: ({
|
|
119
|
+
: Object.assign({}, optionOverride?.radar, {
|
|
111
120
|
shape: "circle",
|
|
112
121
|
indicator: categories?.map((c) => ({ name: c })),
|
|
113
122
|
} as AnyObject);
|
|
114
123
|
|
|
115
|
-
const series =
|
|
116
|
-
|
|
117
|
-
stack,
|
|
124
|
+
const series = _series?.map((item, index) => ({
|
|
125
|
+
...item,
|
|
126
|
+
stack: item.stack ?? stack,
|
|
118
127
|
areaStyle: stacked ? {} : undefined,
|
|
119
128
|
type: _type === "column" ? "bar" : _type,
|
|
120
129
|
name: item.label ?? item.id,
|
|
@@ -123,27 +132,39 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
123
132
|
_type === "radar"
|
|
124
133
|
? [
|
|
125
134
|
{
|
|
126
|
-
value: item.
|
|
135
|
+
value: item.data,
|
|
127
136
|
id: item.id,
|
|
128
|
-
name: item.
|
|
137
|
+
name: item.name ?? item.id,
|
|
129
138
|
},
|
|
130
139
|
]
|
|
131
|
-
: item.
|
|
140
|
+
: item.data,
|
|
132
141
|
}));
|
|
133
142
|
|
|
134
143
|
return {
|
|
144
|
+
...optionOverride,
|
|
135
145
|
xAxis: type.startsWith("bar") ? valueAxis : categoryAxis,
|
|
136
146
|
yAxis: type.startsWith("bar") ? categoryAxis : valueAxis,
|
|
137
147
|
radar,
|
|
138
148
|
series,
|
|
139
|
-
tooltip:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
tooltip: Object.assign(
|
|
150
|
+
{
|
|
151
|
+
trigger: _type === "radar" ? "item" : "axis",
|
|
152
|
+
confine: true,
|
|
153
|
+
position: "top",
|
|
154
|
+
appendToBody: true,
|
|
155
|
+
} as AnyObject,
|
|
156
|
+
optionOverride?.tooltip,
|
|
157
|
+
),
|
|
144
158
|
};
|
|
145
159
|
},
|
|
146
|
-
[
|
|
160
|
+
[
|
|
161
|
+
_series,
|
|
162
|
+
type,
|
|
163
|
+
categories,
|
|
164
|
+
categoryAxisName,
|
|
165
|
+
valueAxisName,
|
|
166
|
+
optionOverride,
|
|
167
|
+
],
|
|
147
168
|
"DataChart options",
|
|
148
169
|
);
|
|
149
170
|
|
|
@@ -154,64 +175,68 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
154
175
|
theme={theme}
|
|
155
176
|
options={options}
|
|
156
177
|
chartRef={chartRef}
|
|
157
|
-
isEmpty={isEmpty(
|
|
178
|
+
isEmpty={isEmpty(_series)}
|
|
158
179
|
emptyIcon={CoreIcons.chartColumn}
|
|
159
180
|
dataTableRenderer={seriesRenderer}
|
|
160
181
|
onClick={(e) => onClick?.({ category: e.name, series: e.seriesId })}
|
|
161
182
|
>
|
|
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
|
-
|
|
183
|
+
{showTypeSelector && (
|
|
184
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
185
|
+
<Button
|
|
186
|
+
size="sm"
|
|
187
|
+
variant="link"
|
|
188
|
+
icon={CoreIcons.chartLine}
|
|
189
|
+
aria-label="line"
|
|
190
|
+
value="line"
|
|
191
|
+
/>
|
|
192
|
+
<Button
|
|
193
|
+
size="sm"
|
|
194
|
+
variant="link"
|
|
195
|
+
icon={CoreIcons.chartColumn}
|
|
196
|
+
aria-label="column"
|
|
197
|
+
value="column"
|
|
198
|
+
/>
|
|
199
|
+
<Button
|
|
200
|
+
size="sm"
|
|
201
|
+
variant="link"
|
|
202
|
+
icon={CoreIcons.chartBar}
|
|
203
|
+
aria-label="bar"
|
|
204
|
+
value="bar"
|
|
205
|
+
/>
|
|
206
|
+
<Button
|
|
207
|
+
size="sm"
|
|
208
|
+
variant="link"
|
|
209
|
+
icon={CoreIcons.chartRadar}
|
|
210
|
+
aria-label="radar"
|
|
211
|
+
value="radar"
|
|
212
|
+
/>
|
|
213
|
+
<Button
|
|
214
|
+
size="sm"
|
|
215
|
+
variant="link"
|
|
216
|
+
icon={CoreIcons.chartLineStacked}
|
|
217
|
+
aria-label="line-stacked"
|
|
218
|
+
value="line-stacked"
|
|
219
|
+
/>
|
|
220
|
+
<Button
|
|
221
|
+
size="sm"
|
|
222
|
+
variant="link"
|
|
223
|
+
icon={CoreIcons.chartColumnStacked}
|
|
224
|
+
aria-label="column-stacked"
|
|
225
|
+
value="column-stacked"
|
|
226
|
+
/>
|
|
227
|
+
<Button
|
|
228
|
+
size="sm"
|
|
229
|
+
variant="link"
|
|
230
|
+
icon={CoreIcons.chartBarStacked}
|
|
231
|
+
aria-label="bar-stacked"
|
|
232
|
+
value="bar-stacked"
|
|
233
|
+
/>
|
|
234
|
+
</ToggleButtonGroup>
|
|
235
|
+
)}
|
|
236
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
237
|
+
{showThemeSelector && (
|
|
238
|
+
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
239
|
+
)}
|
|
215
240
|
</ChartContainer>
|
|
216
241
|
);
|
|
217
242
|
},
|
|
@@ -219,7 +244,32 @@ const DataSeriesChart: FC<DataSeriesProps> = memo(
|
|
|
219
244
|
DataSeriesChart.displayName = "DataSeriesChart";
|
|
220
245
|
|
|
221
246
|
/**
|
|
222
|
-
*
|
|
247
|
+
* DataSeries component renders a chart for visualizing data series.
|
|
248
|
+
* It supports various chart types such as column, line, bar, radar, and stacked variants.
|
|
249
|
+
* It allows users to click on data points to trigger custom actions.
|
|
250
|
+
*
|
|
251
|
+
* @param {DataSeriesProps} props - The properties for the DataSeries component.
|
|
252
|
+
* @returns {JSX.Element} The rendered DataSeries component.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```jsx
|
|
256
|
+
* <DataSeries
|
|
257
|
+
* data={[{ id: "1", label: "Series 1", values: [10, 20, 30] }]}
|
|
258
|
+
* categories={["Category 1", "Category 2", "Category 3"]}
|
|
259
|
+
* categoryAxisName="Categories"
|
|
260
|
+
* valueAxisName="Values"
|
|
261
|
+
* title="Data Series Example"
|
|
262
|
+
* type="column"
|
|
263
|
+
* onClick={(data) => console.log("Clicked data:", data)}
|
|
264
|
+
* onExport={() => console.log("Exporting chart data")}
|
|
265
|
+
* theme="light"
|
|
266
|
+
* />
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-dataseries--docs} for more details on the properties.
|
|
270
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-bar} for ECharts bar series options.
|
|
271
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-line} for ECharts line series options.
|
|
272
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-radar} for ECharts radar series options.
|
|
223
273
|
*/
|
|
224
274
|
export const DataSeries: FC<DataSeriesProps> = (props) => (
|
|
225
275
|
<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,10 +28,10 @@ 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";
|
|
@@ -45,27 +45,35 @@ import {
|
|
|
45
45
|
import WorldMap from "../types/world.svg";
|
|
46
46
|
echarts.registerMap("world", { svg: WorldMap });
|
|
47
47
|
|
|
48
|
-
export interface MapSeriesProps extends BaseChart
|
|
48
|
+
export interface MapSeriesProps extends BaseChart {
|
|
49
|
+
series: Array<{ id: string; label?: string; count: number }>;
|
|
49
50
|
onClick?: (key: string) => void;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
53
|
-
({
|
|
54
|
+
({
|
|
55
|
+
series,
|
|
56
|
+
onExport,
|
|
57
|
+
theme: chartTheme,
|
|
58
|
+
showTypeSelector,
|
|
59
|
+
title,
|
|
60
|
+
onClick,
|
|
61
|
+
}: MapSeriesProps) => {
|
|
54
62
|
const chartRef = useRef<EChartsType>(null);
|
|
55
63
|
const [type, setType] = useState("map");
|
|
56
64
|
const [zoom, setZoom] = useState(1.25);
|
|
57
65
|
|
|
58
|
-
const options = useMemoDebugger<
|
|
66
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
59
67
|
() => {
|
|
60
|
-
if (isEmpty(
|
|
68
|
+
if (isEmpty(series)) return {};
|
|
61
69
|
|
|
62
|
-
const sorted =
|
|
70
|
+
const sorted = series
|
|
63
71
|
.map((d) => ({
|
|
64
72
|
...d,
|
|
65
73
|
label: d.label ?? Countries.name(d.id),
|
|
66
74
|
}))
|
|
67
75
|
.sort(compareValues("desc", "count"));
|
|
68
|
-
const valueMap =
|
|
76
|
+
const valueMap = series.map((d) => d.count);
|
|
69
77
|
|
|
70
78
|
if (type === "column") {
|
|
71
79
|
return {
|
|
@@ -148,13 +156,13 @@ const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
|
148
156
|
],
|
|
149
157
|
};
|
|
150
158
|
},
|
|
151
|
-
[
|
|
159
|
+
[series, title, type],
|
|
152
160
|
"MapChart options",
|
|
153
161
|
);
|
|
154
162
|
|
|
155
163
|
useEffect(() => {
|
|
156
164
|
setZoom(1.25);
|
|
157
|
-
}, [
|
|
165
|
+
}, [series, type]);
|
|
158
166
|
|
|
159
167
|
useEffect(() => {
|
|
160
168
|
chartRef.current?.setOption({
|
|
@@ -185,22 +193,24 @@ const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
|
185
193
|
onChange={(e) => setZoom(e.target.valueAsNumber)}
|
|
186
194
|
/>
|
|
187
195
|
)}
|
|
188
|
-
|
|
189
|
-
<
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
196
|
+
{showTypeSelector && (
|
|
197
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
198
|
+
<Button
|
|
199
|
+
size="sm"
|
|
200
|
+
variant="link"
|
|
201
|
+
icon={CoreIcons.map}
|
|
202
|
+
aria-label="map"
|
|
203
|
+
value="map"
|
|
204
|
+
/>
|
|
205
|
+
<Button
|
|
206
|
+
size="sm"
|
|
207
|
+
variant="link"
|
|
208
|
+
icon={CoreIcons.chartColumn}
|
|
209
|
+
aria-label="column"
|
|
210
|
+
value="column"
|
|
211
|
+
/>
|
|
212
|
+
</ToggleButtonGroup>
|
|
213
|
+
)}
|
|
204
214
|
</ChartContainer>
|
|
205
215
|
);
|
|
206
216
|
},
|
|
@@ -208,7 +218,30 @@ const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
|
208
218
|
MapSeriesChart.displayName = "MapSeriesChart";
|
|
209
219
|
|
|
210
220
|
/**
|
|
211
|
-
*
|
|
221
|
+
* MapSeries component renders a map chart using ECharts.
|
|
222
|
+
* It displays data on a world map, allowing users to visualize counts or other metrics by country.
|
|
223
|
+
* It supports zooming and switching between map and column views.
|
|
224
|
+
*
|
|
225
|
+
* @param {MapSeriesProps} props - The properties for the MapSeries component.
|
|
226
|
+
* @returns {JSX.Element} The rendered MapSeries component.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```jsx
|
|
230
|
+
* <MapSeries
|
|
231
|
+
* data={[
|
|
232
|
+
* { id: "US", label: "United States", count: 100 },
|
|
233
|
+
* { id: "IN", label: "India", count: 200 },
|
|
234
|
+
* { id: "CN", label: "China", count: 300 },
|
|
235
|
+
* ]}
|
|
236
|
+
* onExport={() => console.log("Exporting chart")}
|
|
237
|
+
* title="World Map Series"
|
|
238
|
+
* onClick={(key) => console.log("Clicked country:", key)}
|
|
239
|
+
* theme="light"
|
|
240
|
+
* />
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-mapseries--docs} for more details on the properties.
|
|
244
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-map} for ECharts map series options documentation.
|
|
212
245
|
*/
|
|
213
246
|
export const MapSeries: FC<MapSeriesProps> = (props) => (
|
|
214
247
|
<ChartWrapper>
|