1
- describe ( 'dc.boxPlot' , function ( ) {
1
+ /* global appendChartID, loadBoxPlotFixture */
2
+ describe ( 'dc.boxPlot' , function ( ) {
2
3
var id , chart ;
3
4
var data , dimension , group ;
4
5
@@ -33,127 +34,127 @@ describe('dc.boxPlot', function() {
33
34
chart . render ( ) ;
34
35
} ) ;
35
36
36
- it ( 'should create a non-empty SVG node' , function ( ) {
37
+ it ( 'should create a non-empty SVG node' , function ( ) {
37
38
expect ( chart . svg ( ) . empty ( ) ) . toBeFalsy ( ) ;
38
39
} ) ;
39
40
40
- it ( 'should create one outlier circle per outlier' , function ( ) {
41
+ it ( 'should create one outlier circle per outlier' , function ( ) {
41
42
expect ( chart . selectAll ( 'circle.outlier' ) . size ( ) ) . toBe ( 2 ) ;
42
43
} ) ;
43
44
44
- it ( 'should create an offset box for each dimension in the group' , function ( ) {
45
+ it ( 'should create an offset box for each dimension in the group' , function ( ) {
45
46
expect ( box ( 0 ) . attr ( 'transform' ) ) . toMatchTranslate ( 50 , 0 ) ;
46
47
expect ( box ( 1 ) . attr ( 'transform' ) ) . toMatchTranslate ( 150 , 0 ) ;
47
48
} ) ;
48
49
49
- it ( 'should correctly place median line' , function ( ) {
50
+ it ( 'should correctly place median line' , function ( ) {
50
51
expect ( box ( 1 ) . selectAll ( 'line.median' ) . attr ( 'y1' ) ) . toBe ( '100' ) ;
51
52
expect ( box ( 1 ) . selectAll ( 'line.median' ) . attr ( 'y2' ) ) . toBe ( '100' ) ;
52
53
} ) ;
53
54
54
- it ( 'should set the median value correctly' , function ( ) {
55
+ it ( 'should set the median value correctly' , function ( ) {
55
56
expect ( box ( 1 ) . boxText ( 1 ) . text ( ) ) . toBe ( '44' ) ;
56
57
} ) ;
57
58
58
- it ( 'should place the left box line at the x origin' , function ( ) {
59
+ it ( 'should place the left box line at the x origin' , function ( ) {
59
60
expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( 'x' ) ) . toBe ( '0' ) ;
60
61
} ) ;
61
62
62
63
describe ( 'the width of the box plot' , function ( ) {
63
- it ( 'should default to being based on the rangeBand' , function ( ) {
64
+ it ( 'should default to being based on the rangeBand' , function ( ) {
64
65
expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( 'width' ) ) . toBe ( '100' ) ;
65
66
} ) ;
66
67
67
- it ( 'should be settable to a number' , function ( ) {
68
+ it ( 'should be settable to a number' , function ( ) {
68
69
chart . boxWidth ( 150 ) . render ( ) ;
69
70
expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( 'width' ) ) . toBe ( '150' ) ;
70
71
} ) ;
71
72
72
- it ( 'should be settable to a function' , function ( ) {
73
- chart . boxWidth ( function ( innerChartWidth , xUnits ) {
73
+ it ( 'should be settable to a function' , function ( ) {
74
+ chart . boxWidth ( function ( innerChartWidth , xUnits ) {
74
75
return innerChartWidth / ( xUnits + 2 ) ;
75
76
} ) . render ( ) ;
76
77
expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( 'width' ) ) . toBe ( '75' ) ;
77
78
} ) ;
78
79
} ) ;
79
80
80
81
describe ( 'the tickFormat of the box plot' , function ( ) {
81
- it ( 'should default to whole number' , function ( ) {
82
+ it ( 'should default to whole number' , function ( ) {
82
83
expect ( box ( 1 ) . boxText ( 1 ) . text ( ) ) . toBe ( '44' ) ;
83
84
expect ( box ( 1 ) . whiskerText ( 0 ) . text ( ) ) . toBe ( '22' ) ;
84
85
expect ( box ( 1 ) . whiskerText ( 1 ) . text ( ) ) . toBe ( '66' ) ;
85
86
} ) ;
86
87
87
- it ( 'should be settable to a d3.format' , function ( ) {
88
- chart . tickFormat ( d3 . format ( " .2f" ) ) . render ( ) ;
88
+ it ( 'should be settable to a d3.format' , function ( ) {
89
+ chart . tickFormat ( d3 . format ( ' .2f' ) ) . render ( ) ;
89
90
expect ( box ( 1 ) . boxText ( 1 ) . text ( ) ) . toBe ( '44.00' ) ;
90
91
expect ( box ( 1 ) . whiskerText ( 0 ) . text ( ) ) . toBe ( '22.00' ) ;
91
92
expect ( box ( 1 ) . whiskerText ( 1 ) . text ( ) ) . toBe ( '66.00' ) ;
92
93
} ) ;
93
94
} ) ;
94
95
95
- it ( 'should place interquartile range lines after the first and before the fourth quartile' , function ( ) {
96
+ it ( 'should place interquartile range lines after the first and before the fourth quartile' , function ( ) {
96
97
expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( 'y' ) ) . toBe ( '94.5' ) ;
97
98
expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( 'height' ) ) . toBe ( '16.5' ) ;
98
99
} ) ;
99
100
100
- it ( 'should label the interquartile range lines using their calculated values' , function ( ) {
101
+ it ( 'should label the interquartile range lines using their calculated values' , function ( ) {
101
102
expect ( box ( 1 ) . boxText ( 0 ) . text ( ) ) . toBe ( '33' ) ;
102
103
expect ( box ( 1 ) . boxText ( 2 ) . text ( ) ) . toBe ( '50' ) ;
103
104
} ) ;
104
105
105
- it ( 'should place the whiskers at 1.5x the interquartile range' , function ( ) {
106
+ it ( 'should place the whiskers at 1.5x the interquartile range' , function ( ) {
106
107
expect ( box ( 1 ) . whiskerLine ( 0 ) . attr ( 'y1' ) ) . toBe ( '122' ) ;
107
108
expect ( box ( 1 ) . whiskerLine ( 0 ) . attr ( 'y2' ) ) . toBe ( '122' ) ;
108
109
expect ( box ( 1 ) . whiskerLine ( 1 ) . attr ( 'y1' ) ) . toBeWithinDelta ( 78 ) ;
109
110
expect ( box ( 1 ) . whiskerLine ( 1 ) . attr ( 'y2' ) ) . toBeWithinDelta ( 78 ) ;
110
111
} ) ;
111
112
112
- it ( 'should label the whiskers using their calculated values' , function ( ) {
113
+ it ( 'should label the whiskers using their calculated values' , function ( ) {
113
114
expect ( box ( 1 ) . whiskerText ( 0 ) . text ( ) ) . toBe ( '22' ) ;
114
115
expect ( box ( 1 ) . whiskerText ( 1 ) . text ( ) ) . toBe ( '66' ) ;
115
116
} ) ;
116
117
117
- it ( 'should assign a fill color to the boxes' , function ( ) {
118
- expect ( box ( 0 ) . select ( 'rect.box' ) . attr ( " fill" ) ) . toBe ( " #01" ) ;
119
- expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( " fill" ) ) . toBe ( " #02" ) ;
118
+ it ( 'should assign a fill color to the boxes' , function ( ) {
119
+ expect ( box ( 0 ) . select ( 'rect.box' ) . attr ( ' fill' ) ) . toBe ( ' #01' ) ;
120
+ expect ( box ( 1 ) . select ( 'rect.box' ) . attr ( ' fill' ) ) . toBe ( ' #02' ) ;
120
121
} ) ;
121
122
122
- describe ( 'when a box has no data' , function ( ) {
123
+ describe ( 'when a box has no data' , function ( ) {
123
124
var firstBox ;
124
125
125
- beforeEach ( function ( ) {
126
+ beforeEach ( function ( ) {
126
127
firstBox = chart . select ( 'g.box' ) . node ( ) ;
127
128
var otherDimension = data . dimension ( function ( d ) { return d . countrycode ; } ) ;
128
- otherDimension . filter ( "US" ) ;
129
+ otherDimension . filter ( 'US' ) ;
129
130
chart . redraw ( ) ;
130
131
} ) ;
131
132
132
- it ( 'should not attempt to render that box' , function ( ) {
133
+ it ( 'should not attempt to render that box' , function ( ) {
133
134
expect ( chart . selectAll ( 'g.box' ) . size ( ) ) . toBe ( 1 ) ;
134
135
} ) ;
135
136
136
- it ( 'should not animate the removed box into another box' , function ( ) {
137
+ it ( 'should not animate the removed box into another box' , function ( ) {
137
138
expect ( chart . select ( 'g.box' ) . node ( ) ) . not . toBe ( firstBox ) ;
138
139
} ) ;
139
140
140
- describe ( " with elasticX enabled" , function ( ) {
141
- beforeEach ( function ( ) {
141
+ describe ( ' with elasticX enabled' , function ( ) {
142
+ beforeEach ( function ( ) {
142
143
chart . elasticX ( true ) . render ( ) ;
143
144
} ) ;
144
145
145
- it ( 'should not represent the box in the chart domain' , function ( ) {
146
- expect ( chart . selectAll ( " .axis.x .tick" ) . size ( ) ) . toBe ( 1 ) ;
146
+ it ( 'should not represent the box in the chart domain' , function ( ) {
147
+ expect ( chart . selectAll ( ' .axis.x .tick' ) . size ( ) ) . toBe ( 1 ) ;
147
148
} ) ;
148
149
} ) ;
149
150
150
- describe ( " when elasticX is disabled" , function ( ) {
151
- beforeEach ( function ( ) {
151
+ describe ( ' when elasticX is disabled' , function ( ) {
152
+ beforeEach ( function ( ) {
152
153
chart . elasticX ( false ) . render ( ) ;
153
154
} ) ;
154
155
155
- it ( 'should represent the box in the chart domain' , function ( ) {
156
- expect ( chart . selectAll ( " .axis.x .tick" ) . size ( ) ) . toBe ( 2 ) ;
156
+ it ( 'should represent the box in the chart domain' , function ( ) {
157
+ expect ( chart . selectAll ( ' .axis.x .tick' ) . size ( ) ) . toBe ( 2 ) ;
157
158
} ) ;
158
159
} ) ;
159
160
} ) ;
@@ -166,18 +167,18 @@ describe('dc.boxPlot', function() {
166
167
167
168
describe ( 'filtering the box plot' , function ( ) {
168
169
beforeEach ( function ( ) {
169
- chart . filter ( "CA" ) . redraw ( ) ;
170
+ chart . filter ( 'CA' ) . redraw ( ) ;
170
171
} ) ;
171
172
172
- it ( 'should select the boxes corresponding to the filtered value' , function ( ) {
173
+ it ( 'should select the boxes corresponding to the filtered value' , function ( ) {
173
174
box ( 0 ) . each ( function ( d ) {
174
- expect ( d3 . select ( this ) . classed ( " selected" ) ) . toBeTruthy ( ) ;
175
+ expect ( d3 . select ( this ) . classed ( ' selected' ) ) . toBeTruthy ( ) ;
175
176
} ) ;
176
177
} ) ;
177
178
178
- it ( 'should deselect the boxes not corresponding to the filtered value' , function ( ) {
179
+ it ( 'should deselect the boxes not corresponding to the filtered value' , function ( ) {
179
180
box ( 1 ) . each ( function ( d ) {
180
- expect ( d3 . select ( this ) . classed ( " deselected" ) ) . toBeTruthy ( ) ;
181
+ expect ( d3 . select ( this ) . classed ( ' deselected' ) ) . toBeTruthy ( ) ;
181
182
} ) ;
182
183
} ) ;
183
184
} ) ;
@@ -187,21 +188,21 @@ describe('dc.boxPlot', function() {
187
188
box ( 0 ) . on ( 'click' ) . call ( chart , box ( 0 ) . datum ( ) ) ;
188
189
} ) ;
189
190
190
- it ( 'should apply a filter to the chart' , function ( ) {
191
- expect ( chart . hasFilter ( "CA" ) ) . toBeTruthy ( ) ;
191
+ it ( 'should apply a filter to the chart' , function ( ) {
192
+ expect ( chart . hasFilter ( 'CA' ) ) . toBeTruthy ( ) ;
192
193
} ) ;
193
194
} ) ;
194
195
} ) ;
195
196
196
- function box ( n ) {
197
+ function box ( n ) {
197
198
var nthBox = d3 . select ( chart . selectAll ( 'g.box' ) [ 0 ] [ n ] ) ;
198
- nthBox . boxText = function ( n ) {
199
+ nthBox . boxText = function ( n ) {
199
200
return d3 . select ( this . selectAll ( 'text.box' ) [ 0 ] [ n ] ) ;
200
201
} ;
201
- nthBox . whiskerLine = function ( n ) {
202
+ nthBox . whiskerLine = function ( n ) {
202
203
return d3 . select ( this . selectAll ( 'line.whisker' ) [ 0 ] [ n ] ) ;
203
204
} ;
204
- nthBox . whiskerText = function ( n ) {
205
+ nthBox . whiskerText = function ( n ) {
205
206
return d3 . select ( this . selectAll ( 'text.whisker' ) [ 0 ] [ n ] ) ;
206
207
} ;
207
208
return nthBox ;
0 commit comments