client/annotviz/app/js/generalView.js
author rougeronj
Mon, 19 Jan 2015 09:52:52 +0100
changeset 92 a323578ea954
parent 91 09a9074ea7b0
child 99 9d968fbcaa2a
permissions -rw-r--r--
generalview take interval in pixel as argument (not time anymore)
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
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    13
function GeneralView(parentContainer, xInit, yInit, width, height, timeBegin, timeEnd, intervalSize){
91
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
    
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    23
    this.timeBegin = timeBegin;
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    24
    this.timeEnd = timeEnd;
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    25
    this.duration = (timeEnd - timeBegin)/1000 
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    26
    this.width = width;
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    27
    this.height = height;
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    28
    //define interval corresponding to the time of one step
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    29
    //e.g: 60 for a step of 60 seconds
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    30
    this.intervalSize = intervalSize;
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    31
    // define the step depending the interval we passed and the duration
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    32
    this.intervalDuration = (intervalSize*this.duration/width);
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    33
    
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    34
  //Initialise the list of step
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    35
    //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
    36
    this.cells = []
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
    
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    39
    // draw temp line to locate the middle of the container
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    40
    var graphics = new PIXI.Graphics();
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    41
    graphics.beginFill(0x000000);
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    42
    graphics.lineStyle(1, 0x000000);
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    43
    graphics.moveTo(xInit, (-this.height/2) );
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    44
    graphics.lineTo(this.width, (-this.height/2));
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    45
    graphics.endFill();
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    46
    this.container.addChild(graphics);
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    47
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    48
    this.addAnnot = function(category, time){
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    49
    	var x = Math.floor( (time-this.timeBegin)/(1000*this.intervalDuration)) * this.intervalSize;
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    50
    	var y = (-this.height/2);
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    51
    	
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    52
    	//Check if cell is already set.
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    53
    	//If yes get increment the numbere of annots in the category corresponding
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    54
    	//If not initialise the cell
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    55
//    	if (this.cells[x] === "undefined"){
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    56
//    		cells[x].push({
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    57
//    			"code" : category.code,
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    58
//    			"color" : category.color,
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    59
//    			"count" : 1
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    60
//    		});
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    61
//    	} else {
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    62
//    		if (c)
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
    	
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    65
    	console.log("x : " + x + " | y : " + y);
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    66
        
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    67
    	// We draw the rectangle
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    68
        var graphics = new PIXI.Graphics();
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    69
        graphics.beginFill(0x536991);
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    70
        graphics.drawRect(x, y, this.intervalSize, -10);
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    71
        graphics.endFill();
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    72
        
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    73
        this.container.addChild(graphics);
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
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    78
module.exports = GeneralView;