UNPKG

@alicloud/cloud-charts

Version:

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

149 lines (121 loc) 5.82 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports["default"] = void 0; var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); var _legend = _interopRequireDefault(require("@antv/g2/esm/chart/controller/legend")); var _dependents = require("@antv/g2/esm/dependents"); var _reactLegend = _interopRequireDefault(require("../component/reactLegend")); var _constants = require("../../constants"); // 引入自定义的图例组件 // @ts-ignore var WidgetsLegendController = /*#__PURE__*/function (_RawLegendController) { (0, _inheritsLoose2["default"])(WidgetsLegendController, _RawLegendController); function WidgetsLegendController(props) { var _this; _this = _RawLegendController.call(this, props) || this; _this.parentDom = void 0; _this.widgetsContainer = void 0; _this.parentDom = _this.view.getCanvas().get('el').parentNode.parentNode.parentNode; return _this; } // @ts-ignore var _proto = WidgetsLegendController.prototype; _proto.createCustomLegend = function createCustomLegend(geometry, attr, scale, legendOption) { // 直接使用 分类图例渲染 // @ts-ignore var cfg = this.getCategoryCfg(geometry, attr, scale, legendOption, true); return new _dependents.CategoryLegend(cfg); } // @ts-ignore ; _proto.createCategoryLegend = function createCategoryLegend(geometry, attr, scale, legendOption) { var _this$parentDom$getEl; // @ts-ignore var cfg = this.getCategoryCfg(geometry, attr, scale, legendOption); this.widgetsContainer = (_this$parentDom$getEl = this.parentDom.getElementsByClassName('widgets-legend')) === null || _this$parentDom$getEl === void 0 ? void 0 : _this$parentDom$getEl[0]; // const { // autoCollapse, // collapseRow, // showData, // marker, // allowAllCanceled, // hoverable, // onHover, // clickable, // onClick, // customConfig, // maxWidth, // maxHeight, // maxWidthRatio, // maxHeightRatio, // useReverseChecked, // table, // foldable, // dodge, // } = this.view?.widgetsCtx?.props?.config?.legend || {}; // // 当以下配置项生效时,使用g2 原生legend // if ( // !table && // !foldable && // (autoCollapse || // collapseRow || // showData || // marker || // allowAllCanceled || // hoverable === false || // onHover || // clickable === false || // onClick || // customConfig || // maxWidth || // maxHeight || // maxWidthRatio || // maxHeightRatio || // useReverseChecked === false || // dodge) // ) { // console.log('normal', this.view?.widgetsCtx?.props?.config?.legend); // // 普通legend // return new CategoryLegend(cfg); // } // 列表型legend及折叠型legend if (legendOption !== null && legendOption !== void 0 && legendOption.table || legendOption !== null && legendOption !== void 0 && legendOption.foldable) { if (!this.widgetsContainer) { var _legendOption$positio, _legendOption$positio2, _legendOption$positio3, _legendOption$positio4, _legendOption$positio5; this.widgetsContainer = document.createElement('div'); this.widgetsContainer.className = _constants.FullCrossName + " widgets-legend"; var position = legendOption === null || legendOption === void 0 ? void 0 : (_legendOption$positio = legendOption.position) === null || _legendOption$positio === void 0 ? void 0 : (_legendOption$positio2 = _legendOption$positio.split('-')) === null || _legendOption$positio2 === void 0 ? void 0 : _legendOption$positio2[0]; var align = (_legendOption$positio3 = legendOption === null || legendOption === void 0 ? void 0 : (_legendOption$positio4 = legendOption.position) === null || _legendOption$positio4 === void 0 ? void 0 : (_legendOption$positio5 = _legendOption$positio4.split('-')) === null || _legendOption$positio5 === void 0 ? void 0 : _legendOption$positio5[1]) !== null && _legendOption$positio3 !== void 0 ? _legendOption$positio3 : 'center'; var directionX = ['top', 'bottom'].includes(position) ? align === 'center' ? 'center' : align === 'left' || align === 'top' ? 'flex-start' : 'flex-end' : 'flex-start'; var directionY = align === 'center' ? 'center' : align === 'left' || align === 'top' ? 'flex-start' : 'flex-end'; this.widgetsContainer.style.cssText = "width: 100%; display: flex; justify-content: " + directionX + "; align-items: " + directionY + "; overflow-x: auto;overflow-y: hidden;"; this.parentDom.appendChild(this.widgetsContainer); } this.widgetsContainer.style.visibility = 'visible'; return new _reactLegend["default"]({ cfg: cfg, container: this.widgetsContainer, chart: this.view, legendConfig: legendOption }); } if (this.widgetsContainer) { this.widgetsContainer.style.visibility = 'hidden'; } // 普通legend return new _dependents.CategoryLegend(cfg); }; _proto.clear = function clear() { _RawLegendController.prototype.clear.call(this); if (this.widgetsContainer) { this.widgetsContainer.style.visibility = 'hidden'; } }; _proto.destroy = function destroy() { _RawLegendController.prototype.destroy.call(this); // 销毁之前的legend widgetsContainer if (this.widgetsContainer) { this.parentDom.removeChild(this.widgetsContainer); this.widgetsContainer = null; } }; return WidgetsLegendController; }(_legend["default"]); var _default = WidgetsLegendController; exports["default"] = _default;