summaryrefslogtreecommitdiffstats
path: root/data/templates/stats/profit_per_day.html
blob: 5af05dc173767562299430f6db016ebe4e5d5b82 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		<div id="placeholder" style="width:800px;height:400px;float: left;"></div>
		<div style="float: left;">
			<button id="resetzoom" class="btn">Reset Zoom</button>
			<br><br>
			<ul id="overviewLegend">
			</ul>
		</div>

<script type="text/javascript">
$(function () {
    var datasets = {{{DATA}}};

    // hard-code color indices to prevent them from shifting as
    // countries are turned on/off
	var i = 0, choiceContainer = $("#overviewLegend");

	$.each(datasets, function(key, val) {
		val.color = i;
		++i;
		l = val.label;
		var li = $('<li />').appendTo(choiceContainer);
		
		$('<input name="' + key + '" id="' + key + '" type="checkbox" checked="checked" />').appendTo(li);
		$('<label>', {
			text: l, 
			'for': l
		}).appendTo(li);
	});

    choiceContainer.find("input").click(plotAccordingToChoices);
    
    function plotAccordingToChoices() {
        var data = [];

        choiceContainer.find("input:checked").each(function () {
            var key = $(this).attr("name");
            if (key && datasets[key])
                data.push(datasets[key]);
        });

		var options = {
			legend: {
				show: true
			},
			series: {
				lines: { show: true },
				points: { show: true}
			},
			yaxis: { 
				mode: "money",
				tickDecimals: 2,
				tickFormatter: function suffixFormatter(val, axis) {
					return val.toFixed(axis.tickDecimals) + "€"
				}
			},
			xaxis: {
				mode: "time",
				timeformat: "%y-%0m-%0d"
			},
			zoom: {
				interactive: true
			},
			pan: {
				interactive: true
			}
		}

        if (data.length > 0)
            $.plot($("#placeholder"), data, options);
    }

    plotAccordingToChoices();

	$("#resetzoom").click(function(eventObject) { plotAccordingToChoices(); });

	$('.legendColorBox > div').each(function(i){
		$(this).clone().prependTo(choiceContainer.find("li").eq(i));
	});
});
</script>