Improve plot
This commit is contained in:
@@ -13,6 +13,7 @@ interface Props {
|
|||||||
items: HistoryItem[]
|
items: HistoryItem[]
|
||||||
onClick?: (index: number, element: EventTarget) => void
|
onClick?: (index: number, element: EventTarget) => void
|
||||||
classes: any
|
classes: any
|
||||||
|
contentTypeIndicator?: String
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@@ -65,6 +66,7 @@ class MessageHistory extends React.Component<Props, State> {
|
|||||||
>
|
>
|
||||||
{this.state.collapsed ? '▶' : '▼'} History
|
{this.state.collapsed ? '▶' : '▼'} History
|
||||||
</Badge>
|
</Badge>
|
||||||
|
<div style={{ float: 'right' }}>{this.state.collapsed ? this.props.contentTypeIndicator : null}</div>
|
||||||
</Typography>
|
</Typography>
|
||||||
<div style={{ maxHeight: '230px', overflowY: 'scroll' }}>
|
<div style={{ maxHeight: '230px', overflowY: 'scroll' }}>
|
||||||
{this.state.collapsed ? null : this.props.children}
|
{this.state.collapsed ? null : this.props.children}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as React from 'react'
|
|||||||
import * as q from '../../../../backend/src/Model'
|
import * as q from '../../../../backend/src/Model'
|
||||||
|
|
||||||
import { Theme, withTheme } from '@material-ui/core/styles'
|
import { Theme, withTheme } from '@material-ui/core/styles'
|
||||||
|
import BarChart from '@material-ui/icons/BarChart'
|
||||||
import DateFormatter from '../DateFormatter'
|
import DateFormatter from '../DateFormatter'
|
||||||
import History from './History'
|
import History from './History'
|
||||||
import PlotHistory from './PlotHistory'
|
import PlotHistory from './PlotHistory'
|
||||||
@@ -55,25 +55,24 @@ class MessageHistory extends React.Component<Props, State> {
|
|||||||
value: message.value,
|
value: message.value,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const numericMessages = history.filter(message => !isNaN(message.value))
|
||||||
|
const showPlot = numericMessages.length >= 2
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<History
|
<History
|
||||||
items={historyElements}
|
items={historyElements}
|
||||||
|
contentTypeIndicator={showPlot ? <BarChart /> : null}
|
||||||
onClick={this.displayMessage}
|
onClick={this.displayMessage}
|
||||||
>
|
>
|
||||||
{this.renderPlot(history)}
|
{showPlot ? this.renderPlot(history) : null}
|
||||||
</History>
|
</History>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderPlot(history: q.Message[]) {
|
public renderPlot(numericMessages: q.Message[]) {
|
||||||
const numbers = history.filter(message => !isNaN(message.value))
|
return <PlotHistory messages={numericMessages} />
|
||||||
if (numbers.length < 3) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return <PlotHistory messages={numbers} />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private displayMessage = (index: number, eventTarget: EventTarget) => {
|
private displayMessage = (index: number, eventTarget: EventTarget) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { XYPlot, XAxis, YAxis, HorizontalGridLines, LineSeries } = require('react-vis')
|
const { XYPlot, XAxis, LineMarkSeries, Hint, YAxis, HorizontalGridLines, LineSeries } = require('react-vis')
|
||||||
import { default as ReactResizeDetector } from 'react-resize-detector'
|
import { default as ReactResizeDetector } from 'react-resize-detector'
|
||||||
|
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
@@ -12,6 +12,7 @@ interface Props {
|
|||||||
|
|
||||||
interface Stats {
|
interface Stats {
|
||||||
width: number
|
width: number
|
||||||
|
value?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlotHistory extends React.Component<Props, Stats> {
|
class PlotHistory extends React.Component<Props, Stats> {
|
||||||
@@ -36,13 +37,30 @@ class PlotHistory extends React.Component<Props, Stats> {
|
|||||||
<div>
|
<div>
|
||||||
<XYPlot width={this.state.width} height={150}>
|
<XYPlot width={this.state.width} height={150}>
|
||||||
<HorizontalGridLines />
|
<HorizontalGridLines />
|
||||||
<LineSeries data={data} />
|
|
||||||
<YAxis />
|
<YAxis />
|
||||||
|
<LineMarkSeries
|
||||||
|
onValueMouseOver={this._rememberValue}
|
||||||
|
onValueMouseOut={this._forgetValue}
|
||||||
|
size={3}
|
||||||
|
data={data}
|
||||||
|
curve="curveCardinal"
|
||||||
|
/>
|
||||||
|
{this.state.value ? <Hint value={this.state.value} /> : null}
|
||||||
</XYPlot>
|
</XYPlot>
|
||||||
<ReactResizeDetector handleWidth={true} onResize={this.resize} />
|
<ReactResizeDetector handleWidth={true} onResize={this.resize} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _forgetValue = () => {
|
||||||
|
this.setState({
|
||||||
|
value: undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private _rememberValue = (value: any) => {
|
||||||
|
this.setState({ value })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withStyles({}, { withTheme: true })(PlotHistory)
|
export default withStyles({}, { withTheme: true })(PlotHistory)
|
||||||
|
|||||||
Reference in New Issue
Block a user