Add scrolled pixel count for telemetry console

TODO: fix the pixel-line number thing
This commit is contained in:
Shreya 2020-03-13 01:20:33 +05:30
parent de554bfa0b
commit d2c315b93f
2 changed files with 21 additions and 4 deletions

View File

@ -20,6 +20,8 @@ class MapPageComponent extends AuthComponent {
telemetry: [], telemetry: [],
telemetryLastTimestamp: null, telemetryLastTimestamp: null,
isScrolledUp: false, isScrolledUp: false,
telemetryLines: 0,
telemetryCurrentLine: 0,
}; };
this.telemConsole = React.createRef(); this.telemConsole = React.createRef();
this.handleScroll = this.handleScroll.bind(this); this.handleScroll = this.handleScroll.bind(this);
@ -64,15 +66,16 @@ class MapPageComponent extends AuthComponent {
.then(res => { .then(res => {
if ('telemetries' in res) { if ('telemetries' in res) {
let newTelem = this.state.telemetry.concat(res['telemetries']); let newTelem = this.state.telemetry.concat(res['telemetries']);
let telemConsoleRef = this.telemConsole.current;
this.setState( this.setState(
{ {
telemetry: newTelem, telemetry: newTelem,
telemetryLastTimestamp: res['timestamp'] telemetryLastTimestamp: res['timestamp'],
telemetryLines: telemConsoleRef.scrollHeight,
}); });
this.props.onStatusChange(); this.props.onStatusChange();
let telemConsoleRef = this.telemConsole.current;
if (!this.state.isScrolledUp) { if (!this.state.isScrolledUp) {
telemConsoleRef.scrollTop = telemConsoleRef.scrollHeight - telemConsoleRef.clientHeight; telemConsoleRef.scrollTop = telemConsoleRef.scrollHeight - telemConsoleRef.clientHeight;
this.scrollTop = telemConsoleRef.scrollTop; this.scrollTop = telemConsoleRef.scrollTop;
@ -151,9 +154,9 @@ class MapPageComponent extends AuthComponent {
handleScroll(e) { handleScroll(e) {
let element = e.target; let element = e.target;
if (element.scrollTop < this.scrollTop) { if (element.scrollTop < this.scrollTop) {
this.setState({isScrolledUp: true}); this.setState({isScrolledUp: true, telemetryCurrentLine: element.scrollTop});
} else { } else {
this.setState({isScrolledUp: false}); this.setState({isScrolledUp: false, telemetryCurrentLine: element.scrollTop});
} }
} }
@ -167,6 +170,14 @@ class MapPageComponent extends AuthComponent {
); );
} }
renderTelemetryLineCount() {
return (
<div className="telemetry-lines">
<b>[{this.state.telemetryCurrentLine}/{this.state.telemetryLines}]</b>
</div>
);
}
render() { render() {
return ( return (
<div> <div>
@ -189,6 +200,7 @@ class MapPageComponent extends AuthComponent {
<div style={{height: '80vh'}}> <div style={{height: '80vh'}}>
<ReactiveGraph graph={this.state.graph} options={options} events={this.events}/> <ReactiveGraph graph={this.state.graph} options={options} events={this.events}/>
</div> </div>
{this.renderTelemetryLineCount()}
</Col> </Col>
<Col xs={4}> <Col xs={4}>
<input className="form-control input-block" <input className="form-control input-block"

View File

@ -324,6 +324,11 @@ body {
font-weight: bold; font-weight: bold;
} }
.telemetry-lines {
position: absolute;
right: 0;
}
.map-legend { .map-legend {
font-size: 18px; font-size: 18px;
} }