Skip to content
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

Fix box trace with "all" points and line_width=0 doesn't render marker in legend #7162

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7162_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Make marker render in legend when line is hidden with a width of 0 [[#7162](https://github.com/plotly/plotly.js/pull/7162)]
3 changes: 2 additions & 1 deletion src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ module.exports = function style(s, gd, legend) {
var p = d3.select(this);

if((trace.boxpoints === 'all' || trace.points === 'all') &&
Color.opacity(trace.fillcolor) === 0 && Color.opacity((trace.line || {}).color) === 0
Color.opacity(trace.fillcolor) === 0 &&
(Color.opacity((trace.line || {}).color) === 0 || trace.line.width === 0)
) {
var tMod = Lib.minExtend(trace, {
marker: {
Expand Down
Binary file modified test/image/baselines/box_violin_just_pts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 70 additions & 1 deletion test/image/mocks/box_violin_just_pts.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,76 @@
}
},
"hoveron": "points"
}
},
{
"type": "box",
"name": "box width",
"y": [
0.21241263286846768, 0.6283132500282779, 2.059323870167601,
2.1935119470597755, 2.7466418942243536, 3.467395904471225,
3.653212884314042, 4.5139456845169, 4.724443983818345, 4.133047160893449,
4.895798280700072, 4.125891534267504, 3.855907668878962, 4.339440306552532,
3.9878198050969598, 3.387742554567235, 2.4388348464827923,
2.0196998134080077, 1.6468702894198695, 0.9943017399397437,
0.6826942300835983, 0.3588816001294317, -0.9408555890714587,
-1.1907113828655032, -1.9452558895288188, -1.8469883412634,
-2.507784709721651, -3.504441099089313, -3.6122982876732115,
-3.9222888530079216, -3.602674433368737, -3.442554012650344,
-3.2412724072298866, -3.5032754904694814, -2.6048370351384453,
-2.2865075287581567, -1.5084596044414513, -1.7217543646801425,
-0.7771982562904898, 0.3107690591528869, 0.25029597778901336,
0.9298694888494701, 1.378244848035627, 2.354024310314667,
3.0684405570394957, 3.7112025463924434, 4.007092766797532,
4.1488920076238145, 4.176421256377431, 4.083935458554087
],
"boxpoints": "all",
"pointpos": 0,
"fillcolor": "rgba(0, 0, 0, 0)",
"line": {
"width": 0
},
"marker": {
"color": "#fc8d62",
"symbol": "cross"
},
"hoveron": "points"
},
{
"type": "violin",
"name": "violin width",
"y": [
0.21241263286846768, 0.6283132500282779, 2.059323870167601,
2.1935119470597755, 2.7466418942243536, 3.467395904471225,
3.653212884314042, 4.5139456845169, 4.724443983818345, 4.133047160893449,
4.895798280700072, 4.125891534267504, 3.855907668878962, 4.339440306552532,
3.9878198050969598, 3.387742554567235, 2.4388348464827923,
2.0196998134080077, 1.6468702894198695, 0.9943017399397437,
0.6826942300835983, 0.3588816001294317, -0.9408555890714587,
-1.1907113828655032, -1.9452558895288188, -1.8469883412634,
-2.507784709721651, -3.504441099089313, -3.6122982876732115,
-3.9222888530079216, -3.602674433368737, -3.442554012650344,
-3.2412724072298866, -3.5032754904694814, -2.6048370351384453,
-2.2865075287581567, -1.5084596044414513, -1.7217543646801425,
-0.7771982562904898, 0.3107690591528869, 0.25029597778901336,
0.9298694888494701, 1.378244848035627, 2.354024310314667,
3.0684405570394957, 3.7112025463924434, 4.007092766797532,
4.1488920076238145, 4.176421256377431, 4.083935458554087
],
"points": "all",
"pointpos": 0,
"fillcolor": "rgba(0, 0, 0, 0)",
"line": {
"width": 0
},
"marker": {
"color": "#8da0cb",
"size": 10,
"line": {
"width": 1
}
},
"hoveron": "points"
}
],
"layout": {
"legend": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @jnumainville ! This is a great fix.

Let's add "orientation": "h" to the legend spec so that the legend doesn't overlap the data points.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get that to work for some reason, not sure what I was doing wrong, so I flipped the "y" to "x" in the traces, hopefully that works.

Expand Down