@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
163 lines (162 loc) • 6.89 kB
JavaScript
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 __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 { action, computed } from 'mobx';
import { utils } from '@qn-pandora/app-sdk';
import bind from '../../../../utils/bind';
import { isUndefined } from 'lodash';
import ChartStyleService, { styleOption } from './base';
var getUnitTransformer = 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 = 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([
styleOption(),
__metadata("design:type", Array)
], OneDChartStyleService.prototype, "currentBuckets", void 0);
__decorate([
styleOption(),
__metadata("design:type", Array)
], OneDChartStyleService.prototype, "currentMetrics", void 0);
__decorate([
styleOption(),
__metadata("design:type", Array)
], OneDChartStyleService.prototype, "unit", void 0);
__decorate([
styleOption(),
__metadata("design:type", Number)
], OneDChartStyleService.prototype, "precision", void 0);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], OneDChartStyleService.prototype, "unitTransformer", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", void 0)
], OneDChartStyleService.prototype, "setPrecision", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], OneDChartStyleService.prototype, "setCurrentBuckets", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], OneDChartStyleService.prototype, "setCurrentMetrics", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], OneDChartStyleService.prototype, "setUnit", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], OneDChartStyleService.prototype, "contextOption", null);
return OneDChartStyleService;
}(ChartStyleService));
export default OneDChartStyleService;