UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

399 lines (398 loc) 17.4 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; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import { action, computed, observable } from 'mobx'; import bind from '../../../utils/bind'; import { isExtendChart } from '../../../utils/isExtendChart'; import Store from '../../../stores/store'; import ChartStyleService from '../chart-style/charts/base'; import { ChartType } from '../../../constants/chart-style'; import { pickDataset } from './transforms/merge-dataset'; import { sortDatasetColumn } from './transforms/sort-dataset'; import { BoundType } from '../../../constants/outlier'; var ChartConditionService = /** @class */ (function (_super) { __extends(ChartConditionService, _super); function ChartConditionService(analysisService) { var _this = _super.call(this) || this; _this.visualizationStyle = ''; _this.isInitFirst = true; _this.analysisService = analysisService; _this.isInitFirst = true; return _this; } Object.defineProperty(ChartConditionService.prototype, "chartType", { get: function () { return this.chartStyleService.chartType; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "isElement", { get: function () { return [ChartType.Editor].indexOf(this.chartType) !== -1; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "isTableChart", { get: function () { return (this.chartType === ChartType.GridTable || this.chartType === ChartType.TreeTable); }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "originDataset", { get: function () { return this.analysisService.dataset; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "twoDDataConfig", { get: function () { var _a = this.chartStyleService, field = _a.mainAxis.field, _b = _a.crossAxis1, crossAxisFields = _b.fields, crossAxisSubFields = _b.subFields, y1DisplayFields = _b.displayFields, fieldsGetter = _b.fieldsGetter, _c = _a.crossAxis2, crossAxis2Fields = _c.fields, y2Buckets = _c.y2Buckets, y2DisplayFields = _c.displayFields, colorsFields = _a.colors.fields; return { field: field, crossAxisFields: crossAxisFields, crossAxis2Fields: crossAxis2Fields, y2Buckets: y2Buckets, colorsFields: colorsFields, crossAxisSubFields: crossAxisSubFields, y1DisplayFields: y1DisplayFields, y2DisplayFields: y2DisplayFields, fieldsGetter: fieldsGetter }; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "dataset", { get: function () { var _a = this.originDataset, fields = _a.fields, rows = _a.rows; var chartType = this.chartStyleService.chartType; if (this.isExtendsChart) { return this.originDataset; } switch (chartType) { case ChartType.Line: case ChartType.StackLine: case ChartType.PercentageLine: case ChartType.Area: case ChartType.StackArea: case ChartType.PercentageArea: case ChartType.Bar: return pickDataset(fields, rows, __spread(this.twoDDataConfig.crossAxisFields, this.twoDDataConfig.crossAxis2Fields, this.twoDDataConfig.y1DisplayFields), __spread([this.twoDDataConfig.field], this.twoDDataConfig.colorsFields), this.twoDDataConfig.fieldsGetter); case ChartType.LineBarY2: case ChartType.LineY2: return pickDataset(fields, rows, __spread(this.twoDDataConfig.crossAxisFields, this.twoDDataConfig.crossAxis2Fields, this.twoDDataConfig.y1DisplayFields, this.twoDDataConfig.y2DisplayFields), __spread([ this.twoDDataConfig.field ], this.twoDDataConfig.colorsFields, this.twoDDataConfig.colorsFields)); case ChartType.LineBar: return pickDataset(fields, rows, __spread(this.twoDDataConfig.crossAxisFields, this.twoDDataConfig.crossAxisSubFields, this.twoDDataConfig.y1DisplayFields, this.twoDDataConfig.y2DisplayFields), __spread([ this.twoDDataConfig.field ], this.twoDDataConfig.colorsFields, this.twoDDataConfig.colorsFields)); case ChartType.Outlier: var _b = this.chartStyleService, crossAxis1 = _b.crossAxis1, mainAxis = _b.mainAxis, lowerBound = _b.lowerBound, lowerBoundType = _b.lowerBoundType, upperBound = _b.upperBound, upperBoundType = _b.upperBoundType; var metrics = __spread(crossAxis1.fields); if (lowerBoundType === BoundType.Field) { metrics.push(lowerBound.toString()); } if (upperBoundType === BoundType.Field) { metrics.push(upperBound.toString()); } return pickDataset(fields, rows, metrics, [mainAxis.field]); case ChartType.Scatter: return sortDatasetColumn(fields, rows, [], __spread([ this.twoDDataConfig.field ], this.twoDDataConfig.crossAxisFields, this.twoDDataConfig.colorsFields)); case ChartType.Bubble: var sizeField = this.chartStyleService.sizeField; return sortDatasetColumn(fields, rows, sizeField, __spread([ this.twoDDataConfig.field ], this.twoDDataConfig.crossAxisFields, this.twoDDataConfig.colorsFields)); case ChartType.TreeTable: case ChartType.GridTable: return this.originDataset; case ChartType.Editor: return { fields: [], rows: [] }; case ChartType.TimeLine: case ChartType.MapboxBubble: case ChartType.MapboxPath: case ChartType.TopoLogy: return this.originDataset; case ChartType.PieBucket: case ChartType.PieRingBucket: case ChartType.PieRingMetric: case ChartType.PieMetric: case ChartType.PieRoseBucket: case ChartType.PieRoseMetric: case ChartType.RelationCircular: case ChartType.RelationHorizontal: case ChartType.CapsuleBar: case ChartType.MapBubbleChina: case ChartType.MapBubbleWorld: case ChartType.MapColorChina: case ChartType.MapColorWorld: case ChartType.RadarBucket: case ChartType.RadarMetric: case ChartType.SingleGauge: case ChartType.SinglePercent: case ChartType.SingleValue: case ChartType.StatusPanel: case ChartType.MetricPanel: case ChartType.Sunburst: case ChartType.Honeycomb: var _c = this .chartStyleService, currentMetrics = _c.currentMetrics, currentBuckets = _c.currentBuckets; return pickDataset(fields, rows, currentMetrics, currentBuckets); default: return { fields: fields, rows: rows }; } }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "buckets", { get: function () { return this.dataset.fields.filter(function (field) { return field.type === 'bucket'; }); }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "metrics", { get: function () { return this.dataset.fields.filter(function (field) { return field.type === 'metric'; }); }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "isAnalysising", { get: function () { return this.analysisService.isAnalysising; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "hasDataLoaded", { get: function () { return this.analysisService.hasDataLoaded; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "isInitAnalysising", { get: function () { return this.analysisService.isInitAnalysising; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "process", { get: function () { return this.analysisService.process; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "hasData", { get: function () { return !!this.dataset.rows.length; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "isUnauth", { get: function () { return this.analysisService.isUnauth; }, enumerable: false, configurable: true }); Object.defineProperty(ChartConditionService.prototype, "isExtendsChart", { get: function () { // 改为静态判断,因为懒加载了自定义图表列表接口,不能再使用this.extendsCharts属性 return isExtendChart(this.chartType); }, enumerable: false, configurable: true }); ChartConditionService.prototype.handleAnalysis = function (condition) { return this.analysisService.handleAnalysis(condition); }; ChartConditionService.prototype.stop = function () { this.analysisService.stop(); }; ChartConditionService.prototype.clearDataLoaded = function () { this.analysisService.clearDataLoaded(); }; ChartConditionService.prototype.setChartStyleService = function (chartStyleService) { this.chartStyleService = chartStyleService; }; ChartConditionService.prototype.setVisualizationStyle = function (visualizationStyle) { this.visualizationStyle = visualizationStyle; }; __decorate([ observable, __metadata("design:type", String) ], ChartConditionService.prototype, "visualizationStyle", void 0); __decorate([ observable, __metadata("design:type", Boolean) ], ChartConditionService.prototype, "isInitFirst", void 0); __decorate([ observable.ref, __metadata("design:type", ChartStyleService) ], ChartConditionService.prototype, "chartStyleService", void 0); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "chartType", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "isElement", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "isTableChart", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "originDataset", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "twoDDataConfig", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "dataset", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "buckets", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "metrics", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "isAnalysising", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "hasDataLoaded", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "isInitAnalysising", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "process", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "hasData", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "isUnauth", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], ChartConditionService.prototype, "isExtendsChart", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], ChartConditionService.prototype, "handleAnalysis", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], ChartConditionService.prototype, "stop", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], ChartConditionService.prototype, "clearDataLoaded", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [ChartStyleService]), __metadata("design:returntype", void 0) ], ChartConditionService.prototype, "setChartStyleService", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], ChartConditionService.prototype, "setVisualizationStyle", null); return ChartConditionService; }(Store)); export default ChartConditionService;