|
|
@ -24,71 +24,68 @@ var temperatureData = [];
|
|
|
|
var humidity;
|
|
|
|
var humidity;
|
|
|
|
var humidityData = [];
|
|
|
|
var humidityData = [];
|
|
|
|
|
|
|
|
|
|
|
|
var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
|
|
|
|
//var palette = new Rickshaw.Color.Palette({scheme: "classic9"});
|
|
|
|
|
|
|
|
|
|
|
|
$(window).load(function () {
|
|
|
|
$(window).load(function () {
|
|
|
|
|
|
|
|
|
|
|
|
temperature = lineGraph("temperature", temperatureData);
|
|
|
|
|
|
|
|
humidity = lineGraph("humidity", humidityData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var websocketUrl = $("#div-chart").data("websocketurl");
|
|
|
|
var websocketUrl = $("#div-chart").data("websocketurl");
|
|
|
|
connect(websocketUrl)
|
|
|
|
connect(websocketUrl);
|
|
|
|
|
|
|
|
updateCoffee(20);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(window).unload(function () {
|
|
|
|
$(window).unload(function () {
|
|
|
|
disconnect();
|
|
|
|
disconnect();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function lineGraph(type, chartData) {
|
|
|
|
//function lineGraph(type, chartData) {
|
|
|
|
var tNow = new Date().getTime() / 1000;
|
|
|
|
// var tNow = new Date().getTime() / 1000;
|
|
|
|
for (var i = 0; i < 30; i++) {
|
|
|
|
// for (var i = 0; i < 30; i++) {
|
|
|
|
chartData.push({
|
|
|
|
// chartData.push({
|
|
|
|
x: tNow - (30 - i) * 15,
|
|
|
|
// x: tNow - (30 - i) * 15,
|
|
|
|
y: parseFloat(0)
|
|
|
|
// y: parseFloat(0)
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
var graph = new Rickshaw.Graph({
|
|
|
|
// var graph = new Rickshaw.Graph({
|
|
|
|
element: document.getElementById("chart-" + type),
|
|
|
|
// element: document.getElementById("chart-" + type),
|
|
|
|
width: $("#div-chart").width() - 50,
|
|
|
|
// width: $("#div-chart").width() - 50,
|
|
|
|
height: 300,
|
|
|
|
// height: 300,
|
|
|
|
renderer: "line",
|
|
|
|
// renderer: "line",
|
|
|
|
padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2},
|
|
|
|
// padding: {top: 0.2, left: 0.0, right: 0.0, bottom: 0.2},
|
|
|
|
xScale: d3.time.scale(),
|
|
|
|
// xScale: d3.time.scale(),
|
|
|
|
series: [{
|
|
|
|
// series: [{
|
|
|
|
'color': palette.color(),
|
|
|
|
// 'color': palette.color(),
|
|
|
|
'data': chartData,
|
|
|
|
// 'data': chartData,
|
|
|
|
'name': type && type[0].toUpperCase() + type.slice(1)
|
|
|
|
// 'name': type && type[0].toUpperCase() + type.slice(1)
|
|
|
|
}]
|
|
|
|
// }]
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
graph.render();
|
|
|
|
// graph.render();
|
|
|
|
|
|
|
|
//
|
|
|
|
var xAxis = new Rickshaw.Graph.Axis.Time({
|
|
|
|
// var xAxis = new Rickshaw.Graph.Axis.Time({
|
|
|
|
graph: graph
|
|
|
|
// graph: graph
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
xAxis.render();
|
|
|
|
// xAxis.render();
|
|
|
|
|
|
|
|
//
|
|
|
|
new Rickshaw.Graph.Axis.Y({
|
|
|
|
// new Rickshaw.Graph.Axis.Y({
|
|
|
|
graph: graph,
|
|
|
|
// graph: graph,
|
|
|
|
orientation: 'left',
|
|
|
|
// orientation: 'left',
|
|
|
|
height: 300,
|
|
|
|
// height: 300,
|
|
|
|
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
|
|
|
|
// tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
|
|
|
|
element: document.getElementById('y_axis-' + type)
|
|
|
|
// element: document.getElementById('y_axis-' + type)
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
new Rickshaw.Graph.HoverDetail({
|
|
|
|
// new Rickshaw.Graph.HoverDetail({
|
|
|
|
graph: graph,
|
|
|
|
// graph: graph,
|
|
|
|
formatter: function (series, x, y) {
|
|
|
|
// formatter: function (series, x, y) {
|
|
|
|
var date = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
|
|
|
// var date = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
|
|
|
|
var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
|
|
|
|
// var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
|
|
|
|
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
|
|
|
// return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
return graph;
|
|
|
|
// return graph;
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//websocket connection
|
|
|
|
//websocket connection
|
|
|
|
function connect(target) {
|
|
|
|
function connect(target) {
|
|
|
@ -112,12 +109,7 @@ function connect(target) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function graphUpdate(chartData, xValue, yValue, graph) {
|
|
|
|
function graphUpdate(chartData, xValue, yValue, graph) {
|
|
|
|
chartData.push({
|
|
|
|
updateCoffee(xValue);
|
|
|
|
x: parseInt(xValue),
|
|
|
|
|
|
|
|
y: parseFloat(yValue)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
chartData.shift();
|
|
|
|
|
|
|
|
graph.update();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function disconnect() {
|
|
|
|
function disconnect() {
|
|
|
|