integ/iri/js/iri-buzz.js
changeset 53 88666afffe6b
parent 49 531a593a0294
child 54 faf1e584551c
--- a/integ/iri/js/iri-buzz.js	Fri Apr 26 16:40:03 2013 +0200
+++ b/integ/iri/js/iri-buzz.js	Mon Apr 29 15:02:35 2013 +0200
@@ -20,7 +20,14 @@
 	now : new Date(),
 	dayLimit : 1,
 	timelineMin : 5,
-	bar : []
+	bar : [],
+    colorIds: {
+        "-2.0": 2,
+        "0.5": 0, "1.0": 0, "1.5": 0, "2.0": 0,
+        "2.5": 1, "3.0": 1, "3.5": 1,
+        "4.0": 2, "4.5": 2, "5.0": 2
+    },
+    colors: [ "#c00000", "#ffd000", "#008000"]
 };
 
 function init(){
@@ -54,35 +61,14 @@
 
 init();
 
-function resizeImg(parentId){
-	$(parentId+" img").each(function() {
-	    var img = $(this),
-	        div = $(this).parent();
-	    img.load(function() {
-	        var iw = img.width(),
-	            ih = img.height(),
-	            dw = div.width(),
-	            dh = div.height(),
-	            scale = Math.max(dw/iw, dh/ih),
-	            niw = iw * scale,
-	            nih = ih * scale;
-	        img.css({
-	            width: niw,
-	            height: nih,
-	            "margin-left": (dw - niw) / 2,
-	            "margin-top": (dh - nih) / 3
-	        });
-	    });
-	});
-}
-
-
 
 var bcSettings = {
 	width : 960,
 	height : CONFIG.hVS,
 	chart : {
-		spacer : 5
+		spacer : 5,
+		y: 150,
+		height: CONFIG.hVS - 150
 	},
 	data : {
 		model :[],
@@ -91,9 +77,12 @@
 	},
 	sedimentation:{
 	    token:{
-	      size:{original:12,minimum:2}
+	      size:{original:12,minimum:0}
 	    },
-	    aggregation:{height:100},
+	    aggregation:{
+	        height: CONFIG.hVS - 150,
+	        maxData: 50
+        },
 	    suspension:{
 	      decay:{power:1.001}
 	    }
@@ -101,15 +90,14 @@
   	options:{layout:false}
 };
 
-
 var currentDay = new Date().getDate();
 var _reviewMovies = [];
 var nbMovies;
 var indiceMovie = 0;
 var indiceBar = 0;
 var barChart;
-
-var urlBestMovies = 'http://api.allocine.fr/rest/v3/movielist?partner='+ partnerCode +'&format=json&filter=top:week&count=15';
+var count = 10;
+var urlBestMovies = 'http://api.allocine.fr/rest/v3/movielist?partner='+ partnerCode +'&format=json&filter=top:week&count='+count;
 $.getJSON(urlBestMovies, function(data) {
 	
 	var movies = data.feed.movie;
@@ -118,7 +106,7 @@
 	$('.posters').css('width', bcSettings.width);
 	//var wItem = bcSettings.width / nbMovies;
 
-	_.each(movies, function(d){
+	_.each(movies, function(d, i){
 
 		var dataMovie = {
 			title : d.originalTitle,
@@ -130,7 +118,7 @@
 
 		var poster = 
 			'<li>'+
-				'<img src="'+ dataMovie.posterUrl  +'" alt="'+ dataMovie.title +'" />'+
+				'<img width="150" height="200" src="'+ dataMovie.posterUrl  +'" alt="'+ dataMovie.title +'" />'+
 			'</li>';
 		$('.posters').append(poster);
 
@@ -140,18 +128,44 @@
 
 		bcSettings.data.model.push({label:"Column A"});
 
-		var userReviewCount = dataMovie.userReviewCount;
-		if(_.isUndefined(userReviewCount))userReviewCount = 0;
-		var initValue = userReviewCount;
-
-		initValue = 0;
-
-		bcSettings.data.strata.push([{initValue: initValue }]);
 
 	});
 
-	resizeImg('.posters');
+	console.log(CONFIG.bar);
+	
+	bcSettings.data.strata = function() {
+	    if (typeof barChart === "undefined") {
+	        var flocculated = [];
+	        _(function() {
+	            _.range(3).map(function(colorId) {
+	                $(".layer_"+colorId).css("fill", CONFIG.colors[colorId]);
+	            });
+	        }).defer();
+	    } else {
+	        var flocculated = barChart.selectAll("state",2);
+	    }
+	    
+	    var res = CONFIG.bar.map(function(movieCode) {
+	        var movieTokens = flocculated.filter(function(t) {
+	            return t.attr("movieCode") === movieCode;
+	        });
+	        return _.range(3).map(function(colorId) {
+	            var stratumTokens = movieTokens.filter(function(t) {
+    	            return t.attr("colorId") === colorId;
+    	        }).length;
+	            return {
+	                value: function() {
+	                    return stratumTokens
+	                },
+	                text: stratumTokens
+	            }
+	        });
+	    });
+	    return res;
+	};
+	
 	barChart = $("#data-viz").vs(bcSettings).data('visualSedimentation');
+	
 
 	//barChart.settings.sedimentation.token.size.minimum=0;
 });
@@ -301,10 +315,11 @@
 	var rating = data.rating;
 	var author = data.author;
 	var movieCode = data.movieCode;
+	var colorid = CONFIG.colorIds[data.rating.toFixed(1)],
+        color = CONFIG.colors[colorid];
 
 	rating = rating.toString().replace(".","_");
-	console.log(rating);
-
+/*
 	var commentReview = 
 	'<div class="comment clearfix" id="token-'+tokenId+'">'+
 		'<span class="comment-arrow"></span>'+
@@ -321,45 +336,51 @@
 		'</div>'+
 	'</div>';
 	$('body').append(commentReview);
-
-
-	barChart.addToken({
+*/
+	var token = barChart.addToken({
 		mappingElement : 'token-'+tokenId,
 		commentaire : commentaire,
 		movieCode : movieCode,
 		date : date,
 		rating : rating,
 		author : author,
-	  	category:barCharCat,
-	  	size:10,
+	  	category: barCharCat,
+	  	colorId: colorid,
+	  	fillStyle: color,
+	  	strokeStyle: "#555555",
+
+        shape:{
+          type:'box',
+          width:74,
+          height:5
+        },
+	  	callback:{
 /*
-shape:{
-  type:'box',
-  width:75,
-  height:2.5
-},
-*/
-	  	callback:{
 	  		draw : function(token){
 	  			var myDomElement= $('#'+token.attr('mappingElement'))[0];
                 $(myDomElement).css({
                   top : token.attr('y') + 150,
-                  left : token.attr('x') 
+                  left : token.attr('x')
                 })
 	  		},
             mouseover:function(token){
             	$('#'+token.attr('mappingElement')).show();
-            	/*
             	var myDomElement= $('#'+token.attr('mappingElement'))[0];
             	var commentaire = token.attr('commentaire'),
             		author = token.attr('author'),
             		date = token.attr('date'),
             		movieCode = token.attr('movieCode'),
             		rating = token.attr('rating');
-				*/
             },
             mouseout:function(token){
             	$('#'+token.attr('mappingElement')).hide();
+            },
+            */
+            suspension: function(token) {
+                setTimeout(function() {
+                    token.flocculate();
+                    barChart.strata.update(barChart);
+                }, 5000);
             }
      	}
 	});