Skip to content

Commit

Permalink
Added datasource ability to reload charts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Traistaru committed Oct 13, 2015
1 parent f7af9a5 commit 9cb3711
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ module.exports = function(RED)

if( !msg.hasOwnProperty( "payload" ) ) return;

if( typeof msg.payload == "string" && msg.payload == "reset" )
{
self.dataComponents = undefined;
self.sendToAll( JSON.stringify( {
type : "config",
id : self.id,
config : self.getDatasourceConfig()
} ) );
return;
}

// Deduce(?) data components
if( self.dataComponents === undefined )
{
Expand Down
14 changes: 12 additions & 2 deletions static/js/model/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ App.Model.Datasource = ( function() {
};

Datasource.prototype.convertData = function( data ) {
if( $.isArray( data ) )
{
for( var i = 0; i < data.length; i++ )
data[i] = this.convertDataPoint( data[i] );

return data;
}
else return this.convertDataPoint( data );
};

Datasource.prototype.convertDataPoint = function( data ) {
var converted = {
tstamp : this.tstampField == "tstamp" ? data.tstamp : this.getNestedValue( data , this.tstampField ),
data : this.dataField == "data" ? data.data : this.getNestedValue( data , this.dataField )
Expand All @@ -97,8 +108,7 @@ App.Model.Datasource = ( function() {

if( this.tstampField !== "tstamp" || this.dataField !== "data" )
{
for( var i = 0; i < data.length; i++ )
data[i] = this.convertData( data[i] );
data = this.convertData( data );
}

this.charts[ chartID ].pushData( this , data , this.historyRequests[ chartID ] );
Expand Down

0 comments on commit 9cb3711

Please sign in to comment.