aboutsummaryrefslogtreecommitdiff
path: root/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl
blob: 0ca810869a70f528cba7c6af89bcb6a5b4f21076 (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
function graph_init(field) {
	var graph_config = {
		type: 'line',
		data: {
			labels: graph_labels[field],
			datasets: [
				{
					label: field,
					data: graph_data[field],
				},
			],
			fill: false,
			steppedLine: false,
		},
		options: {
			responsive: true,
			title: {
				display:true,
				text:'{{ trans("Sample") }}'
			},
			tooltips: {
				mode: 'index',
				intersect: false,
			},
			hover: {
				mode: 'nearest',
				intersect: true
			},
			scales: {
				xAxes: [{
					display: true,
					scaleLabel: {
						display: true,
						labelString: '{{ trans("Time") }}'
					}
				}],
				yAxes: [{
					display: true,
					scaleLabel: {
						display: true,
						labelString: '{{ trans("Value") }}'
					}
				}],
			},
		},
	};
	if (field == "voltage") {
		graph_config.options.scales.yAxes[0].ticks = { min: 10, max: 15 }
	} else if (field == "light" || field == "temperature") {
		graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 250 }
	} else if (field == "light" || field == "temperature") {
		graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 100 }
	}
	var graph_ctx = document.getElementById("canvas-" + field).getContext("2d");
	Foris.lineChart[field] = new Chart(graph_ctx, graph_config);
	Foris.lineChartData[field] = graph_config.data;
}

$(document).ready(function() {
	Foris.lineChart = [];
	Foris.lineChartData = [];
	graph_init("voltage");
	graph_init("light");
	graph_init("temperature");
	graph_init("trimmer");
});

/*
Foris.WS["i2c-collect"] = function (data) {
	for (d in data) {
		Foris.lineChartData[d].datasets[0].data.push(data[d][0]);
		Foris.lineChartData[d].datasets[0].data.shift();
		Foris.lineChartData[d].labels.push(data[d][1]);
		Foris.lineChartData[d].labels.shift();
		Foris.lineChart[d].update();
	}
};
*/