UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

158 lines (157 loc) 6.91 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 __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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DoughnutInterval = void 0; var mobx_react_1 = require("mobx-react"); var mobx_1 = require("mobx"); var lodash_1 = require("lodash"); var BasicComponent_1 = __importDefault(require("../../../../../components/Base/BasicComponent")); var bind_1 = __importDefault(require("../../../../../utils/bind")); var interval_1 = require("../../../../../utils/interval"); var store_1 = __importDefault(require("../../PieRingBucket/store")); var errorBoundary_1 = __importDefault(require("../../../../../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(mobx_1.reaction(function () { return _this.chartStyleService.circularPlay; }, function (circularPlay) { if (circularPlay === "on" /* On */) { _this.startPlay(); } else { _this.stopPlay(); } }, { fireImmediately: true })); this.addDisposer(mobx_1.reaction(function () { return [ _this.chartStyleService.circularPlayInterval, _this.chartStyleService.maxSlices, _this.props.store.metrics, _this.props.store instanceof store_1.default && _this.props.store.buckets ]; }, function (_a) { var _b = __read(_a, 1), interval = _b[0]; _this.stopPlay(); if (interval > 0) { setTimeout(_this.startPlay, 0); } }, { equals: lodash_1.isEqual })); }; DoughnutInterval.prototype.componentWillUnmount = function () { this.stopPlay(); _super.prototype.componentWillUnmount.call(this); }; DoughnutInterval.prototype.startPlay = function () { var _this = this; this.playInterval = interval_1.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 = lodash_1.get(series, [0, 'data']) || []; echartInst.dispatchAction({ type: 'downplay' }); var nextPlayIndex = (playIndex + 1) % currentData.length; setPlayIndex(nextPlayIndex); var currentPlaySlice = lodash_1.get(currentData, nextPlayIndex); if (currentPlaySlice) { var name_1 = lodash_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_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], DoughnutInterval.prototype, "startPlay", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], DoughnutInterval.prototype, "stopPlay", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], DoughnutInterval.prototype, "handlePieTask", null); DoughnutInterval = __decorate([ mobx_react_1.observer ], DoughnutInterval); return DoughnutInterval; }(BasicComponent_1.default)); exports.DoughnutInterval = DoughnutInterval; exports.default = errorBoundary_1.default(DoughnutInterval);