client/annotviz/app/js/utils.js
author rougeronj
Thu, 22 Jan 2015 15:03:58 +0100
changeset 121 df6b39f962bc
parent 105 25ac8802c189
child 122 3b11017a76a4
permissions -rw-r--r--
Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     1
/**
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     2
* js/utils.js
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     3
*
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     4
* basic tools
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     5
*
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     6
*/
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     7
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     8
'use strict';
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
     9
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    10
function formatTime (ts) {
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    11
	var hours = Math.floor( (ts/1000) / 3600 ) % 24;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    12
	var minutes = Math.floor( (ts/1000) / 60 ) % 60;
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    13
	var seconds = Math.floor( (ts/1000) % 60);
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    14
	return ((hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds  < 10 ? '0' + seconds : seconds));
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    15
}
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    16
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    17
function getAnnotCategories(urlCategories, annotCategories) {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    18
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    19
    var jsonLoader = new PIXI.JsonLoader(urlCategories, true);
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    20
    
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    21
    jsonLoader.on('loaded', function(res) {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    22
        var data = res.target.json;
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    23
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    24
        while(annotCategories.length > 0) {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    25
        	annotCategories.pop();
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    26
        }
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    27
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    28
        data.sessions.forEach(function(session) {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    29
            var annotCat = {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    30
                ts: session.start_ts === null ? new Date(0) : Date.parse(session.start_ts),
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    31
                colors: {}
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    32
            }
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    33
            var categoriesJson = session.categories_json;
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    34
            annotCat.order = categoriesJson.order;
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    35
            categoriesJson.categories.forEach(function(cat) {
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    36
                annotCat.colors[cat.code] = colorToHex(cat.color);
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    37
            });
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    38
            annotCat.defaultColor = categoriesJson.defaultColor || "#536991";
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    39
            annotCategories.push(annotCat);
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    40
        });
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    41
        console.log(annotCategories);
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    42
        annotCategories[0].order.push("default");
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    43
    });
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    44
    
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    45
    jsonLoader.load();
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    46
    
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    47
}
105
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    48
25ac8802c189 Improve interface + Add horizontal pianoroll to annotsvizview
rougeronj
parents: 99
diff changeset
    49
module.exports = {
121
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    50
	formatTime: formatTime,
df6b39f962bc Add getAnnotCategories to utils and propagate the modification to annotsvizview and annotstimeline
rougeronj
parents: 105
diff changeset
    51
	getAnnotCategories: getAnnotCategories
99
9d968fbcaa2a Add General Time Line + minor change in annotsRoll
rougeronj
parents:
diff changeset
    52
};