aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

feat(aws-cloudwatch): support labels on pie charts

Open kofrasa opened this issue 1 year ago • 5 comments

Describe the feature

From the Cloudwatch console an option is provided to display labels on a pie chart which is implemented in the source with the property below.

    "labels": {
        "visible": true
    }

This is missing in the CDK library which makes it impossible to create dashboards with labels on pie charts.

Use Case

Without the labels on the dashboard, a user must explicitly hover their cursor on the dashboard widget for a specific segment. For teams projecting live dashboards on external display this is impractical since you cannot get a single view with labels for all the segments.

Proposed Solution

Include the missing property in the generated graph widget output following the steps below.

  • Add a new LabelProps interface to the aws-cloudwatch/lib/graph.ts module.
  • Expose this as an optional property called labels, consistent with name from the console, in the GraphWidgetProps.
  • Add the labels property to the final output of the toJson() method of the GraphWidget.

Other Information

No response

Acknowledgements

  • [X] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

CDK version used

2.124.0

Environment details (OS name and version, etc.)

MacOS, Sonama 14.3

kofrasa avatar Jan 30 '24 20:01 kofrasa

Thank you for your feedback. Yes we should add this support in a pull request.

pahud avatar Jan 30 '24 21:01 pahud

I will submit a PR

kofrasa avatar Jan 30 '24 23:01 kofrasa

For those looking for a workaround, this very basic implementation worked well enough for me

class LabeledPieWidget extends GraphWidget {
  override toJson(): any[] {
    const json = super.toJson();
    json[0].properties.labels = { visible: true };
    return json;
  }
}

usage:

new LabeledPieWidget({
  view: GraphWidgetView.PIE,
  // ...
})

Kasra-G avatar Jun 11 '25 03:06 Kasra-G

@kofrasa I could potentially submit a PR for this if you are no longer working on it

Kasra-G avatar Jun 12 '25 21:06 Kasra-G

@Kasra-G Please go ahead. I already used the workaround. The PR stalled due to some issues in the testing environment that I never got to resolving.

kofrasa avatar Jun 12 '25 22:06 kofrasa

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

github-actions[bot] avatar Sep 01 '25 13:09 github-actions[bot]