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-- |
91 | 1 |
/** |
98 | 2 |
* js/annotsTimeline |
91 | 3 |
* |
98 | 4 |
* annotsTimeline basic component |
91 | 5 |
* |
6 |
*/ |
|
7 |
||
8 |
'use strict'; |
|
9 |
||
10 |
var PIXI = require('pixi'); |
|
11 |
||
98 | 12 |
function AnnotsTimeline(parentContainer, xInit, yInit, width, height, timeBegin, timeEnd, intervalSize){ |
13 |
||
14 |
// var _this = this; |
|
91 | 15 |
this.container = new PIXI.DisplayObjectContainer(); |
16 |
this.container.position.x = xInit; |
|
17 |
this.container.position.y = yInit; |
|
18 |
this.container.width = width; |
|
19 |
this.container.height = height; |
|
20 |
parentContainer.addChild(this.container); |
|
97 | 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 | 24 |
this.duration = (timeEnd - timeBegin)/1000; |
91 | 25 |
this.width = width; |
26 |
this.height = height; |
|
27 |
//define interval corresponding to the time of one step |
|
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 | 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 | 32 |
|
91 | 33 |
//Initialise the list of step |
34 |
//each cell will contain the list categories and the number of annotations per categories |
|
98 | 35 |
this.cells = []; |
97 | 36 |
|
37 |
||
91 | 38 |
// draw temp line to locate the middle of the container |
39 |
var graphics = new PIXI.Graphics(); |
|
40 |
graphics.beginFill(0x000000); |
|
41 |
graphics.lineStyle(1, 0x000000); |
|
42 |
graphics.moveTo(xInit, (-this.height/2) ); |
|
43 |
graphics.lineTo(this.width, (-this.height/2)); |
|
44 |
graphics.endFill(); |
|
45 |
this.container.addChild(graphics); |
|
46 |
||
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 | 49 |
var y = (-this.height/2); |
97 | 50 |
|
91 | 51 |
//Check if cell is already set. |
52 |
//If yes get increment the numbere of annots in the category corresponding |
|
53 |
//If not initialise the cell |
|
54 |
// if (this.cells[x] === "undefined"){ |
|
55 |
// cells[x].push({ |
|
56 |
// "code" : category.code, |
|
57 |
// "color" : category.color, |
|
58 |
// "count" : 1 |
|
59 |
// }); |
|
60 |
// } else { |
|
61 |
// if (c) |
|
97 | 62 |
// } |
63 |
||
98 | 64 |
console.log('x : ' + x + ' | y : ' + y); |
97 | 65 |
|
91 | 66 |
// We draw the rectangle |
67 |
var graphics = new PIXI.Graphics(); |
|
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 | 70 |
graphics.endFill(); |
97 | 71 |
|
91 | 72 |
this.container.addChild(graphics); |
73 |
}; |
|
74 |
||
75 |
} |
|
76 |
||
98 | 77 |
module.exports = { |
78 |
AnnotsTimeline : AnnotsTimeline |
|
79 |
}; |