src/js/widgets/polemicWidget.js
author hamidouk
Tue, 08 Nov 2011 10:38:29 +0100
branchpopcorn-port
changeset 207 2bc276f0c1ae
parent 203 9b76fc6564b1
child 231 accc7358d8b5
permissions -rw-r--r--
converted tabs to spaces.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
     1
/* 
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     2
 *   
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     3
 *  Copyright 2010 Institut de recherche et d'innovation 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     4
 *  contributor(s) : Samuel Huron 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     5
 *   
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     6
 *  contact@iri.centrepompidou.fr
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     7
 *  http://www.iri.centrepompidou.fr 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     8
 *   
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
     9
 *  This software is a computer program whose purpose is to show and add annotations on a video .
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    10
 *  This software is governed by the CeCILL-C license under French law and
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    11
 *  abiding by the rules of distribution of free software. You can  use, 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    12
 *  modify and/ or redistribute the software under the terms of the CeCILL-C
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    13
 *  license as circulated by CEA, CNRS and INRIA at the following URL
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    14
 *  "http://www.cecill.info". 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    15
 *  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    16
 *  The fact that you are presently reading this means that you have had
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    17
 *  knowledge of the CeCILL-C license and that you accept its terms.
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    18
*/
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    19
// CHART TIMELINE / VERSION PROTOTYPE  ::
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    20
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    21
IriSP.PolemicWidget = function(Popcorn, config, Serializer) {
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    22
  IriSP.Widget.call(this, Popcorn, config, Serializer);
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    23
 
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    24
  this.userPol    = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    25
  this.userNoPol  = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    26
  this.userst      = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    27
  this.numberOfTweet = 0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    28
  this.Users;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    29
  this.TweetPolemic;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    30
  this.yMax        = this.height; 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    31
  this.PaperSlider;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    32
  this.heightOfChart;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    33
  this.tweets  = new Array();
196
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 195
diff changeset
    34
  this.svgElements = new Array();
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    35
  
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    36
  // Make and define the Raphael area
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    37
  this.paper = Raphael(document.getElementById(this._id), config.width, config.height);
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    38
  
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    39
};
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    40
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    41
IriSP.PolemicWidget.prototype = new IriSP.Widget();
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    42
  
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
    43
IriSP.PolemicWidget.prototype.draw = function() {
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    44
  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    45
    // variable 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    46
    // yMax
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
    47
    
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
    48
    var self = this;
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    49
    var yCoef        = 2;             // coef for height of 1 tweet 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    50
    var frameSize     = 5;             // frame size 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    51
    var margin         = 1;            // marge between frame
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    52
    var lineSize      = this.width;        // timeline pixel width 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    53
    var nbrframes     = lineSize/frameSize;     // frame numbers
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    54
    var numberOfTweet   = 0;            // number of tweet overide later 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    55
    var duration      = +this._serializer.currentMedia().meta["dc:duration"];      // timescale width 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    56
    var frameLength   = lineSize / frameSize;    // frame timescale  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    57
    var timeline;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    58
    var colors  = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858");
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    59
    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    60
    // array 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    61
    //var tweets  = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    62
    var element = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    63
    var cluster = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    64
    var frames  = new Array(frameLength);
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    65
    var slices  = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    66
    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    67
    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    68
    // Classes =======================================================================
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    69
    var Frames = function(){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    70
      
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    71
      var Myclusters;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    72
      var x;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    73
      var y;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    74
      var width;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    75
      var height;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    76
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    77
    Frames = function(json){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    78
      // make my clusters
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    79
      // ou Frame vide 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    80
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    81
    Frames.prototype.draw = function(){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    82
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    83
    Frames.prototype.zoom = function(){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    84
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    85
    Frames.prototype.inside = function(){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    86
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    87
    var Clusters = function(){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    88
      var Object;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    89
      var yDist;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    90
      var x;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    91
      var y;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    92
      var width;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    93
      var height;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    94
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    95
    Clusters = function(json){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    96
      // make my object
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    97
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    98
    var Tweet = function(){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
    99
    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   100
    // Classes =======================================================================
187
6f1def85018a removed useless printfs.
hamidouk
parents: 176
diff changeset
   101
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   102
    // Refactoring (parametere) ************************************************************
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   103
    // color translastion
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   104
    var qTweet_0  =0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   105
    var qTweet_Q  =0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   106
    var qTweet_REF=0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   107
    var qTweet_OK =0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   108
    var qTweet_KO =0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   109
    function colorTranslation(value){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   110
      if(value == "Q"){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   111
        qTweet_Q+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   112
        return 2;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   113
      }else if(value =="REF"){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   114
        qTweet_REF+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   115
        return 4;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   116
      }else if(value =="OK"){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   117
        qTweet_OK+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   118
        return 1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   119
      }else if(value =="KO"){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   120
        qTweet_KO+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   121
        return 3;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   122
      }else if(value ==""){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   123
        qTweet_0+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   124
        return 5;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   125
      }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   126
    }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   127
    
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   128
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   129
      this._serializer.sync(function(data) { loaded_callback.call(self, data) });
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   130
      
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   131
      function loaded_callback (json) {
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   132
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   133
        // get current view (the first ???)
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   134
        view = json.views[0];
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   135
        
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   136
        // the tweets are by definition of the second annotation type FIXME ?
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   137
        tweet_annot_type = null;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   138
        if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   139
          tweet_annot_type = view.annotation_types[1];
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   140
        }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   141
      
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   142
      for(var i = 0; i < json.annotations.length; i++) {
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   143
        var item = json.annotations[i];              
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   144
        var MyTime  = Math.floor(item.begin/duration*lineSize);
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   145
        var Myframe = Math.floor(MyTime/lineSize*frameLength);
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   146
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   147
        if (typeof(item.meta) !== "undefined" 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   148
          && typeof(item.meta["id-ref"]) !== "undefined"
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   149
          && item.meta["id-ref"] === tweet_annot_type) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   150
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   151
          var MyTJson = JSON.parse(item.meta['dc:source']['content']);
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   152
          
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   153
            if (item.content['polemics'] != undefined 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   154
            && item.content['polemics'][0] != null) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   155
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   156
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   157
              for(var j=0; j<item.content['polemics'].length; j++){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   158
                  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   159
                  this.tweets[numberOfTweet] = {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   160
                        id:i,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   161
                        qualification:colorTranslation(item.content['polemics'][j]),
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   162
                        yIndicator:MyTime,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   163
                        yframe:Myframe,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   164
                        title:item.content['title'],
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   165
                        timeframe:item.begin,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   166
                        userId: MyTJson.id,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   167
                        userScreenName: MyTJson.screen_name,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   168
                        tsource:MyTJson
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   169
                        };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   170
                  numberOfTweet+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   171
                  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   172
              }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   173
          }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   174
          else {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   175
            this.tweets[numberOfTweet] = {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   176
                  id:i,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   177
                  qualification:colorTranslation(""),
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   178
                  yIndicator:MyTime,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   179
                  yframe:Myframe,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   180
                  title:item.content['title'],
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   181
                  timeframe:item.begin,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   182
                  userId: MyTJson.id,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   183
                  userScreenName: MyTJson.screen_name,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   184
                  tsource:MyTJson
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   185
                  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   186
            };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   187
            numberOfTweet+=1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   188
          }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   189
          
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   190
        } 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   191
      };  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   192
      
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   193
       DrawTweets.call (this); // FIXME: ugly.
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   194
       
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   195
      };      
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   196
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   197
    // tweet Drawing (in raphael) 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   198
    function DrawTweets (){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   199
    // GROUPES TWEET ============================================
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   200
    // Count nbr of cluster and tweet in a frame an save int in "frames"
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   201
      numberOfTweet = this.tweets.length;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   202
      for(var i=0; i<nbrframes; i++) {  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   203
        for(var j=0; j<numberOfTweet; j++) {  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   204
        
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   205
          if (i==this.tweets[j].yframe){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   206
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   207
            var k = this.tweets[j].qualification;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   208
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   209
            // make array for frame cluster
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   210
            if(frames[i]==undefined){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   211
              frames[i] = {id:i,
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   212
                     qualifVol:new Array(),
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   213
                     mytweetsID:new Array()
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   214
                    };
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   215
            }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   216
            // add my tweet to frame
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   217
            frames[i].mytweetsID.push(this.tweets[j]);
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   218
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   219
            // count opinion by frame
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   220
            if( frames[i].qualifVol[k] == undefined){
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   221
              frames[i].qualifVol[k] = 1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   222
            }else{
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   223
              frames[i].qualifVol[k] += 1;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   224
            }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   225
            
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   226
          }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   227
        }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   228
      }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   229
    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   230
    // GROUPES TWEET ============================================    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   231
    // max of tweet by Frame 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   232
      var max = 0; 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   233
      for(var i = 0; i < nbrframes; i++) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   234
        var moy  = 0;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   235
        for (var j = 0; j < 6; j++) {    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   236
          if (frames[i] != undefined) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   237
            if (frames[i].qualifVol[j] != undefined) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   238
              moy += frames[i].qualifVol[j];
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   239
            }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   240
          }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   241
        }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   242
        
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   243
        if (moy > max) {
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   244
          max = moy;
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   245
        }
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   246
      }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   247
    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   248
      var tweetDrawed = new Array();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   249
      var TweetHeight = 5;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   250
      
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   251
      // DRAW  TWEETS ============================================
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   252
      for(var i = 0; i < nbrframes; i++) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   253
        var addEheight = 5;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   254
        if (frames[i] != undefined){                
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   255
          // by type 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   256
          
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   257
          for (var j = 6; j > -1; j--) {
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   258
            if (frames[i].qualifVol[j] != undefined) {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   259
              // show tweet by type 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   260
              for (var k = 0; k < frames[i].mytweetsID.length; k++) {
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   261
              
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   262
                if (frames[i].mytweetsID[k].qualification == j) {                
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   263
                  var x = i * frameSize;
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   264
                  var y = this.heightmax - addEheight;
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   265
                  
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   266
                  if (this.yMax > y) {
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   267
                    this.yMax = y;
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   268
                  }
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   269
                  
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   270
                  var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */).attr({stroke:"#00","stroke-width":0.1,  fill: colors[j]});  
196
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 195
diff changeset
   271
                  this.svgElements.push(e);
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 195
diff changeset
   272
                  
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   273
                  addEheight += TweetHeight;
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   274
                  
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   275
                  e.time= frames[i].mytweetsID[k].timeframe;
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   276
                  e.title= frames[i].mytweetsID[k].title;
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   277
                  
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   278
                  e.mouseover(function(element) { return function (event) {                                             
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   279
                  
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   280
                        // event.clientX and event.clientY are to raphael what event.pageX and pageY are to jquery.
191
43a86ab7703c added color square for tooltips.
hamidouk
parents: 190
diff changeset
   281
                        self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), event.clientX - 106, event.clientY - 160);
176
c04283d7d1ef refactoring.
hamidouk
parents: 169
diff changeset
   282
                        element.displayed = true;
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   283
                  }}(e)).mouseout(function(element) { return function () {                          
195
f46fbf25e827 fixed tooltip hiding bug
hamidouk
parents: 194
diff changeset
   284
                          self.TooltipWidget.hide.call(self.TooltipWidget);
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   285
                  }}(e)).mousedown(function () {
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   286
                    self._Popcorn.currentTime(this.time/1000);
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   287
                  });
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   288
                  
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   289
                  IriSP.jQuery(e.node).attr('id', 't' + k + '');
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   290
                  IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title);
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   291
                  IriSP.jQuery(e.node).attr('begin',  frames[i].mytweetsID[k].timeframe);                  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   292
                }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   293
              }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   294
            }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   295
          }
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   296
        }
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   297
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   298
      }    
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   299
      // DRAW UI :: resize border and bgd      
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   300
      this.paperBackground = this.paper.rect(0, 0, this.width, this.heightmax).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1});  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   301
      // var PaperBorder   = this.paper.rect(0, this.yMax,this.width,1).attr({fill:"#fff",stroke: "none",opacity: 1});  
203
9b76fc6564b1 a couple visual tweaks to polemic tweet.
hamidouk
parents: 197
diff changeset
   302
      
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   303
      this.paperSlider   = this.paper.rect(0, 0, 0, this.heightmax).attr({fill:"#D4D5D5", stroke: "none", opacity: 1});
197
a793a8a0c9d2 added a rectangle tip to show where we are in the video .
hamidouk
parents: 196
diff changeset
   304
      
a793a8a0c9d2 added a rectangle tip to show where we are in the video .
hamidouk
parents: 196
diff changeset
   305
      // the small white line displayed over the slider.
203
9b76fc6564b1 a couple visual tweaks to polemic tweet.
hamidouk
parents: 197
diff changeset
   306
      this.sliderTip = this.paper.rect(0, 0, 1, this.heightmax).attr({fill:"#fc00ff", stroke: "none", opacity: 1});
197
a793a8a0c9d2 added a rectangle tip to show where we are in the video .
hamidouk
parents: 196
diff changeset
   307
      
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   308
      // decalage 
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   309
      // tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1});  
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   310
      
196
9fb4dcb0b878 "fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents: 195
diff changeset
   311
      
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   312
      this.paperSlider.toBack();
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   313
      this.paperBackground.toBack();
197
a793a8a0c9d2 added a rectangle tip to show where we are in the video .
hamidouk
parents: 196
diff changeset
   314
      this.sliderTip.toFront();
207
2bc276f0c1ae converted tabs to spaces.
hamidouk
parents: 203
diff changeset
   315
    }
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   316
    
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   317
    this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater));
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   318
}
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   319
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   320
IriSP.PolemicWidget.prototype.sliderUpdater = function() {
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   321
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   322
    var time = +this._Popcorn.currentTime();
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   323
    var duration = +this._serializer.currentMedia().meta["dc:duration"];
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   324
    
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   325
    this.paperSlider.attr("width", time * (this.width / (duration / 1000)));
197
a793a8a0c9d2 added a rectangle tip to show where we are in the video .
hamidouk
parents: 196
diff changeset
   326
        
a793a8a0c9d2 added a rectangle tip to show where we are in the video .
hamidouk
parents: 196
diff changeset
   327
    this.sliderTip.attr("x", time * (this.width / (duration / 1000)));
194
f5d86e5c4a56 some cleaning. Also added a progression indicator.
hamidouk
parents: 192
diff changeset
   328
};
169
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   329
    
427632a324d5 first import of the polemic tweet widget.
hamidouk
parents:
diff changeset
   330