Skip to content

Commit 7c2ba4b

Browse files
fix: donut chart fixes (#988)
1 parent e2d498f commit 7c2ba4b

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

projects/observability/src/shared/components/donut/donut-builder.service.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export class DonutBuilderService extends D3VisualizationBuilderService<
3939
private static readonly DONUT_ARC_CLASS: string = 'donut-arc';
4040

4141
private static readonly DONUT_PADDING_PX: number = 10;
42+
private static readonly MAX_FONT_SIZE_FOR_TITLE: number = 15;
43+
private static readonly MAX_FONT_SIZE_FOR_VALUE: number = 64;
4244

4345
public constructor(
4446
d3: D3UtilService,
@@ -69,11 +71,19 @@ export class DonutBuilderService extends D3VisualizationBuilderService<
6971

7072
visualizationContainer
7173
.select(selector(DonutBuilderService.DONUT_VALUE_TITLE_CLASS))
72-
.attr('transform', `translate(0,-${dimensions.donutInnerRadius / 2})`);
74+
.attr('transform', `translate(0,-${dimensions.donutInnerRadius / 2})`)
75+
.style(
76+
'font-size',
77+
Math.min(Math.floor(dimensions.donutInnerRadius / 8), DonutBuilderService.MAX_FONT_SIZE_FOR_TITLE)
78+
);
7379

7480
visualizationContainer
7581
.select(selector(DonutBuilderService.DONUT_VALUE_CLASS))
76-
.attr('transform', `translate(0,-${dimensions.donutInnerRadius / 4})`);
82+
.attr('transform', `translate(0,-${dimensions.donutInnerRadius / 4})`)
83+
.style(
84+
'font-size',
85+
Math.min(Math.floor(dimensions.donutInnerRadius / 2), DonutBuilderService.MAX_FONT_SIZE_FOR_VALUE)
86+
);
7787
}
7888

7989
protected drawVisualization(

projects/observability/src/shared/components/donut/donut.component.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99

1010
.donut-svg {
1111
.donut-value-title {
12-
font-size: 15px;
1312
dominant-baseline: hanging;
1413
}
1514

1615
.donut-value {
17-
font-size: 64px;
1816
dominant-baseline: hanging;
1917
}
2018
}

projects/observability/src/shared/components/legend/legend.component.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.legend-entries {
55
display: flex;
66
flex-wrap: wrap;
7+
overflow: hidden;
78

89
&.legend-row {
910
flex-direction: row;
@@ -45,14 +46,14 @@
4546
}
4647

4748
.legend-label {
48-
@include body-2-medium($gray-4);
49+
@include chart-small-regular($gray-4);
4950
@include ellipsis-overflow();
5051
flex: 1;
5152
min-width: 24px;
5253
}
5354

5455
.legend-value {
55-
@include body-2-medium($gray-9);
56+
@include chart-small-regular($gray-9);
5657
padding-left: 16px;
5758
}
5859
}

projects/observability/src/shared/components/utils/d3/d3-visualization-builder.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export abstract class D3VisualizationBuilderService<
226226
let legendWidth = isLegendVisible
227227
? 0
228228
: isSideLegend
229-
? Math.min(legendRect.width, this.getMaxLegendWidth())
229+
? Math.min(this.getLegendWidth(outerRect.width), this.getMaxLegendWidth())
230230
: isTopOrBottomLegend
231231
? outerRect.width
232232
: 0;
@@ -264,6 +264,10 @@ export abstract class D3VisualizationBuilderService<
264264
});
265265
}
266266

267+
private getLegendWidth(outerRectWidth: number): number {
268+
return outerRectWidth >= 200 ? outerRectWidth * 0.35 : 0;
269+
}
270+
267271
private isLegendVisible(config: ChartConfig): boolean {
268272
return config.legend === LegendPosition.None;
269273
}

0 commit comments

Comments
 (0)