@easyv/charts 1.10.18 → 1.10.20

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.
@@ -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
- var legendAreaWidth = Math.max(0, fullWidth - marginLeft - marginRight);
218
- var sideLegendMaxWidth = isSideLegend ? Math.max(0, position === "left" || _alignment === "left" ? marginLeft : marginRight) : 0;
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: legendAreaWidth
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: legendAreaWidth || "100%",
340
- maxWidth: legendAreaWidth || "100%",
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,7 +22,6 @@ 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");
26
25
  var _excluded = ["startAngle", "endAngle", "antiClockwise"],
27
26
  _excluded2 = ["padAngle", "innerRadius", "outerRadius", "cornerRadius", "startAngle", "endAngle"],
28
27
  _excluded3 = ["formatter"],
@@ -35,41 +34,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
35
34
  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; }
36
35
  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; }
37
36
  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
- };
73
37
  var defaultChart = {
74
38
  outerRadius: 1,
75
39
  innerRadius: 0,
@@ -274,7 +238,6 @@ var getCircleScale = function getCircleScale() {
274
238
  }));
275
239
  };
276
240
  var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
277
- var _legend$config2;
278
241
  var width = _ref5.width,
279
242
  height = _ref5.height,
280
243
  _ref5$config = _ref5.config,
@@ -358,43 +321,7 @@ var Component = /*#__PURE__*/(0, _react.memo)(function (_ref5) {
358
321
  chartWidth = _useContext.width,
359
322
  chartHeight = _useContext.height,
360
323
  triggerOnRelative = _useContext.triggerOnRelative,
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 adaptiveMarginPresetKey = (0, _react.useRef)("");
370
- (0, _react.useEffect)(function () {
371
- if (legendLayoutMode !== "Adaptive" || !updateConfig) return;
372
- var presetKey = "".concat(legendLayoutMode, "-").concat(legendShow, "-").concat(legendAlignment);
373
- if (adaptiveMarginPresetKey.current === presetKey) return;
374
- adaptiveMarginPresetKey.current = presetKey;
375
- var target = getPieAdaptiveMargin(legendShow, legendAlignment);
376
- updateConfig({
377
- id: id,
378
- type: "config",
379
- payload: [{
380
- path: ["chart", "margin", "marginTop"],
381
- field: "value",
382
- value: target.marginTop
383
- }, {
384
- path: ["chart", "margin", "marginBottom"],
385
- field: "value",
386
- value: target.marginBottom
387
- }, {
388
- path: ["chart", "margin", "marginLeft"],
389
- field: "value",
390
- value: target.marginLeft
391
- }, {
392
- path: ["chart", "margin", "marginRight"],
393
- field: "value",
394
- value: target.marginRight
395
- }]
396
- });
397
- }, [id, updateConfig, legendLayoutMode, legendShow, legendAlignment]);
324
+ onEmit = _useContext.onEmit;
398
325
  var _useState = (0, _react.useState)(1),
399
326
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
400
327
  y = _useState2[0],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/charts",
3
- "version": "1.10.18",
3
+ "version": "1.10.20",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -128,7 +128,7 @@ const Chart = memo(
128
128
  cPercent: dragPercent,
129
129
  cBarX: controlX,
130
130
  });
131
- }, [JSON.stringify(control), width]);
131
+ }, [JSON.stringify(control), width, height]);
132
132
 
133
133
  const svg = useRef();
134
134
  const axes = useAxes({
@@ -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
- const legendAreaWidth = Math.max(0, fullWidth - marginLeft - marginRight);
236
- const sideLegendMaxWidth = isSideLegend
237
- ? Math.max(
238
- 0,
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: legendAreaWidth } : {}),
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: legendAreaWidth || "100%",
407
- maxWidth: legendAreaWidth || "100%",
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",
@@ -34,21 +34,9 @@ import { pieLegendFormatter as legendFormatter } from "../formatter";
34
34
  import ringCss from "../css/piechart.module.css";
35
35
  import { useAiDataOfPie } from "../hooks";
36
36
  import { PieTooltip } from "./PieTooltip";
37
- import { getPieAdaptiveMarginPreset } from "../utils/legendPlacement";
38
37
 
39
38
  const PI = Math.PI;
40
39
 
41
- const PIE_ADAPTIVE_MARGINS = {
42
- right: { marginTop: 24, marginBottom: 24, marginLeft: 0, marginRight: 200 },
43
- left: { marginTop: 24, marginBottom: 24, marginLeft: 200, marginRight: 0 },
44
- top: { marginTop: 110, marginBottom: 24, marginLeft: 24, marginRight: 24 },
45
- bottom: { marginTop: 24, marginBottom: 110, marginLeft: 24, marginRight: 24 },
46
- hidden: { marginTop: 24, marginBottom: 24, marginLeft: 24, marginRight: 24 },
47
- };
48
-
49
- const getPieAdaptiveMargin = (show, alignment) =>
50
- getPieAdaptiveMarginPreset(show, alignment, PIE_ADAPTIVE_MARGINS);
51
-
52
40
  const defaultChart = {
53
41
  outerRadius: 1,
54
42
  innerRadius: 0,
@@ -312,45 +300,7 @@ const Component = memo(
312
300
  height: chartHeight,
313
301
  triggerOnRelative,
314
302
  onEmit,
315
- updateConfig,
316
303
  } = useContext(chartContext);
317
- const { show: legendShow, name: { layoutMode: legendLayoutMode } = {} } =
318
- legend.config;
319
- const legendAlignment = legend.config?.layout?.alignment;
320
- const adaptiveMarginPresetKey = useRef("");
321
- useEffect(() => {
322
- if (legendLayoutMode !== "Adaptive" || !updateConfig) return;
323
- const presetKey = `${legendLayoutMode}-${legendShow}-${legendAlignment}`;
324
- if (adaptiveMarginPresetKey.current === presetKey) return;
325
- adaptiveMarginPresetKey.current = presetKey;
326
- const target = getPieAdaptiveMargin(legendShow, legendAlignment);
327
- updateConfig({
328
- id,
329
- type: "config",
330
- payload: [
331
- {
332
- path: ["chart", "margin", "marginTop"],
333
- field: "value",
334
- value: target.marginTop,
335
- },
336
- {
337
- path: ["chart", "margin", "marginBottom"],
338
- field: "value",
339
- value: target.marginBottom,
340
- },
341
- {
342
- path: ["chart", "margin", "marginLeft"],
343
- field: "value",
344
- value: target.marginLeft,
345
- },
346
- {
347
- path: ["chart", "margin", "marginRight"],
348
- field: "value",
349
- value: target.marginRight,
350
- },
351
- ],
352
- });
353
- }, [id, updateConfig, legendLayoutMode, legendShow, legendAlignment]);
354
304
  const [y, setY] = useState(1);
355
305
  const radius = (Math.min(chartWidth, chartHeight) / 2) * outerRadius;
356
306