@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
280 lines (279 loc) • 11 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 { get, merge, isNumber } from 'lodash';
import bind from '../../../../utils/bind';
import { SeverityColor, ESingleValueTrendMode } from '../../../../constants/single-style';
import { colorRgba } from '../../../../components/Charts/transforms/color';
import { getColor } from '../transform';
import SingleChartStore from '../store';
import { defaultConfig } from '../constant';
import { lineColors } from './constant';
var SingleValueStore = /** @class */ (function (_super) {
__extends(SingleValueStore, _super);
function SingleValueStore() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(SingleValueStore.prototype, "isShowWhiteColor", {
// 字体相关颜色是否展示为白色
get: function () {
return this.chartStyleOption.colorMode === "background" /* BackGround */;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "showTrend", {
get: function () {
return this.chartStyleOption.trendMode !== ESingleValueTrendMode.None;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "color", {
get: function () {
return getColor(this.defaultColor, this.chartStyleOption, this.colorData);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "chartBackgroundColors", {
// 单值图背景颜色
get: function () {
var colorMode = this.chartStyleOption.colorMode;
if (colorMode === "value" /* Value */) {
return get(this.themeOption, ['gauge', 'singleValue', 'backgroundColors']);
}
return this.color;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "chartColors", {
// 单值图颜色
get: function () {
var colorMode = this.chartStyleOption.colorMode;
if (colorMode === "background" /* BackGround */) {
return SeverityColor.whiteColor;
}
return this.color;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "showTrendData", {
get: function () {
var data = this.getData();
// 趋势图不需要都是数值, 如果存在非数值, 线条中间截断即可
return data.length > 1;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "series", {
get: function () {
var data = this.getData();
return this.toLineSeries(data || []);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "options", {
get: function () {
return merge({}, defaultConfig, {
legend: { show: false },
series: this.series,
grid: __assign({}, defaultConfig.grid)
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "areaStyle", {
get: function () {
return {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: this.isShowWhiteColor
? lineColors.inverseColor
: colorRgba(get(this.themeOption, ['bar', 'color', 0]) ||
get(this.themeOption, ['color', 0]), 0.2) // 0% 处的颜色
},
{
offset: 1,
color: this.isShowWhiteColor
? this.chartBackgroundColors
: lineColors.endColor // 100% 处的颜色
}
]
},
opacity: 1
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(SingleValueStore.prototype, "baseSeries", {
// 线图series配置
get: function () {
var trendMode = this.chartStyleOption.trendMode;
var type = trendMode === ESingleValueTrendMode.Area
? ESingleValueTrendMode.Line
: trendMode;
if (trendMode === ESingleValueTrendMode.Area) {
return {
smooth: true,
type: type,
showSymbol: false,
areaStyle: this.areaStyle
};
}
return {
smooth: true,
type: type,
showSymbol: false
};
},
enumerable: false,
configurable: true
});
SingleValueStore.prototype.toLineSeries = function (data) {
var singleLineSeries = this.showTrend
? [
__assign(__assign({}, this.baseSeries), { itemStyle: {
normal: {
lineStyle: {
color: this.isShowWhiteColor
? lineColors.inverseColor
: get(this.themeOption, ['bar', 'color', 0]) ||
get(this.themeOption, ['color', 0])
},
color: get(this.themeOption, ['line', 'color', 0]) ||
get(this.themeOption, ['color', 0])
}
}, data: data.reverse(), barMaxWidth: 40 })
]
: [];
return singleLineSeries;
};
Object.defineProperty(SingleValueStore.prototype, "hasVertical", {
get: function () {
var _a = this.chartStyleService, suffix = _a.suffix, prefix = _a.prefix;
return (suffix.font.layout === "vertical" /* Vertical */ ||
prefix.font.layout === "vertical" /* Vertical */);
},
enumerable: false,
configurable: true
});
SingleValueStore.prototype.isNumberData = function (data) {
return data.every(function (item) {
return isNumber(item);
});
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "isShowWhiteColor", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "showTrend", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "color", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "chartBackgroundColors", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "chartColors", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "showTrendData", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "series", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "options", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "areaStyle", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "baseSeries", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], SingleValueStore.prototype, "toLineSeries", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleValueStore.prototype, "hasVertical", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array]),
__metadata("design:returntype", void 0)
], SingleValueStore.prototype, "isNumberData", null);
return SingleValueStore;
}(SingleChartStore));
export default SingleValueStore;