@@ -9,8 +9,10 @@ import * as ChartJSZoomPlugin from "./utils/ChartJSZoomPlugin";
9
9
import moment from 'moment' ;
10
10
11
11
import Log from './shared/Log' ;
12
+ import * as Obj from './shared/Obj' ;
12
13
import * as Store from "./Store" ;
13
14
import * as BackendRequest from "./BackendRequest" ;
15
+ import * as GenericUiStore from './GenericUiStore' ;
14
16
import './PhdView.css' ;
15
17
import { PhdStatus } from '@bo/BackOfficeStatus' ;
16
18
import CancellationToken from 'cancellationtoken' ;
@@ -25,12 +27,21 @@ type Props = InputProps & MappedProps;
25
27
26
28
// Avoid loosing zoom
27
29
type State = {
30
+ height : number ;
28
31
track ?: boolean ;
29
32
min ?: number ;
30
33
max ?: number ;
31
34
width ?: number ;
32
35
}
33
36
37
+ const arcSecs = [
38
+ { value :"1" , title :'±1"' } ,
39
+ { value :"2" , title :'±2"' } ,
40
+ { value :"4" , title :'±4"' } ,
41
+ { value :"8" , title :'±8"' } ,
42
+ { value :"16" , title :'±16"' } ,
43
+ ] ;
44
+
34
45
const scales = [
35
46
{ value :"60000" , title :"1min" } ,
36
47
{ value :"120000" , title :"2min" } ,
@@ -41,16 +52,33 @@ const scales = [
41
52
{ value :"1800000" , title :"30min" } ,
42
53
] ;
43
54
55
+ const localStorageId = 'phdGraph' ;
56
+
44
57
// Afficher l'état de phd et permet de le controller
45
58
class PhdGraph extends React . PureComponent < Props , State > {
46
59
pendingTimeout : NodeJS . Timeout | null ;
60
+ savedState : State ;
61
+
47
62
48
63
constructor ( props :Props ) {
49
64
super ( props ) ;
50
- this . state = { }
65
+ this . state = { ...GenericUiStore . initComponentState < State > (
66
+ "localStorageId" ,
67
+ ( t :State | undefined ) => ( { height : 1 , ...t } ) )
68
+ } ;
69
+ this . savedState = { ...this . state } ;
70
+
51
71
this . pendingTimeout = null ;
52
72
}
53
73
74
+ componentDidUpdate = ( ) => {
75
+ if ( this . state . track ) {
76
+ if ( ! Obj . deepEqual ( this . state , this . savedState ) ) {
77
+ GenericUiStore . updateComponentState ( "localStorageId" , { ...this . state } ) ;
78
+ }
79
+ }
80
+ }
81
+
54
82
startGuide = async ( ) => {
55
83
await BackendRequest . RootInvoker ( "phd" ) ( "startGuide" ) ( CancellationToken . CONTINUE , { } ) ;
56
84
}
@@ -63,6 +91,15 @@ class PhdGraph extends React.PureComponent<Props, State> {
63
91
this . handleZoom ( { chart} ) ;
64
92
}
65
93
94
+ updateHeight = ( e :React . ChangeEvent < HTMLSelectElement > ) => {
95
+ const v = parseFloat ( e . target . value ) ;
96
+ if ( this . pendingTimeout !== null ) {
97
+ clearTimeout ( this . pendingTimeout ) ;
98
+ this . pendingTimeout = null ;
99
+ }
100
+ this . setState ( { height : v } ) ;
101
+ }
102
+
66
103
updateZoom = ( e :React . ChangeEvent < HTMLSelectElement > ) => {
67
104
const v = e . target . value ;
68
105
if ( this . pendingTimeout !== null ) {
@@ -103,8 +140,6 @@ class PhdGraph extends React.PureComponent<Props, State> {
103
140
}
104
141
this . pendingTimeout = setTimeout ( ( ) => {
105
142
const { minMoment, maxMoment} = this . getTimeRange ( ) ; ;
106
-
107
-
108
143
logger . debug ( 'current min, max' , { minMoment, maxMoment, delta : maxMoment ! - minMoment ! } ) ;
109
144
logger . debug ( 'zoomed min, max' , { newMin, newMax, delta : newMax - newMin } ) ;
110
145
if ( newMax === newMin ) {
@@ -119,12 +154,15 @@ class PhdGraph extends React.PureComponent<Props, State> {
119
154
this . setState ( {
120
155
track : true ,
121
156
width : newMax - newMin ,
157
+ min : undefined ,
158
+ max : undefined ,
122
159
} ) ;
123
160
} else {
124
161
this . setState ( {
125
162
track : false ,
126
163
min : chart . scales [ 'time' ] . min ,
127
164
max : chart . scales [ 'time' ] . max ,
165
+ width : undefined ,
128
166
} ) ;
129
167
}
130
168
@@ -287,8 +325,8 @@ class PhdGraph extends React.PureComponent<Props, State> {
287
325
type : 'linear' ,
288
326
ticks : {
289
327
beginAtZero : true ,
290
- min : - 1.0 ,
291
- max : 1.0
328
+ min : - this . state . height ,
329
+ max : this . state . height
292
330
}
293
331
} ,
294
332
{
@@ -364,13 +402,18 @@ class PhdGraph extends React.PureComponent<Props, State> {
364
402
< div className = "PhdGraph_Container" >
365
403
< ReactChartJS . Line data = { chartData } options = { chartOptions } plugins = { ChartJSZoomPlugin . plugins ( ) } />
366
404
</ div >
367
- < select value = { currentZoom } onChange = { this . updateZoom } className = "PhdRangeSelector" >
368
- { scales . map ( e => < option key = { e . value } value = { e . value } > { e . title } </ option > ) }
369
- < option value = "full" > full</ option >
370
- { currentZoom === ''
371
- ? < option value = "" > custom</ option >
372
- : null }
373
- </ select >
405
+ < div className = "PhdControlBlock" >
406
+ < select value = { this . state . height } onChange = { this . updateHeight } className = "PhdHeightSelector" >
407
+ { arcSecs . map ( e => < option key = { e . value } value = { "" + e . value } > { e . title } </ option > ) }
408
+ </ select >
409
+ < select value = { currentZoom } onChange = { this . updateZoom } className = "PhdRangeSelector" >
410
+ { scales . map ( e => < option key = { e . value } value = { e . value } > { e . title } </ option > ) }
411
+ < option value = "full" > full</ option >
412
+ { currentZoom === ''
413
+ ? < option value = "" > { this . state . width ? ( this . state . width / 1000 ) . toFixed ( 1 ) + "s" : "custom" } </ option >
414
+ : null }
415
+ </ select >
416
+ </ div >
374
417
</ div > ) ;
375
418
}
376
419
0 commit comments