Skip to content
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

feat(cloudwatch): different view types in GraphWidget #11160

Merged
merged 6 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-cloudwatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ dashboard.addWidgets(new GraphWidget({
}));
```

The graph view can be changed from default 'timeSeries' to 'bar' or 'pie'.

```ts
dashboard.addWidgets(new GraphWidget({
// ...
// ...

view: GraphWidgetView.BAR,
}));
```

### Alarm widget

An alarm widget shows the graph and the alarm line of a single alarm:
Expand Down
28 changes: 27 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ export class AlarmWidget extends ConcreteWidget {
}
}

/**
* Types of view
*/
export enum GraphWidgetView {
/**
* Display as a line graph.
*/
TIME_SERIES = 'timeSeries',
/**
* Display as a bar graph.
*/
BAR = 'bar',
/**
* Display as a pie graph.
*/
PIE = 'pie',
}

/**
* Properties for a GraphWidget
*/
Expand Down Expand Up @@ -187,6 +205,14 @@ export interface GraphWidgetProps extends MetricWidgetProps {
* @default false
*/
readonly liveData?: boolean;


/**
* Display this metric
*
* @default TimeSeries
*/
readonly view?: GraphWidgetView;
}

/**
Expand Down Expand Up @@ -214,7 +240,7 @@ export class GraphWidget extends ConcreteWidget {
x: this.x,
y: this.y,
properties: {
view: 'timeSeries',
view: this.props.view ?? GraphWidgetView.TIME_SERIES,
title: this.props.title,
region: this.props.region || cdk.Aws.REGION,
stacked: this.props.stacked,
Expand Down
26 changes: 25 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/test/test.graphs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { Alarm, AlarmWidget, Color, GraphWidget, LegendPosition, LogQueryWidget, Metric, Shading, SingleValueWidget, LogQueryVisualizationType } from '../lib';
import { Alarm, AlarmWidget, Color, GraphWidget, GraphWidgetView, LegendPosition, LogQueryWidget, Metric, Shading, SingleValueWidget, LogQueryVisualizationType } from '../lib';

export = {
'add stacked property to graphs'(test: Test) {
Expand Down Expand Up @@ -86,6 +86,30 @@ export = {
test.done();
},

'bar view'(test: Test) {
// WHEN
const stack = new Stack();
const widget = new GraphWidget({
title: 'Test widget',
view: GraphWidgetView.BAR,
});

// THEN
test.deepEqual(stack.resolve(widget.toJson()), [{
type: 'metric',
width: 6,
height: 6,
properties: {
view: 'bar',
title: 'Test widget',
region: { Ref: 'AWS::Region' },
yAxis: {},
},
}]);

test.done();
},

'singlevalue widget'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down