UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

137 lines (136 loc) 6.18 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScaleContent = void 0; var React = __importStar(require("react")); var mobx_react_1 = require("mobx-react"); var mobx_1 = require("mobx"); var lodash_1 = require("lodash"); var bind_1 = __importDefault(require("../../../utils/bind")); var BasicComponent_1 = __importDefault(require("../BasicComponent")); var errorBoundary_1 = __importDefault(require("../../../hocs/errorBoundary")); var ScaleContent = /** @class */ (function (_super) { __extends(ScaleContent, _super); function ScaleContent() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._unmounted = false; _this.debounceGetNumScale = lodash_1.debounce(function () { return _this.getNumScale(); }, 100); return _this; } ScaleContent.prototype.componentDidMount = function () { var _this = this; this.addDisposer(mobx_1.reaction(function () { return [ _this.props.children, _this.props.containerWidth, _this.props.containerHeight ]; }, function () { // logdb 请求resolve时间为500ms,这里时间需大于500 setTimeout(function () { return _this.debounceGetNumScale(); }, 550); }, { fireImmediately: true })); }; ScaleContent.prototype.componentWillUnmount = function () { this.setUnMount(true); _super.prototype.componentWillUnmount.call(this); }; ScaleContent.prototype.setScale = function (scale) { if (this.props.onScale) { this.props.onScale(scale); } }; ScaleContent.prototype.setUnMount = function (isUnMount) { this._unmounted = isUnMount; }; ScaleContent.prototype.getNumScale = function () { var scaleX = 1; var scaleY = 1; if (!this._unmounted) { var node = this.getRootDOM(); if (node instanceof HTMLDivElement) { var _a = this.props, containerWidth = _a.containerWidth, containerHeight = _a.containerHeight; var offsetWidth = node.offsetWidth, offsetHeight = node.offsetHeight; if (containerWidth && offsetWidth && offsetWidth > containerWidth) { scaleX = containerWidth / offsetWidth; } if (containerHeight && offsetHeight && offsetHeight > containerHeight) { scaleY = containerHeight / offsetHeight; } } } this.setScale({ scaleX: scaleX, scaleY: scaleY }); }; ScaleContent.prototype.render = function () { return React.createElement("div", null, this.props.children); }; __decorate([ mobx_1.observable, __metadata("design:type", Boolean) ], ScaleContent.prototype, "_unmounted", void 0); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], ScaleContent.prototype, "setScale", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], ScaleContent.prototype, "setUnMount", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], ScaleContent.prototype, "getNumScale", null); ScaleContent = __decorate([ mobx_react_1.observer ], ScaleContent); return ScaleContent; }(BasicComponent_1.default)); exports.ScaleContent = ScaleContent; exports.default = errorBoundary_1.default(ScaleContent);