@@ -19,7 +19,14 @@ var Titles = require('../../components/titles');
1919var Color = require ( '../../components/color' ) ;
2020var Drawing = require ( '../../components/drawing' ) ;
2121
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 ;
2330
2431
2532var axes = module . exports = { } ;
@@ -727,7 +734,7 @@ function roundDTick(roughDTick, base, roundingSet) {
727734// outputs (into ax):
728735// tick0: starting point for ticks (not necessarily on the graph)
729736// 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
731738// if the ticks are spaced linearly (linear scale, categories,
732739// log with only full powers, date ticks < month),
733740// this will just be a number
@@ -741,37 +748,34 @@ axes.autoTicks = function(ax, roughDTick) {
741748
742749 if ( ax . type === 'date' ) {
743750 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 ;
744754
745- if ( roughDTick > 15778800000 ) {
746- // years if roughDTick > 6mo
747- roughDTick /= 31557600000 ;
755+ if ( roughX2 > ONEAVGYEAR ) {
756+ roughDTick /= ONEAVGYEAR ;
748757 base = Math . pow ( 10 , Math . floor ( Math . log ( roughDTick ) / Math . LN10 ) ) ;
749758 ax . dtick = 'M' + ( 12 * roundDTick ( roughDTick , base , roundBase10 ) ) ;
750759 }
751- else if ( roughDTick > 1209600000 ) {
752- // months if roughDTick > 2wk
753- roughDTick /= 2629800000 ;
760+ else if ( roughX2 > ONEAVGMONTH ) {
761+ roughDTick /= ONEAVGMONTH ;
754762 ax . dtick = 'M' + roundDTick ( roughDTick , 1 , roundBase24 ) ;
755763 }
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 ) ;
759766 // get week ticks on sunday
760767 // this will also move the base tick off 2000-01-01 if dtick is
761768 // 2 or 3 days... but that's a weird enough case that we'll ignore it.
762769 ax . tick0 = '2000-01-02' ;
763770 }
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 ) ;
767773 }
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 ) ;
771776 }
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 ) ;
775779 }
776780 else {
777781 // milliseconds
@@ -826,11 +830,6 @@ axes.autoTicks = function(ax, roughDTick) {
826830 }
827831} ;
828832
829- var ONEDAY = 86400000 ,
830- ONEHOUR = 3600000 ,
831- ONEMIN = 60000 ,
832- ONESEC = 1000 ;
833-
834833// after dtick is already known, find tickround = precision
835834// to display in tick labels
836835// for numeric ticks, integer # digits after . to round to
0 commit comments