Skip to content

Commit c0fba1c

Browse files
authored
refactor: updating gauge model, radius calculation and exporting handler service (#349)
* refactor: updating radius calculation and exporting handler service * refactor: adding value and thresholds to widget model
1 parent ba18a38 commit c0fba1c

File tree

5 files changed

+87
-27
lines changed

5 files changed

+87
-27
lines changed

projects/distributed-tracing/src/public-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ export { WaterfallData } from './shared/dashboard/widgets/waterfall/waterfall/wa
9595
// Datasources
9696
export * from './shared/dashboard/widgets/span-detail/data/span-detail-data-source.model';
9797
export * from './shared/dashboard/widgets/trace-detail/data/trace-detail-data-source.model';
98+
99+
// Detail Sheet
100+
export * from './shared/dashboard/interaction/detail-sheet/detail-sheet-interaction.module';
101+
export * from './shared/dashboard/interaction/detail-sheet/detail-sheet-interaction-handler.service';

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class GaugeComponent implements OnChanges {
6767
const radius = this.buildRadius(boundingBox);
6868

6969
return {
70-
origin: this.buildOrigin(boundingBox, radius),
70+
origin: this.buildOrigin(boundingBox),
7171
backgroundArc: this.buildBackgroundArc(radius),
7272
data: this.buildGaugeData(radius, inputData)
7373
};
@@ -107,23 +107,20 @@ export class GaugeComponent implements OnChanges {
107107
}
108108

109109
private buildRadius(boundingBox: ClientRect): number {
110-
return Math.min(
111-
boundingBox.height - GaugeComponent.GAUGE_AXIS_PADDING,
112-
boundingBox.height / 2 + Math.min(boundingBox.height, boundingBox.width) / 2
113-
);
110+
return Math.min(boundingBox.height - GaugeComponent.GAUGE_AXIS_PADDING, boundingBox.width / 2);
114111
}
115112

116-
private buildOrigin(boundingBox: ClientRect, radius: number): Point {
113+
private buildOrigin(boundingBox: ClientRect): Point {
117114
return {
118115
x: boundingBox.width / 2,
119-
y: radius
116+
y: boundingBox.height - GaugeComponent.GAUGE_AXIS_PADDING
120117
};
121118
}
122119

123120
private calculateInputData(): GaugeInputData | undefined {
124121
if (this.value !== undefined && this.maxValue !== undefined && this.maxValue > 0 && this.thresholds.length > 0) {
125122
const currentThreshold = this.thresholds.find(
126-
threshold => this.value! >= threshold.start && this.value! < threshold.end
123+
threshold => this.value! >= threshold.start && this.value! <= threshold.end
127124
);
128125

129126
if (currentThreshold) {
@@ -141,7 +138,7 @@ export interface GaugeThreshold {
141138
label: string;
142139
start: number;
143140
end: number;
144-
color: Color;
141+
color: Color | string;
145142
}
146143

147144
interface GaugeSvgRendererData {

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,17 @@ import { createModelFactory } from '@hypertrace/dashboards/testing';
33
import { MODEL_PROPERTY_TYPES } from '@hypertrace/hyperdash-angular';
44
import { runFakeRxjs } from '@hypertrace/test-utils';
55
import { of } from 'rxjs';
6-
import { GaugeWidgetData } from './gauge-widget';
76
import { GaugeWidgetModel } from './gauge-widget.model';
87

98
describe('Gauge widget model', () => {
109
test('uses colors from color map', () => {
1110
const modelFactory = createModelFactory();
1211

13-
const data: GaugeWidgetData = {
14-
value: 5,
15-
maxValue: 10,
16-
thresholds: [
17-
{
18-
start: 0,
19-
end: 6,
20-
label: 'Medium',
21-
color: Color.Brown1
22-
}
23-
]
24-
};
12+
const value = 5;
2513

2614
const spectator = modelFactory(GaugeWidgetModel, {
2715
api: {
28-
getData: () => of(data)
16+
getData: () => of(value)
2917
},
3018
providers: [
3119
{
@@ -34,7 +22,16 @@ describe('Gauge widget model', () => {
3422
}
3523
],
3624
properties: {
37-
title: 'Test Title'
25+
title: 'Test Title',
26+
maxValue: 10,
27+
thresholds: [
28+
{
29+
start: 0,
30+
end: 6,
31+
label: 'Medium',
32+
color: Color.Brown1
33+
}
34+
]
3835
}
3936
});
4037

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import { Model, ModelApi, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash';
1+
import {
2+
ARRAY_PROPERTY,
3+
Model,
4+
ModelApi,
5+
ModelProperty,
6+
NUMBER_PROPERTY,
7+
STRING_PROPERTY
8+
} from '@hypertrace/hyperdash';
29
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular';
310
import { Observable } from 'rxjs';
11+
import { map } from 'rxjs/operators';
412
import { GaugeWidgetData } from './gauge-widget';
5-
13+
import { GaugeThresholdModel } from './thresholds/gauge-threshold.model';
614
@Model({
715
type: 'gauge-widget'
816
})
@@ -13,10 +21,30 @@ export class GaugeWidgetModel {
1321
})
1422
public title?: string;
1523

24+
@ModelProperty({
25+
key: 'max-value',
26+
type: NUMBER_PROPERTY.type,
27+
required: true
28+
})
29+
public maxValue!: number;
30+
31+
@ModelProperty({
32+
key: 'thresholds',
33+
type: ARRAY_PROPERTY.type,
34+
required: true
35+
})
36+
public thresholds!: GaugeThresholdModel[];
37+
1638
@ModelInject(MODEL_API)
1739
private readonly api!: ModelApi;
1840

1941
public getData(): Observable<GaugeWidgetData> {
20-
return this.api.getData<GaugeWidgetData>();
42+
return this.api.getData<number>().pipe(
43+
map(value => ({
44+
value: value,
45+
maxValue: this.maxValue,
46+
thresholds: this.thresholds
47+
}))
48+
);
2149
}
2250
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Model, ModelProperty, NUMBER_PROPERTY, STRING_PROPERTY, UNKNOWN_PROPERTY } from '@hypertrace/hyperdash';
2+
3+
@Model({
4+
type: 'gauge-threshold'
5+
})
6+
export class GaugeThresholdModel {
7+
@ModelProperty({
8+
key: 'start',
9+
type: NUMBER_PROPERTY.type,
10+
required: true
11+
})
12+
public start!: number;
13+
14+
@ModelProperty({
15+
key: 'end',
16+
type: NUMBER_PROPERTY.type,
17+
required: true
18+
})
19+
public end!: number;
20+
21+
@ModelProperty({
22+
key: 'label',
23+
type: STRING_PROPERTY.type,
24+
required: true
25+
})
26+
public label!: string;
27+
28+
@ModelProperty({
29+
key: 'color',
30+
type: UNKNOWN_PROPERTY.type,
31+
required: true
32+
})
33+
public color!: string;
34+
}

0 commit comments

Comments
 (0)