@easyv/charts 1.0.73 → 1.1.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/.husky/commit-msg +4 -0
- package/CHANGELOG.md +16 -0
- package/commitlint.config.js +1 -0
- package/lib/components/Axis.js +26 -7
- package/lib/components/Band.js +4 -1
- package/lib/components/CartesianChart.js +8 -2
- package/lib/components/Lighter.js +180 -0
- package/lib/components/PieChart.js +14 -8
- package/lib/components/Tooltip.js +30 -12
- package/lib/components/index.js +8 -0
- package/lib/element/ConicGradient.js +73 -0
- package/lib/utils/index.js +3 -3
- package/package.json +18 -5
- package/src/components/Axis.tsx +91 -73
- package/src/components/Band.tsx +4 -2
- package/src/components/CartesianChart.js +7 -1
- package/src/components/Lighter.jsx +74 -63
- package/src/components/PieChart.js +64 -60
- package/src/components/Tooltip.js +69 -34
- package/src/components/index.js +2 -0
- package/src/types/index.d.ts +4 -1
- package/src/utils/index.js +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
## 1.1.0 (2022-04-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* 轴标签,label支持样式传入 ([749a595](https://gitlab.prod.dtstack.cn:10022/visdev/visApplication/easyv-charts/commit/749a595a96b95917dafdc1766f63efec73398d64))
|
|
11
|
+
* axis轴标签支持点击触发回调 ([1f636e1](https://gitlab.prod.dtstack.cn:10022/visdev/visApplication/easyv-charts/commit/1f636e1840f4f3b48c2b9765ce6087759d82fb17))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **band组件:** 修复foreignObject在Safari浏览器下的位置诡异偏离问题 ([1a65d54](https://gitlab.prod.dtstack.cn:10022/visdev/visApplication/easyv-charts/commit/1a65d54abbcf6c9e84cc85cc8b6a9d28b24fa4c4))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {extends: ['@commitlint/config-conventional']}
|
package/lib/components/Axis.js
CHANGED
|
@@ -11,6 +11,10 @@ exports["default"] = void 0;
|
|
|
11
11
|
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
13
|
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
17
|
+
|
|
14
18
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
19
|
|
|
16
20
|
var _utils = require("../utils");
|
|
@@ -19,9 +23,12 @@ var _context = require("../context");
|
|
|
19
23
|
|
|
20
24
|
var _element = require("../element");
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 defaultEvent = function defaultEvent() {};
|
|
31
|
+
|
|
25
32
|
var defaultAlign = {
|
|
26
33
|
textAnchor: 'middle',
|
|
27
34
|
dominantBaseline: 'middle'
|
|
@@ -156,8 +163,11 @@ var Label = function Label(_ref5) {
|
|
|
156
163
|
_ref5$rotate = _ref5.rotate,
|
|
157
164
|
rotate = _ref5$rotate === void 0 ? 0 : _ref5$rotate,
|
|
158
165
|
config = _ref5.config,
|
|
166
|
+
_ref5$onClick = _ref5.onClick,
|
|
167
|
+
onClick = _ref5$onClick === void 0 ? defaultEvent : _ref5$onClick,
|
|
159
168
|
_ref5$config = _ref5.config,
|
|
160
169
|
show = _ref5$config.show,
|
|
170
|
+
style = _ref5$config.style,
|
|
161
171
|
_ref5$config$translat = _ref5$config.translate,
|
|
162
172
|
translateX = _ref5$config$translat.x,
|
|
163
173
|
translateY = _ref5$config$translat.y,
|
|
@@ -182,11 +192,18 @@ var Label = function Label(_ref5) {
|
|
|
182
192
|
var x = (isVertical ? tickSize * directionX : coordinate) + translateX * directionX;
|
|
183
193
|
var y = (isVertical ? coordinate : tickSize * directionY) + translateY * directionY;
|
|
184
194
|
var translateText = 'translate(' + x + ', ' + y + ')';
|
|
195
|
+
|
|
196
|
+
var _style = style && ((0, _typeof2["default"])(style) == 'object' ? style : style(_label));
|
|
197
|
+
|
|
185
198
|
return /*#__PURE__*/_react["default"].createElement("text", {
|
|
186
199
|
className: className,
|
|
187
|
-
style: {
|
|
188
|
-
whiteSpace:
|
|
189
|
-
},
|
|
200
|
+
style: _objectSpread(_objectSpread({}, _style), {}, {
|
|
201
|
+
whiteSpace: 'pre'
|
|
202
|
+
}),
|
|
203
|
+
onClick: onClick,
|
|
204
|
+
"data-data": JSON.stringify({
|
|
205
|
+
x: label
|
|
206
|
+
}),
|
|
190
207
|
dominantBaseline: dominantBaseline,
|
|
191
208
|
textAnchor: textAnchor,
|
|
192
209
|
fontFamily: fontFamily,
|
|
@@ -215,6 +232,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref6) {
|
|
|
215
232
|
ticks = _ref6.ticks,
|
|
216
233
|
formatter = _ref6.formatter,
|
|
217
234
|
rotate = _ref6.rotate,
|
|
235
|
+
triggerClick = _ref6.triggerClick,
|
|
218
236
|
_ref6$config = _ref6.config,
|
|
219
237
|
on = _ref6$config.on,
|
|
220
238
|
label = _ref6$config.label,
|
|
@@ -294,7 +312,8 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref6) {
|
|
|
294
312
|
label: tick,
|
|
295
313
|
tickSize: _tickSize,
|
|
296
314
|
formatter: formatter,
|
|
297
|
-
rotate: rotate
|
|
315
|
+
rotate: rotate,
|
|
316
|
+
onClick: triggerClick
|
|
298
317
|
}), gridLine && /*#__PURE__*/_react["default"].createElement(_element.Line, (0, _extends2["default"])({
|
|
299
318
|
className: "__easyv-gridLine",
|
|
300
319
|
config: gridLine
|
package/lib/components/Band.js
CHANGED
|
@@ -156,7 +156,10 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref3) {
|
|
|
156
156
|
style: {
|
|
157
157
|
width: '100%',
|
|
158
158
|
height: '100%',
|
|
159
|
-
|
|
159
|
+
|
|
160
|
+
/** Safari Bug **/
|
|
161
|
+
position: 'fixed',
|
|
162
|
+
opacity: fillType == 'pattern' ? opacity : 1,
|
|
160
163
|
background: fillType == 'pattern' ? "50% 50% / ".concat(size.width, "px ").concat(size.height, "px repeat ") + 'url(' + url + ')' : (0, _utils.getBandBackground)(pattern, extent === flag ? highlightFill : fill),
|
|
161
164
|
borderRadius: style == 'square' ? '0 0 0 0' : getBorderRadius({
|
|
162
165
|
isVertical: isVertical,
|
|
@@ -125,7 +125,9 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
125
125
|
config: background
|
|
126
126
|
}), (0, _toConsumableArray2["default"])(axes.values()).map(function (item, index) {
|
|
127
127
|
var config = item.axisType == 'x' ? axisX : item;
|
|
128
|
-
return /*#__PURE__*/_react["default"].createElement(_.Axis, (0, _extends2["default"])({
|
|
128
|
+
return /*#__PURE__*/_react["default"].createElement(_.Axis, (0, _extends2["default"])({
|
|
129
|
+
triggerClick: onInteraction
|
|
130
|
+
}, config, {
|
|
129
131
|
key: index
|
|
130
132
|
}));
|
|
131
133
|
}), showTooltip && /*#__PURE__*/_react["default"].createElement(_.Indicator, (0, _extends2["default"])({}, indicator, indicatorAttr)), series.map(function (_ref2, index) {
|
|
@@ -160,8 +162,12 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
160
162
|
}, tooltip, {
|
|
161
163
|
data: tooltipData,
|
|
162
164
|
x: tooltipX,
|
|
165
|
+
marginLeft: marginLeft,
|
|
166
|
+
marginTop: marginTop,
|
|
163
167
|
tickName: tickName,
|
|
164
|
-
series: series
|
|
168
|
+
series: series,
|
|
169
|
+
width: width,
|
|
170
|
+
height: height
|
|
165
171
|
})), brush && /*#__PURE__*/_react["default"].createElement(_.Brush, {
|
|
166
172
|
config: brush,
|
|
167
173
|
width: width
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
+
|
|
16
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
17
|
+
|
|
18
|
+
var _d3v = require("d3v7");
|
|
19
|
+
|
|
20
|
+
var _utils = require("../utils");
|
|
21
|
+
|
|
22
|
+
var _svgPathProperties = require("svg-path-properties");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 区域图发光跟踪路径
|
|
26
|
+
*/
|
|
27
|
+
var _default = function _default(_ref) {
|
|
28
|
+
var d = _ref.path,
|
|
29
|
+
config = _ref.config,
|
|
30
|
+
_ref$config = _ref.config,
|
|
31
|
+
curveLength = _ref$config.length,
|
|
32
|
+
width = _ref$config.width,
|
|
33
|
+
fill = _ref$config.fill,
|
|
34
|
+
unitStep = _ref$config.unitStep;
|
|
35
|
+
var pointIndexRef = (0, _react.useRef)(0);
|
|
36
|
+
var raf = (0, _react.useRef)(null);
|
|
37
|
+
|
|
38
|
+
var _useState = (0, _react.useState)([]),
|
|
39
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
40
|
+
points = _useState2[0],
|
|
41
|
+
setPoints = _useState2[1];
|
|
42
|
+
|
|
43
|
+
var _useState3 = (0, _react.useState)(null),
|
|
44
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
45
|
+
lighter = _useState4[0],
|
|
46
|
+
setLighter = _useState4[1];
|
|
47
|
+
|
|
48
|
+
var pointLength = points.length;
|
|
49
|
+
var totalLength = getLength(pointLength, curveLength);
|
|
50
|
+
var easingFunc = easing.linear;
|
|
51
|
+
var interpolateList = (0, _react.useMemo)(function () {
|
|
52
|
+
return getColorsInterpolate((0, _utils.getColorList)(fill));
|
|
53
|
+
}, [fill]);
|
|
54
|
+
var drawLigher = (0, _react.useCallback)(function () {
|
|
55
|
+
var STEP = 2;
|
|
56
|
+
var LOOP = false;
|
|
57
|
+
|
|
58
|
+
if (lighter && lighter.children) {
|
|
59
|
+
var currentPointLength = pointIndexRef.current;
|
|
60
|
+
var pointIndex = currentPointLength >= totalLength ? LOOP ? curveLength : 0 : currentPointLength + unitStep + Math.floor(easingFunc(pointIndexRef.current / totalLength) * STEP);
|
|
61
|
+
var overstep = pointIndex - pointLength;
|
|
62
|
+
var startIndex = getPointIndex(pointIndex, pointLength, curveLength);
|
|
63
|
+
var endIndex = getPointIndex(pointIndex + curveLength, pointLength, curveLength);
|
|
64
|
+
var overstepPoints = LOOP && overstep > 0 ? points.slice(0, overstep) : [];
|
|
65
|
+
drawCircle(Array.from(lighter.children), [].concat((0, _toConsumableArray2["default"])(points.slice(startIndex, endIndex)), (0, _toConsumableArray2["default"])(overstepPoints)), interpolateList);
|
|
66
|
+
pointIndexRef.current = pointIndex;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
raf.current = requestAnimationFrame(drawLigher);
|
|
70
|
+
}, [lighter, totalLength, curveLength, unitStep, points, interpolateList]);
|
|
71
|
+
(0, _react.useEffect)(function () {
|
|
72
|
+
var path = new _svgPathProperties.svgPathProperties(d);
|
|
73
|
+
var totalLength = path.getTotalLength();
|
|
74
|
+
var points = [];
|
|
75
|
+
|
|
76
|
+
for (var i = 0; i < totalLength; i++) {
|
|
77
|
+
var _path$getPointAtLengt = path.getPointAtLength(i),
|
|
78
|
+
x = _path$getPointAtLengt.x,
|
|
79
|
+
y = _path$getPointAtLengt.y;
|
|
80
|
+
|
|
81
|
+
points.push({
|
|
82
|
+
index: i,
|
|
83
|
+
x: x,
|
|
84
|
+
y: y
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setPoints(points);
|
|
89
|
+
}, [d, config]);
|
|
90
|
+
(0, _react.useEffect)(function () {
|
|
91
|
+
raf.current = requestAnimationFrame(drawLigher);
|
|
92
|
+
return function () {
|
|
93
|
+
cancelAnimationFrame(raf.current);
|
|
94
|
+
};
|
|
95
|
+
}, [drawLigher]);
|
|
96
|
+
return /*#__PURE__*/_react["default"].createElement("g", {
|
|
97
|
+
ref: setLighter
|
|
98
|
+
}, points.map(function (_ref2, index) {
|
|
99
|
+
var x = _ref2.x,
|
|
100
|
+
y = _ref2.y;
|
|
101
|
+
return /*#__PURE__*/_react["default"].createElement("circle", {
|
|
102
|
+
cx: x,
|
|
103
|
+
cy: y,
|
|
104
|
+
key: index,
|
|
105
|
+
r: width,
|
|
106
|
+
fill: "none"
|
|
107
|
+
});
|
|
108
|
+
}));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports["default"] = _default;
|
|
112
|
+
|
|
113
|
+
var drawCircle = function drawCircle(children, points, interpolateList) {
|
|
114
|
+
var pointLength = points.length; // const [startPoint] = points;
|
|
115
|
+
// const startIndex = startPoint ? startPoint.index : 0;
|
|
116
|
+
|
|
117
|
+
children.forEach(function (child, index) {
|
|
118
|
+
var pointIndex = points.findIndex(function (_ref3) {
|
|
119
|
+
var i = _ref3.index;
|
|
120
|
+
return i == index;
|
|
121
|
+
});
|
|
122
|
+
child.setAttribute('fill', pointIndex > -1 ? getColor(pointIndex / pointLength, //TODO: 颜色插值尚需完善
|
|
123
|
+
interpolateList) : 'none');
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
var getColor = function getColor(x, interpolateList) {
|
|
128
|
+
return interpolateList(x);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
var getLength = function getLength(pointLength, length) {
|
|
132
|
+
if (length > pointLength) {
|
|
133
|
+
return pointLength * 2;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return pointLength + length;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
var getColorsInterpolate = function getColorsInterpolate(colors) {
|
|
140
|
+
var length = colors.length;
|
|
141
|
+
if (!!(length < 2)) return (0, _d3v.scaleLinear)().domain([0, 1]).range([colors[0].color || '#000', colors[0].color || '#000']);
|
|
142
|
+
var linear = (0, _d3v.scaleLinear)().domain(colors.map(function (d) {
|
|
143
|
+
return d.offset;
|
|
144
|
+
})).range(colors.map(function (d) {
|
|
145
|
+
return d.color;
|
|
146
|
+
}));
|
|
147
|
+
return linear;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var easing = {
|
|
151
|
+
linear: function linear() {
|
|
152
|
+
return 0;
|
|
153
|
+
},
|
|
154
|
+
easeIn: function easeIn(k) {
|
|
155
|
+
return Math.pow(k, 3);
|
|
156
|
+
},
|
|
157
|
+
easeOut: function easeOut(k) {
|
|
158
|
+
return 1 - easing.easeIn(1 - k);
|
|
159
|
+
},
|
|
160
|
+
easeInOut: function easeInOut(k) {
|
|
161
|
+
return k < 0.5 ? easing.easeIn(k * 2) / 2 : 1 - easing.easeIn(2 - 2 * k) / 2;
|
|
162
|
+
},
|
|
163
|
+
easeOutIn: function easeOutIn(k) {
|
|
164
|
+
return k < 0.5 ? 0.5 * (1 - easing.easeIn(1 - 2 * k)) : 0.5 * easing.easeIn(k * 2 - 1) + 0.5;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
var getPointIndex = function getPointIndex(pointIndex, pointLength, curveLength) {
|
|
169
|
+
var index = pointIndex - curveLength;
|
|
170
|
+
|
|
171
|
+
if (index < 0) {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (index >= pointLength) {
|
|
176
|
+
return pointLength - 1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return index;
|
|
180
|
+
};
|
|
@@ -625,7 +625,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
625
625
|
textAnchor: "middle",
|
|
626
626
|
style: _objectSpread(_objectSpread({}, categoryTextStyle), {}, {
|
|
627
627
|
fontWeight: categoryTextStyle.bold ? "bold" : "normal",
|
|
628
|
-
fontStyle: categoryTextStyle.italic ? "italic" : "normal"
|
|
628
|
+
fontStyle: categoryTextStyle.italic ? "italic" : "normal",
|
|
629
|
+
pointerEvents: "none"
|
|
629
630
|
}),
|
|
630
631
|
fill: categoryTextStyle.color
|
|
631
632
|
}, /*#__PURE__*/_react["default"].createElement("textPath", {
|
|
@@ -647,6 +648,8 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
647
648
|
}
|
|
648
649
|
}, /*#__PURE__*/_react["default"].createElement(Current, {
|
|
649
650
|
config: current,
|
|
651
|
+
width: width,
|
|
652
|
+
height: height,
|
|
650
653
|
data: _arcs,
|
|
651
654
|
currentIndex: +currentIndex
|
|
652
655
|
})))), decorate && /*#__PURE__*/_react["default"].createElement(_.ConicalGradient, {
|
|
@@ -691,6 +694,8 @@ var Current = function Current(_ref9) {
|
|
|
691
694
|
_ref9$config$value$su2 = _ref9$config$value$su.translate,
|
|
692
695
|
translateSuffixX = _ref9$config$value$su2.x,
|
|
693
696
|
translateSuffixY = _ref9$config$value$su2.y,
|
|
697
|
+
width = _ref9.width,
|
|
698
|
+
height = _ref9.height,
|
|
694
699
|
data = _ref9.data,
|
|
695
700
|
currentIndex = _ref9.currentIndex;
|
|
696
701
|
|
|
@@ -720,20 +725,21 @@ var Current = function Current(_ref9) {
|
|
|
720
725
|
nameList.push(nameTemp);
|
|
721
726
|
var foreignStyle = {
|
|
722
727
|
//foreignObject标签样式,
|
|
723
|
-
width:
|
|
724
|
-
height:
|
|
725
|
-
transform: "translate(-
|
|
728
|
+
width: width,
|
|
729
|
+
height: height,
|
|
730
|
+
transform: "translate(-".concat(width / 2, "px,-").concat(height / 2, "px)"),
|
|
731
|
+
pointerEvents: "none"
|
|
726
732
|
},
|
|
727
733
|
boxStyle = {
|
|
728
734
|
//弹性盒子样式,用于当前值的上下居中对齐等
|
|
729
|
-
width:
|
|
730
|
-
height:
|
|
735
|
+
width: width,
|
|
736
|
+
height: height,
|
|
731
737
|
display: "flex",
|
|
732
738
|
flexDirection: "column",
|
|
733
739
|
justifyContent: "center",
|
|
734
740
|
alignItems: "center"
|
|
735
741
|
};
|
|
736
|
-
return show && /*#__PURE__*/_react["default"].createElement(
|
|
742
|
+
return show && /*#__PURE__*/_react["default"].createElement("foreignObject", {
|
|
737
743
|
style: foreignStyle
|
|
738
744
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
739
745
|
style: boxStyle
|
|
@@ -767,7 +773,7 @@ var Current = function Current(_ref9) {
|
|
|
767
773
|
}, (0, _utils.getFontStyle)(percentFont)), {}, {
|
|
768
774
|
margin: gap / 2 + "px 0"
|
|
769
775
|
})
|
|
770
|
-
}, percent + '%')))
|
|
776
|
+
}, percent + '%')));
|
|
771
777
|
};
|
|
772
778
|
|
|
773
779
|
var Label = function Label(_ref10) {
|
|
@@ -20,9 +20,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
20
20
|
var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
21
21
|
var position = _ref.x,
|
|
22
22
|
x = _ref.tickName,
|
|
23
|
+
marginLeft = _ref.marginLeft,
|
|
24
|
+
marginTop = _ref.marginTop,
|
|
23
25
|
data = _ref.data,
|
|
24
26
|
series = _ref.series,
|
|
25
|
-
config = _ref.config,
|
|
26
27
|
_ref$config$tip = _ref.config.tip,
|
|
27
28
|
_ref$config$tip$data = _ref$config$tip.data,
|
|
28
29
|
xAxis = _ref$config$tip$data.xAxis,
|
|
@@ -40,23 +41,40 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
40
41
|
image = _ref$config$tip.image,
|
|
41
42
|
margin = _ref$config$tip.margin,
|
|
42
43
|
_ref$config$tip$size = _ref$config$tip.size,
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
tipWidth = _ref$config$tip$size.width,
|
|
45
|
+
tipHeight = _ref$config$tip$size.height,
|
|
45
46
|
translateTip = _ref$config$tip.translate,
|
|
46
47
|
formatter = _ref.formatter,
|
|
47
|
-
isVertical = _ref.isVertical
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
isVertical = _ref.isVertical,
|
|
49
|
+
width = _ref.width,
|
|
50
|
+
height = _ref.height;
|
|
51
|
+
var tipPosition = (0, _react.useMemo)(function () {
|
|
52
|
+
var translate3d = isVertical ? _objectSpread(_objectSpread({}, translateTip), {}, {
|
|
53
|
+
y: translateTip.y + position + marginTop
|
|
54
|
+
}) : _objectSpread(_objectSpread({}, translateTip), {}, {
|
|
55
|
+
x: translateTip.x + position + marginLeft
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (translate3d.x + tipWidth > width) {
|
|
59
|
+
var newPositon = position + marginLeft - tipWidth - translateTip.x;
|
|
60
|
+
translate3d.x = newPositon >= 0 ? newPositon : 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (translate3d.y + tipHeight > height) {
|
|
64
|
+
var _newPositon = position + marginTop - tipHeight - translateTip.y;
|
|
65
|
+
|
|
66
|
+
translate3d.y = _newPositon >= 0 ? _newPositon : height - tipHeight;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (0, _utils.getTranslate3d)(translate3d);
|
|
70
|
+
}, [width, height, marginLeft, marginTop, position, tipWidth, tipHeight, translateTip]);
|
|
53
71
|
return /*#__PURE__*/React.createElement("div", {
|
|
54
72
|
className: "__easyv-tooltip",
|
|
55
73
|
style: _objectSpread({
|
|
56
74
|
pointerEvents: 'none',
|
|
57
|
-
transform:
|
|
58
|
-
width:
|
|
59
|
-
height:
|
|
75
|
+
transform: tipPosition,
|
|
76
|
+
width: tipWidth,
|
|
77
|
+
height: tipHeight,
|
|
60
78
|
padding: (0, _utils.getMargin)(margin),
|
|
61
79
|
background: image ? '50% 50% / 100% 100% no-repeat url(' + window.appConfig.ASSETS_URL + image + ')' : 'rgba(48, 55, 66, 0.85)'
|
|
62
80
|
}, (0, _utils.getFontStyle)(font))
|
package/lib/components/index.js
CHANGED
|
@@ -71,6 +71,12 @@ Object.defineProperty(exports, "Band", {
|
|
|
71
71
|
return _Band["default"];
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
+
Object.defineProperty(exports, "Lighter", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function get() {
|
|
77
|
+
return _Lighter["default"];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
74
80
|
Object.defineProperty(exports, "Line", {
|
|
75
81
|
enumerable: true,
|
|
76
82
|
get: function get() {
|
|
@@ -161,6 +167,8 @@ var _Indicator = _interopRequireDefault(require("./Indicator"));
|
|
|
161
167
|
|
|
162
168
|
var _Band = _interopRequireDefault(require("./Band"));
|
|
163
169
|
|
|
170
|
+
var _Lighter = _interopRequireDefault(require("./Lighter"));
|
|
171
|
+
|
|
164
172
|
var _Line = _interopRequireDefault(require("./Line"));
|
|
165
173
|
|
|
166
174
|
var _Background = _interopRequireDefault(require("./Background"));
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = ConicGradient;
|
|
9
|
+
|
|
10
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
11
|
+
|
|
12
|
+
//只支持在svg中使用
|
|
13
|
+
//在<clipPath>标签中绘制圆环路径,在<foreignObject>中使用conic-gradient来制作角向渐变
|
|
14
|
+
//然后在foreignObject中调用clipPath来剪切dom元素,实现环形渐变效果
|
|
15
|
+
function ConicGradient(props) {
|
|
16
|
+
var gradientId = props.gradientId,
|
|
17
|
+
_props$colorConfig = props.colorConfig,
|
|
18
|
+
colorConfig = _props$colorConfig === void 0 ? {} : _props$colorConfig,
|
|
19
|
+
_props$circleConfig = props.circleConfig,
|
|
20
|
+
circleConfig = _props$circleConfig === void 0 ? {} : _props$circleConfig,
|
|
21
|
+
_colorConfig$colorTyp = colorConfig.colorType,
|
|
22
|
+
colorType = _colorConfig$colorTyp === void 0 ? "linear" : _colorConfig$colorTyp,
|
|
23
|
+
_colorConfig$colors = colorConfig.colors,
|
|
24
|
+
colors = _colorConfig$colors === void 0 ? [{
|
|
25
|
+
offset: 0,
|
|
26
|
+
color: "rgba(255,0,0,0.5)"
|
|
27
|
+
}, {
|
|
28
|
+
offset: 50,
|
|
29
|
+
color: "rgba(0,255,0,0.5)"
|
|
30
|
+
}, {
|
|
31
|
+
offset: 100,
|
|
32
|
+
color: "rgba(0,0,255,0.5)"
|
|
33
|
+
}] : _colorConfig$colors,
|
|
34
|
+
_circleConfig$innerRa = circleConfig.innerRadius,
|
|
35
|
+
innerRadius = _circleConfig$innerRa === void 0 ? 80 : _circleConfig$innerRa,
|
|
36
|
+
_circleConfig$outerRa = circleConfig.outerRadius,
|
|
37
|
+
outerRadius = _circleConfig$outerRa === void 0 ? 100 : _circleConfig$outerRa,
|
|
38
|
+
_circleConfig$startAn = circleConfig.startAngle,
|
|
39
|
+
startAngle = _circleConfig$startAn === void 0 ? 0 : _circleConfig$startAn,
|
|
40
|
+
_circleConfig$endAngl = circleConfig.endAngle,
|
|
41
|
+
endAngle = _circleConfig$endAngl === void 0 ? 360 : _circleConfig$endAngl,
|
|
42
|
+
_circleConfig$cornerR = circleConfig.cornerRadius,
|
|
43
|
+
cornerRadius = _circleConfig$cornerR === void 0 ? 0 : _circleConfig$cornerR,
|
|
44
|
+
_circleConfig$padAngl = circleConfig.padAngle,
|
|
45
|
+
padAngle = _circleConfig$padAngl === void 0 ? 0 : _circleConfig$padAngl;
|
|
46
|
+
var arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius).startAngle(startAngle * Math.PI / 180).endAngle(endAngle * Math.PI / 180).cornerRadius(cornerRadius).padAngle(padAngle);
|
|
47
|
+
return /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("clipPath", {
|
|
48
|
+
id: "" + gradientId,
|
|
49
|
+
style: {
|
|
50
|
+
transform: "translate(50%,50%)"
|
|
51
|
+
}
|
|
52
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
53
|
+
d: arc()
|
|
54
|
+
})), /*#__PURE__*/React.createElement("foreignObject", {
|
|
55
|
+
style: {
|
|
56
|
+
width: "100%",
|
|
57
|
+
height: "100%",
|
|
58
|
+
transform: "translate(-50%,-50%)",
|
|
59
|
+
background: colorType === "pure" ? colors : "conic-gradient(".concat(colorsToString(colors), ")"),
|
|
60
|
+
clipPath: "url(".concat('#' + gradientId, ")")
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function colorsToString(colors) {
|
|
66
|
+
var s = "";
|
|
67
|
+
colors.sort(function (a, b) {
|
|
68
|
+
return a.offset - b.offset;
|
|
69
|
+
}).map(function (d) {
|
|
70
|
+
s = s + d.color + " " + d.offset + "%,";
|
|
71
|
+
});
|
|
72
|
+
return s.slice(0, -1);
|
|
73
|
+
}
|
package/lib/utils/index.js
CHANGED
|
@@ -791,8 +791,8 @@ exports.sortPie = sortPie;
|
|
|
791
791
|
var getDataWithPercent = function getDataWithPercent() {
|
|
792
792
|
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
793
793
|
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
794
|
-
var digits = Math.pow(10, precision);
|
|
795
|
-
|
|
794
|
+
var digits = Math.pow(10, precision);
|
|
795
|
+
var targetSeats = digits * 100;
|
|
796
796
|
var total = (0, _d3v.sum)(data, function (d) {
|
|
797
797
|
return d.value;
|
|
798
798
|
});
|
|
@@ -805,7 +805,7 @@ var getDataWithPercent = function getDataWithPercent() {
|
|
|
805
805
|
var currentSum = (0, _d3v.sum)(votesPerQuota, function (d) {
|
|
806
806
|
return d.vote;
|
|
807
807
|
});
|
|
808
|
-
var remainder =
|
|
808
|
+
var remainder = targetSeats - currentSum;
|
|
809
809
|
votesPerQuota.sort(function (_ref26, _ref27) {
|
|
810
810
|
var a = _ref26.value;
|
|
811
811
|
var b = _ref27.value;
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyv/charts",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"release": "standard-version",
|
|
8
|
+
"make": "babel src -d lib --extensions .ts,.tsx,.js && cp -r src/css lib && standard-version",
|
|
9
|
+
"prepare": "husky install"
|
|
8
10
|
},
|
|
9
11
|
"keywords": [],
|
|
10
12
|
"author": "",
|
|
@@ -18,17 +20,28 @@
|
|
|
18
20
|
"@babel/preset-env": "^7.11.5",
|
|
19
21
|
"@babel/preset-react": "^7.10.4",
|
|
20
22
|
"@babel/preset-typescript": "^7.14.5",
|
|
23
|
+
"@commitlint/cli": "^16.2.3",
|
|
24
|
+
"@commitlint/config-conventional": "^16.2.1",
|
|
21
25
|
"@types/d3": "^7.0.0",
|
|
22
26
|
"@types/react": "^17.0.14",
|
|
23
27
|
"babel-plugin-transform-import-styles": "0.0.11",
|
|
24
28
|
"babel-preset-env": "^1.7.0",
|
|
25
|
-
"
|
|
29
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
30
|
+
"husky": "^7.0.4",
|
|
31
|
+
"load-styles": "^2.0.0",
|
|
32
|
+
"standard-version": "^9.3.2"
|
|
26
33
|
},
|
|
27
34
|
"dependencies": {
|
|
28
|
-
"@easyv/utils": "^0.0.
|
|
35
|
+
"@easyv/utils": "^0.0.33",
|
|
29
36
|
"d3v7": "npm:d3@^7.0.0",
|
|
30
37
|
"popmotion": "^9.3.6",
|
|
31
38
|
"react": "^17.0.2",
|
|
39
|
+
"svg-path-properties": "^1.0.11",
|
|
32
40
|
"svg-points": "^6.0.1"
|
|
41
|
+
},
|
|
42
|
+
"config": {
|
|
43
|
+
"commitizen": {
|
|
44
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
45
|
+
}
|
|
33
46
|
}
|
|
34
|
-
}
|
|
47
|
+
}
|