@easyv/charts 1.10.19 → 1.10.21
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/Legend.js +7 -5
- package/lib/components/PieChart.js +84 -4
- package/package.json +1 -1
- package/src/components/Legend.js +7 -12
- package/src/components/PieChart.js +1629 -1570
package/lib/components/Legend.js
CHANGED
|
@@ -214,8 +214,10 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
214
214
|
var isSideLegend = isPieAdaptive && isSidePlacement;
|
|
215
215
|
var isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
|
|
216
216
|
var fullWidth = (_ref3 = componentWidth !== null && componentWidth !== void 0 ? componentWidth : chartWidth) !== null && _ref3 !== void 0 ? _ref3 : 0;
|
|
217
|
-
|
|
218
|
-
var
|
|
217
|
+
// Adaptive+上下:组件总宽;Adaptive+左右:仅 maxWidth = 总宽 − 左右 chart.margin,宽度由内容撑开
|
|
218
|
+
var pieLegendFullWidth = Math.max(0, fullWidth);
|
|
219
|
+
var pieLegendInnerWidth = Math.max(0, fullWidth - marginLeft - marginRight);
|
|
220
|
+
var sideLegendMaxWidth = isSideLegend ? pieLegendInnerWidth : 0;
|
|
219
221
|
var fixedColumnsPerRow = Math.min(Math.max(1, Number(gridTemplateColumns) || 1), length);
|
|
220
222
|
var isPieTopBottomFixedMultiCol = isPieChart && isFixedWidth && isCenterTopOrBottom && fixedColumnsPerRow > 1;
|
|
221
223
|
var formatterExtra = _objectSpread(_objectSpread(_objectSpread({}, config), {}, {
|
|
@@ -231,7 +233,7 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
231
233
|
}, isSideLegend && sideLegendMaxWidth > 0 ? {
|
|
232
234
|
adaptiveMaxWidth: sideLegendMaxWidth
|
|
233
235
|
} : {}), isTopBottomAdaptive ? {
|
|
234
|
-
chartWidth:
|
|
236
|
+
chartWidth: pieLegendFullWidth
|
|
235
237
|
} : {});
|
|
236
238
|
var renderPieSideItem = function renderPieSideItem(series, i) {
|
|
237
239
|
var _series$config;
|
|
@@ -336,8 +338,8 @@ var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(function (_ref
|
|
|
336
338
|
if (isTopBottomAdaptive) {
|
|
337
339
|
var topBottomWrapperStyle = _objectSpread(_objectSpread({
|
|
338
340
|
position: "absolute",
|
|
339
|
-
width:
|
|
340
|
-
maxWidth:
|
|
341
|
+
width: pieLegendFullWidth || "100%",
|
|
342
|
+
maxWidth: pieLegendFullWidth || "100%",
|
|
341
343
|
boxSizing: "border-box"
|
|
342
344
|
}, getPosition(position, _alignment, x, y)), {}, {
|
|
343
345
|
height: loop.show ? height : "auto",
|
|
@@ -22,18 +22,54 @@ var _formatter = require("../formatter");
|
|
|
22
22
|
var _piechartModule = _interopRequireDefault(require("../css/piechart.module.css"));
|
|
23
23
|
var _hooks = require("../hooks");
|
|
24
24
|
var _PieTooltip = require("./PieTooltip");
|
|
25
|
+
var _legendPlacement = require("../utils/legendPlacement");
|
|
25
26
|
var _excluded = ["startAngle", "endAngle", "antiClockwise"],
|
|
26
27
|
_excluded2 = ["padAngle", "innerRadius", "outerRadius", "cornerRadius", "startAngle", "endAngle"],
|
|
27
28
|
_excluded3 = ["formatter"],
|
|
28
29
|
_excluded4 = ["startAngle", "endAngle"];
|
|
29
|
-
/**
|
|
30
|
-
* 饼环图
|
|
30
|
+
/**
|
|
31
|
+
* 饼环图
|
|
31
32
|
*/
|
|
32
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); }
|
|
33
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; }
|
|
34
35
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
35
36
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
36
37
|
var PI = Math.PI;
|
|
38
|
+
var PIE_ADAPTIVE_MARGINS = {
|
|
39
|
+
right: {
|
|
40
|
+
marginTop: 24,
|
|
41
|
+
marginBottom: 24,
|
|
42
|
+
marginLeft: 0,
|
|
43
|
+
marginRight: 200
|
|
44
|
+
},
|
|
45
|
+
left: {
|
|
46
|
+
marginTop: 24,
|
|
47
|
+
marginBottom: 24,
|
|
48
|
+
marginLeft: 200,
|
|
49
|
+
marginRight: 0
|
|
50
|
+
},
|
|
51
|
+
top: {
|
|
52
|
+
marginTop: 110,
|
|
53
|
+
marginBottom: 24,
|
|
54
|
+
marginLeft: 24,
|
|
55
|
+
marginRight: 24
|
|
56
|
+
},
|
|
57
|
+
bottom: {
|
|
58
|
+
marginTop: 24,
|
|
59
|
+
marginBottom: 110,
|
|
60
|
+
marginLeft: 24,
|
|
61
|
+
marginRight: 24
|
|
62
|
+
},
|
|
63
|
+
hidden: {
|
|
64
|
+
marginTop: 24,
|
|
65
|
+
marginBottom: 24,
|
|
66
|
+
marginLeft: 24,
|
|
67
|
+
marginRight: 24
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var getPieAdaptiveMargin = function getPieAdaptiveMargin(show, alignment) {
|
|
71
|
+
return (0, _legendPlacement.getPieAdaptiveMarginPreset)(show, alignment, PIE_ADAPTIVE_MARGINS);
|
|
72
|
+
};
|
|
37
73
|
var defaultChart = {
|
|
38
74
|
outerRadius: 1,
|
|
39
75
|
innerRadius: 0,
|
|
@@ -238,6 +274,7 @@ var getCircleScale = function getCircleScale() {
|
|
|
238
274
|
}));
|
|
239
275
|
};
|
|
240
276
|
var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
277
|
+
var _legend$config2;
|
|
241
278
|
var width = _ref5.width,
|
|
242
279
|
height = _ref5.height,
|
|
243
280
|
_ref5$config = _ref5.config,
|
|
@@ -321,8 +358,51 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
|
|
|
321
358
|
chartWidth = _useContext.width,
|
|
322
359
|
chartHeight = _useContext.height,
|
|
323
360
|
triggerOnRelative = _useContext.triggerOnRelative,
|
|
324
|
-
onEmit = _useContext.onEmit
|
|
325
|
-
|
|
361
|
+
onEmit = _useContext.onEmit,
|
|
362
|
+
updateConfig = _useContext.updateConfig;
|
|
363
|
+
var _legend$config = legend.config,
|
|
364
|
+
legendShow = _legend$config.show,
|
|
365
|
+
_legend$config$name = _legend$config.name,
|
|
366
|
+
_legend$config$name2 = _legend$config$name === void 0 ? {} : _legend$config$name,
|
|
367
|
+
legendLayoutMode = _legend$config$name2.layoutMode;
|
|
368
|
+
var legendAlignment = (_legend$config2 = legend.config) === null || _legend$config2 === void 0 || (_legend$config2 = _legend$config2.layout) === null || _legend$config2 === void 0 ? void 0 : _legend$config2.alignment;
|
|
369
|
+
var prevLegendLayoutKey = (0, _react.useRef)(null);
|
|
370
|
+
(0, _react.useEffect)(function () {
|
|
371
|
+
if (legendLayoutMode !== "Adaptive") {
|
|
372
|
+
prevLegendLayoutKey.current = null;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (!updateConfig) return;
|
|
376
|
+
var layoutKey = "".concat(legendShow, "-").concat(legendAlignment);
|
|
377
|
+
var prev = prevLegendLayoutKey.current;
|
|
378
|
+
prevLegendLayoutKey.current = layoutKey;
|
|
379
|
+
|
|
380
|
+
// 挂载/刷新:只记录当前图例布局,margin 始终读配置项
|
|
381
|
+
if (prev === null) return;
|
|
382
|
+
if (prev === layoutKey) return;
|
|
383
|
+
var target = getPieAdaptiveMargin(legendShow, legendAlignment);
|
|
384
|
+
updateConfig({
|
|
385
|
+
id: id,
|
|
386
|
+
type: "config",
|
|
387
|
+
payload: [{
|
|
388
|
+
path: ["chart", "margin", "marginTop"],
|
|
389
|
+
field: "value",
|
|
390
|
+
value: target.marginTop
|
|
391
|
+
}, {
|
|
392
|
+
path: ["chart", "margin", "marginBottom"],
|
|
393
|
+
field: "value",
|
|
394
|
+
value: target.marginBottom
|
|
395
|
+
}, {
|
|
396
|
+
path: ["chart", "margin", "marginLeft"],
|
|
397
|
+
field: "value",
|
|
398
|
+
value: target.marginLeft
|
|
399
|
+
}, {
|
|
400
|
+
path: ["chart", "margin", "marginRight"],
|
|
401
|
+
field: "value",
|
|
402
|
+
value: target.marginRight
|
|
403
|
+
}]
|
|
404
|
+
});
|
|
405
|
+
}, [id, updateConfig, legendLayoutMode, legendShow, legendAlignment]);
|
|
326
406
|
var _useState = (0, _react.useState)(1),
|
|
327
407
|
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
328
408
|
y = _useState2[0],
|
package/package.json
CHANGED
package/src/components/Legend.js
CHANGED
|
@@ -232,15 +232,10 @@ export default memo(
|
|
|
232
232
|
const isSideLegend = isPieAdaptive && isSidePlacement;
|
|
233
233
|
const isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
|
|
234
234
|
const fullWidth = componentWidth ?? chartWidth ?? 0;
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
position === "left" || _alignment === "left"
|
|
240
|
-
? marginLeft
|
|
241
|
-
: marginRight,
|
|
242
|
-
)
|
|
243
|
-
: 0;
|
|
235
|
+
// Adaptive+上下:组件总宽;Adaptive+左右:仅 maxWidth = 总宽 − 左右 chart.margin,宽度由内容撑开
|
|
236
|
+
const pieLegendFullWidth = Math.max(0, fullWidth);
|
|
237
|
+
const pieLegendInnerWidth = Math.max(0, fullWidth - marginLeft - marginRight);
|
|
238
|
+
const sideLegendMaxWidth = isSideLegend ? pieLegendInnerWidth : 0;
|
|
244
239
|
const fixedColumnsPerRow = Math.min(
|
|
245
240
|
Math.max(1, Number(gridTemplateColumns) || 1),
|
|
246
241
|
length,
|
|
@@ -265,7 +260,7 @@ export default memo(
|
|
|
265
260
|
...(isSideLegend && sideLegendMaxWidth > 0
|
|
266
261
|
? { adaptiveMaxWidth: sideLegendMaxWidth }
|
|
267
262
|
: {}),
|
|
268
|
-
...(isTopBottomAdaptive ? { chartWidth:
|
|
263
|
+
...(isTopBottomAdaptive ? { chartWidth: pieLegendFullWidth } : {}),
|
|
269
264
|
};
|
|
270
265
|
|
|
271
266
|
const renderPieSideItem = (series, i) => {
|
|
@@ -403,8 +398,8 @@ export default memo(
|
|
|
403
398
|
if (isTopBottomAdaptive) {
|
|
404
399
|
const topBottomWrapperStyle = {
|
|
405
400
|
position: "absolute",
|
|
406
|
-
width:
|
|
407
|
-
maxWidth:
|
|
401
|
+
width: pieLegendFullWidth || "100%",
|
|
402
|
+
maxWidth: pieLegendFullWidth || "100%",
|
|
408
403
|
boxSizing: "border-box",
|
|
409
404
|
...getPosition(position, _alignment, x, y),
|
|
410
405
|
height: loop.show ? height : "auto",
|