@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
229 lines (228 loc) • 9.85 kB
JavaScript
"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 __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 defaultChartConfig_1 = require("../defaultChartConfig");
var two_d_1 = require("../../stores/two-d");
var bind_1 = __importDefault(require("../../../../utils/bind"));
var env_1 = require("../../../../utils/env");
var store_1 = __importDefault(require("../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 lodash_1.merge({}, defaultChartConfig_1.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 = lodash_1.first(this.yAxisLabels);
var minLeft = two_d_1.DEFAULT_AXIS_NAME_HEIGHT;
var minBottom = two_d_1.DEFAULT_AXIS_NAME_HEIGHT;
var toBottomAlign = 8;
switch (labelRotation) {
case "45" /* RotateM45 */:
// 下边距
var lastLabel = lodash_1.last(this.yAxisLabels);
if (lastLabel) {
var measuredLength = this.getAxisLabelWidth(lastLabel) || 0;
toBottomAlign = measuredLength * two_d_1.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 * two_d_1.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 = lodash_1.maxBy(this.yAxisLabels, function (item) {
return _this.getAxisLabelWidth(item);
});
if (maxWidthLabel) {
var measuredLength = this.getAxisLabelWidth(maxWidthLabel);
var toLeftAlign = measuredLength * two_d_1.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 (lodash_1.isNil(grid.left) || grid.left < minLeft) {
grid.left = minLeft;
}
}
if (this.crossAxisName) {
if (lodash_1.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 + two_d_1.NAME_LABEL_MARIN;
case "-90" /* Rotate90 */:
case "90" /* RotateM90 */:
return this.yLabelMaxHeight + two_d_1.NAME_LABEL_MARIN;
case "45" /* RotateM45 */:
case "-45" /* Rotate45 */:
return this.yLabelMaxLengthWith45Deg + two_d_1.NAME_LABEL_MARIN;
default:
return this.yLabelMaxWidth + two_d_1.NAME_LABEL_MARIN;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseVerticalsChartStore.prototype, "barCrossAxis1NameGap", {
get: function () {
return this.xLabelMaxHeight + two_d_1.NAME_LABEL_MARIN;
},
enumerable: false,
configurable: true
});
BaseVerticalsChartStore.prototype.getOptions = function () {
var crossAxisOptions = this.barCrossAxis1Options;
var showToolBox = this.chartStyleService.showToolBox;
return lodash_1.merge({}, this.commonOptions, {
xAxis: crossAxisOptions,
yAxis: this.mainAxisOptions,
dataZoom: !env_1.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([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], BaseVerticalsChartStore.prototype, "mainAxisOptions", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], BaseVerticalsChartStore.prototype, "barMainAxisNameGap", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], BaseVerticalsChartStore.prototype, "barCrossAxis1NameGap", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], BaseVerticalsChartStore.prototype, "getOptions", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], BaseVerticalsChartStore.prototype, "handleLabelShow", null);
return BaseVerticalsChartStore;
}(store_1.default));
exports.default = BaseVerticalsChartStore;