2017-11-22 11:00:31 +03:00
|
|
|
import {h, render, Component} from 'preact'
|
|
|
|
import {StyleSheet, css} from 'aphrodite'
|
|
|
|
|
|
|
|
import {importFromStackprof} from './stackprof'
|
2017-11-23 12:25:25 +03:00
|
|
|
import {Profile} from './profile'
|
|
|
|
import {Flamechart, FlamechartView} from './flamechart'
|
2017-11-23 06:19:10 +03:00
|
|
|
|
|
|
|
import { request } from 'https';
|
|
|
|
|
2017-11-23 12:25:25 +03:00
|
|
|
interface ApplicaionState {
|
|
|
|
profile: Profile | null
|
|
|
|
flamechart: Flamechart | null
|
2017-11-23 06:19:10 +03:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:25:25 +03:00
|
|
|
class Application extends Component<{}, ApplicaionState> {
|
2017-11-22 11:00:31 +03:00
|
|
|
onDrop = (ev: DragEvent) => {
|
|
|
|
const reader = new FileReader
|
|
|
|
reader.addEventListener('loadend', () => {
|
2017-11-23 12:25:25 +03:00
|
|
|
const profile = importFromStackprof(reader.result)
|
|
|
|
const flamechart = new Flamechart(profile)
|
|
|
|
this.setState({profile, flamechart})
|
2017-11-22 11:00:31 +03:00
|
|
|
})
|
|
|
|
reader.readAsText(ev.dataTransfer.files.item(0))
|
|
|
|
ev.preventDefault()
|
|
|
|
}
|
|
|
|
|
|
|
|
onDragOver = (ev: DragEvent) => {
|
|
|
|
ev.preventDefault()
|
|
|
|
}
|
|
|
|
|
2017-11-28 10:43:37 +03:00
|
|
|
componentDidMount() {
|
|
|
|
window.addEventListener('resize', () => {
|
|
|
|
this.forceUpdate()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-22 11:00:31 +03:00
|
|
|
render() {
|
2017-11-23 12:25:25 +03:00
|
|
|
const {flamechart} = this.state
|
2017-11-22 11:00:31 +03:00
|
|
|
return <div onDrop={this.onDrop} onDragOver={this.onDragOver} className={css(style.root)}>
|
2017-11-28 10:43:37 +03:00
|
|
|
{flamechart &&
|
2017-12-08 07:14:06 +03:00
|
|
|
<FlamechartView flamechart={flamechart} />}
|
2017-11-22 11:00:31 +03:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const style = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
width: '100vw',
|
2017-11-23 06:19:10 +03:00
|
|
|
height: '100vh',
|
|
|
|
overflow: 'hidden'
|
2017-11-22 11:00:31 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
render(<Application />, document.body)
|