UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

187 lines (186 loc) 8.09 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 __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); 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 __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 app_sdk_1 = require("@qn-pandora/app-sdk"); var bind_1 = __importDefault(require("../../../../utils/bind")); var lodash_1 = require("lodash"); var base_1 = __importStar(require("./base")); var getUnitTransformer = app_sdk_1.utils.unit.getUnitTransformer; var OneDChartStyleService = /** @class */ (function (_super) { __extends(OneDChartStyleService, _super); function OneDChartStyleService(option) { var _this = _super.call(this, option) || this; // 当前展示的分组字段 _this.currentBuckets = []; // 当前展示的指标, 仅支持一个单选值 _this.currentMetrics = []; // 单位 _this.unit = ['none', 'short']; // 数值精度 _this.precision = 2; _this.currentBuckets = option.currentBuckets || []; _this.currentMetrics = option.currentMetrics || []; _this.unit = option.unit || ['none', 'short']; _this.precision = lodash_1.isUndefined(option.precision) ? 2 : option.precision; _this.displayColors = option.displayColors || []; return _this; } OneDChartStyleService.getChartInitStyle = function (option, initFirst) { if (initFirst === void 0) { initFirst = true; } var newOption = { currentBuckets: option.buckets.slice(0, 1), currentMetrics: option.metrics.slice(0, 1) }; return initFirst ? __assign(__assign({}, newOption), option) : __assign(__assign({}, option), newOption); }; Object.defineProperty(OneDChartStyleService.prototype, "unitTransformer", { get: function () { var currentUnit = this.unit[1]; var precision = this.precision; return function (value) { return getUnitTransformer(currentUnit)(value, precision); }; }, enumerable: false, configurable: true }); OneDChartStyleService.prototype.setPrecision = function (precision) { this.precision = precision; }; OneDChartStyleService.prototype.setCurrentBuckets = function (currentBuckets) { if (currentBuckets === void 0) { currentBuckets = []; } this.currentBuckets = currentBuckets; }; OneDChartStyleService.prototype.setCurrentMetrics = function (currentMetrics) { this.currentMetrics = currentMetrics; }; OneDChartStyleService.prototype.setUnit = function (unit) { this.unit = unit; }; OneDChartStyleService.prototype.getOptions = function () { return { chartType: this.chartType, currentMetrics: this.currentMetrics, currentBuckets: this.currentBuckets, unit: this.unit, precision: this.precision, displayColors: this.displayColors }; }; Object.defineProperty(OneDChartStyleService.prototype, "contextOption", { get: function () { return __assign(__assign({}, this.getOptions()), { metrics: this.currentMetrics, buckets: this.currentBuckets }); }, enumerable: false, configurable: true }); __decorate([ base_1.styleOption(), __metadata("design:type", Array) ], OneDChartStyleService.prototype, "currentBuckets", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Array) ], OneDChartStyleService.prototype, "currentMetrics", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Array) ], OneDChartStyleService.prototype, "unit", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Number) ], OneDChartStyleService.prototype, "precision", void 0); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], OneDChartStyleService.prototype, "unitTransformer", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], OneDChartStyleService.prototype, "setPrecision", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], OneDChartStyleService.prototype, "setCurrentBuckets", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], OneDChartStyleService.prototype, "setCurrentMetrics", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], OneDChartStyleService.prototype, "setUnit", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], OneDChartStyleService.prototype, "contextOption", null); return OneDChartStyleService; }(base_1.default)); exports.default = OneDChartStyleService;