Skip to content

Commit e84bcb9

Browse files
committed
🔪 handling of horizontal legendgroup
1 parent cff31df commit e84bcb9

File tree

4 files changed

+51
-42
lines changed

4 files changed

+51
-42
lines changed

src/components/legend/draw.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -585,48 +585,6 @@ function computeLegendDimensions(gd, groups, traces) {
585585

586586
extraWidth = 40;
587587
}
588-
else if(isGrouped) {
589-
var groupXOffsets = [opts._width];
590-
var groupData = groups.data();
591-
592-
for(var i = 0, n = groupData.length; i < n; i++) {
593-
var textWidths = groupData[i].map(function(legendItemArray) {
594-
return legendItemArray[0].width;
595-
});
596-
597-
var groupWidth = 40 + Math.max.apply(null, textWidths);
598-
599-
opts._width += opts.tracegroupgap + groupWidth;
600-
601-
groupXOffsets.push(opts._width);
602-
}
603-
604-
groups.each(function(d, i) {
605-
Drawing.setTranslate(this, groupXOffsets[i], 0);
606-
});
607-
608-
groups.each(function() {
609-
var group = d3.select(this);
610-
var groupTraces = group.selectAll('g.traces');
611-
var groupHeight = 0;
612-
613-
groupTraces.each(function(d) {
614-
var legendItem = d[0];
615-
var textHeight = legendItem.height;
616-
617-
Drawing.setTranslate(this,
618-
0,
619-
(5 + borderwidth + groupHeight + textHeight / 2));
620-
621-
groupHeight += textHeight;
622-
});
623-
624-
opts._height = Math.max(opts._height, groupHeight);
625-
});
626-
627-
opts._height += 10 + borderwidth * 2;
628-
opts._width += borderwidth * 2;
629-
}
630588
else {
631589
var rowHeight = 0;
632590
var maxTraceHeight = 0;
Loading
Loading
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"data": [{
3+
"x": [1, 2, 3, 4],
4+
"y": [63.69, 62.55, 61.64, 61.39],
5+
"legendgroup": 1
6+
}, {
7+
"x": [1, 2, 3, 4],
8+
"y": [58.24, 54.93, 42.11, 50.75],
9+
"legendgroup": 1
10+
}, {
11+
"x": [1, 2, 3, 4],
12+
"y": [51.49, 49.59, 37.12, 31.45]
13+
}, {
14+
"x": [1, 2, 3, 4],
15+
"y": [49.09, 58.54, 53.91, 43.12]
16+
}, {
17+
"x": [1, 2, 3, 4],
18+
"y": [70.53, 72.51, 72.28, 78.65]
19+
}, {
20+
"x": [1, 2, 3, 4],
21+
"y": [62.69, 59.09, 63.82, 62]
22+
}, {
23+
"x": [1, 2, 3, 4],
24+
"y": [76.27, 71.43, 59.83, 64.34]
25+
}, {
26+
"x": [1, 2, 3, 4],
27+
"y": [71.15, 81.82, 88.46, 74.29]
28+
}, {
29+
"x": [1, 2, 3, 4],
30+
"y": [57.89, 57.38, 52.08, 63.83]
31+
}, {
32+
"x": [1, 2, 3, 4],
33+
"y": [65.4, 63.27, 65.78, 64.03]
34+
}],
35+
"layout": {
36+
"width": 600,
37+
"legend": {
38+
"orientation": "h"
39+
},
40+
"xaxis": {
41+
"type": "linear",
42+
"range": [0.7840236686390533, 4.215976331360947],
43+
"autorange": true
44+
},
45+
"yaxis": {
46+
"type": "linear",
47+
"range": [27.274108280254776, 92.63589171974522],
48+
"autorange": true
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)