UNPKG

@alicloud/cloud-charts

Version:

![](https://img.shields.io/npm/v/@alicloud/cloud-charts?color=%23ff8200)

44 lines (41 loc) 2.55 kB
"use strict"; exports.__esModule = true; exports["default"] = _default; var _constants = require("../constants"); var _common = require("./common"); /** * updateChildrenPosition,需要在 chart afterpaint 中调用,相比 afterrender 事件,在数据更新后也会触发 afterpaint * * @param {Chart} chart 图表实例 * @param {HTMLElement} dom 元素节点 * */ function _default(chart, dom) { // 更新子元素位置 // 限制子元素宽度 var childDom = dom && dom.querySelector("." + _constants.FullCrossName + "-children"); if (childDom) { var _chart$widgetsCtx, _chart$widgetsCtx2, _chart$widgetsCtx2$pr, _chart$widgetsCtx2$pr2, _chart$coordinateBBox, _chart$coordinateBBox2; var centerPoint = chart.getCoordinate().getCenter(); childDom.style.left = centerPoint.x + "px"; childDom.style.top = centerPoint.y + "px"; var parentMinSize = 0; // 获取父元素配置 var chartType = (chart === null || chart === void 0 ? void 0 : (_chart$widgetsCtx = chart.widgetsCtx) === null || _chart$widgetsCtx === void 0 ? void 0 : _chart$widgetsCtx.chartName) || 'G2Pie'; var defaultRadius = chartType === 'G2Pie' ? 0.6 : 0.4; var innerRadius = (chart === null || chart === void 0 ? void 0 : (_chart$widgetsCtx2 = chart.widgetsCtx) === null || _chart$widgetsCtx2 === void 0 ? void 0 : (_chart$widgetsCtx2$pr = _chart$widgetsCtx2.props) === null || _chart$widgetsCtx2$pr === void 0 ? void 0 : (_chart$widgetsCtx2$pr2 = _chart$widgetsCtx2$pr.config) === null || _chart$widgetsCtx2$pr2 === void 0 ? void 0 : _chart$widgetsCtx2$pr2.innerRadius) || defaultRadius; // 获取父元素尺寸 var parentDom = childDom && childDom.parentNode; if (parentDom) { var _ref = (parentDom === null || parentDom === void 0 ? void 0 : parentDom.style) || {}, width = _ref.width, height = _ref.height; parentMinSize = Math.min((0, _common.pxToNumber)(width), (0, _common.pxToNumber)(height)); } // 获取坐标系尺寸 var bBoxMinSize = Math.min(chart === null || chart === void 0 ? void 0 : (_chart$coordinateBBox = chart.coordinateBBox) === null || _chart$coordinateBBox === void 0 ? void 0 : _chart$coordinateBBox.width, chart === null || chart === void 0 ? void 0 : (_chart$coordinateBBox2 = chart.coordinateBBox) === null || _chart$coordinateBBox2 === void 0 ? void 0 : _chart$coordinateBBox2.height); var minSize = Math.min(parentMinSize, bBoxMinSize); if (minSize !== 0) { childDom.style.maxWidth = minSize * innerRadius + "px"; } } }