client/annotviz/app/js/annotstimeline.js
author ymh <ymh.work@gmail.com>
Tue, 20 Jan 2015 11:57:44 +0100
changeset 98 72d767c5142d
parent 97 545803e685e0
child 100 0d7dac03c1a0
permissions -rw-r--r--
refactor and make work annotsroll
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     1
/**
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
     2
* js/annotsTimeline
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     3
*
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
     4
* annotsTimeline basic component
91
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
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    12
function AnnotsTimeline(parentContainer, xInit, yInit, width, height, timeBegin, timeEnd, intervalSize){
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    13
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    14
//    var _this = this;
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    15
    this.container = new PIXI.DisplayObjectContainer();
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    16
    this.container.position.x = xInit;
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    17
    this.container.position.y = yInit;
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    18
    this.container.width = width;
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    19
    this.container.height = height;
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    20
    parentContainer.addChild(this.container);
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    21
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    22
    this.timeBegin = timeBegin;
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    23
    this.timeEnd = timeEnd;
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    24
    this.duration = (timeEnd - timeBegin)/1000;
91
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
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    29
    this.intervalSize = intervalSize;
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    30
    // 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
    31
    this.intervalDuration = (intervalSize*this.duration/width);
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    32
91
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
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    35
    this.cells = [];
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    36
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    37
91
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){
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    48
    	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
    49
    	var y = (-this.height/2);
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    50
91
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)
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    62
//    	}
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    63
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    64
    	console.log('x : ' + x + ' | y : ' + y);
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    65
91
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);
92
a323578ea954 generalview take interval in pixel as argument (not time anymore)
rougeronj
parents: 91
diff changeset
    69
        graphics.drawRect(x, y, this.intervalSize, -10);
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    70
        graphics.endFill();
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    71
91
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
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    77
module.exports = {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    78
	AnnotsTimeline : AnnotsTimeline
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    79
};