annot-server/webapp/templates/annotviz.html
author ymh <ymh.work@gmail.com>
Thu, 22 Jan 2015 12:12:33 +0100
changeset 119 e6605fecb175
parent 113 7531e4180915
child 131 0bb70072a56f
permissions -rw-r--r--
move colorToHex to utils
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
108
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<html>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
<head>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
    <meta charset="UTF-8">
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    <title>Piano Roll {{event.label}}</title>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    <link href="{{ config['STATIC_URL'] }}/css/annotviz.min.css" rel="stylesheet">
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
</head>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
<body>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    <h1>Piano Roll {{event.label}}</h1>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    <noscript>You must enable JavaScript</noscript>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    <div id="canvasContainer"></div>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    <p>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
        <a href="#" onclick="stop(); return false;">stop intervals</a> -
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
        <a href="#" onclick="start(); return false;">start intervals</a> -
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
        temps écoulé : <span id="timeStarted"></span>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    </p>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    <pre id="log"></pre>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    <script src="{{ config['STATIC_URL'] }}/js/libs-annotviz.min.js"></script>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    <script src="{{ config['STATIC_URL'] }}/js/annotviz.min.js"></script>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    <script>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    var PIXI = require('pixi');
110
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    22
    var annotCategories = [
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    23
        {
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    24
            "ts": 1421928213000,
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    25
            "colors": {
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    26
                "transgressions": "#b90000",
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    27
                "rythmique": "#af931e",
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    28
                "narration": "#4bdd71",
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    29
                "relation": "#1c28ba"
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    30
            },
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    31
            "order": [
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    32
                "transgressions",
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    33
                "rythmique",
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    34
                "narration",
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    35
                "relation"
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    36
            ],
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    37
            "defaultColor": "#536991"
108
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        }
110
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    39
    ];
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    40
108
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    function getAnnotCategories(ecode, serverUrl) {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        var url = serverUrl+"/p/api/v1/event/" + ecode;
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
        var jsonLoader = new PIXI.JsonLoader(url, true);
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
        jsonLoader.on('loaded', function(res) {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
            var data = res.target.json;
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
            while(annotCategories.length > 0) {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
                annotCategories.pop();
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
            }
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
            data.sessions.forEach(function(session) {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
                var annotCat = {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
                    ts: session.start_ts === null ? new Date(0) : Date.parse(session.start_ts),
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
                    colors: {}
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
                }
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
                var categoriesJson = session.categories_json;
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
                annotCat.order = categoriesJson.order;
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
                categoriesJson.categories.forEach(function(cat) {
119
e6605fecb175 move colorToHex to utils
ymh <ymh.work@gmail.com>
parents: 113
diff changeset
    61
                    annotCat.colors[cat.code] = annotviz.colorToHex(cat.color);
108
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
                });
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
                annotCat.defaultColor = categoriesJson.defaultColor || "#536991";
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
                annotCategories.push(annotCat);
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
            });
110
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 108
diff changeset
    66
            console.log(JSON.stringify(annotCategories, null, '  '));
108
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        });
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        jsonLoader.load();
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
    }
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    var pianorollChannel  = 'PIANOROLL';
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    var annotationChannel = 'ANNOT';
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    var eventCode = '{{event.code}}';
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    getAnnotCategories(eventCode, 'http://' + window.location.hostname + ':8080');
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    var wsUri = 'ws://' + window.location.hostname + ':8090/broadcast';
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    wsUriPianoroll = wsUri + '?channel=' + pianorollChannel + '&event_code=' + eventCode;
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    wsUriAnnotation = wsUri + '?channel=' + annotationChannel + '&event_code=' + eventCode;
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    var logger = new annotviz.ConsoleLogger(true);
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
    var stageView = new annotviz.StageView({
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        logger: logger
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
    });
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
    var annotsvizview = new annotviz.AnnotsVizView({
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
        logger: logger,
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
        stageView: stageView,
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
        wsPianoroll: new annotviz.WsWrapper(wsUriPianoroll, logger),
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
        wsAnnot: new annotviz.WsWrapper(wsUriAnnotation, logger),
113
7531e4180915 Minor time correction
rougeronj
parents: 110
diff changeset
    95
        annotCategories: annotCategories,
7531e4180915 Minor time correction
rougeronj
parents: 110
diff changeset
    96
        timeBegin: 1421919000000,
7531e4180915 Minor time correction
rougeronj
parents: 110
diff changeset
    97
    	timeEnd: 1421951400000
108
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
    });
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    function stop() {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
        stageView.stop();
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
    }
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
    function start() {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        stageView.start();
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    }
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    window.onload = function() {
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
        stageView.init();
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
        start();
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
    }
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
</script>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
</body>
082b64a5c699 add vizualizations to server
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
</html>