UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

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