@visactor/vrender-components 0.14.3-alpha.0 → 0.14.3-alpha.1

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 (69) hide show
  1. package/cjs/axis/base.d.ts +4 -0
  2. package/cjs/axis/base.js +3 -5
  3. package/cjs/axis/base.js.map +1 -1
  4. package/cjs/axis/circle.d.ts +5 -1
  5. package/cjs/axis/circle.js +6 -0
  6. package/cjs/axis/circle.js.map +1 -1
  7. package/cjs/axis/line.d.ts +5 -0
  8. package/cjs/axis/line.js +10 -3
  9. package/cjs/axis/line.js.map +1 -1
  10. package/cjs/axis/overlap/auto-rotate.d.ts +9 -1
  11. package/cjs/axis/overlap/auto-rotate.js +41 -30
  12. package/cjs/axis/overlap/auto-rotate.js.map +1 -1
  13. package/cjs/index.d.ts +1 -1
  14. package/cjs/index.js +1 -1
  15. package/cjs/index.js.map +1 -1
  16. package/cjs/label/arc.d.ts +2 -2
  17. package/cjs/label/arc.js +33 -26
  18. package/cjs/label/arc.js.map +1 -1
  19. package/cjs/label/base.d.ts +1 -1
  20. package/cjs/label/base.js +11 -23
  21. package/cjs/label/base.js.map +1 -1
  22. package/cjs/label/type.d.ts +2 -0
  23. package/cjs/label/type.js.map +1 -1
  24. package/cjs/legend/constant.d.ts +2 -1
  25. package/cjs/legend/constant.js +1 -1
  26. package/cjs/legend/constant.js.map +1 -1
  27. package/cjs/legend/discrete/discrete.js +26 -13
  28. package/cjs/legend/discrete/discrete.js.map +1 -1
  29. package/cjs/marker/base.d.ts +3 -0
  30. package/cjs/marker/base.js +25 -6
  31. package/cjs/marker/base.js.map +1 -1
  32. package/cjs/marker/type.d.ts +6 -0
  33. package/cjs/marker/type.js.map +1 -1
  34. package/dist/index.js +200 -120
  35. package/dist/index.min.js +1 -1
  36. package/es/axis/base.d.ts +4 -0
  37. package/es/axis/base.js +3 -5
  38. package/es/axis/base.js.map +1 -1
  39. package/es/axis/circle.d.ts +5 -1
  40. package/es/axis/circle.js +6 -0
  41. package/es/axis/circle.js.map +1 -1
  42. package/es/axis/line.d.ts +5 -0
  43. package/es/axis/line.js +11 -3
  44. package/es/axis/line.js.map +1 -1
  45. package/es/axis/overlap/auto-rotate.d.ts +9 -1
  46. package/es/axis/overlap/auto-rotate.js +38 -28
  47. package/es/axis/overlap/auto-rotate.js.map +1 -1
  48. package/es/index.d.ts +1 -1
  49. package/es/index.js +1 -1
  50. package/es/index.js.map +1 -1
  51. package/es/label/arc.d.ts +2 -2
  52. package/es/label/arc.js +32 -26
  53. package/es/label/arc.js.map +1 -1
  54. package/es/label/base.d.ts +1 -1
  55. package/es/label/base.js +11 -23
  56. package/es/label/base.js.map +1 -1
  57. package/es/label/type.d.ts +2 -0
  58. package/es/label/type.js.map +1 -1
  59. package/es/legend/constant.d.ts +2 -1
  60. package/es/legend/constant.js +1 -1
  61. package/es/legend/constant.js.map +1 -1
  62. package/es/legend/discrete/discrete.js +26 -13
  63. package/es/legend/discrete/discrete.js.map +1 -1
  64. package/es/marker/base.d.ts +3 -0
  65. package/es/marker/base.js +26 -5
  66. package/es/marker/base.js.map +1 -1
  67. package/es/marker/type.d.ts +6 -0
  68. package/es/marker/type.js.map +1 -1
  69. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import type { IText } from '@visactor/vrender';
1
+ import type { IText, TextAlignType, TextBaselineType } from '@visactor/vrender';
2
2
  type RotateConfig = {
3
3
  orient: string;
4
4
  labelRotateAngle?: number[];
@@ -6,4 +6,12 @@ type RotateConfig = {
6
6
  export declare function autoRotate(items: IText[], rotateConfig: RotateConfig): void;
7
7
  export declare function rotateYAxis(orient: string, items: IText[]): void;
8
8
  export declare function rotateXAxis(orient: string, items: IText[]): void;
9
+ export declare function getXAxisLabelAlign(orient: string, angle?: number): {
10
+ textAlign: TextAlignType;
11
+ textBaseline: TextBaselineType;
12
+ };
13
+ export declare function getYAxisLabelAlign(orient: string, angle?: number): {
14
+ textAlign: TextAlignType;
15
+ textBaseline: TextBaselineType;
16
+ };
9
17
  export {};
@@ -55,41 +55,51 @@ function genRotateBounds(items) {
55
55
  }));
56
56
  }
57
57
 
58
+ function clampAngle(angle = 0) {
59
+ if (angle < 0) for (;angle < 0; ) angle += 2 * Math.PI;
60
+ if (angle > 0) for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
61
+ return angle;
62
+ }
63
+
58
64
  export function rotateYAxis(orient, items) {
59
- let align = [ "right", "right", "center", "left", "center", "left", "center", "right", "right" ], baseline = [ "middle", "middle", "top", "top", "middle", "middle", "bottom", "bottom", "middle" ];
60
- "right" === orient && (align = [ "left", "right", "right", "right", "left", "left", "left", "left", "right" ],
61
- baseline = [ "middle", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]),
62
65
  items.forEach(((item, i) => {
63
- let angle = item.attribute.angle || 0;
64
- if (angle < 0) for (;angle < 0; ) angle += 2 * Math.PI;
65
- if (angle > 0) for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
66
- const step = angle / (.5 * Math.PI);
67
- let index;
68
- index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
69
- item.setAttributes({
70
- textAlign: align[index],
71
- textBaseline: baseline[index],
72
- angle: angle
73
- });
66
+ item.setAttributes(Object.assign(Object.assign({}, getYAxisLabelAlign(orient, item.attribute.angle)), {
67
+ angle: clampAngle(item.attribute.angle)
68
+ }));
74
69
  }));
75
70
  }
76
71
 
77
72
  export function rotateXAxis(orient, items) {
78
- let align = [ "center", "left", "left", "left", "center", "right", "right", "right", "left" ], baseline = [ "top", "top", "middle", "bottom", "bottom", "bottom", "middle", "top", "top" ];
79
- "top" === orient && (align = [ "center", "right", "right", "right", "center", "left", "left", "left", "right" ],
80
- baseline = [ "bottom", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]),
81
73
  items.forEach((item => {
82
- let angle = item.attribute.angle || 0;
83
- if (angle < 0) for (;angle < 0; ) angle += 2 * Math.PI;
84
- if (angle > 0) for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
85
- const step = angle / (.5 * Math.PI);
86
- let index;
87
- index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
88
- item.setAttributes({
89
- textAlign: align[index],
90
- textBaseline: baseline[index],
91
- angle: angle
92
- });
74
+ item.setAttributes(Object.assign(Object.assign({}, getXAxisLabelAlign(orient, item.attribute.angle)), {
75
+ angle: clampAngle(item.attribute.angle)
76
+ }));
93
77
  }));
94
78
  }
79
+
80
+ export function getXAxisLabelAlign(orient, angle = 0) {
81
+ let align = [ "center", "left", "left", "left", "center", "right", "right", "right", "left" ], baseline = [ "top", "top", "middle", "bottom", "bottom", "bottom", "middle", "top", "top" ];
82
+ "top" === orient && (align = [ "center", "right", "right", "right", "center", "left", "left", "left", "right" ],
83
+ baseline = [ "bottom", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]);
84
+ const step = (angle = clampAngle(angle)) / (.5 * Math.PI);
85
+ let index;
86
+ return index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
87
+ {
88
+ textAlign: align[index],
89
+ textBaseline: baseline[index]
90
+ };
91
+ }
92
+
93
+ export function getYAxisLabelAlign(orient, angle = 0) {
94
+ let align = [ "right", "right", "center", "left", "center", "left", "center", "right", "right" ], baseline = [ "middle", "middle", "top", "top", "middle", "middle", "bottom", "bottom", "middle" ];
95
+ "right" === orient && (align = [ "left", "right", "right", "right", "left", "left", "left", "left", "right" ],
96
+ baseline = [ "middle", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]);
97
+ const step = (angle = clampAngle(angle)) / (.5 * Math.PI);
98
+ let index;
99
+ return index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
100
+ {
101
+ textAlign: align[index],
102
+ textBaseline: baseline[index]
103
+ };
104
+ }
95
105
  //# sourceMappingURL=auto-rotate.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["axis/overl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,CAAC,EAAE;gBAC3B,KAAK,IAAI,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;aACtB;SACF;QACD,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;QACrC,IAAI,KAAK,CAAC;QACV,IAAI,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAC9B;aAAM;YACL,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAClC;QACD,IAAI,CAAC,aAAa,CAAC;YACjB,SAAS,EAAE,KAAK,CAAC,KAAK,CAAkB;YACxC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAqB;YACjD,KAAK;SACN,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","file":"auto-rotate.js","sourcesContent":["/**\n * @description 坐标轴标签自动旋转\n */\nimport type { IText, TextAlignType, TextBaselineType } from '@visactor/vrender';\nimport { degreeToRadian, isEmpty, isRotateAABBIntersect } from '@visactor/vutils';\n\ntype RotateConfig = {\n /**\n * 坐标轴的显示位置\n */\n orient: string;\n /**\n * 自动旋转的可选角度\n */\n labelRotateAngle?: number[];\n};\n\nexport function autoRotate(items: IText[], rotateConfig: RotateConfig) {\n if (isEmpty(items)) {\n return;\n }\n\n const { orient, labelRotateAngle = [0, 45, 90] } = rotateConfig;\n if (labelRotateAngle.length === 0 || items.some(item => !!item.attribute.angle)) {\n return;\n }\n\n let i = 0;\n let n = 0;\n if (labelRotateAngle && labelRotateAngle.length > 0) {\n n = labelRotateAngle.length;\n }\n\n while (i < n) {\n const angle = labelRotateAngle[i++];\n items.forEach(item => {\n // item.angle = angle;\n item.attribute.angle = degreeToRadian(angle);\n });\n tryRotate(orient, items);\n if (!hasIntersect(items)) {\n break;\n }\n }\n}\n\nfunction hasIntersect(items: IText[]): boolean {\n for (let i = 1; i < items.length; i++) {\n if (itemIntersect(items[i - 1], items[i])) {\n return true;\n }\n }\n return false;\n}\n\nfunction itemIntersect(item1: IText, item2: IText) {\n return isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true);\n}\n\nfunction tryRotate(orient: string, items: IText[]) {\n // 针对 top bottom轴的自动旋转逻辑\n if (orient === 'bottom' || orient === 'top') {\n rotateXAxis(orient, items);\n }\n if (orient === 'left' || orient === 'right') {\n rotateYAxis(orient, items);\n }\n // 先旋转,再计算这个limit,避免算limit后发现不需要旋转,导致莫名的水平limit\n genRotateBounds(items);\n}\n\nfunction rotate(x: number, y: number, deg: number, originX: number, originY: number) {\n return {\n x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,\n y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY\n };\n}\n\n// 计算水平情况下的包围盒\nfunction genNormalBounds(item: IText) {\n const bounds = item.AABBBounds;\n\n return {\n x1: bounds.x1,\n x2: bounds.x2,\n y1: bounds.y1,\n y2: bounds.y2,\n centerX: item.attribute.x,\n centerY: item.attribute.y,\n angle: item.attribute.angle\n };\n}\n\nfunction genRotateBounds(items: IText[]) {\n items.forEach(item => {\n // 计算水平情况下的包围盒\n const bounds = genNormalBounds(item);\n // 旋转\n const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);\n const deltaX = rotatedCenter.x - bounds.centerX;\n const deltaY = rotatedCenter.y - bounds.centerY;\n bounds.x1 += deltaX;\n bounds.x2 += deltaX;\n bounds.y1 += deltaY;\n bounds.y2 += deltaY;\n bounds.centerX += deltaX;\n bounds.centerY += deltaY;\n item.rotatedBounds = bounds;\n });\n}\n\nexport function rotateYAxis(orient: string, items: IText[]) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['right', 'right', 'center', 'left', 'center', 'left', 'center', 'right', 'right'];\n let baseline = ['middle', 'middle', 'top', 'top', 'middle', 'middle', 'bottom', 'bottom', 'middle'];\n\n if (orient === 'right') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['left', 'right', 'right', 'right', 'left', 'left', 'left', 'left', 'right'];\n baseline = ['middle', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n // 由于左右轴会裁切,所以上下两个label需要额外处理,做tighten处理\n items.forEach((item, i) => {\n let angle = item.attribute.angle || 0;\n if (angle < 0) {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n }\n if (angle > 0) {\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n }\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n item.setAttributes({\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType,\n angle: angle\n });\n });\n}\n\nexport function rotateXAxis(orient: string, items: IText[]) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['center', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'left'];\n let baseline = ['top', 'top', 'middle', 'bottom', 'bottom', 'bottom', 'middle', 'top', 'top'];\n if (orient === 'top') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['center', 'right', 'right', 'right', 'center', 'left', 'left', 'left', 'right'];\n baseline = ['bottom', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n items.forEach(item => {\n let angle = item.attribute.angle || 0;\n // todo angle为0跳过会导致下轴高度有bug\n // if (angle === 0) return;\n if (angle < 0) {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n }\n if (angle > 0) {\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n }\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n item.setAttributes({\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType,\n angle\n });\n });\n}\n"]}
1
+ {"version":3,"sources":["axis/overlap/auto-rotate.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAalF,MAAM,UAAU,UAAU,CAAC,KAAc,EAAE,YAA0B;IACnE,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,OAAO;KACR;IAED,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC;IAChE,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAC/E,OAAO;KACR;IAED,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;QACnD,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC;KAC7B;IAED,OAAO,CAAC,GAAG,CAAC,EAAE;QACZ,MAAM,KAAK,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;QACpC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAEnB,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;YACxB,MAAM;SACP;KACF;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC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AQ,EAAE,QAAQ,CAAC,CAAC;IAEpG,IAAI,MAAM,KAAK,OAAO,EAAE;QAEtB,KAAK,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACrF,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;KAC9F;IAED,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC1B,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC;IACV,IAAI,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QAC7B,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC9B;SAAM;QACL,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KAClC;IAED,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,KAAK,CAAkB;QACxC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAqB;KAClD,CAAC;AACJ,CAAC","file":"auto-rotate.js","sourcesContent":["/**\n * @description 坐标轴标签自动旋转\n */\nimport type { IText, TextAlignType, TextBaselineType } from '@visactor/vrender';\nimport { degreeToRadian, isEmpty, isRotateAABBIntersect } from '@visactor/vutils';\n\ntype RotateConfig = {\n /**\n * 坐标轴的显示位置\n */\n orient: string;\n /**\n * 自动旋转的可选角度\n */\n labelRotateAngle?: number[];\n};\n\nexport function autoRotate(items: IText[], rotateConfig: RotateConfig) {\n if (isEmpty(items)) {\n return;\n }\n\n const { orient, labelRotateAngle = [0, 45, 90] } = rotateConfig;\n if (labelRotateAngle.length === 0 || items.some(item => !!item.attribute.angle)) {\n return;\n }\n\n let i = 0;\n let n = 0;\n if (labelRotateAngle && labelRotateAngle.length > 0) {\n n = labelRotateAngle.length;\n }\n\n while (i < n) {\n const angle = labelRotateAngle[i++];\n items.forEach(item => {\n // item.angle = angle;\n item.attribute.angle = degreeToRadian(angle);\n });\n tryRotate(orient, items);\n if (!hasIntersect(items)) {\n break;\n }\n }\n}\n\nfunction hasIntersect(items: IText[]): boolean {\n for (let i = 1; i < items.length; i++) {\n if (itemIntersect(items[i - 1], items[i])) {\n return true;\n }\n }\n return false;\n}\n\nfunction itemIntersect(item1: IText, item2: IText) {\n return isRotateAABBIntersect(item1.rotatedBounds, item2.rotatedBounds, true);\n}\n\nfunction tryRotate(orient: string, items: IText[]) {\n // 针对 top bottom轴的自动旋转逻辑\n if (orient === 'bottom' || orient === 'top') {\n rotateXAxis(orient, items);\n }\n if (orient === 'left' || orient === 'right') {\n rotateYAxis(orient, items);\n }\n // 先旋转,再计算这个limit,避免算limit后发现不需要旋转,导致莫名的水平limit\n genRotateBounds(items);\n}\n\nfunction rotate(x: number, y: number, deg: number, originX: number, originY: number) {\n return {\n x: (x - originX) * Math.cos(deg) + (y - originY) * Math.sin(deg) + originX,\n y: (x - originX) * Math.sin(deg) + (originY - y) * Math.cos(deg) + originY\n };\n}\n\n// 计算水平情况下的包围盒\nfunction genNormalBounds(item: IText) {\n const bounds = item.AABBBounds;\n\n return {\n x1: bounds.x1,\n x2: bounds.x2,\n y1: bounds.y1,\n y2: bounds.y2,\n centerX: item.attribute.x,\n centerY: item.attribute.y,\n angle: item.attribute.angle\n };\n}\n\nfunction genRotateBounds(items: IText[]) {\n items.forEach(item => {\n // 计算水平情况下的包围盒\n const bounds = genNormalBounds(item);\n // 旋转\n const rotatedCenter = rotate(bounds.centerX, bounds.centerY, bounds.angle, item.attribute.x, item.attribute.y);\n const deltaX = rotatedCenter.x - bounds.centerX;\n const deltaY = rotatedCenter.y - bounds.centerY;\n bounds.x1 += deltaX;\n bounds.x2 += deltaX;\n bounds.y1 += deltaY;\n bounds.y2 += deltaY;\n bounds.centerX += deltaX;\n bounds.centerY += deltaY;\n item.rotatedBounds = bounds;\n });\n}\n\nfunction clampAngle(angle = 0) {\n if (angle < 0) {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n }\n if (angle > 0) {\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n }\n\n return angle;\n}\n\nexport function rotateYAxis(orient: string, items: IText[]) {\n // 由于左右轴会裁切,所以上下两个label需要额外处理,做tighten处理\n items.forEach((item, i) => {\n item.setAttributes({\n ...getYAxisLabelAlign(orient, item.attribute.angle),\n angle: clampAngle(item.attribute.angle)\n });\n });\n}\n\nexport function rotateXAxis(orient: string, items: IText[]) {\n items.forEach(item => {\n item.setAttributes({\n ...getXAxisLabelAlign(orient, item.attribute.angle),\n angle: clampAngle(item.attribute.angle)\n });\n });\n}\n\nexport function getXAxisLabelAlign(orient: string, angle: number = 0) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['center', 'left', 'left', 'left', 'center', 'right', 'right', 'right', 'left'];\n let baseline = ['top', 'top', 'middle', 'bottom', 'bottom', 'bottom', 'middle', 'top', 'top'];\n if (orient === 'top') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['center', 'right', 'right', 'right', 'center', 'left', 'left', 'left', 'right'];\n baseline = ['bottom', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n\n angle = clampAngle(angle);\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n\n return {\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType\n };\n}\n\nexport function getYAxisLabelAlign(orient: string, angle: number = 0) {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n let align = ['right', 'right', 'center', 'left', 'center', 'left', 'center', 'right', 'right'];\n let baseline = ['middle', 'middle', 'top', 'top', 'middle', 'middle', 'bottom', 'bottom', 'middle'];\n\n if (orient === 'right') {\n // 0, 0-90, 90, 90-180, 180, 180-270, 270, 270-360, 360\n align = ['left', 'right', 'right', 'right', 'left', 'left', 'left', 'left', 'right'];\n baseline = ['middle', 'bottom', 'middle', 'top', 'top', 'top', 'middle', 'bottom', 'bottom'];\n }\n\n angle = clampAngle(angle);\n const step = angle / (Math.PI * 0.5);\n let index;\n if (step === Math.floor(step)) {\n index = Math.floor(step) * 2;\n } else {\n index = Math.floor(step) * 2 + 1;\n }\n\n return {\n textAlign: align[index] as TextAlignType,\n textBaseline: baseline[index] as TextBaselineType\n };\n}\n"]}
package/es/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.14.3-alpha.0";
1
+ export declare const version = "0.14.3-alpha.1";
2
2
  export * from './core/base';
3
3
  export * from './scrollbar';
4
4
  export * from './tag';
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = "0.14.3-alpha.0";
1
+ export const version = "0.14.3-alpha.1";
2
2
 
3
3
  export * from "./core/base";
4
4
 
package/es/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.14.3-alpha.0\";\n\nexport * from './core/base';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './interface';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.14.3-alpha.1\";\n\nexport * from './core/base';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './interface';\n"]}
package/es/label/arc.d.ts CHANGED
@@ -40,7 +40,7 @@ export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
40
40
  x: number;
41
41
  y: number;
42
42
  } | undefined;
43
- protected layoutArcLabels(position: BaseLabelAttrs['position'], attribute: any, currentMarks?: IGraphic[], data?: any, textBoundsArray?: any): ArcInfo[];
43
+ protected layoutArcLabels(position: BaseLabelAttrs['position'], attribute: any, currentMarks?: IGraphic[], data?: any, textBoundsArray?: any, ellipsisWidth?: number): ArcInfo[];
44
44
  private _layoutInsideLabels;
45
45
  private _layoutOutsideLabels;
46
46
  private _computeX;
@@ -59,7 +59,7 @@ export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
59
59
  private _restoreY;
60
60
  private _checkYRange;
61
61
  private _coverLabels;
62
- protected computeRadius(r: number, width?: number, height?: number, k?: number): number;
62
+ protected computeRadius(r: number, width?: number, height?: number, centerOffset?: number, k?: number): number;
63
63
  protected computeLayoutRadius(width: number, height: number): number;
64
64
  private computeLayoutOuterRadius;
65
65
  private computeDatumRadius;
package/es/label/arc.js CHANGED
@@ -39,16 +39,17 @@ export class ArcLabel extends LabelBase {
39
39
  y: 0
40
40
  };
41
41
  }
42
- layoutArcLabels(position, attribute, currentMarks, data, textBoundsArray) {
43
- this._arcLeft.clear(), this._arcRight.clear();
44
- const {width: width, height: height} = attribute;
42
+ layoutArcLabels(position, attribute, currentMarks, data, textBoundsArray, ellipsisWidth) {
43
+ var _a;
44
+ this._arcLeft.clear(), this._arcRight.clear(), this._ellipsisWidth = ellipsisWidth;
45
+ const {width: width, height: height} = attribute, centerOffset = null !== (_a = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _a ? _a : 0;
45
46
  currentMarks.forEach(((currentMark, index) => {
46
47
  var _a, _b;
47
- const graphicAttribute = currentMark.attribute, radiusRatio = this.computeLayoutOuterRadius(graphicAttribute.outerRadius, width, height), radius = this.computeRadius(radiusRatio, width, height), center = {
48
+ const graphicAttribute = currentMark.attribute, radiusRatio = this.computeLayoutOuterRadius(graphicAttribute.outerRadius, width, height), radius = this.computeRadius(radiusRatio, width, height, centerOffset), center = {
48
49
  x: null !== (_a = null == graphicAttribute ? void 0 : graphicAttribute.x) && void 0 !== _a ? _a : 0,
49
50
  y: null !== (_b = null == graphicAttribute ? void 0 : graphicAttribute.y) && void 0 !== _b ? _b : 0
50
51
  }, item = data[index], textBounds = textBoundsArray[index], arcMiddleAngle = (graphicAttribute.startAngle + graphicAttribute.endAngle) / 2, intervalAngle = graphicAttribute.endAngle - graphicAttribute.startAngle, arcQuadrant = computeQuadrant(graphicAttribute.endAngle - intervalAngle / 2), arcMiddle = circlePoint(center.x, center.y, graphicAttribute.outerRadius, arcMiddleAngle), outerArcMiddle = circlePoint(center.x, center.y, radius + attribute.line.line1MinLength, arcMiddleAngle), arc = new ArcInfo(item, arcMiddle, outerArcMiddle, arcQuadrant, intervalAngle, arcMiddleAngle);
51
- arc.pointA = circlePoint(center.x, center.y, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttribute.outerRadius), arc.middleAngle),
52
+ arc.pointA = circlePoint(center.x, center.y, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttribute.outerRadius, centerOffset), arc.middleAngle),
52
53
  arc.labelSize = {
53
54
  width: textBounds.x2 - textBounds.x1,
54
55
  height: textBounds.y2 - textBounds.y1
@@ -60,14 +61,14 @@ export class ArcLabel extends LabelBase {
60
61
  arcs.push(...this._layoutOutsideLabels(leftArcs, attribute, currentMarks))), arcs;
61
62
  }
62
63
  _layoutInsideLabels(arcs, attribute, currentMarks) {
63
- var _a, _b, _c, _d;
64
+ var _a, _b, _c, _d, _e;
64
65
  const center = {
65
66
  x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
66
67
  y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
67
- }, 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;
68
+ }, centerOffset = null !== (_e = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _e ? _e : 0, 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;
68
69
  return arcs.forEach((arc => {
69
70
  var _a, _b;
70
- const {labelSize: labelSize, radian: radian} = arc, innerRadius = this.computeRadius(innerRadiusRatio, attribute.width, attribute.height, 1), outerRadius = this.computeRadius(outerRadiusRatio, attribute.width, attribute.height, 1);
71
+ const {labelSize: labelSize, radian: radian} = arc, innerRadius = this.computeRadius(innerRadiusRatio, attribute.width, attribute.height, centerOffset, 1), outerRadius = this.computeRadius(outerRadiusRatio, attribute.width, attribute.height, centerOffset, 1);
71
72
  let limit;
72
73
  if (radian < connectLineRadian(outerRadius, labelSize.height)) limit = 0; else {
73
74
  let minRadius;
@@ -125,14 +126,14 @@ export class ArcLabel extends LabelBase {
125
126
  })), arcs;
126
127
  }
127
128
  _computeX(arc, attribute, currentMarks) {
128
- var _a, _b, _c, _d, _e;
129
- 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,
130
- 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, {labelPosition: labelPosition, quadrant: quadrant, pointB: pointB} = arc;
129
+ var _a, _b, _c, _d, _e, _f;
130
+ const center_x = null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0, centerOffset = (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y,
131
+ null !== (_e = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _e ? _e : 0), plotLayout_width = 2 * center_x, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = attribute.line.line1MinLength, line2MinLength = attribute.line.line2MinLength, labelLayoutAlign = null === (_f = attribute.layout) || void 0 === _f ? void 0 : _f.align, spaceWidth = attribute.spaceWidth, {labelPosition: labelPosition, quadrant: quadrant, pointB: pointB} = arc;
131
132
  isValidNumber(pointB.x * pointB.y) || (arc.pointC = {
132
133
  x: NaN,
133
134
  y: NaN
134
135
  }, labelPosition.x = NaN, arc.labelLimit = 0);
135
- const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), flag = isQuadrantLeft(quadrant) ? -1 : 1;
136
+ const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height, centerOffset), flag = isQuadrantLeft(quadrant) ? -1 : 1;
136
137
  let cx = 0;
137
138
  let limit = (flag > 0 ? plotLayout_width - pointB.x : pointB.x) - line2MinLength - spaceWidth;
138
139
  "labelLine" === labelLayoutAlign && (cx = (radius + line1MinLength + line2MinLength) * flag + center_x,
@@ -151,17 +152,19 @@ export class ArcLabel extends LabelBase {
151
152
  default:
152
153
  cx = pointB.x + flag * line2MinLength;
153
154
  }
154
- if (labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.pointC = {
155
+ labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.labelLimit = labelWidth,
156
+ arc.pointC = {
155
157
  x: cx,
156
158
  y: labelPosition.y
157
- }, "edge" === labelLayoutAlign) {
159
+ };
160
+ const targetCenterOffset = .5 * (arc.labelLimit < arc.labelSize.width ? arc.labelLimit : arc.labelSize.width);
161
+ if ("edge" === labelLayoutAlign) {
158
162
  const alignOffset = 0;
159
- labelPosition.x = flag > 0 ? plotLayout_width + alignOffset : alignOffset;
163
+ labelPosition.x = (flag > 0 ? plotLayout_width + alignOffset : alignOffset) - flag * targetCenterOffset;
160
164
  } else {
161
165
  const alignOffset = 0;
162
- labelPosition.x = cx + alignOffset + flag * (spaceWidth + .5 * arc.labelSize.width);
166
+ labelPosition.x = cx + alignOffset + flag * (spaceWidth + .5 * targetCenterOffset);
163
167
  }
164
- arc.labelLimit = labelWidth;
165
168
  }
166
169
  _computeAlignOffset(align, labelWidth, alignFlag) {
167
170
  switch (align) {
@@ -267,7 +270,7 @@ export class ArcLabel extends LabelBase {
267
270
  return -1;
268
271
  }
269
272
  _computePointB(arc, r, attribute, currentMarks) {
270
- var _a, _b, _c, _d;
273
+ var _a, _b, _c, _d, _e;
271
274
  const labelConfig = attribute, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = labelConfig.line.line1MinLength;
272
275
  if ("none" === labelConfig.layout.strategy) arc.pointB = {
273
276
  x: arc.outerCenter.x,
@@ -276,7 +279,7 @@ export class ArcLabel extends LabelBase {
276
279
  const center = {
277
280
  x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
278
281
  y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
279
- }, 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;
282
+ }, centerOffset = null !== (_e = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _e ? _e : 0, radius = this.computeRadius(radiusRatio, attribute.width, attribute.height, centerOffset), {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;
280
283
  isValidNumber(x) ? arc.pointB = {
281
284
  x: center.x + x * (isQuadrantLeft(quadrant) ? -1 : 1),
282
285
  y: labelPosition.y
@@ -290,11 +293,11 @@ export class ArcLabel extends LabelBase {
290
293
  for (const arc of arcs) arc.labelVisible && (arc.lastLabelY = arc.labelPosition.y);
291
294
  }
292
295
  _computeYRange(arc, attribute, currentMarks) {
293
- var _a, _b, _c, _d;
296
+ var _a, _b, _c, _d, _e;
294
297
  const plotRect = {
295
298
  width: 2 * (null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0),
296
299
  height: 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0)
297
- }, 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;
300
+ }, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = attribute.line.line1MinLength, {width: width, height: height} = plotRect, centerOffset = null !== (_e = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _e ? _e : 0, radius = this.computeRadius(radiusRatio, attribute.width, attribute.height, centerOffset), r = this._computeLayoutRadius(height / 2, attribute, currentMarks), cx = Math.abs(arc.center.x - width / 2), cy = arc.center.y - height / 2;
298
301
  let a, b, c;
299
302
  if (isClose(width / 2, cx)) a = 0, b = 1, c = -cy; else if (isClose(height / 2, cy)) a = 1,
300
303
  b = 0, c = -cx; else {
@@ -310,7 +313,8 @@ export class ArcLabel extends LabelBase {
310
313
  max = Math.max(points[0].y, points[1].y) + height / 2), arc.labelYRange = [ min, max ];
311
314
  }
312
315
  _computeLayoutRadius(halfYLength, attribute, currentMarks) {
313
- 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;
316
+ var _a;
317
+ const labelConfig = attribute, layoutArcGap = labelConfig.layoutArcGap, line1MinLength = labelConfig.line.line1MinLength, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), centerOffset = null !== (_a = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _a ? _a : 0, outerR = this.computeRadius(radiusRatio, attribute.width, attribute.height, centerOffset) + line1MinLength, a = outerR - layoutArcGap;
314
318
  return Math.max((a ** 2 + halfYLength ** 2) / (2 * a), outerR);
315
319
  }
316
320
  _findNeighborIndex(arcs, priorityArc) {
@@ -354,8 +358,9 @@ export class ArcLabel extends LabelBase {
354
358
  checkBoundsOverlap(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
355
359
  }
356
360
  }
357
- computeRadius(r, width, height, k) {
358
- return this.computeLayoutRadius(width || 0, height || 0) * r * (isNil(k) ? 1 : k);
361
+ computeRadius(r, width, height, centerOffset, k) {
362
+ var _a;
363
+ return null !== (_a = this.computeLayoutRadius(width || 0, height || 0) * r * (isNil(k) ? 1 : k) + centerOffset) && void 0 !== _a ? _a : 0;
359
364
  }
360
365
  computeLayoutRadius(width, height) {
361
366
  return Math.min(width / 2, height / 2);
@@ -363,9 +368,10 @@ export class ArcLabel extends LabelBase {
363
368
  computeLayoutOuterRadius(r, width, height) {
364
369
  return r / (Math.min(width, height) / 2);
365
370
  }
366
- computeDatumRadius(width, height, outerRadius) {
371
+ computeDatumRadius(width, height, outerRadius, centerOffset) {
372
+ var _a;
367
373
  const outerRadiusRatio = this.computeLayoutOuterRadius(outerRadius, width, height);
368
- return this.computeLayoutRadius(width || 0, height || 0) * outerRadiusRatio;
374
+ return null !== (_a = this.computeLayoutRadius(width || 0, height || 0) * outerRadiusRatio + centerOffset) && void 0 !== _a ? _a : 0;
369
375
  }
370
376
  }
371
377