Skip to content

Commit a3c2c3c

Browse files
committed
updated donut inner area placement
1 parent dece205 commit a3c2c3c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/pie-chart/chart-inner-area.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,34 @@ class ChartInnerDescriptions {
3131
private descriptionElement: null | Highcharts.SVGElement = null;
3232

3333
public create({ innerAreaTitle, innerAreaDescription }: InnerAreaProps, chart: Highcharts.Chart) {
34-
const textX = chart.plotLeft + chart.series[0].center[0];
35-
const textY = chart.plotTop + chart.series[0].center[1];
34+
const centerX = chart.plotLeft + chart.series[0].center[0];
35+
const centerY = chart.plotTop + chart.series[0].center[1];
3636

3737
if (innerAreaTitle) {
3838
this.titleElement = chart.renderer
39-
.text(innerAreaTitle, textX, textY)
39+
.text(innerAreaTitle, -9999, -9999)
4040
.attr({ zIndex: 5, class: testClasses["inner-value"] })
4141
.css(Styles.innerAreaTitleCss)
4242
.add();
43-
this.titleElement.attr({
44-
x: textX - this.titleElement.getBBox().width / 2,
45-
y: innerAreaDescription ? textY : textY + 10,
46-
});
4743
}
4844
if (innerAreaDescription) {
4945
this.descriptionElement = chart.renderer
50-
.text(innerAreaDescription, textX, textY)
46+
.text(innerAreaDescription, -9999, -9999)
5147
.attr({ zIndex: 5, class: testClasses["inner-description"] })
5248
.css(Styles.innerAreaDescriptionCss)
5349
.add();
54-
this.descriptionElement.attr({
55-
x: textX - this.descriptionElement.getBBox().width / 2,
56-
y: textY + 20,
57-
});
50+
}
51+
52+
const titleBox = this.titleElement?.getBBox();
53+
const descriptionBox = this.descriptionElement?.getBBox();
54+
55+
if (titleBox && descriptionBox) {
56+
this.titleElement!.attr({ x: centerX - titleBox.width / 2, y: centerY - titleBox.height / 4 });
57+
this.descriptionElement!.attr({ x: centerX - descriptionBox.width / 2, y: centerY + descriptionBox.height / 2 });
58+
} else if (titleBox) {
59+
this.titleElement!.attr({ x: centerX - titleBox.width / 2, y: centerY + titleBox.height / 4 });
60+
} else if (descriptionBox) {
61+
this.descriptionElement!.attr({ x: centerX - descriptionBox.width / 2, y: centerY + descriptionBox.height / 4 });
5862
}
5963
}
6064

0 commit comments

Comments
 (0)