client/annotviz/app/js/utils.js
changeset 127 0386fb9efe27
parent 124 b5697bcdbaff
child 125 f9dd7bfed997
child 128 9f2334598088
equal deleted inserted replaced
126:13d9a532a0a7 127:0386fb9efe27
     4 * basic tools
     4 * basic tools
     5 *
     5 *
     6 */
     6 */
     7 
     7 
     8 'use strict';
     8 'use strict';
       
     9 
       
    10 var PIXI = require('pixi');
       
    11 var _ = require('lodash');
     9 
    12 
    10 function formatTime (ts) {
    13 function formatTime (ts) {
    11 	var hours = Math.floor( (ts/1000) / 3600 ) % 24;
    14 	var hours = Math.floor( (ts/1000) / 3600 ) % 24;
    12 	var minutes = Math.floor( (ts/1000) / 60 ) % 60;
    15 	var minutes = Math.floor( (ts/1000) / 60 ) % 60;
    13 	var seconds = Math.floor( (ts/1000) % 60);
    16 	var seconds = Math.floor( (ts/1000) % 60);
    20 }
    23 }
    21 
    24 
    22 function getAnnotCategories(urlCategories, annotCategories) {
    25 function getAnnotCategories(urlCategories, annotCategories) {
    23 
    26 
    24     var jsonLoader = new PIXI.JsonLoader(urlCategories, true);
    27     var jsonLoader = new PIXI.JsonLoader(urlCategories, true);
    25     
    28 
    26     jsonLoader.on('loaded', function(res) {
    29     jsonLoader.on('loaded', function(res) {
    27         var data = res.target.json;
    30         var data = res.target.json;
    28 
    31 
    29         while(annotCategories.length > 0) {
    32         while(annotCategories.length > 0) {
    30         	annotCategories.pop();
    33         	annotCategories.pop();
    35                 ts: session.start_ts === null ? new Date(0) : Date.parse(session.start_ts),
    38                 ts: session.start_ts === null ? new Date(0) : Date.parse(session.start_ts),
    36                 colors: {}
    39                 colors: {}
    37             }
    40             }
    38             var categoriesJson = session.categories_json;
    41             var categoriesJson = session.categories_json;
    39             annotCat.order = categoriesJson.order;
    42             annotCat.order = categoriesJson.order;
       
    43 			var catList = _.clone(categoriesJson.categories);
       
    44 			while(catList.length > 0) {
       
    45 				var cat = catList.pop();
       
    46 				if(cat.code) {
       
    47 					annotCat.colors[cat.code] = colorToHex(cat.color);
       
    48 				}
       
    49 				if(cat.subcategories) {
       
    50 					catList = catList.concat(cat.subcategories);
       
    51 				}
       
    52 			}
    40             categoriesJson.categories.forEach(function(cat) {
    53             categoriesJson.categories.forEach(function(cat) {
    41                 annotCat.colors[cat.code] = colorToHex(cat.color);
    54 				if(cat.code) {
       
    55                 	annotCat.colors[cat.code] = colorToHex(cat.color);
       
    56 				}
    42             });
    57             });
    43             annotCat.defaultColor = categoriesJson.defaultColor || "#536991";
    58             annotCat.defaultColor = categoriesJson.defaultColor || "#536991";
    44             annotCategories.push(annotCat);
    59             annotCategories.push(annotCat);
    45         });
    60         });
    46         console.log(annotCategories);
    61         console.log(annotCategories);
    47         annotCategories[0].order.push("default");
    62         annotCategories[0].order.push("default");
    48     });
    63     });
    49     
    64 
    50     jsonLoader.load();
    65     jsonLoader.load();
    51     
    66 
    52 }
    67 }
    53 
    68 
    54 module.exports = {
    69 module.exports = {
    55 	formatTime: formatTime,
    70 	formatTime: formatTime,
    56 	getAnnotCategories: getAnnotCategories,
    71 	getAnnotCategories: getAnnotCategories,