-
-
Save danderson00/06b969834d8203791e16efddc9464bdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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