feat(chart): add data labels support for charts#455
Open
SOUMITRO-SAHA wants to merge 1 commit intogetnao:mainfrom
Open
feat(chart): add data labels support for charts#455SOUMITRO-SAHA wants to merge 1 commit intogetnao:mainfrom
SOUMITRO-SAHA wants to merge 1 commit intogetnao:mainfrom
Conversation
Add optional data labels display functionality to chart components. Allows users to show values directly on chart elements (bars, points, etc.) - Add `show_data_labels` parameter to chart input schema - Implement data labels for bar charts with rotated labels and stack positioning - Add data labels for area charts with top-positioned labels - Update display components to support the new parameter - Add story segment parsing for `show_data_labels` attribute - Include data labels in chart blocks generated for stories Improves chart readability by allowing users to see exact values directly on the visualizations without needing to reference tooltips.
Contributor
There was a problem hiding this comment.
1 issue found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/shared/src/chart-builder.tsx">
<violation number="1" location="apps/shared/src/chart-builder.tsx:44">
P2: Pie chart rendering ignores the new `showDataLabels` option and always displays labels, causing inconsistent behavior across chart types.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| @@ -1,5 +1,17 @@ | |||
| import React from 'react'; | |||
Contributor
There was a problem hiding this comment.
P2: Pie chart rendering ignores the new showDataLabels option and always displays labels, causing inconsistent behavior across chart types.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/shared/src/chart-builder.tsx, line 44:
<comment>Pie chart rendering ignores the new `showDataLabels` option and always displays labels, causing inconsistent behavior across chart types.</comment>
<file context>
@@ -29,6 +41,7 @@ export interface BuildChartProps {
colorFor?: (key: string, index: number) => string;
labelFormatter?: (value: string) => string;
showGrid?: boolean;
+ showDataLabels?: boolean;
children?: React.ReactNode[];
margin?: { top?: number; right?: number; bottom?: number; left?: number };
</file context>
Contributor
🚀 Preview Deployment
Preview will be automatically removed when this PR is closed. |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

feat(charts): Add data label support
Closes: #396
Summary
This PR introduces the functionality to display data labels directly on chart elements (e.g., bars, line points, pie slices). This allows users to see the exact values of data points without needing to hover over them, significantly improving chart readability.
The AI agent can now be prompted to show labels (e.g., "show me sales with data labels"), and the labels will be rendered on the chart and preserved when added to stories.
Changes
display-chart.ts): Added an optionalshow_data_labels: booleanfield to thedisplay_charttool's input schema.chart-builder.tsx):line/areacharts, positioned above each data point.display-chart.tsxandstory-chart-embed.tsxto pass theshowDataLabelsprop to the chart rendering logic.show_data_labelsattribute in the generated<chart>tag.story-segments.ts): Updated the story parser to correctly read the show_data_labels attribute from saved stories.Before
Previously, charts did not display any data labels, even when requested. Values were only visible in tooltips on hover.
After
Charts now clearly display data labels when the
show_data_labelsoption is enabled. The label formatting is tailored to the chart type for optimal readability.How to test