1
- var Plotly = require ( '@src/plotly' ) ;
1
+ var PlotlyInternal = require ( '@src/plotly' ) ;
2
+
3
+ var Plots = require ( '@src/plots/plots' ) ;
4
+ var Lib = require ( '@src/lib' ) ;
5
+ var Color = require ( '@src/components/color' ) ;
6
+
7
+ var handleTickValueDefaults = require ( '@src/plots/cartesian/tick_value_defaults' ) ;
8
+ var Axes = PlotlyInternal . Axes ;
2
9
3
10
4
11
describe ( 'Test axes' , function ( ) {
@@ -28,15 +35,15 @@ describe('Test axes', function() {
28
35
}
29
36
}
30
37
} ;
31
- var expectedYaxis = Plotly . Lib . extendDeep ( { } , gd . layout . xaxis ) ,
38
+ var expectedYaxis = Lib . extendDeep ( { } , gd . layout . xaxis ) ,
32
39
expectedXaxis = {
33
40
title : 'Click to enter X axis title' ,
34
41
type : 'date'
35
42
} ;
36
43
37
- Plotly . Plots . supplyDefaults ( gd ) ;
44
+ Plots . supplyDefaults ( gd ) ;
38
45
39
- Plotly . Axes . swap ( gd , [ 0 ] ) ;
46
+ Axes . swap ( gd , [ 0 ] ) ;
40
47
41
48
expect ( gd . layout . xaxis ) . toEqual ( expectedXaxis ) ;
42
49
expect ( gd . layout . yaxis ) . toEqual ( expectedYaxis ) ;
@@ -61,13 +68,13 @@ describe('Test axes', function() {
61
68
}
62
69
}
63
70
} ;
64
- var expectedLayoutAfter = Plotly . Lib . extendDeep ( { } , gd . layout ) ;
71
+ var expectedLayoutAfter = Lib . extendDeep ( { } , gd . layout ) ;
65
72
expectedLayoutAfter . xaxis . type = 'linear' ;
66
73
expectedLayoutAfter . yaxis . type = 'linear' ;
67
74
68
- Plotly . Plots . supplyDefaults ( gd ) ;
75
+ Plots . supplyDefaults ( gd ) ;
69
76
70
- Plotly . Axes . swap ( gd , [ 0 ] ) ;
77
+ Axes . swap ( gd , [ 0 ] ) ;
71
78
72
79
expect ( gd . layout . xaxis ) . toEqual ( expectedLayoutAfter . xaxis ) ;
73
80
expect ( gd . layout . yaxis ) . toEqual ( expectedLayoutAfter . yaxis ) ;
@@ -145,9 +152,9 @@ describe('Test axes', function() {
145
152
{ x : 5 , y : 0.5 , xref : 'x' , yref : 'paper' }
146
153
] ;
147
154
148
- Plotly . Plots . supplyDefaults ( gd ) ;
155
+ Plots . supplyDefaults ( gd ) ;
149
156
150
- Plotly . Axes . swap ( gd , [ 0 , 1 ] ) ;
157
+ Axes . swap ( gd , [ 0 , 1 ] ) ;
151
158
152
159
expect ( gd . layout . xaxis ) . toEqual ( expectedXaxis ) ;
153
160
expect ( gd . layout . xaxis2 ) . toEqual ( expectedXaxis2 ) ;
@@ -161,7 +168,7 @@ describe('Test axes', function() {
161
168
layoutOut = { } ,
162
169
fullData = [ ] ;
163
170
164
- var supplyLayoutDefaults = Plotly . Axes . supplyLayoutDefaults ;
171
+ var supplyLayoutDefaults = Axes . supplyLayoutDefaults ;
165
172
166
173
it ( 'should set undefined linewidth/linecolor if linewidth, linecolor or showline is not supplied' , function ( ) {
167
174
layoutIn = {
@@ -181,7 +188,7 @@ describe('Test axes', function() {
181
188
} ;
182
189
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
183
190
expect ( layoutOut . xaxis . linewidth ) . toBe ( 1 ) ;
184
- expect ( layoutOut . xaxis . linecolor ) . toBe ( Plotly . Color . defaultLine ) ;
191
+ expect ( layoutOut . xaxis . linecolor ) . toBe ( Color . defaultLine ) ;
185
192
} ) ;
186
193
187
194
it ( 'should set linewidth to default if linecolor is supplied and valid' , function ( ) {
@@ -199,7 +206,7 @@ describe('Test axes', function() {
199
206
} ;
200
207
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
201
208
expect ( layoutOut . yaxis . linewidth ) . toBe ( 2 ) ;
202
- expect ( layoutOut . yaxis . linecolor ) . toBe ( Plotly . Color . defaultLine ) ;
209
+ expect ( layoutOut . yaxis . linecolor ) . toBe ( Color . defaultLine ) ;
203
210
} ) ;
204
211
205
212
it ( 'should set default gridwidth and gridcolor' , function ( ) {
@@ -209,9 +216,9 @@ describe('Test axes', function() {
209
216
} ;
210
217
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
211
218
expect ( layoutOut . xaxis . gridwidth ) . toBe ( 1 ) ;
212
- expect ( layoutOut . xaxis . gridcolor ) . toBe ( Plotly . Color . lightLine ) ;
219
+ expect ( layoutOut . xaxis . gridcolor ) . toBe ( Color . lightLine ) ;
213
220
expect ( layoutOut . yaxis . gridwidth ) . toBe ( 1 ) ;
214
- expect ( layoutOut . yaxis . gridcolor ) . toBe ( Plotly . Color . lightLine ) ;
221
+ expect ( layoutOut . yaxis . gridcolor ) . toBe ( Color . lightLine ) ;
215
222
} ) ;
216
223
217
224
it ( 'should set gridcolor/gridwidth to undefined if showgrid is false' , function ( ) {
@@ -230,9 +237,9 @@ describe('Test axes', function() {
230
237
} ;
231
238
supplyLayoutDefaults ( layoutIn , layoutOut , fullData ) ;
232
239
expect ( layoutOut . xaxis . zerolinewidth ) . toBe ( 1 ) ;
233
- expect ( layoutOut . xaxis . zerolinecolor ) . toBe ( Plotly . Color . defaultLine ) ;
240
+ expect ( layoutOut . xaxis . zerolinecolor ) . toBe ( Color . defaultLine ) ;
234
241
expect ( layoutOut . yaxis . zerolinewidth ) . toBe ( 1 ) ;
235
- expect ( layoutOut . yaxis . zerolinecolor ) . toBe ( Plotly . Color . defaultLine ) ;
242
+ expect ( layoutOut . yaxis . zerolinecolor ) . toBe ( Color . defaultLine ) ;
236
243
} ) ;
237
244
238
245
it ( 'should set zerolinecolor/zerolinewidth to undefined if zeroline is false' , function ( ) {
@@ -246,103 +253,101 @@ describe('Test axes', function() {
246
253
} ) ;
247
254
248
255
describe ( 'handleTickValueDefaults' , function ( ) {
249
- function handleTickValueDefaults ( axIn , axOut , axType ) {
256
+ function mockSupplyDefaults ( axIn , axOut , axType ) {
250
257
function coerce ( attr , dflt ) {
251
- return Plotly . Lib . coerce ( axIn , axOut ,
252
- Plotly . Axes . layoutAttributes ,
253
- attr , dflt ) ;
258
+ return Lib . coerce ( axIn , axOut , Axes . layoutAttributes , attr , dflt ) ;
254
259
}
255
260
256
- Plotly . Axes . handleTickValueDefaults ( axIn , axOut , coerce , axType ) ;
261
+ handleTickValueDefaults ( axIn , axOut , coerce , axType ) ;
257
262
}
258
263
259
264
it ( 'should set default tickmode correctly' , function ( ) {
260
265
var axIn = { } ,
261
266
axOut = { } ;
262
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
267
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
263
268
expect ( axOut . tickmode ) . toBe ( 'auto' ) ;
264
269
265
270
axIn = { tickmode : 'array' , tickvals : 'stuff' } ;
266
271
axOut = { } ;
267
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
272
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
268
273
expect ( axOut . tickmode ) . toBe ( 'auto' ) ;
269
274
270
275
axIn = { tickmode : 'array' , tickvals : [ 1 , 2 , 3 ] } ;
271
276
axOut = { } ;
272
- handleTickValueDefaults ( axIn , axOut , 'date' ) ;
277
+ mockSupplyDefaults ( axIn , axOut , 'date' ) ;
273
278
expect ( axOut . tickmode ) . toBe ( 'auto' ) ;
274
279
275
280
axIn = { tickvals : [ 1 , 2 , 3 ] } ;
276
281
axOut = { } ;
277
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
282
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
278
283
expect ( axOut . tickmode ) . toBe ( 'array' ) ;
279
284
280
285
axIn = { dtick : 1 } ;
281
286
axOut = { } ;
282
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
287
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
283
288
expect ( axOut . tickmode ) . toBe ( 'linear' ) ;
284
289
} ) ;
285
290
286
291
it ( 'should set nticks iff tickmode=auto' , function ( ) {
287
292
var axIn = { } ,
288
293
axOut = { } ;
289
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
294
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
290
295
expect ( axOut . nticks ) . toBe ( 0 ) ;
291
296
292
297
axIn = { tickmode : 'auto' , nticks : 5 } ;
293
298
axOut = { } ;
294
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
299
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
295
300
expect ( axOut . nticks ) . toBe ( 5 ) ;
296
301
297
302
axIn = { tickmode : 'linear' , nticks : 15 } ;
298
303
axOut = { } ;
299
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
304
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
300
305
expect ( axOut . nticks ) . toBe ( undefined ) ;
301
306
} ) ;
302
307
303
308
it ( 'should set tick0 and dtick iff tickmode=linear' , function ( ) {
304
309
var axIn = { tickmode : 'auto' , tick0 : 1 , dtick : 1 } ,
305
310
axOut = { } ;
306
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
311
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
307
312
expect ( axOut . tick0 ) . toBe ( undefined ) ;
308
313
expect ( axOut . dtick ) . toBe ( undefined ) ;
309
314
310
315
axIn = { tickvals : [ 1 , 2 , 3 ] , tick0 : 1 , dtick : 1 } ;
311
316
axOut = { } ;
312
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
317
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
313
318
expect ( axOut . tick0 ) . toBe ( undefined ) ;
314
319
expect ( axOut . dtick ) . toBe ( undefined ) ;
315
320
316
321
axIn = { tick0 : 2.71 , dtick : 0.00828 } ;
317
322
axOut = { } ;
318
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
323
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
319
324
expect ( axOut . tick0 ) . toBe ( 2.71 ) ;
320
325
expect ( axOut . dtick ) . toBe ( 0.00828 ) ;
321
326
322
327
axIn = { tickmode : 'linear' , tick0 : 3.14 , dtick : 0.00159 } ;
323
328
axOut = { } ;
324
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
329
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
325
330
expect ( axOut . tick0 ) . toBe ( 3.14 ) ;
326
331
expect ( axOut . dtick ) . toBe ( 0.00159 ) ;
327
332
} ) ;
328
333
329
334
it ( 'should set tickvals and ticktext iff tickmode=array' , function ( ) {
330
335
var axIn = { tickmode : 'auto' , tickvals : [ 1 , 2 , 3 ] , ticktext : [ '4' , '5' , '6' ] } ,
331
336
axOut = { } ;
332
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
337
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
333
338
expect ( axOut . tickvals ) . toBe ( undefined ) ;
334
339
expect ( axOut . ticktext ) . toBe ( undefined ) ;
335
340
336
341
axIn = { tickvals : [ 2 , 4 , 6 , 8 ] , ticktext : [ 'who' , 'do' , 'we' , 'appreciate' ] } ;
337
342
axOut = { } ;
338
- handleTickValueDefaults ( axIn , axOut , 'linear' ) ;
343
+ mockSupplyDefaults ( axIn , axOut , 'linear' ) ;
339
344
expect ( axOut . tickvals ) . toEqual ( [ 2 , 4 , 6 , 8 ] ) ;
340
345
expect ( axOut . ticktext ) . toEqual ( [ 'who' , 'do' , 'we' , 'appreciate' ] ) ;
341
346
} ) ;
342
347
} ) ;
343
348
344
349
describe ( 'saveRangeInitial' , function ( ) {
345
- var saveRangeInitial = Plotly . Axes . saveRangeInitial ;
350
+ var saveRangeInitial = Axes . saveRangeInitial ;
346
351
var gd , hasOneAxisChanged ;
347
352
348
353
beforeEach ( function ( ) {
@@ -401,7 +406,7 @@ describe('Test axes', function() {
401
406
} ) ;
402
407
403
408
describe ( 'list' , function ( ) {
404
- var listFunc = Plotly . Axes . list ;
409
+ var listFunc = Axes . list ;
405
410
var gd ;
406
411
407
412
it ( 'returns empty array when no fullLayout is present' , function ( ) {
@@ -484,7 +489,7 @@ describe('Test axes', function() {
484
489
} ) ;
485
490
486
491
describe ( 'getSubplots' , function ( ) {
487
- var getSubplots = Plotly . Axes . getSubplots ;
492
+ var getSubplots = Axes . getSubplots ;
488
493
var gd ;
489
494
490
495
it ( 'returns list of subplots ids (from data only)' , function ( ) {
0 commit comments