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