Skip to content

Commit f9e90c4

Browse files
authored
Merge pull request #2816 from plotly/legendonly-arrayok-marker-symbol
Fix legend item for 'legendonly' traces with array 'marker.symbol'
2 parents e605853 + 10ac170 commit f9e90c4

File tree

3 files changed

+97
-30
lines changed

3 files changed

+97
-30
lines changed

src/components/legend/style.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ module.exports = function style(s, gd) {
8383
}
8484

8585
function stylePoints(d) {
86-
var d0 = d[0],
87-
trace = d0.trace,
88-
showMarkers = subTypes.hasMarkers(trace),
89-
showText = subTypes.hasText(trace),
90-
showLines = subTypes.hasLines(trace);
91-
86+
var d0 = d[0];
87+
var trace = d0.trace;
88+
var showMarkers = subTypes.hasMarkers(trace);
89+
var showText = subTypes.hasText(trace);
90+
var showLines = subTypes.hasLines(trace);
9291
var dMod, tMod;
9392

9493
// 'scatter3d' and 'scattergeo' don't use gd.calcdata yet;
9594
// use d0.trace to infer arrayOk attributes
9695

9796
function boundVal(attrIn, arrayToValFn, bounds) {
98-
var valIn = Lib.nestedProperty(trace, attrIn).get(),
99-
valToBound = (Array.isArray(valIn) && arrayToValFn) ?
100-
arrayToValFn(valIn) : valIn;
97+
var valIn = Lib.nestedProperty(trace, attrIn).get();
98+
var valToBound = (Array.isArray(valIn) && arrayToValFn) ?
99+
arrayToValFn(valIn) :
100+
valIn;
101101

102102
if(bounds) {
103103
if(valToBound < bounds[0]) return bounds[0];
@@ -115,6 +115,7 @@ module.exports = function style(s, gd) {
115115

116116
if(showMarkers) {
117117
dEdit.mc = boundVal('marker.color', pickFirst);
118+
dEdit.mx = boundVal('marker.symbol', pickFirst);
118119
dEdit.mo = boundVal('marker.opacity', Lib.mean, [0.2, 1]);
119120
dEdit.ms = boundVal('marker.size', Lib.mean, [2, 16]);
120121
dEdit.mlc = boundVal('marker.line.color', pickFirst);
-438 Bytes
Loading
Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,90 @@
11
{
2-
"data":[
3-
{"name":"bar A","type":"bar","y":["2","3","5","4","1"]},
4-
{"name":"bar B","type":"bar","visible":"legendonly","y":["3","5","7","6","8"]},
5-
{"name":"bar C","type":"bar","y":["2","4","6","3","8"]},
6-
{"name":"line A","yaxis":"y2","y":["2","3","5","4","1"]},
7-
{"name":"line B","yaxis":"y2","visible":"legendonly","y":["3","5","7","6","8"]},
8-
{"name":"line C","yaxis":"y2","y":["2","4","6","3","8"]},
9-
{"name":"box A","type":"box","xaxis":"x2","yaxis":"y3","y":[1,2,3,4,5,6,7,8,9]},
10-
{"name":"box B","type":"box","xaxis":"x2","yaxis":"y3","visible":"legendonly","y":[2,3,3,4,4,4,5,5,6]},
11-
{"name":"box C","type":"box","xaxis":"x2","yaxis":"y3","y":[1,4,6,7,7,8,8,8,9]}
12-
],
13-
"layout": {
14-
"showlegend":true,
15-
"height":400,
16-
"width":600,
17-
"barnorm":"fraction",
18-
"barmode":"stack",
19-
"xaxis":{"domain":[0,0.45]},
20-
"xaxis2":{"anchor":"y3","domain":[0.55,1]},
21-
"yaxis2":{"overlaying":"y","side":"right"},
22-
"yaxis3":{"anchor":"x2"}
2+
"data": [
3+
{
4+
"name": "bar A",
5+
"type": "bar",
6+
"y": ["2", "3", "5", "4", "1"]
7+
},
8+
{
9+
"name": "bar B",
10+
"type": "bar",
11+
"visible": "legendonly",
12+
"y": ["3", "5", "7", "6", "8"]
13+
},
14+
{
15+
"name": "bar C",
16+
"type": "bar",
17+
"y": ["2", "4", "6", "3", "8"]
18+
},
19+
{
20+
"name": "line A",
21+
"yaxis": "y2",
22+
"y": ["2", "3", "5", "4", "1"]
23+
},
24+
{
25+
"name": "line B",
26+
"yaxis": "y2",
27+
"visible": "legendonly",
28+
"y": ["3", "5", "7", "6", "8"]
29+
},
30+
{
31+
"name": "line C",
32+
"yaxis": "y2",
33+
"y": ["2", "4", "6", "3", "8"]
34+
},
35+
{
36+
"name": "box A",
37+
"type": "box",
38+
"xaxis": "x2",
39+
"yaxis": "y3",
40+
"y": [1, 2, 3, 4, 5, 6, 7, 8, 9]
41+
},
42+
{
43+
"name": "box B",
44+
"type": "box",
45+
"xaxis": "x2",
46+
"yaxis": "y3",
47+
"visible": "legendonly",
48+
"y": [2, 3, 3, 4, 4, 4, 5, 5, 6]
49+
},
50+
{
51+
"name": "box C",
52+
"type": "box",
53+
"xaxis": "x2",
54+
"yaxis": "y3",
55+
"y": [1, 4, 6, 7, 7, 8, 8, 8, 9]
56+
},
57+
{
58+
"name": "marker A",
59+
"mode": "markers",
60+
"visible": "legendonly",
61+
"y": [1, 4, 6, 3, 2, 8, 8, 8, 4],
62+
"yaxis": "y2",
63+
"marker": {
64+
"size": 15,
65+
"symbol": ["square", "square", "square", "square", "square", "square", "square", "square", "square"]
66+
}
2367
}
68+
],
69+
"layout": {
70+
"showlegend": true,
71+
"height": 400,
72+
"width": 600,
73+
"barnorm": "fraction",
74+
"barmode": "stack",
75+
"xaxis": {
76+
"domain": [0, 0.45]
77+
},
78+
"xaxis2": {
79+
"anchor": "y3",
80+
"domain": [0.55, 1]
81+
},
82+
"yaxis2": {
83+
"overlaying": "y",
84+
"side": "right"
85+
},
86+
"yaxis3": {
87+
"anchor": "x2"
88+
}
89+
}
2490
}

0 commit comments

Comments
 (0)