amazing-react-charts 0.5.2 → 0.7.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/dist/core/MultipurposeChart.d.ts +21 -0
- package/dist/core/MultipurposeChart.js +230 -0
- package/dist/core/RadarChart.d.ts +19 -0
- package/dist/core/RadarChart.js +90 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +17 -1
- package/package.json +1 -1
- package/src/core/MultipurposeChart.tsx +247 -0
- package/src/core/RadarChart.tsx +87 -0
- package/src/docz/MultipurposeChart.mdx +39 -0
- package/src/docz/RadarChart.mdx +89 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IDefaultChartProps, WidthProps } from './types';
|
|
3
|
+
interface MultipurposeChartProps {
|
|
4
|
+
series: Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
data: number[];
|
|
8
|
+
}>;
|
|
9
|
+
xData: Array<number | string>;
|
|
10
|
+
xType?: IDefaultChartProps['xType'];
|
|
11
|
+
yType?: IDefaultChartProps['yType'];
|
|
12
|
+
width?: WidthProps;
|
|
13
|
+
dateFormat?: string;
|
|
14
|
+
yComplement?: (input: string) => string;
|
|
15
|
+
rangeSelector?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const WIDTH_STYLE: {
|
|
18
|
+
width: string;
|
|
19
|
+
};
|
|
20
|
+
declare const _default: React.MemoExoticComponent<(props: MultipurposeChartProps) => JSX.Element>;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = exports.WIDTH_STYLE = void 0;
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
|
|
16
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
17
|
+
|
|
18
|
+
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
|
|
19
|
+
|
|
20
|
+
var _auxiliarFunctions = require("../lib/auxiliarFunctions");
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
29
|
+
|
|
30
|
+
var WIDTH_STYLE = {
|
|
31
|
+
width: '99.9%'
|
|
32
|
+
};
|
|
33
|
+
exports.WIDTH_STYLE = WIDTH_STYLE;
|
|
34
|
+
|
|
35
|
+
var isDarkColor = function isDarkColor(color) {
|
|
36
|
+
var c = color.substring(1);
|
|
37
|
+
var rgb = parseInt(c, 16);
|
|
38
|
+
var r = rgb >> 16 & 0xff;
|
|
39
|
+
var g = rgb >> 8 & 0xff;
|
|
40
|
+
var b = rgb >> 0 & 0xff;
|
|
41
|
+
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
42
|
+
return luma < 40;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var MAGIC_TYPE = ['line', 'bar', 'stack'];
|
|
46
|
+
|
|
47
|
+
var MultipurposeChart = function MultipurposeChart(props) {
|
|
48
|
+
var series = props.series,
|
|
49
|
+
yType = props.yType,
|
|
50
|
+
xData = props.xData,
|
|
51
|
+
xType = props.xType,
|
|
52
|
+
width = props.width,
|
|
53
|
+
yComplement = props.yComplement,
|
|
54
|
+
dateFormat = props.dateFormat,
|
|
55
|
+
rangeSelector = props.rangeSelector;
|
|
56
|
+
var ref = (0, _react.useRef)(null);
|
|
57
|
+
var actualGraph = (0, _react.useRef)('bar');
|
|
58
|
+
var isStacked = (0, _react.useRef)(false);
|
|
59
|
+
|
|
60
|
+
var getLabelOptions = function getLabelOptions(barColor) {
|
|
61
|
+
var isDarkBarColor = isDarkColor(barColor);
|
|
62
|
+
return {
|
|
63
|
+
show: true,
|
|
64
|
+
position: 'insideBottom',
|
|
65
|
+
align: 'left',
|
|
66
|
+
verticalAlign: 'middle',
|
|
67
|
+
rotate: 90,
|
|
68
|
+
formatter: yComplement('{c}') + ' {name|{a}}',
|
|
69
|
+
color: isDarkBarColor ? '#FFFFFF' : '#000000',
|
|
70
|
+
fontSize: 16,
|
|
71
|
+
rich: {
|
|
72
|
+
name: {
|
|
73
|
+
color: isDarkBarColor ? '#FFFFFF' : '#000000'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
var formatTooltip = function formatTooltip(lines) {
|
|
80
|
+
var takeComplement = function takeComplement(value) {
|
|
81
|
+
return yType === 'time' ? (0, _auxiliarFunctions.timeConvert)(Number(value)) + 'h' : (0, _auxiliarFunctions.takeLabelComplement)(Number(value), yComplement);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
var linesTooltips = lines.map(function (line) {
|
|
85
|
+
return line.seriesName + ': ' + takeComplement(Number(line.value)) + '<br>';
|
|
86
|
+
});
|
|
87
|
+
var tooltipTitle = xType === 'time' ? (0, _auxiliarFunctions.formatTime)(dateFormat === 'yyyy-MM' ? lines[0].name + '-02' : lines[0].name, dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd MMM') : lines[0].name;
|
|
88
|
+
return "".concat(tooltipTitle, " <br> ").concat(linesTooltips.join(' '));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
var slider = rangeSelector ? [{
|
|
92
|
+
type: 'slider',
|
|
93
|
+
xAxisIndex: 0,
|
|
94
|
+
filterMode: 'none'
|
|
95
|
+
}] : [];
|
|
96
|
+
var options = {
|
|
97
|
+
color: (0, _toConsumableArray2.default)(series.map(function (it) {
|
|
98
|
+
return it.color;
|
|
99
|
+
})),
|
|
100
|
+
dataZoom: [].concat(slider),
|
|
101
|
+
tooltip: {
|
|
102
|
+
formatter: formatTooltip,
|
|
103
|
+
trigger: 'axis',
|
|
104
|
+
axisPointer: {
|
|
105
|
+
type: 'shadow'
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
legend: {
|
|
109
|
+
data: series.map(function (it) {
|
|
110
|
+
return it.name;
|
|
111
|
+
})
|
|
112
|
+
},
|
|
113
|
+
toolbox: {
|
|
114
|
+
show: true,
|
|
115
|
+
orient: 'vertical',
|
|
116
|
+
left: 'right',
|
|
117
|
+
top: 'center',
|
|
118
|
+
feature: {
|
|
119
|
+
mark: {
|
|
120
|
+
show: true
|
|
121
|
+
},
|
|
122
|
+
dataView: {
|
|
123
|
+
show: true,
|
|
124
|
+
readOnly: false,
|
|
125
|
+
title: 'Visualização de dados',
|
|
126
|
+
lang: ['Visualização de dados', 'Fechar', 'Atualizar']
|
|
127
|
+
},
|
|
128
|
+
magicType: {
|
|
129
|
+
show: true,
|
|
130
|
+
type: MAGIC_TYPE,
|
|
131
|
+
title: {
|
|
132
|
+
line: 'Gráfico de linha',
|
|
133
|
+
bar: 'Gráfico de barras',
|
|
134
|
+
stack: 'Estacar',
|
|
135
|
+
tile: 'Lado a lado'
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
saveAsImage: {
|
|
139
|
+
show: true,
|
|
140
|
+
title: 'Salvar como imagem'
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
xAxis: {
|
|
145
|
+
type: yType || 'category',
|
|
146
|
+
axisTick: {
|
|
147
|
+
show: false
|
|
148
|
+
},
|
|
149
|
+
data: xData
|
|
150
|
+
},
|
|
151
|
+
yAxis: {
|
|
152
|
+
type: xType || 'value'
|
|
153
|
+
},
|
|
154
|
+
series: (0, _toConsumableArray2.default)(series.map(function (it) {
|
|
155
|
+
return {
|
|
156
|
+
name: it.name,
|
|
157
|
+
type: 'bar',
|
|
158
|
+
barGap: 0,
|
|
159
|
+
label: getLabelOptions(it.color),
|
|
160
|
+
emphasis: {
|
|
161
|
+
focus: 'series'
|
|
162
|
+
},
|
|
163
|
+
data: it.data
|
|
164
|
+
};
|
|
165
|
+
}))
|
|
166
|
+
};
|
|
167
|
+
var onEvents = {
|
|
168
|
+
'magictypechanged': function magictypechanged(e) {
|
|
169
|
+
var echartsInstance = ref.current.getEchartsInstance();
|
|
170
|
+
var actualOptions = echartsInstance.getOption();
|
|
171
|
+
|
|
172
|
+
if (e.currentType === 'stack') {
|
|
173
|
+
isStacked.current = !isStacked.current;
|
|
174
|
+
} else {
|
|
175
|
+
actualGraph.current = e.currentType;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
var newOptions = _objectSpread({}, actualOptions);
|
|
179
|
+
|
|
180
|
+
newOptions.toolbox = options.toolbox;
|
|
181
|
+
var isVertical = actualGraph.current === 'bar' && !isStacked.current;
|
|
182
|
+
var isLine = actualGraph.current === 'line';
|
|
183
|
+
var originalSeries = options.series;
|
|
184
|
+
newOptions.series.forEach(function (it, i) {
|
|
185
|
+
it.label.rotate = isVertical ? 90 : 0;
|
|
186
|
+
it.label.align = isVertical ? 'left' : 'center';
|
|
187
|
+
it.type = actualGraph.current;
|
|
188
|
+
it.label.rich.name.color = isLine ? '#000000' : originalSeries[i].label.rich.name.color;
|
|
189
|
+
it.label.color = isLine ? '#000000' : originalSeries[i].label.color;
|
|
190
|
+
});
|
|
191
|
+
ref.current.getEchartsInstance().setOption(newOptions);
|
|
192
|
+
},
|
|
193
|
+
'mouseover': function mouseover(e) {
|
|
194
|
+
var echartsInstance = ref.current.getEchartsInstance();
|
|
195
|
+
var actualOptions = echartsInstance.getOption();
|
|
196
|
+
actualOptions.color = (0, _toConsumableArray2.default)(options.color.map(function (it, i) {
|
|
197
|
+
return e.componentIndex === i ? it : "#".concat(it.slice(1), "66");
|
|
198
|
+
}));
|
|
199
|
+
actualOptions.series.forEach(function (it, i) {
|
|
200
|
+
if (i === e.componentIndex) return;
|
|
201
|
+
it.label.rich.name.color = '#00000000';
|
|
202
|
+
it.label.color = '#00000000';
|
|
203
|
+
});
|
|
204
|
+
echartsInstance.setOption(_objectSpread({}, actualOptions));
|
|
205
|
+
},
|
|
206
|
+
'mouseout': function mouseout() {
|
|
207
|
+
var echartsInstance = ref.current.getEchartsInstance();
|
|
208
|
+
var actualOptions = echartsInstance.getOption();
|
|
209
|
+
actualOptions.color = (0, _toConsumableArray2.default)(options.color);
|
|
210
|
+
var originalSeries = options.series;
|
|
211
|
+
var isLine = actualGraph.current === 'line';
|
|
212
|
+
actualOptions.series.forEach(function (it, i) {
|
|
213
|
+
it.label.rich.name.color = isLine ? '#000000' : originalSeries[i].label.rich.name.color;
|
|
214
|
+
it.label.color = isLine ? '#000000' : originalSeries[i].label.color;
|
|
215
|
+
});
|
|
216
|
+
echartsInstance.setOption(_objectSpread({}, actualOptions));
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
return /*#__PURE__*/_react.default.createElement(_echartsForReact.default, {
|
|
220
|
+
style: WIDTH_STYLE,
|
|
221
|
+
opts: (0, _auxiliarFunctions.getWidthOpts)(width || 'auto'),
|
|
222
|
+
option: options,
|
|
223
|
+
ref: ref,
|
|
224
|
+
onEvents: onEvents
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
var _default = _react.default.memo(MultipurposeChart);
|
|
229
|
+
|
|
230
|
+
exports.default = _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { WidthProps } from './types';
|
|
3
|
+
interface RadarChartProps {
|
|
4
|
+
series: Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
color: string;
|
|
7
|
+
data: number[];
|
|
8
|
+
}>;
|
|
9
|
+
indicators: Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
max: number;
|
|
12
|
+
}>;
|
|
13
|
+
width?: WidthProps;
|
|
14
|
+
yComplement?: (input: string) => string;
|
|
15
|
+
circular?: boolean;
|
|
16
|
+
highlight?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare const RadarChart: (props: RadarChartProps) => JSX.Element;
|
|
19
|
+
export default RadarChart;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
16
|
+
var _auxiliarFunctions = require("../lib/auxiliarFunctions");
|
|
17
|
+
|
|
18
|
+
var _DonutChart = require("./DonutChart");
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
|
+
|
|
24
|
+
var RadarChart = function RadarChart(props) {
|
|
25
|
+
var width = props.width,
|
|
26
|
+
series = props.series,
|
|
27
|
+
indicators = props.indicators,
|
|
28
|
+
yComplement = props.yComplement,
|
|
29
|
+
circular = props.circular,
|
|
30
|
+
highlight = props.highlight;
|
|
31
|
+
|
|
32
|
+
var formatTooltip = function formatTooltip(lines) {
|
|
33
|
+
var takeComplement = function takeComplement(value) {
|
|
34
|
+
return (0, _auxiliarFunctions.takeLabelComplement)(Number(value), yComplement);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var linesTooltips = lines.data.value.map(function (value, i) {
|
|
38
|
+
return indicators[i].name + ': ' + takeComplement(Number(value)) + '<br>';
|
|
39
|
+
});
|
|
40
|
+
return "".concat(lines.name, " <br> ").concat(linesTooltips.join(' '));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var emphasis = highlight ? {
|
|
44
|
+
emphasis: {
|
|
45
|
+
areaStyle: {
|
|
46
|
+
color: 'rgba(0,250,0,0.3)'
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} : {};
|
|
50
|
+
var options = {
|
|
51
|
+
color: series.map(function (it) {
|
|
52
|
+
return it.color;
|
|
53
|
+
}),
|
|
54
|
+
tooltip: {
|
|
55
|
+
formatter: formatTooltip,
|
|
56
|
+
trigger: 'item'
|
|
57
|
+
},
|
|
58
|
+
legend: {
|
|
59
|
+
data: series.map(function (it) {
|
|
60
|
+
return it.name;
|
|
61
|
+
})
|
|
62
|
+
},
|
|
63
|
+
radar: {
|
|
64
|
+
shape: circular && 'circle',
|
|
65
|
+
indicator: indicators.map(function (it) {
|
|
66
|
+
return {
|
|
67
|
+
name: it.name,
|
|
68
|
+
max: it.max
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
},
|
|
72
|
+
series: [_objectSpread({
|
|
73
|
+
type: 'radar',
|
|
74
|
+
data: series.map(function (it) {
|
|
75
|
+
return {
|
|
76
|
+
name: it.name,
|
|
77
|
+
value: it.data
|
|
78
|
+
};
|
|
79
|
+
})
|
|
80
|
+
}, emphasis)]
|
|
81
|
+
};
|
|
82
|
+
return /*#__PURE__*/_react.default.createElement(_echartsForReact.default, {
|
|
83
|
+
style: _DonutChart.WIDTH_STYLE,
|
|
84
|
+
opts: (0, _auxiliarFunctions.getWidthOpts)(width || 'auto'),
|
|
85
|
+
option: options
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var _default = RadarChart;
|
|
90
|
+
exports.default = _default;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { default as PictorialChart } from './core/PictorialChart';
|
|
|
9
9
|
export { default as AudiometryChart } from './core/AudiometryChart';
|
|
10
10
|
export { default as DonutChart } from './core/DonutChart';
|
|
11
11
|
export { default as CoordinateLineChart } from './core/CoordinateLineChart';
|
|
12
|
+
export { default as MultipurposeChart } from './core/MultipurposeChart';
|
|
13
|
+
export { default as RadarChart } from './core/RadarChart';
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,18 @@ Object.defineProperty(exports, "CoordinateLineChart", {
|
|
|
71
71
|
return _CoordinateLineChart.default;
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
+
Object.defineProperty(exports, "MultipurposeChart", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function get() {
|
|
77
|
+
return _MultipurposeChart.default;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "RadarChart", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function get() {
|
|
83
|
+
return _RadarChart.default;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
74
86
|
|
|
75
87
|
var _AreaChart = _interopRequireDefault(require("./core/AreaChart"));
|
|
76
88
|
|
|
@@ -92,4 +104,8 @@ var _AudiometryChart = _interopRequireDefault(require("./core/AudiometryChart"))
|
|
|
92
104
|
|
|
93
105
|
var _DonutChart = _interopRequireDefault(require("./core/DonutChart"));
|
|
94
106
|
|
|
95
|
-
var _CoordinateLineChart = _interopRequireDefault(require("./core/CoordinateLineChart"));
|
|
107
|
+
var _CoordinateLineChart = _interopRequireDefault(require("./core/CoordinateLineChart"));
|
|
108
|
+
|
|
109
|
+
var _MultipurposeChart = _interopRequireDefault(require("./core/MultipurposeChart"));
|
|
110
|
+
|
|
111
|
+
var _RadarChart = _interopRequireDefault(require("./core/RadarChart"));
|
package/package.json
CHANGED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import React, { useRef } from 'react'
|
|
3
|
+
import ReactEcharts from 'echarts-for-react'
|
|
4
|
+
import { EChartOption } from 'echarts/lib/echarts'
|
|
5
|
+
import {
|
|
6
|
+
formatTime,
|
|
7
|
+
getWidthOpts,
|
|
8
|
+
takeLabelComplement,
|
|
9
|
+
timeConvert
|
|
10
|
+
} from '../lib/auxiliarFunctions'
|
|
11
|
+
import { IDefaultChartProps, WidthProps } from './types'
|
|
12
|
+
|
|
13
|
+
interface MultipurposeChartProps {
|
|
14
|
+
series: Array<{
|
|
15
|
+
name: string
|
|
16
|
+
color?: string
|
|
17
|
+
data: number[]
|
|
18
|
+
}>
|
|
19
|
+
xData: Array<number | string>
|
|
20
|
+
xType?: IDefaultChartProps['xType']
|
|
21
|
+
yType?: IDefaultChartProps['yType']
|
|
22
|
+
width?: WidthProps
|
|
23
|
+
dateFormat?: string
|
|
24
|
+
yComplement?: (input: string) => string
|
|
25
|
+
rangeSelector?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const WIDTH_STYLE = { width: '99.9%' }
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const isDarkColor = (color: string) => {
|
|
32
|
+
const c = color.substring(1)
|
|
33
|
+
const rgb = parseInt(c, 16)
|
|
34
|
+
const r = (rgb >> 16) & 0xff
|
|
35
|
+
const g = (rgb >> 8) & 0xff
|
|
36
|
+
const b = (rgb >> 0) & 0xff
|
|
37
|
+
|
|
38
|
+
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
39
|
+
return luma < 40
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const MAGIC_TYPE = ['line', 'bar', 'stack']
|
|
43
|
+
|
|
44
|
+
const MultipurposeChart = (props: MultipurposeChartProps) => {
|
|
45
|
+
const {series, yType, xData, xType,
|
|
46
|
+
width, yComplement, dateFormat, rangeSelector} = props
|
|
47
|
+
const ref = useRef<ReactEcharts>(null)
|
|
48
|
+
const actualGraph = useRef('bar')
|
|
49
|
+
const isStacked = useRef(false)
|
|
50
|
+
|
|
51
|
+
const getLabelOptions = (barColor: string) => {
|
|
52
|
+
const isDarkBarColor = isDarkColor(barColor)
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
show: true,
|
|
56
|
+
position: 'insideBottom',
|
|
57
|
+
align: 'left',
|
|
58
|
+
verticalAlign: 'middle',
|
|
59
|
+
rotate: 90,
|
|
60
|
+
formatter: yComplement('{c}') + ' {name|{a}}',
|
|
61
|
+
color: isDarkBarColor ? '#FFFFFF' : '#000000',
|
|
62
|
+
fontSize: 16,
|
|
63
|
+
rich: {
|
|
64
|
+
name: {
|
|
65
|
+
color: isDarkBarColor ? '#FFFFFF' : '#000000'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const formatTooltip = (
|
|
72
|
+
lines: { name: string, seriesName: string, value: number }[]
|
|
73
|
+
) => {
|
|
74
|
+
const takeComplement = (value: number) =>
|
|
75
|
+
yType === 'time'
|
|
76
|
+
? timeConvert(Number(value)) + 'h'
|
|
77
|
+
: takeLabelComplement(Number(value), yComplement)
|
|
78
|
+
|
|
79
|
+
const linesTooltips = lines.map(
|
|
80
|
+
line =>
|
|
81
|
+
line.seriesName + ': ' + takeComplement(Number(line.value)) + '<br>'
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
const tooltipTitle =
|
|
85
|
+
xType === 'time'
|
|
86
|
+
? formatTime(
|
|
87
|
+
dateFormat === 'yyyy-MM' ? lines[0].name + '-02' : lines[0].name,
|
|
88
|
+
dateFormat === 'yyyy-MM' ? 'MMM/yy' : 'dd MMM'
|
|
89
|
+
)
|
|
90
|
+
: lines[0].name
|
|
91
|
+
|
|
92
|
+
return `${tooltipTitle} <br> ${linesTooltips.join(' ')}`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const slider = rangeSelector ?
|
|
96
|
+
[
|
|
97
|
+
{
|
|
98
|
+
type: 'slider',
|
|
99
|
+
xAxisIndex: 0,
|
|
100
|
+
filterMode: 'none'
|
|
101
|
+
},
|
|
102
|
+
]: []
|
|
103
|
+
|
|
104
|
+
const options: EChartOption = {
|
|
105
|
+
color: [...series.map(it => it.color)],
|
|
106
|
+
dataZoom: [...slider],
|
|
107
|
+
tooltip: {
|
|
108
|
+
formatter: formatTooltip,
|
|
109
|
+
trigger: 'axis',
|
|
110
|
+
axisPointer: {
|
|
111
|
+
type: 'shadow'
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
legend: {
|
|
115
|
+
data: series.map(it => it.name)
|
|
116
|
+
},
|
|
117
|
+
toolbox: {
|
|
118
|
+
show: true,
|
|
119
|
+
orient: 'vertical',
|
|
120
|
+
left: 'right',
|
|
121
|
+
top: 'center',
|
|
122
|
+
feature: {
|
|
123
|
+
mark: { show: true },
|
|
124
|
+
dataView: {
|
|
125
|
+
show: true,
|
|
126
|
+
readOnly: false,
|
|
127
|
+
title: 'Visualização de dados',
|
|
128
|
+
lang: ['Visualização de dados', 'Fechar', 'Atualizar']
|
|
129
|
+
},
|
|
130
|
+
magicType: {
|
|
131
|
+
show: true,
|
|
132
|
+
type: MAGIC_TYPE,
|
|
133
|
+
title: {
|
|
134
|
+
line: 'Gráfico de linha',
|
|
135
|
+
bar: 'Gráfico de barras',
|
|
136
|
+
stack: 'Estacar',
|
|
137
|
+
tile: 'Lado a lado',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
saveAsImage: { show: true, title: 'Salvar como imagem' }
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
xAxis: {
|
|
144
|
+
type: yType || 'category',
|
|
145
|
+
axisTick: { show: false },
|
|
146
|
+
data: xData
|
|
147
|
+
},
|
|
148
|
+
yAxis: {
|
|
149
|
+
type: xType || 'value'
|
|
150
|
+
},
|
|
151
|
+
series: [
|
|
152
|
+
...series.map(it => ({
|
|
153
|
+
name: it.name,
|
|
154
|
+
type: 'bar',
|
|
155
|
+
barGap: 0,
|
|
156
|
+
label: getLabelOptions(it.color),
|
|
157
|
+
emphasis: {
|
|
158
|
+
focus: 'series'
|
|
159
|
+
},
|
|
160
|
+
data: it.data
|
|
161
|
+
}))
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const onEvents = {
|
|
166
|
+
'magictypechanged': (e: {
|
|
167
|
+
currentType: 'stack' | 'line' | 'bar'
|
|
168
|
+
}) => {
|
|
169
|
+
const echartsInstance = ref.current.getEchartsInstance()
|
|
170
|
+
const actualOptions = echartsInstance.getOption()
|
|
171
|
+
|
|
172
|
+
if(e.currentType === 'stack') {
|
|
173
|
+
isStacked.current = !isStacked.current
|
|
174
|
+
} else {
|
|
175
|
+
actualGraph.current = e.currentType
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const newOptions: EChartOption = {...actualOptions}
|
|
179
|
+
newOptions.toolbox = options.toolbox
|
|
180
|
+
const isVertical = actualGraph.current === 'bar' && !isStacked.current
|
|
181
|
+
const isLine = actualGraph.current === 'line'
|
|
182
|
+
const originalSeries = options.series
|
|
183
|
+
newOptions.series.forEach((it, i) => {
|
|
184
|
+
it.label.rotate = isVertical ? 90 : 0
|
|
185
|
+
it.label.align = isVertical ? 'left': 'center'
|
|
186
|
+
it.type = actualGraph.current
|
|
187
|
+
it.label.rich.name.color = isLine
|
|
188
|
+
? '#000000'
|
|
189
|
+
: originalSeries[i].label.rich.name.color
|
|
190
|
+
it.label.color = isLine ? '#000000' : originalSeries[i].label.color
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
ref.current.getEchartsInstance().setOption(newOptions)
|
|
194
|
+
},
|
|
195
|
+
'mouseover': (e) => {
|
|
196
|
+
const echartsInstance = ref.current.getEchartsInstance()
|
|
197
|
+
const actualOptions = echartsInstance.getOption()
|
|
198
|
+
|
|
199
|
+
actualOptions.color = [
|
|
200
|
+
...options.color.map(
|
|
201
|
+
(it, i) => e.componentIndex === i ? it : `#${it.slice(1)}66`
|
|
202
|
+
)
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
actualOptions.series.forEach((it, i) => {
|
|
206
|
+
if(i === e.componentIndex)
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
it.label.rich.name.color = '#00000000'
|
|
210
|
+
it.label.color = '#00000000'
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
echartsInstance.setOption({...actualOptions})
|
|
214
|
+
},
|
|
215
|
+
'mouseout': () => {
|
|
216
|
+
const echartsInstance = ref.current.getEchartsInstance()
|
|
217
|
+
const actualOptions = echartsInstance.getOption()
|
|
218
|
+
|
|
219
|
+
actualOptions.color = [
|
|
220
|
+
...options.color
|
|
221
|
+
]
|
|
222
|
+
|
|
223
|
+
const originalSeries = options.series
|
|
224
|
+
const isLine = actualGraph.current === 'line'
|
|
225
|
+
actualOptions.series.forEach((it, i) => {
|
|
226
|
+
it.label.rich.name.color = isLine
|
|
227
|
+
? '#000000'
|
|
228
|
+
: originalSeries[i].label.rich.name.color
|
|
229
|
+
it.label.color = isLine ? '#000000' : originalSeries[i].label.color
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
echartsInstance.setOption({...actualOptions})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<ReactEcharts
|
|
238
|
+
style={WIDTH_STYLE}
|
|
239
|
+
opts={getWidthOpts(width || 'auto')}
|
|
240
|
+
option={options}
|
|
241
|
+
ref={ref}
|
|
242
|
+
onEvents={onEvents}
|
|
243
|
+
/>
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export default React.memo(MultipurposeChart)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import ReactEcharts from 'echarts-for-react'
|
|
2
|
+
import { EChartOption } from 'echarts/lib/echarts'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { getWidthOpts, takeLabelComplement } from '../lib/auxiliarFunctions'
|
|
5
|
+
import { WIDTH_STYLE } from './DonutChart'
|
|
6
|
+
import { WidthProps } from './types'
|
|
7
|
+
|
|
8
|
+
interface RadarChartProps {
|
|
9
|
+
series: Array<{
|
|
10
|
+
name: string
|
|
11
|
+
color: string
|
|
12
|
+
data: number[]
|
|
13
|
+
}>
|
|
14
|
+
indicators: Array<{
|
|
15
|
+
name: string
|
|
16
|
+
max: number
|
|
17
|
+
}>
|
|
18
|
+
width?: WidthProps
|
|
19
|
+
yComplement?: (input: string) => string
|
|
20
|
+
circular?: boolean
|
|
21
|
+
highlight?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const RadarChart = (props: RadarChartProps) => {
|
|
25
|
+
const { width, series, indicators, yComplement, circular, highlight } = props
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const formatTooltip = (
|
|
29
|
+
lines: { name: string, seriesName: string, value: number, data: any }
|
|
30
|
+
) => {
|
|
31
|
+
const takeComplement =
|
|
32
|
+
(value: number) => takeLabelComplement(Number(value), yComplement)
|
|
33
|
+
|
|
34
|
+
const linesTooltips = lines.data.value.map(
|
|
35
|
+
(value: string | number, i: number) =>
|
|
36
|
+
indicators[i].name + ': ' + takeComplement(Number(value)) + '<br>'
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return `${lines.name} <br> ${linesTooltips.join(' ')}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const emphasis = highlight ? {
|
|
43
|
+
emphasis: {
|
|
44
|
+
areaStyle: {
|
|
45
|
+
color: 'rgba(0,250,0,0.3)'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} : {}
|
|
49
|
+
|
|
50
|
+
const options: EChartOption = {
|
|
51
|
+
color: series.map(it => it.color),
|
|
52
|
+
tooltip: {
|
|
53
|
+
formatter: formatTooltip,
|
|
54
|
+
trigger: 'item',
|
|
55
|
+
},
|
|
56
|
+
legend: {
|
|
57
|
+
data: series.map(it => it.name)
|
|
58
|
+
},
|
|
59
|
+
radar: {
|
|
60
|
+
shape: circular && 'circle',
|
|
61
|
+
indicator: indicators.map(it => ({
|
|
62
|
+
name: it.name,
|
|
63
|
+
max: it.max
|
|
64
|
+
}))
|
|
65
|
+
},
|
|
66
|
+
series: [
|
|
67
|
+
{
|
|
68
|
+
type: 'radar',
|
|
69
|
+
data: series.map(it => ({
|
|
70
|
+
name: it.name,
|
|
71
|
+
value: it.data
|
|
72
|
+
})),
|
|
73
|
+
...emphasis
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<ReactEcharts
|
|
80
|
+
style={WIDTH_STYLE}
|
|
81
|
+
opts={getWidthOpts(width || 'auto')}
|
|
82
|
+
option={options}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default RadarChart
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Multipurpose charts
|
|
3
|
+
route: /multipurpose-charts
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import MultipurposeChart from '../core/MultipurposeChart'
|
|
7
|
+
import { Playground } from 'docz'
|
|
8
|
+
|
|
9
|
+
# Multipurpose chart example
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
<Playground>
|
|
13
|
+
<MultipurposeChart
|
|
14
|
+
yComplement={value => `R$ ${value},00`}
|
|
15
|
+
series={[
|
|
16
|
+
{
|
|
17
|
+
name: 'Dinheiro',
|
|
18
|
+
color: '#142459',
|
|
19
|
+
data: [320, 332, 301, 334, 390]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'Crédito',
|
|
23
|
+
color: '#176BA0',
|
|
24
|
+
data: [220, 182, 191, 234, 290]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Débito',
|
|
28
|
+
color: '#19AADE',
|
|
29
|
+
data: [150, 232, 201, 154, 190]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'Pix',
|
|
33
|
+
color: '#1AC9E6',
|
|
34
|
+
data: [98, 77, 101, 99, 40]
|
|
35
|
+
}
|
|
36
|
+
]}
|
|
37
|
+
xData={['2012', '2013', '2014', '2015', '2016']}
|
|
38
|
+
/>
|
|
39
|
+
</Playground>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Radar charts
|
|
3
|
+
route: /radar-chart
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import RadarChart from '../core/RadarChart'
|
|
7
|
+
import { Playground } from 'docz'
|
|
8
|
+
|
|
9
|
+
# Radar chart example
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
<Playground>
|
|
13
|
+
<RadarChart
|
|
14
|
+
yComplement={value => `R$ ${value},00`}
|
|
15
|
+
series={[
|
|
16
|
+
{
|
|
17
|
+
name: 'Dinheiro',
|
|
18
|
+
color: '#142459',
|
|
19
|
+
data: [320, 332, 301, 334, 390]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'Crédito',
|
|
23
|
+
color: '#176BA0',
|
|
24
|
+
data: [220, 182, 191, 234, 290]
|
|
25
|
+
},
|
|
26
|
+
]}
|
|
27
|
+
indicators={[
|
|
28
|
+
{ name: 'Roupas', max: 500 },
|
|
29
|
+
{ name: 'Sapatos', max: 500 },
|
|
30
|
+
{ name: 'Bolsas', max: 500 },
|
|
31
|
+
{ name: 'Acessórios', max: 500 },
|
|
32
|
+
{ name: 'Outros', max: 500 }
|
|
33
|
+
]}
|
|
34
|
+
/>
|
|
35
|
+
</Playground>
|
|
36
|
+
|
|
37
|
+
## Circular chart
|
|
38
|
+
<Playground>
|
|
39
|
+
<RadarChart
|
|
40
|
+
circular
|
|
41
|
+
yComplement={value => `R$ ${value},00`}
|
|
42
|
+
series={[
|
|
43
|
+
{
|
|
44
|
+
name: 'Dinheiro',
|
|
45
|
+
color: '#142459',
|
|
46
|
+
data: [320, 332, 301, 334, 390]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'Crédito',
|
|
50
|
+
color: '#176BA0',
|
|
51
|
+
data: [220, 182, 191, 234, 290]
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
indicators={[
|
|
55
|
+
{ name: 'Roupas', max: 500 },
|
|
56
|
+
{ name: 'Sapatos', max: 500 },
|
|
57
|
+
{ name: 'Bolsas', max: 500 },
|
|
58
|
+
{ name: 'Acessórios', max: 500 },
|
|
59
|
+
{ name: 'Outros', max: 500 }
|
|
60
|
+
]}
|
|
61
|
+
/>
|
|
62
|
+
</Playground>
|
|
63
|
+
|
|
64
|
+
## Area highlighting (mouse over the lines)
|
|
65
|
+
<Playground>
|
|
66
|
+
<RadarChart
|
|
67
|
+
highlight
|
|
68
|
+
yComplement={value => `R$ ${value},00`}
|
|
69
|
+
series={[
|
|
70
|
+
{
|
|
71
|
+
name: 'Dinheiro',
|
|
72
|
+
color: '#142459',
|
|
73
|
+
data: [320, 332, 301, 334, 390]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Crédito',
|
|
77
|
+
color: '#176BA0',
|
|
78
|
+
data: [220, 182, 191, 234, 290]
|
|
79
|
+
},
|
|
80
|
+
]}
|
|
81
|
+
indicators={[
|
|
82
|
+
{ name: 'Roupas', max: 500 },
|
|
83
|
+
{ name: 'Sapatos', max: 500 },
|
|
84
|
+
{ name: 'Bolsas', max: 500 },
|
|
85
|
+
{ name: 'Acessórios', max: 500 },
|
|
86
|
+
{ name: 'Outros', max: 500 }
|
|
87
|
+
]}
|
|
88
|
+
/>
|
|
89
|
+
</Playground>
|
package/src/index.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { default as PictorialChart } from './core/PictorialChart'
|
|
|
9
9
|
export { default as AudiometryChart } from './core/AudiometryChart'
|
|
10
10
|
export { default as DonutChart } from './core/DonutChart'
|
|
11
11
|
export { default as CoordinateLineChart } from './core/CoordinateLineChart'
|
|
12
|
+
export { default as MultipurposeChart } from './core/MultipurposeChart'
|
|
13
|
+
export { default as RadarChart } from './core/RadarChart'
|