@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
334 lines (333 loc) • 13.9 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);
};
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 } from 'mobx';
import { isUndefined } from 'lodash';
import { InitDataFontStyle, InitDisplayField } from '../../../../../constants/single-style';
import bind from '../../../../../utils/bind';
import { styleOption } from '../base';
import OneDChartStyleService from '../one-d';
/**
* 单值图的通用属性
*/
var SingleBaseStyleService = /** @class */ (function (_super) {
__extends(SingleBaseStyleService, _super);
function SingleBaseStyleService(option) {
var _this = _super.call(this, option) || this;
// 单值图空值模式
_this.gaugeEmptyValueMode = "empty" /* Empty */;
// 最小值设置
_this.gaugeMin = 0;
// 最大值设置
_this.gaugeMax = 100;
// 标题的数值字体
_this.titleDataFont = InitDataFontStyle;
// 当前颜色所用的指标, 默认跟展示指标一样, 仅支持一个单选值
_this.colorMetrics = [];
_this.colorMetricIsNumberic = true;
// 展示字段
_this.displayField = InitDisplayField;
_this.unit = option.unit || ['none', 'short'];
_this.gaugeEmptyValueMode =
option.gaugeEmptyValueMode || "empty" /* Empty */;
_this.titleDataFont = option.titleDataFont || InitDataFontStyle;
_this.displayField = option.displayField || InitDisplayField;
_this.colorMetrics =
option.colorMetrics && option.colorMetrics.length
? option.colorMetrics
: option.currentMetrics;
_this.colorMetricIsNumberic = isUndefined(option.colorMetricIsNumberic)
? true
: option.colorMetricIsNumberic;
return _this;
}
SingleBaseStyleService.prototype.getOptions = function () {
return {
chartType: this.chartType,
unit: this.unit,
precision: this.precision,
currentBuckets: this.currentBuckets,
currentMetrics: this.currentMetrics,
gaugeMin: this.gaugeMin,
gaugeMax: this.gaugeMax,
gaugeSplitters: this.gaugeSplitters,
titleDataFont: this.titleDataFont,
colorMetrics: this.colorMetrics,
colorMetricIsNumberic: this.colorMetricIsNumberic,
displayField: this.displayField,
gaugeEmptyValueMode: this.gaugeEmptyValueMode
};
};
SingleBaseStyleService.prototype.setGaugeEmptyValueMode = function (gaugeEmptyValueMode) {
this.gaugeEmptyValueMode = gaugeEmptyValueMode;
};
SingleBaseStyleService.prototype.setDisplayField = function (displayField) {
this.displayField = displayField;
};
SingleBaseStyleService.prototype.setGaugeMax = function (gaugeMax) {
if ((typeof gaugeMax === 'number' && gaugeMax >= this.gaugeMin) ||
typeof gaugeMax === 'string') {
this.gaugeMax = typeof gaugeMax === 'string' ? Infinity : gaugeMax;
this.gaugeSplitters = this.calcGaugeSplitters(this.gaugeSplitters, this.gaugeMin, this.gaugeMax);
}
};
SingleBaseStyleService.prototype.setGaugeMin = function (gaugeMin) {
if ((typeof gaugeMin === 'number' && gaugeMin <= this.gaugeMax) ||
typeof gaugeMin === 'string') {
this.gaugeMin = typeof gaugeMin === 'string' ? -Infinity : gaugeMin;
this.gaugeSplitters = this.calcGaugeSplitters(this.gaugeSplitters, this.gaugeMin, this.gaugeMax);
}
};
SingleBaseStyleService.prototype.setTitleDataFont = function (titleDataFont) {
this.titleDataFont = titleDataFont;
};
SingleBaseStyleService.prototype.setGaugeSplitters = function (gaugeSplitters) {
this.gaugeSplitters = gaugeSplitters;
var scale = gaugeSplitters.scale;
if (scale) {
var len = scale.length;
var min = len && scale[0].toString() !== '' ? scale[0] : -Infinity;
var max = len && scale[len - 1].toString() !== '' ? scale[len - 1] : Infinity;
this.gaugeMin = min;
this.gaugeMax = max;
}
};
SingleBaseStyleService.prototype.setColorMetrics = function (colorMetrics) {
this.colorMetrics = colorMetrics;
};
// 拦截基类此方法,使colorMetrics跟随currentMetrics改变
SingleBaseStyleService.prototype.setCurrentMetrics = function (currentMetrics) {
this.currentMetrics = currentMetrics;
if (!this.colorMetrics.length) {
this.setColorMetrics(currentMetrics);
}
};
SingleBaseStyleService.prototype.setColorMetricIsNumberic = function (colorMetricIsNumberic) {
this.colorMetricIsNumberic = colorMetricIsNumberic;
if (colorMetricIsNumberic && !this.gaugeSplitters.scale) {
var min = this.gaugeMin;
var max = this.gaugeMax;
var scale = [min === -Infinity ? '' : min, max === Infinity ? '' : max];
this.gaugeSplitters = {
colorPalette: {
type: this.gaugeSplitters.colorPalette.type,
value: []
},
scale: scale
};
}
};
SingleBaseStyleService.prototype.calcGaugeSplitters = function (gaugeSplitters, min, max) {
var scale = gaugeSplitters.scale;
if (scale && scale.length) {
var scaleNew = __spread(scale);
scaleNew[0] = min === -Infinity ? '' : min;
scaleNew[scale.length - 1] = max === Infinity ? '' : max;
return __assign(__assign({}, gaugeSplitters), { scale: scaleNew });
}
return gaugeSplitters;
};
SingleBaseStyleService.prototype.getGaugeBoundWithColorSplitter = function (gaugeSplitters) {
var scale = gaugeSplitters.scale;
if (scale && scale.length) {
return { min: scale[0], max: scale[scale.length - 1] };
}
return { min: -Infinity, max: Infinity };
};
SingleBaseStyleService.prototype.getGaugeMinWithOption = function (option, gaugeSplitters) {
if (option.gaugeMin) {
return option.gaugeMin;
}
var scale = gaugeSplitters.scale;
if (scale && scale.length) {
return scale[0];
}
return -Infinity;
};
SingleBaseStyleService.prototype.getGaugeMaxWithOption = function (option, gaugeSplitters) {
if (option.gaugeMax) {
return option.gaugeMax;
}
var scale = gaugeSplitters.scale;
if (scale && scale.length) {
return scale[scale.length - 1];
}
return Infinity;
};
SingleBaseStyleService.getChartInitStyle = getChartInitStyle;
__decorate([
styleOption(),
__metadata("design:type", String)
], SingleBaseStyleService.prototype, "gaugeEmptyValueMode", void 0);
__decorate([
styleOption(),
__metadata("design:type", Number)
], SingleBaseStyleService.prototype, "gaugeMin", void 0);
__decorate([
styleOption(),
__metadata("design:type", Number)
], SingleBaseStyleService.prototype, "gaugeMax", void 0);
__decorate([
styleOption(),
__metadata("design:type", Object)
], SingleBaseStyleService.prototype, "titleDataFont", void 0);
__decorate([
styleOption(),
__metadata("design:type", Array)
], SingleBaseStyleService.prototype, "colorMetrics", void 0);
__decorate([
styleOption(),
__metadata("design:type", Boolean)
], SingleBaseStyleService.prototype, "colorMetricIsNumberic", void 0);
__decorate([
styleOption(),
__metadata("design:type", Object)
], SingleBaseStyleService.prototype, "displayField", void 0);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setGaugeEmptyValueMode", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setDisplayField", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setGaugeMax", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setGaugeMin", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setTitleDataFont", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setGaugeSplitters", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setColorMetrics", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setCurrentMetrics", null);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Boolean]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "setColorMetricIsNumberic", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Number, Number]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "calcGaugeSplitters", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "getGaugeBoundWithColorSplitter", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "getGaugeMinWithOption", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], SingleBaseStyleService.prototype, "getGaugeMaxWithOption", null);
return SingleBaseStyleService;
}(OneDChartStyleService));
export default SingleBaseStyleService;
export function getChartInitStyle(option, initFirst) {
if (initFirst === void 0) { initFirst = true; }
var newOption = {
currentBuckets: option.buckets,
currentMetrics: option.metrics.slice(0, 1)
};
return initFirst ? __assign(__assign({}, newOption), option) : __assign(__assign({}, option), newOption);
}