@@ -59,7 +59,7 @@ export default class Chart extends React.Component {
59
59
}
60
60
61
61
render ( ) {
62
- const { width, height, data } = this . props ;
62
+ const { width, height, data, xAxisType = 'time' , hideXAxisLabels = false } = this . props ;
63
63
const plotting = { } ;
64
64
let minX = Infinity ;
65
65
let maxX = - Infinity ;
@@ -83,7 +83,12 @@ export default class Chart extends React.Component {
83
83
}
84
84
plotting [ key ] = { data : ordered , index : data [ key ] . index } ;
85
85
}
86
- const timeBuckets = Charting . timeAxisBuckets ( minX , maxX ) ;
86
+ let timeBuckets ;
87
+ if ( xAxisType === 'index' ) {
88
+ timeBuckets = Charting . numericAxisBuckets ( minX , maxX ) ;
89
+ } else {
90
+ timeBuckets = Charting . timeAxisBuckets ( minX , maxX ) ;
91
+ }
87
92
const valueBuckets = Charting . valueAxisBuckets ( maxY || 10 ) ;
88
93
const groups = [ ] ;
89
94
for ( const key in plotting ) {
@@ -134,23 +139,28 @@ export default class Chart extends React.Component {
134
139
t =>
135
140
( chartWidth * ( t - timeBuckets [ 0 ] ) ) / ( timeBuckets [ timeBuckets . length - 1 ] - timeBuckets [ 0 ] )
136
141
) ;
137
- let last = null ;
138
- const tickLabels = timeBuckets . map ( ( t , i ) => {
139
- let text = '' ;
140
- if ( timeBuckets . length > 20 && i % 2 === 0 ) {
141
- return '' ;
142
- }
143
- if ( ! last || t . getMonth ( ) !== last . getMonth ( ) ) {
144
- text += shortMonth ( t . getMonth ( ) ) + ' ' ;
145
- }
146
- if ( ! last || t . getDate ( ) !== last . getDate ( ) ) {
147
- text += t . getDate ( ) ;
148
- } else if ( last && t . getHours ( ) !== last . getHours ( ) ) {
149
- text += t . getHours ( ) + ':00' ;
150
- }
151
- last = t ;
152
- return text ;
153
- } ) ;
142
+ let tickLabels ;
143
+ if ( xAxisType === 'index' ) {
144
+ tickLabels = timeBuckets . map ( t => t ) ;
145
+ } else {
146
+ let last = null ;
147
+ tickLabels = timeBuckets . map ( ( t , i ) => {
148
+ let text = '' ;
149
+ if ( timeBuckets . length > 20 && i % 2 === 0 ) {
150
+ return '' ;
151
+ }
152
+ if ( ! last || t . getMonth ( ) !== last . getMonth ( ) ) {
153
+ text += shortMonth ( t . getMonth ( ) ) + ' ' ;
154
+ }
155
+ if ( ! last || t . getDate ( ) !== last . getDate ( ) ) {
156
+ text += t . getDate ( ) ;
157
+ } else if ( last && t . getHours ( ) !== last . getHours ( ) ) {
158
+ text += t . getHours ( ) + ':00' ;
159
+ }
160
+ last = t ;
161
+ return text ;
162
+ } ) ;
163
+ }
154
164
let popup = null ;
155
165
if ( this . state . hoverValue !== null ) {
156
166
const style = {
@@ -191,17 +201,19 @@ export default class Chart extends React.Component {
191
201
</ div >
192
202
) ) }
193
203
</ div >
194
- < div className = { styles . xAxis } >
195
- { tickLabels . map ( ( t , i ) => (
196
- < div
197
- key = { t + '_' + i }
198
- className = { styles . tick }
199
- style = { { left : tickPoints [ i ] + MARGIN_LEFT } }
200
- >
201
- { t }
202
- </ div >
203
- ) ) }
204
- </ div >
204
+ { ! hideXAxisLabels && (
205
+ < div className = { styles . xAxis } >
206
+ { tickLabels . map ( ( t , i ) => (
207
+ < div
208
+ key = { t + '_' + i }
209
+ className = { styles . tick }
210
+ style = { { left : tickPoints [ i ] + MARGIN_LEFT } }
211
+ >
212
+ { t }
213
+ </ div >
214
+ ) ) }
215
+ </ div >
216
+ ) }
205
217
< svg width = { chartWidth + 10 } height = { chartHeight + 10 } >
206
218
< g >
207
219
{ labelHeights . map ( h => (
@@ -245,4 +257,6 @@ Chart.propTypes = {
245
257
'It receives the numeric value of a point and label, and should return a string. ' +
246
258
'This is ideally used for providing descriptive units like "active installations."'
247
259
) ,
260
+ xAxisType : PropTypes . string . describe ( 'Axis type: "time" or "index"' ) ,
261
+ hideXAxisLabels : PropTypes . bool . describe ( 'Hide labels on the x-axis' ) ,
248
262
} ;
0 commit comments