@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
190 lines (189 loc) • 8.79 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 __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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 React from 'react';
import PropTypes from 'prop-types';
import { v4 as uuid } from 'uuid';
import classnames from 'classnames';
import screenfull from 'screenfull';
import { reaction, computed } from 'mobx';
import { observer } from 'mobx-react';
import { Spin } from 'antd';
import BasicComponent from '../../components/Base/BasicComponent';
import bind from '../../utils/bind';
import { ThemeProvider } from '../../context/theme';
import ThemeService from '../../services/theme/registerTheme';
import { initialTheme } from '../../constants';
import VariableWrapper, { replaceVariable } from './VariableWrapper';
import OperationBar from './OperationBar';
import Panel from './Panel';
import Store from './store';
import { transformDomToCanvas, transformDomToPDF } from './transform';
import * as style from './style.mless';
export * from './constants';
export * from './transform';
export * from './OperationBar';
export { calcVariableMap, replaceVariable } from './VariableWrapper';
var BaseDashboard = /** @class */ (function (_super) {
__extends(BaseDashboard, _super);
function BaseDashboard() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.uid = uuid();
_this.themeService = new ThemeService(_this.props.theme || initialTheme, _this.uid);
_this.store = new Store();
return _this;
}
BaseDashboard.prototype.getChildContext = function () {
var _this = this;
var _a = this.props, getPopupContainer = _a.getPopupContainer, getModalContainer = _a.getModalContainer;
return {
baseDashboardStore: this.store,
toggleFullscreen: this.toggleFullscreen,
getPopupContainer: getPopupContainer || this.getRootDOM,
getModalContainer: getModalContainer || this.getRootDOM,
getDashboardCanvas: function () { return transformDomToCanvas(_this.getRootDOM()); },
getDashboardPDF: function () { return transformDomToPDF(_this.getRootDOM()); },
themeService: this.themeService
};
};
Object.defineProperty(BaseDashboard.prototype, "themeContext", {
get: function () {
return {
themeService: this.themeService
};
},
enumerable: false,
configurable: true
});
BaseDashboard.prototype.updateIsFullscreen = function () {
var onToggleFullscreen = this.props.onToggleFullscreen;
var isFullscreen = screenfull ? screenfull.isFullscreen : false;
this.store.setIsFullscreen(isFullscreen);
if (onToggleFullscreen) {
onToggleFullscreen(isFullscreen);
}
};
BaseDashboard.prototype.toggleFullscreen = function () {
if (screenfull) {
if (this.store.isFullscreen) {
screenfull.exit();
}
else {
screenfull.request(this.getRootDOM());
}
}
};
BaseDashboard.prototype.replaceVariable = function (target, variables) {
var _a = this.props.variableMap, variableMap = _a === void 0 ? {} : _a;
return replaceVariable(target, __assign(__assign({}, variableMap), variables));
};
BaseDashboard.prototype.componentDidMount = function () {
var _this = this;
var screenfullLib = screenfull;
if (screenfullLib) {
screenfullLib.onchange(this.updateIsFullscreen);
this.addDisposer(function () {
screenfullLib.off('change', _this.updateIsFullscreen);
});
}
// 同步prop状态到store
this.addDisposer(reaction(function () { return _this.props.theme; }, function (theme) {
if (theme) {
_this.themeService.setTheme(theme);
_this.store.setTheme(theme);
}
}, { fireImmediately: true }), reaction(function () { return _this.props.isEditing; }, function (isEditing) { return _this.store.setIsEditing(isEditing || false); }, { fireImmediately: true }), reaction(function () { return _this.props.screenRatio; }, function (screenRatio) { return _this.store.setScreenScaleY(screenRatio || 0); }, { fireImmediately: true }));
};
BaseDashboard.prototype.componentWillUnmount = function () {
this.themeService.dispose();
};
BaseDashboard.prototype.render = function () {
var _a;
var _b = this.props, className = _b.className, loading = _b.loading, children = _b.children, backgroundColor = _b.backgroundColor, fullscreen = _b.fullscreen;
var _c = this.store, isFullscreen = _c.isFullscreen, screenScaleY = _c.screenScaleY, theme = _c.theme;
var rootCls = classnames(style.root, className, style[theme], "chart-container-" + (this.props.theme || initialTheme), (_a = {},
_a[style.fullscreen] = isFullscreen || fullscreen === 'true',
_a));
var rootStyle = screenScaleY
? {
transformOrigin: 'top',
transform: "scaleY(" + screenScaleY + ")"
}
: undefined;
return (React.createElement(ThemeProvider, { value: this.themeContext },
React.createElement("div", { ref: this.setRootRef, className: rootCls, style: { backgroundColor: backgroundColor } },
React.createElement("div", { className: style.content, style: rootStyle },
React.createElement(Spin, { spinning: !!loading },
React.createElement("div", null, children))))));
};
BaseDashboard.VariableWrapper = VariableWrapper;
BaseDashboard.OperationBar = OperationBar;
BaseDashboard.Panel = Panel;
BaseDashboard.childContextTypes = {
baseDashboardStore: PropTypes.object,
toggleFullscreen: PropTypes.func,
getPopupContainer: PropTypes.func,
getModalContainer: PropTypes.func,
getDashboardCanvas: PropTypes.func,
getDashboardPDF: PropTypes.func,
themeService: PropTypes.object
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], BaseDashboard.prototype, "themeContext", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], BaseDashboard.prototype, "updateIsFullscreen", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], BaseDashboard.prototype, "toggleFullscreen", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", void 0)
], BaseDashboard.prototype, "replaceVariable", null);
BaseDashboard = __decorate([
observer
], BaseDashboard);
return BaseDashboard;
}(BasicComponent));
export default BaseDashboard;