aboutsummaryrefslogtreecommitdiffstats
path: root/python/risk_insight/static/indices.js
blob: d3cc002a0a3668c5c88a2f6cd47d546abea0b69a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function update_graph(g) {
    return function(e) {
	      var payload = {i: document.getElementById('index').value,
		                   s: document.getElementById('series').value,
		                   t: document.getElementById('tenor').value,
                       w: document.getElementById('what').value};
	      $.getJSON("_data_indices",
		              payload,
		              function(data){
		                  var newdata = data["data"].map(function(e){
			                    f = e.slice(1);
			                    f.unshift(new Date(e[0]));
			                    return f});
		                  g.updateOptions({'file': newdata, 'labels': data['labels']});
		              });
    }
};

document.addEventListener("DOMContentLoaded", function(event) {
    var g = new Dygraph(document.getElementById("graph"),
		                    [], // path to CSV file
		                { labels: [],
		                  title: "Index quotes",
		                  showRoller: true,
		                  legend: "always"});
    ["index", "series", "tenor", "what"].forEach(function(id) {
        document.getElementById(id).addEventListener('change',
                                                     update_graph(g))});
    var event = new Event('change');
    document.getElementById('index').dispatchEvent(event);

});