Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test for legends with title and scroll - fix title scroll
  • Loading branch information
archmoj committed Nov 29, 2019
commit ce35947f2e39730f4a2005fcc21c0f81387d68cc
6 changes: 3 additions & 3 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ module.exports = function draw(gd) {
.call(Color.fill, opts.bgcolor)
.style('stroke-width', opts.borderwidth + 'px');

var scrollBox = Lib.ensureSingle(legend, 'g', 'scrollbox');

var title = opts.title;
opts._titleWidth = 0;
opts._titleHeight = 0;
if(title.text) {
var titleEl = Lib.ensureSingle(legend, 'text', 'legendtitletext');
var titleEl = Lib.ensureSingle(scrollBox, 'text', 'legendtitletext');
titleEl.attr('text-anchor', 'start')
.classed('user-select-none', true)
.call(Drawing.font, title.font)
.text(title.text);

textLayout(titleEl, legend, gd); // handle mathjax or multi-line text and compute title height
textLayout(titleEl, scrollBox, gd); // handle mathjax or multi-line text and compute title height
}
var scrollBox = Lib.ensureSingle(legend, 'g', 'scrollbox');

var scrollBar = Lib.ensureSingle(legend, 'rect', 'scrollbar', function(s) {
s.attr(constants.scrollBarEnterAttrs)
Expand Down
Binary file added test/image/baselines/legend_scroll_with_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 132 additions & 0 deletions test/image/mocks/legend_scroll_with_title.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"data": [
{
"x": [1,2,3],
"y": [1,2,3],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [2,3,4],
"type": "bar"
},
{
"x": [1,2,3],
"y": [3,4,5],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [4,5,6],
"type": "bar"
},
{
"x": [1,2,3],
"y": [5,6,7],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [6,7,8],
"type": "bar"
},
{
"x": [1,2,3],
"y": [7,8,9],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [8,9,10],
"type": "bar"
},
{
"x": [1,2,3],
"y": [9,10,11],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [10,11,12],
"type": "bar"
},
{
"x": [1,2,3],
"y": [11,12,13],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [12,13,14],
"type": "bar"
},
{
"x": [1,2,3],
"y": [13,14,15],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [14,15,16],
"type": "bar"
},
{
"x": [1,2,3],
"y": [15,16,17],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [16,17,18],
"type": "bar"
},
{
"x": [1,2,3],
"y": [17,18,19],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [18,19,20],
"type": "bar"
},
{
"x": [1,2,3],
"y": [19,20,21],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [20,21,22],
"type": "bar"
},
{
"x": [1,2,3],
"y": [21,22,23],
"type": "scatter"
},
{
"x": [1,2,3],
"y": [22,23,24],
"type": "bar"
},
{
"x": [1,2,3],
"y": [23,24,25],
"type": "scatter"
}
],
"layout": {
"legend": {
"bordercolor": "#000000",
"borderwidth": 1,
"bgcolor": "#eeffee",
"title": {
"text": "<b>Legend title</b>",
"font": {
"size": 20
}
}
}
}
}