news-chart.html 6.69 KB
Newer Older
Alberto Pascual's avatar
Alberto Pascual committed
1
2
3
<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">
4
5
<link rel="import" href="/bower_components/iron-collapse/iron-collapse.html">

Alberto Pascual's avatar
Alberto Pascual committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19

<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"> 
Alberto Pascual's avatar
Alberto Pascual committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
          <div class$="tweet {{checkSentiment(news.sentiments)}} same-height" style="border: 2px dashed rgba(96, 125, 139, .5); text-align: center;">
            <div class="row"><div class="col-md-7 headline">
              <div class="col-md-4">
                <img src="{{news.schema:thumbnailUrl}}" style="width: 100%; display:inline-block; left: 0%; position: relative; ">
              </div>
              <div class="col-md-8">
                <span style="font-weight: bold; font-size:30px; display:inline-block; vertical-align: middle;">{{news.schema:headline}}</span>
              </div>
            </div>
            <div class="col-md-1 see-more">
              <img src={{checkSource(news.schema:author)}} style="width: 100%; display:block; position: relative;" align="left">
            </div>
            <div class="col-md-2 emotion-box">
            <img src={{checkEmotion(news.emotions)}} style="width: 30%; margin: 0 auto; display: block; position:relative;" data-toggle="tooltip" data-placement="top" title="{{getemotion(news.emotions)}}">
            <p class$="emotion {{getemotion(news.emotions)}}">Emotion: {{getemotion(news.emotions)}}</p></br>
            </div>
            
            <div class="see-more col-md-2">
38
            <button class="btn btn-primary" ident$="subitem[[index]]" on-click="toggle" aria-expanded$="[[opened]]" aria-controls="collapse">{{buttontext}}<iron-icon icon="expand-more"></iron-icon></button>
Alberto Pascual's avatar
Alberto Pascual committed
39
40
41
            </div>
            </div>

42
            <iron-collapse ident$="subitem[[index]]">
43
              <div class="content" style="text-align:justify; width: 94%; margin: 0 auto;">
44
45
46
47
48
                <br>
                <template is="dom-repeat" items="{{news.sentiments}}" as="sentiment"> 
                <span class$="{{checkSpanSentiment(sentiment.marl:hasPolarity)}}">{{sentiment.nif:anchorOf}}</span>
              </div>
            </iron-collapse>
Alberto Pascual's avatar
Alberto Pascual committed
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
            </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"
        },
80
81
82
83
        buttontext:{
          type: String,
          value : "See more"
        },
Alberto Pascual's avatar
Alberto Pascual committed
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

        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() {   

      },
136
137
138
139
140
141
142
143
144
145
      toggle: function(event) {
        var id = event.currentTarget.getAttribute('ident');
        var collapse = this.$$('iron-collapse[ident="' + id + '"]');
        var button = this.$$('button[ident="' + id + '"]');
        if (button.innerHTML.indexOf("expand-more") > -1) button.innerHTML = 'See less <iron-icon icon="expand-less"></iron-icon>'
        else button.innerHTML = 'See more <iron-icon icon="expand-more"></iron-icon>'
        //console.log(collapse)
        //console.log("id: "+id+" collapse: "+ collapse.getAttribute('ident'))
        collapse.toggle();
      },
Alberto Pascual's avatar
Alberto Pascual committed
146
147
148
149
150
151
152
153
154
155
156
157

      _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) {
Alberto Pascual's avatar
Alberto Pascual committed
158
159
160
161
162
        console.log(sentiment[0]['marl:hasPolarity'])
        if (sentiment[0]['marl:hasPolarity'] == "marl:Positive")
          return "tweet positive-news"
        else if (sentiment[0]['marl:hasPolarity'] == "marl:Negative")
          return "tweet negative-news"
Alberto Pascual's avatar
Alberto Pascual committed
163
        else 
Alberto Pascual's avatar
Alberto Pascual committed
164
          return "tweet neutral-news"
Alberto Pascual's avatar
Alberto Pascual committed
165
      },
166
      getemotion: function(emotion) {
Alberto Pascual's avatar
Alberto Pascual committed
167
168
        //console.log(emotion)
        return emotion[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].split(':')[1]
169
      },
Alberto Pascual's avatar
Alberto Pascual committed
170
      checkSpanSentiment: function(sentiment) {
171
        //console.log(sentiment)
Alberto Pascual's avatar
Alberto Pascual committed
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        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>