@@ -30,6 +30,8 @@ const NeoLineChart = (props: ChartProps) => {
30
30
}
31
31
32
32
const [ isTimeChart , setIsTimeChart ] = React . useState ( false ) ;
33
+ const [ parseFormat , setParseFormat ] = React . useState ( "%Y-%m-%dT%H:%M:%SZ" ) ;
34
+
33
35
const settings = ( props . settings ) ? props . settings : { } ;
34
36
35
37
const colorScheme = ( settings [ "colors" ] ) ? settings [ "colors" ] : 'set2' ;
@@ -88,23 +90,31 @@ const NeoLineChart = (props: ChartProps) => {
88
90
data : [ ]
89
91
} ) )
90
92
93
+ const isDate = ( x ) => {
94
+ return x . __isDate__ ;
95
+ }
96
+
91
97
const isDateTime = ( x ) => {
92
- return x !== undefined && x . day !== undefined && x . hour !== undefined && x . minute !== undefined &&
93
- x . month !== undefined && x . nanosecond !== undefined && x . second !== undefined && x . year !== undefined ;
98
+ return x . __isDateTime__ ;
99
+ }
100
+
101
+ const isDateTimeOrDate = ( x ) => {
102
+ return isDate ( x ) || isDateTime ( x ) || x instanceof Date ;
94
103
}
95
104
96
105
records . forEach ( ( row ) => {
97
106
selection [ 'value' ] . forEach ( key => {
98
107
const index = data . findIndex ( item => ( item as Record < string , any > ) . id === key )
99
- const x : any = row . get ( selection [ 'x' ] ) || 0
108
+ let x : any = row . get ( selection [ 'x' ] ) || 0
100
109
const y : any = recordToNative ( row . get ( key ) ) || 0
101
110
if ( data [ index ] && ! isNaN ( y ) ) {
102
- if ( isDateTime ( x ) ) {
111
+ if ( isDate ( x ) ) {
103
112
data [ index ] . data . push ( { x, y } )
104
- }
105
- if ( ! isNaN ( x ) ) {
113
+ } else if ( isDateTime ( x ) ) {
114
+ x = new Date ( x . toString ( ) ) ;
106
115
data [ index ] . data . push ( { x, y } )
107
116
}
117
+ else data [ index ] . data . push ( { x, y } )
108
118
}
109
119
} )
110
120
} )
@@ -124,13 +134,20 @@ const NeoLineChart = (props: ChartProps) => {
124
134
125
135
// TODO - Nivo has a bug that, when we switch from a time-axis to a number axis, the visualization breaks.
126
136
// Therefore, we now require a manual refresh.
127
- const chartIsTimeChart = ( data [ 0 ] !== undefined && data [ 0 ] . data [ 0 ] !== undefined && data [ 0 ] . data [ 0 ] [ 'x' ] !== undefined && isNaN ( data [ 0 ] . data [ 0 ] [ 'x' ] ) ) ;
137
+
138
+
139
+ const chartIsTimeChart = ( data [ 0 ] !== undefined && data [ 0 ] . data [ 0 ] !== undefined && data [ 0 ] . data [ 0 ] [ 'x' ] !== undefined && isDateTimeOrDate ( data [ 0 ] . data [ 0 ] [ 'x' ] ) ) ;
140
+
128
141
if ( isTimeChart !== chartIsTimeChart ) {
129
142
if ( ! chartIsTimeChart ) {
130
143
return < div style = { { margin : "15px" } } >
131
144
Line chart switched from time-axis to number-axis.
132
145
Please re-run the report to see your changes. </ div > ;
133
146
}
147
+
148
+ let p = chartIsTimeChart ? ( isDateTime ( data [ 0 ] . data [ 0 ] [ 'x' ] ) ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%d" ) : "" ;
149
+
150
+ setParseFormat ( p ) ;
134
151
setIsTimeChart ( chartIsTimeChart ) ;
135
152
}
136
153
@@ -151,12 +168,13 @@ const NeoLineChart = (props: ChartProps) => {
151
168
return < code style = { { margin : "10px" } } > Invalid tick size specification for time chart. Parameter value must be set to "every [number] ['years', 'months', 'weeks', 'days', 'hours', 'seconds', 'milliseconds']".</ code > ;
152
169
}
153
170
154
-
171
+ //T18:40:32.142+0100
172
+ //%Y-%m-%dT%H:%M:%SZ
155
173
const lineViz = < div className = "h-full w-full overflow-hidden" style = { { height : "100%" } } >
156
174
< ResponsiveLine
157
175
data = { data }
158
176
xScale = { isTimeChart ?
159
- { format : "%Y-%m-%dT%H:%M:%SZ" , type : "time" } :
177
+ { format : parseFormat , type : "time" } :
160
178
xScale == 'linear' ?
161
179
{ type : xScale , min : minXValue , max : maxXValue , stacked : false , reverse : false } :
162
180
{ type : xScale , min : minXValue , max : maxXValue , constant : xScaleLogBase , base : xScaleLogBase }
0 commit comments