From 0b4e3665a016d40a1fbf47a8542cb6a022096e1c Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Fri, 14 Jun 2013 16:37:54 +0100 Subject: hack things around to allow independent ds transformers, even when they are in the same RRD file --- docs/examples/jarmon_example_recipes.js | 4 +-- jarmon/jarmon.js | 43 +++++++++++++++++---------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/docs/examples/jarmon_example_recipes.js b/docs/examples/jarmon_example_recipes.js index 7acfa8d..524515b 100644 --- a/docs/examples/jarmon_example_recipes.js +++ b/docs/examples/jarmon_example_recipes.js @@ -54,8 +54,8 @@ jarmon.CHART_RECIPES_COLLECTD = { 'interface': { title: 'Wlan0 Throughput', data: [ - ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return v*8; }], - ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }] + ['data/interface-wlan0/if_octets.rrd', 'tx', 'Transmit', 'bit/s', function (v) { return -v*8; }], + ['data/interface-wlan0/if_octets.rrd', 'rx', 'Receive', 'bit/s', function (v) { return v*8; }] ], options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS) }, diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index e4fd1dc..51b1c33 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -337,21 +337,14 @@ jarmon.localTimeFormatter = function (v, axis) { * @constructor * @param rrd {Object} A javascriptrrd.RRDFile * @param unit {String} The unit symbol for this data series - * @param transformer {Function} A callable which performs a - * tranfsformation of the values returned from the RRD file. **/ -jarmon.RrdQuery = function(rrd, unit, transformer) { +jarmon.RrdQuery = function(rrd, unit) { this.rrd = rrd; this.unit = unit; - if(typeof(transformer) !== 'undefined') { - this.transformer = transformer; - } else { - this.transformer = function(v) {return v;}; - } }; jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, - dsId, cfName) { + dsId, cfName, transformer) { /** * Generate a Flot compatible data object containing rows between start and * end time. The rows are taken from the first RRA whose data spans the @@ -363,6 +356,8 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, * @param dsId {Variant} identifier of the RRD datasource (string or number) * @param cfName {String} The name of an RRD consolidation function (CF) * eg AVERAGE, MIN, MAX + * @param transformer {Function} A callable which performs a + * tranfsformation of the values returned from the RRD file. * @return {Object} A Flot compatible data series * eg label: '', data: [], unit: '' **/ @@ -392,6 +387,10 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, cfName = 'AVERAGE'; } + if(typeof(transformer) === 'undefined') { + transformer = function(v) {return v;}; + } + var rra, step, rraRowCount, lastRowTime, firstRowTime; for(var i=0; i