@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
112 lines (111 loc) • 4.91 kB
JavaScript
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 __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 __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import * as React from 'react';
import { observer } from 'mobx-react';
import { observable, action, reaction } from 'mobx';
import { debounce } from 'lodash';
import bind from '../../../utils/bind';
import BasicComponent from '../BasicComponent';
import errorBoundary from '../../../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 = debounce(function () { return _this.getNumScale(); }, 100);
return _this;
}
ScaleContent.prototype.componentDidMount = function () {
var _this = this;
this.addDisposer(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([
observable,
__metadata("design:type", Boolean)
], ScaleContent.prototype, "_unmounted", void 0);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ScaleContent.prototype, "setScale", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Boolean]),
__metadata("design:returntype", void 0)
], ScaleContent.prototype, "setUnMount", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ScaleContent.prototype, "getNumScale", null);
ScaleContent = __decorate([
observer
], ScaleContent);
return ScaleContent;
}(BasicComponent));
export { ScaleContent };
export default errorBoundary(ScaleContent);