Skip to content

Commit f70fb6c

Browse files
feat: add custom configurations to the topology widget (#938)
* feat: custom configurations for topology
1 parent 3d7da37 commit f70fb6c

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

projects/observability/src/shared/components/topology/d3/d3-topology.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class D3Topology implements Topology {
182182
target: data,
183183
scroll: this.config.zoomable ? zoomScrollConfig : undefined,
184184
pan: this.config.zoomable ? zoomPanConfig : undefined,
185-
showBrush: true
185+
showBrush: this.config.showBrush
186186
});
187187

188188
this.onDestroy(() => {

projects/observability/src/shared/components/topology/d3/interactions/topology-interaction-control.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, InjectionToken } from '@angular/core';
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, InjectionToken, OnInit } from '@angular/core';
22
import { IconType } from '@hypertrace/assets-library';
33
import { SubscriptionLifecycle, throwIfNil } from '@hypertrace/common';
44

@@ -69,7 +69,7 @@ export const TOPOLOGY_INTERACTION_CONTROL_DATA = new InjectionToken<TopologyInte
6969
</div>
7070
`
7171
})
72-
export class TopologyInteractionControlComponent {
72+
export class TopologyInteractionControlComponent implements OnInit {
7373
public currentZoomPercentage: string = '100';
7474
public canIncrement: boolean = true;
7575
public canDecrement: boolean = true;
@@ -111,6 +111,12 @@ export class TopologyInteractionControlComponent {
111111
this.nodeDataSpecifiers = interactionControlData.topologyConfig.nodeDataSpecifiers;
112112
}
113113

114+
public ngOnInit(): void {
115+
if (this.interactionControlData.topologyConfig.shouldAutoZoomToFit) {
116+
this.zoomToFit();
117+
}
118+
}
119+
114120
// TODO should make the increments logarithmic
115121
public incrementZoom(): void {
116122
this.getZoomOrThrow().setZoomScale(this.getZoomOrThrow().getZoomScale() + 0.1);

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export class TopologyComponent implements OnChanges, OnDestroy {
4343
@Input()
4444
public edgeDataSpecifiers?: TopologyDataSpecifier[];
4545

46+
@Input()
47+
public showBrush?: boolean = true;
48+
49+
@Input()
50+
public shouldAutoZoomToFit?: boolean = false;
51+
4652
@ViewChild('topologyContainer', { static: true })
4753
private readonly container!: ElementRef;
4854

@@ -65,7 +71,9 @@ export class TopologyComponent implements OnChanges, OnDestroy {
6571
edgeRenderer: this.edgeRenderer,
6672
nodeDataSpecifiers: this.nodeDataSpecifiers,
6773
edgeDataSpecifiers: this.edgeDataSpecifiers,
68-
tooltipRenderer: this.tooltipRenderer
74+
tooltipRenderer: this.tooltipRenderer,
75+
showBrush: this.showBrush,
76+
shouldAutoZoomToFit: this.shouldAutoZoomToFit
6977
});
7078

7179
// Angular doesn't like introducing new child views mid-change detection

projects/observability/src/shared/components/topology/topology.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ export interface TopologyConfiguration {
4444
*/
4545
zoomable: boolean;
4646

47+
/**
48+
* If true, brush will be shown
49+
*/
50+
showBrush?: boolean;
51+
52+
/**
53+
* If true, it will be automatic zoom to fit
54+
*/
55+
shouldAutoZoomToFit?: boolean;
56+
4757
/**
4858
* A list of specifiers for node data. Up to one will be selectable to the user,
4959
* and provided to the node renderer.

projects/observability/src/shared/dashboard/widgets/topology/topology-widget-renderer.component.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ describe('Topology Widget renderer', () => {
8383
edgeSpecification: edgeSpec,
8484
nodeTypes: uniq(mockResponse.map(node => node.data[entityTypeKey]))
8585
})
86-
)
86+
),
87+
showLegend: true
8788
};
8889

8990
const createComponent = createComponentFactory<TopologyWidgetRendererComponent>({

projects/observability/src/shared/dashboard/widgets/topology/topology-widget-renderer.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { TopologyWidgetModel } from './topology-widget.model';
3535
template: `
3636
<ht-titled-content [title]="this.model.title | htDisplayTitle">
3737
<div class="visualization" *htLoadAsync="this.data$ as data">
38-
<div class="legend">
38+
<div *ngIf="this.model.showLegend" class="legend">
3939
<div class="latency">
4040
<div class="label">P99 Latency:</div>
4141
<div class="entry" *ngFor="let entry of this.getLatencyLegendConfig()">
@@ -59,6 +59,8 @@ import { TopologyWidgetModel } from './topology-widget.model';
5959
[tooltipRenderer]="this.tooltipRenderer"
6060
[nodeDataSpecifiers]="data.nodeSpecs"
6161
[edgeDataSpecifiers]="data.edgeSpecs"
62+
[showBrush]="this.model.showBrush"
63+
[shouldAutoZoomToFit]="this.model.shouldAutoZoomToFit"
6264
>
6365
</ht-topology>
6466
</div>

projects/observability/src/shared/dashboard/widgets/topology/topology-widget.model.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Model, ModelApi, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';
1+
import { BOOLEAN_PROPERTY, Model, ModelApi, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';
22
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular';
33
import { Observable } from 'rxjs';
44
import { TopologyData, TopologyDataSourceModel } from '../../data/graphql/topology/topology-data-source.model';
@@ -16,6 +16,30 @@ export class TopologyWidgetModel {
1616
})
1717
public title?: string;
1818

19+
@ModelProperty({
20+
key: 'showLegend',
21+
displayName: 'Show Legend',
22+
type: BOOLEAN_PROPERTY.type,
23+
required: false
24+
})
25+
public showLegend?: boolean = true;
26+
27+
@ModelProperty({
28+
key: 'showBrush',
29+
displayName: 'Show Brush',
30+
type: BOOLEAN_PROPERTY.type,
31+
required: false
32+
})
33+
public showBrush?: boolean = true;
34+
35+
@ModelProperty({
36+
key: 'shouldAutoZoomToFit',
37+
displayName: 'Should Auto Zoom To Fit',
38+
type: BOOLEAN_PROPERTY.type,
39+
required: false
40+
})
41+
public shouldAutoZoomToFit?: boolean = false;
42+
1943
@ModelInject(MODEL_API)
2044
private readonly api!: ModelApi;
2145

0 commit comments

Comments
 (0)