news-chart.html 4.55 KB
Newer Older
Alberto Pascual's avatar
Alberto Pascual committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/iron-icons/iron-icons.html">
<link rel="import" href="/bower_components/paper-dialog/paper-dialog.html">

<dom-module id="news-chart">

<link rel="import" type="css" href="tweet-chart.css">

  <template>

    <!-- Shadow DOM -->
    <paper-material elevation="1">
        <div class="top-bar">
            <iron-icon icon="{{icon}}"></iron-icon>
            <span>{{title}}</span>
        </div>
        <template is="dom-repeat" items="{{data}}" as="news"> 
          <div class="tweet same-height" style="background: rgba(204, 207, 208, 0.5); border: 2px dashed rgba(96, 125, 139, .5);">
            <span style="font-weight: bold; font-size:20px; text-align:center; margin: 0 auto; display:block;">{{news.headline}}</span></br>
            <img src={{checkSource(news.creator)}} style="width: 10%; display:block;" data-tooltip="I’m the tooltip text.">
            <img src={{checkEmotion(news.emotions)}} style="width: 3%; margin: 0 auto; display:block; float:right;">
            </br>
            <template is="dom-repeat" items="{{news.sentiments}}" as="sentiment"> 
              <span class$="{{checkSpanSentiment(sentiment.marl:hasPolarity)}}">{{sentiment.nif:anchorOf}}</span>
            </template>
          </div>
        </template>
        <div style="width:100%; clear: both"></div>
    </paper-material>

  </template>

  <script>
    var filtered = false;

    Polymer({

      is: 'news-chart',

      properties: {

        data: {
            type: Array,
            value: [] //default value for data array.
        },

        icon: {
          type: String,
          value: "face"
        },

        title: {
          type: String,
          value: "List of different tweets"
        },

        brand: {
          type: String,
          value: "Undefined"
        },

        query: {
          type: String,
          observer: '_queryChanged'
        },

        index: {
          type: String
        },

        subindex: {
          type: String
        },

        fields: {
          type: Array,
          value: function() { return []; }
        },

        datos:{
          type: Object,
          observer: '_dataChanged'
        },

        field: {
          type: String
        },

        host: {
          type: String
        },

        param: {
          type: String,
          notify: true
        },

        filters: {
          type: Array,
          notify: true,
          value: function() { return []; }
        }
      },

      ready: function() {   

      },

      _dataChanged: function() {
        var that = this
        var hits = this.datos.hits.hits;
        var results = []
        hits.forEach(function(entry) {
            results.push(entry._source);
        });
        that.data = results
      },

      checkSentiment: function(sentiment) {
        console.log(sentiment)
        if (sentiment == "marl:Positive")
          return "tweet positive"
        else if (sentiment == "marl:Negative")
          return "tweet negative"
        else 
          return "tweet neutral"
      },
      checkSpanSentiment: function(sentiment) {
        console.log(sentiment)
        if (sentiment == "marl:Positive")
          return "span positive"
        else if (sentiment == "marl:Negative")
          return "span negative"
        else 
          return "span neutral"
      },

      checkSource: function(source) {
        if(source.indexOf("CNN") > -1 || source.indexOf("cnn") > -1 )
          return "/images/cnn.png"
        else if(source.indexOf("Times") > -1)
          return "/images/times.png"
        else 
          return ""
      },
      checkEmotion: function(source) {
        if(source[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].indexOf("anger") > -1)
          return "/images/emotion/anger.png"
        else if(source[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].indexOf("disgust") > -1)
          return "/images/emotion/disgust.png"
        else if(source[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].indexOf("fear") > -1)
          return "/images/emotion/fear.png"
        else if(source[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].indexOf("joy") > -1)
          return "/images/emotion/joy.png"
        else if(source[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].indexOf("neutral") > -1)
          return "/images/emotion/neutral.png"
        else if(source[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].indexOf("sadness") > -1)
          return "/images/emotion/sadness.png"
      }

    });
  </script>

</dom-module>