UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

191 lines (190 loc) 9.4 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 store_1 = __importDefault(require("../../BarChart/store")); var transform_1 = require("../../LineChart/transform"); var transform_2 = require("./transform"); var LineBarChartStore = /** @class */ (function (_super) { __extends(LineBarChartStore, _super); function LineBarChartStore() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(LineBarChartStore.prototype, "showingSeries", { get: function () { var currentMetrics = this.chartStyleService.crossAxis1.fields; var series = this.notFormatSeries.series || []; var currentMetricNames = currentMetrics; return series.filter(function (e) { // 柱状图只渲染当前指标中选中的值 return lodash_1.includes(currentMetricNames, e.metricName); }); }, enumerable: false, configurable: true }); Object.defineProperty(LineBarChartStore.prototype, "notFormatSeries", { get: function () { var _a = this.chartStyleService, _b = _a.crossAxis1, y1Scale = _b.scale, yEmptyValueMode = _b.yEmptyValueMode, isCompareEnable = _a.compare.isCompareEnable, stack = _a.stack; var data = this.baseSeries; var data2 = this.independentLineSeries; var barSeries = transform_2.toBarSeries(data); var lineSeries = transform_1.toOverlapLineSeries(data2, yEmptyValueMode === "0" /* Zero */); if (y1Scale === "log" /* Log */) { this.processSeriesForLog(barSeries); 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(LineBarChartStore.prototype, "series", { get: function () { var _this = this; var _a = this.chartStyleService, _b = _a.crossAxis1, currentMetrics = _b.fields, unitTransformer = _b.unitTransformer, y1EmptyValueMode = _b.yEmptyValueMode, showBarLabel = _a.showBarLabel, baseLine = _a.baseLine, useCrossAxis2 = _a.useCrossAxis2, chartType = _a.chartType, mainAxis = _a.mainAxis, colorMode = _a.colorMode; var lineThemeOption = lodash_1.get(this.themeOption, 'line'); var series = this.notFormatSeries.series || []; var currentMetricNames = currentMetrics; var showingSeries = series.filter(function (e) { if (e.isOverlap) { // 非柱状图允许渲染,例如叠加折线 return true; } // 柱状图只渲染当前指标中选中的值 return lodash_1.includes(currentMetricNames, e.metricName); }); var themeColors = lodash_1.get(this.themeOption, 'color'); var typeColors = lodash_1.get(this.themeOption, ['bar', 'color']); var colorModeColors = lodash_1.get(LegendColorPanel_1.colorMap, colorMode); var defaultColors = colorModeColors || typeColors || themeColors; showingSeries.forEach(function (sery, index) { var displayColor = lodash_1.find(_this.chartStyleService.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['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.getBaseLineSeries(baseLine, this.chartContainerService.chartConditionService.originDataset, lodash_1.get(this.themeOption, ['bar', 'thresholdColor']), chartType, mainAxis.field, y1EmptyValueMode === "0" /* Zero */, mainAxis.type === "time" /* Time */), numberSeries = _c.numberSeries, dynamicSeries = _c.dynamicSeries; transform_1.updateSeriesDataByBound(showingSeries, baseLine, dynamicSeries, function (data, matchLine) { return __assign(__assign({}, data), { itemStyle: { color: matchLine.color } }); }); return __spread(showingSeries, [numberSeries], dynamicSeries); } return __spread(showingSeries); }, enumerable: false, configurable: true }); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarChartStore.prototype, "showingSeries", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarChartStore.prototype, "notFormatSeries", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], LineBarChartStore.prototype, "series", null); return LineBarChartStore; }(store_1.default)); exports.default = LineBarChartStore;