client/annotviz/app/js/annotsRoll.js
changeset 96 f58715468f1e
parent 89 b4bd49f01837
child 99 9d968fbcaa2a
equal deleted inserted replaced
95:806739a26858 96:f58715468f1e
       
     1 /**
       
     2 * js/annotsRoll.js
       
     3 *
       
     4 * annotsRoll basic component
       
     5 *
       
     6 */
       
     7 
       
     8 'use strict';
       
     9 
       
    10 var PIXI = require('pixi');
       
    11 var randomColor = require('randomColor');
       
    12 
       
    13 function AnnotsRoll(parentContainer, xInit, yInit, width, height, widthRoll, pixelsPerSecond, annotColors, lineInterval){
       
    14     var _this = this;
       
    15     this.container = new PIXI.DisplayObjectContainer();
       
    16     this.container.position.x = xInit;
       
    17     this.container.position.y = yInit;
       
    18     this.container.width = width;
       
    19     parentContainer.addChild(this.container);
       
    20 
       
    21     this.height = height;
       
    22     this.width = width;
       
    23     this.widthRoll = widthRoll;
       
    24     this.pixelsPerSecond = pixelsPerSecond;
       
    25     this.lineInterval = lineInterval;
       
    26 
       
    27     this.addAnnot = function(category, user, catColor){
       
    28     	var graphics = new PIXI.Graphics();
       
    29     	var color = catColor;
       
    30     	var x = 0;
       
    31     	var y = -this.container.y;
       
    32         graphics.beginFill(color);
       
    33         graphics.drawRect(x, y, 10, 3);
       
    34         graphics.endFill();
       
    35         
       
    36         this.container.addChild(graphics);
       
    37 
       
    38         var catText = new PIXI.Text(category, { font: '16pt Arial', fill: '#65A954' });
       
    39         catText.x = x + 20;
       
    40         catText.y = y - 23;
       
    41         this.container.addChild(catText);
       
    42         
       
    43         var userText = new PIXI.Text(user, { font: '10pt Arial', fill: '#444444' });
       
    44         userText.x = x + 20;
       
    45         userText.y = y + 2;
       
    46         this.container.addChild(userText);
       
    47         
       
    48         this.addAnnotLine(color)
       
    49     };
       
    50 
       
    51     this.addAnnotLine = function(color){
       
    52     	var x = this.widthRoll;
       
    53     	var y = -this.container.y;
       
    54     	
       
    55     	var graphics = new PIXI.Graphics();
       
    56     	
       
    57         graphics.beginFill(color);
       
    58         graphics.drawRect(x, y, this.width - x, 3);
       
    59         graphics.endFill();
       
    60         
       
    61         this.container.addChild(graphics);
       
    62     };
       
    63 
       
    64     this.moveTo = function(diffTime){
       
    65     	this.container.y = Math.floor(diffTime*this.pixelsPerSecond);
       
    66     };
       
    67 
       
    68     this.removePassedObjets = function(){
       
    69         var nbChilds = _this.container.children.length;
       
    70         var i = 0, childIsNowDisplayed = false, childrenToRemove = [];
       
    71         while(i<nbChilds && !childIsNowDisplayed){
       
    72             var child = _this.container.children[i++];
       
    73             
       
    74             if(typeof(child) == 'undefined') {
       
    75                 continue;
       
    76             }
       
    77         	if((child.y + child.height) < (Math.abs(_this.container.y) - _this.height)){
       
    78                 childrenToRemove.push(child);
       
    79             }
       
    80             else {
       
    81                 childIsNowDisplayed = true;
       
    82             }
       
    83         }
       
    84         childrenToRemove.forEach(function(child) {
       
    85             _this.container.removeChild(child);
       
    86         });
       
    87     };
       
    88 
       
    89 	window.setInterval(this.removePassedObjets, 1000 * this.height / this.pixelsPerSecond );
       
    90 
       
    91 }
       
    92 
       
    93 module.exports = AnnotsRoll;