UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

152 lines (151 loc) 6.46 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); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import { observer } from 'mobx-react'; import { reaction } from 'mobx'; import { get, isEqual } from 'lodash'; import BasicComponent from '../../../../../components/Base/BasicComponent'; import bind from '../../../../../utils/bind'; import { startInterval } from '../../../../../utils/interval'; import PieRingBucketStore from '../../PieRingBucket/store'; import errorBoundary from '../../../../../hocs/errorBoundary'; var DoughnutInterval = /** @class */ (function (_super) { __extends(DoughnutInterval, _super); function DoughnutInterval() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.playInterval = null; _this.chartStyleService = _this.props.store .chartStyleService; return _this; } DoughnutInterval.prototype.componentDidMount = function () { var _this = this; this.addDisposer(reaction(function () { return _this.chartStyleService.circularPlay; }, function (circularPlay) { if (circularPlay === "on" /* On */) { _this.startPlay(); } else { _this.stopPlay(); } }, { fireImmediately: true })); this.addDisposer(reaction(function () { return [ _this.chartStyleService.circularPlayInterval, _this.chartStyleService.maxSlices, _this.props.store.metrics, _this.props.store instanceof PieRingBucketStore && _this.props.store.buckets ]; }, function (_a) { var _b = __read(_a, 1), interval = _b[0]; _this.stopPlay(); if (interval > 0) { setTimeout(_this.startPlay, 0); } }, { equals: isEqual })); }; DoughnutInterval.prototype.componentWillUnmount = function () { this.stopPlay(); _super.prototype.componentWillUnmount.call(this); }; DoughnutInterval.prototype.startPlay = function () { var _this = this; this.playInterval = startInterval(function () { _this.handlePieTask(); }, this.chartStyleService.circularPlayInterval * 1000, true); }; DoughnutInterval.prototype.stopPlay = function () { var _a = this.props.store, echartInst = _a.echartInst, setCurrentPlaySlice = _a.setCurrentPlaySlice, setPlayIndex = _a.setPlayIndex; if (echartInst) { echartInst.dispatchAction({ type: 'downplay' }); } if (this.playInterval) { clearInterval(this.playInterval); } setCurrentPlaySlice(null); setPlayIndex(-1); }; DoughnutInterval.prototype.handlePieTask = function () { var _a = this.props.store, echartInst = _a.echartInst, playIndex = _a.playIndex, setPlayIndex = _a.setPlayIndex, series = _a.series, setCurrentPlaySlice = _a.setCurrentPlaySlice; if (echartInst) { var currentData = get(series, [0, 'data']) || []; echartInst.dispatchAction({ type: 'downplay' }); var nextPlayIndex = (playIndex + 1) % currentData.length; setPlayIndex(nextPlayIndex); var currentPlaySlice = get(currentData, nextPlayIndex); if (currentPlaySlice) { var name_1 = get(currentPlaySlice, 'name'); if (currentData.length > 1) { echartInst.dispatchAction({ type: 'highlight', seriesIndex: 0, name: name_1 }); } setCurrentPlaySlice(currentPlaySlice); } } }; DoughnutInterval.prototype.render = function () { return null; }; __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], DoughnutInterval.prototype, "startPlay", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], DoughnutInterval.prototype, "stopPlay", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], DoughnutInterval.prototype, "handlePieTask", null); DoughnutInterval = __decorate([ observer ], DoughnutInterval); return DoughnutInterval; }(BasicComponent)); export { DoughnutInterval }; export default errorBoundary(DoughnutInterval);