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 Date: Thu, 20 Jun 2013 20:19:24 +0100 Subject: add extra condition suggested by trubus to take into account negative y axis --- jarmon/jarmon.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 51b1c33..a7d0adc 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -649,7 +649,8 @@ jarmon.Chart = function(template, recipe, downloader) { }; var si = 0; while(true) { - if( Math.pow(1000, si+1)*0.9 > axis.max ) { + if( Math.pow(1000, si+1)*0.9 > axis.max + && -(Math.pow(1000, si+1))*0.9 < axis.min ) { break; } si++; -- cgit v1.1-4-g5e80 From 5718df70d0af2c3ad9fb0e7b47b623f3a6e8f360 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Thu, 20 Jun 2013 23:59:41 +0100 Subject: choose best si based on total length of y axis - negative to positive. Also add a few more step sizes to graphs without any ticks. --- jarmon/jarmon.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index a7d0adc..4e58334 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -649,8 +649,7 @@ jarmon.Chart = function(template, recipe, downloader) { }; var si = 0; while(true) { - if( Math.pow(1000, si+1)*0.9 > axis.max - && -(Math.pow(1000, si+1))*0.9 < axis.min ) { + if( Math.pow(1000, si+1)*0.9 > (axis.max - axis.min) ) { break; } si++; @@ -660,7 +659,7 @@ jarmon.Chart = function(template, recipe, downloader) { var maxVal = axis.max/Math.pow(1000, si); var stepSizes = [0.01, 0.05, 0.1, 0.25, 0.5, - 1, 5, 10, 25, 50, 100, 250]; + 1, 2, 5, 10, 20, 25, 50, 100, 250]; var realStep = (maxVal - minVal)/5.0; var stepSize, decimalPlaces = 0; -- cgit v1.1-4-g5e80 From 2bff39e9b7c31f49ca02d7977d4315d6f09e1d36 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 8 Dec 2016 21:15:55 -0500 Subject: Adjust the tests to work with the new transformer interface. --- jarmon/jarmon.test.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 5f5989d..8494406 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -296,11 +296,8 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d.done( function(rrd) { self.resume(function() { - var rq = new jarmon.RrdQuery(rrd, '', self._x10transformer); - var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME); - // Make sure that the transformer is the - // function we asked for - Y.Assert.areEqual(self._x10transformer, rq.transformer); + var rq = new jarmon.RrdQuery(rrd, ''); + var data = rq.getData(RRD_STARTTIME, RRD_ENDTIME, undefined, undefined, self._x10transformer); // Real data goes 0,1,2,3... // should be transformed to 0,10,20... Y.Assert.areEqual(0, data.data[0][1]); -- cgit v1.1-4-g5e80