Skip to content

Commit 7ed9877

Browse files
committed
Improve guiding graph: height & remember pos
1 parent 3db0521 commit 7ed9877

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

ui/src/PhdGraph.tsx

+55-12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import * as ChartJSZoomPlugin from "./utils/ChartJSZoomPlugin";
99
import moment from 'moment';
1010

1111
import Log from './shared/Log';
12+
import * as Obj from './shared/Obj';
1213
import * as Store from "./Store";
1314
import * as BackendRequest from "./BackendRequest";
15+
import * as GenericUiStore from './GenericUiStore';
1416
import './PhdView.css';
1517
import { PhdStatus } from '@bo/BackOfficeStatus';
1618
import CancellationToken from 'cancellationtoken';
@@ -25,12 +27,21 @@ type Props = InputProps & MappedProps;
2527

2628
// Avoid loosing zoom
2729
type State = {
30+
height: number;
2831
track?: boolean;
2932
min?: number;
3033
max?: number;
3134
width?: number;
3235
}
3336

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+
3445
const scales = [
3546
{value:"60000" , title:"1min"},
3647
{value:"120000", title:"2min"},
@@ -41,16 +52,33 @@ const scales = [
4152
{value:"1800000", title:"30min"},
4253
];
4354

55+
const localStorageId = 'phdGraph';
56+
4457
// Afficher l'état de phd et permet de le controller
4558
class PhdGraph extends React.PureComponent<Props, State> {
4659
pendingTimeout: NodeJS.Timeout|null;
60+
savedState : State;
61+
4762

4863
constructor(props:Props) {
4964
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+
5171
this.pendingTimeout = null;
5272
}
5373

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+
5482
startGuide = async ()=> {
5583
await BackendRequest.RootInvoker("phd")("startGuide")(CancellationToken.CONTINUE, {});
5684
}
@@ -63,6 +91,15 @@ class PhdGraph extends React.PureComponent<Props, State> {
6391
this.handleZoom({chart});
6492
}
6593

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+
66103
updateZoom = (e:React.ChangeEvent<HTMLSelectElement>) => {
67104
const v = e.target.value;
68105
if (this.pendingTimeout !== null) {
@@ -103,8 +140,6 @@ class PhdGraph extends React.PureComponent<Props, State> {
103140
}
104141
this.pendingTimeout = setTimeout(()=> {
105142
const {minMoment, maxMoment} = this.getTimeRange();;
106-
107-
108143
logger.debug('current min, max', {minMoment, maxMoment, delta: maxMoment! - minMoment!});
109144
logger.debug('zoomed min, max', {newMin, newMax, delta: newMax - newMin});
110145
if (newMax === newMin) {
@@ -119,12 +154,15 @@ class PhdGraph extends React.PureComponent<Props, State> {
119154
this.setState({
120155
track: true,
121156
width: newMax - newMin,
157+
min: undefined,
158+
max: undefined,
122159
});
123160
} else {
124161
this.setState({
125162
track: false,
126163
min: chart.scales['time'].min,
127164
max: chart.scales['time'].max,
165+
width: undefined,
128166
});
129167
}
130168

@@ -287,8 +325,8 @@ class PhdGraph extends React.PureComponent<Props, State> {
287325
type: 'linear',
288326
ticks: {
289327
beginAtZero: true,
290-
min: -1.0,
291-
max: 1.0
328+
min: -this.state.height,
329+
max: this.state.height
292330
}
293331
},
294332
{
@@ -364,13 +402,18 @@ class PhdGraph extends React.PureComponent<Props, State> {
364402
<div className="PhdGraph_Container">
365403
<ReactChartJS.Line data={chartData} options={chartOptions} plugins={ChartJSZoomPlugin.plugins()}/>
366404
</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>
374417
</div>);
375418
}
376419

ui/src/PhdView.css

+10-1
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ table.RADECTable tr td:first-child{
5252
height: 100%;
5353
}
5454

55-
.PhdRangeSelector {
55+
.PhdControlBlock {
56+
display: block;
57+
position: absolute;
5658
display: block;
5759
position: absolute;
5860
bottom: 0px;
5961
right: 0px;
6062
padding: 0px;
63+
}
64+
65+
.PhdRangeSelector {
66+
font-size: 0.6em;
67+
}
68+
69+
.PhdHeightSelector {
6170
font-size: 0.6em;
6271
}
6372

0 commit comments

Comments
 (0)