Skip to content

Instantly share code, notes, and snippets.

@danderson00
Created June 14, 2017 19:00
Show Gist options
  • Save danderson00/06b969834d8203791e16efddc9464bdd to your computer and use it in GitHub Desktop.
Save danderson00/06b969834d8203791e16efddc9464bdd to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import createClient from 'webpack-worker/client'
import Plotly from 'plotly.js/dist/plotly-basic.js'
export default class Graph extends Component {
componentDidMount = () => {
// create a client for our worker API, passing in the URL
// the promise resolves once initialization has finished
createClient(new Worker('/static/js/worker.bundle.js'), '/sp500hst.txt')
.then(worker => {
this.worker = worker
this.renderGraph()
})
}
renderGraph = (filter = {}) => {
this.setState({ filter })
// call our topTenMovers API function
this.worker.topTenMovers(filter)
.then(data => Plotly.newPlot(this.element, [data]))
}
// render a container for our graph and create a reference to it
render = () => <div ref={element => this.element = element}></div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment