| author | hamidouk |
| Thu, 17 Nov 2011 16:51:19 +0100 | |
| branch | tweet-widget |
| changeset 267 | f84013fb19dc |
| parent 265 | e0d32948bf62 |
| child 357 | 6edf399cfa26 |
| 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 |
IriSP.PolemicWidget.prototype = new IriSP.Widget(); |
|
| 207 | 41 |
|
| 169 | 42 |
IriSP.PolemicWidget.prototype.draw = function() { |
| 207 | 43 |
|
44 |
// variable |
|
45 |
// yMax |
|
| 176 | 46 |
|
47 |
var self = this; |
|
| 207 | 48 |
var yCoef = 2; // coef for height of 1 tweet |
49 |
var frameSize = 5; // frame size |
|
50 |
var margin = 1; // marge between frame |
|
51 |
var lineSize = this.width; // timeline pixel width |
|
52 |
var nbrframes = lineSize/frameSize; // frame numbers |
|
53 |
var numberOfTweet = 0; // number of tweet overide later |
|
54 |
var duration = +this._serializer.currentMedia().meta["dc:duration"]; // timescale width |
|
55 |
var frameLength = lineSize / frameSize; // frame timescale |
|
56 |
var timeline; |
|
57 |
var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); |
|
58 |
|
|
59 |
// array |
|
60 |
//var tweets = new Array(); |
|
61 |
var element = new Array(); |
|
62 |
var cluster = new Array(); |
|
63 |
var frames = new Array(frameLength); |
|
64 |
var slices = new Array(); |
|
65 |
|
|
66 |
|
|
67 |
// Classes ======================================================================= |
|
68 |
var Frames = function(){ |
|
69 |
|
|
70 |
var Myclusters; |
|
71 |
var x; |
|
72 |
var y; |
|
73 |
var width; |
|
74 |
var height; |
|
75 |
}; |
|
76 |
Frames = function(json){ |
|
77 |
// make my clusters |
|
78 |
// ou Frame vide |
|
79 |
}; |
|
80 |
Frames.prototype.draw = function(){ |
|
81 |
}; |
|
82 |
Frames.prototype.zoom = function(){ |
|
83 |
}; |
|
84 |
Frames.prototype.inside = function(){ |
|
85 |
}; |
|
86 |
var Clusters = function(){ |
|
87 |
var Object; |
|
88 |
var yDist; |
|
89 |
var x; |
|
90 |
var y; |
|
91 |
var width; |
|
92 |
var height; |
|
93 |
}; |
|
94 |
Clusters = function(json){ |
|
95 |
// make my object |
|
96 |
}; |
|
97 |
var Tweet = function(){ |
|
98 |
}; |
|
99 |
// Classes ======================================================================= |
|
| 187 | 100 |
|
| 207 | 101 |
// Refactoring (parametere) ************************************************************ |
102 |
// color translastion |
|
103 |
var qTweet_0 =0; |
|
104 |
var qTweet_Q =0; |
|
105 |
var qTweet_REF=0; |
|
106 |
var qTweet_OK =0; |
|
107 |
var qTweet_KO =0; |
|
108 |
function colorTranslation(value){ |
|
109 |
if(value == "Q"){ |
|
110 |
qTweet_Q+=1; |
|
111 |
return 2; |
|
112 |
}else if(value =="REF"){ |
|
113 |
qTweet_REF+=1; |
|
114 |
return 4; |
|
115 |
}else if(value =="OK"){ |
|
116 |
qTweet_OK+=1; |
|
117 |
return 1; |
|
118 |
}else if(value =="KO"){ |
|
119 |
qTweet_KO+=1; |
|
120 |
return 3; |
|
121 |
}else if(value ==""){ |
|
122 |
qTweet_0+=1; |
|
123 |
return 5; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
| 169 | 127 |
|
| 176 | 128 |
this._serializer.sync(function(data) { loaded_callback.call(self, data) }); |
129 |
|
|
130 |
function loaded_callback (json) { |
|
131 |
||
| 207 | 132 |
// get current view (the first ???) |
133 |
view = json.views[0]; |
|
134 |
|
|
135 |
// the tweets are by definition of the second annotation type FIXME ? |
|
136 |
tweet_annot_type = null; |
|
137 |
if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
138 |
tweet_annot_type = view.annotation_types[1]; |
|
139 |
} |
|
140 |
|
|
| 176 | 141 |
for(var i = 0; i < json.annotations.length; i++) { |
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
142 |
var item = json.annotations[i]; |
| 207 | 143 |
var MyTime = Math.floor(item.begin/duration*lineSize); |
144 |
var Myframe = Math.floor(MyTime/lineSize*frameLength); |
|
| 169 | 145 |
|
| 207 | 146 |
if (typeof(item.meta) !== "undefined" |
147 |
&& typeof(item.meta["id-ref"]) !== "undefined" |
|
148 |
&& item.meta["id-ref"] === tweet_annot_type) { |
|
149 |
|
|
150 |
var MyTJson = JSON.parse(item.meta['dc:source']['content']); |
|
151 |
|
|
152 |
if (item.content['polemics'] != undefined |
|
153 |
&& item.content['polemics'][0] != null) { |
|
154 |
|
|
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
155 |
// a tweet can have many polemics at the same time. |
| 207 | 156 |
for(var j=0; j<item.content['polemics'].length; j++){ |
157 |
|
|
158 |
this.tweets[numberOfTweet] = { |
|
159 |
id:i, |
|
160 |
qualification:colorTranslation(item.content['polemics'][j]), |
|
161 |
yIndicator:MyTime, |
|
162 |
yframe:Myframe, |
|
163 |
title:item.content['title'], |
|
164 |
timeframe:item.begin, |
|
165 |
userId: MyTJson.id, |
|
166 |
userScreenName: MyTJson.screen_name, |
|
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
167 |
tsource:MyTJson, |
|
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
168 |
cinecast_id: item.id |
| 207 | 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, |
|
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
184 |
tsource:MyTJson, |
|
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
185 |
cinecast_id: item.id |
| 207 | 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 |
|
|
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
270 |
var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */) |
|
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
271 |
.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
|
272 |
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
|
273 |
|
| 207 | 274 |
addEheight += TweetHeight; |
275 |
|
|
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
276 |
e.time = frames[i].mytweetsID[k].timeframe; |
|
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
277 |
e.title = frames[i].mytweetsID[k].title; |
|
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
278 |
e.id = frames[i].mytweetsID[k].cinecast_id; |
|
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
279 |
|
| 231 | 280 |
e.mouseover(function(element) { return function (event) { |
281 |
// event.clientX and event.clientY are to raphael what event.pageX and pageY are to jquery. |
|
| 191 | 282 |
self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), event.clientX - 106, event.clientY - 160); |
| 176 | 283 |
element.displayed = true; |
|
194
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
284 |
}}(e)).mouseout(function(element) { return function () { |
| 195 | 285 |
self.TooltipWidget.hide.call(self.TooltipWidget); |
| 207 | 286 |
}}(e)).mousedown(function () { |
287 |
self._Popcorn.currentTime(this.time/1000); |
|
|
265
e0d32948bf62
added a message sent when the user clicks on a tweet.
hamidouk
parents:
246
diff
changeset
|
288 |
self._Popcorn.trigger("IriSP.PolemicTweet.click", this.id); |
| 207 | 289 |
}); |
290 |
|
|
|
194
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
291 |
IriSP.jQuery(e.node).attr('id', 't' + k + ''); |
| 207 | 292 |
IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title); |
293 |
IriSP.jQuery(e.node).attr('begin', frames[i].mytweetsID[k].timeframe); |
|
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
| 169 | 299 |
|
| 207 | 300 |
} |
301 |
// DRAW UI :: resize border and bgd |
|
302 |
this.paperBackground = this.paper.rect(0, 0, this.width, this.heightmax).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1}); |
|
303 |
// var PaperBorder = this.paper.rect(0, this.yMax,this.width,1).attr({fill:"#fff",stroke: "none",opacity: 1}); |
|
| 203 | 304 |
|
| 207 | 305 |
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
|
306 |
|
|
a793a8a0c9d2
added a rectangle tip to show where we are in the video .
hamidouk
parents:
196
diff
changeset
|
307 |
// the small white line displayed over the slider. |
| 203 | 308 |
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
|
309 |
|
| 207 | 310 |
// decalage |
311 |
// tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1}); |
|
312 |
|
|
|
196
9fb4dcb0b878
"fixed" a test and added a new array to contain references to the raphael nodes we create.
hamidouk
parents:
195
diff
changeset
|
313 |
|
| 207 | 314 |
this.paperSlider.toBack(); |
315 |
this.paperBackground.toBack(); |
|
|
197
a793a8a0c9d2
added a rectangle tip to show where we are in the video .
hamidouk
parents:
196
diff
changeset
|
316 |
this.sliderTip.toFront(); |
| 207 | 317 |
} |
|
194
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 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater)); |
|
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
320 |
} |
|
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
321 |
|
|
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
322 |
IriSP.PolemicWidget.prototype.sliderUpdater = function() { |
| 169 | 323 |
|
|
194
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
324 |
var time = +this._Popcorn.currentTime(); |
|
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
325 |
var duration = +this._serializer.currentMedia().meta["dc:duration"]; |
|
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
326 |
|
|
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
327 |
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
|
328 |
|
|
a793a8a0c9d2
added a rectangle tip to show where we are in the video .
hamidouk
parents:
196
diff
changeset
|
329 |
this.sliderTip.attr("x", time * (this.width / (duration / 1000))); |
|
194
f5d86e5c4a56
some cleaning. Also added a progression indicator.
hamidouk
parents:
192
diff
changeset
|
330 |
}; |
| 169 | 331 |
|
332 |
|