UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

157 lines (156 loc) 6.47 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 __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 { action, toJS } from 'mobx'; import { isArray, values } from 'lodash'; import { EColorMode } from '@qn-pandora/pandora-app-component'; import bind from '../../../../../utils/bind'; import { InitOneDLegend } from '../../../../../constants/legend-style'; import OneDLegend from '../../components/one-d-legend'; import OneDChartStyleService from '../one-d'; import { styleOption } from '../base'; var PieBaseStyleService = /** @class */ (function (_super) { __extends(PieBaseStyleService, _super); function PieBaseStyleService(chart) { var _this = _super.call(this, chart) || this; _this.legend = new OneDLegend(InitOneDLegend); // 最大区域数量 _this.maxSlices = [20]; // 标签显示 _this.labelTypes = []; _this.colorMode = EColorMode.Classical; _this.tooltipAppendToBody = true; _this.maxSlices = isArray(chart.maxSlices) ? chart.maxSlices : chart.maxSlices ? [chart.maxSlices] : [20]; _this.legend = new OneDLegend(chart.legend || InitOneDLegend); _this.labelTypes = chart.labelTypes || []; // 注意: 单值图的mode 与饼图的类型不一致,切换时候需要兼容 _this.colorMode = chart.colorMode ? values(EColorMode).includes(chart.colorMode) ? chart.colorMode : EColorMode.Classical : EColorMode.Classical; _this.tooltipAppendToBody = chart.tooltipAppendToBody === false ? false : true; return _this; } PieBaseStyleService.prototype.getOptions = function () { return { chartType: this.chartType, legend: this.legend.option, currentMetrics: this.currentMetrics, currentBuckets: this.currentBuckets, unit: this.unit, precision: this.precision, maxSlices: toJS(this.maxSlices), displayColors: this.displayColors, sectorOffset: this.sectorOffset, labelTypes: this.labelTypes, colorMode: this.colorMode, tooltipAppendToBody: this.tooltipAppendToBody }; }; PieBaseStyleService.prototype.setMaxSlices = function (maxSlices) { this.maxSlices = maxSlices; }; PieBaseStyleService.prototype.setSectorOffset = function (sectorOffset) { this.sectorOffset = sectorOffset; }; PieBaseStyleService.prototype.setLabelTypes = function (labelTypes) { this.labelTypes = labelTypes; }; PieBaseStyleService.prototype.setColorMode = function (colorMode) { this.colorMode = colorMode; }; PieBaseStyleService.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; this.executeFieldHandlers(obj, [ { field: 'legend', handler: function (legend) { _this.legend.set(legend); } } ], allowNil); }; __decorate([ styleOption(), __metadata("design:type", Array) ], PieBaseStyleService.prototype, "maxSlices", void 0); __decorate([ styleOption(), __metadata("design:type", Array) ], PieBaseStyleService.prototype, "labelTypes", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], PieBaseStyleService.prototype, "colorMode", void 0); __decorate([ styleOption(), __metadata("design:type", Boolean) ], PieBaseStyleService.prototype, "tooltipAppendToBody", void 0); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], PieBaseStyleService.prototype, "setMaxSlices", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], PieBaseStyleService.prototype, "setSectorOffset", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], PieBaseStyleService.prototype, "setLabelTypes", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], PieBaseStyleService.prototype, "setColorMode", null); __decorate([ action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], PieBaseStyleService.prototype, "set", null); return PieBaseStyleService; }(OneDChartStyleService)); export default PieBaseStyleService;