42 |
42 |
43 IriSP.PolemicWidget.prototype.draw = function() { |
43 IriSP.PolemicWidget.prototype.draw = function() { |
44 |
44 |
45 // variable |
45 // variable |
46 // yMax |
46 // yMax |
|
47 |
|
48 var self = this; |
47 var yCoef = 2; // coef for height of 1 tweet |
49 var yCoef = 2; // coef for height of 1 tweet |
48 var frameSize = 5; // frame size |
50 var frameSize = 5; // frame size |
49 var margin = 1; // marge between frame |
51 var margin = 1; // marge between frame |
50 var lineSize = this.width; // timeline pixel width |
52 var lineSize = this.width; // timeline pixel width |
51 var nbrframes = lineSize/frameSize; // frame numbers |
53 var nbrframes = lineSize/frameSize; // frame numbers |
52 var numberOfTweet = 0; // number of tweet overide later |
54 var numberOfTweet = 0; // number of tweet overide later |
53 var duration = config.duration; // timescale width |
55 var duration = +this._serializer.currentMedia().meta["dc:duration"]; // timescale width |
54 var frameLenght = lineSize/frameSize; // frame timescale |
56 var frameLenght = lineSize/frameSize; // frame timescale |
55 var timeline; |
57 var timeline; |
56 var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); |
58 var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); |
57 |
59 |
58 // array |
60 // array |
59 //var tweets = new Array(); |
61 //var tweets = new Array(); |
129 return 5; |
131 return 5; |
130 } |
132 } |
131 } |
133 } |
132 |
134 |
133 |
135 |
134 // Refactoring (parametere) ************************************************************ |
136 this._serializer.sync(function(data) { loaded_callback.call(self, data) }); |
135 // load tweets send in parameters |
137 |
136 __IriSP.jQuery.ajax({ |
138 function loaded_callback (json) { |
137 dataType: "jsonp", |
139 |
138 url:config.metadata, |
|
139 success : function(json){ |
|
140 trace("load",""); |
|
141 // get current view (the first ???) |
140 // get current view (the first ???) |
142 view = json.views[0]; |
141 view = json.views[0]; |
143 |
142 |
144 // the tweets are by definition of the second annotation type |
143 // the tweets are by definition of the second annotation type |
145 tweet_annot_type = null; |
144 tweet_annot_type = null; |
146 if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
145 if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
147 tweet_annot_type = view.annotation_types[1]; |
146 tweet_annot_type = view.annotation_types[1]; |
148 } |
147 } |
149 RAWTweets = json.annotations; |
148 RAWTweets = json.annotations; |
150 |
149 |
151 __IriSP.jQuery.each(json.annotations, function(i,item) { |
150 for(var i = 0; i < json.annotations.length; i++) { |
152 |
151 var item = json.annotations[i]; |
153 var MyTime = Math.floor(item.begin/duration*lineSize); |
152 var MyTime = Math.floor(item.begin/duration*lineSize); |
154 var Myframe = Math.floor(MyTime/lineSize*frameLenght); |
153 var Myframe = Math.floor(MyTime/lineSize*frameLenght); |
155 |
154 |
156 if (typeof(item.meta) !== "undefined" |
155 if (typeof(item.meta) !== "undefined" |
157 && typeof(item.meta["id-ref"]) !== "undefined" |
156 && typeof(item.meta["id-ref"]) !== "undefined" |
327 console.log("tweets conversationel : "+tweetConversationel.length); |
325 console.log("tweets conversationel : "+tweetConversationel.length); |
328 console.log("tweets conversationel sp : "+pourcent(tweetConversationelSP,tweetConversationel.length)); |
326 console.log("tweets conversationel sp : "+pourcent(tweetConversationelSP,tweetConversationel.length)); |
329 console.log("tweets conversationel nsp: "+pourcent(tweetConversationel.length-tweetConversationelSP,tweetConversationel.length)); |
327 console.log("tweets conversationel nsp: "+pourcent(tweetConversationel.length-tweetConversationelSP,tweetConversationel.length)); |
330 } |
328 } |
331 function tweetsStats(){ |
329 function tweetsStats(){ |
332 for(var i=0; i<tweets.length; i++) { |
330 for(var i=0; i<this.tweets.length; i++) { |
333 conversationalCount(tweets[i]) |
331 conversationalCount(this.tweets[i]) |
334 tweetClientCount(tweets[i]); |
332 tweetClientCount(this.tweets[i]); |
335 //tweetRetweetCount(tweets[i]); |
333 //tweetRetweetCount(tweets[i]); |
336 } |
334 } |
337 conversationalReport(); |
335 conversationalReport(); |
338 tweetClientReport(); |
336 tweetClientReport(); |
339 } |
337 } |
340 function numberUserUsePolemic(){ |
338 function numberUserUsePolemic(){ |
341 |
339 |
342 for(var i=0; i<tweets.length; i++) { |
340 for(var i=0; i<this.tweets.length; i++) { |
343 if (tweets[i].qualification!=5){ |
341 if (this.tweets[i].qualification!=5){ |
344 var searchKeyValueArrayTest = searchKeyValueArray('userId',tweets[i].userId,userPol); |
342 var searchKeyValueArrayTest = searchKeyValueArray('userId', this.tweets[i].userId,userPol); |
345 if(searchKeyValueArrayTest==true){ |
343 if(searchKeyValueArrayTest==true){ |
346 myUser = userPol.push({ |
344 myUser = userPol.push({ |
347 userId: tweets[i].userId, |
345 userId: this.tweets[i].userId, |
348 userScreenName: tweets[i].userScreenName, |
346 userScreenName: this.tweets[i].userScreenName, |
349 tweets:[] |
347 tweets:[] |
350 }); |
348 }); |
351 } |
349 } |
352 }else{ |
350 }else{ |
353 var searchKeyValueArrayTest = searchKeyValueArray('userId',tweets[i].userId,userPol); |
351 var searchKeyValueArrayTest = searchKeyValueArray('userId',tweets[i].userId,userPol); |
429 console.log("accord : "+qTweet_OK+" "+pourcent(qTweet_OK,numberOfTweet)+" %"); |
427 console.log("accord : "+qTweet_OK+" "+pourcent(qTweet_OK,numberOfTweet)+" %"); |
430 console.log("desaccord : "+qTweet_KO+" "+pourcent(qTweet_KO,numberOfTweet)+" %"); |
428 console.log("desaccord : "+qTweet_KO+" "+pourcent(qTweet_KO,numberOfTweet)+" %"); |
431 console.log("question : "+qTweet_Q+" "+pourcent(qTweet_Q,numberOfTweet)+" %"); |
429 console.log("question : "+qTweet_Q+" "+pourcent(qTweet_Q,numberOfTweet)+" %"); |
432 console.log("reference : "+qTweet_REF+" "+pourcent(qTweet_REF,numberOfTweet)+" %"); |
430 console.log("reference : "+qTweet_REF+" "+pourcent(qTweet_REF,numberOfTweet)+" %"); |
433 console.log("sans polemic : "+qTweet_0+" "+pourcent(qTweet_0,numberOfTweet)+" %"); |
431 console.log("sans polemic : "+qTweet_0+" "+pourcent(qTweet_0,numberOfTweet)+" %"); |
434 numberUserUsePolemic(); |
432 // numberUserUsePolemic(); |
435 tweetsStats(); |
433 // tweetsStats.call(this); //fixme: ugly |
436 } |
434 } |
437 // tweet Drawing (in raphael) |
435 // tweet Drawing (in raphael) |
438 function DrawTweets (){ |
436 function DrawTweets (){ |
439 // GROUPES TWEET ============================================ |
437 // GROUPES TWEET ============================================ |
440 // Count nbr of cluster and tweet in a frame an save int in "frames" |
438 // Count nbr of cluster and tweet in a frame an save int in "frames" |
441 numberOfTweet = tweets.length; |
439 numberOfTweet = this.tweets.length; |
442 for(var i=0; i<nbrframes; i++) { |
440 for(var i=0; i<nbrframes; i++) { |
443 for(var j=0; j<numberOfTweet; j++) { |
441 for(var j=0; j<numberOfTweet; j++) { |
444 |
442 |
445 if (i==tweets[j].yframe){ |
443 if (i==this.tweets[j].yframe){ |
446 |
444 |
447 var k = tweets[j].qualification; |
445 var k = this.tweets[j].qualification; |
448 |
446 |
449 // make array for frame cluster |
447 // make array for frame cluster |
450 if(frames[i]==undefined){ |
448 if(frames[i]==undefined){ |
451 frames[i] = {id:i, |
449 frames[i] = {id:i, |
452 qualifVol:new Array(), |
450 qualifVol:new Array(), |
453 mytweetsID:new Array() |
451 mytweetsID:new Array() |
454 }; |
452 }; |
455 } |
453 } |
456 // add my tweet to frame |
454 // add my tweet to frame |
457 frames[i].mytweetsID.push(tweets[j]); |
455 frames[i].mytweetsID.push(this.tweets[j]); |
458 |
456 |
459 // count opinion by frame |
457 // count opinion by frame |
460 if( frames[i].qualifVol[k] == undefined){ |
458 if( frames[i].qualifVol[k] == undefined){ |
461 frames[i].qualifVol[k] = 1; |
459 frames[i].qualifVol[k] = 1; |
462 }else{ |
460 }else{ |
468 } |
466 } |
469 |
467 |
470 // GROUPES TWEET ============================================ |
468 // GROUPES TWEET ============================================ |
471 // max of tweet by Frame |
469 // max of tweet by Frame |
472 var max = 0; |
470 var max = 0; |
473 for(var i=0; i<nbrframes; i++) { |
471 for(var i = 0; i < nbrframes; i++) { |
474 var moy = 0; |
472 var moy = 0; |
475 for (var j=0; j<6; j++){ |
473 for (var j = 0; j < 6; j++) { |
476 if (frames[i]!=undefined){ |
474 if (frames[i] != undefined) { |
477 if (frames[i].qualifVol[j]!=undefined){ |
475 if (frames[i].qualifVol[j] != undefined) { |
478 moy += frames[i].qualifVol[j]; |
476 moy += frames[i].qualifVol[j]; |
479 } |
477 } |
480 } |
478 } |
481 } |
479 } |
482 //trace("frame "+i,moy); |
480 |
483 if (moy>max){max=moy;} |
481 if (moy > max) { |
|
482 max = moy; |
|
483 } |
484 } |
484 } |
485 |
485 |
486 var tweetDrawed = new Array(); |
486 var tweetDrawed = new Array(); |
487 var TweetHeight = 5; |
487 var TweetHeight = 5; |
488 |
488 |
489 // DRAW TWEETS ============================================ |
489 // DRAW TWEETS ============================================ |
490 for(var i=0; i<nbrframes;i++) { |
490 for(var i=0; i<nbrframes;i++) { |
491 var addEheight = 5; |
491 var addEheight = 5; |
492 if (frames[i]!=undefined){ |
492 if (frames[i] != undefined){ |
493 trace (i+" k=",frames[i].mytweetsID.length); |
493 |
494 // by type |
494 // by type |
495 for (var j=6; j>-1; j--){ |
495 for (var j = 6; j>-1; j--){ |
496 if (frames[i].qualifVol[j]!=undefined){ |
496 if (frames[i].qualifVol[j]!=undefined){ |
497 // show tweet by type |
497 // show tweet by type |
498 for (var k=0; k<frames[i].mytweetsID.length; k++){ |
498 for (var k = 0; k < frames[i].mytweetsID.length; k++) { |
499 if (frames[i].mytweetsID[k].qualification==j){ |
499 if (frames[i].mytweetsID[k].qualification == j) { |
500 var y=config.heightmax-addEheight; |
500 var x = i*frameSize; |
501 if(yMax>y){yMax=y;} |
501 var y = this.heightmax - addEheight; |
502 e = paper.rect( i*frameSize, // x |
502 if (this.yMax > y) { |
503 y, // y |
503 this.yMax = y; |
504 frameSize-margin, // width |
504 } |
505 TweetHeight // height |
505 |
506 ).attr({stroke:"#00","stroke-width":0.1, fill: colors[j]}); |
506 var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */).attr({stroke:"#00","stroke-width":0.1, fill: colors[j]}); |
507 addEheight +=TweetHeight; |
507 addEheight += TweetHeight; |
508 e.time= frames[i].mytweetsID[k].timeframe; |
508 e.time= frames[i].mytweetsID[k].timeframe; |
509 e.title= frames[i].mytweetsID[k].title; |
509 e.title= frames[i].mytweetsID[k].title; |
510 e.mouseover(function () { |
510 |
511 //this.attr({stroke:"#fff","stroke-width":5}); |
511 e.mouseover(function(element) { return function (event) { |
512 //this.toFront(); |
512 // event.clientX and event.clientY are to raphael what event.pageX and pageY are to jquery. |
513 }).mouseout(function () { |
513 self.TooltipWidget.show.call(self.TooltipWidget, element.title, "#fefefe", event.clientX - 106, event.clientY - 160); |
|
514 element.displayed = true; |
|
515 }}(e)).mouseout(function(element) { return function () { |
|
516 self.TooltipWidget.hide.call(self); |
514 //this.attr({stroke:"#00","stroke-width":0.1}); |
517 //this.attr({stroke:"#00","stroke-width":0.1}); |
515 }).mousedown(function () { |
518 }}(e)).mousedown(function () { |
516 __IriSP.MyApiPlayer.seek(this.time/1000); |
519 self._Popcorn.currentTime(this.time/1000); // FIXME: update ? |
517 }); |
520 }); |
518 __IriSP.jQuery(e.node).attr('id', 't'+k+''); |
521 __IriSP.jQuery(e.node).attr('id', 't'+k+''); |
519 __IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title); |
522 __IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title); |
520 __IriSP.jQuery(e.node).attr('begin', frames[i].mytweetsID[k].timeframe); |
523 __IriSP.jQuery(e.node).attr('begin', frames[i].mytweetsID[k].timeframe); |
521 var tempPosition = {x:i*frameSize,y:config.heightmax-addEheight}; |
524 var tempPosition = {x:i*frameSize,y: this.heightmax-addEheight}; |
522 addTip(e.node, frames[i].mytweetsID[k].title,colors[j],tempPosition); |
525 addTip(e.node, frames[i].mytweetsID[k].title,colors[j],tempPosition); |
523 //frames[i].mytweetsID.pop(); |
526 //frames[i].mytweetsID.pop(); |
524 } |
527 } |
525 } |
528 } |
526 } |
529 } |
527 } |
530 } |
528 } |
531 } |
529 |
532 |
530 } |
533 } |
531 // DRAW UI :: resize border and bgd |
534 // DRAW UI :: resize border and bgd |
532 heightOfChart = (yMax-(config.height-yMax)); |
535 var heightOfChart = (this.yMax-(this.height- this.yMax)); |
533 PaperBackground = paper.rect(0,yMax, this.width,heightOfChart).attr({fill:"#fff","stroke-width":0.1,opacity: 0.1}); |
536 var PaperBackground = this.paper.rect(0, this.yMax, this.width,heightOfChart).attr({fill:"#fff","stroke-width":0.1,opacity: 0.1}); |
534 PaperBorder = paper.rect(0,yMax,this.width,1).attr({fill:"#fff",stroke: "none",opacity: 1}); |
537 var PaperBorder = this.paper.rect(0, this.yMax,this.width,1).attr({fill:"#fff",stroke: "none",opacity: 1}); |
535 PaperSlider = paper.rect(0,20,1,heightOfChart).attr({fill:"#fc00ff",stroke: "none",opacity: 1}); |
538 var PaperSlider = this.paper.rect(0,20,1,heightOfChart).attr({fill:"#fc00ff",stroke: "none",opacity: 1}); |
536 |
539 |
537 // decalage |
540 // decalage |
538 tweetSelection = paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1}); |
541 tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1}); |
539 |
542 |
540 PaperSlider.toFront(); |
543 PaperSlider.toFront(); |
541 PaperBackground.toBack(); |
544 PaperBackground.toBack(); |
542 } |
545 } |
543 |
546 |
544 if(typeof(PaperSlider) !== 'undefined' ) { |
547 if(typeof(PaperSlider) !== 'undefined' ) { |
545 PaperSlider.toFront(); |
548 PaperSlider.toFront(); |
546 } |
549 } |
547 Report(); |
550 Report.call(this); |
548 } |
551 } |
549 |
552 |
550 |
553 |
551 // jQuery(document).mousemove(function(e){ |
554 // jQuery(document).mousemove(function(e){ |
552 // if (over){ |
555 // if (over){ |