UNPKG

@alicloud/cloud-charts

Version:

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

99 lines (81 loc) 2.92 kB
'use strict'; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; import _extends from "@babel/runtime/helpers/extends"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import * as React from 'react'; import classNames from 'classnames'; import chartLog from "../common/log"; import Shoot from './shoot'; import { PrefixName } from '../constants'; import "./index.css"; var prefix = PrefixName + "-wshoot"; var Wshoot = /*#__PURE__*/function (_React$Component) { _inheritsLoose(Wshoot, _React$Component); function Wshoot(props) { var _this; _this = _React$Component.call(this, props) || this; // 图表初始化时记录日志 _this.canvas = null; _this.shoot = null; chartLog('Wshoot', 'init'); return _this; } var _proto = Wshoot.prototype; _proto.componentDidMount = function componentDidMount() { var _this$props = this.props, width = _this$props.width, height = _this$props.height, config = _this$props.config, getPosition = _this$props.getPosition, data = _this$props.data; this.shoot = new Shoot(this.canvas, getPosition, _extends({ width: width, height: height }, config)); this.shoot.draw(data); }; _proto.componentDidUpdate = function componentDidUpdate(prevProps) { var _this$props2 = this.props, newData = _this$props2.data, newWidth = _this$props2.width, newHeight = _this$props2.height, getPosition = _this$props2.getPosition; var oldData = prevProps.data, oldWidth = prevProps.width, oldHeight = prevProps.height; // 更新 getPosition 函数 this.shoot.getPosition = getPosition; // 绘制飞线 if (newData !== oldData) { this.shoot.draw(newData); } // 调整尺寸 if (newWidth !== oldWidth || newHeight !== oldHeight) { this.shoot.changeSize(newWidth, newHeight); } }; _proto.componentWillUnmount = function componentWillUnmount() { this.shoot && this.shoot.destroy(); }; _proto.render = function render() { var _classNames, _this2 = this; var _this$props3 = this.props, className = _this$props3.className, data = _this$props3.data, config = _this$props3.config, getPosition = _this$props3.getPosition, otherProps = _objectWithoutPropertiesLoose(_this$props3, ["className", "data", "config", "getPosition"]); var mainClasses = classNames(prefix, (_classNames = {}, _classNames[className] = !!className, _classNames)); return /*#__PURE__*/React.createElement("canvas", _extends({ className: mainClasses }, otherProps, { ref: function ref(c) { return _this2.canvas = c; } })); }; return Wshoot; }(React.Component); Wshoot.defaultProps = { width: 800, height: 600, config: {} }; export { Wshoot as default };