diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/DashboardWithGraphWidgetWithLabelsIntegrationTest.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/DashboardWithGraphWidgetWithLabelsIntegrationTest.assets.json new file mode 100644 index 0000000000000..dece896fe612a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/DashboardWithGraphWidgetWithLabelsIntegrationTest.assets.json @@ -0,0 +1,19 @@ +{ + "version": "30.0.0", + "files": { + "fa0b1fe0c3043238b7413b794c626bac246c94f150aa6e3ff441a030d7dce521": { + "source": { + "path": "DashboardWithGraphWidgetWithLabelsIntegrationTest.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "fa0b1fe0c3043238b7413b794c626bac246c94f150aa6e3ff441a030d7dce521.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/DashboardWithGraphWidgetWithLabelsIntegrationTest.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/DashboardWithGraphWidgetWithLabelsIntegrationTest.template.json new file mode 100644 index 0000000000000..8b9b5d39e5340 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/DashboardWithGraphWidgetWithLabelsIntegrationTest.template.json @@ -0,0 +1,55 @@ +{ + "Resources": { + "DashCCD7F836": { + "Type": "AWS::CloudWatch::Dashboard", + "Properties": { + "DashboardBody": { + "Fn::Join": [ + "", + [ + "{\"widgets\":[{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":0,\"properties\":{\"view\":\"pie\",\"title\":\"My fancy graph\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\",{\"label\":\"Metric left 1 - p99\",\"stat\":\"p99\"}],[\"CDK/Test\",\"Metric\",{\"label\":\"Metric left 2 - TC_10P_90P\",\"stat\":\"TC(10%:90%)\"}],[\"CDK/Test\",\"Metric\",{\"label\":\"Metric left 3 - TS(5%:95%)\",\"stat\":\"TS(5%:95%)\"}],[\"CDK/Test\",\"Metric\",{\"label\":\"Metric right 1 - p90.1234\",\"stat\":\"p90.1234\",\"yAxis\":\"right\"}]],\"yAxis\":{},\"labels\":{\"visible\":true}}}]}" + ] + ] + } + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } + } \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdk.out new file mode 100644 index 0000000000000..9982913536117 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdk.out @@ -0,0 +1 @@ +{"version":"30.0.0"} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets.json new file mode 100644 index 0000000000000..2fcd64b88063a --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets.json @@ -0,0 +1,19 @@ +{ + "version": "30.0.0", + "files": { + "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { + "source": { + "path": "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.template.json", + "packaging": "file" + }, + "destinations": { + "current_account-current_region": { + "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", + "objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" + } + } + } + }, + "dockerImages": {} +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.template.json new file mode 100644 index 0000000000000..ec488341c0126 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.template.json @@ -0,0 +1,36 @@ +{ + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/integ.json new file mode 100644 index 0000000000000..0960e066d0248 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "30.0.0", + "testCases": { + "cdk-integ-dashboard-with-graph-widget-with-lables/DefaultTest": { + "stacks": [ + "DashboardWithGraphWidgetWithLabelsIntegrationTest" + ], + "assertionStack": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert", + "assertionStackName": "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74" + } + } +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/manifest.json new file mode 100644 index 0000000000000..d1032a4e91b43 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/manifest.json @@ -0,0 +1,111 @@ +{ + "version": "30.0.0", + "artifacts": { + "DashboardWithGraphWidgetWithLabelsIntegrationTest.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "DashboardWithGraphWidgetWithLabelsIntegrationTest.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "DashboardWithGraphWidgetWithLabelsIntegrationTest": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "DashboardWithGraphWidgetWithLabelsIntegrationTest.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fa0b1fe0c3043238b7413b794c626bac246c94f150aa6e3ff441a030d7dce521.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "DashboardWithGraphWidgetWithLabelsIntegrationTest.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "DashboardWithGraphWidgetWithLabelsIntegrationTest.assets" + ], + "metadata": { + "/DashboardWithGraphWidgetWithLabelsIntegrationTest/Dash/Resource": [ + { + "type": "aws:cdk:logicalId", + "data": "DashCCD7F836" + } + ], + "/DashboardWithGraphWidgetWithLabelsIntegrationTest/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/DashboardWithGraphWidgetWithLabelsIntegrationTest/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "DashboardWithGraphWidgetWithLabelsIntegrationTest" + }, + "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets": { + "type": "cdk:asset-manifest", + "properties": { + "file": "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74": { + "type": "aws:cloudformation:stack", + "environment": "aws://unknown-account/unknown-region", + "properties": { + "templateFile": "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.template.json", + "validateOnSynth": false, + "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", + "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json", + "requiresBootstrapStackVersion": 6, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", + "additionalDependencies": [ + "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets" + ], + "lookupRole": { + "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", + "requiresBootstrapStackVersion": 8, + "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" + } + }, + "dependencies": [ + "cdkintegdashboardwithgraphwidgetwithlabelsDefaultTestDeployAssertD4707D74.assets" + ], + "metadata": { + "/cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "CheckBootstrapVersion" + } + ] + }, + "displayName": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert" + }, + "Tree": { + "type": "cdk:tree", + "properties": { + "file": "tree.json" + } + } + } +} diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/tree.json new file mode 100644 index 0000000000000..216cf9d2bf236 --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.js.snapshot/tree.json @@ -0,0 +1,136 @@ +{ + "version": "tree-0.1", + "tree": { + "id": "App", + "path": "", + "children": { + "DashboardWithGraphWidgetWithLabelsIntegrationTest": { + "id": "DashboardWithGraphWidgetWithLabelsIntegrationTest", + "path": "DashboardWithGraphWidgetWithLabelsIntegrationTest", + "children": { + "Dash": { + "id": "Dash", + "path": "DashboardWithGraphWidgetWithLabelsIntegrationTest/Dash", + "children": { + "Resource": { + "id": "Resource", + "path": "DashboardWithGraphWidgetWithLabelsIntegrationTest/Dash/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::CloudWatch::Dashboard", + "aws:cdk:cloudformation:props": { + "dashboardBody": { + "Fn::Join": [ + "", + [ + "{\"widgets\":[{\"type\":\"metric\",\"width\":6,\"height\":6,\"x\":0,\"y\":0,\"properties\":{\"view\":\"timeSeries\",\"title\":\"My fancy graph\",\"region\":\"", + { + "Ref": "AWS::Region" + }, + "\",\"metrics\":[[\"CDK/Test\",\"Metric\",{\"label\":\"Metric left 1 - p99\",\"stat\":\"p99\"}],[\"CDK/Test\",\"Metric\",{\"label\":\"Metric left 2 - TC_10P_90P\",\"stat\":\"TC(10%:90%)\"}],[\"CDK/Test\",\"Metric\",{\"label\":\"Metric left 3 - TS(5%:95%)\",\"stat\":\"TS(5%:95%)\"}],[\"CDK/Test\",\"Metric\",{\"label\":\"Metric right 1 - p90.1234\",\"stat\":\"p90.1234\",\"yAxis\":\"right\"}]],\"yAxis\":{},\"labels\":{\"visible\":true}}}]}" + ] + ] + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-cloudwatch.CfnDashboard", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-cloudwatch.Dashboard", + "version": "0.0.0" + } + }, + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "DashboardWithGraphWidgetWithLabelsIntegrationTest/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "DashboardWithGraphWidgetWithLabelsIntegrationTest/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + }, + "cdk-integ-dashboard-with-graph-widget-with-labels": { + "id": "cdk-integ-dashboard-with-graph-widget-with-labels", + "path": "cdk-integ-dashboard-with-graph-widget-with-labels", + "children": { + "DefaultTest": { + "id": "DefaultTest", + "path": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest", + "children": { + "Default": { + "id": "Default", + "path": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/Default", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.252" + } + }, + "DeployAssert": { + "id": "DeployAssert", + "path": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert", + "children": { + "BootstrapVersion": { + "id": "BootstrapVersion", + "path": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert/BootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnParameter", + "version": "0.0.0" + } + }, + "CheckBootstrapVersion": { + "id": "CheckBootstrapVersion", + "path": "cdk-integ-dashboard-with-graph-widget-with-labels/DefaultTest/DeployAssert/CheckBootstrapVersion", + "constructInfo": { + "fqn": "@aws-cdk/core.CfnRule", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.Stack", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTestCase", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/integ-tests.IntegTest", + "version": "0.0.0" + } + }, + "Tree": { + "id": "Tree", + "path": "Tree", + "constructInfo": { + "fqn": "constructs.Construct", + "version": "10.1.252" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/core.App", + "version": "0.0.0" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.ts new file mode 100644 index 0000000000000..e4662ec2a1bbc --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-cloudwatch/test/integ.dashboard-with-graphwidget-with-labels.ts @@ -0,0 +1,56 @@ +import { App, Stack, StackProps } from 'aws-cdk-lib'; +import { IntegTest } from '@aws-cdk/integ-tests-alpha'; +import { Dashboard, GraphWidget, GraphWidgetView, Metric, Stats } from 'aws-cdk-lib/aws-cloudwatch'; + +class DashboardWithGraphWidgetWithLabelsIntegrationTest extends Stack { + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); + + const dashboard = new Dashboard(this, 'Dash'); + + const widget = new GraphWidget({ + title: 'My fancy graph', + view: GraphWidgetView.PIE, + left: [ + new Metric({ + namespace: 'CDK/Test', + metricName: 'Metric', + label: 'Metric left 1 - p99', + statistic: Stats.p(99), + }), + + new Metric({ + namespace: 'CDK/Test', + metricName: 'Metric', + label: 'Metric left 2 - TC_10P_90P', + statistic: Stats.tc(10, 90), + }), + + new Metric({ + namespace: 'CDK/Test', + metricName: 'Metric', + label: 'Metric left 3 - TS(5%:95%)', + statistic: 'TS(5%:95%)', + }), + ], + right: [ + new Metric({ + namespace: 'CDK/Test', + metricName: 'Metric', + label: 'Metric right 1 - p90.1234', + statistic: 'p90.1234', + }), + ], + labels: { + visible: true, + }, + }); + + dashboard.addWidgets(widget); + } +} + +const app = new App(); +new IntegTest(app, 'cdk-integ-dashboard-with-graph-widget-with-labels', { + testCases: [new DashboardWithGraphWidgetWithLabelsIntegrationTest(app, 'DashboardWithGraphWidgetWithLabelsIntegrationTest')], +}); \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-cloudwatch/README.md b/packages/aws-cdk-lib/aws-cloudwatch/README.md index be53d4f3becdd..02839fbd24156 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/README.md +++ b/packages/aws-cdk-lib/aws-cloudwatch/README.md @@ -496,6 +496,16 @@ dashboard.addWidgets(new cloudwatch.GraphWidget({ })); ``` +When the `view` property is set to `GraphWidgetView.PIE`, the `labels` property can be used to toggle whether the magnitude of a pie segment is shown on the graph as a percentage of the whole. + +```ts +dashboard.addWiedgets(new cloudwatch.GraphWidget({ + // ... + view: cloudwatch.GraphWidgetView.PIE, + labels: { visible: true }, +})); +``` + ### Table Widget A `TableWidget` can display any number of metrics in tabular form. diff --git a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts index 008513b30d9cc..0f8501e512794 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/lib/graph.ts @@ -71,6 +71,21 @@ export interface YAxisProps { readonly showUnits?: boolean; } +/** + * Properties for lables shown on the graph. + */ +export interface LabelProps { + /** + * Whether to display labels on chart. + * + * If false, no labels are shown directly on the pie chart; + * if true, each segment of the pie chat is labelled with the percentage contribution. + * + * @default false + */ + readonly visible?: boolean; +} + /** * Properties for an AlarmWidget */ @@ -373,6 +388,13 @@ export interface GraphWidgetProps extends MetricWidgetProps { */ readonly view?: GraphWidgetView; + /** + * Properties for the graph's labels. Only applicable for Pie charts. + * + * @default - None + */ + readonly labels?: LabelProps; + /** * Whether to show the value from the entire time range. Only applicable for Bar and Pie charts. * @@ -508,6 +530,7 @@ export class GraphWidget extends ConcreteWidget { right: this.props.rightYAxis ?? undefined, }, legend: this.props.legendPosition !== undefined ? { position: this.props.legendPosition } : undefined, + labels: this.props.labels, liveData: this.props.liveData, setPeriodToTimeRange: this.props.setPeriodToTimeRange, period: this.props.period?.toSeconds(), diff --git a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts index dd70bce845df0..ab24443b24cd3 100644 --- a/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts +++ b/packages/aws-cdk-lib/aws-cloudwatch/test/graphs.test.ts @@ -1106,6 +1106,32 @@ describe('Graphs', () => { }]); }); + test('add labels to GraphWidget piehcart', () => { + // GIVEN + const stack = new Stack(); + const widget = new GraphWidget({ + left: [new Metric({ namespace: 'CDK', metricName: 'Test' })], + view: GraphWidgetView.PIE, + labels: { visible: true }, + }); + + // THEN + expect(stack.resolve(widget.toJson())).toEqual([{ + type: 'metric', + width: 6, + height: 6, + properties: { + view: 'pie', + region: { Ref: 'AWS::Region' }, + metrics: [ + ['CDK', 'Test'], + ], + yAxis: {}, + labels: { visible: true }, + }, + }]); + }); + describe('TableWidget', () => { let stack; let metric;