Guest User

Untitled

a guest
Nov 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import ReactHighcharts from 'react-highcharts'
  3. import {connect} from 'react-redux'
  4. import autobind from 'react-autobind'
  5. import '../style.scss'
  6. import axios from 'axios';
  7. import { handleKeywordTweets } from '../actions'
  8. import { store } from '../../../app.jsx'
  9. require('highcharts/modules/wordcloud.js')(ReactHighcharts.Highcharts)
  10.  
  11. class WordCloud extends Component {
  12. constructor(props) {
  13. super(props);
  14. autobind(this);
  15. }
  16.  
  17. render() {
  18. const { keywords } = this.props
  19. console.log(keywords);
  20. let words = []
  21. keywords.map(data => {
  22. let obj = {}
  23. obj.name = data.word
  24. if(data.count < 100) {
  25. obj.weight = 5
  26. } else {
  27. obj.weight = 6
  28. }
  29. words.push(obj)
  30. })
  31.  
  32. let config = {
  33. chart: {
  34. type: 'column',
  35. inverted: false,
  36. height:400,
  37. marginTop:75,
  38. marginBottom: 20,
  39. borderRadius: 8,
  40. backgroundColor: "#2B2E4A",
  41. },
  42. tooltip: {
  43. enabled: false
  44. },
  45. series: [{
  46. type: 'wordcloud',
  47. data: words,
  48. name: 'Occurrences',
  49.  
  50. }],
  51. title: {
  52. text: 'SENTIMENTAL WORDCLOUD',
  53. y: 40,
  54. style: {
  55. color: '#ADB0D0',
  56. fontFamily: 'Montserrat'
  57. }
  58. },
  59. plotOptions: {
  60. series: {
  61. cursor: 'pointer',
  62. events: {
  63. click: function(event) {
  64. let keyword = event.point.name
  65. axios.all([
  66. axios.get(`/api/v1/tweets/@36,-115,7z?${keyword}`),
  67. axios.get(`/api/v1/tweets/@36,-115,7z/sentiments?keyword=${keyword}`)
  68.  
  69. ])
  70. .then(axios.spread((tweets, sentiments) => {
  71. console.log(tweets);
  72. this.props.dispatch(handleKeywordTweets())
  73. console.log(sentiments);
  74. }))
  75. .catch(function(error){
  76. console.log(error);
  77. })
  78. }
  79. }
  80. }
  81. }
  82. }
  83. return (
  84. <ReactHighcharts config = {config}
  85. style={{ "min-width": "310px", "max-width": "800px", margin:" 0 auto"}}
  86. ></ReactHighcharts>
  87. );
  88. }
  89. }
  90.  
  91. const mapStateToProps = (state) => {
  92. const { keywords } = state.places
  93. return { keywords }
  94. }
  95.  
  96. export default connect(mapStateToProps)(WordCloud)
Add Comment
Please, Sign In to add comment