@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 ECharts, type EChartsOption } from "echarts";
|
|
33
32
|
import { memo, useCallback, useEffect, useRef, useState, type FC } from "react";
|
|
34
33
|
import { type BaseChart, type TimeSeriesType } from "../types";
|
|
35
34
|
import { timeSeriesRenderer } from "../types/utils";
|
|
@@ -45,17 +44,20 @@ export interface TimeSeriesProps extends BaseChart, TimeSeriesType {
|
|
|
45
44
|
|
|
46
45
|
const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
47
46
|
({
|
|
48
|
-
|
|
47
|
+
series: _series,
|
|
49
48
|
onExport,
|
|
50
49
|
categoryAxisName,
|
|
51
50
|
valueAxisName,
|
|
52
51
|
title,
|
|
52
|
+
showThemeSelector,
|
|
53
|
+
showTypeSelector,
|
|
53
54
|
theme: chartTheme,
|
|
54
55
|
type: chartType = "column",
|
|
56
|
+
options: optionOverride,
|
|
55
57
|
onClick,
|
|
56
58
|
onBrush,
|
|
57
59
|
}: TimeSeriesProps) => {
|
|
58
|
-
const chartRef = useRef<
|
|
60
|
+
const chartRef = useRef<ECharts>(null);
|
|
59
61
|
const [type, setType] = useState(chartType);
|
|
60
62
|
const [theme, setTheme] = useState(chartTheme);
|
|
61
63
|
|
|
@@ -90,7 +92,7 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
90
92
|
if (chart && !chart?.isDisposed()) {
|
|
91
93
|
enableBrush();
|
|
92
94
|
let range = [0, 0];
|
|
93
|
-
chart.on("brushselected", (e:
|
|
95
|
+
chart.on("brushselected", (e: any) => {
|
|
94
96
|
range = e.batch?.[0]?.areas?.[0]?.coordRange;
|
|
95
97
|
});
|
|
96
98
|
chart.on("brushEnd", () => {
|
|
@@ -104,9 +106,9 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
104
106
|
}
|
|
105
107
|
}, [chartRef.current, onBrush]);
|
|
106
108
|
|
|
107
|
-
const options = useMemoDebugger<
|
|
109
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
108
110
|
() => {
|
|
109
|
-
if (isEmpty(
|
|
111
|
+
if (isEmpty(_series)) {
|
|
110
112
|
chartRef.current?.clear();
|
|
111
113
|
return {};
|
|
112
114
|
}
|
|
@@ -114,65 +116,73 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
114
116
|
const stack = type.includes("stacked") ? "stack" : undefined;
|
|
115
117
|
|
|
116
118
|
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
|
-
|
|
119
|
+
const categoryAxis: AnyObject = Object.assign(
|
|
120
|
+
{},
|
|
121
|
+
optionOverride?.xAxis,
|
|
122
|
+
{
|
|
123
|
+
name: categoryAxisName,
|
|
124
|
+
type: "time",
|
|
125
|
+
nameGap: 32,
|
|
126
|
+
nameLocation: "center",
|
|
127
|
+
axisTick: {
|
|
128
|
+
show: false,
|
|
129
|
+
},
|
|
130
|
+
axisLabel: {
|
|
131
|
+
formatter: {
|
|
132
|
+
year: "{yyyy}",
|
|
133
|
+
month: "{MMM}",
|
|
134
|
+
day: "{d}",
|
|
135
|
+
hour: "{HH}:{mm}",
|
|
136
|
+
minute: "{HH}:{mm}",
|
|
137
|
+
second: "{HH}:{mm}:{ss}",
|
|
138
|
+
millisecond: "{hh}:{mm}:{ss} {SSS}",
|
|
139
|
+
none: "{yyyy}-{MM}-{dd} {hh}:{mm}:{ss} {SSS}",
|
|
140
|
+
} as AnyObject,
|
|
141
|
+
},
|
|
142
|
+
} as EChartsOption["xAxis"],
|
|
143
|
+
);
|
|
144
|
+
const valueAxis: AnyObject = Object.assign({}, optionOverride?.yAxis, {
|
|
139
145
|
name: valueAxisName,
|
|
140
146
|
type: "value",
|
|
141
147
|
nameGap: 32,
|
|
142
148
|
nameLocation: "center",
|
|
143
|
-
} as
|
|
149
|
+
} as EChartsOption["yAxis"]);
|
|
144
150
|
|
|
145
|
-
const series =
|
|
151
|
+
const series = _series?.map(
|
|
146
152
|
(item) =>
|
|
147
153
|
({
|
|
148
|
-
|
|
149
|
-
stack,
|
|
154
|
+
...item,
|
|
155
|
+
stack: item.stack ?? stack,
|
|
150
156
|
areaStyle: stacked ? {} : undefined,
|
|
151
157
|
symbol: "none",
|
|
152
158
|
type: _type === "column" ? "bar" : _type,
|
|
153
|
-
name: item.
|
|
154
|
-
data: item.values,
|
|
159
|
+
name: item.name ?? item.id,
|
|
155
160
|
universalTransition: true,
|
|
156
161
|
}) as AnyObject,
|
|
157
162
|
);
|
|
158
163
|
|
|
159
164
|
return {
|
|
160
|
-
xAxis: categoryAxis,
|
|
161
|
-
yAxis: valueAxis,
|
|
162
|
-
series,
|
|
163
165
|
brush: {
|
|
164
166
|
toolbox: ["lineX", "clear"],
|
|
165
167
|
brushType: "lineX",
|
|
166
168
|
xAxisIndex: 0,
|
|
167
169
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
...optionOverride,
|
|
171
|
+
tooltip: Object.assign(
|
|
172
|
+
{
|
|
173
|
+
trigger: "axis",
|
|
174
|
+
confine: true,
|
|
175
|
+
position: "top",
|
|
176
|
+
appendTo: "body",
|
|
177
|
+
},
|
|
178
|
+
optionOverride?.tooltip,
|
|
179
|
+
),
|
|
180
|
+
xAxis: categoryAxis,
|
|
181
|
+
yAxis: valueAxis,
|
|
182
|
+
series,
|
|
173
183
|
};
|
|
174
184
|
},
|
|
175
|
-
[
|
|
185
|
+
[_series, type, categoryAxisName, valueAxisName, optionOverride],
|
|
176
186
|
"TimeChart options",
|
|
177
187
|
);
|
|
178
188
|
|
|
@@ -183,43 +193,47 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
183
193
|
theme={theme}
|
|
184
194
|
options={options}
|
|
185
195
|
chartRef={chartRef}
|
|
186
|
-
isEmpty={isEmpty(
|
|
187
|
-
emptyIcon=
|
|
196
|
+
isEmpty={isEmpty(_series)}
|
|
197
|
+
emptyIcon="icon-[mdi--chart-bar] rotate-90 -scale-x-100"
|
|
188
198
|
dataTableRenderer={timeSeriesRenderer}
|
|
189
199
|
onClick={(e) => onClick?.({ category: e.data[0], series: e.seriesId })}
|
|
190
200
|
>
|
|
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
|
-
|
|
201
|
+
{showTypeSelector && (
|
|
202
|
+
<ToggleButtonGroup value={type} onChange={setType as AnyObject}>
|
|
203
|
+
<Button
|
|
204
|
+
size="sm"
|
|
205
|
+
variant="link"
|
|
206
|
+
icon="icon-[mdi--chart-line]"
|
|
207
|
+
value="line"
|
|
208
|
+
aria-label="line"
|
|
209
|
+
/>
|
|
210
|
+
<Button
|
|
211
|
+
size="sm"
|
|
212
|
+
variant="link"
|
|
213
|
+
icon="icon-[mdi--chart-bar]"
|
|
214
|
+
value="column"
|
|
215
|
+
aria-label="column"
|
|
216
|
+
/>
|
|
217
|
+
<Button
|
|
218
|
+
size="sm"
|
|
219
|
+
variant="link"
|
|
220
|
+
icon="icon-[mdi--chart-line-stacked]"
|
|
221
|
+
value="line-stacked"
|
|
222
|
+
aria-label="line-stacked"
|
|
223
|
+
/>
|
|
224
|
+
<Button
|
|
225
|
+
size="sm"
|
|
226
|
+
variant="link"
|
|
227
|
+
icon="icon-[mdi--chart-bar-stacked]"
|
|
228
|
+
value="column-stacked"
|
|
229
|
+
aria-label="column-stacked"
|
|
230
|
+
/>
|
|
231
|
+
</ToggleButtonGroup>
|
|
232
|
+
)}
|
|
233
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
234
|
+
{showThemeSelector && (
|
|
235
|
+
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
236
|
+
)}
|
|
223
237
|
</ChartContainer>
|
|
224
238
|
);
|
|
225
239
|
},
|
|
@@ -227,7 +241,30 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
227
241
|
TimeSeriesChart.displayName = "TimeSeriesChart";
|
|
228
242
|
|
|
229
243
|
/**
|
|
230
|
-
*
|
|
244
|
+
* TimeSeries component renders a time series chart using the provided data and options.
|
|
245
|
+
* It supports different chart types such as line, column, and stacked variants.
|
|
246
|
+
* It also allows for interaction through click and brush events.
|
|
247
|
+
*
|
|
248
|
+
* @param {TimeSeriesProps} props - The properties for the TimeSeries component.
|
|
249
|
+
* @returns {JSX.Element} The rendered TimeSeries component.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```jsx
|
|
253
|
+
* <TimeSeries
|
|
254
|
+
* data={data}
|
|
255
|
+
* onExport={handleExport}
|
|
256
|
+
* categoryAxisName="Time"
|
|
257
|
+
* valueAxisName="Value"
|
|
258
|
+
* title="Time Series Chart"
|
|
259
|
+
* type="line"
|
|
260
|
+
* onClick={(data) => console.log(data)}
|
|
261
|
+
* onBrush={(range) => console.log(range)}
|
|
262
|
+
* />
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-timeseries--docs} for more details on the properties.
|
|
266
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-line} for more details on the ECharts line series options.
|
|
267
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-bar} for more details on the ECharts bar series options.
|
|
231
268
|
*/
|
|
232
269
|
export const TimeSeries: FC<TimeSeriesProps> = (props) => (
|
|
233
270
|
<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} />
|
|
@@ -21,27 +21,28 @@
|
|
|
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 {
|
|
24
|
+
import { 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,8 +92,8 @@ const WordBubbleChart: FC<WordBubbleProps> = memo(
|
|
|
85
92
|
title={title}
|
|
86
93
|
onExport={onExport}
|
|
87
94
|
options={options}
|
|
88
|
-
isEmpty={isEmpty(
|
|
89
|
-
emptyIcon=
|
|
95
|
+
isEmpty={isEmpty(series)}
|
|
96
|
+
emptyIcon="icon-[mdi--chart-bubble]"
|
|
90
97
|
dataTableRenderer={countRenderer}
|
|
91
98
|
onClick={(e) => onClick?.(e?.name ?? "")}
|
|
92
99
|
/>
|
|
@@ -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",
|