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