fix(legend): apply dataset borderDash when pointStyle is line (#12291) - #12294
Open
vaibhavmashal wants to merge 1 commit into
Open
fix(legend): apply dataset borderDash when pointStyle is line (#12291)#12294vaibhavmashal wants to merge 1 commit into
vaibhavmashal wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes correctly address the legend dash inheritance bug and include targeted unit tests, with only minor optional performance tweaks suggested in review comments.
Pull request overview
Fixes legend rendering for usePointStyle: true with pointStyle: 'line' so the legend’s line symbol inherits the dataset’s dash pattern (borderDash / borderDashOffset), aligning legend output with dataset line styling.
Changes:
- Extended
drawPointLegendto accept/applylineDashandlineDashOffsetwhen renderingpointStyle: 'line'. - Updated legend label generation to resolve line-cap/join/dash properties from the dataset style when needed and pass them into the point-style drawing options.
- Added unit tests covering both the helper behavior and the legend integration.
File summaries
| File | Description |
|---|---|
src/helpers/helpers.canvas.ts |
Adds dash/offset support to DrawPointOptions and applies dash state for legend line point-style rendering. |
src/plugins/plugin.legend.js |
Resolves dataset line dash/cap/join for pointStyle: 'line' and forwards dash settings into drawPointLegend. |
test/specs/helpers.canvas.tests.js |
Adds a unit test verifying drawPointLegend sets dash and dash offset for pointStyle: 'line'. |
test/specs/plugin.legend.tests.js |
Adds an integration test asserting dashed datasets produce dashed legend line symbols. |
Review details
Suppressed comments (1)
src/plugins/plugin.legend.js:698
- After updating
getLegendItemStyleto accept a pre-resolved style, pass thestylecomputed ingenerateLabelsto avoid resolving the same style twice per dataset.
return chart._getSortedDatasetMetas().map((meta) => {
const style = meta.controller.getStyle(usePointStyle ? 0 : undefined);
const borderWidth = toPadding(style.borderWidth);
const lineStyle = getLegendItemStyle(meta, usePointStyle, pointStyle);
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+594
to
+605
| function getLegendItemStyle(meta, usePointStyle, pointStyle) { | ||
| const style = meta.controller.getStyle(usePointStyle ? 0 : undefined); | ||
| const resolvedPointStyle = pointStyle || style.pointStyle; | ||
| const datasetStyle = usePointStyle && resolvedPointStyle === 'line' ? meta.controller.getStyle() : {}; | ||
| return { | ||
| pointStyle: resolvedPointStyle, | ||
| lineCap: valueOrDefault(style.borderCapStyle, datasetStyle.borderCapStyle), | ||
| lineDash: valueOrDefault(style.borderDash, datasetStyle.borderDash), | ||
| lineDashOffset: valueOrDefault(style.borderDashOffset, datasetStyle.borderDashOffset), | ||
| lineJoin: valueOrDefault(style.borderJoinStyle, datasetStyle.borderJoinStyle), | ||
| }; | ||
| } |
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.
Fixes #12291
Description
When \usePointStyle: true\ with \pointStyle: 'line'\ is used in legend labels, the legend line segment should inherit and render with the dataset's \�orderDash\ and \�orderDashOffset\ pattern. Previously, only the color and width were inherited while the dash pattern was ignored.
Solution