@@ -19,7 +19,14 @@ var Titles = require('../../components/titles');
19
19
var Color = require ( '../../components/color' ) ;
20
20
var Drawing = require ( '../../components/drawing' ) ;
21
21
22
- var FP_SAFE = require ( '../../constants/numerical' ) . FP_SAFE ;
22
+ var constants = require ( '../../constants/numerical' ) ;
23
+ var FP_SAFE = constants . FP_SAFE ;
24
+ var ONEAVGYEAR = constants . ONEAVGYEAR ;
25
+ var ONEAVGMONTH = constants . ONEAVGMONTH ;
26
+ var ONEDAY = constants . ONEDAY ;
27
+ var ONEHOUR = constants . ONEHOUR ;
28
+ var ONEMIN = constants . ONEMIN ;
29
+ var ONESEC = constants . ONESEC ;
23
30
24
31
25
32
var axes = module . exports = { } ;
@@ -727,7 +734,7 @@ function roundDTick(roughDTick, base, roundingSet) {
727
734
// outputs (into ax):
728
735
// tick0: starting point for ticks (not necessarily on the graph)
729
736
// usually 0 for numeric (=10^0=1 for log) or jan 1, 2000 for dates
730
- // dtick: the actual, nice round tick spacing, somewhat larger than roughDTick
737
+ // dtick: the actual, nice round tick spacing, usually a little larger than roughDTick
731
738
// if the ticks are spaced linearly (linear scale, categories,
732
739
// log with only full powers, date ticks < month),
733
740
// this will just be a number
@@ -741,37 +748,34 @@ axes.autoTicks = function(ax, roughDTick) {
741
748
742
749
if ( ax . type === 'date' ) {
743
750
ax . tick0 = '2000-01-01' ;
751
+ // the criteria below are all based on the rough spacing we calculate
752
+ // being > half of the final unit - so precalculate twice the rough val
753
+ var roughX2 = 2 * roughDTick ;
744
754
745
- if ( roughDTick > 15778800000 ) {
746
- // years if roughDTick > 6mo
747
- roughDTick /= 31557600000 ;
755
+ if ( roughX2 > ONEAVGYEAR ) {
756
+ roughDTick /= ONEAVGYEAR ;
748
757
base = Math . pow ( 10 , Math . floor ( Math . log ( roughDTick ) / Math . LN10 ) ) ;
749
758
ax . dtick = 'M' + ( 12 * roundDTick ( roughDTick , base , roundBase10 ) ) ;
750
759
}
751
- else if ( roughDTick > 1209600000 ) {
752
- // months if roughDTick > 2wk
753
- roughDTick /= 2629800000 ;
760
+ else if ( roughX2 > ONEAVGMONTH ) {
761
+ roughDTick /= ONEAVGMONTH ;
754
762
ax . dtick = 'M' + roundDTick ( roughDTick , 1 , roundBase24 ) ;
755
763
}
756
- else if ( roughDTick > 43200000 ) {
757
- // days if roughDTick > 12h
758
- ax . dtick = roundDTick ( roughDTick , 86400000 , roundDays ) ;
764
+ else if ( roughX2 > ONEDAY ) {
765
+ ax . dtick = roundDTick ( roughDTick , ONEDAY , roundDays ) ;
759
766
// get week ticks on sunday
760
767
// this will also move the base tick off 2000-01-01 if dtick is
761
768
// 2 or 3 days... but that's a weird enough case that we'll ignore it.
762
769
ax . tick0 = '2000-01-02' ;
763
770
}
764
- else if ( roughDTick > 1800000 ) {
765
- // hours if roughDTick > 30m
766
- ax . dtick = roundDTick ( roughDTick , 3600000 , roundBase24 ) ;
771
+ else if ( roughX2 > ONEHOUR ) {
772
+ ax . dtick = roundDTick ( roughDTick , ONEHOUR , roundBase24 ) ;
767
773
}
768
- else if ( roughDTick > 30000 ) {
769
- // minutes if roughDTick > 30sec
770
- ax . dtick = roundDTick ( roughDTick , 60000 , roundBase60 ) ;
774
+ else if ( roughX2 > ONEMIN ) {
775
+ ax . dtick = roundDTick ( roughDTick , ONEMIN , roundBase60 ) ;
771
776
}
772
- else if ( roughDTick > 500 ) {
773
- // seconds if roughDTick > 0.5sec
774
- ax . dtick = roundDTick ( roughDTick , 1000 , roundBase60 ) ;
777
+ else if ( roughX2 > ONESEC ) {
778
+ ax . dtick = roundDTick ( roughDTick , ONESEC , roundBase60 ) ;
775
779
}
776
780
else {
777
781
// milliseconds
@@ -826,11 +830,6 @@ axes.autoTicks = function(ax, roughDTick) {
826
830
}
827
831
} ;
828
832
829
- var ONEDAY = 86400000 ,
830
- ONEHOUR = 3600000 ,
831
- ONEMIN = 60000 ,
832
- ONESEC = 1000 ;
833
-
834
833
// after dtick is already known, find tickround = precision
835
834
// to display in tick labels
836
835
// for numeric ticks, integer # digits after . to round to
0 commit comments