Skip to content

Commit 236e3c7

Browse files
committed
Position title after legend width calculated
1 parent a5577d9 commit 236e3c7

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/components/legend/draw.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ function drawOne(gd, opts) {
148148
var title = legendObj.title;
149149
legendObj._titleWidth = 0;
150150
legendObj._titleHeight = 0;
151+
var titleEl;
151152
if(title.text) {
152-
var titleEl = Lib.ensureSingle(scrollBox, 'text', legendId + 'titletext');
153+
titleEl = Lib.ensureSingle(scrollBox, 'text', legendId + 'titletext');
153154
titleEl.attr('text-anchor', 'start')
154155
.call(Drawing.font, title.font)
155156
.text(title.text);
@@ -193,6 +194,11 @@ function drawOne(gd, opts) {
193194
var isPaperX = legendObj.xref === 'paper';
194195
var isPaperY = legendObj.yref === 'paper';
195196

197+
// re-calculate title position after legend width is derived. To allow for horizontal alignment
198+
if(title.text) {
199+
textLayout(titleEl, scrollBox, gd, legendObj, MAIN_TITLE);
200+
}
201+
196202
if(!inHover) {
197203
var lx, ly;
198204

-17.8 KB
Loading

test/image/mocks/legend_horizontal_one_row.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
],
2222
"layout": {
23+
"height": 300,
2324
"title": {"text": "Average Distribution per Month"},
2425
"legend": { "orientation": "h", "title": { "text": "Legend Title", "side": "top center" }}
2526
}

0 commit comments

Comments
 (0)