@@ -13,6 +13,10 @@ const MILLISECONDS_IN_DAY = MILLISECONDS_IN_MINUTE * 60 * 24; // eslint-disable-
1313const DAYS_IN_MONTH = 30 ;
1414const MONTHS_IN_YEAR = 12 ; //eslint-disable-line
1515
16+ function twoDecimalsRound ( value ) {
17+ return Math . round ( value * 100 ) / 100 ;
18+ }
19+
1620function getSmallestUnit ( milliseconds ) {
1721 const units = {
1822 seconds : MILLISECONDS_IN_SECOND ,
@@ -36,7 +40,7 @@ function getSmallestUnit(milliseconds) {
3640 return smallestUnit ;
3741}
3842
39- class UnconnectedAxisInterval extends Component {
43+ export class UnconnectedAxisInterval extends Component {
4044 constructor ( props ) {
4145 super ( props ) ;
4246
@@ -54,13 +58,22 @@ class UnconnectedAxisInterval extends Component {
5458
5559 update ( value ) {
5660 let adjustedValue = value < 0 ? 0 : value ;
61+ const isValueInteger = adjustedValue % 1 === 0 ;
5762
5863 if ( this . state . units === 'years' ) {
59- adjustedValue = 'M' + adjustedValue * MONTHS_IN_YEAR ;
64+ if ( isValueInteger ) {
65+ adjustedValue = 'M' + adjustedValue * MONTHS_IN_YEAR ;
66+ } else {
67+ adjustedValue = adjustedValue * MONTHS_IN_YEAR * DAYS_IN_MONTH * MILLISECONDS_IN_DAY ;
68+ }
6069 }
6170
6271 if ( this . state . units === 'months' ) {
63- adjustedValue = 'M' + adjustedValue ;
72+ if ( isValueInteger ) {
73+ adjustedValue = 'M' + adjustedValue ;
74+ } else {
75+ adjustedValue = adjustedValue * DAYS_IN_MONTH * MILLISECONDS_IN_DAY ;
76+ }
6477 }
6578
6679 if ( this . state . units === 'days' ) {
@@ -89,7 +102,12 @@ class UnconnectedAxisInterval extends Component {
89102 this . setState ( { units : value } ) ;
90103
91104 if ( [ 'years' , 'months' ] . includes ( value ) ) {
92- this . props . updatePlot ( 'M' + Math . round ( milliseconds / MILLISECONDS_IN_DAY / DAYS_IN_MONTH ) ) ;
105+ const nbMonths = milliseconds / MILLISECONDS_IN_DAY / DAYS_IN_MONTH ;
106+ if ( nbMonths % 1 === 0 ) {
107+ this . props . updatePlot ( 'M' + nbMonths ) ;
108+ } else {
109+ this . props . updatePlot ( milliseconds ) ;
110+ }
93111 } else {
94112 this . props . updatePlot ( milliseconds ) ;
95113 }
@@ -100,19 +118,25 @@ class UnconnectedAxisInterval extends Component {
100118 typeof value === 'string' && value [ 0 ] === 'M' ? parseInt ( value . substring ( 1 ) , 10 ) : value ;
101119
102120 if ( this . state . units === 'years' ) {
103- return numericValue / MONTHS_IN_YEAR ;
121+ if ( typeof value === 'string' ) {
122+ return twoDecimalsRound ( numericValue / MONTHS_IN_YEAR ) ;
123+ }
124+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_DAY / DAYS_IN_MONTH / MONTHS_IN_YEAR ) ;
104125 }
105126 if ( this . state . units === 'months' ) {
106- return numericValue ;
127+ if ( typeof value === 'string' ) {
128+ return twoDecimalsRound ( numericValue ) ;
129+ }
130+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_DAY / DAYS_IN_MONTH ) ;
107131 }
108132 if ( this . state . units === 'days' ) {
109- return Math . round ( numericValue / MILLISECONDS_IN_DAY ) ;
133+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_DAY ) ;
110134 }
111135 if ( this . state . units === 'minutes' ) {
112- return Math . round ( numericValue / MILLISECONDS_IN_MINUTE ) ;
136+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_MINUTE ) ;
113137 }
114138 if ( this . state . units === 'seconds' ) {
115- return Math . round ( numericValue / MILLISECONDS_IN_SECOND ) ;
139+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_SECOND ) ;
116140 }
117141 if ( this . state . units === 'milliseconds' ) {
118142 return numericValue ;
@@ -126,8 +150,12 @@ class UnconnectedAxisInterval extends Component {
126150 const binStartValue = this . props . fullContainer [ attrHead ] . start ;
127151 const BinStartIsDate =
128152 typeof binStartValue === 'string' && ( isDateTime ( binStartValue ) || isJSDate ( binStartValue ) ) ;
153+ const tick0 =
154+ this . props . fullContainer . tick0 &&
155+ ( this . props . fullContainer . tick0 || this . props . fullContainer . colorbar . tick0 ) ;
156+ const tick0IsDate = tick0 && ( isDateTime ( tick0 ) || isJSDate ( tick0 ) ) ;
129157
130- return BinStartIsDate ? (
158+ return BinStartIsDate || tick0IsDate ? (
131159 < Field { ...this . props } >
132160 < Dropdown
133161 options = { [
@@ -142,7 +170,7 @@ class UnconnectedAxisInterval extends Component {
142170 onChange = { value => this . onUnitChange ( value ) }
143171 value = { this . state . units }
144172 />
145- < div style = { { height : '7px' , width : '100%' , display : 'block' } } > </ div >
173+ < div style = { { width : '100%' , display : 'block' } } > </ div >
146174 < NumericInput
147175 value = { this . getDisplayValue ( this . props . fullValue ) }
148176 onUpdate = { value => this . update ( value ) }
0 commit comments