@ -158,6 +158,15 @@ function threeDlineGraph(type, xChartData, yChartData, zChartData) {
graph : graph
} ) ;
new Rickshaw . Graph . HoverDetail ( {
graph : graph ,
formatter : function ( series , x , y ) {
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>' ;
return swatch + series . name + ": " + parseInt ( y ) + '<br>' + date ;
}
} ) ;
graph . render ( ) ;
return graph ;
@ -234,58 +243,61 @@ function connect(target) {
if ( ws ) {
ws . onmessage = function ( event ) {
var dataPoint = JSON . parse ( event . data ) ;
if ( dataPoint ) {
var time = parseInt ( dataPoint [ 4 ] ) / 1000 ;
switch ( dataPoint [ typeId ] ) {
case "battery" :
graphUpdate ( batteryData , time , dataPoint [ batteryId ] , graphMap [ "battery" ] ) ;
graphUpdate ( batteryData , time , dataPoint [ batteryId ] ) ;
graphMap [ "battery" ] . update ( ) ;
break ;
case "light" :
graphUpdate ( lightData , time , dataPoint [ lightId ] , graphMap [ "light" ] ) ;
graphUpdate ( lightData , time , dataPoint [ lightId ] ) ;
graphMap [ "light" ] . update ( ) ;
break ;
case "pressure" :
graphUpdate ( pressureData , time , dataPoint [ pressureId ] , graphMap [ "pressure" ] ) ;
graphUpdate ( pressureData , time , dataPoint [ pressureId ] ) ;
graphMap [ "pressure" ] . update ( ) ;
break ;
case "proximity" :
graphUpdate ( proximityData , time , dataPoint [ proximityId ] , graphMap [ "proximity" ] ) ;
graphUpdate ( proximityData , time , dataPoint [ proximityId ] ) ;
graphMap [ "proximity" ] . update ( ) ;
break ;
case "accelerometer" :
data Update( accelerometer _xData , time , dataPoint [ accelerometer _xId ] ) ;
data Update( accelerometer _yData , time , dataPoint [ accelerometer _yId ] ) ;
data Update( accelerometer _zData , time , dataPoint [ accelerometer _zId ] ) ;
graph Update( accelerometer _xData , time , dataPoint [ accelerometer _xId ] ) ;
graph Update( accelerometer _yData , time , dataPoint [ accelerometer _yId ] ) ;
graph Update( accelerometer _zData , time , dataPoint [ accelerometer _zId ] ) ;
graphMap [ "accelerometer" ] . update ( ) ;
break ;
case "magnetic" :
data Update( magnetic _xData , time , dataPoint [ magnetic _xId ] ) ;
data Update( magnetic _yData , time , dataPoint [ magnetic _yId ] ) ;
data Update( magnetic _zData , time , dataPoint [ magnetic _zId ] ) ;
graph Update( magnetic _xData , time , dataPoint [ magnetic _xId ] ) ;
graph Update( magnetic _yData , time , dataPoint [ magnetic _yId ] ) ;
graph Update( magnetic _zData , time , dataPoint [ magnetic _zId ] ) ;
graphMap [ "magnetic" ] . update ( ) ;
break ;
case "gyroscope" :
data Update( gyroscope _xData , time , dataPoint [ gyroscope _xId ] ) ;
data Update( gyroscope _yData , time , dataPoint [ gyroscope _yId ] ) ;
data Update( gyroscope _zData , time , dataPoint [ gyroscope _zId ] ) ;
graph Update( gyroscope _xData , time , dataPoint [ gyroscope _xId ] ) ;
graph Update( gyroscope _yData , time , dataPoint [ gyroscope _yId ] ) ;
graph Update( gyroscope _zData , time , dataPoint [ gyroscope _zId ] ) ;
graphMap [ "gyroscope" ] . update ( ) ;
break ;
case "rotation" :
data Update( magnetic _xData , time , dataPoint [ rotation _xId ] ) ;
data Update( magnetic _yData , time , dataPoint [ rotation _yId ] ) ;
data Update( magnetic _zData , time , dataPoint [ rotation _zId ] ) ;
graph Update( magnetic _xData , time , dataPoint [ rotation _xId ] ) ;
graph Update( magnetic _yData , time , dataPoint [ rotation _yId ] ) ;
graph Update( magnetic _zData , time , dataPoint [ rotation _zId ] ) ;
graphMap [ "rotation" ] . update ( ) ;
break ;
case "gravity" :
data Update( gravity _xData , time , dataPoint [ gravity _xId ] ) ;
data Update( gravity _yData , time , dataPoint [ gravity _yId ] ) ;
data Update( gravity _zData , time , dataPoint [ gravity _zId ] ) ;
graph Update( gravity _xData , time , dataPoint [ gravity _xId ] ) ;
graph Update( gravity _yData , time , dataPoint [ gravity _yId ] ) ;
graph Update( gravity _zData , time , dataPoint [ gravity _zId ] ) ;
graphMap [ "gravity" ] . update ( ) ;
break ;
}
@ -294,16 +306,7 @@ function connect(target) {
}
}
function graphUpdate ( chartData , xValue , yValue , graph ) {
chartData . push ( {
x : parseInt ( xValue ) ,
y : parseFloat ( yValue )
} ) ;
chartData . shift ( ) ;
graph . update ( ) ;
}
function dataUpdate ( chartData , xValue , yValue ) {
function graphUpdate ( chartData , xValue , yValue ) {
chartData . push ( {
x : parseInt ( xValue ) ,
y : parseFloat ( yValue )