@visactor/vrender-components 0.13.9-alpha.5 → 0.13.9-alpha.7

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.
Files changed (55) hide show
  1. package/cjs/index.d.ts +1 -1
  2. package/cjs/index.js +1 -1
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/label/base.d.ts +1 -3
  5. package/cjs/label/base.js +30 -69
  6. package/cjs/label/base.js.map +1 -1
  7. package/cjs/label/dataLabel.js +2 -3
  8. package/cjs/label/dataLabel.js.map +1 -1
  9. package/cjs/label/index.d.ts +0 -1
  10. package/cjs/label/index.js +1 -2
  11. package/cjs/label/index.js.map +1 -1
  12. package/cjs/label/type.d.ts +2 -41
  13. package/cjs/label/type.js.map +1 -1
  14. package/cjs/link-path/type.js +2 -1
  15. package/cjs/marker/base.js +1 -2
  16. package/cjs/pager/index.js +1 -1
  17. package/cjs/pager/pager.js +1 -1
  18. package/cjs/util/common.d.ts +3 -1
  19. package/cjs/util/common.js +14 -2
  20. package/cjs/util/common.js.map +1 -1
  21. package/dist/index.js +61 -853
  22. package/dist/index.min.js +1 -1
  23. package/es/index.d.ts +1 -1
  24. package/es/index.js +1 -1
  25. package/es/index.js.map +1 -1
  26. package/es/label/base.d.ts +1 -3
  27. package/es/label/base.js +32 -71
  28. package/es/label/base.js.map +1 -1
  29. package/es/label/dataLabel.js +1 -4
  30. package/es/label/dataLabel.js.map +1 -1
  31. package/es/label/index.d.ts +0 -1
  32. package/es/label/index.js +0 -2
  33. package/es/label/index.js.map +1 -1
  34. package/es/label/type.d.ts +2 -41
  35. package/es/label/type.js.map +1 -1
  36. package/es/link-path/type.js +2 -1
  37. package/es/marker/base.js +1 -2
  38. package/es/pager/index.js +1 -1
  39. package/es/pager/pager.js +1 -1
  40. package/es/util/common.d.ts +3 -1
  41. package/es/util/common.js +12 -0
  42. package/es/util/common.js.map +1 -1
  43. package/package.json +2 -2
  44. package/cjs/label/arc.d.ts +0 -69
  45. package/cjs/label/arc.js +0 -397
  46. package/cjs/label/arc.js.map +0 -1
  47. package/cjs/label/util.d.ts +0 -12
  48. package/cjs/label/util.js +0 -113
  49. package/cjs/label/util.js.map +0 -1
  50. package/es/label/arc.d.ts +0 -69
  51. package/es/label/arc.js +0 -387
  52. package/es/label/arc.js.map +0 -1
  53. package/es/label/util.d.ts +0 -12
  54. package/es/label/util.js +0 -99
  55. package/es/label/util.js.map +0 -1
package/es/pager/pager.js CHANGED
@@ -131,4 +131,4 @@ Pager.defaultAttributes = {
131
131
  fontSize: 12
132
132
  }
133
133
  };
134
- //# sourceMappingURL=pager.js.map
134
+ //# sourceMappingURL=pager.js.map
@@ -1,3 +1,5 @@
1
- import { IGraphicAttribute, IGraphic } from '@visactor/vrender';
1
+ import type { IGraphicAttribute, IGraphic, IGroup } from '@visactor/vrender';
2
2
  export declare function traverseGroup(group: IGraphic, cb: (node: IGraphic) => boolean | void): void;
3
3
  export declare const isVisible: (obj?: Partial<IGraphicAttribute>) => boolean;
4
+ export declare function getMarksByName(root: IGroup, name: string): IGraphic<Partial<IGraphicAttribute>>[];
5
+ export declare function getNoneGroupMarksByName(root: IGroup, name: string): IGraphic<Partial<IGraphicAttribute>>[];
package/es/util/common.js CHANGED
@@ -8,4 +8,16 @@ export function traverseGroup(group, cb) {
8
8
  }
9
9
 
10
10
  export const isVisible = obj => !isNil(obj) && !1 !== obj.visible;
11
+
12
+ export function getMarksByName(root, name) {
13
+ if (!name) return [];
14
+ const group = root.find((node => node.name === name), !0);
15
+ return group ? group.getChildren() : [];
16
+ }
17
+
18
+ export function getNoneGroupMarksByName(root, name) {
19
+ if (!name) return [];
20
+ const group = root.find((node => node.name === name), !0);
21
+ return group ? group.findAll((node => "group" !== node.type), !0) : [];
22
+ }
11
23
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["util/common.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,UAAU,aAAa,CAAC,KAAe,EAAE,EAAsC;IACnF,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QAC3B,MAAM,OAAO,GAAG,EAAE,CAAC,IAAgB,CAAC,CAAC;QACrC,IAAK,IAAe,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE;YAC5C,aAAa,CAAC,IAAgB,EAAE,EAAE,CAAC,CAAC;SACrC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAgC,EAAW,EAAE;IACrE,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IACD,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC;AAC/B,CAAC,CAAC","file":"common.js","sourcesContent":["/**\n * @description 存放工具函数\n */\nimport { IGraphicAttribute, IGraphic, IGroup } from '@visactor/vrender';\nimport { isNil } from '@visactor/vutils';\n\nexport function traverseGroup(group: IGraphic, cb: (node: IGraphic) => boolean | void) {\n group.forEachChildren(node => {\n const stopped = cb(node as IGraphic);\n if ((node as IGroup).isContainer && !stopped) {\n traverseGroup(node as IGraphic, cb);\n }\n });\n}\n\nexport const isVisible = (obj?: Partial<IGraphicAttribute>): boolean => {\n if (isNil(obj)) {\n return false;\n }\n return obj.visible !== false;\n};\n"]}
1
+ {"version":3,"sources":["util/common.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,UAAU,aAAa,CAAC,KAAe,EAAE,EAAsC;IACnF,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QAC3B,MAAM,OAAO,GAAG,EAAE,CAAC,IAAgB,CAAC,CAAC;QACrC,IAAK,IAAe,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE;YAC5C,aAAa,CAAC,IAAgB,EAAE,EAAE,CAAC,CAAC;SACrC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAgC,EAAW,EAAE;IACrE,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IACD,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY;IACvD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,CAAC;KACX;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,CAAW,CAAC;IACpE,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IACD,OAAO,KAAK,CAAC,WAAW,EAAgB,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAY,EAAE,IAAY;IAChE,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,CAAC;KACX;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,CAAW,CAAC;IACpE,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAC;KACX;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,IAAI,CAA0B,CAAC;AACrF,CAAC","file":"common.js","sourcesContent":["/**\n * @description 存放工具函数\n */\nimport type { IGraphicAttribute, IGraphic, IGroup } from '@visactor/vrender';\nimport { isNil } from '@visactor/vutils';\n\nexport function traverseGroup(group: IGraphic, cb: (node: IGraphic) => boolean | void) {\n group.forEachChildren(node => {\n const stopped = cb(node as IGraphic);\n if ((node as IGroup).isContainer && !stopped) {\n traverseGroup(node as IGraphic, cb);\n }\n });\n}\n\nexport const isVisible = (obj?: Partial<IGraphicAttribute>): boolean => {\n if (isNil(obj)) {\n return false;\n }\n return obj.visible !== false;\n};\n\nexport function getMarksByName(root: IGroup, name: string) {\n if (!name) {\n return [];\n }\n const group = root.find(node => node.name === name, true) as IGroup;\n if (!group) {\n return [];\n }\n return group.getChildren() as IGraphic[];\n}\n\nexport function getNoneGroupMarksByName(root: IGroup, name: string) {\n if (!name) {\n return [];\n }\n const group = root.find(node => node.name === name, true) as IGroup;\n if (!group) {\n return [];\n }\n return group.findAll(node => node.type !== 'group', true) as unknown as IGraphic[];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vrender-components",
3
- "version": "0.13.9-alpha.5",
3
+ "version": "0.13.9-alpha.7",
4
4
  "description": "components library for dp visualization",
5
5
  "sideEffects": false,
6
6
  "main": "cjs/index.js",
@@ -12,7 +12,7 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@visactor/vrender": "0.13.8-alpha.5",
15
+ "@visactor/vrender": "0.14.0-alpha.7",
16
16
  "@visactor/vutils": "~0.13.0",
17
17
  "@visactor/vscale": "~0.13.0",
18
18
  "inversify": "6.0.1"
@@ -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/cjs/label/arc.js DELETED
@@ -1,397 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: !0
5
- }), exports.ArcLabel = exports.ArcInfo = void 0;
6
-
7
- const vutils_1 = require("@visactor/vutils"), base_1 = require("./base"), vutils_2 = require("@visactor/vutils"), util_1 = require("./util");
8
-
9
- 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
- exports.ArcInfo = ArcInfo;
31
-
32
- class ArcLabel extends base_1.LabelBase {
33
- constructor(attributes) {
34
- super((0, vutils_1.merge)({}, ArcLabel.defaultAttributes, attributes)), this.name = "arc-label",
35
- this._ellipsisWidth = 0, this._arcLeft = new Map, this._arcRight = new Map;
36
- }
37
- labeling(textBounds, graphicBounds, position = "outside", offset = 0, graphicAttributes, textData, width, height, attribute) {
38
- var _a, _b;
39
- if (!textBounds || !graphicBounds) return;
40
- const radiusRatio = this.computeLayoutOuterRadius(graphicAttributes.outerRadius, width, height), radius = this.computeRadius(radiusRatio, width, height), center = {
41
- x: null !== (_a = null == graphicAttributes ? void 0 : graphicAttributes.x) && void 0 !== _a ? _a : 0,
42
- y: null !== (_b = null == graphicAttributes ? void 0 : graphicAttributes.y) && void 0 !== _b ? _b : 0
43
- }, item = textData, arcMiddleAngle = (graphicAttributes.startAngle + graphicAttributes.endAngle) / 2, intervalAngle = graphicAttributes.endAngle - graphicAttributes.startAngle, arcQuadrant = (0,
44
- util_1.computeQuadrant)(graphicAttributes.endAngle - intervalAngle / 2), arcMiddle = (0,
45
- util_1.circlePoint)(center.x, center.y, graphicAttributes.outerRadius, arcMiddleAngle), outerArcMiddle = (0,
46
- util_1.circlePoint)(center.x, center.y, radius + attribute.line.line1MinLength, arcMiddleAngle), arc = new ArcInfo(item, arcMiddle, outerArcMiddle, arcQuadrant, intervalAngle, arcMiddleAngle);
47
- arc.pointA = (0, util_1.circlePoint)(center.x, center.y, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttributes.outerRadius), arc.middleAngle),
48
- arc.labelSize = {
49
- width: textBounds.x2 - textBounds.x1,
50
- height: textBounds.y2 - textBounds.y1
51
- }, (0, util_1.isQuadrantRight)(arc.quadrant) ? (arc.textAlign = "left", arc.textBaseline = "middle",
52
- this._arcRight.set(arc.refDatum, arc)) : (0, util_1.isQuadrantLeft)(arc.quadrant) && (arc.textAlign = "right",
53
- arc.textBaseline = "middle", this._arcLeft.set(arc.refDatum, arc));
54
- }
55
- layoutArcLabels(position, attribute, currentMarks) {
56
- const leftArcs = Array.from(this._arcLeft.values()), rightArcs = Array.from(this._arcRight.values()), arcs = [];
57
- return "inside" === position ? (arcs.push(...this._layoutInsideLabels(rightArcs, attribute, currentMarks)),
58
- arcs.push(...this._layoutInsideLabels(leftArcs, attribute, currentMarks))) : (arcs.push(...this._layoutOutsideLabels(rightArcs, attribute, currentMarks)),
59
- arcs.push(...this._layoutOutsideLabels(leftArcs, attribute, currentMarks))), arcs;
60
- }
61
- _layoutInsideLabels(arcs, attribute, currentMarks) {
62
- var _a, _b, _c, _d;
63
- const center = {
64
- x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
65
- y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
66
- }, 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;
67
- return arcs.forEach((arc => {
68
- const {labelSize: labelSize, radian: radian} = arc, innerRadius = this.computeRadius(innerRadiusRatio, attribute.width, attribute.height, 1), outerRadius = this.computeRadius(outerRadiusRatio, attribute.width, attribute.height, 1);
69
- let limit;
70
- if (radian < (0, util_1.connectLineRadian)(outerRadius, labelSize.height)) limit = 0; else {
71
- let minRadius;
72
- minRadius = radian >= Math.PI ? innerRadius : Math.max(innerRadius, labelSize.height / 2 / Math.tan(radian / 2)),
73
- limit = outerRadius - minRadius - spaceWidth;
74
- }
75
- !0 !== (null == labelConfig ? void 0 : labelConfig.rotate) && (limit = outerRadius - spaceWidth);
76
- const text = this._getFormatLabelText(arc.refDatum, limit);
77
- arc.labelText = text;
78
- const labelWidth = Math.min(limit, arc.labelSize.width), align = this._computeAlign(arc, attribute), labelRadius = outerRadius - spaceWidth - ("left" === align ? labelWidth : "right" === align ? 0 : labelWidth / 2);
79
- arc.labelPosition = (0, util_1.circlePoint)(center.x, center.y, labelRadius, arc.middleAngle),
80
- arc.labelLimit = labelWidth, (0, vutils_2.isGreater)(labelWidth, 0) || (arc.labelVisible = !1),
81
- arc.textAlign = "center", arc.textBaseline = "middle", arc.angle = arc.middleAngle;
82
- })), arcs;
83
- }
84
- _layoutOutsideLabels(arcs, attribute, currentMarks) {
85
- var _a, _b, _c, _d, _e;
86
- 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;
87
- if (arcs.forEach((arc => {
88
- const direction = (0, util_1.isQuadrantLeft)(arc.quadrant) ? -1 : 1;
89
- arc.labelPosition = {
90
- x: arc.outerCenter.x + direction * (arc.labelSize.width / 2 + line2MinLength + spaceWidth),
91
- y: arc.outerCenter.y
92
- };
93
- })), arcs.sort(((a, b) => a.labelPosition.y - b.labelPosition.y)), !1 !== attribute.coverEnable || "none" === labelLayout.strategy) {
94
- for (const arc of arcs) {
95
- const {labelPosition: labelPosition, labelSize: labelSize} = arc;
96
- arc.labelLimit = labelSize.width, arc.pointB = (0, util_1.isQuadrantLeft)(arc.quadrant) ? {
97
- x: labelPosition.x + labelSize.width / 2 + line2MinLength + spaceWidth,
98
- y: labelPosition.y
99
- } : {
100
- x: labelPosition.x - labelSize.width / 2 - line2MinLength - spaceWidth,
101
- y: labelPosition.y
102
- }, this._computeX(arc, attribute, currentMarks);
103
- }
104
- !1 === attribute.coverEnable && "none" === labelLayout.strategy && this._coverLabels(arcs);
105
- } else {
106
- const maxLabels = height / ((null === (_e = attribute.textStyle) || void 0 === _e ? void 0 : _e.fontSize) || 16);
107
- this._adjustY(arcs, maxLabels, attribute, currentMarks);
108
- const {minY: minY, maxY: maxY} = arcs.reduce(((yInfo, arc) => {
109
- const {y1: y1, y2: y2} = arc.getLabelBounds();
110
- return yInfo.minY = Math.max(0, Math.min(y1, yInfo.minY)), yInfo.maxY = Math.min(height, Math.max(y2, yInfo.maxY)),
111
- yInfo;
112
- }), {
113
- minY: 1 / 0,
114
- maxY: -1 / 0
115
- }), halfY = Math.max(Math.abs(height / 2 - minY), Math.abs(maxY - height / 2)), r = this._computeLayoutRadius(halfY, attribute, currentMarks);
116
- for (const arc of arcs) this._computePointB(arc, r, attribute, currentMarks), this._computeX(arc, attribute, currentMarks);
117
- }
118
- const width = 2 * center_x;
119
- return arcs.forEach((arc => {
120
- arc.labelVisible && ((0, vutils_2.isLess)(arc.pointB.x, line2MinLength + spaceWidth) || (0,
121
- vutils_2.isGreater)(arc.pointB.x, width - line2MinLength - spaceWidth)) && (arc.labelVisible = !1),
122
- arc.angle = 0;
123
- })), arcs;
124
- }
125
- _computeX(arc, attribute, currentMarks) {
126
- var _a, _b, _c, _d, _e;
127
- 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,
128
- 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;
129
- (0, vutils_2.isValidNumber)(pointB.x * pointB.y) || (arc.pointC = {
130
- x: NaN,
131
- y: NaN
132
- }, labelPosition.x = NaN, arc.labelLimit = 0);
133
- const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), flag = (0,
134
- util_1.isQuadrantLeft)(quadrant) ? -1 : 1;
135
- let cx = 0;
136
- let limit = (flag > 0 ? plotLayout_width - pointB.x : pointB.x) - line2MinLength - spaceWidth;
137
- "labelLine" === labelLayoutAlign && (cx = (radius + line1MinLength + line2MinLength) * flag + center_x,
138
- limit = (flag > 0 ? plotLayout_width - cx : cx) - spaceWidth);
139
- const text = this._getFormatLabelText(arc.refDatum, limit);
140
- arc.labelText = text;
141
- let labelWidth = Math.min(limit, arc.labelSize.width);
142
- switch (labelLayoutAlign) {
143
- case "labelLine":
144
- break;
145
-
146
- case "edge":
147
- cx = flag > 0 ? plotLayout_width - labelWidth - spaceWidth : labelWidth + spaceWidth;
148
- break;
149
-
150
- default:
151
- cx = pointB.x + flag * line2MinLength;
152
- }
153
- if (labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.pointC = {
154
- x: cx,
155
- y: labelPosition.y
156
- }, "edge" === labelLayoutAlign) {
157
- const alignOffset = this._computeAlignOffset(align, labelWidth, -flag);
158
- labelPosition.x = flag > 0 ? plotLayout_width + alignOffset : alignOffset;
159
- } else {
160
- const alignOffset = this._computeAlignOffset(align, labelWidth, flag);
161
- labelPosition.x = cx + alignOffset + flag * spaceWidth;
162
- }
163
- arc.labelLimit = labelWidth;
164
- }
165
- _computeAlignOffset(align, labelWidth, alignFlag) {
166
- switch (align) {
167
- case "left":
168
- return alignFlag < 0 ? -labelWidth : 0;
169
-
170
- case "right":
171
- return alignFlag < 0 ? 0 : labelWidth;
172
-
173
- default:
174
- return labelWidth / 2 * alignFlag;
175
- }
176
- }
177
- _computeAlign(arc, attribute) {
178
- var _a, _b, _c, _d, _e, _f;
179
- 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;
180
- return "inside" !== labelConfig.position ? (0, vutils_2.isNil)(textAlign) || "auto" === textAlign ? "edge" === layoutAlign ? (0,
181
- util_1.isQuadrantLeft)(arc.quadrant) ? "left" : "right" : (0, util_1.isQuadrantLeft)(arc.quadrant) ? "right" : "left" : textAlign : (0,
182
- vutils_2.isNil)(textAlign) || "auto" === textAlign ? "center" : textAlign;
183
- }
184
- _getFormatLabelText(value, limit) {
185
- return value.text;
186
- }
187
- _adjustY(arcs, maxLabels, attribute, currentMarks) {
188
- var _a, _b, _c, _d;
189
- _b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x;
190
- 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;
191
- if ("vertical" === labelLayout.strategy) {
192
- let delta, lastY = 0;
193
- const len = arcs.length;
194
- if (len <= 0) return;
195
- for (let i = 0; i < len; i++) {
196
- const {y1: y1} = arcs[i].getLabelBounds();
197
- if (delta = y1 - lastY, (0, vutils_2.isLess)(delta, 0)) {
198
- const index = this._shiftY(arcs, i, len - 1, -delta);
199
- this._shiftY(arcs, index, 0, delta / 2);
200
- }
201
- const {y2: y2} = arcs[i].getLabelBounds();
202
- lastY = y2;
203
- }
204
- const {y1: firstY1} = arcs[0].getLabelBounds();
205
- delta = firstY1 - 0, (0, vutils_2.isLess)(delta, 0) && this._shiftY(arcs, 0, len - 1, -delta);
206
- for (let i = arcs.length - 1; i >= 0 && arcs[i].getLabelBounds().y2 > plotRect_height; i--) arcs[i].labelVisible = !1;
207
- } else if ("none" !== labelLayout.strategy) {
208
- const priorityArcs = arcs.map(((arc, i) => ({
209
- arc: arc,
210
- originIndex: i,
211
- priorityIndex: 0
212
- })));
213
- priorityArcs.sort(((a, b) => b.arc.radian - a.arc.radian)), priorityArcs.forEach(((priorityArc, i) => {
214
- priorityArc.priorityIndex = i, priorityArc.arc.labelVisible = !1;
215
- }));
216
- let topLabelIndex = 1 / 0, bottomLabelIndex = -1 / 0;
217
- for (let i = 0; i < maxLabels && i < arcs.length; i++) {
218
- this._storeY(arcs);
219
- const arc = priorityArcs[i].arc;
220
- this._computeYRange(arc, attribute, currentMarks), arc.labelVisible = !0;
221
- const curY = arc.labelPosition.y, {lastIndex: lastIndex, nextIndex: nextIndex} = this._findNeighborIndex(arcs, priorityArcs[i]), lastArc = arcs[lastIndex], nextArc = arcs[nextIndex];
222
- if (-1 === lastIndex && -1 !== nextIndex) {
223
- const nextY = nextArc.labelPosition.y;
224
- curY > nextY ? arc.labelPosition.y = nextY - nextArc.labelSize.height / 2 - arc.labelSize.height / 2 : this._twoWayShift(arcs, arc, nextArc, nextIndex);
225
- } else if (-1 !== lastIndex && -1 === nextIndex) {
226
- const lastY = lastArc.labelPosition.y;
227
- curY < lastY ? arc.labelPosition.y = lastY + lastArc.labelSize.height / 2 + arc.labelSize.height / 2 : this._twoWayShift(arcs, lastArc, arc, priorityArcs[i].originIndex);
228
- } else if (-1 !== lastIndex && -1 !== nextIndex) {
229
- const lastY = lastArc.labelPosition.y, nextY = nextArc.labelPosition.y;
230
- curY > nextY ? (arc.labelPosition.y = nextY - nextArc.labelSize.height / 2 - arc.labelSize.height / 2,
231
- this._twoWayShift(arcs, lastArc, arc, priorityArcs[i].originIndex)) : curY < lastY ? (arc.labelPosition.y = lastY + lastArc.labelSize.height / 2 + arc.labelSize.height / 2,
232
- this._twoWayShift(arcs, arc, nextArc, nextIndex)) : (this._twoWayShift(arcs, lastArc, arc, priorityArcs[i].originIndex),
233
- this._twoWayShift(arcs, arc, nextArc, nextIndex));
234
- }
235
- const nextTopIndex = Math.min(topLabelIndex, priorityArcs[i].originIndex), nextBottomIndex = Math.max(bottomLabelIndex, priorityArcs[i].originIndex);
236
- let delta;
237
- if (delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, (0, vutils_2.isGreater)(delta, 0) && this._shiftY(arcs, nextBottomIndex, 0, -delta),
238
- delta = arcs[nextTopIndex].getLabelBounds().y1 - 0, (0, vutils_2.isLess)(delta, 0) && this._shiftY(arcs, nextTopIndex, arcs.length - 1, -delta),
239
- delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, (0, vutils_2.isGreater)(delta, 0)) {
240
- arc.labelVisible = !1, this._restoreY(arcs);
241
- break;
242
- }
243
- labelLayout.tangentConstraint && !this._checkYRange(arcs) ? (arc.labelVisible = !1,
244
- this._restoreY(arcs)) : (topLabelIndex = nextTopIndex, bottomLabelIndex = nextBottomIndex);
245
- }
246
- }
247
- }
248
- _shiftY(arcs, start, end, delta) {
249
- const direction = start < end ? 1 : -1;
250
- let index = start;
251
- for (;-1 !== index; ) {
252
- arcs[index].labelPosition.y += delta;
253
- const nextIndex = this._findNextVisibleIndex(arcs, index, end, direction);
254
- if (nextIndex >= 0 && nextIndex < arcs.length) {
255
- const {y1: curY1, y2: curY2} = arcs[index].getLabelBounds(), {y1: nextY1, y2: nextY2} = arcs[nextIndex].getLabelBounds();
256
- if (direction > 0 && curY2 < nextY1 || direction < 0 && curY1 > nextY2) return index;
257
- }
258
- index = nextIndex;
259
- }
260
- return end;
261
- }
262
- _findNextVisibleIndex(arcs, start, end, direction) {
263
- const diff = (end - start) * direction;
264
- for (let i = 1; i <= diff; i++) {
265
- const index = start + i * direction;
266
- if (arcs[index].labelVisible) return index;
267
- }
268
- return -1;
269
- }
270
- _computePointB(arc, r, attribute, currentMarks) {
271
- var _a, _b, _c, _d;
272
- const labelConfig = attribute, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = labelConfig.line.line1MinLength;
273
- if ("none" === labelConfig.layout.strategy) arc.pointB = {
274
- x: arc.outerCenter.x,
275
- y: arc.outerCenter.y
276
- }; else {
277
- const center = {
278
- x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
279
- y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
280
- }, 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;
281
- (0, vutils_2.isValidNumber)(x) ? arc.pointB = {
282
- x: center.x + x * ((0, util_1.isQuadrantLeft)(quadrant) ? -1 : 1),
283
- y: labelPosition.y
284
- } : arc.pointB = {
285
- x: NaN,
286
- y: NaN
287
- };
288
- }
289
- }
290
- _storeY(arcs) {
291
- for (const arc of arcs) arc.labelVisible && (arc.lastLabelY = arc.labelPosition.y);
292
- }
293
- _computeYRange(arc, attribute, currentMarks) {
294
- var _a, _b, _c, _d;
295
- const plotRect = {
296
- width: 2 * (null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0),
297
- height: 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0)
298
- }, 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;
299
- let a, b, c;
300
- if ((0, vutils_2.isNumberClose)(width / 2, cx)) a = 0, b = 1, c = -cy; else if ((0,
301
- vutils_2.isNumberClose)(height / 2, cy)) a = 1, b = 0, c = -cx; else {
302
- const k = -1 / (cy / cx);
303
- a = k, b = -1, c = cy - k * cx;
304
- }
305
- const points = (0, util_1.lineCirclePoints)(a, b, c, line1MinLength + radius - r, 0, r);
306
- if (points.length < 2) return;
307
- let min, max;
308
- points[0].x > points[1].x && points.reverse(), points[0].x < 0 ? (0, vutils_2.isNumberClose)(points[0].y, points[1].y) ? Math.abs(arc.middleAngle) < Math.PI / 2 ? (min = 0,
309
- max = points[1].y + height / 2) : (min = points[1].y + height / 2, max = height) : points[0].y < points[1].y ? (min = 0,
310
- 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,
311
- max = Math.max(points[0].y, points[1].y) + height / 2), arc.labelYRange = [ min, max ];
312
- }
313
- _computeLayoutRadius(halfYLength, attribute, currentMarks) {
314
- 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;
315
- return Math.max((a ** 2 + halfYLength ** 2) / (2 * a), outerR);
316
- }
317
- _findNeighborIndex(arcs, priorityArc) {
318
- const index = priorityArc.originIndex;
319
- let lastIndex = -1, nextIndex = -1;
320
- for (let i = index - 1; i >= 0; i--) if (arcs[i].labelVisible) {
321
- lastIndex = i;
322
- break;
323
- }
324
- for (let i = index + 1; i < arcs.length; i++) if (arcs[i].labelVisible) {
325
- nextIndex = i;
326
- break;
327
- }
328
- return {
329
- lastIndex: lastIndex,
330
- nextIndex: nextIndex
331
- };
332
- }
333
- _twoWayShift(arcs, lastArc, nextArc, nextIndex) {
334
- const delta = nextArc.getLabelBounds().y1 - lastArc.getLabelBounds().y2;
335
- if ((0, vutils_2.isLess)(delta, 0)) {
336
- const i = this._shiftY(arcs, nextIndex, arcs.length - 1, -delta);
337
- this._shiftY(arcs, i, 0, delta / 2);
338
- }
339
- }
340
- _restoreY(arcs) {
341
- for (const arc of arcs) arc.labelVisible && (arc.labelPosition.y = arc.lastLabelY);
342
- }
343
- _checkYRange(arcs) {
344
- for (const arc of arcs) {
345
- const {labelYRange: labelYRange, labelPosition: labelPosition} = arc;
346
- if (arc.labelVisible && labelYRange && ((0, vutils_2.isLess)(labelPosition.y, labelYRange[0]) || (0,
347
- vutils_2.isGreater)(labelPosition.y, labelYRange[1]))) return !1;
348
- }
349
- return !0;
350
- }
351
- _coverLabels(arcs) {
352
- if (arcs.length <= 1) return;
353
- let lastBounds = arcs[0].getLabelBounds();
354
- for (let i = 1; i < arcs.length; i++) {
355
- const bounds = arcs[i].getLabelBounds();
356
- (0, util_1.checkBoundsOverlap)(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
357
- }
358
- }
359
- computeRadius(r, width, height, k) {
360
- return this.computeLayoutRadius(width || 0, height || 0) * r * ((0, vutils_2.isNil)(k) ? 1 : k);
361
- }
362
- computeLayoutRadius(width, height) {
363
- return Math.min(width / 2, height / 2);
364
- }
365
- computeLayoutOuterRadius(r, width, height) {
366
- return r / (Math.min(width, height) / 2);
367
- }
368
- computeDatumRadius(width, height, outerRadius) {
369
- const outerRadiusRatio = this.computeLayoutOuterRadius(outerRadius, width, height);
370
- return this.computeLayoutRadius(width || 0, height || 0) * outerRadiusRatio;
371
- }
372
- }
373
-
374
- exports.ArcLabel = ArcLabel, ArcLabel.defaultAttributes = {
375
- coverEnable: !1,
376
- spaceWidth: 5,
377
- layoutArcGap: 6,
378
- textStyle: {
379
- visible: !0,
380
- fontSize: 14,
381
- fontWeight: "normal",
382
- fillOpacity: 1
383
- },
384
- position: "outside",
385
- offset: 0,
386
- line: {
387
- visible: !0,
388
- line1MinLength: 20,
389
- line2MinLength: 10
390
- },
391
- layout: {
392
- align: "arc",
393
- strategy: "priority",
394
- tangentConstraint: !0
395
- }
396
- };
397
- //# sourceMappingURL=arc.js.map