|
1 | 1 | var Plotly = require('@lib/index');
|
2 | 2 | var Lib = require('@src/lib');
|
| 3 | +var constants = require('@src/components/legend/constants'); |
3 | 4 |
|
4 | 5 | var createGraph = require('../assets/create_graph_div');
|
5 | 6 | var destroyGraph = require('../assets/destroy_graph_div');
|
@@ -55,14 +56,23 @@ describe('The legend', function() {
|
55 | 56 | });
|
56 | 57 |
|
57 | 58 | it('should scroll when there\'s a wheel event', function() {
|
58 |
| - var scrollBox = legend.getElementsByClassName('scrollbox')[0]; |
59 |
| - |
60 |
| - legend.dispatchEvent(scrollTo(100)); |
61 |
| - |
62 |
| - // Compare against -5 because of a scroll factor of 20 |
63 |
| - // ( 100 / 20 === 5 ) |
64 |
| - expect(scrollBox.getAttribute('transform')).toBe('translate(0, -5)'); |
65 |
| - expect(scrollBox.getAttribute('data-scroll')).toBe('-5'); |
| 59 | + var scrollBox = legend.getElementsByClassName('scrollbox')[0], |
| 60 | + legendHeight = getBBox(legend).height, |
| 61 | + scrollBoxYMax = gd._fullLayout.legend.height - legendHeight, |
| 62 | + scrollBarYMax = legendHeight - |
| 63 | + constants.scrollBarHeight - |
| 64 | + 2 * constants.scrollBarMargin, |
| 65 | + initialDataScroll = scrollBox.getAttribute('data-scroll'), |
| 66 | + wheelDeltaY = 100, |
| 67 | + finalDataScroll = '' + Lib.constrain(initialDataScroll - |
| 68 | + wheelDeltaY / scrollBarYMax * scrollBoxYMax, |
| 69 | + -scrollBoxYMax, 0); |
| 70 | + |
| 71 | + legend.dispatchEvent(scrollTo(wheelDeltaY)); |
| 72 | + |
| 73 | + expect(scrollBox.getAttribute('data-scroll')).toBe(finalDataScroll); |
| 74 | + expect(scrollBox.getAttribute('transform')).toBe( |
| 75 | + 'translate(0, ' + finalDataScroll + ')'); |
66 | 76 | });
|
67 | 77 |
|
68 | 78 | it('should constrain scrolling to the contents', function() {
|
|
0 commit comments