client/annotviz/app/js/annotstimeline.js
author rougeronj
Fri, 23 Jan 2015 01:00:00 +0100
changeset 129 7181e1f28eb0
parent 128 9f2334598088
parent 125 f9dd7bfed997
child 131 0bb70072a56f
permissions -rw-r--r--
Merge with f9dd7bfed9976461c79bf521ed01bf4caaf4fbcf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     1
/**
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
     2
* js/annotstimeline
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     3
*
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
     4
* annotstimeline basic component
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     5
*
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     6
*/
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     7
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     8
'use strict';
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
     9
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    10
var PIXI = require('pixi');
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
    11
var Utils = require('./utils.js');
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    12
var _ = require('lodash');
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    13
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    14
var defaultOptions = {
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    15
    logger: undefined,
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    16
    intervalWidth: 10,
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    17
    intervalHeight: 5,
102
cc7b06bfd574 update to circle representation
rougeronj
parents: 100
diff changeset
    18
    maxCellHeight: 200,
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    19
    radius: 300,
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    20
    serverUrl: 'http://127.0.0.1:8080',
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    21
    channel: 'ANNOT',
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    22
    maxPages: 1000,
128
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
    23
    showClockGraphics: true,
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
    24
    archive: false
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    25
};
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    26
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    27
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    28
function AnnotsTimeLine(options){
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    29
    var _this = this;
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    30
    var opts = _(options).defaults(defaultOptions).value();
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    31
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    32
    this.container = new PIXI.DisplayObjectContainer();
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    33
    this.container.x = opts.xInit;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    34
    this.container.y = opts.yInit;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    35
    this.container.width = opts.width;
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    36
    this.container.height = opts.height;
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    37
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    38
    this.timeBegin = opts.timeBegin;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    39
    this.timeEnd = opts.timeEnd;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    40
    this.duration = (this.timeEnd - this.timeBegin)/1000;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    41
    this.width = opts.width;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    42
    this.height = opts.height;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    43
    this.intervalHeight = opts.intervalHeight;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    44
    this.intervalWidth = opts.intervalWidth;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    45
    this.maxCellHeight = opts.maxCellHeight;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    46
    this.annotCategories = opts.annotCategories;
127
0386fb9efe27 Merge with b5697bcdbaffd1d52ea785e6276bc70422bf1286
rougeronj
parents: 126 124
diff changeset
    47
	this.startTs = options.startTs || Date.now();
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
    48
    this.showClockGraphics = opts.showClockGraphics;
128
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
    49
    this.archive = opts.archive;
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
    50
    
103
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
    51
    this.circleX = opts.circleX || (this.width/2);
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
    52
    this.circleY = opts.circleY || (this.height/2);
102
cc7b06bfd574 update to circle representation
rougeronj
parents: 100
diff changeset
    53
    this.radius = opts.radius;
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
    54
    var perimeter = 2*Math.PI* this.radius;
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
    55
    this.intervalDuration = (this.intervalWidth * this.duration / perimeter);
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
    56
    
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    57
    var channel = opts.channel;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    58
    var eventCode = opts.eventCode;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    59
    var serverUrl = opts.serverUrl;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    60
    var maxPages = opts.maxPages;
127
0386fb9efe27 Merge with b5697bcdbaffd1d52ea785e6276bc70422bf1286
rougeronj
parents: 126 124
diff changeset
    61
    
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
    62
    var totalIndex = Math.floor( perimeter/this.intervalWidth);
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    63
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    64
    this.cells = []
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
    65
    for (var i=0; i<(perimeter/this.intervalWidth) ; i++){
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
    66
    	this.cells[i] = [];
103
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
    67
    	this.cells[i].i = i;
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
    68
    	this.cells[i].totalAnnots = 0;
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
    69
    	this.cells[i].categories = {};
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
    70
    }
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    71
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    72
    var ws = opts.ws;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    73
    var stageView = opts.stageView;
102
cc7b06bfd574 update to circle representation
rougeronj
parents: 100
diff changeset
    74
103
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
    75
    //draw the base - circle and line to locate the scene
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    76
    var graphics = new PIXI.Graphics();
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
    77
    graphics.lineStyle(2, 0x646464)
103
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
    78
    	.drawCircle(this.circleX, this.circleY, this.radius - 3)
102
cc7b06bfd574 update to circle representation
rougeronj
parents: 100
diff changeset
    79
    	.endFill()
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
    80
    this.container.addChild(graphics);
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
    81
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
    82
    stageView.registerComponent(this);
97
545803e685e0 rename components
ymh <ymh.work@gmail.com>
parents: 92
diff changeset
    83
127
0386fb9efe27 Merge with b5697bcdbaffd1d52ea785e6276bc70422bf1286
rougeronj
parents: 126 124
diff changeset
    84
	var loadArchives = function() {
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    85
        //start timeBegin end startTime
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    86
        //query -> need channel + eventCode
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    87
        //iterate over data fill cells
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    88
        var startTs = _this.timeBegin;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    89
        var endTs = _this.startTs;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    90
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    91
        var url = serverUrl + '/p/api/v1/annotation';
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    92
        var filters = [
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    93
            { name: 'ts', op: '>', val: new Date(startTs).toISOString()}, //start
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    94
            { name: 'ts', op: '<=', val: new Date(endTs).toISOString()}, //end
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    95
            { name: 'channel', op: '==', val: channel}, //channel
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    96
            { name: 'event_code', op: '==', val: eventCode} //eventcode
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    97
        ];
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    98
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
    99
        url = url + '?q=' + JSON.stringify({filters:filters});
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   100
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   101
        var totalPage = 1;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   102
        var currentPage = 1;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   103
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   104
        var processResFunction = function(res) {
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   105
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   106
            if(res) {
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   107
                var data = res.target.json;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   108
                /*jshint -W069 */
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   109
                totalPage = Math.min(maxPages,parseInt(data['total_pages']));
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   110
                data.objects.forEach(function(annotation) {
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   111
                    _this.addAnnot(annotation);
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   112
                });
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   113
            }
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   114
            if(currentPage <= totalPage) {
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   115
                var jsonLoader = new PIXI.JsonLoader(url+'&page='+currentPage, true);
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   116
                jsonLoader.on('loaded', processResFunction);
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   117
                jsonLoader.load();
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   118
                currentPage++;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   119
            }
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   120
        };
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   121
        processResFunction();
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   122
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   123
    };
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   124
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   125
    //Add Annotation to the TimeLine
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   126
    this.addAnnot = function(data){
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   127
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   128
    	var ts = Date.parse(data.ts);
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   129
    	var colorsDef;
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   130
    	_(this.annotCategories).eachRight(function(cdef) {
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   131
            if(cdef.ts < ts) {
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   132
                colorsDef = cdef;
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   133
                return false;
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   134
            }
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   135
        });
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   136
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   137
    	if (this.timeEnd > ts){
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   138
	    	var i = Math.floor((ts - this.timeBegin)/(1000*this.intervalDuration));
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   139
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   140
	    	if (typeof(this.cells[i].graphics) === 'undefined'){
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   141
	    		this.initCell(this.cells[i], colorsDef);
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   142
	    	}
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   143
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   144
	    	if (typeof(colorsDef.colors[data.content.category.code]) !== 'undefined'){
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   145
	    		var annotCode = data.content.category.code;
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   146
	    	} else {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   147
	    		var annotCode = 'default';
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   148
	    	}
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   149
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   150
			this.cells[i].categories[annotCode].count += 1;
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   151
			this.cells[i].totalAnnots +=1;
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   152
			this.redrawCell(this.cells[i], colorsDef);
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   153
    	}
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   154
    };
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   155
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   156
    this.initClockGraphics = function() {
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   157
	    var tBeg = new PIXI.Text(Utils.formatTime(this.timeBegin), { font: '12pt Gothic Standard', fill: '#646464' });
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   158
	    tBeg.x = this.circleX + 15;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   159
	    tBeg.y = this.circleY - this.radius - this.maxCellHeight - 10;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   160
	    this.container.addChild(tBeg);
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   161
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   162
	    var tEnd = new PIXI.Text(Utils.formatTime(this.timeEnd), { font: '12pt Gothic Standard', fill: '#646464' });
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   163
	    tEnd.x = this.circleX - 15 - tEnd.width;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   164
	    tEnd.y = this.circleY - this.radius - this.maxCellHeight - 10;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   165
	    this.container.addChild(tEnd);
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   166
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   167
	    var t15 = new PIXI.Text(Utils.formatTime(((this.timeEnd - this.timeBegin)/4) + this.timeBegin), { font: '12pt Gothic Standard', fill: '#646464' });
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   168
	    t15.x = this.circleX + this.radius + this.maxCellHeight + 10 ;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   169
	    t15.y = this.circleY - t15.height;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   170
	    t15.rotation = Math.PI /2;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   171
	    this.container.addChild(t15);
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   172
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   173
	    var t30 = new PIXI.Text(Utils.formatTime(((this.timeEnd - this.timeBegin)/2) + this.timeBegin), { font: '12pt Gothic Standard', fill: '#646464' });
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   174
	    t30.x = this.circleX - t30.width/2;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   175
	    t30.y = this.circleY + this.radius + this.maxCellHeight - 2;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   176
	    this.container.addChild(t30);
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   177
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   178
	    var t45 = new PIXI.Text(Utils.formatTime(((this.timeEnd - this.timeBegin)*3/4) + this.timeBegin), { font: '12pt Gothic Standard', fill: '#646464' });
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   179
	    t45.x = this.circleX - this.radius - this.maxCellHeight - 10 ;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   180
	    t45.y = this.circleY + t15.height;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   181
	    t45.rotation = -Math.PI/2;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   182
	    this.container.addChild(t45);
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   183
	    
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   184
	    var lineV = new PIXI.Graphics();
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   185
	    lineV.lineStyle(1, 0x646464)
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   186
	    	.moveTo(this.circleX, this.circleY - (this.radius/3)/2)
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   187
	    	.lineTo(this.circleX, this.circleY - this.radius - this.maxCellHeight - 10)
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   188
    	.endFill();
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   189
	    this.container.addChild(lineV);
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 103
diff changeset
   190
    }
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   191
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   192
    //Draw the cellule
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   193
    this.redrawCell = function(cell, colorsDef){
102
cc7b06bfd574 update to circle representation
rougeronj
parents: 100
diff changeset
   194
    	var y = 0;
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   195
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   196
        //Check if total height is higher than Max Cell Height
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   197
        var heightStep;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   198
        if ((cell.totalAnnots*this.intervalHeight) > this.maxCellHeight){
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   199
            heightStep = this.maxCellHeight/cell.totalAnnots;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   200
        } else {
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   201
            heightStep = this.intervalHeight;
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   202
        }
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   203
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   204
    	//Draw the rect depending on the height step calculated
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   205
    	for (var i=0; i< colorsDef.order.length; i++){
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   206
    		var currentCode = colorsDef.order[i];
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   207
			cell.graphics.beginFill(cell.categories[currentCode].color.replace("#", "0x"))
103
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
   208
    			.drawRect(0, y, this.intervalWidth-1, -cell.categories[currentCode].count * heightStep)
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   209
    			.endFill();
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   210
    		y -= cell.categories[currentCode].count*heightStep;
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   211
    	}
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents: 92
diff changeset
   212
    }
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   213
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   214
    this.initCell = function(cell, colorsDef){
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   215
    	cell.graphics = new PIXI.Graphics();
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   216
    	cell.graphics.position.x = this.circleX + this.radius * Math.sin(cell.i*(360/totalIndex)*(Math.PI/180));
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   217
    	cell.graphics.position.y = this.circleY - this.radius * Math.cos(cell.i*(360/totalIndex)*(Math.PI/180));
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   218
    	cell.graphics.rotation = (cell.i)*(360/totalIndex)*(Math.PI/180) + (360/(totalIndex*2))*(Math.PI/180);
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   219
    	this.container.addChild(cell.graphics);
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   220
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   221
    	for (var category in colorsDef.colors){
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   222
    		cell.categories[category] = {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   223
				"count": 0,
123
d8ef840eaf68 get the correct json category depending on the timestamp
rougeronj
parents: 121
diff changeset
   224
				"color": colorsDef.colors[category]
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   225
    		};
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   226
    	}
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   227
    	if (typeof(cell.categories['default']) === 'undefined'){
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   228
			cell.categories['default'] = {
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   229
				"count": 0,
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   230
				"color": colorsDef.defaultColor
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   231
			}
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   232
    	}
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 114
diff changeset
   233
    }
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   234
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   235
    this.init = function() {
128
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
   236
    	if (!this.archive){
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
   237
	        ws.message(function(data) {
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
   238
	            _this.addAnnot(data);
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
   239
	        });
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
   240
    	}
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   241
126
13d9a532a0a7 Add timeline of the 2nd day - take out from the clock annotstimeline and put it in annotsvizview - make the clocks graphics optional through showClockGraphics
rougeronj
parents: 123
diff changeset
   242
    	if (this.showClockGraphics){this.initClockGraphics();}
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   243
    };
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   244
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   245
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   246
    this.start = function() {
128
9f2334598088 add archive variable to desactivate the socket listening for the static timeLines
rougeronj
parents: 127
diff changeset
   247
    	this.startTs = Date.now();
124
b5697bcdbaff add history load for time lines
ymh <ymh.work@gmail.com>
parents: 123
diff changeset
   248
        loadArchives();
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
   249
    };
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   250
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   251
    this.refresh = function() {
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   252
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   253
    };
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   254
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   255
    this.stop = function(){
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   256
    };
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 105
diff changeset
   257
100
0d7dac03c1a0 Merge with 72d767c5142df7fc6387215096321295fbaaa73d
rougeronj
parents: 99 98
diff changeset
   258
    return this;
91
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
   259
}
09a9074ea7b0 Add general View fonction for main representation
rougeronj
parents:
diff changeset
   260
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   261
module.exports = {
103
123a611c7903 minor update of options and add annotsvizview
rougeronj
parents: 102
diff changeset
   262
	AnnotsTimeLine: AnnotsTimeLine
98
72d767c5142d refactor and make work annotsroll
ymh <ymh.work@gmail.com>
parents: 97
diff changeset
   263
};