Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts chart data label display logic so stacked bar charts only show labels for non-zero values, preventing overlapping text, and updates the chart project metadata. Sequence diagram for stacked bar chart data label display logicsequenceDiagram
participant ChartComponent
participant getChartOption
participant ChartJS
ChartComponent->>getChartOption: getChartOption(option)
getChartOption->>getChartOption: read option.options.showDataLabel
alt x axis stacked and showDataLabel true
getChartOption->>ChartJS: set dataLabels.display = showDataLabel(context)
ChartJS->>ChartJS: showDataLabel(context)
alt Number(context.dataset.data[context.dataIndex]) !== 0
ChartJS->>ChartJS: render data label
else Number(...) === 0
ChartJS->>ChartJS: skip data label
end
else not stacked or showDataLabel not true
getChartOption->>ChartJS: set dataLabels.display = option.options.showDataLabel
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Accessing
option.options.x.stackedwithout checking thatoptions.xexists may throw if x-axis config is omitted; consider guarding this access or providing a safe default. - The data label display condition
Number(...) !== 0will show labels for negative values andNaN; if the intent is to hide labels on zero-height bars only, consider a stricter check (e.g.> 0) or explicitly handling non-numeric values.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Accessing `option.options.x.stacked` without checking that `options.x` exists may throw if x-axis config is omitted; consider guarding this access or providing a safe default.
- The data label display condition `Number(...) !== 0` will show labels for negative values and `NaN`; if the intent is to hide labels on zero-height bars only, consider a stricter check (e.g. `> 0`) or explicitly handling non-numeric values.
## Individual Comments
### Comment 1
<location path="src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js" line_range="385" />
<code_context>
+ let showDataLabel = option.options.showDataLabel;
+ if (showDataLabel === true && option.options.x.stacked) {
+ showDataLabel = context => Number(context.dataset?.data[context.dataIndex]) !== 0;
+ }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Refine the zero-check logic to avoid treating `undefined`/`null` as non-zero values.
`Number(context.dataset?.data[context.dataIndex]) !== 0` will treat `undefined`, `null`, or non-numeric values as `NaN`, which still passes the `!== 0` check, so labels may appear for missing/invalid data. Use a more explicit guard, e.g.:
```ts
const v = context.dataset?.data[context.dataIndex];
return v != null && Number(v) !== 0;
```
to restrict labels to meaningful, non-zero values.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| let showDataLabel = option.options.showDataLabel; | ||
| if (showDataLabel === true && option.options.x.stacked) { | ||
| showDataLabel = context => Number(context.dataset?.data[context.dataIndex]) !== 0; |
There was a problem hiding this comment.
issue (bug_risk): Refine the zero-check logic to avoid treating undefined/null as non-zero values.
Number(context.dataset?.data[context.dataIndex]) !== 0 will treat undefined, null, or non-numeric values as NaN, which still passes the !== 0 check, so labels may appear for missing/invalid data. Use a more explicit guard, e.g.:
const v = context.dataset?.data[context.dataIndex];
return v != null && Number(v) !== 0;to restrict labels to meaningful, non-zero values.
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.
Link issues
fixes #1057
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Bug Fixes: