UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

303 lines (302 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 { isUndefined } from 'lodash'; import { computed, action } from 'mobx'; import { utils } from '@qn-pandora/app-sdk'; import bind from '../../../../../utils/bind'; import { ChartType, BubbleChartDefaultSettings, ESizeType } from '../../../../../constants/chart-style'; import { styleOption } from '../base'; import TwoDChartStyleService from '../two-d'; import TwoDLegend from '../../components/two-d-legend'; import { getFirstUsefulField, getFirstUsefulBucket, getFirstUsefulMetric } from '../scatter/scatter'; var getUnitTransformer = utils.unit.getUnitTransformer; var BubbleChartStyleService = /** @class */ (function (_super) { __extends(BubbleChartStyleService, _super); function BubbleChartStyleService(option) { var _this = _super.call(this, option) || this; // 图表类型 _this.chartType = ChartType.Bubble; // 气泡最小半径 _this.minSize = BubbleChartDefaultSettings.min; // 气泡最大半径 _this.maxSize = BubbleChartDefaultSettings.max; // 高亮阀值 _this.threshold = 0; // 零值显示 _this.showZero = "off" /* Off */; // 大小字段 _this.sizeType = ESizeType.Dynamic; _this.sizeField = []; // 单位 _this.unit = ['none', 'short']; // 数值精度 _this.precision = 2; _this.maxSize = option.maxSize; _this.minSize = option.minSize; _this.minDiameter = option.minDiameter; _this.maxDiameter = option.maxDiameter; _this.threshold = option.threshold; _this.showZero = option.showZero; _this.sizeType = option.sizeType; _this.sizeField = option.sizeField; _this.unit = option.unit; _this.precision = isUndefined(option.precision) ? 2 : option.precision; // 重置图例,散点图不显示值,并且不显示基线 _this.legend = new TwoDLegend(__assign(__assign({}, option.legend), { legendDisplayMode: [], hideBaseLineLegend: true })); return _this; } Object.defineProperty(BubbleChartStyleService.prototype, "unitTransformer", { get: function () { var precision = this.precision; if (this.unit) { var currentUnit_1 = this.unit[1]; return function (value) { return getUnitTransformer(currentUnit_1)(value, precision); }; } return function (value) { return getUnitTransformer('short')(value, precision); }; }, enumerable: false, configurable: true }); BubbleChartStyleService.prototype.getOptions = function () { return __assign(__assign({}, _super.prototype.getOptions.call(this)), { minSize: this.minSize, maxSize: this.maxSize, minDiameter: this.minDiameter, maxDiameter: this.maxDiameter, threshold: this.threshold, showZero: this.showZero, sizeType: this.sizeType, sizeField: this.sizeField, unit: this.unit, precision: this.precision }); }; BubbleChartStyleService.prototype.setPrecision = function (precision) { this.precision = precision; }; BubbleChartStyleService.prototype.setMinSize = function (minSize) { this.minSize = minSize; }; BubbleChartStyleService.prototype.setMaxSize = function (maxSize) { this.maxSize = maxSize; }; BubbleChartStyleService.prototype.setMinDiameter = function (minDiameter) { this.minDiameter = minDiameter; }; BubbleChartStyleService.prototype.setMaxDiameter = function (maxDiameter) { this.maxDiameter = maxDiameter; }; BubbleChartStyleService.prototype.setThreshold = function (threshold) { this.threshold = threshold; }; BubbleChartStyleService.prototype.setSizeField = function (sizeField) { this.sizeField = sizeField; }; BubbleChartStyleService.prototype.setSizeType = function (sizeType) { this.sizeType = sizeType; }; BubbleChartStyleService.prototype.setShowZero = function (showZero) { this.showZero = showZero; }; BubbleChartStyleService.prototype.setUnit = function (unit) { this.unit = unit; }; BubbleChartStyleService.getChartInitStyle = getChartInitStyle; __decorate([ styleOption(), __metadata("design:type", Number) ], BubbleChartStyleService.prototype, "minSize", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], BubbleChartStyleService.prototype, "minDiameter", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], BubbleChartStyleService.prototype, "maxSize", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], BubbleChartStyleService.prototype, "maxDiameter", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], BubbleChartStyleService.prototype, "threshold", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], BubbleChartStyleService.prototype, "showZero", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], BubbleChartStyleService.prototype, "sizeType", void 0); __decorate([ styleOption(), __metadata("design:type", Array) ], BubbleChartStyleService.prototype, "sizeField", void 0); __decorate([ styleOption(), __metadata("design:type", Array) ], BubbleChartStyleService.prototype, "unit", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], BubbleChartStyleService.prototype, "precision", void 0); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BubbleChartStyleService.prototype, "unitTransformer", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setPrecision", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setMinSize", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setMaxSize", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setMinDiameter", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setMaxDiameter", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setThreshold", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setSizeField", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setSizeType", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setShowZero", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], BubbleChartStyleService.prototype, "setUnit", null); return BubbleChartStyleService; }(TwoDChartStyleService)); export default BubbleChartStyleService; export function getChartInitStyle(option, initFirst) { if (initFirst === void 0) { initFirst = true; } var metrics = option.metrics, buckets = option.buckets; var copyedBuckets = __spread(buckets); var copyedMetrics = __spread(metrics); var mainAxisField = getFirstUsefulField(copyedBuckets, copyedMetrics); var crossAxisField = getFirstUsefulField(copyedBuckets, copyedMetrics); var colorAxisField = getFirstUsefulBucket(copyedBuckets); var sizeField = getFirstUsefulMetric(copyedMetrics); var newOption = { minSize: BubbleChartDefaultSettings.min, maxSize: BubbleChartDefaultSettings.max, minDiameter: undefined, maxDiameter: undefined, sizeType: ESizeType.Dynamic, threshold: 0, showZero: "off" /* Off */, sizeField: sizeField ? [sizeField] : [], unit: ['none', 'short'], precision: 2, colors: { fields: colorAxisField ? [colorAxisField] : [] }, mainAxis: { name: '', nameMode: "on" /* On */, labelShowMode: "showauto" /* ShowAuto */, labelRotation: "0" /* Zero */, field: mainAxisField, unit: ['none', 'short'], precision: 2 }, crossAxis1: { name: '', nameMode: "on" /* On */, fields: crossAxisField ? [crossAxisField] : [], scale: "value" /* Value */, yEmptyValueMode: "gap" /* Gap */ } }; return initFirst ? __assign(__assign({}, newOption), option) : __assign(__assign({}, option), newOption); }