@react-fabric/chart 1.0.0-beta.8 → 1.0.1
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} +11 -11
- package/css/styles.css +24 -0
- package/dist/cjs/charts/ActivityMap.js +70 -36
- package/dist/cjs/charts/CountSeries.js +67 -35
- package/dist/cjs/charts/DataSeries.js +75 -40
- package/dist/cjs/charts/Generic.js +41 -19
- package/dist/cjs/charts/MapSeries.js +41 -17
- package/dist/cjs/charts/TimeSeries.js +73 -40
- package/dist/cjs/charts/TimeSlider.js +40 -21
- package/dist/cjs/charts/WordBubble.js +65 -29
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/theme/darkBase.js +13 -10
- package/dist/cjs/theme/index.js +43 -23
- package/dist/cjs/theme/lightBase.js +18 -15
- package/dist/cjs/theme/palettes.js +5 -54
- package/dist/cjs/types/charts.js +4 -2
- package/dist/cjs/types/utils.js +6 -9
- package/dist/cjs/wrapper/ChartContainer.js +26 -18
- package/dist/cjs/wrapper/ChartToolbar.js +4 -5
- package/dist/cjs/wrapper/ChartWrapper.js +4 -5
- package/dist/cjs/wrapper/PaletteSelect.js +31 -18
- package/dist/esm/charts/ActivityMap.js +71 -37
- package/dist/esm/charts/CountSeries.js +68 -36
- package/dist/esm/charts/DataSeries.js +76 -41
- package/dist/esm/charts/Generic.js +43 -21
- package/dist/esm/charts/MapSeries.js +41 -17
- package/dist/esm/charts/TimeSeries.js +74 -41
- package/dist/esm/charts/TimeSlider.js +41 -22
- package/dist/esm/charts/WordBubble.js +67 -31
- package/dist/esm/index.js +30 -0
- package/dist/esm/theme/darkBase.js +13 -10
- package/dist/esm/theme/index.js +43 -23
- package/dist/esm/theme/lightBase.js +18 -15
- package/dist/esm/theme/palettes.js +5 -54
- package/dist/esm/types/charts.js +4 -2
- package/dist/esm/types/utils.js +6 -9
- package/dist/esm/wrapper/ChartContainer.js +27 -19
- package/dist/esm/wrapper/ChartToolbar.js +4 -5
- package/dist/esm/wrapper/ChartWrapper.js +4 -5
- package/dist/esm/wrapper/PaletteSelect.js +32 -19
- package/dist/types/charts/ActivityMap.d.ts +20 -4
- package/dist/types/charts/CountSeries.d.ts +25 -3
- package/dist/types/charts/DataSeries.d.ts +26 -1
- package/dist/types/charts/Generic.d.ts +36 -52
- 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 +19 -5
- package/dist/types/charts/WordBubble.d.ts +28 -5
- package/dist/types/index.d.ts +26 -0
- package/dist/types/theme/darkBase.d.ts +8 -5
- package/dist/types/theme/index.d.ts +3 -2
- package/dist/types/theme/lightBase.d.ts +8 -5
- package/dist/types/types/charts.d.ts +2 -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 +7 -7
- package/dist/types/wrapper/ChartToolbar.d.ts +2 -3
- package/dist/types/wrapper/ChartWrapper.d.ts +3 -5
- package/dist/types/wrapper/PaletteSelect.d.ts +6 -1
- package/package.json +17 -21
- package/src/charts/ActivityMap.tsx +95 -94
- package/src/charts/CountSeries.tsx +73 -65
- package/src/charts/DataSeries.tsx +104 -98
- package/src/charts/Generic.tsx +56 -86
- package/src/charts/MapSeries.tsx +153 -151
- package/src/charts/TimeSeries.tsx +96 -79
- package/src/charts/TimeSlider.tsx +194 -195
- package/src/charts/WordBubble.tsx +97 -62
- package/src/index.ts +22 -17
- package/src/theme/darkBase.ts +12 -9
- package/src/theme/index.ts +92 -30
- 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 +18 -30
- package/src/wrapper/ChartContainer.tsx +48 -79
- package/src/wrapper/ChartToolbar.tsx +5 -12
- package/src/wrapper/ChartWrapper.tsx +5 -10
- package/src/wrapper/PaletteSelect.tsx +43 -40
- package/dist/cjs/wrapper/Chart.module.css +0 -1
- package/dist/esm/wrapper/Chart.module.css +0 -1
package/src/charts/MapSeries.tsx
CHANGED
|
@@ -21,194 +21,196 @@
|
|
|
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 {
|
|
25
|
-
|
|
26
|
-
Countries,
|
|
27
|
-
Format,
|
|
28
|
-
isEmpty,
|
|
29
|
-
} from "@react-fabric/utilities";
|
|
24
|
+
import { Button, ToggleButtonGroup, useMemoDebugger } from "@react-fabric/core";
|
|
25
|
+
import { compareValues, Countries, Format, isEmpty } from "@react-fabric/utilities";
|
|
30
26
|
import * as echarts from "echarts";
|
|
31
|
-
import { type
|
|
27
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
32
28
|
import { memo, useEffect, useRef, useState, type FC } from "react";
|
|
33
29
|
import { ChartPalette } from "../theme/palettes";
|
|
34
|
-
import { type BaseChart
|
|
30
|
+
import { type BaseChart } from "../types";
|
|
35
31
|
import { countRenderer } from "../types/utils";
|
|
36
32
|
import { ChartContainer } from "../wrapper/ChartContainer";
|
|
37
33
|
import { ChartWrapper } from "../wrapper/ChartWrapper";
|
|
38
34
|
|
|
39
|
-
import {
|
|
40
|
-
Button,
|
|
41
|
-
CoreIcons,
|
|
42
|
-
ToggleButtonGroup,
|
|
43
|
-
useMemoDebugger,
|
|
44
|
-
} from "@react-fabric/core";
|
|
45
35
|
import WorldMap from "../types/world.svg";
|
|
46
36
|
echarts.registerMap("world", { svg: WorldMap });
|
|
47
37
|
|
|
48
|
-
export interface MapSeriesProps extends BaseChart
|
|
38
|
+
export interface MapSeriesProps extends BaseChart {
|
|
39
|
+
series: Array<{ id: string; label?: string; count: number }>;
|
|
49
40
|
onClick?: (key: string) => void;
|
|
50
41
|
}
|
|
51
42
|
|
|
52
|
-
const MapSeriesChart: FC<MapSeriesProps> = memo(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const [zoom, setZoom] = useState(1.25);
|
|
43
|
+
const MapSeriesChart: FC<MapSeriesProps> = memo(({ series, onExport, showTypeSelector, title, onClick }: MapSeriesProps) => {
|
|
44
|
+
const chartRef = useRef<EChartsType>(null);
|
|
45
|
+
const [type, setType] = useState("map");
|
|
46
|
+
const [zoom, setZoom] = useState(1.25);
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
const options = useMemoDebugger<EChartsOption>(
|
|
49
|
+
() => {
|
|
50
|
+
if (isEmpty(series)) return {};
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
const sorted = series
|
|
53
|
+
.map((d) => ({
|
|
54
|
+
...d,
|
|
55
|
+
label: d.label ?? Countries.name(d.id),
|
|
56
|
+
}))
|
|
57
|
+
.sort(compareValues("desc", "count"));
|
|
58
|
+
const valueMap = series.map((d) => d.count);
|
|
69
59
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
axisLabel: {
|
|
79
|
-
rotate: 30,
|
|
80
|
-
},
|
|
81
|
-
data: [],
|
|
60
|
+
if (type === "column") {
|
|
61
|
+
return {
|
|
62
|
+
xAxis: {
|
|
63
|
+
type: "category",
|
|
64
|
+
nameLocation: "center",
|
|
65
|
+
axisTick: {
|
|
66
|
+
show: false,
|
|
82
67
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
axisLabel: {
|
|
86
|
-
formatter: (val: AnyObject) => Format.number(val),
|
|
87
|
-
},
|
|
68
|
+
axisLabel: {
|
|
69
|
+
rotate: 30,
|
|
88
70
|
},
|
|
89
|
-
|
|
90
|
-
id: item.id + index,
|
|
91
|
-
type: "bar",
|
|
92
|
-
label: {
|
|
93
|
-
show: true,
|
|
94
|
-
rotate: 90,
|
|
95
|
-
formatter: "{a}",
|
|
96
|
-
position: "inside",
|
|
97
|
-
color: "#fff",
|
|
98
|
-
},
|
|
99
|
-
data: [
|
|
100
|
-
{
|
|
101
|
-
value: item.count,
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
name: item.label ?? item.id,
|
|
105
|
-
universalTransition: true,
|
|
106
|
-
})),
|
|
107
|
-
} as AnyObject;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
legend: {
|
|
112
|
-
show: false,
|
|
71
|
+
data: [],
|
|
113
72
|
},
|
|
114
|
-
|
|
115
|
-
type: "
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
show: false,
|
|
119
|
-
color: [...ChartPalette.Heatmap],
|
|
120
|
-
calculable: true,
|
|
121
|
-
orient: "horizontal",
|
|
122
|
-
left: "center",
|
|
123
|
-
bottom: 48,
|
|
124
|
-
} as AnyObject,
|
|
125
|
-
series: [
|
|
126
|
-
{
|
|
127
|
-
id: "mapseries",
|
|
128
|
-
name: title ?? "Map Series",
|
|
129
|
-
type: "map",
|
|
130
|
-
map: "world",
|
|
131
|
-
aspectScale: 1,
|
|
132
|
-
roam: "move",
|
|
133
|
-
colorBy: "data",
|
|
134
|
-
nameProperty: "name",
|
|
135
|
-
universalTransition: true,
|
|
136
|
-
emphasis: {
|
|
137
|
-
label: { show: false },
|
|
138
|
-
},
|
|
139
|
-
select: {
|
|
140
|
-
disabled: true,
|
|
141
|
-
},
|
|
142
|
-
data: sorted.map(({ id, label: name, count: value }) => ({
|
|
143
|
-
id,
|
|
144
|
-
name,
|
|
145
|
-
value,
|
|
146
|
-
})),
|
|
73
|
+
yAxis: {
|
|
74
|
+
type: "value",
|
|
75
|
+
axisLabel: {
|
|
76
|
+
formatter: (val) => Format.number(val),
|
|
147
77
|
},
|
|
148
|
-
|
|
78
|
+
},
|
|
79
|
+
series: sorted.map((item, index) => ({
|
|
80
|
+
id: item.id + index,
|
|
81
|
+
type: "bar",
|
|
82
|
+
label: {
|
|
83
|
+
show: true,
|
|
84
|
+
rotate: 90,
|
|
85
|
+
formatter: "{a}",
|
|
86
|
+
position: "inside",
|
|
87
|
+
color: "#fff",
|
|
88
|
+
},
|
|
89
|
+
data: [
|
|
90
|
+
{
|
|
91
|
+
value: item.count,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
name: item.label ?? item.id,
|
|
95
|
+
universalTransition: true,
|
|
96
|
+
})),
|
|
149
97
|
};
|
|
150
|
-
}
|
|
151
|
-
[data, title, type],
|
|
152
|
-
"MapChart options",
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
useEffect(() => {
|
|
156
|
-
setZoom(1.25);
|
|
157
|
-
}, [data, type]);
|
|
98
|
+
}
|
|
158
99
|
|
|
159
|
-
|
|
160
|
-
|
|
100
|
+
return {
|
|
101
|
+
legend: {
|
|
102
|
+
show: false,
|
|
103
|
+
},
|
|
104
|
+
visualMap: {
|
|
105
|
+
type: "piecewise",
|
|
106
|
+
min: Math.min(...valueMap) - 1,
|
|
107
|
+
max: Math.max(...valueMap) + 1,
|
|
108
|
+
show: false,
|
|
109
|
+
color: [...ChartPalette.Heatmap],
|
|
110
|
+
calculable: true,
|
|
111
|
+
orient: "horizontal",
|
|
112
|
+
left: "center",
|
|
113
|
+
bottom: 48,
|
|
114
|
+
},
|
|
161
115
|
series: [
|
|
162
116
|
{
|
|
163
|
-
|
|
117
|
+
id: "mapseries",
|
|
118
|
+
name: title ?? "Map Series",
|
|
119
|
+
type: "map",
|
|
120
|
+
map: "world",
|
|
121
|
+
aspectScale: 1,
|
|
122
|
+
roam: "move",
|
|
123
|
+
colorBy: "data",
|
|
124
|
+
nameProperty: "name",
|
|
125
|
+
universalTransition: true,
|
|
126
|
+
emphasis: {
|
|
127
|
+
label: { show: false },
|
|
128
|
+
},
|
|
129
|
+
select: {
|
|
130
|
+
disabled: true,
|
|
131
|
+
},
|
|
132
|
+
data: sorted.map(({ id, label: name, count: value }) => ({
|
|
133
|
+
id,
|
|
134
|
+
name,
|
|
135
|
+
value,
|
|
136
|
+
})),
|
|
164
137
|
},
|
|
165
138
|
],
|
|
166
|
-
}
|
|
167
|
-
},
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
[series, title, type],
|
|
142
|
+
"MapChart options",
|
|
143
|
+
);
|
|
168
144
|
|
|
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
|
-
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
147
|
+
setZoom(1.25);
|
|
148
|
+
}, [series, type]);
|
|
149
|
+
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
chartRef.current?.setOption({
|
|
152
|
+
series: [
|
|
153
|
+
{
|
|
154
|
+
zoom,
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
});
|
|
158
|
+
}, [zoom]);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<ChartContainer
|
|
162
|
+
title={title}
|
|
163
|
+
onExport={onExport}
|
|
164
|
+
chartRef={chartRef}
|
|
165
|
+
options={options}
|
|
166
|
+
dataTableRenderer={countRenderer}
|
|
167
|
+
onClick={(e) => e.data && onClick?.((e?.data as KeyValue<string>)?.id ?? "")}
|
|
168
|
+
>
|
|
169
|
+
{type === "map" && (
|
|
170
|
+
<input type="range" min={1.25} max={24} step={0.25} value={zoom} onChange={(e) => setZoom(e.target.valueAsNumber)} />
|
|
171
|
+
)}
|
|
172
|
+
{showTypeSelector && (
|
|
173
|
+
<ToggleButtonGroup value={type} onChange={setType}>
|
|
174
|
+
<Button size="sm" variant="link" icon="icon-[mdi--map]" aria-label="map" value="map" />
|
|
196
175
|
<Button
|
|
197
176
|
size="sm"
|
|
198
177
|
variant="link"
|
|
199
|
-
icon=
|
|
178
|
+
icon="icon-[mdi--chart-bar] rotate-90 -scale-x-100"
|
|
200
179
|
aria-label="column"
|
|
201
180
|
value="column"
|
|
202
181
|
/>
|
|
203
182
|
</ToggleButtonGroup>
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
);
|
|
183
|
+
)}
|
|
184
|
+
</ChartContainer>
|
|
185
|
+
);
|
|
186
|
+
});
|
|
208
187
|
MapSeriesChart.displayName = "MapSeriesChart";
|
|
209
188
|
|
|
210
189
|
/**
|
|
211
|
-
*
|
|
190
|
+
* MapSeries component renders a map chart using ECharts.
|
|
191
|
+
* It displays data on a world map, allowing users to visualize counts or other metrics by country.
|
|
192
|
+
* It supports zooming and switching between map and column views.
|
|
193
|
+
*
|
|
194
|
+
* @param {MapSeriesProps} props - The properties for the MapSeries component.
|
|
195
|
+
* @returns {React.ReactElement} The rendered MapSeries component.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```jsx
|
|
199
|
+
* <MapSeries
|
|
200
|
+
* data={[
|
|
201
|
+
* { id: "US", label: "United States", count: 100 },
|
|
202
|
+
* { id: "IN", label: "India", count: 200 },
|
|
203
|
+
* { id: "CN", label: "China", count: 300 },
|
|
204
|
+
* ]}
|
|
205
|
+
* onExport={() => console.log("Exporting chart")}
|
|
206
|
+
* title="World Map Series"
|
|
207
|
+
* onClick={(key) => console.log("Clicked country:", key)}
|
|
208
|
+
* theme="light"
|
|
209
|
+
* />
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-mapseries--docs} for more details on the properties.
|
|
213
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-map} for ECharts map series options documentation.
|
|
212
214
|
*/
|
|
213
215
|
export const MapSeries: FC<MapSeriesProps> = (props) => (
|
|
214
216
|
<ChartWrapper>
|
|
@@ -21,15 +21,9 @@
|
|
|
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 {
|
|
25
|
-
Button,
|
|
26
|
-
CoreIcons,
|
|
27
|
-
Divider,
|
|
28
|
-
ToggleButtonGroup,
|
|
29
|
-
useMemoDebugger,
|
|
30
|
-
} from "@react-fabric/core";
|
|
24
|
+
import { Button, Divider, ToggleButtonGroup, useMemoDebugger } from "@react-fabric/core";
|
|
31
25
|
import { isEmpty } from "@react-fabric/utilities";
|
|
32
|
-
import { type
|
|
26
|
+
import { type ECharts, type EChartsOption } from "echarts";
|
|
33
27
|
import { memo, useCallback, useEffect, useRef, useState, type FC } from "react";
|
|
34
28
|
import { type BaseChart, type TimeSeriesType } from "../types";
|
|
35
29
|
import { timeSeriesRenderer } from "../types/utils";
|
|
@@ -45,24 +39,29 @@ export interface TimeSeriesProps extends BaseChart, TimeSeriesType {
|
|
|
45
39
|
|
|
46
40
|
const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
47
41
|
({
|
|
48
|
-
|
|
42
|
+
series: _series,
|
|
49
43
|
onExport,
|
|
50
44
|
categoryAxisName,
|
|
51
45
|
valueAxisName,
|
|
52
46
|
title,
|
|
47
|
+
showThemeSelector,
|
|
48
|
+
showTypeSelector,
|
|
53
49
|
theme: chartTheme,
|
|
54
50
|
type: chartType = "column",
|
|
51
|
+
options: optionOverride,
|
|
55
52
|
onClick,
|
|
56
53
|
onBrush,
|
|
57
54
|
}: TimeSeriesProps) => {
|
|
58
|
-
const chartRef = useRef<
|
|
55
|
+
const chartRef = useRef<ECharts>(null);
|
|
59
56
|
const [type, setType] = useState(chartType);
|
|
60
57
|
const [theme, setTheme] = useState(chartTheme);
|
|
61
58
|
|
|
62
59
|
useEffect(() => {
|
|
60
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
63
61
|
setType(chartType);
|
|
64
62
|
}, [chartType]);
|
|
65
63
|
useEffect(() => {
|
|
64
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
66
65
|
setTheme(chartTheme);
|
|
67
66
|
}, [chartTheme]);
|
|
68
67
|
|
|
@@ -90,7 +89,8 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
90
89
|
if (chart && !chart?.isDisposed()) {
|
|
91
90
|
enableBrush();
|
|
92
91
|
let range = [0, 0];
|
|
93
|
-
chart.on("brushselected", (e:
|
|
92
|
+
chart.on("brushselected", (e: AnyObject) => {
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
94
94
|
range = e.batch?.[0]?.areas?.[0]?.coordRange;
|
|
95
95
|
});
|
|
96
96
|
chart.on("brushEnd", () => {
|
|
@@ -98,15 +98,18 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
98
98
|
enableBrush();
|
|
99
99
|
});
|
|
100
100
|
return () => {
|
|
101
|
-
!chart.isDisposed()
|
|
102
|
-
|
|
101
|
+
if (!chart.isDisposed()) {
|
|
102
|
+
chart.off("brushEnd");
|
|
103
|
+
chart.off("brushselected");
|
|
104
|
+
}
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
|
-
|
|
107
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
108
|
+
}, [enableBrush, onBrush, chartRef.current]);
|
|
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,7 +117,7 @@ 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
|
|
120
|
+
const categoryAxis = Object.assign({}, optionOverride?.xAxis, {
|
|
118
121
|
name: categoryAxisName,
|
|
119
122
|
type: "time",
|
|
120
123
|
nameGap: 32,
|
|
@@ -132,47 +135,48 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
132
135
|
second: "{HH}:{mm}:{ss}",
|
|
133
136
|
millisecond: "{hh}:{mm}:{ss} {SSS}",
|
|
134
137
|
none: "{yyyy}-{MM}-{dd} {hh}:{mm}:{ss} {SSS}",
|
|
135
|
-
}
|
|
138
|
+
},
|
|
136
139
|
},
|
|
137
|
-
} as
|
|
138
|
-
const valueAxis
|
|
140
|
+
} as EChartsOption["xAxis"]);
|
|
141
|
+
const valueAxis = Object.assign({}, optionOverride?.yAxis, {
|
|
139
142
|
name: valueAxisName,
|
|
140
143
|
type: "value",
|
|
141
144
|
nameGap: 32,
|
|
142
145
|
nameLocation: "center",
|
|
143
|
-
} as
|
|
146
|
+
} as EChartsOption["yAxis"]);
|
|
144
147
|
|
|
145
|
-
const series =
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
data: item.values,
|
|
155
|
-
universalTransition: true,
|
|
156
|
-
}) as AnyObject,
|
|
157
|
-
);
|
|
148
|
+
const series = _series?.map((item) => ({
|
|
149
|
+
...item,
|
|
150
|
+
stack: item.stack ?? stack,
|
|
151
|
+
areaStyle: stacked ? {} : undefined,
|
|
152
|
+
symbol: "none",
|
|
153
|
+
type: _type === "column" ? "bar" : _type,
|
|
154
|
+
name: item.name ?? item.id,
|
|
155
|
+
universalTransition: true,
|
|
156
|
+
}));
|
|
158
157
|
|
|
159
158
|
return {
|
|
160
|
-
xAxis: categoryAxis,
|
|
161
|
-
yAxis: valueAxis,
|
|
162
|
-
series,
|
|
163
159
|
brush: {
|
|
164
160
|
toolbox: ["lineX", "clear"],
|
|
165
161
|
brushType: "lineX",
|
|
166
162
|
xAxisIndex: 0,
|
|
167
163
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
...optionOverride,
|
|
165
|
+
tooltip: Object.assign(
|
|
166
|
+
{
|
|
167
|
+
trigger: "axis",
|
|
168
|
+
confine: true,
|
|
169
|
+
position: "top",
|
|
170
|
+
appendTo: "body",
|
|
171
|
+
},
|
|
172
|
+
optionOverride?.tooltip,
|
|
173
|
+
),
|
|
174
|
+
xAxis: categoryAxis,
|
|
175
|
+
yAxis: valueAxis,
|
|
176
|
+
series,
|
|
173
177
|
};
|
|
174
178
|
},
|
|
175
|
-
[
|
|
179
|
+
[_series, type, categoryAxisName, valueAxisName, optionOverride],
|
|
176
180
|
"TimeChart options",
|
|
177
181
|
);
|
|
178
182
|
|
|
@@ -183,43 +187,33 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
183
187
|
theme={theme}
|
|
184
188
|
options={options}
|
|
185
189
|
chartRef={chartRef}
|
|
186
|
-
isEmpty={isEmpty(
|
|
187
|
-
emptyIcon=
|
|
190
|
+
isEmpty={isEmpty(_series)}
|
|
191
|
+
emptyIcon="icon-[mdi--chart-bar] rotate-90 -scale-x-100"
|
|
188
192
|
dataTableRenderer={timeSeriesRenderer}
|
|
189
|
-
onClick={(e) => onClick?.({ category: e
|
|
193
|
+
onClick={(e) => onClick?.({ category: (e?.data as KeyValue<string>)?.[0] ?? "", series: e.seriesId ?? "" })}
|
|
190
194
|
>
|
|
191
|
-
|
|
192
|
-
<
|
|
193
|
-
size="sm"
|
|
194
|
-
variant="link"
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
<Button
|
|
214
|
-
size="sm"
|
|
215
|
-
variant="link"
|
|
216
|
-
icon={CoreIcons.chartColumnStacked}
|
|
217
|
-
value="column-stacked"
|
|
218
|
-
aria-label="column-stacked"
|
|
219
|
-
/>
|
|
220
|
-
</ToggleButtonGroup>
|
|
221
|
-
<Divider vertical />
|
|
222
|
-
<PaletteSelect theme={theme} onClick={setTheme} />
|
|
195
|
+
{showTypeSelector && (
|
|
196
|
+
<ToggleButtonGroup value={type} onChange={setType}>
|
|
197
|
+
<Button size="sm" variant="link" icon="icon-[mdi--chart-line]" value="line" aria-label="line" />
|
|
198
|
+
<Button size="sm" variant="link" icon="icon-[mdi--chart-bar]" value="column" aria-label="column" />
|
|
199
|
+
<Button
|
|
200
|
+
size="sm"
|
|
201
|
+
variant="link"
|
|
202
|
+
icon="icon-[mdi--chart-line-stacked]"
|
|
203
|
+
value="line-stacked"
|
|
204
|
+
aria-label="line-stacked"
|
|
205
|
+
/>
|
|
206
|
+
<Button
|
|
207
|
+
size="sm"
|
|
208
|
+
variant="link"
|
|
209
|
+
icon="icon-[mdi--chart-bar-stacked]"
|
|
210
|
+
value="column-stacked"
|
|
211
|
+
aria-label="column-stacked"
|
|
212
|
+
/>
|
|
213
|
+
</ToggleButtonGroup>
|
|
214
|
+
)}
|
|
215
|
+
{showTypeSelector && showThemeSelector && <Divider vertical />}
|
|
216
|
+
{showThemeSelector && <PaletteSelect theme={theme} onClick={setTheme} />}
|
|
223
217
|
</ChartContainer>
|
|
224
218
|
);
|
|
225
219
|
},
|
|
@@ -227,7 +221,30 @@ const TimeSeriesChart: FC<TimeSeriesProps> = memo(
|
|
|
227
221
|
TimeSeriesChart.displayName = "TimeSeriesChart";
|
|
228
222
|
|
|
229
223
|
/**
|
|
230
|
-
*
|
|
224
|
+
* TimeSeries component renders a time series chart using the provided data and options.
|
|
225
|
+
* It supports different chart types such as line, column, and stacked variants.
|
|
226
|
+
* It also allows for interaction through click and brush events.
|
|
227
|
+
*
|
|
228
|
+
* @param {TimeSeriesProps} props - The properties for the TimeSeries component.
|
|
229
|
+
* @returns {React.ReactElement} The rendered TimeSeries component.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```jsx
|
|
233
|
+
* <TimeSeries
|
|
234
|
+
* data={data}
|
|
235
|
+
* onExport={handleExport}
|
|
236
|
+
* categoryAxisName="Time"
|
|
237
|
+
* valueAxisName="Value"
|
|
238
|
+
* title="Time Series Chart"
|
|
239
|
+
* type="line"
|
|
240
|
+
* onClick={(data) => console.log(data)}
|
|
241
|
+
* onBrush={(range) => console.log(range)}
|
|
242
|
+
* />
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/charts-timeseries--docs} for more details on the properties.
|
|
246
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-line} for more details on the ECharts line series options.
|
|
247
|
+
* @see {@link https://echarts.apache.org/en/option.html#series-bar} for more details on the ECharts bar series options.
|
|
231
248
|
*/
|
|
232
249
|
export const TimeSeries: FC<TimeSeriesProps> = (props) => (
|
|
233
250
|
<ChartWrapper>
|