Skip to content

Commit 2bbf486

Browse files
authored
Merge pull request #3846 from plotly/box-violin-legend-item-just-pts
Draw box/violin pts as legend item when other parts have opacity 0
2 parents 2ac74c0 + eed7812 commit 2bbf486

File tree

3 files changed

+166
-4
lines changed

3 files changed

+166
-4
lines changed

Diff for: src/components/legend/style.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,27 @@ module.exports = function style(s, gd) {
356356

357357
pts.each(function() {
358358
var p = d3.select(this);
359-
var w = boundLineWidth(undefined, trace.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);
360359

361-
p.style('stroke-width', w + 'px')
362-
.call(Color.fill, trace.fillcolor);
360+
if((trace.boxpoints === 'all' || trace.points === 'all') &&
361+
Color.opacity(trace.fillcolor) === 0 && Color.opacity((trace.line || {}).color) === 0
362+
) {
363+
var tMod = Lib.minExtend(trace, {
364+
marker: {
365+
size: constantItemSizing ? CST_MARKER_SIZE : Lib.constrain(trace.marker.size, 2, 16),
366+
sizeref: 1,
367+
sizemin: 1,
368+
sizemode: 'diameter'
369+
}
370+
});
371+
pts.call(Drawing.pointStyle, tMod, gd);
372+
} else {
373+
var w = boundLineWidth(undefined, trace.line, MAX_MARKER_LINE_WIDTH, CST_MARKER_LINE_WIDTH);
363374

364-
if(w) Color.stroke(p, trace.line.color);
375+
p.style('stroke-width', w + 'px')
376+
.call(Color.fill, trace.fillcolor);
377+
378+
if(w) Color.stroke(p, trace.line.color);
379+
}
365380
});
366381
}
367382

Diff for: test/image/baselines/box_violin_just_pts.png

29.7 KB
Loading

Diff for: test/image/mocks/box_violin_just_pts.json

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"data": [
3+
{
4+
"type": "box",
5+
"name": "box",
6+
"y": [
7+
0.21241263286846768,
8+
0.6283132500282779,
9+
2.059323870167601,
10+
2.1935119470597755,
11+
2.7466418942243536,
12+
3.467395904471225,
13+
3.653212884314042,
14+
4.5139456845169,
15+
4.724443983818345,
16+
4.133047160893449,
17+
4.895798280700072,
18+
4.125891534267504,
19+
3.855907668878962,
20+
4.339440306552532,
21+
3.9878198050969598,
22+
3.387742554567235,
23+
2.4388348464827923,
24+
2.0196998134080077,
25+
1.6468702894198695,
26+
0.9943017399397437,
27+
0.6826942300835983,
28+
0.3588816001294317,
29+
-0.9408555890714587,
30+
-1.1907113828655032,
31+
-1.9452558895288188,
32+
-1.8469883412634,
33+
-2.507784709721651,
34+
-3.504441099089313,
35+
-3.6122982876732115,
36+
-3.9222888530079216,
37+
-3.602674433368737,
38+
-3.442554012650344,
39+
-3.2412724072298866,
40+
-3.5032754904694814,
41+
-2.6048370351384453,
42+
-2.2865075287581567,
43+
-1.5084596044414513,
44+
-1.7217543646801425,
45+
-0.7771982562904898,
46+
0.3107690591528869,
47+
0.25029597778901336,
48+
0.9298694888494701,
49+
1.378244848035627,
50+
2.354024310314667,
51+
3.0684405570394957,
52+
3.7112025463924434,
53+
4.007092766797532,
54+
4.1488920076238145,
55+
4.176421256377431,
56+
4.083935458554087
57+
],
58+
"boxpoints": "all",
59+
"pointpos": 0,
60+
"fillcolor": "rgba(0, 0, 0, 0)",
61+
"line": {
62+
"color": "rgba(0, 0, 0, 0)"
63+
},
64+
"marker": {
65+
"color": "#fc8d62",
66+
"symbol": "cross"
67+
},
68+
"hoveron": "points"
69+
},
70+
{
71+
"type": "violin",
72+
"name": "violin",
73+
"y": [
74+
0.21241263286846768,
75+
0.6283132500282779,
76+
2.059323870167601,
77+
2.1935119470597755,
78+
2.7466418942243536,
79+
3.467395904471225,
80+
3.653212884314042,
81+
4.5139456845169,
82+
4.724443983818345,
83+
4.133047160893449,
84+
4.895798280700072,
85+
4.125891534267504,
86+
3.855907668878962,
87+
4.339440306552532,
88+
3.9878198050969598,
89+
3.387742554567235,
90+
2.4388348464827923,
91+
2.0196998134080077,
92+
1.6468702894198695,
93+
0.9943017399397437,
94+
0.6826942300835983,
95+
0.3588816001294317,
96+
-0.9408555890714587,
97+
-1.1907113828655032,
98+
-1.9452558895288188,
99+
-1.8469883412634,
100+
-2.507784709721651,
101+
-3.504441099089313,
102+
-3.6122982876732115,
103+
-3.9222888530079216,
104+
-3.602674433368737,
105+
-3.442554012650344,
106+
-3.2412724072298866,
107+
-3.5032754904694814,
108+
-2.6048370351384453,
109+
-2.2865075287581567,
110+
-1.5084596044414513,
111+
-1.7217543646801425,
112+
-0.7771982562904898,
113+
0.3107690591528869,
114+
0.25029597778901336,
115+
0.9298694888494701,
116+
1.378244848035627,
117+
2.354024310314667,
118+
3.0684405570394957,
119+
3.7112025463924434,
120+
4.007092766797532,
121+
4.1488920076238145,
122+
4.176421256377431,
123+
4.083935458554087
124+
],
125+
"points": "all",
126+
"pointpos": 0,
127+
"fillcolor": "rgba(0, 0, 0, 0)",
128+
"line": {
129+
"color": "rgba(0, 0, 0, 0)"
130+
},
131+
"marker": {
132+
"color": "#8da0cb",
133+
"size": 10,
134+
"line": {
135+
"width": 1
136+
}
137+
},
138+
"hoveron": "points"
139+
}
140+
],
141+
"layout": {
142+
"legend": {
143+
"x": 0,
144+
"y": 1
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)