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