news-chart.html 5.94 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"> 
20
21
          <div class="tweet same-height" style="border: 2px dashed rgba(96, 125, 139, .5); text-align: center;">
            <span style="font-weight: bold; font-size:30px; text-align:center; margin: 0 auto; display:block;">{{news.headline}}</span></br>
22
23
24
            <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>
            <img src={{checkSource(news.author)}} style="width: 10%; display:block; left: 3%; position: relative;">
            <img src={{checkEmotion(news.emotions)}} style="width: 3%; margin: 0 auto; display:block; float:right; position:relative; top:-65px;left: -43px;" data-toggle="tooltip" data-placement="top" title="{{getemotion(news.emotions)}}">
25
            <iron-collapse ident$="subitem[[index]]">
26
              <div class="content" style="text-align:justify; width: 94%; margin: 0 auto;">
27
28
29
30
31
                <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
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
            </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"
        },
63
64
65
66
        buttontext:{
          type: String,
          value : "See more"
        },
Alberto Pascual's avatar
Alberto Pascual committed
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

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

      },
119
120
121
122
123
124
125
126
127
128
      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
129
130
131
132
133
134
135
136
137
138
139
140

      _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) {
141
        //console.log(sentiment)
Alberto Pascual's avatar
Alberto Pascual committed
142
143
144
145
146
147
148
        if (sentiment == "marl:Positive")
          return "tweet positive"
        else if (sentiment == "marl:Negative")
          return "tweet negative"
        else 
          return "tweet neutral"
      },
149
150
151
152
      getemotion: function(emotion) {
        //console.log(sentiment)
        return emotion[0]['onyx:hasEmotion']['onyx:hasEmotionCategory'].split('#')[1]
      },
Alberto Pascual's avatar
Alberto Pascual committed
153
      checkSpanSentiment: function(sentiment) {
154
        //console.log(sentiment)
Alberto Pascual's avatar
Alberto Pascual committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        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>