1
+ import { isIntegerArray } from "../../instrumented/functions" ;
1
2
import { Vertex } from "../../instrumented/baseShape" ;
2
3
import { Rect } from "../../instrumented/primitives" ;
3
4
import { Axis , ParallelAxis } from "../../instrumented/axes" ;
@@ -30,7 +31,7 @@ describe('Axis', function() {
30
31
const ticks = [ - 1 , 0 , 1 , 2 ]
31
32
expect ( axis . ticks ) . to . deep . equal ( ticks ) ;
32
33
expect ( axis . isDiscrete , `isDiscrete` ) . to . be . true ;
33
- } ) ;
34
+ } ) ;
34
35
35
36
it ( 'should be well created with empty vector features' , function ( ) {
36
37
const axis = new Axis ( [ ] , boundingBox , origin , end , name , initScale , nTicks ) ;
@@ -40,8 +41,19 @@ describe('Axis', function() {
40
41
} ) ;
41
42
42
43
it ( 'should be well created without only one feature' , function ( ) {
43
- const axis = new Axis ( [ 1 ] , boundingBox , origin , end , name , initScale , nTicks ) ;
44
- expect ( axis . ticks . length , `length ticks` ) . to . equal ( 7 ) ;
44
+ const axis = new Axis ( [ 1.2 ] , boundingBox , origin , end , name , initScale , nTicks ) ;
45
+ expect ( axis . ticks . length , `length ticks` ) . to . equal ( 5 ) ;
46
+ } ) ;
47
+
48
+ it ( 'should be only show integer ticks' , function ( ) {
49
+ const axis = new Axis ( vector , boundingBox , origin , end , name , initScale , nTicks ) ;
50
+ expect ( isIntegerArray ( axis . ticks ) , `integer ticks` ) . to . be . true ;
51
+ axis . updateScale ( new Vertex ( 20 , 20 ) , new Vertex ( 2 , 0.5 ) , new Vertex ( ) ) ;
52
+ expect ( isIntegerArray ( axis . ticks ) , `integer ticks` ) . to . be . true ;
53
+ axis . updateScale ( new Vertex ( 20 , 20 ) , new Vertex ( - 2 , - 0.5 ) , new Vertex ( ) ) ;
54
+ expect ( isIntegerArray ( axis . ticks ) , `integer ticks` ) . to . be . true ;
55
+ axis . updateScale ( new Vertex ( 20 , 20 ) , new Vertex ( 10 , 0.5 ) , new Vertex ( ) ) ;
56
+ expect ( isIntegerArray ( axis . ticks ) , `integer ticks` ) . to . be . true ;
45
57
} ) ;
46
58
47
59
it ( "should scale axis with another one" , function ( ) {
@@ -75,6 +87,13 @@ describe('Axis', function() {
75
87
expect ( axis . maxValue , "maxValue" ) . to . be . closeTo ( 8.7 , 0.05 ) ;
76
88
} ) ;
77
89
90
+ it ( "should scale axis in a logarithmic way" , function ( ) {
91
+ const axis = new Axis ( vector , boundingBox , origin , end , name , initScale , nTicks ) ;
92
+ expect ( vector . map ( element => Math . floor ( axis . relativeToAbsolute ( element ) ) ) , "projected values" ) . to . deep . equal ( [ 4 , 27 , 50 , 72 , 95 ] ) ;
93
+ axis . switchLogScale ( vector ) ;
94
+ expect ( vector . map ( element => Math . floor ( axis . relativeToAbsolute ( element ) ) ) , "projected log values" ) . to . deep . equal ( [ - 19 , - 12 , - 8 , - 5 , - 3 ] ) ;
95
+ } ) ;
96
+
78
97
it ( 'should update axis with translation and style' , function ( ) {
79
98
const axis = new Axis ( vector , boundingBox , origin , end , name , initScale , nTicks ) ;
80
99
const viewPoint = new Vertex ( 0 , 0 ) ;
@@ -112,7 +131,43 @@ describe('Axis', function() {
112
131
113
132
numericStringVector . forEach ( ( value , index ) => expect ( stringAxis . labels [ value ] , `string value ${ index } ` ) . to . equal ( stringVector [ index ] ) ) ;
114
133
numericNumberVector . forEach ( ( value , index ) => expect ( value , `number value ${ index } ` ) . to . equal ( numberVector [ index ] ) ) ;
115
- } )
134
+ } ) ;
135
+
136
+ it ( "should be drawn with date labels" , function ( ) {
137
+ const timeZoneOffSet = new Date ( ) . getTimezoneOffset ( ) * 60 ;
138
+ const dateVector = [
139
+ new Date ( ( 123456789 + timeZoneOffSet ) * 1000 ) ,
140
+ new Date ( ( 234242524 + timeZoneOffSet ) * 1000 ) ,
141
+ new Date ( ( 326472910 + timeZoneOffSet ) * 1000 ) ,
142
+ new Date ( ( 564927592 + timeZoneOffSet ) * 1000 ) ,
143
+ new Date ( ( 675829471 + timeZoneOffSet ) * 1000 )
144
+ ] ;
145
+ const dateAxis = new Axis ( dateVector , boundingBox , origin , end , name , initScale , nTicks ) ;
146
+ const controlLabels = timeZoneOffSet == 0 ?
147
+ [
148
+ "07/03/1973 - 09:46:40" ,
149
+ "02/05/1976 - 19:33:20" ,
150
+ "05/07/1979 - 05:20:00" ,
151
+ "07/09/1982 - 15:06:40" ,
152
+ "03/11/1985 - 00:53:20" ,
153
+ "05/01/1989 - 10:40:00" ,
154
+ "07/03/1992 - 20:26:40"
155
+ ]
156
+ :
157
+ [
158
+ "07/03/1973 - 10:46:40" ,
159
+ "02/05/1976 - 21:33:20" ,
160
+ "05/07/1979 - 07:20:00" ,
161
+ "07/09/1982 - 17:06:40" ,
162
+ "03/11/1985 - 01:53:20" ,
163
+ "05/01/1989 - 11:40:00" ,
164
+ "07/03/1992 - 21:26:40"
165
+ ] ;
166
+ const controlTicks = [ 100000000000 , 200000000000 , 300000000000 , 400000000000 , 500000000000 , 600000000000 , 700000000000 ] ;
167
+ expect ( dateAxis . labels , "labels" ) . to . deep . equal ( controlLabels ) ;
168
+ expect ( dateAxis . ticks , "labels" ) . to . deep . equal ( controlTicks ) ;
169
+
170
+ } ) ;
116
171
} ) ;
117
172
118
173
describe ( "RubberBand" , function ( ) {
0 commit comments