UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

224 lines (223 loc) 11 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 __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; }; 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 LegendColorPanel_1 = require("@qn-pandora/pandora-app-component/es/components/LegendColorPanel"); var bind_1 = __importDefault(require("../../../../utils/bind")); var store_1 = __importDefault(require("../../BarChart/store")); var transform_1 = require("../../LineChart/transform"); var transform_2 = require("../../BarChart/transform"); var LineBarY2ChartStore = /** @class */ (function (_super) { __extends(LineBarY2ChartStore, _super); function LineBarY2ChartStore() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(LineBarY2ChartStore.prototype, "showingSeries", { get: function () { var currentMetrics = this.chartStyleService.crossAxis1.fields; var series = this.notFormatSeries.series || []; var currentMetricNames = currentMetrics; return series.filter(function (e) { if (e.isOverlap) { // 非柱状图的所有metrics允许渲染,例如叠加折线 return true; } // 柱状图只渲染当前指标中选中的值(metric) return lodash_1.includes(currentMetricNames, e.metricName); }); }, enumerable: false, configurable: true }); Object.defineProperty(LineBarY2ChartStore.prototype, "barCrossAxis2Options", { get: function () { return this.crossAxis2Options; }, enumerable: false, configurable: true }); LineBarY2ChartStore.prototype.getOptions = function () { var currentLineMetrics = this.chartStyleService.crossAxis2.fields; var crossAxisOptions = __spread([ this.barCrossAxis1Options ], (currentLineMetrics.length > 0 ? [this.barCrossAxis2Options] : [])); var baseBarOption = _super.prototype.getOptions.call(this); var option = __assign(__assign({}, baseBarOption), { yAxis: crossAxisOptions }); return option; }; Object.defineProperty(LineBarY2ChartStore.prototype, "notFormatSeries", { get: function () { var _a = this.chartStyleService, y1Scale = _a.crossAxis1.scale, _b = _a.crossAxis2, y2EmptyValueMode = _b.yEmptyValueMode, y2Scale = _b.scale, isCompareEnable = _a.compare.isCompareEnable, stack = _a.stack; var data = this.baseSeries; var data2 = this.overlapLineSeries; var barSeries = transform_2.toBarSeries(data); var lineSeries = transform_1.toOverlapLineSeries(data2, y2EmptyValueMode === "0" /* Zero */); if (y1Scale === "log" /* Log */) { this.processSeriesForLog(barSeries); } if (y2Scale === "log" /* Log */) { this.processSeriesForLog(lineSeries); } if (stack) { barSeries.forEach(function (sery, index) { // 设置堆叠模式 if (isCompareEnable) { sery['stack'] = index % 2 === 0 ? 'current' : 'compare'; } else { sery['stack'] = 'stacked'; } }); } var series = __spread(barSeries, lineSeries); return { series: series }; }, enumerable: false, configurable: true }); Object.defineProperty(LineBarY2ChartStore.prototype, "series", { get: function () { var _this = this; var _a = this.chartStyleService, unitTransformer = _a.crossAxis1.unitTransformer, showBarLabel = _a.showBarLabel, baseLine = _a.baseLine, useCrossAxis2 = _a.useCrossAxis2, _b = _a.mainAxis, field = _b.field, type = _b.type, y1EmptyValueMode = _a.crossAxis1.yEmptyValueMode, y2EmptyValueMode = _a.crossAxis2.yEmptyValueMode, colorMode = _a.colorMode; var lineThemeOption = lodash_1.get(this.themeOption, 'line'); var showingSeries = this.showingSeries; var themeColors = lodash_1.get(this.themeOption, 'color'); var typeColors = lodash_1.get(this.themeOption, ['bar', 'color']) || []; var displayColors = this.chartStyleService.displayColors; var colorModeColors = lodash_1.get(LegendColorPanel_1.colorMap, colorMode); var defaultColors = colorModeColors || typeColors || themeColors; showingSeries.forEach(function (sery, index) { // 设置颜色 var displayColor = lodash_1.find(displayColors, function (displayColor) { return displayColor.name === sery.name; }); sery['itemStyle'] = { normal: { color: displayColor ? displayColor.color : defaultColors[index % defaultColors.length] } }; if (sery.type === 'line') { _this.handleLineSeries(sery, lineThemeOption, useCrossAxis2); } else if (sery.type === 'bar') { // 设置label var labelPosition = showBarLabel === true ? 'inside' : showBarLabel; sery['showSymbol'] = showBarLabel; sery['label'] = { position: labelPosition, distance: 0, show: !!showBarLabel, color: labelPosition === 'inside' ? '#fff' : 'inherit', formatter: function (params) { return unitTransformer(params.value); } }; // 设置柱状图最大宽度 sery['barMaxWidth'] = 40; //设置鼠标样式 sery['cursor'] = _this.chartCanClick ? 'pointer' : 'default'; sery['silent'] = _this.chartCanClick ? false : true; } }); if (baseLine.length) { var _c = transform_1.getBaseLineBar2Series(baseLine, this.chartContainerService.chartConditionService.originDataset, lodash_1.get(this.themeOption, ['bar', 'thresholdColor']), field, y1EmptyValueMode === "0" /* Zero */, y2EmptyValueMode === "0" /* Zero */, type === "time" /* Time */), numberRightSeries = _c.numberRightSeries, numberLeftSeries = _c.numberLeftSeries, dynamicSeries = _c.dynamicSeries; transform_1.updateSeriesDataByBound(showingSeries, baseLine, dynamicSeries, function (data, matchLine) { return __assign(__assign({}, data), { itemStyle: { color: matchLine.color } }); }); var currentLineMetrics = this.chartStyleService.crossAxis2.fields; return currentLineMetrics.length > 0 ? __spread(showingSeries, [ numberLeftSeries, numberRightSeries ], dynamicSeries) : __spread(showingSeries, [numberLeftSeries], dynamicSeries); } return __spread(showingSeries); }, enumerable: false, configurable: true }); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarY2ChartStore.prototype, "showingSeries", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarY2ChartStore.prototype, "barCrossAxis2Options", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LineBarY2ChartStore.prototype, "getOptions", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarY2ChartStore.prototype, "notFormatSeries", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarY2ChartStore.prototype, "series", null); return LineBarY2ChartStore; }(store_1.default)); exports.default = LineBarY2ChartStore;