client/annotviz/app/js/generalView.js
changeset 91 09a9074ea7b0
child 92 a323578ea954
equal deleted inserted replaced
90:111350ddb81d 91:09a9074ea7b0
       
     1 /**
       
     2 * js/generalView
       
     3 *
       
     4 * generalView basic component
       
     5 *
       
     6 */
       
     7 
       
     8 'use strict';
       
     9 
       
    10 var PIXI = require('pixi');
       
    11 var randomColor = require('randomColor');
       
    12 
       
    13 function GeneralView(parentContainer, xInit, yInit, width, height, duration, interval, beginTime){
       
    14 	console.log(width);
       
    15     var _this = this;
       
    16     this.container = new PIXI.DisplayObjectContainer();
       
    17     this.container.position.x = xInit;
       
    18     this.container.position.y = yInit;
       
    19     this.container.width = width;
       
    20     this.container.height = height;
       
    21     parentContainer.addChild(this.container);
       
    22     
       
    23     this.duration = duration;
       
    24     this.beginTime = beginTime;
       
    25     this.width = width;
       
    26     this.height = height;
       
    27     //define interval corresponding to the time of one step
       
    28     //e.g: 60 for a step of 60 seconds
       
    29     this.interval = interval;
       
    30     // define the step depending the interval we passed and the duration
       
    31     this.step = width*interval/duration;
       
    32     
       
    33   //Initialise the list of step
       
    34     //each cell will contain the list categories and the number of annotations per categories
       
    35     this.cells = []
       
    36     
       
    37     
       
    38     // draw temp line to locate the middle of the container
       
    39     var graphics = new PIXI.Graphics();
       
    40     graphics.beginFill(0x000000);
       
    41     graphics.lineStyle(1, 0x000000);
       
    42     graphics.moveTo(xInit, (-this.height/2) );
       
    43     graphics.lineTo(this.width, (-this.height/2));
       
    44     graphics.endFill();
       
    45     this.container.addChild(graphics);
       
    46 
       
    47     this.addAnnot = function(category, time){
       
    48     	var x = Math.floor( (time-this.beginTime)/(1000*this.interval)) * this.step;
       
    49     	var y = (-this.height/2);
       
    50     	
       
    51     	//Check if cell is already set.
       
    52     	//If yes get increment the numbere of annots in the category corresponding
       
    53     	//If not initialise the cell
       
    54 //    	if (this.cells[x] === "undefined"){
       
    55 //    		cells[x].push({
       
    56 //    			"code" : category.code,
       
    57 //    			"color" : category.color,
       
    58 //    			"count" : 1
       
    59 //    		});
       
    60 //    	} else {
       
    61 //    		if (c)
       
    62 //    	} 
       
    63     	
       
    64     	console.log("x : " + x + " | y : " + y);
       
    65         
       
    66     	// We draw the rectangle
       
    67         var graphics = new PIXI.Graphics();
       
    68         graphics.beginFill(0x536991);
       
    69         graphics.drawRect(x, y, this.step, -10);
       
    70         graphics.endFill();
       
    71         
       
    72         this.container.addChild(graphics);
       
    73     };
       
    74 
       
    75 }
       
    76 
       
    77 module.exports = GeneralView;