mt-polygon-simplification/benchmarking/src/index.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-07-14 20:37:26 +02:00
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { Form } from './components/form.js'
2019-08-04 22:45:39 +02:00
import { DebouncedChart, Chart } from './components/chart.js'
import { BenchmarkRunner } from './components/runner.js'
2019-07-14 20:37:26 +02:00
2019-08-04 22:45:39 +02:00
import { simplifyMapper } from './simplifyMapper.js'
2019-07-19 15:15:05 +02:00
2019-07-14 20:37:26 +02:00
class App extends Component {
constructor(props) {
super(props)
2019-08-04 22:45:39 +02:00
this.handleFormChange = this.handleFormChange.bind(this)
this.handleStatsChange = this.handleStatsChange.bind(this)
2019-07-14 20:37:26 +02:00
this.state = {
stats: {},
2019-08-04 22:45:39 +02:00
formState: {},
nodeData: []
2019-07-14 20:37:26 +02:00
}
}
2019-08-04 22:45:39 +02:00
async handleFormChange(formState) {
2019-07-19 15:15:05 +02:00
this.setState({
2019-08-04 22:45:39 +02:00
formState,
nodeData: await simplifyMapper(formState),
stats: {}
2019-07-19 15:15:05 +02:00
})
2019-07-14 20:37:26 +02:00
}
2019-08-04 22:45:39 +02:00
handleStatsChange(stats) {
this.setState({ stats })
2019-07-14 20:37:26 +02:00
}
render() {
2019-08-04 22:45:39 +02:00
let ChartComponent = this.state.formState.debouncedChart
? DebouncedChart
: Chart
2019-07-14 20:37:26 +02:00
return (
2019-07-19 15:15:05 +02:00
<>
2019-08-04 22:45:39 +02:00
<Form onFormChange={this.handleFormChange} />
<BenchmarkRunner
formState={this.state.formState}
onStatsChange={this.handleStatsChange}
2019-07-14 20:37:26 +02:00
/>
2019-08-04 22:45:39 +02:00
<ChartComponent
formState={this.state.formState}
stats={this.state.stats}
nodeData={this.state.nodeData}
2019-07-14 20:37:26 +02:00
/>
2019-07-19 15:15:05 +02:00
</>
2019-07-14 20:37:26 +02:00
)
}
}
ReactDOM.render(<App />, document.getElementsByTagName('main')[0])