Merge pull request #565 from shreyamalviya/auto-scroll-telemetry-console

Autoscroll to last line in telemetry console
This commit is contained in:
Shay Nehmad 2020-03-18 14:31:13 +02:00 committed by GitHub
commit 10767390a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 3 deletions

View File

@ -18,8 +18,14 @@ class MapPageComponent extends AuthComponent {
killPressed: false, killPressed: false,
showKillDialog: false, showKillDialog: false,
telemetry: [], telemetry: [],
telemetryLastTimestamp: null telemetryLastTimestamp: null,
isScrolledUp: false,
telemetryLines: 0,
telemetryCurrentLine: 0
}; };
this.telemConsole = React.createRef();
this.handleScroll = this.handleScroll.bind(this);
this.scrollTop = 0;
} }
events = { events = {
@ -67,6 +73,12 @@ class MapPageComponent extends AuthComponent {
telemetryLastTimestamp: res['timestamp'] telemetryLastTimestamp: res['timestamp']
}); });
this.props.onStatusChange(); this.props.onStatusChange();
let telemConsoleRef = this.telemConsole.current;
if (!this.state.isScrolledUp) {
telemConsoleRef.scrollTop = telemConsoleRef.scrollHeight - telemConsoleRef.clientHeight;
this.scrollTop = telemConsoleRef.scrollTop;
}
} }
}); });
}; };
@ -138,9 +150,22 @@ class MapPageComponent extends AuthComponent {
); );
} }
handleScroll(e) {
let element = e.target;
let telemetryStyle = window.getComputedStyle(element);
let telemetryLineHeight = parseInt((telemetryStyle.lineHeight).replace('px', ''));
this.setState({
isScrolledUp: (element.scrollTop < this.scrollTop),
telemetryCurrentLine: Math.trunc(element.scrollTop/telemetryLineHeight)+1,
telemetryLines: Math.trunc(element.scrollHeight/telemetryLineHeight)
});
}
renderTelemetryConsole() { renderTelemetryConsole() {
return ( return (
<div className="telemetry-console"> <div className="telemetry-console" onScroll={this.handleScroll} ref={this.telemConsole}>
{ {
this.state.telemetry.map(this.renderTelemetryEntry) this.state.telemetry.map(this.renderTelemetryEntry)
} }
@ -148,6 +173,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>
@ -170,6 +203,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,17 @@ body {
font-weight: bold; font-weight: bold;
} }
.telemetry-lines {
z-index: 3;
position: absolute;
bottom: 103px;
right: 20px;
background: #000000cc;
border-radius: 5px;
padding: 1px;
color: white;
}
.map-legend { .map-legend {
font-size: 18px; font-size: 18px;
} }
@ -582,4 +593,3 @@ body {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }