-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix/legend resize #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/legend resize #356
Changes from all commits
52f1a3c
197f7fa
94bd5ff
3e6b949
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -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() { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check against the computed height using It helps catch potential bugs earlier than just relative size comparison. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, will be happy to; sorry for the flurry of commits; my local set up broke this morning. |
||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('when plotted with few traces', function() { | ||
var gd; | ||
var gd, legend; | ||
|
||
beforeEach(function() { | ||
gd = createGraph(); | ||
|
@@ -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(); | ||
}); | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐄 spacing between
scrollheight
andopts.height
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thanks. should have thought about using
d3
wheel also. great change!