@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 ECharts, type EChartsOption } from "echarts";
|
|
33
33
|
import { memo, useCallback, useEffect, useRef, useState, type FC } from "react";
|
|
34
34
|
import { type BaseChart, type TimeSeriesType } from "../types";
|
|
35
35
|
import { timeSeriesRenderer } from "../types/utils";
|
|
@@ -45,17 +45,20 @@ export interface TimeSeriesProps extends BaseChart, TimeSeriesType {
|
|
|
45
45
|
|
|
46
46
|
const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
47
47
|
({
|
|
48
|
-
|
|
48
|
+
series: _series,
|
|
49
49
|
onExport,
|
|
50
50
|
categoryAxisName,
|
|
51
51
|
valueAxisName,
|
|
52
52
|
title,
|
|
53
|
+
showThemeSelector,
|
|
54
|
+
showTypeSelector,
|
|
53
55
|
theme: chartTheme,
|
|
54
56
|
type: chartType = "column",
|
|
57
|
+
options: optionOverride,
|
|
55
58
|
onClick,
|
|
56
59
|
onBrush,
|
|
57
60
|
}: TimeSeriesProps) => {
|
|
58
|
-
const chartRef = useRef<
|
|
61
|
+
const chartRef = useRef<ECharts>(null);
|
|
59
62
|
const [type, setType] = useState(chartType);
|
|
60
63
|
const [theme, setTheme] = useState(chartTheme);
|
|
61
64
|
|
|
@@ -90,7 +93,7 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
90
93
|
if (chart && !chart?.isDisposed()) {
|
|
91
94
|
enableBrush();
|
|
92
95
|
let range = [0, 0];
|
|
93
|
-
chart.on("brushselected", (e:
|
|
96
|
+
chart.on("brushselected", (e: any) => {
|
|
94
97
|
range = e.batch?.[0]?.areas?.[0]?.coordRange;
|
|
95
98
|
});
|
|
96
99
|
chart.on("brushEnd", () => {
|
|
@@ -104,9 +107,9 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
104
107
|
}
|
|
105
108
|
}, [chartRef.current, onBrush]);
|
|
106
109
|
|
|
107
|
-
const options = useMemoDebugger<
|
|
110
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
108
111
|
() => {
|
|
109
|
-
if (isEmpty(
|
|
112
|
+
if (isEmpty(_series)) {
|
|
110
113
|
chartRef.current?.clear();
|
|
111
114
|
return {};
|
|
112
115
|
}
|
|
@@ -114,65 +117,73 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
114
117
|
const stack = type.includes("stacked") ? "stack" : undefined;
|
|
115
118
|
|
|
116
119
|
const [_type, stacked] = type.split("-");
|
|
117
|
-
const categoryAxis: AnyObject =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
120
|
+
const categoryAxis: AnyObject = Object.assign(
|
|
121
|
+
{},
|
|
122
|
+
optionOverride?.xAxis,
|
|
123
|
+
{
|
|
124
|
+
name: categoryAxisName,
|
|
125
|
+
type: "time",
|
|
126
|
+
nameGap: 32,
|
|
127
|
+
nameLocation: "center",
|
|
128
|
+
axisTick: {
|
|
129
|
+
show: false,
|
|
130
|
+
},
|
|
131
|
+
axisLabel: {
|
|
132
|
+
formatter: {
|
|
133
|
+
year: "{yyyy}",
|
|
134
|
+
month: "{MMM}",
|
|
135
|
+
day: "{d}",
|
|
136
|
+
hour: "{HH}:{mm}",
|
|
137
|
+
minute: "{HH}:{mm}",
|
|
138
|
+
second: "{HH}:{mm}:{ss}",
|
|
139
|
+
millisecond: "{hh}:{mm}:{ss} {SSS}",
|
|
140
|
+
none: "{yyyy}-{MM}-{dd} {hh}:{mm}:{ss} {SSS}",
|
|
141
|
+
} as AnyObject,
|
|
142
|
+
},
|
|
143
|
+
} as EChartsOption["xAxis"],
|
|
144
|
+
);
|
|
145
|
+
const valueAxis: AnyObject = Object.assign({}, optionOverride?.yAxis, {
|
|
139
146
|
name: valueAxisName,
|
|
140
147
|
type: "value",
|
|
141
148
|
nameGap: 32,
|
|
142
149
|
nameLocation: "center",
|
|
143
|
-
} as
|
|
150
|
+
} as EChartsOption["yAxis"]);
|
|
144
151
|
|
|
145
|
-
const series =
|
|
152
|
+
const series = _series?.map(
|
|
146
153
|
(item) =>
|
|
147
154
|
({
|
|
148
|
-
|
|
149
|
-
stack,
|
|
155
|
+
...item,
|
|
156
|
+
stack: item.stack ?? stack,
|
|
150
157
|
areaStyle: stacked ? {} : undefined,
|
|
151
158
|
symbol: "none",
|
|
152
159
|
type: _type === "column" ? "bar" : _type,
|
|
153
|
-
name: item.
|
|
154
|
-
data: item.values,
|
|
160
|
+
name: item.name ?? item.id,
|
|
155
161
|
universalTransition: true,
|
|
156
162
|
}) as AnyObject,
|
|
157
163
|
);
|
|
158
164
|
|
|
159
165
|
return {
|
|
160
|
-
xAxis: categoryAxis,
|
|
161
|
-
yAxis: valueAxis,
|
|
162
|
-
series,
|
|
163
166
|
brush: {
|
|
164
167
|
toolbox: ["lineX", "clear"],
|
|
165
168
|
brushType: "lineX",
|
|
166
169
|
xAxisIndex: 0,
|
|
167
170
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
...optionOverride,
|
|
172
|
+
tooltip: Object.assign(
|
|
173
|
+
{
|
|
174
|
+
trigger: "axis",
|
|
175
|
+
confine: true,
|
|
176
|
+
position: "top",
|
|
177
|
+
appendTo: "body",
|
|
178
|
+
},
|
|
179
|
+
optionOverride?.tooltip,
|
|
180
|
+
),
|
|
181
|
+
xAxis: categoryAxis,
|
|
182
|
+
yAxis: valueAxis,
|
|
183
|
+
series,
|
|
173
184
|
};
|
|
174
185
|
},
|
|
175
|
-
[
|
|
186
|
+
[_series, type, categoryAxisName, valueAxisName, optionOverride],
|
|
176
187
|
"TimeChart options",
|
|
177
188
|
);
|
|
178
189
|
|
|
@@ -183,43 +194,47 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
183
194
|
theme={theme}
|
|
184
195
|
options={options}
|
|
185
196
|
chartRef={chartRef}
|
|
186
|
-
isEmpty={isEmpty(
|
|
197
|
+
isEmpty={isEmpty(_series)}
|
|
187
198
|
emptyIcon={CoreIcons.chartColumn}
|
|
188
199
|
dataTableRenderer={timeSeriesRenderer}
|
|
189
200
|
onClick={(e) => onClick?.({ category: e.data[0], series: e.seriesId })}
|
|
190
201
|
>
|
|
191
|
-
|
|
192
|
-
<
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
202
|
+
{showTypeSelector && (
|
|
203
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
204
|
+
<Button
|
|
205
|
+
size="sm"
|
|
206
|
+
variant="link"
|
|
207
|
+
icon={CoreIcons.chartLine}
|
|
208
|
+
value="line"
|
|
209
|
+
aria-label="line"
|
|
210
|
+
/>
|
|
211
|
+
<Button
|
|
212
|
+
size="sm"
|
|
213
|
+
variant="link"
|
|
214
|
+
icon={CoreIcons.chartColumn}
|
|
215
|
+
value="column"
|
|
216
|
+
aria-label="column"
|
|
217
|
+
/>
|
|
218
|
+
<Button
|
|
219
|
+
size="sm"
|
|
220
|
+
variant="link"
|
|
221
|
+
icon={CoreIcons.chartLineStacked}
|
|
222
|
+
value="line-stacked"
|
|
223
|
+
aria-label="line-stacked"
|
|
224
|
+
/>
|
|
225
|
+
<Button
|
|
226
|
+
size="sm"
|
|
227
|
+
variant="link"
|
|
228
|
+
icon={CoreIcons.chartColumnStacked}
|
|
229
|
+
value="column-stacked"
|
|
230
|
+
aria-label="column-stacked"
|
|
231
|
+
/>
|
|
232
|
+
</ToggleButtonGroup>
|
|
233
|
+
)}
|
|
234
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
235
|
+
{showThemeSelector && (
|
|
236
|
+
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
237
|
+
)}
|
|
223
238
|
</ChartContainer>
|
|
224
239
|
);
|
|
225
240
|
},
|
|
@@ -227,7 +242,30 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
227
242
|
TimeSeriesChart.displayName = "TimeSeriesChart";
|
|
228
243
|
|
|
229
244
|
/**
|
|
230
|
-
*
|
|
245
|
+
* TimeSeries component renders a time series chart using the provided data and options.
|
|
246
|
+
* It supports different chart types such as line, column, and stacked variants.
|
|
247
|
+
* It also allows for interaction through click and brush events.
|
|
248
|
+
*
|
|
249
|
+
* @param {TimeSeriesProps} props - The properties for the TimeSeries component.
|
|
250
|
+
* @returns {JSX.Element} The rendered TimeSeries component.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```jsx
|
|
254
|
+
* <TimeSeries
|
|
255
|
+
* data={data}
|
|
256
|
+
* onExport={handleExport}
|
|
257
|
+
* categoryAxisName="Time"
|
|
258
|
+
* valueAxisName="Value"
|
|
259
|
+
* title="Time Series Chart"
|
|
260
|
+
* type="line"
|
|
261
|
+
* onClick={(data) => console.log(data)}
|
|
262
|
+
* onBrush={(range) => console.log(range)}
|
|
263
|
+
* />
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-timeseries--docs} for more details on the properties.
|
|
267
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-line} for more details on the ECharts line series options.
|
|
268
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-bar} for more details on the ECharts bar series options.
|
|
231
269
|
*/
|
|
232
270
|
export const TimeSeries: FC<TimeSeriesProps> = (props) => (
|
|
233
271
|
<ChartWrapper>
|
|
@@ -28,20 +28,20 @@ import {
|
|
|
28
28
|
} from "@react-fabric/core";
|
|
29
29
|
import { isEmpty } from "@react-fabric/utilities";
|
|
30
30
|
import { endOfDay, startOfDay } from "date-fns";
|
|
31
|
-
import { type
|
|
31
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
32
32
|
import { memo, useCallback, useEffect, useRef, useState, type FC } from "react";
|
|
33
33
|
import { type BaseChart } from "../types";
|
|
34
34
|
import { ChartContainer } from "../wrapper/ChartContainer";
|
|
35
35
|
import { ChartWrapper } from "../wrapper/ChartWrapper";
|
|
36
36
|
|
|
37
37
|
export interface TimeSliderProps extends BaseChart {
|
|
38
|
-
|
|
38
|
+
series: Array<[Date, number]>;
|
|
39
39
|
range?: { start: Date; end: Date };
|
|
40
40
|
onBrush?: (range: { start: Date; end: Date }) => void;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
44
|
-
({
|
|
44
|
+
({ series: dataSeries, range: sliderRange, onBrush }: TimeSliderProps) => {
|
|
45
45
|
const chartRef = useRef<EChartsType>(null);
|
|
46
46
|
|
|
47
47
|
const [range, setRange] = useState({ startValue: 0, endValue: 0 });
|
|
@@ -53,9 +53,12 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
useEffect(() => {
|
|
56
|
-
const defaultStart =
|
|
56
|
+
const defaultStart =
|
|
57
|
+
dataSeries.length > 0 ? dataSeries?.[0]?.[0]?.getTime() : 0;
|
|
57
58
|
const defaultEnd =
|
|
58
|
-
|
|
59
|
+
dataSeries.length > 0
|
|
60
|
+
? dataSeries?.[dataSeries.length - 1]?.[0]?.getTime()
|
|
61
|
+
: 32;
|
|
59
62
|
|
|
60
63
|
const getRangeValue = (v: number = 0, def = 0) =>
|
|
61
64
|
v >= defaultStart && v <= defaultEnd ? v : def;
|
|
@@ -63,7 +66,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
63
66
|
startValue: getRangeValue(sliderRange?.start.getTime(), defaultStart),
|
|
64
67
|
endValue: getRangeValue(sliderRange?.end.getTime(), defaultEnd),
|
|
65
68
|
});
|
|
66
|
-
}, [sliderRange,
|
|
69
|
+
}, [sliderRange, dataSeries]);
|
|
67
70
|
|
|
68
71
|
const enableBrush = useCallback(() => {
|
|
69
72
|
chartRef.current?.dispatchAction({
|
|
@@ -83,7 +86,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
83
86
|
if (chart && !chart?.isDisposed()) {
|
|
84
87
|
enableBrush();
|
|
85
88
|
chart.on("datazoom", () => {
|
|
86
|
-
const zoom = chart.getOption().dataZoom?.[0];
|
|
89
|
+
const zoom = (chart.getOption().dataZoom as any)?.[0];
|
|
87
90
|
if (zoom) {
|
|
88
91
|
const startValue = Math.floor(zoom.startValue as number);
|
|
89
92
|
const endValue = Math.ceil(
|
|
@@ -105,9 +108,9 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
105
108
|
"TimeSldier onBrush",
|
|
106
109
|
);
|
|
107
110
|
|
|
108
|
-
const options = useMemoDebugger<
|
|
111
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
109
112
|
() => {
|
|
110
|
-
if (isEmpty(
|
|
113
|
+
if (isEmpty(dataSeries)) {
|
|
111
114
|
chartRef.current?.clear();
|
|
112
115
|
return {};
|
|
113
116
|
}
|
|
@@ -126,7 +129,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
126
129
|
show: false,
|
|
127
130
|
},
|
|
128
131
|
position: "bottom",
|
|
129
|
-
} as
|
|
132
|
+
} as EChartsOption["xAxis"];
|
|
130
133
|
const valueAxis: AnyObject = {
|
|
131
134
|
type: "value",
|
|
132
135
|
nameGap: 24,
|
|
@@ -143,7 +146,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
143
146
|
show: false,
|
|
144
147
|
},
|
|
145
148
|
nameLocation: "center",
|
|
146
|
-
} as
|
|
149
|
+
} as EChartsOption["yAxis"];
|
|
147
150
|
|
|
148
151
|
const series = [
|
|
149
152
|
{
|
|
@@ -152,7 +155,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
152
155
|
type: "line",
|
|
153
156
|
smooth: true,
|
|
154
157
|
lineStyle: { width: 2 },
|
|
155
|
-
data,
|
|
158
|
+
data: dataSeries,
|
|
156
159
|
} as AnyObject,
|
|
157
160
|
];
|
|
158
161
|
|
|
@@ -194,7 +197,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
194
197
|
} as AnyObject,
|
|
195
198
|
};
|
|
196
199
|
},
|
|
197
|
-
[
|
|
200
|
+
[dataSeries],
|
|
198
201
|
"TimeSlider options",
|
|
199
202
|
);
|
|
200
203
|
|
|
@@ -219,7 +222,7 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
219
222
|
<ChartContainer
|
|
220
223
|
options={options}
|
|
221
224
|
chartRef={chartRef}
|
|
222
|
-
isEmpty={isEmpty(
|
|
225
|
+
isEmpty={isEmpty(dataSeries)}
|
|
223
226
|
/>
|
|
224
227
|
);
|
|
225
228
|
},
|
|
@@ -227,7 +230,27 @@ const TimeSliderChart: FC<TimeSliderProps> = memo(
|
|
|
227
230
|
TimeSliderChart.displayName = "TimeSliderChart";
|
|
228
231
|
|
|
229
232
|
/**
|
|
230
|
-
*
|
|
233
|
+
* TimeSlider component renders a time slider chart.
|
|
234
|
+
* It allows users to visualize time-based data and interactively select a range.
|
|
235
|
+
* The chart supports brushing to select a specific time range,
|
|
236
|
+
* and it emits an event when the range is changed.
|
|
237
|
+
*
|
|
238
|
+
* @param {TimeSliderProps} props - The properties for the TimeSlider component.
|
|
239
|
+
* @returns {JSX.Element} The rendered TimeSlider component.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```jsx
|
|
243
|
+
* <TimeSlider
|
|
244
|
+
* data={data}
|
|
245
|
+
* range={{ start: new Date("2023-01-01"), end: new Date("2023-12-31") }}
|
|
246
|
+
* onBrush={(range) => console.log("Selected range:", range)}
|
|
247
|
+
* />
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-timeslider--docs} for more details on the properties.
|
|
251
|
+
* @see {@link https://echarts.apache.org/en/option.html#dataZoom} for more details on the ECharts dataZoom feature.
|
|
252
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-line} for more details on the ECharts line series.
|
|
253
|
+
*/
|
|
231
254
|
export const TimeSlider: FC<TimeSliderProps> = (props) => (
|
|
232
255
|
<ChartWrapper>
|
|
233
256
|
<TimeSliderChart {...props} />
|
|
@@ -23,25 +23,26 @@
|
|
|
23
23
|
|
|
24
24
|
import { CoreIcons, useIsDark, useMemoDebugger } from "@react-fabric/core";
|
|
25
25
|
import { compareValues, isEmpty } from "@react-fabric/utilities";
|
|
26
|
-
import { type
|
|
26
|
+
import { type EChartsOption } from "echarts";
|
|
27
27
|
import { memo, type FC } from "react";
|
|
28
28
|
import { ChartPalette } from "../theme/palettes";
|
|
29
|
-
import { type BaseChart
|
|
29
|
+
import { type BaseChart } from "../types";
|
|
30
30
|
import { countRenderer } from "../types/utils";
|
|
31
31
|
import { ChartContainer } from "../wrapper/ChartContainer";
|
|
32
32
|
import { ChartWrapper } from "../wrapper/ChartWrapper";
|
|
33
33
|
|
|
34
|
-
export interface WordBubbleProps extends Omit<BaseChart, "theme"
|
|
34
|
+
export interface WordBubbleProps extends Omit<BaseChart, "theme"> {
|
|
35
|
+
series: Array<{ id: string; label?: string; count: number }>;
|
|
35
36
|
onClick?: (key: string) => void;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
39
|
-
({
|
|
40
|
+
({ series, title, onExport, onClick }: WordBubbleProps) => {
|
|
40
41
|
const isDark = useIsDark();
|
|
41
42
|
|
|
42
|
-
const options = useMemoDebugger<
|
|
43
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
43
44
|
() => {
|
|
44
|
-
if (isEmpty(
|
|
45
|
+
if (isEmpty(series)) return {};
|
|
45
46
|
|
|
46
47
|
const palette = isDark
|
|
47
48
|
? ChartPalette.CloudDark
|
|
@@ -49,6 +50,12 @@ const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
|
49
50
|
|
|
50
51
|
return {
|
|
51
52
|
legend: undefined,
|
|
53
|
+
tooltip: {
|
|
54
|
+
trigger: "axis",
|
|
55
|
+
confine: true,
|
|
56
|
+
position: "top",
|
|
57
|
+
appendToBody: true,
|
|
58
|
+
} as EChartsOption["tooltip"],
|
|
52
59
|
series: [
|
|
53
60
|
{
|
|
54
61
|
name: title,
|
|
@@ -66,7 +73,7 @@ const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
|
66
73
|
color: ({ dataIndex }: KeyValue) =>
|
|
67
74
|
palette[dataIndex % palette.length],
|
|
68
75
|
},
|
|
69
|
-
data:
|
|
76
|
+
data: series
|
|
70
77
|
.sort(compareValues("desc", "count"))
|
|
71
78
|
.map(({ id: key, label, count }, index) => ({
|
|
72
79
|
name: label ?? key,
|
|
@@ -76,7 +83,7 @@ const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
|
76
83
|
],
|
|
77
84
|
};
|
|
78
85
|
},
|
|
79
|
-
[
|
|
86
|
+
[series, title, isDark],
|
|
80
87
|
"WordChart options",
|
|
81
88
|
);
|
|
82
89
|
|
|
@@ -85,7 +92,7 @@ const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
|
85
92
|
title={title}
|
|
86
93
|
onExport={onExport}
|
|
87
94
|
options={options}
|
|
88
|
-
isEmpty={isEmpty(
|
|
95
|
+
isEmpty={isEmpty(series)}
|
|
89
96
|
emptyIcon={CoreIcons.chartActivityScatter}
|
|
90
97
|
dataTableRenderer={countRenderer}
|
|
91
98
|
onClick={(e) => onClick?.(e?.name ?? "")}
|
|
@@ -96,7 +103,31 @@ const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
|
96
103
|
WordBubbleChart.displayName = "WordBubbleChart";
|
|
97
104
|
|
|
98
105
|
/**
|
|
99
|
-
*
|
|
106
|
+
* WordBubble component renders a word cloud chart using ECharts.
|
|
107
|
+
* It displays words with sizes proportional to their frequency in the data.
|
|
108
|
+
* Users can click on words to trigger an action, such as filtering or navigating.
|
|
109
|
+
* It also supports exporting the chart and displays an empty state when no data is available.
|
|
110
|
+
*
|
|
111
|
+
* @param {WordBubbleProps} props - The properties for the WordBubble component.
|
|
112
|
+
* @returns {JSX.Element} The rendered WordBubble component.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```jsx
|
|
116
|
+
* <WordBubble
|
|
117
|
+
* data={[
|
|
118
|
+
* { id: "1", label: "Word One", count: 10 },
|
|
119
|
+
* { id: "2", label: "Word Two", count: 20 },
|
|
120
|
+
* { id: "3", label: "Word Three", count: 30 },
|
|
121
|
+
* ]}
|
|
122
|
+
* title="Word Frequency"
|
|
123
|
+
* onExport={() => console.log("Exporting chart...")}
|
|
124
|
+
* onClick={(key) => console.log("Clicked word:", key)}
|
|
125
|
+
* theme="light"
|
|
126
|
+
* />
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-wordbubble--docs} for the properties that can be passed to this component.
|
|
130
|
+
* @see {@link https://github.com/ecomfe/echarts-wordcloud} for the underlying chart implementation.
|
|
100
131
|
*/
|
|
101
132
|
export const WordBubble: FC<WordBubbleProps> = (props) => (
|
|
102
133
|
<ChartWrapper>
|
package/src/theme/darkBase.ts
CHANGED
|
@@ -195,7 +195,7 @@ export const DarkThemeBase = {
|
|
|
195
195
|
splitLine: {
|
|
196
196
|
show: true,
|
|
197
197
|
lineStyle: {
|
|
198
|
-
color: ["#
|
|
198
|
+
color: ["#363636"],
|
|
199
199
|
},
|
|
200
200
|
},
|
|
201
201
|
splitArea: {
|
|
@@ -229,7 +229,7 @@ export const DarkThemeBase = {
|
|
|
229
229
|
splitLine: {
|
|
230
230
|
show: true,
|
|
231
231
|
lineStyle: {
|
|
232
|
-
color: ["#
|
|
232
|
+
color: ["#363636"],
|
|
233
233
|
},
|
|
234
234
|
},
|
|
235
235
|
splitArea: {
|
|
@@ -263,7 +263,7 @@ export const DarkThemeBase = {
|
|
|
263
263
|
splitLine: {
|
|
264
264
|
show: true,
|
|
265
265
|
lineStyle: {
|
|
266
|
-
color: ["#
|
|
266
|
+
color: ["#363636"],
|
|
267
267
|
},
|
|
268
268
|
},
|
|
269
269
|
splitArea: {
|
|
@@ -297,7 +297,7 @@ export const DarkThemeBase = {
|
|
|
297
297
|
splitLine: {
|
|
298
298
|
show: true,
|
|
299
299
|
lineStyle: {
|
|
300
|
-
color: ["#
|
|
300
|
+
color: ["#363636"],
|
|
301
301
|
},
|
|
302
302
|
},
|
|
303
303
|
splitArea: {
|
|
@@ -307,11 +307,6 @@ export const DarkThemeBase = {
|
|
|
307
307
|
},
|
|
308
308
|
},
|
|
309
309
|
},
|
|
310
|
-
visualMap: {
|
|
311
|
-
textStyle: {
|
|
312
|
-
color: "#eee",
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
310
|
toolbox: {
|
|
316
311
|
iconStyle: {
|
|
317
312
|
borderColor: "#999999",
|
|
@@ -324,9 +319,17 @@ export const DarkThemeBase = {
|
|
|
324
319
|
},
|
|
325
320
|
legend: {
|
|
326
321
|
inactiveColor: "rgb(192 192 192 / .75)",
|
|
322
|
+
itemHeight: 8,
|
|
327
323
|
textStyle: {
|
|
324
|
+
fontSize: 10,
|
|
328
325
|
color: "#5d6d7d6",
|
|
329
326
|
},
|
|
327
|
+
pageTextStyle: {
|
|
328
|
+
fontSize: 8,
|
|
329
|
+
},
|
|
330
|
+
pageIconSize: 8,
|
|
331
|
+
pageIconColor: "#6997A3",
|
|
332
|
+
pageIconInactiveColor: "#474B4A",
|
|
330
333
|
},
|
|
331
334
|
tooltip: {
|
|
332
335
|
backgroundColor: "#0C141D",
|