Skip to content

Commit dea7932

Browse files
authored
fix: fix misc issues with gauge and donuts (#950)
* fix: fix misc issues with gauge and donuts * refactor: remove unused code * refactor: addressing self review * refactor: addressing self review * refactor: fixing style * refactor: addressing revew commits * refactor: fixing lint errors
1 parent df5c71a commit dea7932

File tree

9 files changed

+53
-30
lines changed

9 files changed

+53
-30
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ browserslist
1515
LICENSE*
1616
conf/
1717
coverage/
18+
test-results/

projects/components/src/titled-content/titled-content.component.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
}
2727

2828
.title {
29-
@include widget-title($gray-9);
29+
@include overline($gray-9);
3030
margin-top: 16px;
3131
}
3232
}
@@ -40,7 +40,7 @@
4040

4141
.footer {
4242
.title {
43-
@include widget-title($gray-4);
43+
@include overline($gray-4);
4444
margin-top: 8px;
4545
}
4646
}

projects/observability/src/public-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export { LegendPosition } from './shared/components/legend/legend.component';
7171

7272
// Donut
7373
export * from './shared/components/donut/donut';
74+
export * from './shared/components/donut/donut.component';
75+
export * from './shared/components/donut/donut.module';
7476

7577
// Pages
7678
export * from './pages/apis/backends/backend-list.module';

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export class DonutBuilderService extends D3VisualizationBuilderService<
3838
private static readonly DONUT_VALUE_CLASS: string = 'donut-value';
3939
private static readonly DONUT_ARC_CLASS: string = 'donut-arc';
4040

41-
private static readonly DONUT_PADDING_PX: number = 60;
42-
private static readonly LEGEND_SIZE_MULTIPLE: number = 1.5;
41+
private static readonly DONUT_PADDING_PX: number = 10;
4342

4443
public constructor(
4544
d3: D3UtilService,
@@ -128,17 +127,7 @@ export class DonutBuilderService extends D3VisualizationBuilderService<
128127
protected decorateDimensions(calculatedDimensions: ChartDimensions): DonutDimensions {
129128
let diameter = Math.min(calculatedDimensions.visualizationWidth, calculatedDimensions.visualizationHeight);
130129

131-
// Save available width before reducing width by adding padding
132-
const chartWidth = calculatedDimensions.visualizationWidth;
133-
134-
// Legend takes up to width of donut or remaining available space (This needs more work to look good in all cases)
135-
calculatedDimensions.legendWidth = Math.min(
136-
diameter * DonutBuilderService.LEGEND_SIZE_MULTIPLE,
137-
chartWidth - diameter
138-
);
139-
140-
// Reduce diameter by padding amount (don't need to do this with legend since it provides its own padding)
141-
diameter -= DonutBuilderService.DONUT_PADDING_PX * 2;
130+
diameter -= DonutBuilderService.DONUT_PADDING_PX;
142131

143132
// Reduce visualization area to diameter
144133
calculatedDimensions.visualizationWidth = diameter;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class DonutComponent implements OnChanges, OnDestroy, AfterViewInit {
4646
public ngOnChanges(): void {
4747
this.draw();
4848
}
49-
5049
public ngOnDestroy(): void {
5150
this.donut && this.donut.destroy();
5251
}

projects/observability/src/shared/components/gauge-list/gauge-list.component.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
width: 100%;
77
display: grid;
88
margin-top: 16px;
9-
grid-template-columns: minmax(60px, auto) minmax(80px, 160px) max-content;
9+
grid-template-columns: minmax(60px, 1fr) max-content;
1010
grid-auto-rows: 20px;
1111
column-gap: 16px;
1212
align-items: center;
1313

14+
&.with-label {
15+
grid-template-columns: minmax(60px, auto) minmax(60px, 1fr) max-content;
16+
}
17+
1418
.border-top {
1519
grid-column-start: 1;
1620
grid-column-end: 4;

projects/observability/src/shared/components/gauge-list/gauge-list.component.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@ import { maxBy } from 'lodash-es';
77
styleUrls: ['./gauge-list.component.scss'],
88
changeDetection: ChangeDetectionStrategy.OnPush,
99
template: `
10-
<div class="gauge-list">
10+
<div class="gauge-list" [ngClass]="{ 'with-label': this.showLabels }">
1111
<ng-container *ngFor="let item of this.itemOptions">
12-
<div class="border-top"></div>
12+
<div class="border-top" *ngIf="this.showItemBorders"></div>
1313
<div
1414
class="label"
15+
*ngIf="this.showLabels"
1516
[htTooltip]="item.label"
1617
(click)="this.onItemClick(item)"
1718
[ngClass]="{ clickable: this.itemClickable }"
1819
[ngStyle]="{ color: item.color }"
1920
>
2021
{{ item.label }}
2122
</div>
22-
<div class="progress">
23+
<div class="progress" [htTooltip]="item.label">
2324
<div class="progress-value" [ngStyle]="{ width: item.width, backgroundColor: item.color }"></div>
2425
</div>
2526
<div class="value">
@@ -39,6 +40,12 @@ export class GaugeListComponent<T extends GaugeItem = GaugeItem> implements OnCh
3940
@Input()
4041
public determineColor?: (colorKey: string) => string;
4142

43+
@Input()
44+
public showLabels: boolean = true;
45+
46+
@Input()
47+
public showItemBorders: boolean = true;
48+
4249
@Output()
4350
public readonly itemClick: EventEmitter<T> = new EventEmitter();
4451

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,20 @@ export abstract class D3VisualizationBuilderService<
220220
// tslint:disable-next-line: no-null-keyword
221221
visualizationSelection.style('display', null);
222222

223+
const isLegendVisible = this.isLegendVisible(config);
223224
const isTopOrBottomLegend = this.isTopOrBottomLegend(config);
224225
const isSideLegend = config.legend === LegendPosition.Right;
225-
const legendWidth = isSideLegend
226+
let legendWidth = isLegendVisible
227+
? 0
228+
: isSideLegend
226229
? Math.min(legendRect.width, this.getMaxLegendWidth())
227230
: isTopOrBottomLegend
228231
? outerRect.width
229232
: 0;
230233

231-
const legendHeight = isTopOrBottomLegend
234+
let legendHeight = isLegendVisible
235+
? 0
236+
: isTopOrBottomLegend
232237
? Math.min(legendRect.height, this.getMaxLegendHeight())
233238
: isSideLegend
234239
? outerRect.height
@@ -237,8 +242,19 @@ export abstract class D3VisualizationBuilderService<
237242
const legendWidthOffset = isSideLegend ? legendWidth : 0;
238243
const legendHeightOffset = isTopOrBottomLegend ? legendHeight : 0;
239244

240-
const vizWidth = outerRect.width - legendWidthOffset;
241-
const vizHeight = outerRect.height - legendHeightOffset;
245+
let vizWidth = outerRect.width - legendWidthOffset;
246+
let vizHeight = outerRect.height - legendHeightOffset;
247+
248+
// Hide Legend if less space is available for the viz
249+
if (vizWidth <= legendWidthOffset || legendWidth <= 60) {
250+
vizWidth = outerRect.width;
251+
legendWidth = 0;
252+
}
253+
254+
if (vizHeight <= legendHeightOffset || legendHeight <= 12) {
255+
vizHeight = outerRect.height;
256+
legendHeight = 0;
257+
}
242258

243259
return this.decorateDimensions({
244260
visualizationWidth: vizWidth,
@@ -248,6 +264,10 @@ export abstract class D3VisualizationBuilderService<
248264
});
249265
}
250266

267+
private isLegendVisible(config: ChartConfig): boolean {
268+
return config.legend === LegendPosition.None;
269+
}
270+
251271
private isTopOrBottomLegend(config: ChartConfig): boolean {
252272
switch (config.legend) {
253273
case LegendPosition.Bottom:

projects/observability/src/shared/components/utils/d3/d3-visualization.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.chart-container {
2+
flex: 1 1 auto;
23
position: absolute; // We want parent to ignore size to detect resizes
34
display: flex;
45
align-items: center;
@@ -7,24 +8,24 @@
78
&.row {
89
flex-direction: row;
910
.chart-legend-container {
10-
padding-left: 48px;
11-
padding-right: 12px;
11+
margin-left: 12px;
12+
margin-right: 12px;
1213
}
1314
}
1415

1516
&.column {
1617
flex-direction: column;
1718
.chart-legend-container {
18-
padding-top: 24px;
19-
padding-bottom: 12px;
19+
margin-top: 24px;
20+
margin-bottom: 12px;
2021
}
2122
}
2223

2324
&.column-reverse {
2425
flex-direction: column-reverse;
2526
.chart-legend-container {
26-
padding-bottom: 24px;
27-
padding-top: 12px;
27+
margin-bottom: 24px;
28+
margin-top: 12px;
2829
}
2930
}
3031

0 commit comments

Comments
 (0)