Skip to content

Commit

Permalink
feat(custom): add graphWidgetWidth to allow for custom widths in Cust…
Browse files Browse the repository at this point in the history
…omMetricGroup 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_
  • Loading branch information
echeung-amzn authored May 9, 2024
1 parent 96b9fa8 commit 619690d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
21 changes: 19 additions & 2 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/common/widget/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const DefaultLogWidgetHeight = 7;
/**
* Suggests the best widget width, given the total number of widgets.
* The main point is to make widgets as wide as possible, while saving vertical space and minimizing number of gaps.
*
* @param numTotalWidgets total number of widgets to be placed
*/
export function recommendedWidgetWidth(numTotalWidgets: number) {
Expand Down
25 changes: 17 additions & 8 deletions lib/monitoring/custom/CustomMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export interface CustomMetricGroup {
* @see {GraphWidgetProps.setPeriodToTimeRange}
*/
readonly graphWidgetSetPeriodToTimeRange?: boolean;
/**
* Width of graph widget. Note that widgets will overflow into new rows if the summed width
* exceeds 24.
*
* @default - Automatically calculcated width, generally as wide as possible considering all metrics' widgets.
*/
readonly graphWidgetWidth?: number;
/**
* @deprecated use addToSummaryDashboard. addToSummaryDashboard will take precedence over important.
* @see addToSummaryDashboard
Expand Down Expand Up @@ -207,17 +214,20 @@ export interface CustomMetricGroup {
export interface CustomMonitoringProps extends BaseMonitoringProps {
/**
* optional description of the whole section, in markdown
* @default no description
*
* @default - no description
*/
readonly description?: string;
/**
* optional height of the description widget, so the content fits
* @default minimum height (should fit one or two lines of text)
*
* @default - minimum height (should fit one or two lines of text)
*/
readonly descriptionWidgetHeight?: number;
/**
* height override
* @default default height
* Height override.
*
* @default - default height
*/
readonly height?: number;
/**
Expand Down Expand Up @@ -380,9 +390,6 @@ export class CustomMonitoring extends Monitoring {
summary: boolean
) {
const widgets: IWidget[] = [];
const metricGroupWidgetWidth = recommendedWidgetWidth(
annotatedGroups.length
);
const metricGroupWidgetHeightDefault = summary
? DefaultSummaryWidgetHeight
: DefaultGraphWidgetHeight;
Expand Down Expand Up @@ -416,7 +423,9 @@ export class CustomMonitoring extends Monitoring {

const graphWidgetProps: GraphWidgetProps = {
title,
width: metricGroupWidgetWidth,
width:
annotatedGroup.metricGroup.graphWidgetWidth ??
recommendedWidgetWidth(annotatedGroups.length),
height: metricGroupWidgetHeight,
left,
right,
Expand Down
2 changes: 2 additions & 0 deletions test/monitoring/custom/CustomMonitoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test("snapshot test", () => {
{
title: "DummyGroup1",
addToSummaryDashboard: true,
graphWidgetWidth: 6,
metrics: [
// regular metric
new Metric({ metricName: "DummyMetric1", namespace, dimensionsMap }),
Expand Down Expand Up @@ -75,6 +76,7 @@ test("snapshot test", () => {
{
title: "DummyGroup2",
graphWidgetType: GraphWidgetType.BAR,
graphWidgetWidth: 2,
metrics: [
// regular metric
new Metric({ metricName: "DummyMetric10", namespace, dimensionsMap }),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 619690d

Please sign in to comment.