UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

224 lines (223 loc) 9.48 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); }; import { computed } from 'mobx'; import { merge, last, isNil, maxBy, first } from 'lodash'; import { mainAxis } from '../defaultChartConfig'; import { DEFAULT_AXIS_NAME_HEIGHT, FORTY_FIVE_DEGREE_RATIO, NAME_LABEL_MARIN } from '../../stores/two-d'; import bind from '../../../../utils/bind'; import { isMobileDevice } from '../../../../utils/env'; import BaseBarChartStore from '../store'; var BaseVerticalsChartStore = /** @class */ (function (_super) { __extends(BaseVerticalsChartStore, _super); function BaseVerticalsChartStore() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(BaseVerticalsChartStore.prototype, "mainAxisOptions", { get: function () { return merge({}, mainAxis, { name: this.mainAxisName, axisLabel: __assign(__assign({}, this.mainAxisLabelDisplayOption), { rotate: this.mainAxis.labelRotation, formatter: this.getMainAxisFormatter() }), inverse: true, data: this.axisData, nameGap: this.barMainAxisNameGap }); }, enumerable: false, configurable: true }); BaseVerticalsChartStore.prototype.getGrid = function () { var _this = this; var grid = {}; var labelRotation = this.chartStyleService.mainAxis.labelRotation; var firstLabel = first(this.yAxisLabels); var minLeft = DEFAULT_AXIS_NAME_HEIGHT; var minBottom = DEFAULT_AXIS_NAME_HEIGHT; var toBottomAlign = 8; switch (labelRotation) { case "45" /* RotateM45 */: // 下边距 var lastLabel = last(this.yAxisLabels); if (lastLabel) { var measuredLength = this.getAxisLabelWidth(lastLabel) || 0; toBottomAlign = measuredLength * FORTY_FIVE_DEGREE_RATIO; } if (!grid.bottom || grid.bottom < toBottomAlign) { grid.bottom = toBottomAlign; } // 左边距 minLeft = 10; break; case "-45" /* Rotate45 */: // 上边距 if (firstLabel) { var measuredLength = this.getAxisLabelWidth(firstLabel) || 0; var toTopAlign = measuredLength * FORTY_FIVE_DEGREE_RATIO; if (firstLabel.length > 2 * this.WRAP_CHAR_NUM) { toTopAlign += 5 + 3 * (Math.ceil(firstLabel.length / this.WRAP_CHAR_NUM) - 2); } grid.top = toTopAlign; } // 下边距 if (!grid.bottom || grid.bottom < toBottomAlign) { grid.bottom = toBottomAlign; } // 左边距 var maxWidthLabel = maxBy(this.yAxisLabels, function (item) { return _this.getAxisLabelWidth(item); }); if (maxWidthLabel) { var measuredLength = this.getAxisLabelWidth(maxWidthLabel); var toLeftAlign = measuredLength * FORTY_FIVE_DEGREE_RATIO; if (!grid.left || grid.left < toLeftAlign) { grid.left = toLeftAlign; } } break; case "-90" /* Rotate90 */: case "90" /* RotateM90 */: if (firstLabel) { var measuredLength = this.getAxisLabelWidth(firstLabel); var toTopAlign = measuredLength / 2; toTopAlign = toTopAlign < 8 ? 8 : toTopAlign; if (!grid.top || grid.top < toTopAlign) { grid.top = toTopAlign; } } break; default: break; } if (this.mainAxisName) { if (isNil(grid.left) || grid.left < minLeft) { grid.left = minLeft; } } if (this.crossAxisName) { if (isNil(grid.bottom) || grid.bottom < minBottom) { grid.bottom = minBottom; } } return grid; }; Object.defineProperty(BaseVerticalsChartStore.prototype, "barMainAxisNameGap", { get: function () { var labelRotation = this.chartStyleService.mainAxis.labelRotation; switch (labelRotation) { case "0" /* Zero */: return this.yLabelMaxWidth + NAME_LABEL_MARIN; case "-90" /* Rotate90 */: case "90" /* RotateM90 */: return this.yLabelMaxHeight + NAME_LABEL_MARIN; case "45" /* RotateM45 */: case "-45" /* Rotate45 */: return this.yLabelMaxLengthWith45Deg + NAME_LABEL_MARIN; default: return this.yLabelMaxWidth + NAME_LABEL_MARIN; } }, enumerable: false, configurable: true }); Object.defineProperty(BaseVerticalsChartStore.prototype, "barCrossAxis1NameGap", { get: function () { return this.xLabelMaxHeight + NAME_LABEL_MARIN; }, enumerable: false, configurable: true }); BaseVerticalsChartStore.prototype.getOptions = function () { var crossAxisOptions = this.barCrossAxis1Options; var showToolBox = this.chartStyleService.showToolBox; return merge({}, this.commonOptions, { xAxis: crossAxisOptions, yAxis: this.mainAxisOptions, dataZoom: !isMobileDevice() && showToolBox && [{ yAxisIndex: 0, xAxisIndex: 'none' }], brush: !showToolBox && { yAxisIndex: 0, xAxisIndex: 'none', transformable: false }, toolbox: { feature: { dataZoom: { yAxisIndex: [0], xAxisIndex: 'none' } } } }); }; BaseVerticalsChartStore.prototype.handleLabelShow = function (params) { if (params.componentType === 'yAxis' && params.targetType === 'axisLabel') { this.setHoveredLabel({ text: params.value, position: { x: params.event.offsetX + 10, y: params.event.offsetY + 10 } }); } }; __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseVerticalsChartStore.prototype, "mainAxisOptions", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseVerticalsChartStore.prototype, "barMainAxisNameGap", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseVerticalsChartStore.prototype, "barCrossAxis1NameGap", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], BaseVerticalsChartStore.prototype, "getOptions", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], BaseVerticalsChartStore.prototype, "handleLabelShow", null); return BaseVerticalsChartStore; }(BaseBarChartStore)); export default BaseVerticalsChartStore;