@@ -2449,8 +2449,10 @@ describe('Test axes', function() {
2449
2449
} ) ;
2450
2450
2451
2451
describe ( 'makeCalcdata' , function ( ) {
2452
+ var ax ;
2453
+
2452
2454
function _makeCalcdata ( trace , axLetter , axType ) {
2453
- var ax = { type : axType } ;
2455
+ ax = { type : axType } ;
2454
2456
Axes . setConvert ( ax ) ;
2455
2457
ax . _categories = [ ] ;
2456
2458
return ax . makeCalcdata ( trace , axLetter ) ;
@@ -2508,7 +2510,7 @@ describe('Test axes', function() {
2508
2510
} ) ;
2509
2511
2510
2512
describe ( 'should subarray typed arrays' , function ( ) {
2511
- it ( '- same length case' , function ( ) {
2513
+ it ( '- same length linear case' , function ( ) {
2512
2514
var x = new Float32Array ( [ 1 , 2 , 3 ] ) ;
2513
2515
var out = _makeCalcdata ( {
2514
2516
_length : 3 ,
@@ -2517,6 +2519,15 @@ describe('Test axes', function() {
2517
2519
expect ( out ) . toBe ( x ) ;
2518
2520
} ) ;
2519
2521
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
+
2520
2531
it ( '- subarray case' , function ( ) {
2521
2532
var x = new Float32Array ( [ 1 , 2 , 3 ] ) ;
2522
2533
var out = _makeCalcdata ( {
@@ -2529,6 +2540,29 @@ describe('Test axes', function() {
2529
2540
expect ( out . buffer ) . toEqual ( x . buffer ) ;
2530
2541
} ) ;
2531
2542
} ) ;
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
+ } ) ;
2532
2566
} ) ;
2533
2567
} ) ;
2534
2568
0 commit comments