@easyv/charts 1.10.36 → 1.10.38
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 +3 -2
- package/lib/components/ConicalGradient.js +6 -2
- package/lib/components/Label.js +11 -1
- package/lib/components/PieChart.js +3 -3
- package/package.json +1 -1
- package/src/components/Chart.js +3 -2
- package/src/components/ConicalGradient.js +8 -3
- package/src/components/Label.js +18 -6
- package/src/components/PieChart.js +1838 -1835
package/lib/components/Chart.js
CHANGED
|
@@ -56,8 +56,9 @@ var Chart = /*#__PURE__*/(0, _react.memo)(function (_ref2) {
|
|
|
56
56
|
height = props.height;
|
|
57
57
|
var isIOS = (0, _react.useRef)(/iPad|iPhone|iPod|iOS/i.test(navigator.userAgent) || /Mac OS X/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent));
|
|
58
58
|
var svg = /*#__PURE__*/(0, _react.createRef)();
|
|
59
|
-
|
|
60
|
-
var
|
|
59
|
+
// 组件尺寸小于边距之和时,绘图区可能为负;钳制为 >= 0,避免饼/环图半径为负导致崩溃
|
|
60
|
+
var chartWidth = Math.max(0, width - marginLeft - marginRight);
|
|
61
|
+
var chartHeight = Math.max(0, height - marginTop - marginBottom);
|
|
61
62
|
var _useState = (0, _react.useState)(true),
|
|
62
63
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
63
64
|
active = _useState2[0],
|
|
@@ -30,20 +30,22 @@ var _default = exports["default"] = function _default(_ref) {
|
|
|
30
30
|
speed = _ref$config.speed,
|
|
31
31
|
direction = _ref$config.direction,
|
|
32
32
|
arcs = _ref.arcs;
|
|
33
|
-
if (!show) return null;
|
|
33
|
+
if (!show || !(radius > 0)) return null;
|
|
34
34
|
var _useState = (0, _react.useState)(null),
|
|
35
35
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
36
36
|
canvas = _useState2[0],
|
|
37
37
|
setCanvas = _useState2[1];
|
|
38
38
|
(0, _react.useEffect)(function () {
|
|
39
|
+
if (!(radius > 0)) return;
|
|
39
40
|
if (arcs && arcs.length > 0 && canvas && canvas.getContext('2d')) {
|
|
40
41
|
var _radius = radius * devicePixelRatio;
|
|
42
|
+
if (!(_radius > 0)) return;
|
|
41
43
|
var context = canvas.getContext('2d');
|
|
42
44
|
context.clearRect(0, 0, width * devicePixelRatio, height * devicePixelRatio);
|
|
43
45
|
context.save();
|
|
44
46
|
context.translate(centerX * devicePixelRatio, centerY * devicePixelRatio);
|
|
45
47
|
context.beginPath();
|
|
46
|
-
var _arc = (0, _d3v.arc)().innerRadius(innerRadius * _radius).outerRadius(outerRadius * _radius)
|
|
48
|
+
var _arc = (0, _d3v.arc)().innerRadius(Math.max(0, innerRadius * _radius)).outerRadius(Math.max(0, outerRadius * _radius))
|
|
47
49
|
// .padAngle(axis.pole.padAngle)
|
|
48
50
|
// .cornerRadius(axis.pole.cornerRadius)
|
|
49
51
|
.context(context);
|
|
@@ -145,6 +147,8 @@ ConicalGradient.prototype = {
|
|
|
145
147
|
* @param {Boolean} anticlockwise
|
|
146
148
|
*/
|
|
147
149
|
fill: function fill(context, x, y, radius, startAngle, endAngle, anticlockwise) {
|
|
150
|
+
// CanvasRenderingContext2D.arc 不允许负半径
|
|
151
|
+
if (!(radius > 0)) return this;
|
|
148
152
|
var offsets = this._offsets;
|
|
149
153
|
var colors = this._colors;
|
|
150
154
|
var PI = Math.PI;
|
package/lib/components/Label.js
CHANGED
|
@@ -43,6 +43,13 @@ var getHighlightData = function getHighlightData(data, extent) {
|
|
|
43
43
|
return data;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
var formatWithComma = function formatWithComma(value) {
|
|
47
|
+
if (value === null || value === undefined || value === "") return value;
|
|
48
|
+
return String(value).replace(/^(-?\d+)(\.\d+)?$/, function (_, _int) {
|
|
49
|
+
var dec = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
|
|
50
|
+
return _int.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + dec;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
46
53
|
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
47
54
|
var isXRepeat = _ref.isXRepeat,
|
|
48
55
|
_ref$config = _ref.config,
|
|
@@ -228,11 +235,14 @@ var Label = function Label(_ref5) {
|
|
|
228
235
|
_ref5$config$suffix$t = _ref5$config$suffix.translate,
|
|
229
236
|
suffixX = _ref5$config$suffix$t.x,
|
|
230
237
|
suffixY = _ref5$config$suffix$t.y,
|
|
238
|
+
_ref5$config$commaFor = _ref5$config.commaFormatting,
|
|
239
|
+
commaFormatting = _ref5$config$commaFor === void 0 ? true : _ref5$config$commaFor,
|
|
231
240
|
_ref5$textAnchor = _ref5.textAnchor,
|
|
232
241
|
textAnchor = _ref5$textAnchor === void 0 ? "middle" : _ref5$textAnchor,
|
|
233
242
|
_ref5$dominantBaselin = _ref5.dominantBaseline,
|
|
234
243
|
dominantBaseline = _ref5$dominantBaselin === void 0 ? "middle" : _ref5$dominantBaselin,
|
|
235
244
|
reverse = _ref5.reverse;
|
|
245
|
+
var displayValue = commaFormatting ? formatWithComma(value) : value;
|
|
236
246
|
return /*#__PURE__*/React.createElement("text", {
|
|
237
247
|
x: x,
|
|
238
248
|
y: y,
|
|
@@ -243,7 +253,7 @@ var Label = function Label(_ref5) {
|
|
|
243
253
|
textAnchor: textAnchor,
|
|
244
254
|
dominantBaseline: dominantBaseline,
|
|
245
255
|
style: _objectSpread({}, (0, _utils.formatFont)(font, "svg"))
|
|
246
|
-
}, /*#__PURE__*/React.createElement("tspan", null,
|
|
256
|
+
}, /*#__PURE__*/React.createElement("tspan", null, displayValue), /*#__PURE__*/React.createElement("tspan", {
|
|
247
257
|
dx: suffixX,
|
|
248
258
|
dy: suffixY,
|
|
249
259
|
style: _objectSpread({}, (0, _utils.getFontStyle)(suffixFont, "svg"))
|
|
@@ -27,8 +27,8 @@ var _excluded = ["startAngle", "endAngle", "antiClockwise"],
|
|
|
27
27
|
_excluded2 = ["padAngle", "innerRadius", "outerRadius", "cornerRadius", "startAngle", "endAngle"],
|
|
28
28
|
_excluded3 = ["formatter"],
|
|
29
29
|
_excluded4 = ["startAngle", "endAngle"];
|
|
30
|
-
/**
|
|
31
|
-
* 饼环图
|
|
30
|
+
/**
|
|
31
|
+
* 饼环图
|
|
32
32
|
*/
|
|
33
33
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
34
34
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
@@ -518,7 +518,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref14) {
|
|
|
518
518
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
519
519
|
y = _useState2[0],
|
|
520
520
|
setY = _useState2[1];
|
|
521
|
-
var radius = Math.min(chartWidth, chartHeight) / 2 * outerRadius;
|
|
521
|
+
var radius = Math.max(0, Math.min(chartWidth, chartHeight) / 2 * outerRadius);
|
|
522
522
|
var arcsFunc = (0, _react.useMemo)(function () {
|
|
523
523
|
var _getAngle = getAngle(angle),
|
|
524
524
|
_getAngle$startAngle = _getAngle.startAngle,
|
package/package.json
CHANGED
package/src/components/Chart.js
CHANGED
|
@@ -50,8 +50,9 @@ const Chart = memo(
|
|
|
50
50
|
!/Chrome/i.test(navigator.userAgent)),
|
|
51
51
|
);
|
|
52
52
|
const svg = createRef();
|
|
53
|
-
|
|
54
|
-
const
|
|
53
|
+
// 组件尺寸小于边距之和时,绘图区可能为负;钳制为 >= 0,避免饼/环图半径为负导致崩溃
|
|
54
|
+
const chartWidth = Math.max(0, width - marginLeft - marginRight);
|
|
55
|
+
const chartHeight = Math.max(0, height - marginTop - marginBottom);
|
|
55
56
|
const [active, setActive] = useState(true);
|
|
56
57
|
const scaleRef = useRef([1, 1]);
|
|
57
58
|
const screenPosRef = useRef({ left: 0, top: 0 });
|
|
@@ -15,12 +15,14 @@ export default ({
|
|
|
15
15
|
config: { show, innerRadius, outerRadius, opacity, speed, direction },
|
|
16
16
|
arcs,
|
|
17
17
|
}) => {
|
|
18
|
-
if (!show) return null;
|
|
18
|
+
if (!show || !(radius > 0)) return null;
|
|
19
19
|
const [canvas, setCanvas] = useState(null);
|
|
20
20
|
|
|
21
21
|
useEffect(() => {
|
|
22
|
+
if (!(radius > 0)) return;
|
|
22
23
|
if (arcs && arcs.length > 0 && canvas && canvas.getContext('2d')) {
|
|
23
24
|
const _radius = radius * devicePixelRatio;
|
|
25
|
+
if (!(_radius > 0)) return;
|
|
24
26
|
const context = canvas.getContext('2d');
|
|
25
27
|
context.clearRect(
|
|
26
28
|
0,
|
|
@@ -34,8 +36,8 @@ export default ({
|
|
|
34
36
|
context.beginPath();
|
|
35
37
|
|
|
36
38
|
const _arc = arc()
|
|
37
|
-
.innerRadius(innerRadius * _radius)
|
|
38
|
-
.outerRadius(outerRadius * _radius)
|
|
39
|
+
.innerRadius(Math.max(0, innerRadius * _radius))
|
|
40
|
+
.outerRadius(Math.max(0, outerRadius * _radius))
|
|
39
41
|
// .padAngle(axis.pole.padAngle)
|
|
40
42
|
// .cornerRadius(axis.pole.cornerRadius)
|
|
41
43
|
.context(context);
|
|
@@ -147,6 +149,9 @@ ConicalGradient.prototype = {
|
|
|
147
149
|
* @param {Boolean} anticlockwise
|
|
148
150
|
*/
|
|
149
151
|
fill: function (context, x, y, radius, startAngle, endAngle, anticlockwise) {
|
|
152
|
+
// CanvasRenderingContext2D.arc 不允许负半径
|
|
153
|
+
if (!(radius > 0)) return this;
|
|
154
|
+
|
|
150
155
|
var offsets = this._offsets;
|
|
151
156
|
var colors = this._colors;
|
|
152
157
|
|
package/src/components/Label.js
CHANGED
|
@@ -30,6 +30,13 @@ const getHighlightData = (data, extent) => {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
const formatWithComma = (value) => {
|
|
34
|
+
if (value === null || value === undefined || value === "") return value;
|
|
35
|
+
return String(value).replace(/^(-?\d+)(\.\d+)?$/, (_, int, dec = "") => {
|
|
36
|
+
return int.replace(/\B(?=(\d{3})+(?!\d))/g, ",") + dec;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
33
40
|
export default memo(
|
|
34
41
|
({
|
|
35
42
|
isXRepeat,
|
|
@@ -98,15 +105,18 @@ export default memo(
|
|
|
98
105
|
data,
|
|
99
106
|
data: { x, y, showY, s },
|
|
100
107
|
},
|
|
101
|
-
i
|
|
108
|
+
i,
|
|
102
109
|
) => {
|
|
103
110
|
let y1, y2;
|
|
104
111
|
const { icon, label } =
|
|
105
112
|
x == curXLabel ? selectConfig : flag ? highlightConfig : other;
|
|
106
113
|
const showIcon = icon && icon.show;
|
|
107
114
|
const showLabel = label && label.show;
|
|
108
|
-
const {
|
|
109
|
-
|
|
115
|
+
const {
|
|
116
|
+
position: _position = "outerStart",
|
|
117
|
+
reverse = true,
|
|
118
|
+
} = label || {};
|
|
119
|
+
|
|
110
120
|
if (isClipAxis) {
|
|
111
121
|
if (end > +clipValue) {
|
|
112
122
|
y1 = yScaler[1](start);
|
|
@@ -183,11 +193,11 @@ export default memo(
|
|
|
183
193
|
)}
|
|
184
194
|
</g>
|
|
185
195
|
);
|
|
186
|
-
}
|
|
196
|
+
},
|
|
187
197
|
)}
|
|
188
198
|
</g>
|
|
189
199
|
);
|
|
190
|
-
}
|
|
200
|
+
},
|
|
191
201
|
);
|
|
192
202
|
|
|
193
203
|
const Label = ({
|
|
@@ -202,11 +212,13 @@ const Label = ({
|
|
|
202
212
|
font: suffixFont,
|
|
203
213
|
translate: { x: suffixX, y: suffixY },
|
|
204
214
|
},
|
|
215
|
+
commaFormatting = true,
|
|
205
216
|
},
|
|
206
217
|
textAnchor = "middle",
|
|
207
218
|
dominantBaseline = "middle",
|
|
208
219
|
reverse,
|
|
209
220
|
}) => {
|
|
221
|
+
const displayValue = commaFormatting ? formatWithComma(value) : value;
|
|
210
222
|
return (
|
|
211
223
|
<text
|
|
212
224
|
x={x}
|
|
@@ -219,7 +231,7 @@ const Label = ({
|
|
|
219
231
|
dominantBaseline={dominantBaseline}
|
|
220
232
|
style={{ ...formatFont(font, "svg") }}
|
|
221
233
|
>
|
|
222
|
-
<tspan>{
|
|
234
|
+
<tspan>{displayValue}</tspan>
|
|
223
235
|
<tspan
|
|
224
236
|
dx={suffixX}
|
|
225
237
|
dy={suffixY}
|