UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

109 lines (108 loc) 5.12 kB
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 React from 'react'; import classnames from 'classnames'; import { reaction } from 'mobx'; import { observer } from 'mobx-react'; import vis from 'vis-timeline'; import BasicComponent from '../../../components/Base/BasicComponent'; import bind from '../../../utils/bind'; import ChartContainer from '../components/ChartContainer'; import storeWrapper from '../components/StoreWrapper'; import TimeLineChartStore from './store'; import 'vis-timeline/dist/vis-timeline-graph2d.min.css'; import * as style from './style.mless'; var TimeLineChart = /** @class */ (function (_super) { __extends(TimeLineChart, _super); function TimeLineChart() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.store = _this.props.store; _this.container = null; return _this; } TimeLineChart.prototype.setContainer = function (container) { this.container = container; }; TimeLineChart.prototype.updateTimeline = function () { if (this.store.timeline) { this.store.timeline.setOptions(this.store.options); this.store.timeline.setItems(this.store.items); } }; TimeLineChart.prototype.componentDidMount = function () { var _this = this; if (this.container) { this.store.timeline = new vis.Timeline(this.container, undefined, this.store.options); this.updateTimeline(); } var itemDoms = document.getElementsByClassName('vis-item'); if (itemDoms.length) { Array.from(itemDoms).forEach(function (itemDom) { itemDom.style.color = _this.store.itemStyle.color; itemDom.style.background = _this.store.itemStyle.background; itemDom.style.borderColor = _this.store.itemStyle.borderColor; }); } this.addDisposer(reaction(function () { return [_this.store.options, _this.store.items]; }, function () { _this.updateTimeline(); }), reaction(function () { return _this.store.itemStyle; }, function (itemStyle) { var itemDoms = document.getElementsByClassName('vis-item'); if (itemDoms.length) { Array.from(itemDoms).map(function (itemDom) { itemDom.style.color = itemStyle.color; itemDom.style.background = itemStyle.background; itemDom.style.borderColor = itemStyle.borderColor; }); } })); }; TimeLineChart.prototype.componentWillUnmount = function () { if (this.store.timeline) { this.store.timeline.destroy(); } _super.prototype.componentWillUnmount.call(this); }; TimeLineChart.prototype.render = function () { return (React.createElement(ChartContainer, { onClient: this.store.debounceHandleClient }, React.createElement("div", { ref: this.setContainer, className: classnames(style.timelineChartContainer, this.store.theme), style: { background: this.store.itemStyle.chartBackGround } }))); }; __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TimeLineChart.prototype, "setContainer", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], TimeLineChart.prototype, "updateTimeline", null); TimeLineChart = __decorate([ observer ], TimeLineChart); return TimeLineChart; }(BasicComponent)); export default storeWrapper(TimeLineChart, TimeLineChartStore);