@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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- }), exports.rotateXAxis = exports.rotateYAxis = exports.autoRotate = void 0;
5
+ }), exports.getYAxisLabelAlign = exports.getXAxisLabelAlign = exports.rotateXAxis = exports.rotateYAxis = exports.autoRotate = void 0;
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils");
8
8
 
@@ -61,43 +61,54 @@ function genRotateBounds(items) {
61
61
  }));
62
62
  }
63
63
 
64
+ function clampAngle(angle = 0) {
65
+ if (angle < 0) for (;angle < 0; ) angle += 2 * Math.PI;
66
+ if (angle > 0) for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
67
+ return angle;
68
+ }
69
+
64
70
  function rotateYAxis(orient, items) {
65
- let align = [ "right", "right", "center", "left", "center", "left", "center", "right", "right" ], baseline = [ "middle", "middle", "top", "top", "middle", "middle", "bottom", "bottom", "middle" ];
66
- "right" === orient && (align = [ "left", "right", "right", "right", "left", "left", "left", "left", "right" ],
67
- baseline = [ "middle", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]),
68
71
  items.forEach(((item, i) => {
69
- let angle = item.attribute.angle || 0;
70
- if (angle < 0) for (;angle < 0; ) angle += 2 * Math.PI;
71
- if (angle > 0) for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
72
- const step = angle / (.5 * Math.PI);
73
- let index;
74
- index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
75
- item.setAttributes({
76
- textAlign: align[index],
77
- textBaseline: baseline[index],
78
- angle: angle
79
- });
72
+ item.setAttributes(Object.assign(Object.assign({}, getYAxisLabelAlign(orient, item.attribute.angle)), {
73
+ angle: clampAngle(item.attribute.angle)
74
+ }));
80
75
  }));
81
76
  }
82
77
 
83
78
  function rotateXAxis(orient, items) {
84
- let align = [ "center", "left", "left", "left", "center", "right", "right", "right", "left" ], baseline = [ "top", "top", "middle", "bottom", "bottom", "bottom", "middle", "top", "top" ];
85
- "top" === orient && (align = [ "center", "right", "right", "right", "center", "left", "left", "left", "right" ],
86
- baseline = [ "bottom", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]),
87
79
  items.forEach((item => {
88
- let angle = item.attribute.angle || 0;
89
- if (angle < 0) for (;angle < 0; ) angle += 2 * Math.PI;
90
- if (angle > 0) for (;angle >= 2 * Math.PI; ) angle -= 2 * Math.PI;
91
- const step = angle / (.5 * Math.PI);
92
- let index;
93
- index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
94
- item.setAttributes({
95
- textAlign: align[index],
96
- textBaseline: baseline[index],
97
- angle: angle
98
- });
80
+ item.setAttributes(Object.assign(Object.assign({}, getXAxisLabelAlign(orient, item.attribute.angle)), {
81
+ angle: clampAngle(item.attribute.angle)
82
+ }));
99
83
  }));
100
84
  }
101
85
 
102
- exports.autoRotate = autoRotate, exports.rotateYAxis = rotateYAxis, exports.rotateXAxis = rotateXAxis;
86
+ function getXAxisLabelAlign(orient, angle = 0) {
87
+ let align = [ "center", "left", "left", "left", "center", "right", "right", "right", "left" ], baseline = [ "top", "top", "middle", "bottom", "bottom", "bottom", "middle", "top", "top" ];
88
+ "top" === orient && (align = [ "center", "right", "right", "right", "center", "left", "left", "left", "right" ],
89
+ baseline = [ "bottom", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]);
90
+ const step = (angle = clampAngle(angle)) / (.5 * Math.PI);
91
+ let index;
92
+ return index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
93
+ {
94
+ textAlign: align[index],
95
+ textBaseline: baseline[index]
96
+ };
97
+ }
98
+
99
+ function getYAxisLabelAlign(orient, angle = 0) {
100
+ let align = [ "right", "right", "center", "left", "center", "left", "center", "right", "right" ], baseline = [ "middle", "middle", "top", "top", "middle", "middle", "bottom", "bottom", "middle" ];
101
+ "right" === orient && (align = [ "left", "right", "right", "right", "left", "left", "left", "left", "right" ],
102
+ baseline = [ "middle", "bottom", "middle", "top", "top", "top", "middle", "bottom", "bottom" ]);
103
+ const step = (angle = clampAngle(angle)) / (.5 * Math.PI);
104
+ let index;
105
+ return index = step === Math.floor(step) ? 2 * Math.floor(step) : 2 * Math.floor(step) + 1,
106
+ {
107
+ textAlign: align[index],
108
+ textBaseline: baseline[index]
109
+ };
110
+ }
111
+
112
+ exports.autoRotate = autoRotate, exports.rotateYAxis = rotateYAxis, exports.rotateXAxis = rotateXAxis,
113
+ exports.getXAxisLabelAlign = getXAxisLabelAlign, exports.getYAxisLabelAlign = getYAxisLabelAlign;
103
114
  //# sourceMappingURL=auto-rotate.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["axis/overlap/auto-rotate.ts"],"names":[],"mappings":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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;AApCD,kCAoCC","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,6CAAkF;AAalF,SAAgB,UAAU,CAAC,KAAc,EAAE,YAA0B;IACnE,IAAI,IAAA,gBAAO,EAAC,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,IAAA,uBAAc,EAAC,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;AA3BD,gCA2BC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE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AAM,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;AAxBD,gDAwBC","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/cjs/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/cjs/index.js CHANGED
@@ -17,7 +17,7 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
17
17
 
18
18
  Object.defineProperty(exports, "__esModule", {
19
19
  value: !0
20
- }), exports.version = void 0, exports.version = "0.14.3-alpha.0", __exportStar(require("./core/base"), exports),
20
+ }), exports.version = void 0, exports.version = "0.14.3-alpha.1", __exportStar(require("./core/base"), exports),
21
21
  __exportStar(require("./scrollbar"), exports), __exportStar(require("./tag"), exports),
22
22
  __exportStar(require("./poptip"), exports), __exportStar(require("./crosshair"), exports),
23
23
  __exportStar(require("./label"), exports), __exportStar(require("./axis"), exports),
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B","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,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B","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"]}
@@ -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/cjs/label/arc.js CHANGED
@@ -43,19 +43,20 @@ class ArcLabel extends base_1.LabelBase {
43
43
  y: 0
44
44
  };
45
45
  }
46
- layoutArcLabels(position, attribute, currentMarks, data, textBoundsArray) {
47
- this._arcLeft.clear(), this._arcRight.clear();
48
- const {width: width, height: height} = attribute;
46
+ layoutArcLabels(position, attribute, currentMarks, data, textBoundsArray, ellipsisWidth) {
47
+ var _a;
48
+ this._arcLeft.clear(), this._arcRight.clear(), this._ellipsisWidth = ellipsisWidth;
49
+ const {width: width, height: height} = attribute, centerOffset = null !== (_a = null == attribute ? void 0 : attribute.centerOffset) && void 0 !== _a ? _a : 0;
49
50
  currentMarks.forEach(((currentMark, index) => {
50
51
  var _a, _b;
51
- const graphicAttribute = currentMark.attribute, radiusRatio = this.computeLayoutOuterRadius(graphicAttribute.outerRadius, width, height), radius = this.computeRadius(radiusRatio, width, height), center = {
52
+ const graphicAttribute = currentMark.attribute, radiusRatio = this.computeLayoutOuterRadius(graphicAttribute.outerRadius, width, height), radius = this.computeRadius(radiusRatio, width, height, centerOffset), center = {
52
53
  x: null !== (_a = null == graphicAttribute ? void 0 : graphicAttribute.x) && void 0 !== _a ? _a : 0,
53
54
  y: null !== (_b = null == graphicAttribute ? void 0 : graphicAttribute.y) && void 0 !== _b ? _b : 0
54
55
  }, item = data[index], textBounds = textBoundsArray[index], arcMiddleAngle = (graphicAttribute.startAngle + graphicAttribute.endAngle) / 2, intervalAngle = graphicAttribute.endAngle - graphicAttribute.startAngle, arcQuadrant = (0,
55
56
  util_1.computeQuadrant)(graphicAttribute.endAngle - intervalAngle / 2), arcMiddle = (0,
56
57
  util_1.circlePoint)(center.x, center.y, graphicAttribute.outerRadius, arcMiddleAngle), outerArcMiddle = (0,
57
58
  util_1.circlePoint)(center.x, center.y, radius + attribute.line.line1MinLength, arcMiddleAngle), arc = new ArcInfo(item, arcMiddle, outerArcMiddle, arcQuadrant, intervalAngle, arcMiddleAngle);
58
- arc.pointA = (0, util_1.circlePoint)(center.x, center.y, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttribute.outerRadius), arc.middleAngle),
59
+ arc.pointA = (0, util_1.circlePoint)(center.x, center.y, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttribute.outerRadius, centerOffset), arc.middleAngle),
59
60
  arc.labelSize = {
60
61
  width: textBounds.x2 - textBounds.x1,
61
62
  height: textBounds.y2 - textBounds.y1
@@ -68,14 +69,14 @@ class ArcLabel extends base_1.LabelBase {
68
69
  arcs.push(...this._layoutOutsideLabels(leftArcs, attribute, currentMarks))), arcs;
69
70
  }
70
71
  _layoutInsideLabels(arcs, attribute, currentMarks) {
71
- var _a, _b, _c, _d;
72
+ var _a, _b, _c, _d, _e;
72
73
  const center = {
73
74
  x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
74
75
  y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
75
- }, 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;
76
+ }, 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;
76
77
  return arcs.forEach((arc => {
77
78
  var _a, _b;
78
- const {labelSize: labelSize, radian: radian} = arc, innerRadius = this.computeRadius(innerRadiusRatio, attribute.width, attribute.height, 1), outerRadius = this.computeRadius(outerRadiusRatio, attribute.width, attribute.height, 1);
79
+ 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);
79
80
  let limit;
80
81
  if (radian < (0, util_1.connectLineRadian)(outerRadius, labelSize.height)) limit = 0; else {
81
82
  let minRadius;
@@ -134,14 +135,14 @@ class ArcLabel extends base_1.LabelBase {
134
135
  })), arcs;
135
136
  }
136
137
  _computeX(arc, attribute, currentMarks) {
137
- var _a, _b, _c, _d, _e;
138
- 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,
139
- 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;
138
+ var _a, _b, _c, _d, _e, _f;
139
+ 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,
140
+ 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;
140
141
  (0, vutils_1.isValidNumber)(pointB.x * pointB.y) || (arc.pointC = {
141
142
  x: NaN,
142
143
  y: NaN
143
144
  }, labelPosition.x = NaN, arc.labelLimit = 0);
144
- const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), flag = (0,
145
+ const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height, centerOffset), flag = (0,
145
146
  util_1.isQuadrantLeft)(quadrant) ? -1 : 1;
146
147
  let cx = 0;
147
148
  let limit = (flag > 0 ? plotLayout_width - pointB.x : pointB.x) - line2MinLength - spaceWidth;
@@ -161,17 +162,19 @@ class ArcLabel extends base_1.LabelBase {
161
162
  default:
162
163
  cx = pointB.x + flag * line2MinLength;
163
164
  }
164
- if (labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.pointC = {
165
+ labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.labelLimit = labelWidth,
166
+ arc.pointC = {
165
167
  x: cx,
166
168
  y: labelPosition.y
167
- }, "edge" === labelLayoutAlign) {
169
+ };
170
+ const targetCenterOffset = .5 * (arc.labelLimit < arc.labelSize.width ? arc.labelLimit : arc.labelSize.width);
171
+ if ("edge" === labelLayoutAlign) {
168
172
  const alignOffset = 0;
169
- labelPosition.x = flag > 0 ? plotLayout_width + alignOffset : alignOffset;
173
+ labelPosition.x = (flag > 0 ? plotLayout_width + alignOffset : alignOffset) - flag * targetCenterOffset;
170
174
  } else {
171
175
  const alignOffset = 0;
172
- labelPosition.x = cx + alignOffset + flag * (spaceWidth + .5 * arc.labelSize.width);
176
+ labelPosition.x = cx + alignOffset + flag * (spaceWidth + .5 * targetCenterOffset);
173
177
  }
174
- arc.labelLimit = labelWidth;
175
178
  }
176
179
  _computeAlignOffset(align, labelWidth, alignFlag) {
177
180
  switch (align) {
@@ -279,7 +282,7 @@ class ArcLabel extends base_1.LabelBase {
279
282
  return -1;
280
283
  }
281
284
  _computePointB(arc, r, attribute, currentMarks) {
282
- var _a, _b, _c, _d;
285
+ var _a, _b, _c, _d, _e;
283
286
  const labelConfig = attribute, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = labelConfig.line.line1MinLength;
284
287
  if ("none" === labelConfig.layout.strategy) arc.pointB = {
285
288
  x: arc.outerCenter.x,
@@ -288,7 +291,7 @@ class ArcLabel extends base_1.LabelBase {
288
291
  const center = {
289
292
  x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
290
293
  y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
291
- }, 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;
294
+ }, 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;
292
295
  (0, vutils_1.isValidNumber)(x) ? arc.pointB = {
293
296
  x: center.x + x * ((0, util_1.isQuadrantLeft)(quadrant) ? -1 : 1),
294
297
  y: labelPosition.y
@@ -302,11 +305,11 @@ class ArcLabel extends base_1.LabelBase {
302
305
  for (const arc of arcs) arc.labelVisible && (arc.lastLabelY = arc.labelPosition.y);
303
306
  }
304
307
  _computeYRange(arc, attribute, currentMarks) {
305
- var _a, _b, _c, _d;
308
+ var _a, _b, _c, _d, _e;
306
309
  const plotRect = {
307
310
  width: 2 * (null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0),
308
311
  height: 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0)
309
- }, 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;
312
+ }, 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;
310
313
  let a, b, c;
311
314
  if ((0, vutils_1.isNumberClose)(width / 2, cx)) a = 0, b = 1, c = -cy; else if ((0,
312
315
  vutils_1.isNumberClose)(height / 2, cy)) a = 1, b = 0, c = -cx; else {
@@ -322,7 +325,8 @@ class ArcLabel extends base_1.LabelBase {
322
325
  max = Math.max(points[0].y, points[1].y) + height / 2), arc.labelYRange = [ min, max ];
323
326
  }
324
327
  _computeLayoutRadius(halfYLength, attribute, currentMarks) {
325
- 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;
328
+ var _a;
329
+ 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;
326
330
  return Math.max((a ** 2 + halfYLength ** 2) / (2 * a), outerR);
327
331
  }
328
332
  _findNeighborIndex(arcs, priorityArc) {
@@ -367,8 +371,10 @@ class ArcLabel extends base_1.LabelBase {
367
371
  (0, util_1.checkBoundsOverlap)(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
368
372
  }
369
373
  }
370
- computeRadius(r, width, height, k) {
371
- return this.computeLayoutRadius(width || 0, height || 0) * r * ((0, vutils_1.isNil)(k) ? 1 : k);
374
+ computeRadius(r, width, height, centerOffset, k) {
375
+ var _a;
376
+ return null !== (_a = this.computeLayoutRadius(width || 0, height || 0) * r * ((0,
377
+ vutils_1.isNil)(k) ? 1 : k) + centerOffset) && void 0 !== _a ? _a : 0;
372
378
  }
373
379
  computeLayoutRadius(width, height) {
374
380
  return Math.min(width / 2, height / 2);
@@ -376,9 +382,10 @@ class ArcLabel extends base_1.LabelBase {
376
382
  computeLayoutOuterRadius(r, width, height) {
377
383
  return r / (Math.min(width, height) / 2);
378
384
  }
379
- computeDatumRadius(width, height, outerRadius) {
385
+ computeDatumRadius(width, height, outerRadius, centerOffset) {
386
+ var _a;
380
387
  const outerRadiusRatio = this.computeLayoutOuterRadius(outerRadius, width, height);
381
- return this.computeLayoutRadius(width || 0, height || 0) * outerRadiusRatio;
388
+ return null !== (_a = this.computeLayoutRadius(width || 0, height || 0) * outerRadiusRatio + centerOffset) && void 0 !== _a ? _a : 0;
382
389
  }
383
390
  }
384
391