@@ -13,6 +13,10 @@ const MILLISECONDS_IN_DAY = MILLISECONDS_IN_MINUTE * 60 * 24; // eslint-disable-
13
13
const DAYS_IN_MONTH = 30 ;
14
14
const MONTHS_IN_YEAR = 12 ; //eslint-disable-line
15
15
16
+ function twoDecimalsRound ( value ) {
17
+ return Math . round ( value * 100 ) / 100 ;
18
+ }
19
+
16
20
function getSmallestUnit ( milliseconds ) {
17
21
const units = {
18
22
seconds : MILLISECONDS_IN_SECOND ,
@@ -36,7 +40,7 @@ function getSmallestUnit(milliseconds) {
36
40
return smallestUnit ;
37
41
}
38
42
39
- class UnconnectedAxisInterval extends Component {
43
+ export class UnconnectedAxisInterval extends Component {
40
44
constructor ( props ) {
41
45
super ( props ) ;
42
46
@@ -54,13 +58,22 @@ class UnconnectedAxisInterval extends Component {
54
58
55
59
update ( value ) {
56
60
let adjustedValue = value < 0 ? 0 : value ;
61
+ const isValueInteger = adjustedValue % 1 === 0 ;
57
62
58
63
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
+ }
60
69
}
61
70
62
71
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
+ }
64
77
}
65
78
66
79
if ( this . state . units === 'days' ) {
@@ -89,7 +102,12 @@ class UnconnectedAxisInterval extends Component {
89
102
this . setState ( { units : value } ) ;
90
103
91
104
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
+ }
93
111
} else {
94
112
this . props . updatePlot ( milliseconds ) ;
95
113
}
@@ -100,19 +118,25 @@ class UnconnectedAxisInterval extends Component {
100
118
typeof value === 'string' && value [ 0 ] === 'M' ? parseInt ( value . substring ( 1 ) , 10 ) : value ;
101
119
102
120
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 ) ;
104
125
}
105
126
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 ) ;
107
131
}
108
132
if ( this . state . units === 'days' ) {
109
- return Math . round ( numericValue / MILLISECONDS_IN_DAY ) ;
133
+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_DAY ) ;
110
134
}
111
135
if ( this . state . units === 'minutes' ) {
112
- return Math . round ( numericValue / MILLISECONDS_IN_MINUTE ) ;
136
+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_MINUTE ) ;
113
137
}
114
138
if ( this . state . units === 'seconds' ) {
115
- return Math . round ( numericValue / MILLISECONDS_IN_SECOND ) ;
139
+ return twoDecimalsRound ( numericValue / MILLISECONDS_IN_SECOND ) ;
116
140
}
117
141
if ( this . state . units === 'milliseconds' ) {
118
142
return numericValue ;
@@ -126,8 +150,12 @@ class UnconnectedAxisInterval extends Component {
126
150
const binStartValue = this . props . fullContainer [ attrHead ] . start ;
127
151
const BinStartIsDate =
128
152
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 ) ) ;
129
157
130
- return BinStartIsDate ? (
158
+ return BinStartIsDate || tick0IsDate ? (
131
159
< Field { ...this . props } >
132
160
< Dropdown
133
161
options = { [
@@ -142,7 +170,7 @@ class UnconnectedAxisInterval extends Component {
142
170
onChange = { value => this . onUnitChange ( value ) }
143
171
value = { this . state . units }
144
172
/>
145
- < div style = { { height : '7px' , width : '100%' , display : 'block' } } > </ div >
173
+ < div style = { { width : '100%' , display : 'block' } } > </ div >
146
174
< NumericInput
147
175
value = { this . getDisplayValue ( this . props . fullValue ) }
148
176
onUpdate = { value => this . update ( value ) }
0 commit comments