Skip to content

Commit db48de1

Browse files
authored
More user defined band properties (#592)
* feat: add more user definable props for bands * style: prettier
1 parent 9a6f1c0 commit db48de1

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

projects/observability/src/shared/dashboard/widgets/charts/cartesian-widget/band.model.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,42 @@ import { Observable } from 'rxjs';
1414
type: 'band'
1515
})
1616
export class BandModel<TInterval> {
17-
public static readonly BAND_COLOR: string = Color.Gray2;
18-
public static readonly BASELINE_COLOR: string = Color.Gray4;
19-
public static readonly BASELINE_NAME: string = 'Baseline';
20-
public static readonly UPPER_BOUND_NAME: string = 'Upper Bound';
21-
public static readonly LOWER_BOUND_NAME: string = 'Lower Bound';
22-
public static readonly DEFAULT_OPACITY: number = 0.4;
17+
private static readonly BAND_COLOR: string = Color.Gray2;
18+
private static readonly BASELINE_COLOR: string = Color.Gray4;
19+
private static readonly DEFAULT_OPACITY: number = 0.4;
20+
private static readonly BASELINE_NAME: string = 'Baseline';
21+
private static readonly UPPER_BOUND_NAME: string = 'Upper Bound';
22+
private static readonly LOWER_BOUND_NAME: string = 'Lower Bound';
2323

2424
@ModelProperty({
25-
key: 'band-color',
25+
key: 'name',
2626
type: STRING_PROPERTY.type
2727
})
28-
public bandColor: string = BandModel.BAND_COLOR;
28+
public name: string = BandModel.BASELINE_NAME;
29+
30+
@ModelProperty({
31+
key: 'upper-bound-name',
32+
type: STRING_PROPERTY.type
33+
})
34+
public upperBoundName: string = BandModel.UPPER_BOUND_NAME;
35+
36+
@ModelProperty({
37+
key: 'lower-bound-name',
38+
type: STRING_PROPERTY.type
39+
})
40+
public lowerBoundName: string = BandModel.LOWER_BOUND_NAME;
41+
42+
@ModelProperty({
43+
key: 'color',
44+
type: STRING_PROPERTY.type
45+
})
46+
public color: string = BandModel.BASELINE_COLOR;
2947

3048
@ModelProperty({
31-
key: 'baseline-color',
49+
key: 'band-color',
3250
type: STRING_PROPERTY.type
3351
})
34-
public baselineColor: string = BandModel.BASELINE_COLOR;
52+
public bandColor: string = BandModel.BAND_COLOR;
3553

3654
@ModelProperty({
3755
key: 'opacity',

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class CartesianWidgetModel<TInterval> {
171171
this.mapToBaseline(bands[index].bandModel, b)
172172
)
173173
],
174-
bands: result.bands.map((b: MetricBand<TInterval>) => this.mapToBand(b))
174+
bands: result.bands.map((b: MetricBand<TInterval>, index: number) => this.mapToBand(bands[index].bandModel, b))
175175
}))
176176
);
177177
}
@@ -202,18 +202,18 @@ export class CartesianWidgetModel<TInterval> {
202202
return {
203203
data: metricBand.intervals,
204204
units: metricBand.units,
205-
color: BandModel.BASELINE_COLOR,
206-
name: BandModel.BASELINE_NAME,
205+
color: model.color,
206+
name: model.name,
207207
type: CartesianSeriesVisualizationType.DashedLine,
208208
hide: model.hide
209209
};
210210
}
211211

212-
private mapToBand(metricSeries: MetricSeries<TInterval>): Band<TInterval> {
212+
private mapToBand(model: BandModel<TInterval>, metricSeries: MetricSeries<TInterval>): Band<TInterval> {
213213
return {
214214
name: '',
215-
color: BandModel.BAND_COLOR,
216-
opacity: BandModel.DEFAULT_OPACITY,
215+
color: model.bandColor,
216+
opacity: model.opacity,
217217
upper: {
218218
data: metricSeries.intervals
219219
.map((interval: unknown) => interval as MetricTimeseriesBandInterval)
@@ -226,8 +226,8 @@ export class CartesianWidgetModel<TInterval> {
226226
)
227227
.map(interval => interval as TInterval),
228228
type: CartesianSeriesVisualizationType.DashedLine,
229-
color: BandModel.BAND_COLOR,
230-
name: BandModel.UPPER_BOUND_NAME
229+
color: model.bandColor,
230+
name: model.upperBoundName
231231
},
232232
lower: {
233233
data: metricSeries.intervals
@@ -241,8 +241,8 @@ export class CartesianWidgetModel<TInterval> {
241241
)
242242
.map(interval => interval as TInterval),
243243
type: CartesianSeriesVisualizationType.DashedLine,
244-
color: BandModel.BAND_COLOR,
245-
name: BandModel.LOWER_BOUND_NAME
244+
color: model.bandColor,
245+
name: model.lowerBoundName
246246
}
247247
};
248248
}

0 commit comments

Comments
 (0)