UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

157 lines (156 loc) 6.78 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var mobx_1 = require("mobx"); var lodash_1 = require("lodash"); var app_sdk_1 = require("@qn-pandora/app-sdk"); var bind_1 = __importDefault(require("../../../utils/bind")); var chart_drill_down_1 = require("../../../services/chart-drill-down"); var chart_common_action_1 = require("../../../services/chart-common-action"); var chart_dataset_1 = require("../transforms/chart-dataset"); var base_1 = __importDefault(require("./base")); var OneDChartStore = /** @class */ (function (_super) { __extends(OneDChartStore, _super); function OneDChartStore(getProps) { var _this = _super.call(this, getProps) || this; _this.onEvents = { click: _this.handleDrillDown }; return _this; } Object.defineProperty(OneDChartStore.prototype, "isDateSeries", { get: function () { return !!this.currentBuckets.find(function (bucket) { return bucket.fieldType === app_sdk_1.EChartFieldType.Time; }); }, enumerable: false, configurable: true }); Object.defineProperty(OneDChartStore.prototype, "currentMetrics", { get: function () { var _this = this; var currentMetrics = this.chartStyleService.currentMetrics; return currentMetrics .map(function (metric) { return _this.fields.find(function (field) { return field.key === metric; }); }) .filter(function (metric) { return !!metric; }); }, enumerable: false, configurable: true }); Object.defineProperty(OneDChartStore.prototype, "currentBuckets", { get: function () { var _this = this; var currentBuckets = this.chartStyleService.currentBuckets; return currentBuckets .map(function (bucket) { return _this.fields.find(function (field) { return field.key === bucket; }); }) .filter(function (bucket) { return !!bucket; }); }, enumerable: false, configurable: true }); Object.defineProperty(OneDChartStore.prototype, "chartDataset", { get: function () { var _a = this.chartStyleService, currentMetrics = _a.currentMetrics, unitTransformer = _a.unitTransformer; return chart_dataset_1.formatUnit(this.dataset, currentMetrics.reduce(function (res, metric) { res[metric] = unitTransformer; return res; }, {})); }, enumerable: false, configurable: true }); Object.defineProperty(OneDChartStore.prototype, "baseData", { get: function () { var _a = this.dataset, rows = _a.rows, fields = _a.fields; if (fields.length === 0) { return []; } else if (fields.length === 1) { return [ { name: fields[0].name || fields[0].key, value: rows[0][0][0], bucketName: '' } ]; } else { return rows.map(function (row) { return ({ name: (row[0][0] || '').toString(), value: row[1][0], bucketName: fields[0].name || fields[0].key }); }); } }, enumerable: false, configurable: true }); OneDChartStore.prototype.handleDrillDown = function (params) { if (params.componentType !== 'series') { return; } this.onAction({ mainAxisValue: params.name, mainAxisField: lodash_1.get(this.currentBuckets, [0, 'key']), metricValue: params.data && params.data.value, metricField: lodash_1.get(this.currentMetrics, [0, 'key']), fields: this.fields }, chart_drill_down_1.OneDChartDrillDownService, chart_common_action_1.OneDChartActionService); }; __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], OneDChartStore.prototype, "isDateSeries", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], OneDChartStore.prototype, "currentMetrics", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], OneDChartStore.prototype, "currentBuckets", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], OneDChartStore.prototype, "chartDataset", null); __decorate([ mobx_1.computed, __metadata("design:type", Array), __metadata("design:paramtypes", []) ], OneDChartStore.prototype, "baseData", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], OneDChartStore.prototype, "handleDrillDown", null); return OneDChartStore; }(base_1.default)); exports.default = OneDChartStore;