@alicloud/cloud-charts
Version:

92 lines (90 loc) • 4.18 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _log = _interopRequireDefault(require("../common/log"));
var _shoot = _interopRequireDefault(require("./shoot"));
var _constants = require("../constants");
require("./index.css");
var _excluded = ["className", "data", "config", "getPosition"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var prefix = _constants.PrefixName + "-wshoot";
var Wshoot = exports["default"] = /*#__PURE__*/function (_React$Component) {
(0, _inheritsLoose2["default"])(Wshoot, _React$Component);
function Wshoot(props) {
var _this;
_this = _React$Component.call(this, props) || this;
// 图表初始化时记录日志
_this.canvas = null;
_this.shoot = null;
(0, _log["default"])('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["default"](this.canvas, getPosition, (0, _extends2["default"])({
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 = (0, _objectWithoutPropertiesLoose2["default"])(_this$props3, _excluded);
var mainClasses = (0, _classnames["default"])(prefix, (_classNames = {}, _classNames[className] = !!className, _classNames));
return /*#__PURE__*/React.createElement("canvas", (0, _extends2["default"])({
className: mainClasses
}, otherProps, {
ref: function ref(c) {
return _this2.canvas = c;
}
}));
};
return Wshoot;
}(React.Component);
Wshoot.defaultProps = {
width: 800,
height: 600,
config: {}
};