@visactor/vrender-components 0.14.3 → 0.14.4

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 (59) 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 +4 -9
  17. package/cjs/label/arc.js +56 -48
  18. package/cjs/label/arc.js.map +1 -1
  19. package/cjs/label/base.d.ts +3 -3
  20. package/cjs/label/base.js +61 -44
  21. package/cjs/label/base.js.map +1 -1
  22. package/cjs/label/type.d.ts +7 -1
  23. package/cjs/label/type.js.map +1 -1
  24. package/cjs/legend/discrete/discrete.js +11 -6
  25. package/cjs/legend/discrete/discrete.js.map +1 -1
  26. package/cjs/util/labelSmartInvert.d.ts +2 -1
  27. package/cjs/util/labelSmartInvert.js +2 -2
  28. package/cjs/util/labelSmartInvert.js.map +1 -1
  29. package/dist/index.js +205 -153
  30. package/dist/index.min.js +1 -1
  31. package/es/axis/base.d.ts +4 -0
  32. package/es/axis/base.js +3 -5
  33. package/es/axis/base.js.map +1 -1
  34. package/es/axis/circle.d.ts +5 -1
  35. package/es/axis/circle.js +6 -0
  36. package/es/axis/circle.js.map +1 -1
  37. package/es/axis/line.d.ts +5 -0
  38. package/es/axis/line.js +11 -3
  39. package/es/axis/line.js.map +1 -1
  40. package/es/axis/overlap/auto-rotate.d.ts +9 -1
  41. package/es/axis/overlap/auto-rotate.js +38 -28
  42. package/es/axis/overlap/auto-rotate.js.map +1 -1
  43. package/es/index.d.ts +1 -1
  44. package/es/index.js +1 -1
  45. package/es/index.js.map +1 -1
  46. package/es/label/arc.d.ts +4 -9
  47. package/es/label/arc.js +37 -32
  48. package/es/label/arc.js.map +1 -1
  49. package/es/label/base.d.ts +3 -3
  50. package/es/label/base.js +59 -46
  51. package/es/label/base.js.map +1 -1
  52. package/es/label/type.d.ts +7 -1
  53. package/es/label/type.js.map +1 -1
  54. package/es/legend/discrete/discrete.js +11 -6
  55. package/es/legend/discrete/discrete.js.map +1 -1
  56. package/es/util/labelSmartInvert.d.ts +2 -1
  57. package/es/util/labelSmartInvert.js +1 -1
  58. package/es/util/labelSmartInvert.js.map +1 -1
  59. package/package.json +3 -3
@@ -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":";;;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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,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,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K,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";
1
+ export declare const version = "0.14.4";
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", __exportStar(require("./core/base"), exports),
20
+ }), exports.version = void 0, exports.version = "0.14.4", __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,QAAQ,CAAC;AAEhC,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\";\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,QAAQ,CAAC;AAEhC,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.4\";\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,9 +1,7 @@
1
1
  import type { IBoundsLike } from '@visactor/vutils';
2
2
  import { LabelBase } from './base';
3
- import type { ArcLabelAttrs, IPoint, Quadrant } from './type';
4
- import type { BaseLabelAttrs } from './type';
5
- import type { TextAlignType, TextBaselineType, IText } from '@visactor/vrender';
6
- import type { IGraphic } from '@visactor/vrender';
3
+ import type { ArcLabelAttrs, IPoint, Quadrant, BaseLabelAttrs } from './type';
4
+ import type { IText, IGraphic } from '@visactor/vrender';
7
5
  export declare class ArcInfo {
8
6
  key: string;
9
7
  refDatum: any;
@@ -22,13 +20,10 @@ export declare class ArcInfo {
22
20
  pointA: IPoint;
23
21
  pointB: IPoint;
24
22
  pointC: IPoint;
25
- labelLinePath: string;
26
23
  quadrant: Quadrant;
27
24
  radian: number;
28
25
  middleAngle: number;
29
26
  k: number;
30
- textAlign: TextAlignType;
31
- textBaseline: TextBaselineType;
32
27
  angle: number;
33
28
  constructor(refDatum: any, center: IPoint, outerCenter: IPoint, quadrant: Quadrant, radian: number, middleAngle: number);
34
29
  getLabelBounds(): IBoundsLike;
@@ -45,7 +40,7 @@ export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
45
40
  x: number;
46
41
  y: number;
47
42
  } | undefined;
48
- 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[];
49
44
  private _layoutInsideLabels;
50
45
  private _layoutOutsideLabels;
51
46
  private _computeX;
@@ -64,7 +59,7 @@ export declare class ArcLabel extends LabelBase<ArcLabelAttrs> {
64
59
  private _restoreY;
65
60
  private _checkYRange;
66
61
  private _coverLabels;
67
- 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;
68
63
  protected computeLayoutRadius(width: number, height: number): number;
69
64
  private computeLayoutOuterRadius;
70
65
  private computeDatumRadius;
package/cjs/label/arc.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.ArcLabel = exports.ArcInfo = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), base_1 = require("./base"), vutils_2 = require("@visactor/vutils"), util_1 = require("./util");
7
+ const vutils_1 = require("@visactor/vutils"), base_1 = require("./base"), util_1 = require("./util");
8
8
 
9
9
  class ArcInfo {
10
10
  constructor(refDatum, center, outerCenter, quadrant, radian, middleAngle) {
@@ -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,13 +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
- const {labelSize: labelSize, radian: radian} = arc, innerRadius = this.computeRadius(innerRadiusRatio, attribute.width, attribute.height, 1), outerRadius = this.computeRadius(outerRadiusRatio, attribute.width, attribute.height, 1);
78
+ var _a, _b;
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);
78
80
  let limit;
79
81
  if (radian < (0, util_1.connectLineRadian)(outerRadius, labelSize.height)) limit = 0; else {
80
82
  let minRadius;
@@ -86,8 +88,8 @@ class ArcLabel extends base_1.LabelBase {
86
88
  arc.labelText = text;
87
89
  const labelWidth = Math.min(limit, arc.labelSize.width), align = this._computeAlign(arc, attribute), labelRadius = outerRadius - spaceWidth - ("left" === align ? labelWidth : "right" === align ? 0 : labelWidth / 2);
88
90
  arc.labelPosition = (0, util_1.circlePoint)(center.x, center.y, labelRadius, arc.middleAngle),
89
- arc.labelLimit = labelWidth, (0, vutils_2.isGreater)(labelWidth, 0) || (arc.labelVisible = !1),
90
- arc.angle = arc.middleAngle;
91
+ arc.labelLimit = labelWidth, (0, vutils_1.isGreater)(labelWidth, 0) || (arc.labelVisible = !1),
92
+ arc.angle = null !== (_b = null === (_a = null == attribute ? void 0 : attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : arc.middleAngle;
91
93
  })), arcs;
92
94
  }
93
95
  _layoutOutsideLabels(arcs, attribute, currentMarks) {
@@ -126,21 +128,21 @@ class ArcLabel extends base_1.LabelBase {
126
128
  }
127
129
  const width = 2 * center_x;
128
130
  return arcs.forEach((arc => {
129
- arc.labelVisible && ((0, vutils_2.isLess)(arc.pointB.x, line2MinLength + spaceWidth) || (0,
130
- vutils_2.isGreater)(arc.pointB.x, width - line2MinLength - spaceWidth)) && (arc.labelVisible = !1),
131
- arc.angle = 0, arc.labelLinePath = `M${Math.round(arc.pointA.x)},${Math.round(arc.pointA.y)} L${Math.round(arc.pointB.x)},${Math.round(arc.pointB.y)} L${Math.round(arc.pointC.x)},${Math.round(arc.pointC.y)}`;
131
+ var _a, _b;
132
+ arc.labelVisible && ((0, vutils_1.isLess)(arc.pointB.x, line2MinLength + spaceWidth) || (0,
133
+ vutils_1.isGreater)(arc.pointB.x, width - line2MinLength - spaceWidth)) && (arc.labelVisible = !1),
134
+ arc.angle = null !== (_b = null === (_a = null == attribute ? void 0 : attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : 0;
132
135
  })), arcs;
133
136
  }
134
137
  _computeX(arc, attribute, currentMarks) {
135
- var _a, _b, _c, _d, _e;
136
- 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,
137
- 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} = (this._computeAlign(arc, attribute),
138
- arc);
139
- (0, vutils_2.isValidNumber)(pointB.x * pointB.y) || (arc.pointC = {
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;
141
+ (0, vutils_1.isValidNumber)(pointB.x * pointB.y) || (arc.pointC = {
140
142
  x: NaN,
141
143
  y: NaN
142
144
  }, labelPosition.x = NaN, arc.labelLimit = 0);
143
- const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height), flag = (0,
145
+ const radius = this.computeRadius(radiusRatio, attribute.width, attribute.height, centerOffset), flag = (0,
144
146
  util_1.isQuadrantLeft)(quadrant) ? -1 : 1;
145
147
  let cx = 0;
146
148
  let limit = (flag > 0 ? plotLayout_width - pointB.x : pointB.x) - line2MinLength - spaceWidth;
@@ -160,17 +162,19 @@ class ArcLabel extends base_1.LabelBase {
160
162
  default:
161
163
  cx = pointB.x + flag * line2MinLength;
162
164
  }
163
- if (labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.pointC = {
165
+ labelWidth = Math.max(this._ellipsisWidth, labelWidth), arc.labelLimit = labelWidth,
166
+ arc.pointC = {
164
167
  x: cx,
165
168
  y: labelPosition.y
166
- }, "edge" === labelLayoutAlign) {
169
+ };
170
+ const targetCenterOffset = .5 * (arc.labelLimit < arc.labelSize.width ? arc.labelLimit : arc.labelSize.width);
171
+ if ("edge" === labelLayoutAlign) {
167
172
  const alignOffset = 0;
168
- labelPosition.x = flag > 0 ? plotLayout_width + alignOffset : alignOffset;
173
+ labelPosition.x = (flag > 0 ? plotLayout_width + alignOffset : alignOffset) - flag * targetCenterOffset;
169
174
  } else {
170
175
  const alignOffset = 0;
171
- labelPosition.x = cx + alignOffset + flag * (spaceWidth + .5 * arc.labelSize.width);
176
+ labelPosition.x = cx + alignOffset + flag * (spaceWidth + .5 * targetCenterOffset);
172
177
  }
173
- arc.labelLimit = labelWidth;
174
178
  }
175
179
  _computeAlignOffset(align, labelWidth, alignFlag) {
176
180
  switch (align) {
@@ -187,9 +191,9 @@ class ArcLabel extends base_1.LabelBase {
187
191
  _computeAlign(arc, attribute) {
188
192
  var _a, _b, _c, _d, _e, _f;
189
193
  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;
190
- return "inside" !== labelConfig.position ? (0, vutils_2.isNil)(textAlign) || "auto" === textAlign ? "edge" === layoutAlign ? (0,
194
+ return "inside" !== labelConfig.position ? (0, vutils_1.isNil)(textAlign) || "auto" === textAlign ? "edge" === layoutAlign ? (0,
191
195
  util_1.isQuadrantLeft)(arc.quadrant) ? "left" : "right" : (0, util_1.isQuadrantLeft)(arc.quadrant) ? "right" : "left" : textAlign : (0,
192
- vutils_2.isNil)(textAlign) || "auto" === textAlign ? "center" : textAlign;
196
+ vutils_1.isNil)(textAlign) || "auto" === textAlign ? "center" : textAlign;
193
197
  }
194
198
  _getFormatLabelText(value, limit) {
195
199
  return value.text;
@@ -204,7 +208,7 @@ class ArcLabel extends base_1.LabelBase {
204
208
  if (len <= 0) return;
205
209
  for (let i = 0; i < len; i++) {
206
210
  const {y1: y1} = arcs[i].getLabelBounds();
207
- if (delta = y1 - lastY, (0, vutils_2.isLess)(delta, 0)) {
211
+ if (delta = y1 - lastY, (0, vutils_1.isLess)(delta, 0)) {
208
212
  const index = this._shiftY(arcs, i, len - 1, -delta);
209
213
  this._shiftY(arcs, index, 0, delta / 2);
210
214
  }
@@ -212,7 +216,7 @@ class ArcLabel extends base_1.LabelBase {
212
216
  lastY = y2;
213
217
  }
214
218
  const {y1: firstY1} = arcs[0].getLabelBounds();
215
- delta = firstY1 - 0, (0, vutils_2.isLess)(delta, 0) && this._shiftY(arcs, 0, len - 1, -delta);
219
+ delta = firstY1 - 0, (0, vutils_1.isLess)(delta, 0) && this._shiftY(arcs, 0, len - 1, -delta);
216
220
  for (let i = arcs.length - 1; i >= 0 && arcs[i].getLabelBounds().y2 > plotRect_height; i--) arcs[i].labelVisible = !1;
217
221
  } else if ("none" !== labelLayout.strategy) {
218
222
  const priorityArcs = arcs.map(((arc, i) => ({
@@ -244,9 +248,9 @@ class ArcLabel extends base_1.LabelBase {
244
248
  }
245
249
  const nextTopIndex = Math.min(topLabelIndex, priorityArcs[i].originIndex), nextBottomIndex = Math.max(bottomLabelIndex, priorityArcs[i].originIndex);
246
250
  let delta;
247
- if (delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, (0, vutils_2.isGreater)(delta, 0) && this._shiftY(arcs, nextBottomIndex, 0, -delta),
248
- delta = arcs[nextTopIndex].getLabelBounds().y1 - 0, (0, vutils_2.isLess)(delta, 0) && this._shiftY(arcs, nextTopIndex, arcs.length - 1, -delta),
249
- delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, (0, vutils_2.isGreater)(delta, 0)) {
251
+ if (delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, (0, vutils_1.isGreater)(delta, 0) && this._shiftY(arcs, nextBottomIndex, 0, -delta),
252
+ delta = arcs[nextTopIndex].getLabelBounds().y1 - 0, (0, vutils_1.isLess)(delta, 0) && this._shiftY(arcs, nextTopIndex, arcs.length - 1, -delta),
253
+ delta = arcs[nextBottomIndex].getLabelBounds().y2 - plotRect_height, (0, vutils_1.isGreater)(delta, 0)) {
250
254
  arc.labelVisible = !1, this._restoreY(arcs);
251
255
  break;
252
256
  }
@@ -278,7 +282,7 @@ class ArcLabel extends base_1.LabelBase {
278
282
  return -1;
279
283
  }
280
284
  _computePointB(arc, r, attribute, currentMarks) {
281
- var _a, _b, _c, _d;
285
+ var _a, _b, _c, _d, _e;
282
286
  const labelConfig = attribute, radiusRatio = this.computeLayoutOuterRadius(currentMarks[0].attribute.outerRadius, attribute.width, attribute.height), line1MinLength = labelConfig.line.line1MinLength;
283
287
  if ("none" === labelConfig.layout.strategy) arc.pointB = {
284
288
  x: arc.outerCenter.x,
@@ -287,8 +291,8 @@ class ArcLabel extends base_1.LabelBase {
287
291
  const center = {
288
292
  x: null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0,
289
293
  y: null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0
290
- }, 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;
291
- (0, vutils_2.isValidNumber)(x) ? arc.pointB = {
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;
295
+ (0, vutils_1.isValidNumber)(x) ? arc.pointB = {
292
296
  x: center.x + x * ((0, util_1.isQuadrantLeft)(quadrant) ? -1 : 1),
293
297
  y: labelPosition.y
294
298
  } : arc.pointB = {
@@ -301,27 +305,28 @@ class ArcLabel extends base_1.LabelBase {
301
305
  for (const arc of arcs) arc.labelVisible && (arc.lastLabelY = arc.labelPosition.y);
302
306
  }
303
307
  _computeYRange(arc, attribute, currentMarks) {
304
- var _a, _b, _c, _d;
308
+ var _a, _b, _c, _d, _e;
305
309
  const plotRect = {
306
310
  width: 2 * (null !== (_b = null === (_a = currentMarks[0].attribute) || void 0 === _a ? void 0 : _a.x) && void 0 !== _b ? _b : 0),
307
311
  height: 2 * (null !== (_d = null === (_c = currentMarks[0].attribute) || void 0 === _c ? void 0 : _c.y) && void 0 !== _d ? _d : 0)
308
- }, 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;
309
313
  let a, b, c;
310
- if ((0, vutils_2.isNumberClose)(width / 2, cx)) a = 0, b = 1, c = -cy; else if ((0,
311
- vutils_2.isNumberClose)(height / 2, cy)) a = 1, b = 0, c = -cx; else {
314
+ if ((0, vutils_1.isNumberClose)(width / 2, cx)) a = 0, b = 1, c = -cy; else if ((0,
315
+ vutils_1.isNumberClose)(height / 2, cy)) a = 1, b = 0, c = -cx; else {
312
316
  const k = -1 / (cy / cx);
313
317
  a = k, b = -1, c = cy - k * cx;
314
318
  }
315
319
  const points = (0, util_1.lineCirclePoints)(a, b, c, line1MinLength + radius - r, 0, r);
316
320
  if (points.length < 2) return;
317
321
  let min, max;
318
- 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,
322
+ points[0].x > points[1].x && points.reverse(), points[0].x < 0 ? (0, vutils_1.isNumberClose)(points[0].y, points[1].y) ? Math.abs(arc.middleAngle) < Math.PI / 2 ? (min = 0,
319
323
  max = points[1].y + height / 2) : (min = points[1].y + height / 2, max = height) : points[0].y < points[1].y ? (min = 0,
320
324
  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,
321
325
  max = Math.max(points[0].y, points[1].y) + height / 2), arc.labelYRange = [ min, max ];
322
326
  }
323
327
  _computeLayoutRadius(halfYLength, attribute, currentMarks) {
324
- 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;
325
330
  return Math.max((a ** 2 + halfYLength ** 2) / (2 * a), outerR);
326
331
  }
327
332
  _findNeighborIndex(arcs, priorityArc) {
@@ -342,7 +347,7 @@ class ArcLabel extends base_1.LabelBase {
342
347
  }
343
348
  _twoWayShift(arcs, lastArc, nextArc, nextIndex) {
344
349
  const delta = nextArc.getLabelBounds().y1 - lastArc.getLabelBounds().y2;
345
- if ((0, vutils_2.isLess)(delta, 0)) {
350
+ if ((0, vutils_1.isLess)(delta, 0)) {
346
351
  const i = this._shiftY(arcs, nextIndex, arcs.length - 1, -delta);
347
352
  this._shiftY(arcs, i, 0, delta / 2);
348
353
  }
@@ -353,8 +358,8 @@ class ArcLabel extends base_1.LabelBase {
353
358
  _checkYRange(arcs) {
354
359
  for (const arc of arcs) {
355
360
  const {labelYRange: labelYRange, labelPosition: labelPosition} = arc;
356
- if (arc.labelVisible && labelYRange && ((0, vutils_2.isLess)(labelPosition.y, labelYRange[0]) || (0,
357
- vutils_2.isGreater)(labelPosition.y, labelYRange[1]))) return !1;
361
+ if (arc.labelVisible && labelYRange && ((0, vutils_1.isLess)(labelPosition.y, labelYRange[0]) || (0,
362
+ vutils_1.isGreater)(labelPosition.y, labelYRange[1]))) return !1;
358
363
  }
359
364
  return !0;
360
365
  }
@@ -366,8 +371,10 @@ class ArcLabel extends base_1.LabelBase {
366
371
  (0, util_1.checkBoundsOverlap)(lastBounds, bounds) ? arcs[i].labelVisible = !1 : lastBounds = bounds;
367
372
  }
368
373
  }
369
- computeRadius(r, width, height, k) {
370
- return this.computeLayoutRadius(width || 0, height || 0) * r * ((0, vutils_2.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;
371
378
  }
372
379
  computeLayoutRadius(width, height) {
373
380
  return Math.min(width / 2, height / 2);
@@ -375,9 +382,10 @@ class ArcLabel extends base_1.LabelBase {
375
382
  computeLayoutOuterRadius(r, width, height) {
376
383
  return r / (Math.min(width, height) / 2);
377
384
  }
378
- computeDatumRadius(width, height, outerRadius) {
385
+ computeDatumRadius(width, height, outerRadius, centerOffset) {
386
+ var _a;
379
387
  const outerRadiusRatio = this.computeLayoutOuterRadius(outerRadius, width, height);
380
- 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;
381
389
  }
382
390
  }
383
391