-
Notifications
You must be signed in to change notification settings - Fork 11
feat: adding gauge widget #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...ects/components/src/gauge/gauge.module.ts → ...c/shared/components/gauge/gauge.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../observability/src/shared/dashboard/widgets/gauge/gauge-widget-renderer.component.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Color, FormattingModule } from '@hypertrace/common'; | ||
import { LoadAsyncModule, TitledContentComponent } from '@hypertrace/components'; | ||
import { RENDERER_API } from '@hypertrace/hyperdash-angular'; | ||
import { createComponentFactory } from '@ngneat/spectator/jest'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { EMPTY, of } from 'rxjs'; | ||
import { GaugeComponent } from './../../../components/gauge/gauge.component'; | ||
import { GaugeWidgetRendererComponent } from './gauge-widget-renderer.component'; | ||
import { GaugeWidgetModel } from './gauge-widget.model'; | ||
|
||
describe('Gauge widget renderer component', () => { | ||
let mockModel: Partial<GaugeWidgetModel> = {}; | ||
const componentFactory = createComponentFactory({ | ||
component: GaugeWidgetRendererComponent, | ||
shallow: true, | ||
imports: [FormattingModule, LoadAsyncModule], | ||
providers: [ | ||
{ | ||
provide: RENDERER_API, | ||
useFactory: () => ({ | ||
getTimeRange: jest.fn(), | ||
model: mockModel, | ||
change$: EMPTY, | ||
dataRefresh$: EMPTY, | ||
timeRangeChanged$: EMPTY | ||
}) | ||
} | ||
], | ||
declarations: [MockComponent(GaugeComponent), MockComponent(TitledContentComponent)] | ||
}); | ||
|
||
test('should render provided data with title', () => { | ||
mockModel = { | ||
title: 'Test title', | ||
getData: jest.fn(() => | ||
of({ | ||
value: 5, | ||
maxValue: 10, | ||
thresholds: [ | ||
{ | ||
start: 0, | ||
end: 6, | ||
label: 'Medium', | ||
color: Color.Brown1 | ||
} | ||
] | ||
}) | ||
) | ||
}; | ||
|
||
const spectator = componentFactory(); | ||
expect(spectator.query(TitledContentComponent)!.title).toBe('TEST TITLE'); | ||
|
||
const gaugeComponent = spectator.query(GaugeComponent); | ||
expect(gaugeComponent).toExist(); | ||
expect(gaugeComponent!.value).toEqual(5); | ||
expect(gaugeComponent!.maxValue).toEqual(10); | ||
expect(gaugeComponent!.thresholds).toEqual([ | ||
{ | ||
start: 0, | ||
end: 6, | ||
label: 'Medium', | ||
color: Color.Brown1 | ||
} | ||
]); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget-renderer.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { WidgetRenderer } from '@hypertrace/dashboards'; | ||
import { Renderer } from '@hypertrace/hyperdash'; | ||
import { Observable } from 'rxjs'; | ||
import { GaugeWidgetData } from './gauge-widget'; | ||
import { GaugeWidgetModel } from './gauge-widget.model'; | ||
|
||
@Renderer({ modelClass: GaugeWidgetModel }) | ||
@Component({ | ||
selector: 'ht-gauge-widget-renderer', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<ht-titled-content [title]="this.model.title | htDisplayTitle" *htLoadAsync="this.data$ as gaugeData"> | ||
<ht-gauge | ||
class="fill-container" | ||
[value]="gaugeData.value" | ||
[maxValue]="gaugeData.maxValue" | ||
[thresholds]="gaugeData.thresholds" | ||
></ht-gauge> | ||
</ht-titled-content> | ||
` | ||
}) | ||
export class GaugeWidgetRendererComponent extends WidgetRenderer<GaugeWidgetModel, GaugeWidgetData> { | ||
protected fetchData(): Observable<GaugeWidgetData> { | ||
return this.model.getData(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget.model.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Color } from '@hypertrace/common'; | ||
import { createModelFactory } from '@hypertrace/dashboards/testing'; | ||
import { MODEL_PROPERTY_TYPES } from '@hypertrace/hyperdash-angular'; | ||
import { runFakeRxjs } from '@hypertrace/test-utils'; | ||
import { of } from 'rxjs'; | ||
import { GaugeWidgetData } from './gauge-widget'; | ||
import { GaugeWidgetModel } from './gauge-widget.model'; | ||
|
||
describe('Gauge widget model', () => { | ||
test('uses colors from color map', () => { | ||
const modelFactory = createModelFactory(); | ||
|
||
const data: GaugeWidgetData = { | ||
value: 5, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm - I think I'd expect the max and thresholds to come from the widget model rather than the data model - those seem like they're independent of where we actually get the value from, and would allow dropping in our existing aggregation data sources. |
||
maxValue: 10, | ||
thresholds: [ | ||
{ | ||
start: 0, | ||
end: 6, | ||
label: 'Medium', | ||
color: Color.Brown1 | ||
} | ||
] | ||
}; | ||
|
||
const spectator = modelFactory(GaugeWidgetModel, { | ||
api: { | ||
getData: () => of(data) | ||
}, | ||
providers: [ | ||
{ | ||
provide: MODEL_PROPERTY_TYPES, | ||
useValue: [] | ||
} | ||
], | ||
properties: { | ||
title: 'Test Title' | ||
} | ||
}); | ||
|
||
runFakeRxjs(({ expectObservable }) => { | ||
expectObservable(spectator.model.getData()).toBe('(x|)', { | ||
x: { | ||
value: 5, | ||
maxValue: 10, | ||
thresholds: [ | ||
{ | ||
start: 0, | ||
end: 6, | ||
label: 'Medium', | ||
color: Color.Brown1 | ||
} | ||
] | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget.model.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Model, ModelApi, ModelProperty, STRING_PROPERTY } from '@hypertrace/hyperdash'; | ||
import { ModelInject, MODEL_API } from '@hypertrace/hyperdash-angular'; | ||
import { Observable } from 'rxjs'; | ||
import { GaugeWidgetData } from './gauge-widget'; | ||
|
||
@Model({ | ||
type: 'gauge-widget' | ||
}) | ||
export class GaugeWidgetModel { | ||
@ModelProperty({ | ||
key: 'title', | ||
type: STRING_PROPERTY.type | ||
}) | ||
public title?: string; | ||
|
||
@ModelInject(MODEL_API) | ||
private readonly api!: ModelApi; | ||
|
||
public getData(): Observable<GaugeWidgetData> { | ||
return this.api.getData<GaugeWidgetData>(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { FormattingModule } from '@hypertrace/common'; | ||
import { LoadAsyncModule, TitledContentModule } from '@hypertrace/components'; | ||
import { DashboardCoreModule } from '@hypertrace/hyperdash-angular'; | ||
import { GaugeModule } from '../../../components/gauge/gauge.module'; | ||
import { GaugeWidgetRendererComponent } from './gauge-widget-renderer.component'; | ||
import { GaugeWidgetModel } from './gauge-widget.model'; | ||
|
||
@NgModule({ | ||
declarations: [GaugeWidgetRendererComponent], | ||
imports: [ | ||
DashboardCoreModule.with({ | ||
models: [GaugeWidgetModel], | ||
renderers: [GaugeWidgetRendererComponent] | ||
}), | ||
GaugeModule, | ||
CommonModule, | ||
TitledContentModule, | ||
LoadAsyncModule, | ||
FormattingModule | ||
] | ||
}) | ||
export class GaugeWidgetModule {} |
7 changes: 7 additions & 0 deletions
7
projects/observability/src/shared/dashboard/widgets/gauge/gauge-widget.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { GaugeThreshold } from '../../../components/gauge/gauge.component'; | ||
|
||
export interface GaugeWidgetData { | ||
value: number; | ||
maxValue: number; | ||
thresholds: GaugeThreshold[]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doubled up gauge component/module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed