Skip to content

Commit ac5f177

Browse files
fix: donut and legend responsiveness issue
1 parent d51f5d6 commit ac5f177

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ 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_DIAMETER_FOR_DONUT: number = 320;
4342
private static readonly MAX_FONT_SIZE_FOR_TITLE: number = 15;
4443
private static readonly MAX_FONT_SIZE_FOR_VALUE: number = 64;
4544

@@ -138,14 +137,12 @@ export class DonutBuilderService extends D3VisualizationBuilderService<
138137
protected decorateDimensions(calculatedDimensions: ChartDimensions): DonutDimensions {
139138
let diameter = Math.min(calculatedDimensions.visualizationWidth, calculatedDimensions.visualizationHeight);
140139

140+
diameter -= DonutBuilderService.DONUT_PADDING_PX;
141+
141142
// Reduce visualization area to diameter
142143
calculatedDimensions.visualizationWidth = diameter;
143144
calculatedDimensions.visualizationHeight = diameter;
144145

145-
diameter -= DonutBuilderService.DONUT_PADDING_PX;
146-
diameter =
147-
diameter > DonutBuilderService.MAX_DIAMETER_FOR_DONUT ? DonutBuilderService.MAX_DIAMETER_FOR_DONUT : diameter;
148-
149146
return {
150147
...calculatedDimensions,
151148
donutOuterRadius: diameter / 2,

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)