Skip to content

Commit 619690d

Browse files
author
Eugene Cheung
authored
feat(custom): add graphWidgetWidth to allow for custom widths in CustomMetricGroup objects (#517)
Closes #487 --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 96b9fa8 commit 619690d

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

API.md

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/common/widget/size.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const DefaultLogWidgetHeight = 7;
2020
/**
2121
* Suggests the best widget width, given the total number of widgets.
2222
* The main point is to make widgets as wide as possible, while saving vertical space and minimizing number of gaps.
23+
*
2324
* @param numTotalWidgets total number of widgets to be placed
2425
*/
2526
export function recommendedWidgetWidth(numTotalWidgets: number) {

lib/monitoring/custom/CustomMonitoring.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ export interface CustomMetricGroup {
174174
* @see {GraphWidgetProps.setPeriodToTimeRange}
175175
*/
176176
readonly graphWidgetSetPeriodToTimeRange?: boolean;
177+
/**
178+
* Width of graph widget. Note that widgets will overflow into new rows if the summed width
179+
* exceeds 24.
180+
*
181+
* @default - Automatically calculcated width, generally as wide as possible considering all metrics' widgets.
182+
*/
183+
readonly graphWidgetWidth?: number;
177184
/**
178185
* @deprecated use addToSummaryDashboard. addToSummaryDashboard will take precedence over important.
179186
* @see addToSummaryDashboard
@@ -207,17 +214,20 @@ export interface CustomMetricGroup {
207214
export interface CustomMonitoringProps extends BaseMonitoringProps {
208215
/**
209216
* optional description of the whole section, in markdown
210-
* @default no description
217+
*
218+
* @default - no description
211219
*/
212220
readonly description?: string;
213221
/**
214222
* optional height of the description widget, so the content fits
215-
* @default minimum height (should fit one or two lines of text)
223+
*
224+
* @default - minimum height (should fit one or two lines of text)
216225
*/
217226
readonly descriptionWidgetHeight?: number;
218227
/**
219-
* height override
220-
* @default default height
228+
* Height override.
229+
*
230+
* @default - default height
221231
*/
222232
readonly height?: number;
223233
/**
@@ -380,9 +390,6 @@ export class CustomMonitoring extends Monitoring {
380390
summary: boolean
381391
) {
382392
const widgets: IWidget[] = [];
383-
const metricGroupWidgetWidth = recommendedWidgetWidth(
384-
annotatedGroups.length
385-
);
386393
const metricGroupWidgetHeightDefault = summary
387394
? DefaultSummaryWidgetHeight
388395
: DefaultGraphWidgetHeight;
@@ -416,7 +423,9 @@ export class CustomMonitoring extends Monitoring {
416423

417424
const graphWidgetProps: GraphWidgetProps = {
418425
title,
419-
width: metricGroupWidgetWidth,
426+
width:
427+
annotatedGroup.metricGroup.graphWidgetWidth ??
428+
recommendedWidgetWidth(annotatedGroups.length),
420429
height: metricGroupWidgetHeight,
421430
left,
422431
right,

test/monitoring/custom/CustomMonitoring.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ test("snapshot test", () => {
3939
{
4040
title: "DummyGroup1",
4141
addToSummaryDashboard: true,
42+
graphWidgetWidth: 6,
4243
metrics: [
4344
// regular metric
4445
new Metric({ metricName: "DummyMetric1", namespace, dimensionsMap }),
@@ -75,6 +76,7 @@ test("snapshot test", () => {
7576
{
7677
title: "DummyGroup2",
7778
graphWidgetType: GraphWidgetType.BAR,
79+
graphWidgetWidth: 2,
7880
metrics: [
7981
// regular metric
8082
new Metric({ metricName: "DummyMetric10", namespace, dimensionsMap }),

test/monitoring/custom/__snapshots__/CustomMonitoring.test.ts.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)