UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

311 lines (310 loc) 12.5 kB
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; }; import { computed, action } from 'mobx'; import { values } from 'lodash'; import { EColorMode } from '@qn-pandora/pandora-app-component'; import bind from '../../../../utils/bind'; import { InitLineDataConfig, ETooltipType } from '../../../../constants/chart-style'; import Compare from '../components/compare'; import MainAxis from '../components/main-axis'; import CrossAxis from '../components/cross-axis'; import CrossAxis2 from '../components/cross-axis-2'; import TwoDLegend from '../components/two-d-legend'; import Colors from '../components/colors-style'; import ChartStyleService, { styleOption } from './base'; var TwoDChartStyleService = /** @class */ (function (_super) { __extends(TwoDChartStyleService, _super); function TwoDChartStyleService(option) { var _this = _super.call(this, option) || this; // 是否使用右y轴 _this.useCrossAxis2 = false; // 基线 _this.baseLine = []; // 基线列表 _this.colorMode = EColorMode.Classical; _this.showToolBox = false; _this.tooltipType = ETooltipType.NumberDesc; _this.tooltipAppendToBody = true; _this.mainAxis = new MainAxis(option.mainAxis || {}); _this.crossAxis1 = new CrossAxis(option.crossAxis1 || {}); _this.crossAxis2 = new CrossAxis2(option.crossAxis2 || {}); _this.legend = new TwoDLegend(option.legend || { position: "top" /* Top */, width: undefined, height: 0, legendDisplayMode: [] }); _this.colors = new Colors(option.colors || {}); // 注意: 单值图的mode 与二维图表的类型不一致,切换时候需要兼容 _this.colorMode = option.colorMode ? values(EColorMode).includes(option.colorMode) ? option.colorMode : EColorMode.Classical : EColorMode.Classical; _this.compare = new Compare(option.compare || { method: "none" /* None */ }); _this.baseLine = option.baseLine || []; _this.displayColors = option.displayColors || []; _this.showToolBox = option.showToolBox || false; _this.tooltipType = option.tooltipType || ETooltipType.NumberDesc; _this.tooltipAppendToBody = option.tooltipAppendToBody === false ? false : true; _this.markLine = option.markLine; return _this; } TwoDChartStyleService.prototype.getOptions = function () { return { chartType: this.chartType, mainAxis: this.mainAxis.option, crossAxis1: this.crossAxis1.option, crossAxis2: this.crossAxis2.option, legend: this.legend.option, colors: this.colors.option, colorMode: this.colorMode, compare: this.compare.option, baseLine: this.baseLine, displayColors: this.displayColors, showToolBox: this.showToolBox, tooltipType: this.tooltipType, tooltipAppendToBody: this.tooltipAppendToBody, markLine: this.markLine }; }; Object.defineProperty(TwoDChartStyleService.prototype, "contextOption", { get: function () { var buckets = this.mainAxis.field.length ? __spread([this.mainAxis.field], this.colors.fields) : __spread(this.colors.fields); var metrics = __spread(this.crossAxis1.fields, (this.useCrossAxis2 ? this.crossAxis2.fields : '')); return __assign(__assign({}, this.getOptions()), { // 由于部分二维图表未开放下面的GUI配置,故上下文Option中用默认值替代 legend: this.legend.contextOption, metrics: metrics, buckets: buckets }); }, enumerable: false, configurable: true }); TwoDChartStyleService.prototype.setBaseLine = function (baseLine) { this.baseLine = baseLine; }; TwoDChartStyleService.prototype.setColorMode = function (colorMode) { this.colorMode = colorMode; }; TwoDChartStyleService.prototype.setShowToolBox = function (showToolBox) { this.showToolBox = showToolBox; }; TwoDChartStyleService.prototype.setTooltipType = function (tooltipType) { this.tooltipType = tooltipType; }; TwoDChartStyleService.prototype.setMarkLine = function (markLine) { this.markLine = markLine; }; TwoDChartStyleService.prototype.set = function (key, value) { var _this = this; _super.prototype.set.call(this, key, value); if (typeof key !== 'object') { return; } var allowNil = !!value; var obj = key; var fieldHandlers = __spread([ { field: 'mainAxis', handler: function (mainAxis) { _this.mainAxis.set(mainAxis); } }, { field: 'crossAxis1', handler: function (crossAxis1) { _this.crossAxis1.set(crossAxis1); } }, { field: 'legend', handler: function (legend) { _this.legend.set(legend); } }, { field: 'colors', handler: function (colors) { _this.colors.set(colors); } }, { field: 'compare', handler: function (compare) { _this.compare.set(compare); } } ], (this.useCrossAxis2 ? [ { field: 'crossAxis2', handler: function (crossAxis2) { _this.crossAxis2.set(crossAxis2); } } ] : [])); this.executeFieldHandlers(obj, fieldHandlers, allowNil); }; TwoDChartStyleService.getChartInitStyle = getChartInitStyle; __decorate([ styleOption(), __metadata("design:type", Array) ], TwoDChartStyleService.prototype, "baseLine", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], TwoDChartStyleService.prototype, "colorMode", void 0); __decorate([ styleOption(), __metadata("design:type", Boolean) ], TwoDChartStyleService.prototype, "showToolBox", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], TwoDChartStyleService.prototype, "tooltipType", void 0); __decorate([ styleOption(), __metadata("design:type", Boolean) ], TwoDChartStyleService.prototype, "tooltipAppendToBody", void 0); __decorate([ styleOption(), __metadata("design:type", Object) ], TwoDChartStyleService.prototype, "markLine", void 0); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TwoDChartStyleService.prototype, "contextOption", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TwoDChartStyleService.prototype, "setBaseLine", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TwoDChartStyleService.prototype, "setColorMode", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TwoDChartStyleService.prototype, "setShowToolBox", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TwoDChartStyleService.prototype, "setTooltipType", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TwoDChartStyleService.prototype, "setMarkLine", null); __decorate([ action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], TwoDChartStyleService.prototype, "set", null); return TwoDChartStyleService; }(ChartStyleService)); export default TwoDChartStyleService; export function getChartInitStyle(option, initFirst, useCrossAxis2) { if (initFirst === void 0) { initFirst = true; } if (useCrossAxis2 === void 0) { useCrossAxis2 = false; } var buckets = option.buckets, metrics = option.metrics; var newOption = __assign({ // color 最多支持三个 colors: { fields: buckets.length > 1 ? buckets.slice(1, 4) : [] }, mainAxis: { name: '', nameMode: "on" /* On */, labelShowMode: "showauto" /* ShowAuto */, labelRotation: "0" /* Zero */, field: buckets.length ? buckets[0] : '', unit: ['none', 'short'] }, crossAxis1: { name: '', nameMode: "on" /* On */, fields: metrics || [], scale: "value" /* Value */, yEmptyValueMode: "gap" /* Gap */, lineDataConfig: InitLineDataConfig } }, (useCrossAxis2 ? { crossAxis2: { name: '', nameMode: "on" /* On */, fields: [], scale: "value" /* Value */, yEmptyValueMode: "gap" /* Gap */, y2Buckets: [] } } : {})); return initFirst ? __assign(__assign({}, newOption), option) : __assign(__assign({}, option), newOption); }