client/annotviz/app/js/annotstimeline.js
changeset 123 d8ef840eaf68
parent 121 df6b39f962bc
child 124 b5697bcdbaff
child 126 13d9a532a0a7
--- a/client/annotviz/app/js/annotstimeline.js	Thu Jan 22 15:49:07 2015 +0100
+++ b/client/annotviz/app/js/annotstimeline.js	Thu Jan 22 16:16:54 2015 +0100
@@ -85,14 +85,23 @@
     //Add Annotation to the TimeLine
     this.addAnnot = function(data){
     	
+    	var ts = Date.parse(data.ts);
+    	var colorsDef;
+    	_(this.annotCategories).eachRight(function(cdef) {
+            if(cdef.ts < ts) {
+                colorsDef = cdef;
+                return false;
+            }
+        });
+    	
     	if (this.timeEnd > Date.parse(data.ts)){
 	    	var i = Math.floor(((Date.parse(data.ts) + 3600*1000) - this.timeBegin)/(1000*this.intervalDuration));
 
 	    	if (typeof(this.cells[i].graphics) === 'undefined'){
-	    		this.initCell(this.cells[i]);
+	    		this.initCell(this.cells[i], colorsDef);
 	    	}
 	    	
-	    	if (typeof(this.annotCategories[0].colors[data.content.category.code]) !== 'undefined'){
+	    	if (typeof(colorsDef.colors[data.content.category.code]) !== 'undefined'){
 	    		var annotCode = data.content.category.code;
 	    	} else {
 	    		var annotCode = 'default';
@@ -100,7 +109,7 @@
 	    	
 			this.cells[i].categories[annotCode].count += 1;
 			this.cells[i].totalAnnots +=1;
-			this.redrawCell(this.cells[i], i);
+			this.redrawCell(this.cells[i], colorsDef);
     	}
     };
 
@@ -134,7 +143,7 @@
     }
 
     //Draw the cellule
-    this.redrawCell = function(cell){
+    this.redrawCell = function(cell, colorsDef){
     	
     	var y = 0;
 
@@ -146,8 +155,8 @@
     	}
 
     	//Draw the rect depending on the height step calculated
-    	for (var i=0; i< this.annotCategories[0].order.length; i++){
-    		var currentCode = this.annotCategories[0].order[i];
+    	for (var i=0; i< colorsDef.order.length; i++){
+    		var currentCode = colorsDef.order[i];
 			cell.graphics.beginFill(cell.categories[currentCode].color.replace("#", "0x"))
     			.drawRect(0, y, this.intervalWidth-1, -cell.categories[currentCode].count * heightStep)
     			.endFill();
@@ -155,22 +164,22 @@
     	}
     }
     
-    this.initCell = function(cell){
+    this.initCell = function(cell, colorsDef){
     	cell.graphics = new PIXI.Graphics();
     	cell.graphics.position.x = this.circleX + this.radius * Math.sin(cell.i*(360/totalIndex)*(Math.PI/180));
     	cell.graphics.position.y = this.circleY - this.radius * Math.cos(cell.i*(360/totalIndex)*(Math.PI/180));
     	cell.graphics.rotation = (cell.i)*(360/totalIndex)*(Math.PI/180) + (360/(totalIndex*2))*(Math.PI/180);
     	this.container.addChild(cell.graphics);
     	
-    	for (var category in this.annotCategories[0].colors){
+    	for (var category in colorsDef.colors){
     		cell.categories[category] = {
 				"count": 0,
-				"color": this.annotCategories[0].colors[category]
+				"color": colorsDef.colors[category]
     		};
     	}
     	cell.categories['default'] = {
 			"count": 0,
-			"color": this.annotCategories[0].defaultColor
+			"color": colorsDef.defaultColor
     	}
     }