@@ -2449,8 +2449,10 @@ describe('Test axes', function() {
24492449 } ) ;
24502450
24512451 describe ( 'makeCalcdata' , function ( ) {
2452+ var ax ;
2453+
24522454 function _makeCalcdata ( trace , axLetter , axType ) {
2453- var ax = { type : axType } ;
2455+ ax = { type : axType } ;
24542456 Axes . setConvert ( ax ) ;
24552457 ax . _categories = [ ] ;
24562458 return ax . makeCalcdata ( trace , axLetter ) ;
@@ -2508,7 +2510,7 @@ describe('Test axes', function() {
25082510 } ) ;
25092511
25102512 describe ( 'should subarray typed arrays' , function ( ) {
2511- it ( '- same length case' , function ( ) {
2513+ it ( '- same length linear case' , function ( ) {
25122514 var x = new Float32Array ( [ 1 , 2 , 3 ] ) ;
25132515 var out = _makeCalcdata ( {
25142516 _length : 3 ,
@@ -2517,6 +2519,15 @@ describe('Test axes', function() {
25172519 expect ( out ) . toBe ( x ) ;
25182520 } ) ;
25192521
2522+ it ( '- same length log case' , function ( ) {
2523+ var x = new Float32Array ( [ 1 , 2 , 3 ] ) ;
2524+ var out = _makeCalcdata ( {
2525+ _length : 3 ,
2526+ x : x
2527+ } , 'x' , 'log' ) ;
2528+ expect ( out ) . toBe ( x ) ;
2529+ } ) ;
2530+
25202531 it ( '- subarray case' , function ( ) {
25212532 var x = new Float32Array ( [ 1 , 2 , 3 ] ) ;
25222533 var out = _makeCalcdata ( {
@@ -2529,6 +2540,29 @@ describe('Test axes', function() {
25292540 expect ( out . buffer ) . toEqual ( x . buffer ) ;
25302541 } ) ;
25312542 } ) ;
2543+
2544+ describe ( 'should convert typed arrays to plain array' , function ( ) {
2545+ it ( '- on a category axis' , function ( ) {
2546+ var out = _makeCalcdata ( {
2547+ x : new Float32Array ( [ 3 , 1 , 2 ] ) ,
2548+ } , 'x' , 'category' ) ;
2549+ expect ( out ) . toEqual ( [ 0 , 1 , 2 ] ) ;
2550+ expect ( ax . _categories ) . toEqual ( [ 3 , 1 , 2 ] ) ;
2551+ } ) ;
2552+
2553+ it ( '- on a date axis' , function ( ) {
2554+ var dates = [ [ 2000 , 0 , 1 ] , [ 2001 , 0 , 1 ] , [ 2002 , 0 , 1 ] ]
2555+ . map ( function ( d ) { return new Date ( d [ 0 ] , d [ 1 ] , d [ 2 ] ) . getTime ( ) ; } ) ;
2556+
2557+ // We could make this work down the road (in v2),
2558+ // when address our timezone problems.
2559+ var out = _makeCalcdata ( {
2560+ x : new Float64Array ( dates )
2561+ } , 'x' , 'date' ) ;
2562+
2563+ expect ( out ) . toEqual ( [ 946684800000 , 978307200000 , 1009843200000 ] ) ;
2564+ } ) ;
2565+ } ) ;
25322566 } ) ;
25332567} ) ;
25342568
0 commit comments