-function Graph(container, id, options, transform) {
+function Graph(container, id, options, transform, legend) {
if( !options ) options = { };
this.id = id;
this.options = options;
this.transform = transform;
this.dataset = {};
-
+ this.legend = legend;
+ this.lastvalue = {};
+
+ var name = (options.instanceNames && options.instanceNames[id])
+ ? options.instanceNames[id] : id;
var graph = document.createElement('div');
var label = document.createElement('h2');
label.innerHTML = options.title
- ? options.title.replace("%s", id ) : id;
+ ? options.title.replace("%s", name) : name;
container.appendChild( label );
container.appendChild( graph );
value = Math.abs( parseFloat(value) || 0 );
if( this.transform ) {
- value = ( ds[this.cols-1][1] > 0 )
- ? this.transform(value, ds[this.cols-1][1]) : 0.01;
+ var orgvalue = value;
+ value = (this.lastvalue[name]) ? this.transform(value, this.lastvalue[name]) : 0;
+ this.lastvalue[name] = orgvalue;
}
ds[this.cols-1][1] = value;
this.layout.evaluate();
this.plotter.render();
+
+ legend_opt = {
+ "legendStyle": 'li'
+ };
+
+ legend = new LegendRenderer(this.legend, this.layout, legend_opt);
+ legend.render();
}
}
}
-function GraphRPC(container, uri, action, interval, datasources, options, transform) {
+function GraphRPC(container, uri, action, interval, datasources, options, transform, legend) {
this.ds = datasources;
this.uri = uri
this.action = action;
this.transform = transform;
this.proxy = new MochiKit.JsonRpc.JsonRpcProxy(uri, [action]);
this.graphs = new Object();
+ this.legend = legend;
this.requestData();
if( !this.graphs[gid] ) {
this.options.title = otle.replace('%s', instance) + ': ' + name;
this.graphs[gid] = new Graph(
- this.container, gid, this.options, this.transform
+ this.container, gid, this.options, this.transform, this.legend
);
this.graphs[gid].addDataset(name);
}
else
{
- this.graphs[gid].updateDataset(
- name, instance
+ var datum = null;
+ if (typeof (this.ds[i]) == "function") {
+ datum = this.ds[i](
+ instance ? response[instance] : response
+ );
+ } else {
+ datum = instance
? response[instance][this.ds[i]]
: response[this.ds[i]]
+ }
+ this.graphs[gid].updateDataset(
+ name, datum
);
this.graphs[gid].redraw();
}
var gid = instance || 'livegraph';
if( !this.graphs[gid] ) {
this.graphs[gid] = new Graph(
- this.container, gid, this.options, this.transform
+ this.container, gid, this.options, this.transform, this.legend
);
for( var i = 0; i < this.ds.length; i += 2 ) {
else {
for( var i = 0; i < this.ds.length; i += 2 ) {
var name = this.ds[i+1] || this.ds[i];
- this.graphs[gid].updateDataset(
- name, instance
+ var datum = null;
+ if (typeof (this.ds[i]) == "function") {
+ datum = this.ds[i](
+ instance ? response[instance] : response
+ );
+ } else {
+ datum = instance
? response[instance][this.ds[i]]
: response[this.ds[i]]
+ }
+ this.graphs[gid].updateDataset(
+ name, datum
);
}