@easyv/charts 1.4.33 → 1.4.34
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/lib/components/Chart.js
CHANGED
|
@@ -11,6 +11,8 @@ exports["default"] = void 0;
|
|
|
11
11
|
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
13
|
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
|
|
14
16
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
17
|
|
|
16
18
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -19,6 +21,8 @@ var _context = require("../context");
|
|
|
19
21
|
|
|
20
22
|
var _ = require(".");
|
|
21
23
|
|
|
24
|
+
var _d3v = require("d3v7");
|
|
25
|
+
|
|
22
26
|
var _excluded = ["id", "type", "config", "config", "data", "onRelative", "emit", "emitEvent"];
|
|
23
27
|
|
|
24
28
|
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); }
|
|
@@ -48,6 +52,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
48
52
|
type = _ref2.type,
|
|
49
53
|
config = _ref2.config,
|
|
50
54
|
_ref2$config = _ref2.config,
|
|
55
|
+
axes = _ref2$config.axes,
|
|
51
56
|
_ref2$config$chart = _ref2$config.chart,
|
|
52
57
|
_ref2$config$chart$di = _ref2$config$chart.dimension.chartDimension,
|
|
53
58
|
height = _ref2$config$chart$di.height,
|
|
@@ -58,7 +63,7 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
58
63
|
marginBottom = _ref2$config$chart$ma.marginBottom,
|
|
59
64
|
marginTop = _ref2$config$chart$ma.marginTop,
|
|
60
65
|
interaction = _ref2$config.interaction,
|
|
61
|
-
|
|
66
|
+
originData = _ref2.data,
|
|
62
67
|
onRelative = _ref2.onRelative,
|
|
63
68
|
emit = _ref2.emit,
|
|
64
69
|
emitEvent = _ref2.emitEvent,
|
|
@@ -101,7 +106,33 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
101
106
|
svg: svg,
|
|
102
107
|
onEmit: onEmit
|
|
103
108
|
};
|
|
104
|
-
}, [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]);
|
|
109
|
+
}, [id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]); //对轴类图表进行
|
|
110
|
+
|
|
111
|
+
var data = originData;
|
|
112
|
+
|
|
113
|
+
if (axes) {
|
|
114
|
+
var xAxis = axes.find(function (d) {
|
|
115
|
+
return d.axisType == "x";
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (xAxis) {
|
|
119
|
+
var _xAxis$config$label = xAxis.config.label,
|
|
120
|
+
autoSort = _xAxis$config$label.autoSort,
|
|
121
|
+
_type = _xAxis$config$label.format.type;
|
|
122
|
+
|
|
123
|
+
if (_type == "date" && autoSort) {
|
|
124
|
+
var groupBySeries = (0, _d3v.group)(data, function (d) {
|
|
125
|
+
return d.s;
|
|
126
|
+
});
|
|
127
|
+
data = (0, _toConsumableArray2["default"])(groupBySeries).flatMap(function (d) {
|
|
128
|
+
return d[1].sort(function (a, b) {
|
|
129
|
+
return a.x > b.x ? 1 : -1;
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
105
136
|
return /*#__PURE__*/_react["default"].createElement(_context.chartContext.Provider, {
|
|
106
137
|
value: context
|
|
107
138
|
}, type == 'pie' ? /*#__PURE__*/_react["default"].createElement(_.PieChart, (0, _extends2["default"])({
|
package/package.json
CHANGED
package/src/components/Chart.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import React, { memo, useMemo, createRef, useCallback } from 'react';
|
|
5
5
|
import { chartContext } from '../context';
|
|
6
6
|
import { PieChart, CartesianChart } from '.';
|
|
7
|
+
import { group } from 'd3v7';
|
|
7
8
|
|
|
8
9
|
const getCallbackData = (action,callbacks, data) => {
|
|
9
10
|
const callbackData={};
|
|
@@ -23,6 +24,7 @@ const Chart = memo(
|
|
|
23
24
|
type,
|
|
24
25
|
config,
|
|
25
26
|
config: {
|
|
27
|
+
axes,
|
|
26
28
|
chart: {
|
|
27
29
|
dimension: {
|
|
28
30
|
chartDimension: { height, width },
|
|
@@ -31,7 +33,7 @@ const Chart = memo(
|
|
|
31
33
|
},
|
|
32
34
|
interaction,
|
|
33
35
|
},
|
|
34
|
-
data,
|
|
36
|
+
data:originData,
|
|
35
37
|
onRelative,
|
|
36
38
|
emit,
|
|
37
39
|
emitEvent,
|
|
@@ -85,6 +87,21 @@ const Chart = memo(
|
|
|
85
87
|
}),
|
|
86
88
|
[id, chartWidth, chartHeight, triggerOnRelative, svg, onEmit]
|
|
87
89
|
);
|
|
90
|
+
//对轴类图表进行
|
|
91
|
+
let data = originData;
|
|
92
|
+
if(axes){
|
|
93
|
+
const xAxis = axes.find(d=>d.axisType=="x");
|
|
94
|
+
if(xAxis){
|
|
95
|
+
const { config:{ label:{ autoSort, format:{ type } } } } = xAxis;
|
|
96
|
+
if(type=="date" && autoSort){
|
|
97
|
+
const groupBySeries = group(data, (d) => d.s);
|
|
98
|
+
data=[...groupBySeries].flatMap(d=>{
|
|
99
|
+
return d[1].sort((a,b)=>a.x>b.x?1:-1)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
88
105
|
return (
|
|
89
106
|
<chartContext.Provider value={context}>
|
|
90
107
|
{type == 'pie' ? (
|