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 1
1
var Plotly = require ( '@lib/index' ) ;
2
2
var createGraph = require ( '../assets/create_graph_div' ) ;
3
3
var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
4
+ var getBBox = require ( '../assets/get_bbox' ) ;
4
5
var mock = require ( '../../image/mocks/legend_scroll.json' ) ;
5
6
7
+
6
8
describe ( 'The legend' , function ( ) {
7
- var gd ,
8
- legend ;
9
+ 'use strict' ;
10
+
11
+ var gd , legend ;
9
12
10
13
describe ( 'when plotted with many traces' , function ( ) {
11
14
beforeEach ( function ( ) {
@@ -17,7 +20,7 @@ describe('The legend', function() {
17
20
afterEach ( destroyGraph ) ;
18
21
19
22
it ( 'should not exceed plot height' , function ( ) {
20
- var legendHeight = legend . getAttribute ( ' height' ) ,
23
+ var legendHeight = getBBox ( legend ) . height ,
21
24
plotHeight = gd . _fullLayout . height - gd . _fullLayout . margin . t - gd . _fullLayout . margin . b ;
22
25
23
26
expect ( + legendHeight ) . toBe ( plotHeight ) ;
@@ -53,7 +56,7 @@ describe('The legend', function() {
53
56
54
57
it ( 'should scale the scrollbar movement from top to bottom' , function ( ) {
55
58
var scrollBar = legend . getElementsByClassName ( 'scrollbar' ) [ 0 ] ,
56
- legendHeight = legend . getAttribute ( ' height' ) ;
59
+ legendHeight = getBBox ( legend ) . height ;
57
60
58
61
// The scrollbar is 20px tall and has 4px margins
59
62
You can’t perform that action at this time.
0 commit comments