@visactor/vrender-components 0.13.9-alpha.5 → 0.13.9-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/brush/brush.d.ts +5 -3
- package/cjs/brush/brush.js +23 -16
- package/cjs/brush/brush.js.map +1 -1
- package/cjs/brush/type.d.ts +10 -1
- package/cjs/brush/type.js +7 -1
- package/cjs/brush/type.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/label/base.d.ts +1 -2
- package/cjs/label/base.js +22 -61
- package/cjs/label/base.js.map +1 -1
- package/cjs/label/dataLabel.js +2 -3
- package/cjs/label/dataLabel.js.map +1 -1
- package/cjs/label/index.d.ts +0 -1
- package/cjs/label/index.js +1 -2
- package/cjs/label/index.js.map +1 -1
- package/cjs/label/overlap/bitmap.d.ts +1 -1
- package/cjs/label/overlap/bitmap.js +2 -0
- package/cjs/label/overlap/bitmap.js.map +1 -1
- package/cjs/label/type.d.ts +1 -41
- package/cjs/label/type.js.map +1 -1
- package/cjs/link-path/type.js +2 -1
- package/cjs/marker/base.js +1 -2
- package/cjs/pager/index.js +1 -1
- package/cjs/pager/pager.js +1 -1
- package/cjs/tooltip/util.js.map +1 -1
- package/dist/index.js +72 -864
- package/dist/index.min.js +1 -1
- package/es/brush/brush.d.ts +5 -3
- package/es/brush/brush.js +22 -13
- package/es/brush/brush.js.map +1 -1
- package/es/brush/type.d.ts +10 -1
- package/es/brush/type.js +7 -1
- package/es/brush/type.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/label/base.d.ts +1 -2
- package/es/label/base.js +22 -61
- package/es/label/base.js.map +1 -1
- package/es/label/dataLabel.js +1 -4
- package/es/label/dataLabel.js.map +1 -1
- package/es/label/index.d.ts +0 -1
- package/es/label/index.js +0 -2
- package/es/label/index.js.map +1 -1
- package/es/label/overlap/bitmap.d.ts +1 -1
- package/es/label/overlap/bitmap.js +2 -0
- package/es/label/overlap/bitmap.js.map +1 -1
- package/es/label/type.d.ts +1 -41
- package/es/label/type.js.map +1 -1
- package/es/link-path/type.js +2 -1
- package/es/marker/base.js +1 -2
- package/es/pager/index.js +1 -1
- package/es/pager/pager.js +1 -1
- package/es/tooltip/util.js.map +1 -1
- package/package.json +4 -4
- package/cjs/label/arc.d.ts +0 -69
- package/cjs/label/arc.js +0 -397
- package/cjs/label/arc.js.map +0 -1
- package/cjs/label/util.d.ts +0 -12
- package/cjs/label/util.js +0 -113
- package/cjs/label/util.js.map +0 -1
- package/es/label/arc.d.ts +0 -69
- package/es/label/arc.js +0 -387
- package/es/label/arc.js.map +0 -1
- package/es/label/util.d.ts +0 -12
- package/es/label/util.js +0 -99
- package/es/label/util.js.map +0 -1
package/cjs/label/util.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: !0
|
|
5
|
-
}), exports.degrees = exports.checkBoundsOverlap = exports.connectLineRadian = exports.lineCirclePoints = exports.isQuadrantRight = exports.isQuadrantLeft = exports.normalizeAngle = exports.computeQuadrant = exports.circlePoint = exports.polarToCartesian = void 0;
|
|
6
|
-
|
|
7
|
-
const vutils_1 = require("@visactor/vutils");
|
|
8
|
-
|
|
9
|
-
function polarToCartesian(point) {
|
|
10
|
-
return point.radius ? {
|
|
11
|
-
x: Math.cos(point.angle) * point.radius,
|
|
12
|
-
y: Math.sin(point.angle) * point.radius
|
|
13
|
-
} : {
|
|
14
|
-
x: 0,
|
|
15
|
-
y: 0
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function circlePoint(x0, y0, radius, radian) {
|
|
20
|
-
const offset = polarToCartesian({
|
|
21
|
-
radius: radius,
|
|
22
|
-
angle: radian
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
x: x0 + offset.x,
|
|
26
|
-
y: y0 + offset.y
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function computeQuadrant(angle) {
|
|
31
|
-
return (angle = normalizeAngle(angle)) > 0 && angle <= Math.PI / 2 ? 2 : angle > Math.PI / 2 && angle <= Math.PI ? 3 : angle > Math.PI && angle <= 3 * Math.PI / 2 ? 4 : 1;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function normalizeAngle(angle) {
|
|
35
|
-
for (;angle < 0; ) angle += 2 * Math.PI;
|
|
36
|
-
for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
|
|
37
|
-
return angle;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function isQuadrantLeft(quadrant) {
|
|
41
|
-
return 3 === quadrant || 4 === quadrant;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function isQuadrantRight(quadrant) {
|
|
45
|
-
return 1 === quadrant || 2 === quadrant;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function lineCirclePoints(a, b, c, x0, y0, r) {
|
|
49
|
-
if (0 === a && 0 === b || r <= 0) return [];
|
|
50
|
-
if (0 === a) {
|
|
51
|
-
const y1 = -c / b, fd = r ** 2 - (y1 - y0) ** 2;
|
|
52
|
-
if (fd < 0) return [];
|
|
53
|
-
if (0 === fd) return [ {
|
|
54
|
-
x: x0,
|
|
55
|
-
y: y1
|
|
56
|
-
} ];
|
|
57
|
-
return [ {
|
|
58
|
-
x: Math.sqrt(fd) + x0,
|
|
59
|
-
y: y1
|
|
60
|
-
}, {
|
|
61
|
-
x: -Math.sqrt(fd) + x0,
|
|
62
|
-
y: y1
|
|
63
|
-
} ];
|
|
64
|
-
}
|
|
65
|
-
if (0 === b) {
|
|
66
|
-
const x1 = -c / a, fd = r ** 2 - (x1 - x0) ** 2;
|
|
67
|
-
if (fd < 0) return [];
|
|
68
|
-
if (0 === fd) return [ {
|
|
69
|
-
x: x1,
|
|
70
|
-
y: y0
|
|
71
|
-
} ];
|
|
72
|
-
return [ {
|
|
73
|
-
x: x1,
|
|
74
|
-
y: Math.sqrt(fd) + y0
|
|
75
|
-
}, {
|
|
76
|
-
x: x1,
|
|
77
|
-
y: -Math.sqrt(fd) + y0
|
|
78
|
-
} ];
|
|
79
|
-
}
|
|
80
|
-
const fa = (b / a) ** 2 + 1, fb = 2 * ((c / a + x0) * (b / a) - y0), fd = fb ** 2 - 4 * fa * ((c / a + x0) ** 2 + y0 ** 2 - r ** 2);
|
|
81
|
-
if (fd < 0) return [];
|
|
82
|
-
const y1 = (-fb + Math.sqrt(fd)) / (2 * fa), y2 = (-fb - Math.sqrt(fd)) / (2 * fa), x1 = -(b * y1 + c) / a;
|
|
83
|
-
return 0 === fd ? [ {
|
|
84
|
-
x: x1,
|
|
85
|
-
y: y1
|
|
86
|
-
} ] : [ {
|
|
87
|
-
x: x1,
|
|
88
|
-
y: y1
|
|
89
|
-
}, {
|
|
90
|
-
x: -(b * y2 + c) / a,
|
|
91
|
-
y: y2
|
|
92
|
-
} ];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function connectLineRadian(radius, length) {
|
|
96
|
-
return length > 2 * radius ? NaN : 2 * Math.asin(length / 2 / radius);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function checkBoundsOverlap(boundsA, boundsB) {
|
|
100
|
-
const {x1: ax1, y1: ay1, x2: ax2, y2: ay2} = boundsA, {x1: bx1, y1: by1, x2: bx2, y2: by2} = boundsB;
|
|
101
|
-
return !(ax1 <= bx1 && ax2 <= bx1 || ax1 >= bx2 && ax2 >= bx2 || ay1 <= by1 && ay2 <= by1 || ay1 >= by2 && ay2 >= by2);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
exports.polarToCartesian = polarToCartesian, exports.circlePoint = circlePoint,
|
|
105
|
-
exports.computeQuadrant = computeQuadrant, exports.normalizeAngle = normalizeAngle,
|
|
106
|
-
exports.isQuadrantLeft = isQuadrantLeft, exports.isQuadrantRight = isQuadrantRight,
|
|
107
|
-
exports.lineCirclePoints = lineCirclePoints, exports.connectLineRadian = connectLineRadian,
|
|
108
|
-
exports.checkBoundsOverlap = checkBoundsOverlap;
|
|
109
|
-
|
|
110
|
-
const degrees = angle => (0, vutils_1.isValidNumber)(angle) ? (0, vutils_1.radianToDegree)(angle) : null;
|
|
111
|
-
|
|
112
|
-
exports.degrees = degrees;
|
|
113
|
-
//# sourceMappingURL=util.js.map
|
package/cjs/label/util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["label/util.ts"],"names":[],"mappings":";;;AAEA,6CAAiE;AAOjE,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACvB;IACD,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;QACvC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;KACxC,CAAC;AACJ,CAAC;AARD,4CAQC;AASD,SAAgB,WAAW,CAAC,EAAU,EAAE,EAAU,EAAE,MAAc,EAAE,MAAc;IAChF,MAAM,MAAM,GAAG,gBAAgB,CAAC;QAC9B,MAAM;QACN,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IACH,OAAO;QACL,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC;QAChB,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC;KACjB,CAAC;AACJ,CAAC;AATD,kCASC;AAQD,SAAgB,eAAe,CAAC,KAAa;IAC3C,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,EAAE,GAAG,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IPoint, Quadrant } from './type';\nimport type { IBoundsLike } from '@visactor/vutils';\nimport { radianToDegree, isValidNumber } from '@visactor/vutils';\n\n/**\n * 极坐标系 -> 直角坐标系\n * @param point\n * @returns\n */\nexport function polarToCartesian(point: IPolarPoint): IPoint {\n if (!point.radius) {\n return { x: 0, y: 0 };\n }\n return {\n x: Math.cos(point.angle) * point.radius,\n y: Math.sin(point.angle) * point.radius\n };\n}\n\n/**\n * 计算圆弧上的点坐标\n * @param x0 圆心 x 坐标\n * @param y0 圆心 y 坐标\n * @param radius 圆弧半径\n * @param radian 点所在弧度\n */\nexport function circlePoint(x0: number, y0: number, radius: number, radian: number): IPoint {\n const offset = polarToCartesian({\n radius,\n angle: radian\n });\n return {\n x: x0 + offset.x,\n y: y0 + offset.y\n };\n}\n\n/**\n * 根据角度计算象限\n * 计算角度所在象限\n * @param angle\n * @returns\n */\nexport function computeQuadrant(angle: number): Quadrant {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\n/**\n * 角度标准化处理\n * @param angle 弧度角\n */\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function isQuadrantLeft(quadrant: Quadrant): boolean {\n return quadrant === 3 || quadrant === 4;\n}\n\nexport function isQuadrantRight(quadrant: Quadrant): boolean {\n return quadrant === 1 || quadrant === 2;\n}\n\n/**\n * 计算直线与圆交点\n * 直线方程:ax + by + c = 0\n * 圆方程:(x - x0)^2 + (y - y0)^2 = r^2\n */\nexport function lineCirclePoints(a: number, b: number, c: number, x0: number, y0: number, r: number): IPoint[] {\n if ((a === 0 && b === 0) || r <= 0) {\n return [];\n }\n if (a === 0) {\n const y1 = -c / b;\n const fy = (y1 - y0) ** 2;\n const fd = r ** 2 - fy;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x0, y: y1 }];\n }\n const x1 = Math.sqrt(fd) + x0;\n const x2 = -Math.sqrt(fd) + x0;\n return [\n { x: x1, y: y1 },\n { x: x2, y: y1 }\n ];\n } else if (b === 0) {\n const x1 = -c / a;\n const fx = (x1 - x0) ** 2;\n const fd = r ** 2 - fx;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x1, y: y0 }];\n }\n const y1 = Math.sqrt(fd) + y0;\n const y2 = -Math.sqrt(fd) + y0;\n return [\n { x: x1, y: y1 },\n { x: x1, y: y2 }\n ];\n }\n const fa = (b / a) ** 2 + 1;\n const fb = 2 * ((c / a + x0) * (b / a) - y0);\n const fc = (c / a + x0) ** 2 + y0 ** 2 - r ** 2;\n const fd = fb ** 2 - 4 * fa * fc;\n if (fd < 0) {\n return [];\n }\n const y1 = (-fb + Math.sqrt(fd)) / (2 * fa);\n const y2 = (-fb - Math.sqrt(fd)) / (2 * fa);\n const x1 = -(b * y1 + c) / a;\n const x2 = -(b * y2 + c) / a;\n if (fd === 0) {\n return [{ x: x1, y: y1 }];\n }\n return [\n { x: x1, y: y1 },\n { x: x2, y: y2 }\n ];\n}\n\n/**\n * 根据圆弧两点连接线长度计算弧度\n * @param radius 圆弧半径\n * @param length 连接线长度\n */\nexport function connectLineRadian(radius: number, length: number) {\n if (length > radius * 2) {\n return NaN;\n }\n return Math.asin(length / 2 / radius) * 2;\n}\n\nexport function checkBoundsOverlap(boundsA: IBoundsLike, boundsB: IBoundsLike): boolean {\n const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = boundsA;\n const { x1: bx1, y1: by1, x2: bx2, y2: by2 } = boundsB;\n return !(\n (ax1 <= bx1 && ax2 <= bx1) ||\n (ax1 >= bx2 && ax2 >= bx2) ||\n (ay1 <= by1 && ay2 <= by1) ||\n (ay1 >= by2 && ay2 >= by2)\n );\n}\n\nexport const degrees = (angle?: number) => {\n if (!isValidNumber(angle)) {\n return null;\n }\n return radianToDegree(angle);\n};\n"]}
|
package/es/label/arc.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { IBoundsLike } from '@visactor/vutils';
|
|
2
|
-
import { LabelBase } from './base';
|
|
3
|
-
import type { ArcLabelAttrs, IPoint, Quadrant } from './type';
|
|
4
|
-
import type { BaseLabelAttrs } from './type';
|
|
5
|
-
import type { TextAlignType, TextBaselineType } from '@visactor/vrender';
|
|
6
|
-
import type { IGraphic } from '@visactor/vrender';
|
|
7
|
-
export declare class ArcInfo {
|
|
8
|
-
key: string;
|
|
9
|
-
refDatum: any;
|
|
10
|
-
center: IPoint;
|
|
11
|
-
outerCenter: IPoint;
|
|
12
|
-
labelSize: {
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
};
|
|
16
|
-
labelPosition: IPoint;
|
|
17
|
-
labelLimit: number;
|
|
18
|
-
labelVisible: boolean;
|
|
19
|
-
lastLabelY: number;
|
|
20
|
-
labelYRange: [number, number];
|
|
21
|
-
labelText: string | string[];
|
|
22
|
-
pointA: IPoint;
|
|
23
|
-
pointB: IPoint;
|
|
24
|
-
pointC: IPoint;
|
|
25
|
-
quadrant: Quadrant;
|
|
26
|
-
radian: number;
|
|
27
|
-
middleAngle: number;
|
|
28
|
-
k: number;
|
|
29
|
-
textAlign: TextAlignType;
|
|
30
|
-
textBaseline: TextBaselineType;
|
|
31
|
-
angle: number;
|
|
32
|
-
constructor(refDatum: any, center: IPoint, outerCenter: IPoint, quadrant: Quadrant, radian: number, middleAngle: number);
|
|
33
|
-
getLabelBounds(): IBoundsLike;
|
|
34
|
-
}
|
|
35
|
-
export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
|
|
36
|
-
name: string;
|
|
37
|
-
static defaultAttributes: Partial<ArcLabelAttrs>;
|
|
38
|
-
private _ellipsisWidth;
|
|
39
|
-
private _arcLeft;
|
|
40
|
-
private _arcRight;
|
|
41
|
-
constructor(attributes: ArcLabelAttrs);
|
|
42
|
-
protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position: string, offset: number, graphicAttributes: any, textData: any, width: number, height: number, attribute: any): {
|
|
43
|
-
x: number;
|
|
44
|
-
y: number;
|
|
45
|
-
} | undefined;
|
|
46
|
-
protected layoutArcLabels(position: BaseLabelAttrs['position'], attribute: any, currentMarks?: IGraphic[]): ArcInfo[];
|
|
47
|
-
private _layoutInsideLabels;
|
|
48
|
-
private _layoutOutsideLabels;
|
|
49
|
-
private _computeX;
|
|
50
|
-
private _computeAlignOffset;
|
|
51
|
-
private _computeAlign;
|
|
52
|
-
private _getFormatLabelText;
|
|
53
|
-
private _adjustY;
|
|
54
|
-
private _shiftY;
|
|
55
|
-
private _findNextVisibleIndex;
|
|
56
|
-
private _computePointB;
|
|
57
|
-
private _storeY;
|
|
58
|
-
private _computeYRange;
|
|
59
|
-
private _computeLayoutRadius;
|
|
60
|
-
private _findNeighborIndex;
|
|
61
|
-
private _twoWayShift;
|
|
62
|
-
private _restoreY;
|
|
63
|
-
private _checkYRange;
|
|
64
|
-
private _coverLabels;
|
|
65
|
-
protected computeRadius(r: number, width?: number, height?: number, k?: number): number;
|
|
66
|
-
protected computeLayoutRadius(width: number, height: number): number;
|
|
67
|
-
private computeLayoutOuterRadius;
|
|
68
|
-
private computeDatumRadius;
|
|
69
|
-
}
|
package/es/label/arc.js
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { merge } from "@visactor/vutils";
|
|
2
|
-
|
|
3
|
-
import { LabelBase } from "./base";
|
|
4
|
-
|
|
5
|
-
import { isValidNumber, isNil, isLess, isGreater, isNumberClose as isClose } from "@visactor/vutils";
|
|
6
|
-
|
|
7
|
-
import { circlePoint, isQuadrantRight, isQuadrantLeft, lineCirclePoints, connectLineRadian, checkBoundsOverlap, computeQuadrant } from "./util";
|
|
8
|
-
|
|
9
|
-
export class ArcInfo {
|
|
10
|
-
constructor(refDatum, center, outerCenter, quadrant, radian, middleAngle) {
|
|
11
|
-
this.refDatum = refDatum, this.center = center, this.outerCenter = outerCenter,
|
|
12
|
-
this.quadrant = quadrant, this.radian = radian, this.middleAngle = middleAngle,
|
|
13
|
-
this.labelVisible = !0, this.labelLimit = 0;
|
|
14
|
-
}
|
|
15
|
-
getLabelBounds() {
|
|
16
|
-
return this.labelPosition && this.labelSize ? {
|
|
17
|
-
x1: this.labelPosition.x - this.labelSize.width / 2,
|
|
18
|
-
y1: this.labelPosition.y - this.labelSize.height / 2,
|
|
19
|
-
x2: this.labelPosition.x + this.labelSize.width / 2,
|
|
20
|
-
y2: this.labelPosition.y + this.labelSize.height / 2
|
|
21
|
-
} : {
|
|
22
|
-
x1: 0,
|
|
23
|
-
x2: 0,
|
|
24
|
-
y1: 0,
|
|
25
|
-
y2: 0
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class ArcLabel extends LabelBase {
|
|
31
|
-
constructor(attributes) {
|
|
32
|
-
super(merge({}, ArcLabel.defaultAttributes, attributes)), this.name = "arc-label",
|
|
33
|
-
this._ellipsisWidth = 0, this._arcLeft = new Map, this._arcRight = new Map;
|
|
34
|
-
}
|
|
35
|
-
labeling(textBounds, graphicBounds, position = "outside", offset = 0, graphicAttributes, textData, width, height, attribute) {
|
|
36
|
-
var _a, _b;
|
|
37
|
-
if (!textBounds || !graphicBounds) return;
|
|
38
|
-
const radiusRatio = this.computeLayoutOuterRadius(graphicAttributes.outerRadius, width, height), radius = this.computeRadius(radiusRatio, width, height), center = {
|
|
39
|
-
x: null !== (_a = null == graphicAttributes ? void 0 : graphicAttributes.x) && void 0 !== _a ? _a : 0,
|
|
40
|
-
y: null !== (_b = null == graphicAttributes ? void 0 : graphicAttributes.y) && void 0 !== _b ? _b : 0
|
|
41
|
-
}, item = textData, arcMiddleAngle = (graphicAttributes.startAngle + graphicAttributes.endAngle) / 2, intervalAngle = graphicAttributes.endAngle - graphicAttributes.startAngle, arcQuadrant = computeQuadrant(graphicAttributes.endAngle - intervalAngle / 2), arcMiddle = circlePoint(center.x, center.y, graphicAttributes.outerRadius, arcMiddleAngle), outerArcMiddle = circlePoint(center.x, center.y, radius + attribute.line.line1MinLength, arcMiddleAngle), arc = new ArcInfo(item, arcMiddle, outerArcMiddle, arcQuadrant, intervalAngle, arcMiddleAngle);
|
|
42
|
-
arc.pointA = circlePoint(center.x, center.y, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttributes.outerRadius), arc.middleAngle),
|
|
43
|
-
arc.labelSize = {
|
|
44
|
-
width: textBounds.x2 - textBounds.x1,
|
|
45
|
-
height: textBounds.y2 - textBounds.y1
|
|
46
|
-
}, isQuadrantRight(arc.quadrant) ? (arc.textAlign = "left", arc.textBaseline = "middle",
|
|
47
|
-
this._arcRight.set(arc.refDatum, arc)) : isQuadrantLeft(arc.quadrant) && (arc.textAlign = "right",
|
|
48
|
-
arc.textBaseline = "middle", this._arcLeft.set(arc.refDatum, arc));
|
|
49
|
-
}
|
|
50
|
-
layoutArcLabels(position, attribute, currentMarks) {
|
|
51
|
-
const leftArcs = Array.from(this._arcLeft.values()), rightArcs = Array.from(this._arcRight.values()), arcs = [];
|
|
52
|
-
return "inside" === position ? (arcs.push(...this._layoutInsideLabels(rightArcs, attribute, currentMarks)),
|
|
53
|
-
arcs.push(...this._layoutInsideLabels(leftArcs, attribute, currentMarks))) : (arcs.push(...this._layoutOutsideLabels(rightArcs, attribute, currentMarks)),
|
|
54
|
-
arcs.push(...this._layoutOutsideLabels(leftArcs, attribute, currentMarks))), arcs;
|
|
55
|
-
}
|
|
56
|
-
_layoutInsideLabels(arcs, attribute, currentMarks) {
|
|
57
|
-
var _a, _b, _c, _d;
|
|
58
|
-
const center = {
|
|
59
|
-
x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
|
|
60
|
-
y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
|
|
61
|
-
}, innerRadiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.innerRadius, attribute.width, attribute.height), outerRadiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), labelConfig = attribute, spaceWidth = labelConfig.spaceWidth;
|
|
62
|
-
return arcs.forEach((arc => {
|
|
63
|
-
const {labelSize: labelSize, radian: radian} = arc, innerRadius = this.computeRadius(innerRadiusRatio, attribute.width, attribute.height, 1), outerRadius = this.computeRadius(outerRadiusRatio, attribute.width, attribute.height, 1);
|
|
64
|
-
let limit;
|
|
65
|
-
if (radian < connectLineRadian(outerRadius, labelSize.height)) limit = 0; else {
|
|
66
|
-
let minRadius;
|
|
67
|
-
minRadius = radian >= Math.PI ? innerRadius : Math.max(innerRadius, labelSize.height / 2 / Math.tan(radian / 2)),
|
|
68
|
-
limit = outerRadius - minRadius - spaceWidth;
|
|
69
|
-
}
|
|
70
|
-
!0 !== (null == labelConfig ? void 0 : labelConfig.rotate) && (limit = outerRadius - spaceWidth);
|
|
71
|
-
const text = this._getFormatLabelText(arc.refDatum, limit);
|
|
72
|
-
arc.labelText = text;
|
|
73
|
-
const labelWidth = Math.min(limit, arc.labelSize.width), align = this._computeAlign(arc, attribute), labelRadius = outerRadius - spaceWidth - ("left" === align ? labelWidth : "right" === align ? 0 : labelWidth / 2);
|
|
74
|
-
arc.labelPosition = circlePoint(center.x, center.y, labelRadius, arc.middleAngle),
|
|
75
|
-
arc.labelLimit = labelWidth, isGreater(labelWidth, 0) || (arc.labelVisible = !1),
|
|
76
|
-
arc.textAlign = "center", arc.textBaseline = "middle", arc.angle = arc.middleAngle;
|
|
77
|
-
})), arcs;
|
|
78
|
-
}
|
|
79
|
-
_layoutOutsideLabels(arcs, attribute, currentMarks) {
|
|
80
|
-
var _a, _b, _c, _d, _e;
|
|
81
|
-
const center_x = null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0, height = 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0), line2MinLength = attribute.line.line2MinLength, labelLayout = attribute.layout, spaceWidth = attribute.spaceWidth;
|
|
82
|
-
if (arcs.forEach((arc => {
|
|
83
|
-
const direction = isQuadrantLeft(arc.quadrant) ? -1 : 1;
|
|
84
|
-
arc.labelPosition = {
|
|
85
|
-
x: arc.outerCenter.x + direction * (arc.labelSize.width / 2 + line2MinLength + spaceWidth),
|
|
86
|
-
y: arc.outerCenter.y
|
|
87
|
-
};
|
|
88
|
-
})), arcs.sort(((a, b) => a.labelPosition.y - b.labelPosition.y)), !1 !== attribute.coverEnable || "none" === labelLayout.strategy) {
|
|
89
|
-
for (const arc of arcs) {
|
|
90
|
-
const {labelPosition: labelPosition, labelSize: labelSize} = arc;
|
|
91
|
-
arc.labelLimit = labelSize.width, arc.pointB = isQuadrantLeft(arc.quadrant) ? {
|
|
92
|
-
x: labelPosition.x + labelSize.width / 2 + line2MinLength + spaceWidth,
|
|
93
|
-
y: labelPosition.y
|
|
94
|
-
} : {
|
|
95
|
-
x: labelPosition.x - labelSize.width / 2 - line2MinLength - spaceWidth,
|
|
96
|
-
y: labelPosition.y
|
|
97
|
-
}, this._computeX(arc, attribute, currentMarks);
|
|
98
|
-
}
|
|
99
|
-
!1 === attribute.coverEnable && "none" === labelLayout.strategy && this._coverLabels(arcs);
|
|
100
|
-
} else {
|
|
101
|
-
const maxLabels = height / ((null === (_e = attribute.textStyle) || void 0 === _e ? void 0 : _e.fontSize) || 16);
|
|
102
|
-
this._adjustY(arcs, maxLabels, attribute, currentMarks);
|
|
103
|
-
const {minY: minY, maxY: maxY} = arcs.reduce(((yInfo, arc) => {
|
|
104
|
-
const {y1: y1, y2: y2} = arc.getLabelBounds();
|
|
105
|
-
return yInfo.minY = Math.max(0, Math.min(y1, yInfo.minY)), yInfo.maxY = Math.min(height, Math.max(y2, yInfo.maxY)),
|
|
106
|
-
yInfo;
|
|
107
|
-
}), {
|
|
108
|
-
minY: 1 / 0,
|
|
109
|
-
maxY: -1 / 0
|
|
110
|
-
}), halfY = Math.max(Math.abs(height / 2 - minY), Math.abs(maxY - height / 2)), r = this._computeLayoutRadius(halfY, attribute, currentMarks);
|
|
111
|
-
for (const arc of arcs) this._computePointB(arc, r, attribute, currentMarks), this._computeX(arc, attribute, currentMarks);
|
|
112
|
-
}
|
|
113
|
-
const width = 2 * center_x;
|
|
114
|
-
return arcs.forEach((arc => {
|
|
115
|
-
arc.labelVisible && (isLess(arc.pointB.x, line2MinLength + spaceWidth) || isGreater(arc.pointB.x, width - line2MinLength - spaceWidth)) && (arc.labelVisible = !1),
|
|
116
|
-
arc.angle = 0;
|
|
117
|
-
})), arcs;
|
|
118
|
-
}
|
|
119
|
-
_computeX(arc, attribute, currentMarks) {
|
|
120
|
-
var _a, _b, _c, _d, _e;
|
|
121
|
-
const center_x = null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0, plotLayout_width = 2 * center_x, radiusRatio = (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y,
|
|
122
|
-
this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height)), line1MinLength = attribute.line.line1MinLength, line2MinLength = attribute.line.line2MinLength, labelLayoutAlign = null === (_e = attribute.layout) || void 0 === _e ? void 0 : _e.align, spaceWidth = attribute.spaceWidth, align = this._computeAlign(arc, attribute), {labelPosition: labelPosition, quadrant: quadrant, pointB: pointB} = arc;
|
|
123
|
-
isValidNumber(pointB.x * pointB.y) || (arc.pointC = {
|
|
124
|
-
x: NaN,
|
|
125
|
-
y: NaN
|
|
126
|
-
}, labelPosition.x = NaN, arc.labelLimit = 0);
|
|
127
|
-
const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), flag = isQuadrantLeft(quadrant) ? -1 : 1;
|
|
128
|
-
let cx = 0;
|
|
129
|
-
let limit = (flag > 0 ? plotLayout_width - pointB.x : pointB.x) - line2MinLength - spaceWidth;
|
|
130
|
-
"labelLine" === labelLayoutAlign && (cx = (radius + line1MinLength + line2MinLength) * flag + center_x,
|
|
131
|
-
limit = (flag > 0 ? plotLayout_width - cx : cx) - spaceWidth);
|
|
132
|
-
const text = this._getFormatLabelText(arc.refDatum, limit);
|
|
133
|
-
arc.labelText = text;
|
|
134
|
-
let labelWidth = Math.min(limit, arc.labelSize.width);
|
|
135
|
-
switch (labelLayoutAlign) {
|
|
136
|
-
case "labelLine":
|
|
137
|
-
break;
|
|
138
|
-
|
|
139
|
-
case "edge":
|
|
140
|
-
cx = flag > 0 ? plotLayout_width - labelWidth - spaceWidth : labelWidth + spaceWidth;
|
|
141
|
-
break;
|
|
142
|
-
|
|
143
|
-
default:
|
|
144
|
-
cx = pointB.x + flag * line2MinLength;
|
|
145
|
-
}
|
|
146
|
-
if (labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.pointC = {
|
|
147
|
-
x: cx,
|
|
148
|
-
y: labelPosition.y
|
|
149
|
-
}, "edge" === labelLayoutAlign) {
|
|
150
|
-
const alignOffset = this._computeAlignOffset(align, labelWidth, -flag);
|
|
151
|
-
labelPosition.x = flag > 0 ? plotLayout_width + alignOffset : alignOffset;
|
|
152
|
-
} else {
|
|
153
|
-
const alignOffset = this._computeAlignOffset(align, labelWidth, flag);
|
|
154
|
-
labelPosition.x = cx + alignOffset + flag * spaceWidth;
|
|
155
|
-
}
|
|
156
|
-
arc.labelLimit = labelWidth;
|
|
157
|
-
}
|
|
158
|
-
_computeAlignOffset(align, labelWidth, alignFlag) {
|
|
159
|
-
switch (align) {
|
|
160
|
-
case "left":
|
|
161
|
-
return alignFlag < 0 ? -labelWidth : 0;
|
|
162
|
-
|
|
163
|
-
case "right":
|
|
164
|
-
return alignFlag < 0 ? 0 : labelWidth;
|
|
165
|
-
|
|
166
|
-
default:
|
|
167
|
-
return labelWidth / 2 * alignFlag;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
_computeAlign(arc, attribute) {
|
|
171
|
-
var _a, _b, _c, _d, _e, _f;
|
|
172
|
-
const labelConfig = attribute, textAlign = null !== (_b = null === (_a = labelConfig.textStyle) || void 0 === _a ? void 0 : _a.textAlign) && void 0 !== _b ? _b : null === (_c = labelConfig.textStyle) || void 0 === _c ? void 0 : _c.align, layoutAlign = null !== (_e = null === (_d = labelConfig.layout) || void 0 === _d ? void 0 : _d.textAlign) && void 0 !== _e ? _e : null === (_f = labelConfig.layout) || void 0 === _f ? void 0 : _f.align;
|
|
173
|
-
return "inside" !== labelConfig.position ? isNil(textAlign) || "auto" === textAlign ? "edge" === layoutAlign ? isQuadrantLeft(arc.quadrant) ? "left" : "right" : isQuadrantLeft(arc.quadrant) ? "right" : "left" : textAlign : isNil(textAlign) || "auto" === textAlign ? "center" : textAlign;
|
|
174
|
-
}
|
|
175
|
-
_getFormatLabelText(value, limit) {
|
|
176
|
-
return value.text;
|
|
177
|
-
}
|
|
178
|
-
_adjustY(arcs, maxLabels, attribute, currentMarks) {
|
|
179
|
-
var _a, _b, _c, _d;
|
|
180
|
-
_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x;
|
|
181
|
-
const plotRect_height = 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0), labelLayout = attribute.layout;
|
|
182
|
-
if ("vertical" === labelLayout.strategy) {
|
|
183
|
-
let delta, lastY = 0;
|
|
184
|
-
const len = arcs.length;
|
|
185
|
-
if (len <= 0) return;
|
|
186
|
-
for (let i = 0; i < len; i++) {
|
|
187
|
-
const {y1: y1} = arcs[i].getLabelBounds();
|
|
188
|
-
if (delta = y1 - lastY, isLess(delta, 0)) {
|
|
189
|
-
const index = this._shiftY(arcs, i, len - 1, -delta);
|
|
190
|
-
this._shiftY(arcs, index, 0, delta / 2);
|
|
191
|
-
}
|
|
192
|
-
const {y2: y2} = arcs[i].getLabelBounds();
|
|
193
|
-
lastY = y2;
|
|
194
|
-
}
|
|
195
|
-
const {y1: firstY1} = arcs[0].getLabelBounds();
|
|
196
|
-
delta = firstY1 - 0, isLess(delta, 0) && this._shiftY(arcs, 0, len - 1, -delta);
|
|
197
|
-
for (let i = arcs.length - 1; i >= 0 && arcs[i].getLabelBounds().y2 > plotRect_height; i--) arcs[i].labelVisible = !1;
|
|
198
|
-
} else if ("none" !== labelLayout.strategy) {
|
|
199
|
-
const priorityArcs = arcs.map(((arc, i) => ({
|
|
200
|
-
arc: arc,
|
|
201
|
-
originIndex: i,
|
|
202
|
-
priorityIndex: 0
|
|
203
|
-
})));
|
|
204
|
-
priorityArcs.sort(((a, b) => b.arc.radian - a.arc.radian)), priorityArcs.forEach(((priorityArc, i) => {
|
|
205
|
-
priorityArc.priorityIndex = i, priorityArc.arc.labelVisible = !1;
|
|
206
|
-
}));
|
|
207
|
-
let topLabelIndex = 1 / 0, bottomLabelIndex = -1 / 0;
|
|
208
|
-
for (let i = 0; i < maxLabels && i < arcs.length; i++) {
|
|
209
|
-
this._storeY(arcs);
|
|
210
|
-
const arc = priorityArcs[i].arc;
|
|
211
|
-
this._computeYRange(arc, attribute, currentMarks), arc.labelVisible = !0;
|
|
212
|
-
const curY = arc.labelPosition.y, {lastIndex: lastIndex, nextIndex: nextIndex} = this._findNeighborIndex(arcs, priorityArcs[i]), lastArc = arcs[lastIndex], nextArc = arcs[nextIndex];
|
|
213
|
-
if (-1 === lastIndex && -1 !== nextIndex) {
|
|
214
|
-
const nextY = nextArc.labelPosition.y;
|
|
215
|
-
curY > nextY ? arc.labelPosition.y = nextY - nextArc.labelSize.height / 2 - arc.labelSize.height / 2 : this._twoWayShift(arcs, arc, nextArc, nextIndex);
|
|
216
|
-
} else if (-1 !== lastIndex && -1 === nextIndex) {
|
|
217
|
-
const lastY = lastArc.labelPosition.y;
|
|
218
|
-
curY < lastY ? arc.labelPosition.y = lastY + lastArc.labelSize.height / 2 + arc.labelSize.height / 2 : this._twoWayShift(arcs, lastArc, arc, priorityArcs[i].originIndex);
|
|
219
|
-
} else if (-1 !== lastIndex && -1 !== nextIndex) {
|
|
220
|
-
const lastY = lastArc.labelPosition.y, nextY = nextArc.labelPosition.y;
|
|
221
|
-
curY > nextY ? (arc.labelPosition.y = nextY - nextArc.labelSize.height / 2 - arc.labelSize.height / 2,
|
|
222
|
-
this._twoWayShift(arcs, lastArc, arc, priorityArcs[i].originIndex)) : curY < lastY ? (arc.labelPosition.y = lastY + lastArc.labelSize.height / 2 + arc.labelSize.height / 2,
|
|
223
|
-
this._twoWayShift(arcs, arc, nextArc, nextIndex)) : (this._twoWayShift(arcs, lastArc, arc, priorityArcs[i].originIndex),
|
|
224
|
-
this._twoWayShift(arcs, arc, nextArc, nextIndex));
|
|
225
|
-
}
|
|
226
|
-
const nextTopIndex = Math.min(topLabelIndex, priorityArcs[i].originIndex), nextBottomIndex = Math.max(bottomLabelIndex, priorityArcs[i].originIndex);
|
|
227
|
-
let delta;
|
|
228
|
-
if (delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, isGreater(delta, 0) && this._shiftY(arcs, nextBottomIndex, 0, -delta),
|
|
229
|
-
delta = arcs[nextTopIndex].getLabelBounds().y1 - 0, isLess(delta, 0) && this._shiftY(arcs, nextTopIndex, arcs.length - 1, -delta),
|
|
230
|
-
delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, isGreater(delta, 0)) {
|
|
231
|
-
arc.labelVisible = !1, this._restoreY(arcs);
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
labelLayout.tangentConstraint && !this._checkYRange(arcs) ? (arc.labelVisible = !1,
|
|
235
|
-
this._restoreY(arcs)) : (topLabelIndex = nextTopIndex, bottomLabelIndex = nextBottomIndex);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
_shiftY(arcs, start, end, delta) {
|
|
240
|
-
const direction = start < end ? 1 : -1;
|
|
241
|
-
let index = start;
|
|
242
|
-
for (;-1 !== index; ) {
|
|
243
|
-
arcs[index].labelPosition.y += delta;
|
|
244
|
-
const nextIndex = this._findNextVisibleIndex(arcs, index, end, direction);
|
|
245
|
-
if (nextIndex >= 0 && nextIndex < arcs.length) {
|
|
246
|
-
const {y1: curY1, y2: curY2} = arcs[index].getLabelBounds(), {y1: nextY1, y2: nextY2} = arcs[nextIndex].getLabelBounds();
|
|
247
|
-
if (direction > 0 && curY2 < nextY1 || direction < 0 && curY1 > nextY2) return index;
|
|
248
|
-
}
|
|
249
|
-
index = nextIndex;
|
|
250
|
-
}
|
|
251
|
-
return end;
|
|
252
|
-
}
|
|
253
|
-
_findNextVisibleIndex(arcs, start, end, direction) {
|
|
254
|
-
const diff = (end - start) * direction;
|
|
255
|
-
for (let i = 1; i <= diff; i++) {
|
|
256
|
-
const index = start + i * direction;
|
|
257
|
-
if (arcs[index].labelVisible) return index;
|
|
258
|
-
}
|
|
259
|
-
return -1;
|
|
260
|
-
}
|
|
261
|
-
_computePointB(arc, r, attribute, currentMarks) {
|
|
262
|
-
var _a, _b, _c, _d;
|
|
263
|
-
const labelConfig = attribute, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = labelConfig.line.line1MinLength;
|
|
264
|
-
if ("none" === labelConfig.layout.strategy) arc.pointB = {
|
|
265
|
-
x: arc.outerCenter.x,
|
|
266
|
-
y: arc.outerCenter.y
|
|
267
|
-
}; else {
|
|
268
|
-
const center = {
|
|
269
|
-
x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
|
|
270
|
-
y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
|
|
271
|
-
}, radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), {labelPosition: labelPosition, quadrant: quadrant} = arc, rd = r - Math.max(radius + line1MinLength, currentMarks[0].attribute.outerRadius), x = Math.sqrt(r ** 2 - Math.abs(center.y - labelPosition.y) ** 2) - rd;
|
|
272
|
-
isValidNumber(x) ? arc.pointB = {
|
|
273
|
-
x: center.x + x * (isQuadrantLeft(quadrant) ? -1 : 1),
|
|
274
|
-
y: labelPosition.y
|
|
275
|
-
} : arc.pointB = {
|
|
276
|
-
x: NaN,
|
|
277
|
-
y: NaN
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
_storeY(arcs) {
|
|
282
|
-
for (const arc of arcs) arc.labelVisible && (arc.lastLabelY = arc.labelPosition.y);
|
|
283
|
-
}
|
|
284
|
-
_computeYRange(arc, attribute, currentMarks) {
|
|
285
|
-
var _a, _b, _c, _d;
|
|
286
|
-
const plotRect = {
|
|
287
|
-
width: 2 * (null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0),
|
|
288
|
-
height: 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0)
|
|
289
|
-
}, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = attribute.line.line1MinLength, {width: width, height: height} = plotRect, radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), r = this._computeLayoutRadius(height / 2, attribute, currentMarks), cx = Math.abs(arc.center.x - width / 2), cy = arc.center.y - height / 2;
|
|
290
|
-
let a, b, c;
|
|
291
|
-
if (isClose(width / 2, cx)) a = 0, b = 1, c = -cy; else if (isClose(height / 2, cy)) a = 1,
|
|
292
|
-
b = 0, c = -cx; else {
|
|
293
|
-
const k = -1 / (cy / cx);
|
|
294
|
-
a = k, b = -1, c = cy - k * cx;
|
|
295
|
-
}
|
|
296
|
-
const points = lineCirclePoints(a, b, c, line1MinLength + radius - r, 0, r);
|
|
297
|
-
if (points.length < 2) return;
|
|
298
|
-
let min, max;
|
|
299
|
-
points[0].x > points[1].x && points.reverse(), points[0].x < 0 ? isClose(points[0].y, points[1].y) ? Math.abs(arc.middleAngle) < Math.PI / 2 ? (min = 0,
|
|
300
|
-
max = points[1].y + height / 2) : (min = points[1].y + height / 2, max = height) : points[0].y < points[1].y ? (min = 0,
|
|
301
|
-
max = points[1].y + height / 2) : (min = points[1].y + height / 2, max = plotRect.height) : (min = Math.min(points[0].y, points[1].y) + height / 2,
|
|
302
|
-
max = Math.max(points[0].y, points[1].y) + height / 2), arc.labelYRange = [ min, max ];
|
|
303
|
-
}
|
|
304
|
-
_computeLayoutRadius(halfYLength, attribute, currentMarks) {
|
|
305
|
-
const labelConfig = attribute, layoutArcGap = labelConfig.layoutArcGap, line1MinLength = labelConfig.line.line1MinLength, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), outerR = this.computeRadius(radiusRatio, attribute.width, attribute.height) + line1MinLength, a = outerR - layoutArcGap;
|
|
306
|
-
return Math.max((a ** 2 + halfYLength ** 2) / (2 * a), outerR);
|
|
307
|
-
}
|
|
308
|
-
_findNeighborIndex(arcs, priorityArc) {
|
|
309
|
-
const index = priorityArc.originIndex;
|
|
310
|
-
let lastIndex = -1, nextIndex = -1;
|
|
311
|
-
for (let i = index - 1; i >= 0; i--) if (arcs[i].labelVisible) {
|
|
312
|
-
lastIndex = i;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
for (let i = index + 1; i < arcs.length; i++) if (arcs[i].labelVisible) {
|
|
316
|
-
nextIndex = i;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
return {
|
|
320
|
-
lastIndex: lastIndex,
|
|
321
|
-
nextIndex: nextIndex
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
_twoWayShift(arcs, lastArc, nextArc, nextIndex) {
|
|
325
|
-
const delta = nextArc.getLabelBounds().y1 - lastArc.getLabelBounds().y2;
|
|
326
|
-
if (isLess(delta, 0)) {
|
|
327
|
-
const i = this._shiftY(arcs, nextIndex, arcs.length - 1, -delta);
|
|
328
|
-
this._shiftY(arcs, i, 0, delta / 2);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
_restoreY(arcs) {
|
|
332
|
-
for (const arc of arcs) arc.labelVisible && (arc.labelPosition.y = arc.lastLabelY);
|
|
333
|
-
}
|
|
334
|
-
_checkYRange(arcs) {
|
|
335
|
-
for (const arc of arcs) {
|
|
336
|
-
const {labelYRange: labelYRange, labelPosition: labelPosition} = arc;
|
|
337
|
-
if (arc.labelVisible && labelYRange && (isLess(labelPosition.y, labelYRange[0]) || isGreater(labelPosition.y, labelYRange[1]))) return !1;
|
|
338
|
-
}
|
|
339
|
-
return !0;
|
|
340
|
-
}
|
|
341
|
-
_coverLabels(arcs) {
|
|
342
|
-
if (arcs.length <= 1) return;
|
|
343
|
-
let lastBounds = arcs[0].getLabelBounds();
|
|
344
|
-
for (let i = 1; i < arcs.length; i++) {
|
|
345
|
-
const bounds = arcs[i].getLabelBounds();
|
|
346
|
-
checkBoundsOverlap(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
computeRadius(r, width, height, k) {
|
|
350
|
-
return this.computeLayoutRadius(width || 0, height || 0) * r * (isNil(k) ? 1 : k);
|
|
351
|
-
}
|
|
352
|
-
computeLayoutRadius(width, height) {
|
|
353
|
-
return Math.min(width / 2, height / 2);
|
|
354
|
-
}
|
|
355
|
-
computeLayoutOuterRadius(r, width, height) {
|
|
356
|
-
return r / (Math.min(width, height) / 2);
|
|
357
|
-
}
|
|
358
|
-
computeDatumRadius(width, height, outerRadius) {
|
|
359
|
-
const outerRadiusRatio = this.computeLayoutOuterRadius(outerRadius, width, height);
|
|
360
|
-
return this.computeLayoutRadius(width || 0, height || 0) * outerRadiusRatio;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
ArcLabel.defaultAttributes = {
|
|
365
|
-
coverEnable: !1,
|
|
366
|
-
spaceWidth: 5,
|
|
367
|
-
layoutArcGap: 6,
|
|
368
|
-
textStyle: {
|
|
369
|
-
visible: !0,
|
|
370
|
-
fontSize: 14,
|
|
371
|
-
fontWeight: "normal",
|
|
372
|
-
fillOpacity: 1
|
|
373
|
-
},
|
|
374
|
-
position: "outside",
|
|
375
|
-
offset: 0,
|
|
376
|
-
line: {
|
|
377
|
-
visible: !0,
|
|
378
|
-
line1MinLength: 20,
|
|
379
|
-
line2MinLength: 10
|
|
380
|
-
},
|
|
381
|
-
layout: {
|
|
382
|
-
align: "arc",
|
|
383
|
-
strategy: "priority",
|
|
384
|
-
tangentConstraint: !0
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
//# sourceMappingURL=arc.js.map
|