@@ -500,6 +500,13 @@ describe('Test Plots', function() {
500500 } ) ;
501501
502502 describe ( 'Plots.graphJson' , function ( ) {
503+ var gd ;
504+
505+ beforeEach ( function ( ) {
506+ gd = createGraphDiv ( ) ;
507+ } ) ;
508+
509+ afterEach ( destroyGraphDiv ) ;
503510
504511 it ( 'should serialize data, layout and frames' , function ( done ) {
505512 var mock = {
@@ -533,7 +540,7 @@ describe('Test Plots', function() {
533540 } ]
534541 } ;
535542
536- Plotly . plot ( createGraphDiv ( ) , mock ) . then ( function ( gd ) {
543+ Plotly . plot ( gd , mock ) . then ( function ( ) {
537544 var str = Plots . graphJson ( gd , false , 'keepdata' ) ;
538545 var obj = JSON . parse ( str ) ;
539546
@@ -547,10 +554,38 @@ describe('Test Plots', function() {
547554 name : 'garbage'
548555 } ) ;
549556 } )
550- . then ( function ( ) {
551- destroyGraphDiv ( ) ;
552- done ( ) ;
553- } ) ;
557+ . catch ( failTest )
558+ . then ( done ) ;
559+ } ) ;
560+
561+ it ( 'should convert typed arrays to regular arrays' , function ( done ) {
562+ var trace = {
563+ x : new Float32Array ( [ 1 , 2 , 3 ] ) ,
564+ y : new Float32Array ( [ 1 , 2 , 1 ] ) ,
565+ marker : {
566+ size : new Float32Array ( [ 20 , 30 , 10 ] ) ,
567+ color : new Float32Array ( [ 10 , 30 , 20 ] ) ,
568+ cmin : 10 ,
569+ cmax : 30 ,
570+ colorscale : [
571+ [ 0 , 'rgb(255, 0, 0)' ] ,
572+ [ 0.5 , 'rgb(0, 255, 0)' ] ,
573+ [ 1 , 'rgb(0, 0, 255)' ]
574+ ]
575+ }
576+ } ;
577+
578+ Plotly . plot ( gd , [ trace ] ) . then ( function ( ) {
579+ var str = Plots . graphJson ( gd , false , 'keepdata' ) ;
580+ var obj = JSON . parse ( str ) ;
581+
582+ expect ( obj . data [ 0 ] . x ) . toEqual ( [ 1 , 2 , 3 ] ) ;
583+ expect ( obj . data [ 0 ] . y ) . toEqual ( [ 1 , 2 , 1 ] ) ;
584+ expect ( obj . data [ 0 ] . marker . size ) . toEqual ( [ 20 , 30 , 10 ] ) ;
585+ expect ( obj . data [ 0 ] . marker . color ) . toEqual ( [ 10 , 30 , 20 ] ) ;
586+ } )
587+ . catch ( failTest )
588+ . then ( done ) ;
554589 } ) ;
555590 } ) ;
556591
0 commit comments