UNPKG

@alicloud/cloud-charts

Version:

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

67 lines (64 loc) 2.2 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import { CategoryLegend } from '@antv/g2/esm/dependents'; import ReactDOM from 'react-dom'; import React from 'react'; import TableLegend from './TableLegend'; import FoldableLegend from './FoldableLegend'; import GradientLegend from './GradientLegend'; // 优先级:table > gradient > foldable function switchLegendComponent(config, items, chart) { if (config !== null && config !== void 0 && config.table) { return /*#__PURE__*/React.createElement(TableLegend, { config: config, legendItems: items, chart: chart }); } else if (config !== null && config !== void 0 && config.gradient) { return /*#__PURE__*/React.createElement(GradientLegend, { config: config, legendItems: items, chart: chart }); } else if (config !== null && config !== void 0 && config.foldable) { return /*#__PURE__*/React.createElement(FoldableLegend, { config: config, legendItems: items, chart: chart }); } return /*#__PURE__*/React.createElement(TableLegend, { config: config, legendItems: items, chart: chart }); } // @ts-ignore var ReactLegend = /*#__PURE__*/function (_CategoryLegend) { _inheritsLoose(ReactLegend, _CategoryLegend); function ReactLegend(props) { var _this; var cfg = props.cfg, container = props.container, chart = props.chart, legendConfig = props.legendConfig; _this = _CategoryLegend.call(this, cfg) || this; _this.container = void 0; _this.chart = void 0; _this.legendConfig = void 0; _this.container = container; _this.chart = chart; _this.legendConfig = legendConfig; return _this; } var _proto = ReactLegend.prototype; _proto.drawLegendContent = function drawLegendContent(group) { var items = this.get('items'); // const currentPoint = this.get('currentPoint'); // const startX = currentPoint.x; // const startY = currentPoint.y; var LegendRender = switchLegendComponent(this.legendConfig, items, this.chart); ReactDOM.render(LegendRender, this.container); }; return ReactLegend; }(CategoryLegend); export default ReactLegend;