Skip to content

Commit

Permalink
add tests for legend resize and this forum [post](http://community.pl…
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Mar 30, 2016
1 parent 94bd5ff commit 3e6b949
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions test/jasmine/tests/legend_scroll_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe('The legend', function() {
return gd._fullLayout._topdefs.selectAll('#legend' + uid).size();
}

function getPlotHeight(gd) {
return gd._fullLayout.height - gd._fullLayout.margin.t - gd._fullLayout.margin.b;
}


describe('when plotted with many traces', function() {
beforeEach(function() {
gd = createGraph();
Expand All @@ -30,10 +35,9 @@ describe('The legend', function() {
afterEach(destroyGraph);

it('should not exceed plot height', function() {
var legendHeight = getBBox(legend).height,
plotHeight = gd._fullLayout.height - gd._fullLayout.margin.t - gd._fullLayout.margin.b;
var legendHeight = getBBox(legend).height;

expect(+legendHeight).toBe(plotHeight);
expect(+legendHeight).toBe(getPlotHeight(gd));
});

it('should insert a scrollbar', function() {
Expand Down Expand Up @@ -88,10 +92,29 @@ describe('The legend', function() {
done();
});
});

it('should resize when relayout\'ed with new height', function(done) {
var origLegendHeight = getBBox(legend).height;

Plotly.relayout(gd, {'height': gd._fullLayout.height/2}).then(function() {
var legendHeight = getBBox(legend).height;

//legend still exists and not duplicated
expect(countLegendGroups(gd)).toBe(1);
expect(countLegendClipPaths(gd)).toBe(1);

// clippath resized to new height less than new plot height
expect(+legendHeight).toBe(getPlotHeight(gd));
expect(+legendHeight).toBeLessThan(+origLegendHeight);

done();
});
});
});


describe('when plotted with few traces', function() {
var gd;
var gd, legend;

beforeEach(function() {
gd = createGraph();
Expand Down Expand Up @@ -122,6 +145,21 @@ describe('The legend', function() {
done();
});
});

it('should resize when traces added', function(done) {
legend = document.getElementsByClassName('legend')[0];
var origLegendHeight = getBBox(legend).height;

Plotly.addTrace(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() {
var legend = document.getElementsByClassName('legend')[0];
var legendHeight = getBBox(legend).height;
// clippath resized to show new trace
expect(+legendHeight).toBeCloseTo(+origLegendHeight+18, 0);

done();
});

});
});
});

Expand Down

0 comments on commit 3e6b949

Please sign in to comment.