author | rougeronj |
Mon, 19 Jan 2015 09:52:52 +0100 | |
changeset 92 | a323578ea954 |
parent 91 | 09a9074ea7b0 |
child 99 | 9d968fbcaa2a |
permissions | -rw-r--r-- |
91 | 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 |
||
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 | 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 |
|
|
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 | 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 |
|
92
a323578ea954
generalview take interval in pixel as argument (not time anymore)
rougeronj
parents:
91
diff
changeset
|
30 |
this.intervalSize = intervalSize; |
91 | 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 | 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){ |
|
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 | 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); |
|
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 | 71 |
graphics.endFill(); |
72 |
|
|
73 |
this.container.addChild(graphics); |
|
74 |
}; |
|
75 |
||
76 |
} |
|
77 |
||
78 |
module.exports = GeneralView; |