File tree Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Expand file tree Collapse file tree 2 files changed +42
-4
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var d3 = require ( 'd3' ) ;
4+
5+
6+ // In-house implementation of SVG getBBox that takes clip paths into account
7+ module . exports = function getBBox ( element ) {
8+ var elementBBox = element . getBBox ( ) ;
9+
10+ var s = d3 . select ( element ) ;
11+ var clipPathAttr = s . attr ( 'clip-path' ) ;
12+
13+ if ( ! clipPathAttr ) return elementBBox ;
14+
15+ // only supports 'url(#<id>)' at the moment
16+ var clipPathId = clipPathAttr . substring ( 5 , clipPathAttr . length - 1 ) ;
17+ var clipPath = d3 . select ( '#' + clipPathId ) . node ( ) ;
18+
19+ return minBBox ( elementBBox , clipPath . getBBox ( ) ) ;
20+ } ;
21+
22+ function minBBox ( bbox1 , bbox2 ) {
23+ var keys = [ 'x' , 'y' , 'width' , 'height' ] ;
24+ var out = { } ;
25+
26+ function min ( attr ) {
27+ return Math . min ( bbox1 [ attr ] , bbox2 [ attr ] ) ;
28+ }
29+
30+ keys . forEach ( function ( key ) {
31+ out [ key ] = min ( key ) ;
32+ } ) ;
33+
34+ return out ;
35+ }
Original file line number Diff line number Diff line change 11var Plotly = require ( '@lib/index' ) ;
22var createGraph = require ( '../assets/create_graph_div' ) ;
33var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
4+ var getBBox = require ( '../assets/get_bbox' ) ;
45var mock = require ( '../../image/mocks/legend_scroll.json' ) ;
56
7+
68describe ( 'The legend' , function ( ) {
7- var gd ,
8- legend ;
9+ 'use strict' ;
10+
11+ var gd , legend ;
912
1013 describe ( 'when plotted with many traces' , function ( ) {
1114 beforeEach ( function ( ) {
@@ -17,7 +20,7 @@ describe('The legend', function() {
1720 afterEach ( destroyGraph ) ;
1821
1922 it ( 'should not exceed plot height' , function ( ) {
20- var legendHeight = legend . getAttribute ( ' height' ) ,
23+ var legendHeight = getBBox ( legend ) . height ,
2124 plotHeight = gd . _fullLayout . height - gd . _fullLayout . margin . t - gd . _fullLayout . margin . b ;
2225
2326 expect ( + legendHeight ) . toBe ( plotHeight ) ;
@@ -53,7 +56,7 @@ describe('The legend', function() {
5356
5457 it ( 'should scale the scrollbar movement from top to bottom' , function ( ) {
5558 var scrollBar = legend . getElementsByClassName ( 'scrollbar' ) [ 0 ] ,
56- legendHeight = legend . getAttribute ( ' height' ) ;
59+ legendHeight = getBBox ( legend ) . height ;
5760
5861 // The scrollbar is 20px tall and has 4px margins
5962
You can’t perform that action at this time.
0 commit comments