From 2362925e5bd2c8ad8e1b1c0f3cfde153a9450806 Mon Sep 17 00:00:00 2001 From: "akash.sonune" Date: Thu, 9 Oct 2025 22:24:02 +0530 Subject: [PATCH 1/3] feat(sunburst): align root node label to center --- src/chart/sunburst/SunburstPiece.ts | 8 +- test/sunburst-label-centering.html | 185 ++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 test/sunburst-label-centering.html diff --git a/src/chart/sunburst/SunburstPiece.ts b/src/chart/sunburst/SunburstPiece.ts index 0925f16f94..e2e8e0bc16 100644 --- a/src/chart/sunburst/SunburstPiece.ts +++ b/src/chart/sunburst/SunburstPiece.ts @@ -233,8 +233,12 @@ class SunburstPiece extends graphic.Sector { } else { if (!textAlign || textAlign === 'center') { - // Put label in the center if it's a circle - if (angle === 2 * Math.PI && layout.r0 === 0) { + // Put label in the center if it's a full circle, or if it's a root-level node with no inner radius + // and there's only one sibling (to avoid overlapping labels) + if (layout.r0 === 0 && ( + angle === 2 * Math.PI + || (this.node.parentNode?.children?.length === 1) + )) { r = 0; } else { diff --git a/test/sunburst-label-centering.html b/test/sunburst-label-centering.html new file mode 100644 index 0000000000..fbf7dd5f1b --- /dev/null +++ b/test/sunburst-label-centering.html @@ -0,0 +1,185 @@ + + + + + + + + + + + + + + + + + +
+
+
+ + + \ No newline at end of file From 8f319edc53ce889d827d6df2736d5d0287a40ea4 Mon Sep 17 00:00:00 2001 From: "akash.sonune" Date: Fri, 10 Oct 2025 13:55:05 +0530 Subject: [PATCH 2/3] chore: apply review comment --- src/chart/sunburst/SunburstPiece.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/chart/sunburst/SunburstPiece.ts b/src/chart/sunburst/SunburstPiece.ts index e2e8e0bc16..d772ee7712 100644 --- a/src/chart/sunburst/SunburstPiece.ts +++ b/src/chart/sunburst/SunburstPiece.ts @@ -235,10 +235,7 @@ class SunburstPiece extends graphic.Sector { if (!textAlign || textAlign === 'center') { // Put label in the center if it's a full circle, or if it's a root-level node with no inner radius // and there's only one sibling (to avoid overlapping labels) - if (layout.r0 === 0 && ( - angle === 2 * Math.PI - || (this.node.parentNode?.children?.length === 1) - )) { + if (layout.r0 === 0 && isRadianAroundZero(angle - 2 * Math.PI)) { r = 0; } else { From 9c07df0e88afd755fc0e262c17e4b56be0de4f94 Mon Sep 17 00:00:00 2001 From: "akash.sonune" Date: Fri, 10 Oct 2025 16:42:58 +0530 Subject: [PATCH 3/3] chore: apply review comment --- src/chart/sunburst/SunburstPiece.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/chart/sunburst/SunburstPiece.ts b/src/chart/sunburst/SunburstPiece.ts index d772ee7712..edff517300 100644 --- a/src/chart/sunburst/SunburstPiece.ts +++ b/src/chart/sunburst/SunburstPiece.ts @@ -233,8 +233,7 @@ class SunburstPiece extends graphic.Sector { } else { if (!textAlign || textAlign === 'center') { - // Put label in the center if it's a full circle, or if it's a root-level node with no inner radius - // and there's only one sibling (to avoid overlapping labels) + // Put label in the center if it's a circle if (layout.r0 === 0 && isRadianAroundZero(angle - 2 * Math.PI)) { r = 0; }