Created
July 14, 2015 19:22
-
-
Save coffeejay/ea5cf8e8c3dcd09e58f6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Chart will take a metric and list | |
| // and generate a chart | |
| window.Chart = React.createClass({ | |
| getDefaultProps: function() { | |
| return { | |
| metric: '', | |
| initialList: null, | |
| url: '', | |
| id: '' | |
| } | |
| }, | |
| getInitialState: function() { | |
| return { | |
| active: GlobalStore.getState().activeList || this.props.initialList, | |
| data: [] | |
| } | |
| }, | |
| componentDidMount: function() { | |
| GlobalStore.listen(this.onChange); | |
| this.fetchData(); | |
| }, | |
| componentWillUnmount: function() { | |
| GlobalStore.unlisten(this.onChange) | |
| }, | |
| onChange: function(state) { | |
| this.setState(state); | |
| this.fetchData(); | |
| }, | |
| fetchData: function() { | |
| component = this | |
| data = {user_id: this.props.user_id, | |
| list_name: GlobalStore.getState().activeList, | |
| metrics: "id, subject, " + this.props.metric}; | |
| $.get(this.props.url, data) | |
| .done(function(response) { | |
| mapped = response.data.map(function(val, index, arr) { | |
| return [index, val[2]] | |
| }); | |
| component.setState({data: mapped}) | |
| }) | |
| }, | |
| render: function() { | |
| return ( | |
| <div className="ibox float-e-margins"> | |
| <div className="ibox-title"> | |
| <h5>{this.props.title} for the last 60 days</h5> | |
| </div> | |
| <div className="ibox-content"> | |
| <FlotBar data={this.state.data} id={this.props.id} key={this.props.metric} /> | |
| </div> | |
| <div className="ibox-footer"> | |
| <a data-toggle="modal" data-target="#myModal"><u>Capp notes #3</u></a> is your top performing campaign over the last 60 days. | |
| </div> | |
| </div> | |
| ) | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment