@easyv/charts 1.10.35 → 1.10.37
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
|
@@ -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;
|
|
@@ -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; }
|
|
@@ -237,6 +237,17 @@ var getLabelColumnHeight = function getLabelColumnHeight(_ref2) {
|
|
|
237
237
|
return height || 12;
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
+
// 大屏 transform:scale 后 getBoundingClientRect 会带缩放;offsetHeight 不受 transform 影响,与 SVG 坐标一致
|
|
241
|
+
var getLabelDomHeight = function getLabelDomHeight(el) {
|
|
242
|
+
if (!el) return 0;
|
|
243
|
+
if (el.offsetHeight) return el.offsetHeight;
|
|
244
|
+
var rect = el.getBoundingClientRect();
|
|
245
|
+
if (!rect.height) return 0;
|
|
246
|
+
// offsetHeight 不可用时,用宽高比估算当前 scaleY 再还原
|
|
247
|
+
var scaleY = el.offsetWidth > 0 && rect.width > 0 ? rect.width / el.offsetWidth : 1;
|
|
248
|
+
return Math.round(rect.height / (scaleY || 1));
|
|
249
|
+
};
|
|
250
|
+
|
|
240
251
|
// 水平布局:同侧重叠时按半高之和推开
|
|
241
252
|
var resolveLabelY = function resolveLabelY(y2, side, placedYBySide, labelHeight) {
|
|
242
253
|
var placed = placedYBySide[side];
|
|
@@ -507,7 +518,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref14) {
|
|
|
507
518
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
508
519
|
y = _useState2[0],
|
|
509
520
|
setY = _useState2[1];
|
|
510
|
-
var radius = Math.min(chartWidth, chartHeight) / 2 * outerRadius;
|
|
521
|
+
var radius = Math.max(0, Math.min(chartWidth, chartHeight) / 2 * outerRadius);
|
|
511
522
|
var arcsFunc = (0, _react.useMemo)(function () {
|
|
512
523
|
var _getAngle = getAngle(angle),
|
|
513
524
|
_getAngle$startAngle = _getAngle.startAngle,
|
|
@@ -1207,7 +1218,7 @@ var Label = function Label(_ref19) {
|
|
|
1207
1218
|
Object.keys(labelElsRef.current).forEach(function (key) {
|
|
1208
1219
|
var el = labelElsRef.current[key];
|
|
1209
1220
|
if (!el) return;
|
|
1210
|
-
var h =
|
|
1221
|
+
var h = getLabelDomHeight(el);
|
|
1211
1222
|
if (!h) return;
|
|
1212
1223
|
next[key] = h;
|
|
1213
1224
|
if (prev[key] !== h) changed = true;
|
|
@@ -1422,7 +1433,7 @@ var RingLabel = function RingLabel(_ref21) {
|
|
|
1422
1433
|
Object.keys(labelElsRef.current).forEach(function (key) {
|
|
1423
1434
|
var el = labelElsRef.current[key];
|
|
1424
1435
|
if (!el) return;
|
|
1425
|
-
var h =
|
|
1436
|
+
var h = getLabelDomHeight(el);
|
|
1426
1437
|
if (!h) return;
|
|
1427
1438
|
next[key] = h;
|
|
1428
1439
|
if (prev[key] !== h) changed = true;
|
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
|
|