UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

336 lines (335 loc) 16.2 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 __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 __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 lodash_1 = require("lodash"); var app_sdk_1 = require("@qn-pandora/app-sdk"); var one_d_1 = __importDefault(require("../stores/one-d")); var normalizeTimeFormat_1 = require("../../../utils/normalizeTimeFormat"); var bind_1 = __importDefault(require("../../../utils/bind")); var chart_drill_down_1 = require("../../../services/chart-drill-down"); var metric_panel_style_1 = require("../../../constants/metric-panel-style"); var getUnitTransformer = app_sdk_1.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 = lodash_1.get(this.themeOption, 'statusPanel'); var fontSize = titleFontSize || metric_panel_style_1.defaultProperty.titleFontSize; var titleHeight = titleFontSize ? titleFontSize * 1.6 + 'px' : lodash_1.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 === metric_panel_style_1.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 = lodash_1.get(this.themeOption, 'statusPanel'); var borderStyle = lodash_1.get(statusPanelOpt, ['borderStyle']); return { borderColor: borderStyle.color, borderRadius: borderStyle.radius, borderWidth: borderStyle.width, width: width || metric_panel_style_1.defaultProperty.width, height: height || metric_panel_style_1.defaultProperty.height }; }, enumerable: false, configurable: true }); Object.defineProperty(MetricPanelChartStore.prototype, "contentStyle", { get: function () { var metricStyles = this.chartStyleService.metricStyles; var statusPanelOpt = lodash_1.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: lodash_1.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 lodash_1.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 lodash_1.findIndex(fields, function (f) { return f.key === b; }); }) .filter(function (num) { return num !== -1; }); var metricIndexs = currentMetrics .map(function (m) { return lodash_1.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_1.normalizeTimeFormat(value); } // 如果是数值类型并且有单位 if (lodash_1.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 lodash_1.isNumber(sourceValue) && item.value >= sourceValue; }); valueColor = lodash_1.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 = lodash_1.get(threshold, 'color', ''); } } var contentStyle = lodash_1.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_1.normalizeTimeFormat(value); } var titleIcon = open ? (color === null || color === void 0 ? void 0 : color.type) === metric_panel_style_1.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 === metric_panel_style_1.ETitleIconColor.System ? (_b = titles.find(function (title) { return title.field === value; })) === null || _b === void 0 ? void 0 : _b.color : lodash_1.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 }, chart_drill_down_1.StatusPanelDrillDownService); }; __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Number]), __metadata("design:returntype", void 0) ], MetricPanelChartStore.prototype, "transfromValue", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "chunkSize", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "carouselSpeed", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "autoplay", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "titleStyle", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "showBackgroundColor", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "panelStyle", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "contentStyle", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "data", null); __decorate([ mobx_1.computed, __metadata("design:type", Array), __metadata("design:paramtypes", []) ], MetricPanelChartStore.prototype, "series", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MetricPanelChartStore.prototype, "handleDrillDown", null); return MetricPanelChartStore; }(one_d_1.default)); exports.default = MetricPanelChartStore;