94 lines
3.0 KiB
Java
94 lines
3.0 KiB
Java
import { __assign, __extends } from "tslib";
|
|
import { get, isArray } from '@antv/util';
|
|
import { getAngleByPoint } from '../../util/coordinate';
|
|
import { polarToCartesian } from '../../util/graphics';
|
|
import PolarLabel from './polar';
|
|
/**
|
|
* 饼图 label
|
|
*/
|
|
var PieLabel = /** @class */ (function (_super) {
|
|
__extends(PieLabel, _super);
|
|
function PieLabel(geometry) {
|
|
var _this = _super.call(this, geometry) || this;
|
|
_this.defaultLayout = 'distribute';
|
|
return _this;
|
|
}
|
|
PieLabel.prototype.getDefaultLabelCfg = function () {
|
|
return get(this.geometry.theme, 'pieLabels', {});
|
|
};
|
|
PieLabel.prototype.getDefaultOffset = function (offset) {
|
|
return offset || 0;
|
|
};
|
|
PieLabel.prototype.getLabelRotate = function (angle, offset, isLabelLimit) {
|
|
var rotate;
|
|
if (offset < 0) {
|
|
rotate = angle;
|
|
if (rotate > Math.PI / 2) {
|
|
rotate = rotate - Math.PI;
|
|
}
|
|
if (rotate < -Math.PI / 2) {
|
|
rotate = rotate + Math.PI;
|
|
}
|
|
}
|
|
return rotate;
|
|
};
|
|
PieLabel.prototype.getLabelAlign = function (point) {
|
|
var coordinate = this.getCoordinate();
|
|
var center = coordinate.getCenter();
|
|
var align;
|
|
if (point.angle <= Math.PI / 2 && point.x >= center.x) {
|
|
align = 'left';
|
|
}
|
|
else {
|
|
align = 'right';
|
|
}
|
|
var offset = this.getDefaultOffset(point.offset);
|
|
if (offset <= 0) {
|
|
if (align === 'right') {
|
|
align = 'left';
|
|
}
|
|
else {
|
|
align = 'right';
|
|
}
|
|
}
|
|
return align;
|
|
};
|
|
PieLabel.prototype.getArcPoint = function (point) {
|
|
return point;
|
|
};
|
|
PieLabel.prototype.getPointAngle = function (point) {
|
|
var coordinate = this.getCoordinate();
|
|
var startPoint = {
|
|
x: isArray(point.x) ? point.x[0] : point.x,
|
|
y: point.y[0],
|
|
};
|
|
var endPoint = {
|
|
x: isArray(point.x) ? point.x[1] : point.x,
|
|
y: point.y[1],
|
|
};
|
|
var angle;
|
|
var startAngle = getAngleByPoint(coordinate, startPoint);
|
|
if (point.points && point.points[0].y === point.points[1].y) {
|
|
angle = startAngle;
|
|
}
|
|
else {
|
|
var endAngle = getAngleByPoint(coordinate, endPoint);
|
|
if (startAngle >= endAngle) {
|
|
// 100% pie slice
|
|
endAngle = endAngle + Math.PI * 2;
|
|
}
|
|
angle = startAngle + (endAngle - startAngle) / 2;
|
|
}
|
|
return angle;
|
|
};
|
|
PieLabel.prototype.getCirclePoint = function (angle, offset, p) {
|
|
var coordinate = this.getCoordinate();
|
|
var center = coordinate.getCenter();
|
|
var r = coordinate.getRadius() + offset;
|
|
return __assign(__assign({}, polarToCartesian(center.x, center.y, r, angle)), { angle: angle,
|
|
r: r });
|
|
};
|
|
return PieLabel;
|
|
}(PolarLabel));
|
|
export default PieLabel;
|
|
//# sourceMappingURL=pie.js.map |