From 8734ed14521f73cacd6cc28bf0b0b3eb3663cb6b Mon Sep 17 00:00:00 2001 From: "linghao.su" Date: Sat, 5 Aug 2023 15:23:38 +0800 Subject: [PATCH] fix(sunburst): fix align error caused by float precision --- src/chart/sunburst/SunburstPiece.ts | 5 +- test/sunburst-label-align.html | 1163 +++++++++++++++++++++++++++ 2 files changed, 1166 insertions(+), 2 deletions(-) create mode 100644 test/sunburst-label-align.html diff --git a/src/chart/sunburst/SunburstPiece.ts b/src/chart/sunburst/SunburstPiece.ts index b0d662796d..35d1d1ac00 100644 --- a/src/chart/sunburst/SunburstPiece.ts +++ b/src/chart/sunburst/SunburstPiece.ts @@ -33,6 +33,7 @@ import {createOrUpdatePatternFromDecal} from '../../util/decal'; import ExtensionAPI from '../../core/ExtensionAPI'; import { saveOldStyle } from '../../animation/basicTransition'; import { normalizeRadian } from 'zrender/src/contain/util'; +import { isRadianAroundZero } from '../../util/number'; const DEFAULT_SECTOR_Z = 2; const DEFAULT_TEXT_Z = 4; @@ -231,13 +232,13 @@ class SunburstPiece extends graphic.Sector { } else if (textAlign === 'left') { r = layout.r0 + labelPadding; - if (midAngle > Math.PI / 2) { + if (midAngle > Math.PI / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) { textAlign = 'right'; } } else if (textAlign === 'right') { r = layout.r - labelPadding; - if (midAngle > Math.PI / 2) { + if (midAngle > Math.PI / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) { textAlign = 'left'; } } diff --git a/test/sunburst-label-align.html b/test/sunburst-label-align.html new file mode 100644 index 0000000000..0bb6e3a637 --- /dev/null +++ b/test/sunburst-label-align.html @@ -0,0 +1,1163 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + \ No newline at end of file