client/annotviz/app/js/annotsroll.js
author rougeronj
Thu, 22 Jan 2015 15:02:54 +0100
changeset 120 89544c28a364
parent 117 c0034b35c44e
child 122 3b11017a76a4
permissions -rw-r--r--
minor improvement and console.log cleaning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     1
/**
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     2
* js/annotsRoll.js
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     3
*
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     4
* annotsRoll basic component
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     5
*
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     6
*/
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     7
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     8
'use strict';
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
     9
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
    10
var PIXI = require('pixi');
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    11
var _ = require('lodash');
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
    12
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    13
var DEFAULT_ANNOT_COLOR = '#bababa';
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    14
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    15
var defaultAnnotStyles = {
106
9b20ddf1fc70 Add WordWrap to annots text style to crates multilines if the text is to large
rougeronj
parents: 105
diff changeset
    16
    'label': { font: '16pt Arial Bold', fill: '#65A954', wordWrap: true},
9b20ddf1fc70 Add WordWrap to annots text style to crates multilines if the text is to large
rougeronj
parents: 105
diff changeset
    17
    'text' : { font: '12pt Arial Regular', fill: '#444444', wordWrap: true},
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
    18
    'user' : { font: '14pt Arial regular', fill: '#666666' },
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    19
};
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    20
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    21
var defaultOptions = {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    22
    externalRefresh: false,
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    23
    defaultColor: DEFAULT_ANNOT_COLOR,
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
    24
    annotStyles: defaultAnnotStyles,
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
    25
    ignoreAnnots:false
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    26
};
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    27
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    28
function AnnotsRoll(options) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    29
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    30
//parentContainer, xInit, yInit, width, height, widthRoll, pixelsPerSecond, annotColors
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
    31
    var _this = this;
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    32
    var opts = _(options).defaults(defaultOptions).value();
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    33
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    34
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
    35
    this.container = new PIXI.DisplayObjectContainer();
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    36
    this.container.x = opts.xInit;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    37
    this.container.y = opts.yInit;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    38
    this.container.width = opts.width;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    39
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    40
    this.height = opts.height;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    41
    this.width = opts.width;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    42
    this.widthRoll = opts.widthRoll;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    43
    this.pixelsPerSecond = opts.pixelsPerSecond;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    44
    this.annotColors = opts.annotColors;
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
    45
    this.startTs = opts.startTs || Date.now();
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
    46
    this.ignoreAnnots = opts.ignoreAnnots;
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
    47
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    48
    var yInit = opts.yInit;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    49
    var annotStyles = _(opts.annotStyles).defaults(defaultAnnotStyles).value();
120
89544c28a364 minor improvement and console.log cleaning
rougeronj
parents: 117
diff changeset
    50
    var marginX = 15;
106
9b20ddf1fc70 Add WordWrap to annots text style to crates multilines if the text is to large
rougeronj
parents: 105
diff changeset
    51
    for(var style in annotStyles) {
9b20ddf1fc70 Add WordWrap to annots text style to crates multilines if the text is to large
rougeronj
parents: 105
diff changeset
    52
    	if (annotStyles[style].wordWrap === true){
120
89544c28a364 minor improvement and console.log cleaning
rougeronj
parents: 117
diff changeset
    53
    		annotStyles[style].wordWrapWidth = this.widthRoll - marginX; 
106
9b20ddf1fc70 Add WordWrap to annots text style to crates multilines if the text is to large
rougeronj
parents: 105
diff changeset
    54
    	}
9b20ddf1fc70 Add WordWrap to annots text style to crates multilines if the text is to large
rougeronj
parents: 105
diff changeset
    55
    }
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    56
    var started = false;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    57
    var ws = opts.ws;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    58
    var externalRefresh = opts.externalRefresh;
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    59
    var stageView = opts.stageView;
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
    60
    var waitInterval;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
    61
    var wait = 0;
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    62
    
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    63
    stageView.registerComponent(this);
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    64
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    65
    var isHidden = function(child) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    66
        // TODO: the origin point is an approximation. Should refine this
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    67
        var globalPos = child.toGlobal(new PIXI.Point(0,0));
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    68
        return ((globalPos.x + child.width) < 0) || ((globalPos.y + child.height) < 0) ;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    69
    };
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    70
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    71
    this.addAnnots = function(data) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    72
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    73
        //var title = data.content.category.label;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    74
        //var user = data.content.user;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    75
        //Test cat and color
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    76
        //var colorAnnot = 0x65A954;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    77
        var category = data.content.category.label,
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    78
            text     = data.content.text,
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    79
            user     = data.content.user,
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    80
            ts       = Date.parse(data.ts),
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    81
            color    = this.getColor(ts, data.content.category.code);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    82
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    83
        this.addAnnot(category, text, user, color, ts);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    84
    };
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
    85
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    86
    this.getColor = function(ts, code) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    87
        var colorsDef;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    88
        _(this.annotColors).eachRight(function(cdef) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    89
            if(cdef.ts < ts) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    90
                colorsDef = cdef.colors;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    91
                return false;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    92
            }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    93
        });
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    94
        var resColor;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    95
        if(colorsDef) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    96
            resColor = colorsDef[code];
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    97
        }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    98
        if(!resColor) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
    99
            resColor = DEFAULT_ANNOT_COLOR;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   100
        }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   101
        return resColor;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   102
    }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   103
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   104
    this.addAnnot = function(category, text, user, catColor, ts){
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   105
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   106
        var color = catColor ? catColor : DEFAULT_ANNOT_COLOR;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   107
        var x = 0;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   108
        var y = (ts-this.startTs) * this.pixelsPerSecond / 1000 + yInit;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   109
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   110
        var colorHex = parseInt(color.replace(/^#/, ''), 16);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   111
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   112
        if (wait === 0){
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   113
	        var graphics = new PIXI.Graphics()
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   114
	            .beginFill(colorHex)
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   115
	            .drawRect(x, y, 10, 3)
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   116
	            .endFill();
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   117
	
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   118
	        this.container.addChild(graphics);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   119
	
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   120
	        var textHeight = 0;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   121
	        var catLabel = new PIXI.Text(
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   122
	            category,
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   123
	            _(annotStyles.label).extend({fill: color}).value()
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   124
	        );
120
89544c28a364 minor improvement and console.log cleaning
rougeronj
parents: 117
diff changeset
   125
	        catLabel.x = x + marginX;
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   126
	        catLabel.y = y - 23;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   127
	        this.container.addChild(catLabel);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   128
	        textHeight += (catLabel.height - 23 + 2);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   129
	
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   130
	        if(text) {
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   131
	            var catText = new PIXI.Text(text, annotStyles.text);
120
89544c28a364 minor improvement and console.log cleaning
rougeronj
parents: 117
diff changeset
   132
	            catText.x = x + marginX;
117
c0034b35c44e merge + gulp + correction of superposition category-text
rougeronj
parents: 112
diff changeset
   133
	            catText.y = y + textHeight;
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   134
	            this.container.addChild(catText);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   135
	            textHeight += (catText.height + 2);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   136
	        }
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   137
	
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   138
	        var catUser = new PIXI.Text(user, annotStyles.user);
120
89544c28a364 minor improvement and console.log cleaning
rougeronj
parents: 117
diff changeset
   139
	        catUser.x = x + marginX;
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   140
	        catUser.y = y + textHeight;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   141
	        this.container.addChild(catUser);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   142
	        textHeight += (catUser.height + 8);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   143
	        
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   144
	        if (this.ignoreAnnots === true){
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   145
		        wait = textHeight / this.pixelsPerSecond;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   146
		        waitInterval = setInterval(function() {_this.refreshWait();}, 1000);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   147
	        }
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   148
        }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   149
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   150
        this.addAnnotLine(colorHex, y);
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   151
    };
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   152
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   153
    this.addAnnotLine = function(color, y) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   154
        var x = this.widthRoll;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   155
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   156
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   157
        var graphics = new PIXI.Graphics()
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   158
            .beginFill(color)
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   159
            .drawRect(x, y, this.width - x, 3)
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   160
            .endFill();
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   161
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   162
        this.container.addChild(graphics);
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   163
    };
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   164
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   165
    this.moveTo = function(diffTime){
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   166
    	this.container.y = Math.floor(diffTime*this.pixelsPerSecond);
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   167
    };
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   168
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   169
    this.move = this.refresh = function() {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   170
        var diff = (this.startTs - Date.now())/1000;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   171
        this.moveTo(diff);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   172
    };
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   173
    
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   174
    this.refreshWait = function(){
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   175
    	wait -= 1;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   176
    	if (wait < 0){
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   177
    		wait = 0;
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   178
    		clearInterval(waitInterval);
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   179
    	}
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   180
    };
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   181
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   182
    this.removePassedObjets = function(){
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   183
        var childrenToRemove = [];
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   184
        _(_this.container.children).forEach(function(child) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   185
            return typeof(child) === 'undefined' ||
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   186
                (isHidden(child) && childrenToRemove.push(child));
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   187
        });
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   188
        childrenToRemove.forEach(function(child) {
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   189
            _this.container.removeChild(child);
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   190
        });
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   191
    };
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   192
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   193
    this.init = function() {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   194
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   195
        ws.message(function(data) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   196
            _this.addAnnots(data);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   197
        });
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   198
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   199
    };
111
a7b72620d227 Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options
rougeronj
parents: 106
diff changeset
   200
    
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   201
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   202
    this.start = function() {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   203
        if(!started) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   204
            this.startTs = Date.now();
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   205
            started = true;
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   206
        }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   207
        this.cleanInterval = setInterval(function () { _this.removePassedObjets(); }, 1000 * this.height / this.pixelsPerSecond );
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   208
        if(!externalRefresh) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   209
            this.refreshInterval = setInterval(function() {_this.move();}, 1000/this.framerate);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   210
        }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   211
    };
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   212
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   213
    this.stop = function() {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   214
        clearInterval(this.cleanInterval);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   215
        if(!externalRefresh) {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   216
            clearInterval(this.refreshInterval);
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   217
        }
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   218
    };
89
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   219
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   220
}
b4bd49f01837 add annotsRoll class and create it in main. Adapt main and pianoroll to allow horizontal or vertical view
rougeronj
parents:
diff changeset
   221
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   222
module.exports = {
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   223
    AnnotsRoll: AnnotsRoll,
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   224
};