@react-fabric/chart 1.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/charts/ActivityMap.js +183 -0
- package/dist/cjs/charts/CountSeries.js +156 -0
- package/dist/cjs/charts/DataSeries.js +185 -0
- package/dist/cjs/charts/Generic.js +90 -0
- package/dist/cjs/charts/MapSeries.js +215 -0
- package/dist/cjs/charts/TimeSeries.js +213 -0
- package/dist/cjs/charts/TimeSlider.js +194 -0
- package/dist/cjs/charts/WordBubble.js +80 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/theme/darkBase.js +418 -0
- package/dist/cjs/theme/index.js +98 -0
- package/dist/cjs/theme/lightBase.js +415 -0
- package/dist/cjs/theme/palettes.js +113 -0
- package/dist/cjs/types/charts.js +56 -0
- package/dist/cjs/types/utils.js +104 -0
- package/dist/cjs/types/world.svg.js +5 -0
- package/dist/cjs/wrapper/Chart.module.css +1 -0
- package/dist/cjs/wrapper/ChartContainer.js +171 -0
- package/dist/cjs/wrapper/ChartToolbar.js +38 -0
- package/dist/cjs/wrapper/ChartWrapper.js +57 -0
- package/dist/cjs/wrapper/PaletteSelect.js +146 -0
- package/dist/esm/charts/ActivityMap.js +183 -0
- package/dist/esm/charts/CountSeries.js +156 -0
- package/dist/esm/charts/DataSeries.js +185 -0
- package/dist/esm/charts/Generic.js +90 -0
- package/dist/esm/charts/MapSeries.js +196 -0
- package/dist/esm/charts/TimeSeries.js +213 -0
- package/dist/esm/charts/TimeSlider.js +194 -0
- package/dist/esm/charts/WordBubble.js +80 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/theme/darkBase.js +418 -0
- package/dist/esm/theme/index.js +97 -0
- package/dist/esm/theme/lightBase.js +415 -0
- package/dist/esm/theme/palettes.js +113 -0
- package/dist/esm/types/charts.js +35 -0
- package/dist/esm/types/utils.js +101 -0
- package/dist/esm/types/world.svg.js +5 -0
- package/dist/esm/wrapper/Chart.module.css +1 -0
- package/dist/esm/wrapper/ChartContainer.js +152 -0
- package/dist/esm/wrapper/ChartToolbar.js +38 -0
- package/dist/esm/wrapper/ChartWrapper.js +57 -0
- package/dist/esm/wrapper/PaletteSelect.js +146 -0
- package/dist/types/charts/ActivityMap.d.ts +21 -0
- package/dist/types/charts/CountSeries.d.ts +10 -0
- package/dist/types/charts/DataSeries.d.ts +13 -0
- package/dist/types/charts/Generic.d.ts +56 -0
- package/dist/types/charts/MapSeries.d.ts +9 -0
- package/dist/types/charts/TimeSeries.d.ts +17 -0
- package/dist/types/charts/TimeSlider.d.ts +16 -0
- package/dist/types/charts/WordBubble.d.ts +9 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/theme/darkBase.d.ts +391 -0
- package/dist/types/theme/index.d.ts +2 -0
- package/dist/types/theme/lightBase.d.ts +388 -0
- package/dist/types/theme/palettes.d.ts +45 -0
- package/dist/types/types/charts.d.ts +3 -0
- package/dist/types/types/index.d.ts +36 -0
- package/dist/types/types/utils.d.ts +4 -0
- package/dist/types/types/world.svg.d.ts +2 -0
- package/dist/types/wrapper/ChartContainer.d.ts +20 -0
- package/dist/types/wrapper/ChartToolbar.d.ts +3 -0
- package/dist/types/wrapper/ChartWrapper.d.ts +5 -0
- package/dist/types/wrapper/PaletteSelect.d.ts +1 -0
- package/package.json +58 -0
- package/src/charts/ActivityMap.tsx +295 -0
- package/src/charts/CountSeries.tsx +186 -0
- package/src/charts/DataSeries.tsx +228 -0
- package/src/charts/Generic.tsx +190 -0
- package/src/charts/MapSeries.tsx +217 -0
- package/src/charts/TimeSeries.tsx +236 -0
- package/src/charts/TimeSlider.tsx +235 -0
- package/src/charts/WordBubble.tsx +105 -0
- package/src/index.ts +32 -0
- package/src/theme/darkBase.ts +400 -0
- package/src/theme/index.ts +122 -0
- package/src/theme/lightBase.ts +397 -0
- package/src/theme/palettes.ts +589 -0
- package/src/types/charts.ts +32 -0
- package/src/types/index.ts +61 -0
- package/src/types/utils.ts +151 -0
- package/src/types/world.svg.ts +467 -0
- package/src/wrapper/Chart.module.css +90 -0
- package/src/wrapper/ChartContainer.tsx +217 -0
- package/src/wrapper/ChartToolbar.tsx +40 -0
- package/src/wrapper/ChartWrapper.tsx +46 -0
- package/src/wrapper/PaletteSelect.tsx +139 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import { useMemoDebugger, CoreIcons, ToggleButtonGroup, Button, Divider } from '@react-fabric/core';
|
|
6
|
+
import { isEmpty } from '@react-fabric/utilities';
|
|
7
|
+
import { memo, useRef, useState, useEffect } from 'react';
|
|
8
|
+
import { seriesRenderer } from '../types/utils.js';
|
|
9
|
+
import { ChartContainer } from '../wrapper/ChartContainer.js';
|
|
10
|
+
import { ChartWrapper } from '../wrapper/ChartWrapper.js';
|
|
11
|
+
import { PaletteSelect } from '../wrapper/PaletteSelect.js';
|
|
12
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
var DataSeriesChart = /*#__PURE__*/memo(function (_ref) {
|
|
17
|
+
var data = _ref.data,
|
|
18
|
+
onExport = _ref.onExport,
|
|
19
|
+
categories = _ref.categories,
|
|
20
|
+
categoryAxisName = _ref.categoryAxisName,
|
|
21
|
+
valueAxisName = _ref.valueAxisName,
|
|
22
|
+
title = _ref.title,
|
|
23
|
+
chartTheme = _ref.theme,
|
|
24
|
+
_ref$type = _ref.type,
|
|
25
|
+
chartType = _ref$type === void 0 ? "column" : _ref$type,
|
|
26
|
+
_onClick = _ref.onClick;
|
|
27
|
+
var chartRef = useRef(null);
|
|
28
|
+
var _useState = useState(chartType),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
type = _useState2[0],
|
|
31
|
+
setType = _useState2[1];
|
|
32
|
+
var _useState3 = useState(chartTheme),
|
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
+
theme = _useState4[0],
|
|
35
|
+
setTheme = _useState4[1];
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
setType(chartType);
|
|
38
|
+
}, [chartType]);
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
setTheme(chartTheme);
|
|
41
|
+
}, [chartTheme]);
|
|
42
|
+
var options = useMemoDebugger(function () {
|
|
43
|
+
if (isEmpty(data)) {
|
|
44
|
+
var _chartRef$current;
|
|
45
|
+
(_chartRef$current = chartRef.current) === null || _chartRef$current === void 0 || _chartRef$current.clear();
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
var stack = type.includes("stacked") ? "stack" : undefined;
|
|
49
|
+
var _type$split = type.split("-"),
|
|
50
|
+
_type$split2 = _slicedToArray(_type$split, 2),
|
|
51
|
+
_type = _type$split2[0],
|
|
52
|
+
stacked = _type$split2[1];
|
|
53
|
+
var categoryAxis = _type === "radar" ? undefined : {
|
|
54
|
+
name: categoryAxisName,
|
|
55
|
+
type: "category",
|
|
56
|
+
nameGap: 32,
|
|
57
|
+
nameLocation: "center",
|
|
58
|
+
axisTick: {
|
|
59
|
+
show: false
|
|
60
|
+
},
|
|
61
|
+
data: categories
|
|
62
|
+
};
|
|
63
|
+
var valueAxis = _type === "radar" ? undefined : {
|
|
64
|
+
name: valueAxisName,
|
|
65
|
+
type: "value",
|
|
66
|
+
nameGap: 32,
|
|
67
|
+
nameLocation: "center"
|
|
68
|
+
};
|
|
69
|
+
var radar = _type !== "radar" ? undefined : {
|
|
70
|
+
shape: "circle",
|
|
71
|
+
indicator: categories === null || categories === void 0 ? void 0 : categories.map(function (c) {
|
|
72
|
+
return {
|
|
73
|
+
name: c
|
|
74
|
+
};
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
var series = data === null || data === void 0 ? void 0 : data.map(function (item, index) {
|
|
78
|
+
var _item$label, _item$label2;
|
|
79
|
+
return {
|
|
80
|
+
id: item.id,
|
|
81
|
+
stack: stack,
|
|
82
|
+
areaStyle: stacked ? {} : undefined,
|
|
83
|
+
type: _type === "column" ? "bar" : _type,
|
|
84
|
+
name: (_item$label = item.label) !== null && _item$label !== void 0 ? _item$label : item.id,
|
|
85
|
+
universalTransition: true,
|
|
86
|
+
data: _type === "radar" ? [{
|
|
87
|
+
value: item.values,
|
|
88
|
+
id: item.id,
|
|
89
|
+
name: (_item$label2 = item.label) !== null && _item$label2 !== void 0 ? _item$label2 : item.id
|
|
90
|
+
}] : item.values
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
xAxis: type.startsWith("bar") ? valueAxis : categoryAxis,
|
|
95
|
+
yAxis: type.startsWith("bar") ? categoryAxis : valueAxis,
|
|
96
|
+
radar: radar,
|
|
97
|
+
series: series,
|
|
98
|
+
tooltip: {
|
|
99
|
+
trigger: _type === "radar" ? "item" : "axis",
|
|
100
|
+
confine: true,
|
|
101
|
+
position: "top"
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}, [data, type, categories, categoryAxisName, valueAxisName], "DataChart options");
|
|
105
|
+
return /*#__PURE__*/jsxs(ChartContainer, {
|
|
106
|
+
title: title,
|
|
107
|
+
onExport: onExport,
|
|
108
|
+
theme: theme,
|
|
109
|
+
options: options,
|
|
110
|
+
chartRef: chartRef,
|
|
111
|
+
isEmpty: isEmpty(data),
|
|
112
|
+
emptyIcon: CoreIcons.chartColumn,
|
|
113
|
+
dataTableRenderer: seriesRenderer,
|
|
114
|
+
onClick: function onClick(e) {
|
|
115
|
+
return _onClick === null || _onClick === void 0 ? void 0 : _onClick({
|
|
116
|
+
category: e.name,
|
|
117
|
+
series: e.seriesId
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
children: [/*#__PURE__*/jsxs(ToggleButtonGroup, {
|
|
121
|
+
value: type,
|
|
122
|
+
onChange: setType,
|
|
123
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
124
|
+
size: "sm",
|
|
125
|
+
variant: "link",
|
|
126
|
+
icon: CoreIcons.chartLine,
|
|
127
|
+
"aria-label": "line",
|
|
128
|
+
value: "line"
|
|
129
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
130
|
+
size: "sm",
|
|
131
|
+
variant: "link",
|
|
132
|
+
icon: CoreIcons.chartColumn,
|
|
133
|
+
"aria-label": "column",
|
|
134
|
+
value: "column"
|
|
135
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
136
|
+
size: "sm",
|
|
137
|
+
variant: "link",
|
|
138
|
+
icon: CoreIcons.chartBar,
|
|
139
|
+
"aria-label": "bar",
|
|
140
|
+
value: "bar"
|
|
141
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
142
|
+
size: "sm",
|
|
143
|
+
variant: "link",
|
|
144
|
+
icon: CoreIcons.chartRadar,
|
|
145
|
+
"aria-label": "radar",
|
|
146
|
+
value: "radar"
|
|
147
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
148
|
+
size: "sm",
|
|
149
|
+
variant: "link",
|
|
150
|
+
icon: CoreIcons.chartLineStacked,
|
|
151
|
+
"aria-label": "line-stacked",
|
|
152
|
+
value: "line-stacked"
|
|
153
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
154
|
+
size: "sm",
|
|
155
|
+
variant: "link",
|
|
156
|
+
icon: CoreIcons.chartColumnStacked,
|
|
157
|
+
"aria-label": "column-stacked",
|
|
158
|
+
value: "column-stacked"
|
|
159
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
160
|
+
size: "sm",
|
|
161
|
+
variant: "link",
|
|
162
|
+
icon: CoreIcons.chartBarStacked,
|
|
163
|
+
"aria-label": "bar-stacked",
|
|
164
|
+
value: "bar-stacked"
|
|
165
|
+
})]
|
|
166
|
+
}), /*#__PURE__*/jsx(Divider, {
|
|
167
|
+
vertical: true
|
|
168
|
+
}), /*#__PURE__*/jsx(PaletteSelect, {
|
|
169
|
+
theme: theme,
|
|
170
|
+
onClick: setTheme
|
|
171
|
+
})]
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
DataSeriesChart.displayName = "DataSeriesChart";
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Chart to display simple data category series
|
|
178
|
+
*/
|
|
179
|
+
var DataSeries = function DataSeries(props) {
|
|
180
|
+
return /*#__PURE__*/jsx(ChartWrapper, {
|
|
181
|
+
children: /*#__PURE__*/jsx(DataSeriesChart, _objectSpread({}, props))
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export { DataSeries };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
+
import { memo, useRef, useImperativeHandle, useEffect } from 'react';
|
|
6
|
+
import { ChartContainer } from '../wrapper/ChartContainer.js';
|
|
7
|
+
import { ChartWrapper } from '../wrapper/ChartWrapper.js';
|
|
8
|
+
import { jsx } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
var _excluded = ["chartRef", "onBrush", "onBrushEnd", "onBrushSelected", "dataTableRenderer", "onClick", "onRendered", "actions", "title", "theme"];
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
var GenericChartBase = /*#__PURE__*/memo(function (_ref2) {
|
|
14
|
+
var _ref = _ref2.chartRef,
|
|
15
|
+
onBrush = _ref2.onBrush,
|
|
16
|
+
onBrushEnd = _ref2.onBrushEnd,
|
|
17
|
+
onBrushSelected = _ref2.onBrushSelected,
|
|
18
|
+
dataTableRenderer = _ref2.dataTableRenderer,
|
|
19
|
+
onClick = _ref2.onClick,
|
|
20
|
+
onRendered = _ref2.onRendered,
|
|
21
|
+
actions = _ref2.actions,
|
|
22
|
+
title = _ref2.title,
|
|
23
|
+
theme = _ref2.theme,
|
|
24
|
+
options = _objectWithoutProperties(_ref2, _excluded);
|
|
25
|
+
var chartRef = useRef(null);
|
|
26
|
+
useImperativeHandle(_ref, function () {
|
|
27
|
+
return chartRef.current;
|
|
28
|
+
}, [chartRef.current]);
|
|
29
|
+
useEffect(function () {
|
|
30
|
+
var chart = chartRef.current;
|
|
31
|
+
if (chart && onRendered) {
|
|
32
|
+
chart.on("finished", onRendered);
|
|
33
|
+
return function () {
|
|
34
|
+
!chart.isDisposed() && chart.off("finished");
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}, [chartRef.current, onRendered]);
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
var chart = chartRef.current;
|
|
40
|
+
if (chart && onClick) {
|
|
41
|
+
chart.on("click", onClick);
|
|
42
|
+
return function () {
|
|
43
|
+
!chart.isDisposed() && chart.off("click");
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}, [chartRef.current, onClick]);
|
|
47
|
+
useEffect(function () {
|
|
48
|
+
var chart = chartRef.current;
|
|
49
|
+
if (chart && onBrush) {
|
|
50
|
+
chart.on("brush", onBrush);
|
|
51
|
+
return function () {
|
|
52
|
+
!chart.isDisposed() && chart.off("brush");
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}, [chartRef.current, onBrush]);
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
var chart = chartRef.current;
|
|
58
|
+
if (chart && onBrushEnd) {
|
|
59
|
+
chart.on("brushend", onBrushEnd);
|
|
60
|
+
return function () {
|
|
61
|
+
!chart.isDisposed() && chart.off("brushend");
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}, [chartRef.current, onBrushEnd]);
|
|
65
|
+
useEffect(function () {
|
|
66
|
+
var chart = chartRef.current;
|
|
67
|
+
if (chart && onBrushSelected) {
|
|
68
|
+
chart.on("brushselected", onBrushSelected);
|
|
69
|
+
return function () {
|
|
70
|
+
!chart.isDisposed() && chart.off("brushselected");
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}, [chartRef.current, onBrushSelected]);
|
|
74
|
+
return /*#__PURE__*/jsx(ChartContainer, {
|
|
75
|
+
theme: theme,
|
|
76
|
+
options: options,
|
|
77
|
+
chartRef: chartRef,
|
|
78
|
+
title: title,
|
|
79
|
+
dataTableRenderer: dataTableRenderer,
|
|
80
|
+
children: actions
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
GenericChartBase.displayName = "GenericChart";
|
|
84
|
+
var GenericChart = function GenericChart(props) {
|
|
85
|
+
return /*#__PURE__*/jsx(ChartWrapper, {
|
|
86
|
+
children: /*#__PURE__*/jsx(GenericChartBase, _objectSpread({}, props))
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export { GenericChart };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
|
+
import { isEmpty, Countries, compareValues, Format } from '@react-fabric/utilities';
|
|
7
|
+
import * as echarts from 'echarts';
|
|
8
|
+
import { memo, useRef, useState, useEffect } from 'react';
|
|
9
|
+
import { ChartPalette } from '../theme/palettes.js';
|
|
10
|
+
import { countRenderer } from '../types/utils.js';
|
|
11
|
+
import { ChartContainer } from '../wrapper/ChartContainer.js';
|
|
12
|
+
import { ChartWrapper } from '../wrapper/ChartWrapper.js';
|
|
13
|
+
import { useMemoDebugger, ToggleButtonGroup, Button, CoreIcons } from '@react-fabric/core';
|
|
14
|
+
import WorldMap from '../types/world.svg.js';
|
|
15
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
echarts.registerMap("world", {
|
|
20
|
+
svg: WorldMap
|
|
21
|
+
});
|
|
22
|
+
var MapSeriesChart = /*#__PURE__*/memo(function (_ref) {
|
|
23
|
+
var data = _ref.data,
|
|
24
|
+
onExport = _ref.onExport;
|
|
25
|
+
_ref.theme;
|
|
26
|
+
var title = _ref.title,
|
|
27
|
+
_onClick = _ref.onClick;
|
|
28
|
+
var chartRef = useRef(null);
|
|
29
|
+
var _useState = useState("map"),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
+
type = _useState2[0],
|
|
32
|
+
setType = _useState2[1];
|
|
33
|
+
var _useState3 = useState(1.25),
|
|
34
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
+
zoom = _useState4[0],
|
|
36
|
+
setZoom = _useState4[1];
|
|
37
|
+
var options = useMemoDebugger(function () {
|
|
38
|
+
if (isEmpty(data)) return {};
|
|
39
|
+
var sorted = data.map(function (d) {
|
|
40
|
+
var _d$label;
|
|
41
|
+
return _objectSpread(_objectSpread({}, d), {}, {
|
|
42
|
+
label: (_d$label = d.label) !== null && _d$label !== void 0 ? _d$label : Countries.name(d.id)
|
|
43
|
+
});
|
|
44
|
+
}).sort(compareValues("desc", "count"));
|
|
45
|
+
var valueMap = data.map(function (d) {
|
|
46
|
+
return d.count;
|
|
47
|
+
});
|
|
48
|
+
if (type === "column") {
|
|
49
|
+
return {
|
|
50
|
+
xAxis: {
|
|
51
|
+
type: "category",
|
|
52
|
+
nameLocation: "center",
|
|
53
|
+
axisTick: {
|
|
54
|
+
show: false
|
|
55
|
+
},
|
|
56
|
+
axisLabel: {
|
|
57
|
+
rotate: 30
|
|
58
|
+
},
|
|
59
|
+
data: []
|
|
60
|
+
},
|
|
61
|
+
yAxis: {
|
|
62
|
+
type: "value",
|
|
63
|
+
axisLabel: {
|
|
64
|
+
formatter: function formatter(val) {
|
|
65
|
+
return Format.number(val);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
series: sorted.map(function (item, index) {
|
|
70
|
+
var _item$label;
|
|
71
|
+
return {
|
|
72
|
+
id: item.id + index,
|
|
73
|
+
type: "bar",
|
|
74
|
+
label: {
|
|
75
|
+
show: true,
|
|
76
|
+
rotate: 90,
|
|
77
|
+
formatter: "{a}",
|
|
78
|
+
position: "inside",
|
|
79
|
+
color: "#fff"
|
|
80
|
+
},
|
|
81
|
+
data: [{
|
|
82
|
+
value: item.count
|
|
83
|
+
}],
|
|
84
|
+
name: (_item$label = item.label) !== null && _item$label !== void 0 ? _item$label : item.id,
|
|
85
|
+
universalTransition: true
|
|
86
|
+
};
|
|
87
|
+
})
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
legend: {
|
|
92
|
+
show: false
|
|
93
|
+
},
|
|
94
|
+
visualMap: {
|
|
95
|
+
type: "piecewise",
|
|
96
|
+
min: Math.min.apply(Math, _toConsumableArray(valueMap)) - 1,
|
|
97
|
+
max: Math.max.apply(Math, _toConsumableArray(valueMap)) + 1,
|
|
98
|
+
show: false,
|
|
99
|
+
color: _toConsumableArray(ChartPalette.Heatmap),
|
|
100
|
+
calculable: true,
|
|
101
|
+
orient: "horizontal",
|
|
102
|
+
left: "center",
|
|
103
|
+
bottom: 48
|
|
104
|
+
},
|
|
105
|
+
series: [{
|
|
106
|
+
id: "mapseries",
|
|
107
|
+
name: title !== null && title !== void 0 ? title : "Map Series",
|
|
108
|
+
type: "map",
|
|
109
|
+
map: "world",
|
|
110
|
+
aspectScale: 1,
|
|
111
|
+
roam: "move",
|
|
112
|
+
colorBy: "data",
|
|
113
|
+
nameProperty: "name",
|
|
114
|
+
universalTransition: true,
|
|
115
|
+
emphasis: {
|
|
116
|
+
label: {
|
|
117
|
+
show: false
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
select: {
|
|
121
|
+
disabled: true
|
|
122
|
+
},
|
|
123
|
+
data: sorted.map(function (_ref2) {
|
|
124
|
+
var id = _ref2.id,
|
|
125
|
+
name = _ref2.label,
|
|
126
|
+
value = _ref2.count;
|
|
127
|
+
return {
|
|
128
|
+
id: id,
|
|
129
|
+
name: name,
|
|
130
|
+
value: value
|
|
131
|
+
};
|
|
132
|
+
})
|
|
133
|
+
}]
|
|
134
|
+
};
|
|
135
|
+
}, [data, title, type], "MapChart options");
|
|
136
|
+
useEffect(function () {
|
|
137
|
+
setZoom(1.25);
|
|
138
|
+
}, [data, type]);
|
|
139
|
+
useEffect(function () {
|
|
140
|
+
var _chartRef$current;
|
|
141
|
+
(_chartRef$current = chartRef.current) === null || _chartRef$current === void 0 || _chartRef$current.setOption({
|
|
142
|
+
series: [{
|
|
143
|
+
zoom: zoom
|
|
144
|
+
}]
|
|
145
|
+
});
|
|
146
|
+
}, [zoom]);
|
|
147
|
+
return /*#__PURE__*/jsxs(ChartContainer, {
|
|
148
|
+
title: title,
|
|
149
|
+
onExport: onExport,
|
|
150
|
+
chartRef: chartRef,
|
|
151
|
+
options: options,
|
|
152
|
+
dataTableRenderer: countRenderer,
|
|
153
|
+
onClick: function onClick(e) {
|
|
154
|
+
var _e$data$id, _e$data;
|
|
155
|
+
return e.data && (_onClick === null || _onClick === void 0 ? void 0 : _onClick((_e$data$id = e === null || e === void 0 || (_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.id) !== null && _e$data$id !== void 0 ? _e$data$id : ""));
|
|
156
|
+
},
|
|
157
|
+
children: [type === "map" && /*#__PURE__*/jsx("input", {
|
|
158
|
+
type: "range",
|
|
159
|
+
min: 1.25,
|
|
160
|
+
max: 24,
|
|
161
|
+
step: 0.25,
|
|
162
|
+
value: zoom,
|
|
163
|
+
onChange: function onChange(e) {
|
|
164
|
+
return setZoom(e.target.valueAsNumber);
|
|
165
|
+
}
|
|
166
|
+
}), /*#__PURE__*/jsxs(ToggleButtonGroup, {
|
|
167
|
+
value: type,
|
|
168
|
+
onChange: setType,
|
|
169
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
170
|
+
size: "sm",
|
|
171
|
+
variant: "link",
|
|
172
|
+
icon: CoreIcons.map,
|
|
173
|
+
"aria-label": "map",
|
|
174
|
+
value: "map"
|
|
175
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
176
|
+
size: "sm",
|
|
177
|
+
variant: "link",
|
|
178
|
+
icon: CoreIcons.chartColumn,
|
|
179
|
+
"aria-label": "column",
|
|
180
|
+
value: "column"
|
|
181
|
+
})]
|
|
182
|
+
})]
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
MapSeriesChart.displayName = "MapSeriesChart";
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Chart to display simple map data series
|
|
189
|
+
*/
|
|
190
|
+
var MapSeries = function MapSeries(props) {
|
|
191
|
+
return /*#__PURE__*/jsx(ChartWrapper, {
|
|
192
|
+
children: /*#__PURE__*/jsx(MapSeriesChart, _objectSpread({}, props))
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export { MapSeries };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
+
import { useMemoDebugger, CoreIcons, ToggleButtonGroup, Button, Divider } from '@react-fabric/core';
|
|
6
|
+
import { isEmpty } from '@react-fabric/utilities';
|
|
7
|
+
import { memo, useRef, useState, useEffect, useCallback } from 'react';
|
|
8
|
+
import { timeSeriesRenderer } from '../types/utils.js';
|
|
9
|
+
import { ChartContainer } from '../wrapper/ChartContainer.js';
|
|
10
|
+
import { ChartWrapper } from '../wrapper/ChartWrapper.js';
|
|
11
|
+
import { PaletteSelect } from '../wrapper/PaletteSelect.js';
|
|
12
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
var TimeSeriesChart = /*#__PURE__*/memo(function (_ref) {
|
|
17
|
+
var data = _ref.data,
|
|
18
|
+
onExport = _ref.onExport,
|
|
19
|
+
categoryAxisName = _ref.categoryAxisName,
|
|
20
|
+
valueAxisName = _ref.valueAxisName,
|
|
21
|
+
title = _ref.title,
|
|
22
|
+
chartTheme = _ref.theme,
|
|
23
|
+
_ref$type = _ref.type,
|
|
24
|
+
chartType = _ref$type === void 0 ? "column" : _ref$type,
|
|
25
|
+
_onClick = _ref.onClick,
|
|
26
|
+
onBrush = _ref.onBrush;
|
|
27
|
+
var chartRef = useRef(null);
|
|
28
|
+
var _useState = useState(chartType),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
type = _useState2[0],
|
|
31
|
+
setType = _useState2[1];
|
|
32
|
+
var _useState3 = useState(chartTheme),
|
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
+
theme = _useState4[0],
|
|
35
|
+
setTheme = _useState4[1];
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
setType(chartType);
|
|
38
|
+
}, [chartType]);
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
setTheme(chartTheme);
|
|
41
|
+
}, [chartTheme]);
|
|
42
|
+
var enableBrush = useCallback(function () {
|
|
43
|
+
var _chartRef$current, _chartRef$current2;
|
|
44
|
+
(_chartRef$current = chartRef.current) === null || _chartRef$current === void 0 || _chartRef$current.dispatchAction({
|
|
45
|
+
type: "restore"
|
|
46
|
+
});
|
|
47
|
+
(_chartRef$current2 = chartRef.current) === null || _chartRef$current2 === void 0 || _chartRef$current2.dispatchAction({
|
|
48
|
+
type: "takeGlobalCursor",
|
|
49
|
+
// If intending to enable brush, must set. Otherwise, the mouse will be disabled to brush.
|
|
50
|
+
key: "brush",
|
|
51
|
+
brushOption: {
|
|
52
|
+
// See more info in the `brushType` of "brush component".
|
|
53
|
+
// If set as `false`, the mouse is disabled to brush.
|
|
54
|
+
brushType: "lineX",
|
|
55
|
+
// See more info in the `brushModel` of "brush component".
|
|
56
|
+
// IF not set, use the `brushMode` of brush component.
|
|
57
|
+
brushMode: "rect"
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}, []);
|
|
61
|
+
useEffect(function () {
|
|
62
|
+
var chart = chartRef.current;
|
|
63
|
+
if (chart && !(chart !== null && chart !== void 0 && chart.isDisposed())) {
|
|
64
|
+
enableBrush();
|
|
65
|
+
var range = [0, 0];
|
|
66
|
+
chart.on("brushselected", function (e) {
|
|
67
|
+
var _e$batch;
|
|
68
|
+
range = (_e$batch = e.batch) === null || _e$batch === void 0 || (_e$batch = _e$batch[0]) === null || _e$batch === void 0 || (_e$batch = _e$batch.areas) === null || _e$batch === void 0 || (_e$batch = _e$batch[0]) === null || _e$batch === void 0 ? void 0 : _e$batch.coordRange;
|
|
69
|
+
});
|
|
70
|
+
chart.on("brushEnd", function () {
|
|
71
|
+
var _range, _range2;
|
|
72
|
+
onBrush === null || onBrush === void 0 || onBrush({
|
|
73
|
+
start: new Date((_range = range) === null || _range === void 0 ? void 0 : _range[0]),
|
|
74
|
+
end: new Date((_range2 = range) === null || _range2 === void 0 ? void 0 : _range2[1])
|
|
75
|
+
});
|
|
76
|
+
enableBrush();
|
|
77
|
+
});
|
|
78
|
+
return function () {
|
|
79
|
+
!chart.isDisposed() && chart.off("brushEnd");
|
|
80
|
+
!chart.isDisposed() && chart.off("brushselected");
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}, [chartRef.current, onBrush]);
|
|
84
|
+
var options = useMemoDebugger(function () {
|
|
85
|
+
if (isEmpty(data)) {
|
|
86
|
+
var _chartRef$current3;
|
|
87
|
+
(_chartRef$current3 = chartRef.current) === null || _chartRef$current3 === void 0 || _chartRef$current3.clear();
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
var stack = type.includes("stacked") ? "stack" : undefined;
|
|
91
|
+
var _type$split = type.split("-"),
|
|
92
|
+
_type$split2 = _slicedToArray(_type$split, 2),
|
|
93
|
+
_type = _type$split2[0],
|
|
94
|
+
stacked = _type$split2[1];
|
|
95
|
+
var categoryAxis = {
|
|
96
|
+
name: categoryAxisName,
|
|
97
|
+
type: "time",
|
|
98
|
+
nameGap: 32,
|
|
99
|
+
nameLocation: "center",
|
|
100
|
+
axisTick: {
|
|
101
|
+
show: false
|
|
102
|
+
},
|
|
103
|
+
axisLabel: {
|
|
104
|
+
formatter: {
|
|
105
|
+
year: "{yyyy}",
|
|
106
|
+
month: "{MMM}",
|
|
107
|
+
day: "{d}",
|
|
108
|
+
hour: "{HH}:{mm}",
|
|
109
|
+
minute: "{HH}:{mm}",
|
|
110
|
+
second: "{HH}:{mm}:{ss}",
|
|
111
|
+
millisecond: "{hh}:{mm}:{ss} {SSS}",
|
|
112
|
+
none: "{yyyy}-{MM}-{dd} {hh}:{mm}:{ss} {SSS}"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var valueAxis = {
|
|
117
|
+
name: valueAxisName,
|
|
118
|
+
type: "value",
|
|
119
|
+
nameGap: 32,
|
|
120
|
+
nameLocation: "center"
|
|
121
|
+
};
|
|
122
|
+
var series = data === null || data === void 0 ? void 0 : data.map(function (item) {
|
|
123
|
+
var _item$label;
|
|
124
|
+
return {
|
|
125
|
+
id: item.id,
|
|
126
|
+
stack: stack,
|
|
127
|
+
areaStyle: stacked ? {} : undefined,
|
|
128
|
+
symbol: "none",
|
|
129
|
+
type: _type === "column" ? "bar" : _type,
|
|
130
|
+
name: (_item$label = item.label) !== null && _item$label !== void 0 ? _item$label : item.id,
|
|
131
|
+
data: item.values,
|
|
132
|
+
universalTransition: true
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
xAxis: categoryAxis,
|
|
137
|
+
yAxis: valueAxis,
|
|
138
|
+
series: series,
|
|
139
|
+
brush: {
|
|
140
|
+
toolbox: ["lineX", "clear"],
|
|
141
|
+
brushType: "lineX",
|
|
142
|
+
xAxisIndex: 0
|
|
143
|
+
},
|
|
144
|
+
tooltip: {
|
|
145
|
+
trigger: "axis",
|
|
146
|
+
confine: true,
|
|
147
|
+
position: "top"
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}, [data, type, categoryAxisName, valueAxisName], "TimeChart options");
|
|
151
|
+
return /*#__PURE__*/jsxs(ChartContainer, {
|
|
152
|
+
title: title,
|
|
153
|
+
onExport: onExport,
|
|
154
|
+
theme: theme,
|
|
155
|
+
options: options,
|
|
156
|
+
chartRef: chartRef,
|
|
157
|
+
isEmpty: isEmpty(data),
|
|
158
|
+
emptyIcon: CoreIcons.chartColumn,
|
|
159
|
+
dataTableRenderer: timeSeriesRenderer,
|
|
160
|
+
onClick: function onClick(e) {
|
|
161
|
+
return _onClick === null || _onClick === void 0 ? void 0 : _onClick({
|
|
162
|
+
category: e.data[0],
|
|
163
|
+
series: e.seriesId
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
children: [/*#__PURE__*/jsxs(ToggleButtonGroup, {
|
|
167
|
+
value: type,
|
|
168
|
+
onChange: setType,
|
|
169
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
170
|
+
size: "sm",
|
|
171
|
+
variant: "link",
|
|
172
|
+
icon: CoreIcons.chartLine,
|
|
173
|
+
value: "line",
|
|
174
|
+
"aria-label": "line"
|
|
175
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
176
|
+
size: "sm",
|
|
177
|
+
variant: "link",
|
|
178
|
+
icon: CoreIcons.chartColumn,
|
|
179
|
+
value: "column",
|
|
180
|
+
"aria-label": "column"
|
|
181
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
182
|
+
size: "sm",
|
|
183
|
+
variant: "link",
|
|
184
|
+
icon: CoreIcons.chartLineStacked,
|
|
185
|
+
value: "line-stacked",
|
|
186
|
+
"aria-label": "line-stacked"
|
|
187
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
188
|
+
size: "sm",
|
|
189
|
+
variant: "link",
|
|
190
|
+
icon: CoreIcons.chartColumnStacked,
|
|
191
|
+
value: "column-stacked",
|
|
192
|
+
"aria-label": "column-stacked"
|
|
193
|
+
})]
|
|
194
|
+
}), /*#__PURE__*/jsx(Divider, {
|
|
195
|
+
vertical: true
|
|
196
|
+
}), /*#__PURE__*/jsx(PaletteSelect, {
|
|
197
|
+
theme: theme,
|
|
198
|
+
onClick: setTheme
|
|
199
|
+
})]
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
TimeSeriesChart.displayName = "TimeSeriesChart";
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Chart to display simple data time series
|
|
206
|
+
*/
|
|
207
|
+
var TimeSeries = function TimeSeries(props) {
|
|
208
|
+
return /*#__PURE__*/jsx(ChartWrapper, {
|
|
209
|
+
children: /*#__PURE__*/jsx(TimeSeriesChart, _objectSpread({}, props))
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export { TimeSeries };
|