File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ describe("AXIS", function() {
23
23
]
24
24
} ,
25
25
axis : {
26
+ x : {
27
+ tick : {
28
+ count : undefined
29
+ }
30
+ } ,
26
31
y : {
27
32
tick : {
28
33
values : null ,
@@ -42,6 +47,25 @@ describe("AXIS", function() {
42
47
chart = util . generate ( args ) ;
43
48
} ) ;
44
49
50
+ describe ( "axis.x.tick.count" , ( ) => {
51
+ after ( ( ) => {
52
+ args . axis . x . type = "indexed" ;
53
+ args . axis . x . tick . count = undefined ;
54
+ } ) ;
55
+
56
+ it ( "set options axis.x.tick.count=3" , ( ) => {
57
+ args . axis . x . type = "category" ;
58
+ args . axis . x . tick . count = 3 ;
59
+ } ) ;
60
+
61
+ it ( "should have only 3 tick on x axis" , ( ) => {
62
+ const ticks = chart . $ . main . select ( `.${ CLASS . axisX } ` ) . selectAll ( "g.tick" ) ;
63
+
64
+ expect ( ticks . size ( ) ) . to . be . equal ( 3 ) ;
65
+ expect ( ticks . data ( ) ) . to . be . deep . equal ( [ 0 , 3 , 5 ] ) ;
66
+ } ) ;
67
+ } ) ;
68
+
45
69
describe ( "axis.y.tick.count" , ( ) => {
46
70
it ( "set options axis.y.tick.count=1" , ( ) => {
47
71
args . axis . y . tick . count = 1 ;
Original file line number Diff line number Diff line change @@ -605,6 +605,8 @@ export default class Axis {
605
605
} else if ( targetCount === 2 ) {
606
606
tickValues = [ values [ 0 ] , values [ values . length - 1 ] ] ;
607
607
} else if ( targetCount > 2 ) {
608
+ const isCategorized = this . owner . isCategorized ( ) ;
609
+
608
610
count = targetCount - 2 ;
609
611
start = values [ 0 ] ;
610
612
end = values [ values . length - 1 ] ;
@@ -615,7 +617,11 @@ export default class Axis {
615
617
616
618
for ( i = 0 ; i < count ; i ++ ) {
617
619
tickValue = + start + interval * ( i + 1 ) ;
618
- tickValues . push ( forTimeSeries ? new Date ( tickValue ) : tickValue ) ;
620
+ tickValues . push (
621
+ forTimeSeries ? new Date ( tickValue ) : (
622
+ isCategorized ? Math . round ( tickValue ) : tickValue
623
+ )
624
+ ) ;
619
625
}
620
626
621
627
tickValues . push ( end ) ;
You can’t perform that action at this time.
0 commit comments