client/annotviz/app/js/annotstimeline.js
changeset 97 545803e685e0
parent 92 a323578ea954
child 98 72d767c5142d
equal deleted inserted replaced
96:f58715468f1e 97:545803e685e0
       
     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, timeBegin, timeEnd, intervalSize){
       
    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.timeBegin = timeBegin;
       
    24     this.timeEnd = timeEnd;
       
    25     this.duration = (timeEnd - timeBegin)/1000
       
    26     this.width = width;
       
    27     this.height = height;
       
    28     //define interval corresponding to the time of one step
       
    29     //e.g: 60 for a step of 60 seconds
       
    30     this.intervalSize = intervalSize;
       
    31     // define the step depending the interval we passed and the duration
       
    32     this.intervalDuration = (intervalSize*this.duration/width);
       
    33 
       
    34   //Initialise the list of step
       
    35     //each cell will contain the list categories and the number of annotations per categories
       
    36     this.cells = []
       
    37 
       
    38 
       
    39     // draw temp line to locate the middle of the container
       
    40     var graphics = new PIXI.Graphics();
       
    41     graphics.beginFill(0x000000);
       
    42     graphics.lineStyle(1, 0x000000);
       
    43     graphics.moveTo(xInit, (-this.height/2) );
       
    44     graphics.lineTo(this.width, (-this.height/2));
       
    45     graphics.endFill();
       
    46     this.container.addChild(graphics);
       
    47 
       
    48     this.addAnnot = function(category, time){
       
    49     	var x = Math.floor( (time-this.timeBegin)/(1000*this.intervalDuration)) * this.intervalSize;
       
    50     	var y = (-this.height/2);
       
    51 
       
    52     	//Check if cell is already set.
       
    53     	//If yes get increment the numbere of annots in the category corresponding
       
    54     	//If not initialise the cell
       
    55 //    	if (this.cells[x] === "undefined"){
       
    56 //    		cells[x].push({
       
    57 //    			"code" : category.code,
       
    58 //    			"color" : category.color,
       
    59 //    			"count" : 1
       
    60 //    		});
       
    61 //    	} else {
       
    62 //    		if (c)
       
    63 //    	}
       
    64 
       
    65     	console.log("x : " + x + " | y : " + y);
       
    66 
       
    67     	// We draw the rectangle
       
    68         var graphics = new PIXI.Graphics();
       
    69         graphics.beginFill(0x536991);
       
    70         graphics.drawRect(x, y, this.intervalSize, -10);
       
    71         graphics.endFill();
       
    72 
       
    73         this.container.addChild(graphics);
       
    74     };
       
    75 
       
    76 }
       
    77 
       
    78 module.exports = GeneralView;