@@ -32,28 +32,33 @@ describe('Test quiver defaults', function() {
3232 expect ( gd . _fullData [ 0 ] . visible ) . toBe ( true ) ;
3333 } ) ;
3434
35- it ( 'should set `visible: false` for traces missing x or y arrays' , function ( ) {
36- var keysToDelete = [ 'x' , 'y' ] ;
37-
38- keysToDelete . forEach ( function ( k ) {
39- gd = makeGD ( ) ;
40- delete gd . data [ 0 ] [ k ] ;
35+ it ( 'should set `visible: false` for traces missing both x and y arrays' , function ( ) {
36+ gd = makeGD ( ) ;
37+ delete gd . data [ 0 ] . x ;
38+ delete gd . data [ 0 ] . y ;
4139
42- supplyAllDefaults ( gd ) ;
43- expect ( gd . _fullData [ 0 ] . visible ) . toBe ( false , 'missing array ' + k ) ;
44- } ) ;
40+ supplyAllDefaults ( gd ) ;
41+ expect ( gd . _fullData [ 0 ] . visible ) . toBe ( false ) ;
4542 } ) ;
4643
47- it ( 'should set `visible: false` for traces with empty x or y arrays' , function ( ) {
48- var keysToEmpty = [ 'x' , 'y' ] ;
49-
50- keysToEmpty . forEach ( function ( k ) {
51- gd = makeGD ( ) ;
52- gd . data [ 0 ] [ k ] = [ ] ;
44+ it ( 'should generate the missing axis from x0/dx or y0/dy (like scatter)' , function ( ) {
45+ // missing x: generated from x0/dx (defaults 0 and 1)
46+ gd = makeGD ( ) ;
47+ delete gd . data [ 0 ] . x ;
48+ supplyAllDefaults ( gd ) ;
49+ expect ( gd . _fullData [ 0 ] . visible ) . toBe ( true , 'missing x' ) ;
50+ expect ( gd . _fullData [ 0 ] . x0 ) . toBe ( 0 ) ;
51+ expect ( gd . _fullData [ 0 ] . dx ) . toBe ( 1 ) ;
52+ expect ( gd . _fullData [ 0 ] . _length ) . toBe ( 2 ) ;
5353
54- supplyAllDefaults ( gd ) ;
55- expect ( gd . _fullData [ 0 ] . visible ) . toBe ( false , 'empty array ' + k ) ;
56- } ) ;
54+ // missing y: generated from y0/dy (defaults 0 and 1)
55+ gd = makeGD ( ) ;
56+ delete gd . data [ 0 ] . y ;
57+ supplyAllDefaults ( gd ) ;
58+ expect ( gd . _fullData [ 0 ] . visible ) . toBe ( true , 'missing y' ) ;
59+ expect ( gd . _fullData [ 0 ] . y0 ) . toBe ( 0 ) ;
60+ expect ( gd . _fullData [ 0 ] . dy ) . toBe ( 1 ) ;
61+ expect ( gd . _fullData [ 0 ] . _length ) . toBe ( 2 ) ;
5762 } ) ;
5863
5964 it ( 'should default u,v to zeros when missing' , function ( ) {
@@ -143,6 +148,33 @@ describe('Test quiver calc', function() {
143148 } )
144149 . then ( done , done . fail ) ;
145150 } ) ;
151+
152+ it ( 'should generate x from x0/dx and y from y0/dy with the expected values' , function ( done ) {
153+ // missing x -> x generated from x0/dx defaults (0, 1)
154+ Plotly . newPlot ( gd , [ {
155+ type : 'quiver' ,
156+ y : [ 10 , 20 , 30 ] ,
157+ u : [ 1 , 1 , 1 ] ,
158+ v : [ 1 , 1 , 1 ]
159+ } ] ) . then ( function ( ) {
160+ var cd = gd . calcdata [ 0 ] ;
161+ expect ( cd . map ( function ( c ) { return c . x ; } ) ) . toEqual ( [ 0 , 1 , 2 ] ) ;
162+ expect ( cd . map ( function ( c ) { return c . y ; } ) ) . toEqual ( [ 10 , 20 , 30 ] ) ;
163+
164+ // missing y -> y generated from y0/dy defaults (0, 1)
165+ return Plotly . newPlot ( gd , [ {
166+ type : 'quiver' ,
167+ x : [ 10 , 20 , 30 ] ,
168+ u : [ 1 , 1 , 1 ] ,
169+ v : [ 1 , 1 , 1 ]
170+ } ] ) ;
171+ } ) . then ( function ( ) {
172+ var cd = gd . calcdata [ 0 ] ;
173+ expect ( cd . map ( function ( c ) { return c . x ; } ) ) . toEqual ( [ 10 , 20 , 30 ] ) ;
174+ expect ( cd . map ( function ( c ) { return c . y ; } ) ) . toEqual ( [ 0 , 1 , 2 ] ) ;
175+ } )
176+ . then ( done , done . fail ) ;
177+ } ) ;
146178} ) ;
147179
148180describe ( 'Test quiver interactions' , function ( ) {
0 commit comments