@easyv/charts 1.10.20 → 1.10.22

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.
@@ -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,7 +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;
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]);
325
406
  var _useState = (0, _react.useState)(1),
326
407
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
327
408
  y = _useState2[0],
@@ -637,7 +637,7 @@ var reverseGradientStops = function reverseGradientStops(gradient) {
637
637
  };
638
638
  var getBandBackground = exports.getBandBackground = function getBandBackground(pattern, fill, y) {
639
639
  if (!(pattern && pattern.path)) {
640
- return (0, _utils.getColor)(y < 0 ? reverseGradientStops(fill) : fill); //小于0颜色翻转
640
+ return (0, _utils.getColor)(y > 0 ? reverseGradientStops(fill) : fill); //小于0颜色翻转
641
641
  }
642
642
  try {
643
643
  var _pattern$backgroundSi = pattern.backgroundSize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.10.20",
3
+ "version": "1.10.22",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {