-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add support for dashed marker lines in scatter plots #7673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
- Enable `marker.line.dash` attribute in scatter trace definitions with support for array values - Apply dash patterns to marker outlines in both open and closed marker styles - Merge dash data into calcdata for per-point dash styling - Include dash information in legend marker rendering to match trace appearance - Default dash handling falls back to trace-level `marker.line.dash` when per-point values are not specified
- Document new feature that adds support for dashed marker lines in scatter plots - Reference pull request plotly#7673 for tracking purposes
- Extends marker line styling capabilities by including the `dash` attribute alongside existing `width` attribute - Enables dashed marker line borders for `scatter3d`, `scattercarpet`, `scattergeo`, `scattergl`, `scatterternary`, and `splom` trace types - Maintains consistency with base scatter trace marker line attributes by reusing `scatterMarkerLineAttrs.dash` - Applies appropriate constraints where needed, such as `arrayOk: false` for 3D traces and `editType: 'calc'` for other trace types
- Prevent marker line borders from rendering on blank data points by setting line width to 0 when `d.isBlank` is true in the `singlePointStyle()` function - Add `dash` and `dashsrc` schema attributes for marker line styling across multiple chart types to support customisable dash patterns - Ensure blank points appear correctly without visible outlines while maintaining proper styling for non-blank markers
- Add `dash` property to marker line configurations across multiple plot types, allowing customisation of line dash patterns - Support both predefined dash styles (`solid`, `dot`, `dash`, `longdash`, `dashdot`, `longdashdot`) and custom dash length lists in pixels - Include `dashsrc` property for Chart Studio Cloud integration to enable data source references for dash styling - Set default value to `solid` for consistent backward compatibility - Enable array support for most implementations to allow per-marker dash customisation
- Simplify the dash line styling implementation by replacing the single `.style()` call with an object parameter with chained `.style()` method calls - Set `stroke-dasharray` to `null` when dash is falsy to properly clear the style rather than setting it to an empty or undefined value - Improve code readability through method chaining pattern
- Consolidate style application in `dashLine()` function to use object notation instead of chained method calls - Remove unused `lineDash` variable and associated `dashLine()` calls in marker styling logic - Eliminate redundant dash line styling for open markers and blank points that was not being applied correctly
camdecoster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this PR together! You've done part of the work, but you'll need to update src/components/drawing/index.js to get the dashed lines to draw. On line 967, if you add the following, you should see the dashes:
const lineDash = d.mld || (markerLine || {}).dash;
if (lineDash) drawing.dashLine(sel, lineDash, lineWidth);Additionally, there are some traces that won't be compatible with this change due to not being supported in WebGL. Could you please remove the following traces from this PR?:
- scatter3d
- scattergl
- splom
From my research, these traces seem like they would most benefit from this feature:
- scatter
- scatterpolar
- scattergeo
- scattermap
- scattercarpet
- scatterternary
- scattersmith
Could you add this feature to all of these traces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove this file from the PR? It only gets updated during releases.
| }, | ||
| dash: extendFlat({}, dash, { | ||
| arrayOk: true, | ||
| editType: 'style' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property already exists on the dash object, so it isn't needed here.
| editType: 'style' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the changes for scatter3d. A dashed line isn't supported at the moment since it doesn't use SVG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the changes for scattergl. A dashed line isn't supported at the moment since it doesn't use SVG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the changes for splom. A dashed line isn't supported at the moment since it doesn't use SVG.
📝 Overview
Introduce support for customising marker line dash patterns in scatter plots, addressing issue #7667.
Currently, the
marker.lineobject only supports properties likecolorandwidth. This PR exposes thedashproperty, allowing users to specify dash styles (e.g., "dash", "dot", "solid") or custom dash lengths for marker borders. This feature is essential for creating clear visual distinctions in scatter plots, such as distinguishing between original and imputed data points, without relying solely on colour or marker symbols.🛠️ Implementation Details
The implementation involves changes across several files to enable the
dashattribute, process it during the calculation step, and render it correctly in both the plot and the legend.Scatter marker line dash support
dashas a supported property in themarker.lineattribute for scatter traces insrc/traces/scatter/attributes.js, including array support.src/traces/scatter/marker_defaults.jsto coercemarker.line.dashvalues, ensuring the property is initialised properly.src/traces/scatter/arrays_to_calcdata.jsto mergemarker.line.dashvalues into the calculated data array (cd) asmld, enabling per-point dash customisation.Rendering updates
drawing.singlePointStylewithinsrc/components/drawing/index.jsto apply the dash pattern to marker outlines. This support both open markers (where the border is the main visual) and closed markers.drawing.dashLineto apply the dash style.src/components/legend/style.jsto includemarker.line.dashin legend item representations, ensuring the legend matches the trace appearance.🚀 Use Case & Example
This feature allow for perfect, fixed-size circles with dashed outlines, which was previously not possible with
markers(only solid lines) orshapes(which distort with axis scaling).Example Usage: (Python)
Closes #7667