@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
331 lines (330 loc) • 15.6 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 { computed } from 'mobx';
import { findIndex, isNumber, get, isUndefined } from 'lodash';
import { utils } from '@qn-pandora/app-sdk';
import OneDChartStore from '../stores/one-d';
import { normalizeTimeFormat } from '../../../utils/normalizeTimeFormat';
import bind from '../../../utils/bind';
import { StatusPanelDrillDownService } from '../../../services/chart-drill-down';
import { defaultProperty, EColorMode, ETitleIconColor } from '../../../constants/metric-panel-style';
var getUnitTransformer = utils.unit.getUnitTransformer;
var MetricPanelChartStore = /** @class */ (function (_super) {
__extends(MetricPanelChartStore, _super);
function MetricPanelChartStore() {
return _super !== null && _super.apply(this, arguments) || this;
}
MetricPanelChartStore.prototype.transfromValue = function (value, index) {
var metricDataConfigs = this.chartStyleService.metricDataConfigs;
var dataConfig = metricDataConfigs[index];
var unitTransformer = getUnitTransformer(dataConfig.unit[1]);
return unitTransformer(value || 0, dataConfig.precision);
};
Object.defineProperty(MetricPanelChartStore.prototype, "chunkSize", {
get: function () {
var pageSize = this.chartStyleService.pageSize;
return pageSize * 1 > 0 ? pageSize : Infinity;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "carouselSpeed", {
get: function () {
var autoplaySpeed = this.chartStyleService.autoplaySpeed;
return autoplaySpeed * 1 > 0 ? autoplaySpeed * 1000 : undefined;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "autoplay", {
get: function () {
var pageSize = this.chartStyleService.pageSize;
return pageSize > 0 && this.series.length > pageSize && !!this.carouselSpeed;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "titleStyle", {
get: function () {
var _a = this.chartStyleService, titleFontSize = _a.titleFontSize, titleFontColor = _a.titleFontColor;
var statusPanelOpt = get(this.themeOption, 'statusPanel');
var fontSize = titleFontSize || defaultProperty.titleFontSize;
var titleHeight = titleFontSize
? titleFontSize * 1.6 + 'px'
: get(statusPanelOpt, ['title', 'lineHeight']) + 'px';
return {
fontSize: fontSize,
lineHeight: titleHeight,
height: titleHeight,
color: titleFontColor
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "showBackgroundColor", {
get: function () {
var colorMode = this.chartStyleService.colorMode;
return colorMode === EColorMode.INVERTED;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "panelStyle", {
get: function () {
// width, height, fontsize 在使用时考虑InputNumber导致为空字符的情况
var _a = this.chartStyleService, width = _a.width, height = _a.height;
var statusPanelOpt = get(this.themeOption, 'statusPanel');
var borderStyle = get(statusPanelOpt, ['borderStyle']);
return {
borderColor: borderStyle.color,
borderRadius: borderStyle.radius,
borderWidth: borderStyle.width,
width: width || defaultProperty.width,
height: height || defaultProperty.height
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "contentStyle", {
get: function () {
var metricStyles = this.chartStyleService.metricStyles;
var statusPanelOpt = get(this.themeOption, 'statusPanel');
return metricStyles.map(function (style) {
var _a;
var prefix = style.prefix, suffix = style.suffix, fontSize = style.fontSize;
var prefixStyle = {
fontSize: prefix.font.fontSize,
color: prefix.font.fontColor,
layout: prefix.font.layout,
display: prefix.font.layout === "vertical" /* Vertical */
? 'block'
: 'inline-block'
};
var suffixStyle = {
fontSize: suffix.font.fontSize,
color: suffix.font.fontColor,
layout: suffix.font.layout,
display: suffix.font.layout === "vertical" /* Vertical */
? 'block'
: 'inline-block'
};
var valueStyle = {
fontSize: fontSize || ((_a = statusPanelOpt.itemStyle) === null || _a === void 0 ? void 0 : _a.fontSize)
};
return {
prefix: prefix.value,
suffix: suffix.value,
prefixStyle: prefixStyle,
suffixStyle: suffixStyle,
valueStyle: valueStyle,
showLabel: isUndefined(style.showMetricName)
? true
: style.showMetricName
};
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "data", {
get: function () {
var currentBuckets = this.chartStyleService.currentBuckets;
var _a = this.dataset, fields = _a.fields, rows = _a.rows;
var bucketIndexs = currentBuckets
.map(function (b) { return findIndex(fields, function (f) { return f.key === b; }); })
.filter(function (num) { return num !== -1; });
return bucketIndexs.length === 0 && rows.length > 0 ? [rows[0]] : rows;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MetricPanelChartStore.prototype, "series", {
get: function () {
var _this = this;
var _a = this.chartStyleService, currentBuckets = _a.currentBuckets, currentMetrics = _a.currentMetrics, colors = _a.colors, _b = _a.titleIcon, icon = _b.icon, _c = _b.titles, titles = _c === void 0 ? [] : _c, open = _b.open, color = _b.color, width = _b.width;
var fields = this.dataset.fields;
var bucketIndexs = currentBuckets
.map(function (b) { return findIndex(fields, function (f) { return f.key === b; }); })
.filter(function (num) { return num !== -1; });
var metricIndexs = currentMetrics
.map(function (m) { return findIndex(fields, function (f) { return f.key === m; }); })
.filter(function (num) { return num !== -1; });
var _d = this.originDataset, rows = _d.rows, originFields = _d.fields;
var colorFieldIndex = originFields.findIndex(function (field) { return field.key === color.field; });
var panels = this.data.map(function (item, index) {
var originRow = rows[index];
var contents = metricIndexs.map(function (metricIndex, index) {
var label = fields[metricIndex].key;
var valueColor = '';
var sourceValue = item[metricIndex][0];
var value = item[metricIndex][0];
if (fields[metricIndex].fieldType === 'Time') {
// 将时间转换为显示用的格式
value = normalizeTimeFormat(value);
}
// 如果是数值类型并且有单位
if (isNumber(value)) {
value = _this.transfromValue(value, index);
}
var metricColor = colors.find(function (e) { return e.fieldKey === label; });
if (metricColor) {
// 比较原始数值
if (metricColor.type === 'number') {
var threshold = metricColor.thresholds.find(function (item) { return isNumber(sourceValue) && item.value >= sourceValue; });
valueColor = get(threshold, 'color', '');
}
else {
var threshold = metricColor.thresholds.find(function (threshold) {
return threshold.value.toString() === (sourceValue === null || sourceValue === void 0 ? void 0 : sourceValue.toString());
});
valueColor = get(threshold, 'color', '');
}
}
var contentStyle = get(_this.contentStyle, index) || {
prefix: '',
suffix: '',
prefixStyle: {},
suffixStyle: {},
valueStyle: {},
showLabel: true
};
return __assign({ label: label,
value: value,
valueColor: valueColor }, contentStyle);
});
return {
key: String(index),
titles: bucketIndexs.map(function (index) {
var _a, _b;
var value = item[index][0];
if (fields[index].fieldType === 'Time') {
// 将时间转换为显示用的格式
value = normalizeTimeFormat(value);
}
var titleIcon = open
? (color === null || color === void 0 ? void 0 : color.type) === ETitleIconColor.System
? ((_a = titles.find(function (title) { return title.field === value; })) === null || _a === void 0 ? void 0 : _a.icon) || icon
: icon
: '';
var titleColor = open
? color.type === ETitleIconColor.System
? (_b = titles.find(function (title) { return title.field === value; })) === null || _b === void 0 ? void 0 : _b.color : get(originRow[colorFieldIndex], '0')
: '';
return {
text: String(value),
icon: titleIcon,
color: titleColor,
width: width
};
}),
contents: contents,
originRow: item
};
});
return panels;
},
enumerable: false,
configurable: true
});
MetricPanelChartStore.prototype.handleDrillDown = function (params) {
this.onDrillDown({
titles: params.titles,
contents: params.contents,
currentBuckets: this.chartStyleService.currentBuckets,
fields: this.fields,
originRow: params.originRow
}, StatusPanelDrillDownService);
};
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Number]),
__metadata("design:returntype", void 0)
], MetricPanelChartStore.prototype, "transfromValue", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "chunkSize", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "carouselSpeed", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "autoplay", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "titleStyle", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "showBackgroundColor", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "panelStyle", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "contentStyle", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "data", null);
__decorate([
computed,
__metadata("design:type", Array),
__metadata("design:paramtypes", [])
], MetricPanelChartStore.prototype, "series", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], MetricPanelChartStore.prototype, "handleDrillDown", null);
return MetricPanelChartStore;
}(OneDChartStore));
export default MetricPanelChartStore;