client/annotviz/app/js/annotsroll.js
changeset 134 119b6193c493
parent 131 0bb70072a56f
equal deleted inserted replaced
133:12f782a13fa2 134:119b6193c493
    48     var yInit = opts.yInit;
    48     var yInit = opts.yInit;
    49     var annotStyles = _(opts.annotStyles).defaults(defaultAnnotStyles).value();
    49     var annotStyles = _(opts.annotStyles).defaults(defaultAnnotStyles).value();
    50     var marginX = 15;
    50     var marginX = 15;
    51     for(var style in annotStyles) {
    51     for(var style in annotStyles) {
    52     	if (annotStyles[style].wordWrap === true){
    52     	if (annotStyles[style].wordWrap === true){
    53     		annotStyles[style].wordWrapWidth = this.widthRoll - marginX; 
    53     		annotStyles[style].wordWrapWidth = this.widthRoll - marginX;
    54     	}
    54     	}
    55     }
    55     }
    56     var started = false;
    56     var started = false;
    57     var ws = opts.ws;
    57     var ws = opts.ws;
    58     var externalRefresh = opts.externalRefresh;
    58     var externalRefresh = opts.externalRefresh;
    59     var stageView = opts.stageView;
    59     var stageView = opts.stageView;
    60     var waitInterval;
    60     var waitInterval;
    61     var wait = 0;
    61     var wait = 0;
    62     
    62 
    63     stageView.registerComponent(this);
    63     stageView.registerComponent(this);
    64 
    64 
    65     var isHidden = function(child) {
    65     var isHidden = function(child) {
    66         // TODO: the origin point is an approximation. Should refine this
    66         // TODO: the origin point is an approximation. Should refine this
    67         var globalPos = child.toGlobal(new PIXI.Point(0,0));
    67         var globalPos = child.toGlobal(new PIXI.Point(0,0));
    97         }
    97         }
    98         if(!resColor) {
    98         if(!resColor) {
    99             resColor = colorsDef.defaultColor || DEFAULT_ANNOT_COLOR;
    99             resColor = colorsDef.defaultColor || DEFAULT_ANNOT_COLOR;
   100         }
   100         }
   101         return resColor;
   101         return resColor;
   102     }
   102     };
   103 
   103 
   104     this.addAnnot = function(category, text, user, color, ts){
   104     this.addAnnot = function(category, text, user, color, ts){
   105 
   105 
   106         var x = 0;
   106         var x = 0;
   107         var y = (ts-this.startTs) * this.pixelsPerSecond / 1000 + yInit;
   107         var y = (ts-this.startTs) * this.pixelsPerSecond / 1000 + yInit;
   111         if (wait === 0){
   111         if (wait === 0){
   112 	        var graphics = new PIXI.Graphics()
   112 	        var graphics = new PIXI.Graphics()
   113 	            .beginFill(colorHex)
   113 	            .beginFill(colorHex)
   114 	            .drawRect(x, y, 10, 3)
   114 	            .drawRect(x, y, 10, 3)
   115 	            .endFill();
   115 	            .endFill();
   116 	
   116 
   117 	        this.container.addChild(graphics);
   117 	        this.container.addChild(graphics);
   118 	
   118 
   119 	        var textHeight = 0;
   119 	        var textHeight = 0;
   120 	        var catLabel = new PIXI.Text(
   120 	        var catLabel = new PIXI.Text(
   121 	            category,
   121 	            category,
   122 	            _(annotStyles.label).extend({fill: color}).value()
   122 	            _(annotStyles.label).extend({fill: color}).value()
   123 	        );
   123 	        );
   124 	        catLabel.x = x + marginX;
   124 	        catLabel.x = x + marginX;
   125 	        catLabel.y = y - 23;
   125 	        catLabel.y = y - 23;
   126 	        this.container.addChild(catLabel);
   126 	        this.container.addChild(catLabel);
   127 	        textHeight += (catLabel.height - 23 + 2);
   127 	        textHeight += (catLabel.height - 23 + 2);
   128 	
   128 
   129 	        if(text) {
   129 	        if(text) {
   130 	            var catText = new PIXI.Text(text, annotStyles.text);
   130 	            var catText = new PIXI.Text(text, annotStyles.text);
   131 	            catText.x = x + marginX;
   131 	            catText.x = x + marginX;
   132 	            catText.y = y + textHeight;
   132 	            catText.y = y + textHeight;
   133 	            this.container.addChild(catText);
   133 	            this.container.addChild(catText);
   134 	            textHeight += (catText.height + 2);
   134 	            textHeight += (catText.height + 2);
   135 	        }
   135 	        }
   136 	
   136 
   137 	        var catUser = new PIXI.Text(user, annotStyles.user);
   137 	        var catUser = new PIXI.Text(user, annotStyles.user);
   138 	        catUser.x = x + marginX;
   138 	        catUser.x = x + marginX;
   139 	        catUser.y = y + textHeight;
   139 	        catUser.y = y + textHeight;
   140 	        this.container.addChild(catUser);
   140 	        this.container.addChild(catUser);
   141 	        textHeight += (catUser.height + 8);
   141 	        textHeight += (catUser.height + 8);
   142 	        
   142 
   143 	        if (this.ignoreAnnots === true){
   143 	        if (this.ignoreAnnots === true){
   144 		        wait = textHeight / this.pixelsPerSecond;
   144 		        wait = textHeight / this.pixelsPerSecond;
   145 		        waitInterval = setInterval(function() {_this.refreshWait();}, 1000);
   145 		        waitInterval = setInterval(function() {_this.refreshWait();}, 1000);
   146 	        }
   146 	        }
   147         }
   147         }
   167 
   167 
   168     this.move = this.refresh = function() {
   168     this.move = this.refresh = function() {
   169         var diff = (this.startTs - Date.now())/1000;
   169         var diff = (this.startTs - Date.now())/1000;
   170         this.moveTo(diff);
   170         this.moveTo(diff);
   171     };
   171     };
   172     
   172 
   173     this.refreshWait = function(){
   173     this.refreshWait = function(){
   174     	wait -= 1;
   174     	wait -= 1;
   175     	if (wait < 0){
   175     	if (wait < 0){
   176     		wait = 0;
   176     		wait = 0;
   177     		clearInterval(waitInterval);
   177     		clearInterval(waitInterval);
   194         ws.message(function(data) {
   194         ws.message(function(data) {
   195             _this.addAnnots(data);
   195             _this.addAnnots(data);
   196         });
   196         });
   197 
   197 
   198     };
   198     };
   199     
   199 
   200 
   200 
   201     this.start = function() {
   201     this.start = function() {
   202         if(!started) {
   202         if(!started) {
   203             this.startTs = Date.now();
   203             this.startTs = Date.now();
   204             started = true;
   204             started = true;