@@ -62,37 +62,47 @@ describe('Test colorbar:', function() {
62
62
. then ( done ) ;
63
63
} ) ;
64
64
65
- // let heatmap stand in for all traces with trace.{showscale, colorbar}
66
- // also test impliedEdits for colorbars at the trace root
67
- it ( 'can show and hide heatmap colorbars and sizes correctly with automargin' , function ( done ) {
68
- function assertCB ( msg , present , expandedMarginR , expandedMarginT , cbTop , cbHeight ) {
69
- var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
70
- expect ( colorbars . size ( ) ) . toBe ( present ? 1 : 0 ) ;
71
-
72
- var cbbg = colorbars . selectAll ( '.colorbar .cbbg' ) ;
73
-
74
- // check that the displayed object has the right size,
75
- // not just that fullLayout._size changed
76
- var plotSizeTest = { } ;
77
- if ( expandedMarginR ) plotSizeTest . widthLessThan = 400 ;
78
- else plotSizeTest . width = 400 ;
79
-
80
- if ( expandedMarginT ) plotSizeTest . heightLessThan = 400 ;
81
- else plotSizeTest . height = 400 ;
82
-
83
- assertPlotSize ( plotSizeTest ) ;
84
-
85
- if ( present ) {
86
- if ( ! cbHeight ) cbHeight = 400 ;
87
- var bgHeight = + cbbg . attr ( 'height' ) ;
88
- if ( expandedMarginT ) expect ( bgHeight ) . toBeLessThan ( cbHeight - 2 ) ;
89
- else expect ( bgHeight ) . toBeWithin ( cbHeight , 2 ) ;
90
-
65
+ function assertCB ( msg , present , opts ) {
66
+ var expandedMarginR = opts . expandedMarginR ;
67
+ var expandedMarginT = opts . expandedMarginT ;
68
+ var cbTop = opts . top ;
69
+ var cbHeight = opts . height ;
70
+ var multiFill = opts . multiFill ;
71
+ var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
72
+ expect ( colorbars . size ( ) ) . toBe ( present ? 1 : 0 ) ;
73
+
74
+ // check that the displayed object has the right size,
75
+ // not just that fullLayout._size changed
76
+ var plotSizeTest = { } ;
77
+ if ( expandedMarginR ) plotSizeTest . widthLessThan = 400 ;
78
+ else plotSizeTest . width = 400 ;
79
+
80
+ if ( expandedMarginT ) plotSizeTest . heightLessThan = 400 ;
81
+ else plotSizeTest . height = 400 ;
82
+
83
+ assertPlotSize ( plotSizeTest ) ;
84
+
85
+ if ( present ) {
86
+ var cbbg = colorbars . selectAll ( '.cbbg' ) ;
87
+ var cbfills = colorbars . selectAll ( '.cbfill' ) ;
88
+
89
+ expect ( cbfills . size ( ) ) . negateIf ( multiFill ) . toBe ( 1 ) ;
90
+
91
+ if ( ! cbHeight ) cbHeight = 400 ;
92
+ var bgHeight = + cbbg . attr ( 'height' ) ;
93
+ if ( expandedMarginT ) expect ( bgHeight ) . toBeLessThan ( cbHeight - 2 ) ;
94
+ else expect ( bgHeight ) . toBeWithin ( cbHeight , 2 ) ;
95
+
96
+ if ( cbTop !== undefined ) {
91
97
var topShift = cbbg . node ( ) . getBoundingClientRect ( ) . top - gd . getBoundingClientRect ( ) . top ;
92
98
expect ( topShift ) . toBeWithin ( cbTop , 2 ) ;
93
99
}
94
100
}
101
+ }
95
102
103
+ // let heatmap stand in for all traces with trace.{showscale, colorbar}
104
+ // also test impliedEdits for colorbars at the trace root
105
+ it ( 'can show and hide heatmap colorbars and sizes correctly with automargin' , function ( done ) {
96
106
var thickPx , lenFrac ;
97
107
98
108
Plotly . newPlot ( gd , [ {
@@ -104,22 +114,22 @@ describe('Test colorbar:', function() {
104
114
margin : { l : 50 , r : 50 , t : 50 , b : 50 }
105
115
} )
106
116
. then ( function ( ) {
107
- assertCB ( 'initial' , true , true , false , 50 ) ;
117
+ assertCB ( 'initial' , true , { expandedMarginR : true , expandedMarginT : false , top : 50 } ) ;
108
118
109
119
return Plotly . restyle ( gd , { showscale : false } ) ;
110
120
} )
111
121
. then ( function ( ) {
112
- assertCB ( 'hidden' , false , false , false ) ;
122
+ assertCB ( 'hidden' , false , { expandedMarginR : false , expandedMarginT : false } ) ;
113
123
114
124
return Plotly . restyle ( gd , { showscale : true , 'colorbar.y' : 0.8 } ) ;
115
125
} )
116
126
. then ( function ( ) {
117
- assertCB ( 'up high' , true , true , true , 12 ) ;
127
+ assertCB ( 'up high' , true , { expandedMarginR : true , expandedMarginT : true , top : 12 } ) ;
118
128
119
129
return Plotly . restyle ( gd , { 'colorbar.y' : 0.7 } ) ;
120
130
} )
121
131
. then ( function ( ) {
122
- assertCB ( 'a little lower' , true , true , true , 12 ) ;
132
+ assertCB ( 'a little lower' , true , { expandedMarginR : true , expandedMarginT : true , top : 12 } ) ;
123
133
124
134
return Plotly . restyle ( gd , {
125
135
'colorbar.x' : 0.7 ,
@@ -129,7 +139,7 @@ describe('Test colorbar:', function() {
129
139
} ) ;
130
140
} )
131
141
. then ( function ( ) {
132
- assertCB ( 'mid-plot' , true , false , false , 150 , 200 ) ;
142
+ assertCB ( 'mid-plot' , true , { expandedMarginR : false , expandedMarginT : false , top : 150 , height : 200 } ) ;
133
143
134
144
thickPx = gd . _fullData [ 0 ] . colorbar . thickness ;
135
145
lenFrac = gd . _fullData [ 0 ] . colorbar . len ;
@@ -146,21 +156,14 @@ describe('Test colorbar:', function() {
146
156
expect ( gd . _fullData [ 0 ] . colorbar . len )
147
157
. toBeCloseTo ( lenFrac * 400 , 3 ) ;
148
158
149
- assertCB ( 'changed size modes' , true , true , false , 150 , 200 ) ;
159
+ assertCB ( 'changed size modes' , true , { expandedMarginR : true , expandedMarginT : false , top : 150 , height : 200 } ) ;
150
160
} )
151
161
. catch ( failTest )
152
162
. then ( done ) ;
153
163
} ) ;
154
164
155
165
// scatter has trace.marker.{showscale, colorbar}
156
166
it ( 'can show and hide scatter colorbars' , function ( done ) {
157
- function assertCB ( present , expandedMargin ) {
158
- var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
159
- expect ( colorbars . size ( ) ) . toBe ( present ? 1 : 0 ) ;
160
-
161
- assertPlotSize ( expandedMargin ? { widthLessThan : 400 } : { width : 400 } ) ;
162
- }
163
-
164
167
Plotly . newPlot ( gd , [ {
165
168
y : [ 1 , 2 , 3 ] ,
166
169
marker : { color : [ 1 , 2 , 3 ] , showscale : true }
@@ -170,36 +173,29 @@ describe('Test colorbar:', function() {
170
173
margin : { l : 50 , r : 50 , t : 50 , b : 50 }
171
174
} )
172
175
. then ( function ( ) {
173
- assertCB ( true , true ) ;
176
+ assertCB ( 'initial' , true , { expandedMarginR : true } ) ;
174
177
175
178
return Plotly . restyle ( gd , { 'marker.showscale' : false } ) ;
176
179
} )
177
180
. then ( function ( ) {
178
- assertCB ( false , false ) ;
181
+ assertCB ( 'hidden' , false , { expandedMarginR : false } ) ;
179
182
180
183
return Plotly . restyle ( gd , { 'marker.showscale' : true , 'marker.colorbar.x' : 0.7 } ) ;
181
184
} )
182
185
. then ( function ( ) {
183
- assertCB ( true , false ) ;
186
+ assertCB ( 'mid-plot' , true , { expandedMarginR : false } ) ;
184
187
185
188
return Plotly . restyle ( gd , { 'marker.colorbar.x' : 1.1 } ) ;
186
189
} )
187
190
. then ( function ( ) {
188
- assertCB ( true , true ) ;
191
+ assertCB ( 'far right' , true , { expandedMarginR : true } ) ;
189
192
} )
190
193
. catch ( failTest )
191
194
. then ( done ) ;
192
195
} ) ;
193
196
194
197
// histogram colorbars could not be edited before
195
- it ( 'can show and hide scatter colorbars' , function ( done ) {
196
- function assertCB ( present , expandedMargin ) {
197
- var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
198
- expect ( colorbars . size ( ) ) . toBe ( present ? 1 : 0 ) ;
199
-
200
- assertPlotSize ( expandedMargin ? { widthLessThan : 400 } : { width : 400 } ) ;
201
- }
202
-
198
+ it ( 'can show and hide histogram colorbars' , function ( done ) {
203
199
Plotly . newPlot ( gd , [ {
204
200
type : 'histogram' ,
205
201
x : [ 0 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 4 ] ,
@@ -211,22 +207,53 @@ describe('Test colorbar:', function() {
211
207
margin : { l : 50 , r : 50 , t : 50 , b : 50 }
212
208
} )
213
209
. then ( function ( ) {
214
- assertCB ( true , true ) ;
210
+ assertCB ( 'initial' , true , { expandedMarginR : true } ) ;
215
211
216
212
return Plotly . restyle ( gd , { 'marker.showscale' : false } ) ;
217
213
} )
218
214
. then ( function ( ) {
219
- assertCB ( false , false ) ;
215
+ assertCB ( 'hidden' , false , { expandedMarginR : false } ) ;
220
216
221
217
return Plotly . restyle ( gd , { 'marker.showscale' : true , 'marker.colorbar.x' : 0.7 } ) ;
222
218
} )
223
219
. then ( function ( ) {
224
- assertCB ( true , false ) ;
220
+ assertCB ( 'mid-plot' , true , { expandedMarginR : false } ) ;
225
221
226
222
return Plotly . restyle ( gd , { 'marker.colorbar.x' : 1.1 } ) ;
227
223
} )
228
224
. then ( function ( ) {
229
- assertCB ( true , true ) ;
225
+ assertCB ( 'far right' , true , { expandedMarginR : true } ) ;
226
+ } )
227
+ . catch ( failTest )
228
+ . then ( done ) ;
229
+ } ) ;
230
+
231
+ it ( 'creates multiple fills for contour colorbars' , function ( done ) {
232
+ Plotly . newPlot ( gd , [ {
233
+ type : 'contour' ,
234
+ z : [ [ 1 , 10 ] , [ 100 , 1000 ] ]
235
+ } ] , {
236
+ height : 500 ,
237
+ width : 500 ,
238
+ margin : { l : 50 , r : 50 , t : 50 , b : 50 }
239
+ } )
240
+ . then ( function ( ) {
241
+ assertCB ( 'initial' , true , { expandedMarginR : true , expandedMarginT : false , top : 50 , multiFill : true } ) ;
242
+
243
+ return Plotly . restyle ( gd , { showscale : false } ) ;
244
+ } )
245
+ . then ( function ( ) {
246
+ assertCB ( 'hidden' , false , { expandedMarginR : false , expandedMarginT : false } ) ;
247
+
248
+ return Plotly . restyle ( gd , { showscale : true , 'colorbar.y' : 0.8 } ) ;
249
+ } )
250
+ . then ( function ( ) {
251
+ assertCB ( 'up high' , true , { expandedMarginR : true , expandedMarginT : true , top : 12 , multiFill : true } ) ;
252
+
253
+ return Plotly . restyle ( gd , { 'contours.coloring' : 'heatmap' } ) ;
254
+ } )
255
+ . then ( function ( ) {
256
+ assertCB ( 'up high' , true , { expandedMarginR : true , expandedMarginT : true , top : 12 , multiFill : false } ) ;
230
257
} )
231
258
. catch ( failTest )
232
259
. then ( done ) ;
@@ -235,7 +262,7 @@ describe('Test colorbar:', function() {
235
262
// parcoords has trace.marker.{showscale, colorbar}
236
263
// also tests impliedEdits for colorbars in containers
237
264
it ( 'can show and hide parcoords colorbars' , function ( done ) {
238
- function assertCB ( present , expandedMargin ) {
265
+ function assertParcoordsCB ( present , expandedMargin ) {
239
266
var colorbars = d3 . select ( gd ) . selectAll ( '.colorbar' ) ;
240
267
expect ( colorbars . size ( ) ) . toBe ( present ? 1 : 0 ) ;
241
268
@@ -244,6 +271,9 @@ describe('Test colorbar:', function() {
244
271
var transform = yAxes [ 0 ] [ 1 ] . getAttribute ( 'transform' ) ;
245
272
if ( expandedMargin ) expect ( transform ) . not . toBe ( 'translate(400, 0)' ) ;
246
273
else expect ( transform ) . toBe ( 'translate(400, 0)' ) ;
274
+
275
+ var cbfills = colorbars . selectAll ( '.cbfill' ) ;
276
+ expect ( cbfills . size ( ) ) . toBe ( present ? 1 : 0 ) ;
247
277
}
248
278
249
279
var thickPx , lenFrac ;
@@ -258,20 +288,20 @@ describe('Test colorbar:', function() {
258
288
margin : { l : 50 , r : 50 , t : 50 , b : 50 }
259
289
} )
260
290
. then ( function ( ) {
261
- assertCB ( true , true ) ;
291
+ assertParcoordsCB ( true , true ) ;
262
292
263
293
return Plotly . restyle ( gd , { 'line.showscale' : false } ) ;
264
294
} )
265
295
. then ( function ( ) {
266
- assertCB ( false , false ) ;
296
+ assertParcoordsCB ( false , false ) ;
267
297
268
298
return Plotly . restyle ( gd , {
269
299
'line.showscale' : true ,
270
300
'line.colorbar.x' : 0.7
271
301
} ) ;
272
302
} )
273
303
. then ( function ( ) {
274
- assertCB ( true , false ) ;
304
+ assertParcoordsCB ( true , false ) ;
275
305
276
306
thickPx = gd . _fullData [ 0 ] . line . colorbar . thickness ;
277
307
lenFrac = gd . _fullData [ 0 ] . line . colorbar . len ;
@@ -288,7 +318,7 @@ describe('Test colorbar:', function() {
288
318
expect ( gd . _fullData [ 0 ] . line . colorbar . len )
289
319
. toBeCloseTo ( lenFrac * 400 , 3 ) ;
290
320
291
- assertCB ( true , true ) ;
321
+ assertParcoordsCB ( true , true ) ;
292
322
} )
293
323
. catch ( failTest )
294
324
. then ( done ) ;
0 commit comments