diff options
author | Richard Wall <richard@largo> | 2011-08-08 01:01:50 +0100 |
---|---|---|
committer | Richard Wall <richard@largo> | 2011-08-08 01:01:50 +0100 |
commit | b404903c1d43af270a0349890f439b4e0637831e (patch) | |
tree | 9e5f03b721a8798e25ebab8d87402a15e1f9966f | |
parent | 2943b57c109cb233e93100dfe35c693fb286854b (diff) | |
parent | 4b7012e0ed9b0bb2b319b78e3e816feb52d1ace6 (diff) |
Merge lp:~richardw/jarmon/prerelease-fixesv11.8
* Add transformer function option to allow optional transformation of RRD values before they are plotted
* Update dates of copyright notices
* Remove DNS reports from example page
* Remove unfinished editable graph controls - I will try and finish those off later.
-rw-r--r-- | LICENSE | 3 | ||||
-rw-r--r-- | docs/examples/index.html | 4 | ||||
-rw-r--r-- | docs/examples/jarmon_example_recipes.js | 32 | ||||
-rw-r--r-- | jarmon/jarmon.js | 143 | ||||
-rw-r--r-- | jarmon/jarmon.test.js | 2 | ||||
-rw-r--r-- | jarmonbuild/commands.py | 3 |
6 files changed, 38 insertions, 149 deletions
@@ -1,4 +1,5 @@ -Copyright (c) 2010 Richard Wall <richard (at) the-moon.net> +Copyright (c) 2010-2011 +Richard Wall <richard (at) the-moon.net> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/docs/examples/index.html b/docs/examples/index.html index 14559e3..6873fd1 100644 --- a/docs/examples/index.html +++ b/docs/examples/index.html @@ -62,10 +62,6 @@ <div class="chart-container"> <div class="chart-header"> <h2 class="title"></h2> - <div class="chart-controls"> - <input type="button" name="chart_edit" value="edit"> - <input type="button" name="chart_delete" value="delete"> - </div> </div> <div class="error"></div> <div class="chart"></div> diff --git a/docs/examples/jarmon_example_recipes.js b/docs/examples/jarmon_example_recipes.js index 610ecb2..aa42d6f 100644 --- a/docs/examples/jarmon_example_recipes.js +++ b/docs/examples/jarmon_example_recipes.js @@ -1,18 +1,17 @@ -/* Copyright (c) 2010 Richard Wall <richard (at) the-moon.net> +/* Copyright (c) Richard Wall * See LICENSE for details. * * Some example recipes for Collectd RRD data - you *will* need to modify this * based on the RRD data available on your system. */ -if(typeof jarmon == 'undefined') { +if(typeof(jarmon) === 'undefined') { var jarmon = {}; } jarmon.TAB_RECIPES_STANDARD = [ ['System', ['cpu', 'memory','load']], - ['Network', ['interface']], - ['DNS', ['dns_query_types', 'dns_return_codes']] + ['Network', ['interface']] ]; jarmon.CHART_RECIPES_COLLECTD = { @@ -42,27 +41,6 @@ jarmon.CHART_RECIPES_COLLECTD = { jarmon.Chart.STACKED_OPTIONS) }, - 'dns_query_types': { - title: 'DNS Query Types', - data: [ - ['data/dns/dns_qtype-A.rrd', 0, 'A', 'Q/s'], - ['data/dns/dns_qtype-PTR.rrd', 0, 'PTR', 'Q/s'], - ['data/dns/dns_qtype-SOA.rrd', 0, 'SOA', 'Q/s'], - ['data/dns/dns_qtype-SRV.rrd', 0, 'SRV', 'Q/s'] - ], - options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS) - }, - - 'dns_return_codes': { - title: 'DNS Return Codes', - data: [ - ['data/dns/dns_rcode-NOERROR.rrd', 0, 'NOERROR', 'Q/s'], - ['data/dns/dns_rcode-NXDOMAIN.rrd', 0, 'NXDOMAIN', 'Q/s'], - ['data/dns/dns_rcode-SERVFAIL.rrd', 0, 'SERVFAIL', 'Q/s'] - ], - options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS) - }, - 'load': { title: 'Load Average', data: [ @@ -76,8 +54,8 @@ jarmon.CHART_RECIPES_COLLECTD = { 'interface': { title: 'Wlan0 Throughput', data: [ - ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'b/s'], - ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'b/s'] + ['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; }] ], options: jQuery.extend(true, {}, jarmon.Chart.BASE_OPTIONS) } diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 677a817..d8cf305 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -1,5 +1,5 @@ /** - * Copyright (c) 2010 Richard Wall <richard (at) the-moon.net> + * Copyright (c) Richard Wall * See LICENSE for details. * * Wrappers and convenience fuctions for working with the javascriptRRD, jQuery, @@ -337,10 +337,17 @@ 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) { +jarmon.RrdQuery = function(rrd, unit, transformer) { 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, @@ -443,7 +450,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, var val; var timestamp = startRowTime; for(i=startRowIndex; i<endRowIndex; i++) { - val = rra.getEl(i, dsIndex); + val = this.transformer(rra.getEl(i, dsIndex)); flotData.push([timestamp*1000.0, val]); timestamp += step; } @@ -480,11 +487,19 @@ jarmon.RrdQuery.prototype.getDSNames = function() { * @param unit {String} The unit suffix of this data eg 'bit/sec' * @param downloader {Function} A callable which returns a Deferred and calls * back with a javascriptrrd.BinaryFile when it has downloaded. + * @param transformer {Function} A callable which performs a + * tranfsformation of the values returned from the RRD file. **/ -jarmon.RrdQueryRemote = function(url, unit, downloader) { +jarmon.RrdQueryRemote = function(url, unit, downloader, transformer) { this.url = url; this.unit = unit; - this.downloader = downloader || jarmon.downloadBinary; + if(typeof(downloader) == 'undefined') { + this.downloader = jarmon.downloadBinary; + } else { + this.downloader = downloader; + } + this.transformer = transformer; + this.lastUpdate = 0; this._download = null; }; @@ -657,7 +672,7 @@ jarmon.Chart = function(template, recipe, downloader) { } } - if(self.options.yaxis.tickDecimals !== null) { + if(typeof(self.options.yaxis.tickDecimals) === 'number') { decimalPlaces = self.options.yaxis.tickDecimals; } @@ -693,10 +708,11 @@ jarmon.Chart.prototype.setup = function() { } var label = recipe.data[j][2]; var unit = recipe.data[j][3]; + var transformer = recipe.data[j][4]; if(typeof(dataDict[rrd]) === 'undefined') { dataDict[rrd] = new jarmon.RrdQueryRemote( - rrd, unit, this.downloader); + rrd, unit, this.downloader, transformer); } this.addData(label, new jarmon.RrdQueryDsProxy(dataDict[rrd], ds)); } @@ -813,10 +829,10 @@ jarmon.Chart.prototype.draw = function() { var yaxisUnitLabel = $('<div>') .text(self.siPrefix + unit) - .css({width: '100px', - position: 'absolute', - top: '80px', - left: '-90px', + .css({'width': '100px', + 'position': 'absolute', + 'top': '80px', + 'left': '-110px', 'text-align': 'right'}); self.template.find('.chart').append(yaxisUnitLabel); @@ -1178,16 +1194,6 @@ jarmon.TabbedInterface = function($tpl, recipe) { this.placeholders = []; this.$tabBar = $('<ul/>', {'class': 'css-tabs'}).appendTo($tpl); - - // Icon and hidden input box for adding new tabs. See event handlers below. - this.$newTabControls = $('<li/>', { - 'class': 'newTabControls', - 'title': 'Add new tab' - }).append( - $('<img/>', {src: 'assets/icons/next.gif'}), - $('<input/>', {'type': 'text'}).hide() - ).appendTo(this.$tabBar); - this.$tabPanels = $('<div/>', {'class': 'css-panes charts'}).appendTo($tpl); var tabName, $tabPanel, placeNames; for(var i=0; i<recipe.length; i++) { @@ -1203,88 +1209,6 @@ jarmon.TabbedInterface = function($tpl, recipe) { } this.setup(); - - // Show the new tab name input box when the user clicks the new tab icon - $('ul.css-tabs > li.newTabControls > img', $tpl[0]).live( - 'click', - function(e) { - $(this).hide().siblings().show().focus(); - } - ); - - // When the "new" tab input loses focus, use its value to create a new - // tab. - // XXX: Due to event bubbling, this event seems to be triggered twice, but - // only when the input is forcefully blurred by the "keypress" event handler - // below. To prevent two tabs, we blank the input field value. Tried - // preventing event bubbling, but there seems to be some subtle difference - // with the use of jquery live event handlers. - $('ul.css-tabs > li.newTabControls > input', $tpl[0]).live( - 'blur', - {self: this}, - function(e) { - var self = e.data.self; - var value = this.value; - this.value = ''; - $(this).hide().siblings().show(); - if(value) { - self.newTab(value); - self.setup(); - self.$tabBar.data("tabs").click(value); - } - } - ); - - // Unfocus the input element when return key is pressed. Triggers a - // blur event which then replaces the input with a tab - $('ul.css-tabs > li > input', $tpl[0]).live( - 'keypress', - function(e) { - if(e.which === 13) { - $(this).blur(); - } - } - ); - - // Show tab name input box when tab is double clicked. - $('ul.css-tabs > li > a', $tpl[0]).live( - 'dblclick', - {self: this}, - function(e) { - var $originalLink = $(this); - var $input = $('<input/>', { - 'value': $originalLink.text(), - 'name': 'editTabTitle', - 'type': 'text' - }); - $originalLink.replaceWith($input); - $input.focus(); - } - ); - - // Handle the updating of the tab when its name is edited. - $('ul.css-tabs > li > input[name=editTabTitle]', $tpl[0]).live( - 'blur', - {self: this}, - function(e) { - var self = e.data.self; - $(this).replaceWith( - $('<a/>', { - href: ['#', this.value].join('') - }).text(this.value) - ); - self.setup(); - self.$tabBar.data("tabs").click(this.value); - } - ); - - $('input[name=add_new_chart]', $tpl[0]).live( - 'click', - {self: this}, - function(e) { - console.log(e); - } - ); }; jarmon.TabbedInterface.prototype.newTab = function(tabName) { @@ -1294,29 +1218,18 @@ jarmon.TabbedInterface.prototype.newTab = function(tabName) { ).appendTo(this.$tabBar); var $placeholder = $('<div/>'); // Add tab panel - $('<div/>').append( - $placeholder, - $('<div/>', {'class': 'tab-controls'}).append( - $('<input/>', { - type: 'button', - value: 'Add new chart', - name: 'add_new_chart' - }) - ) - ).appendTo(this.$tabPanels); + $('<div/>').append($placeholder).appendTo(this.$tabPanels); return $placeholder; }; jarmon.TabbedInterface.prototype.setup = function() { - this.$newTabControls.remove(); // Destroy then re-initialise the jquerytools tabs plugin var api = this.$tabBar.data("tabs"); if(api) { api.destroy(); } this.$tabBar.tabs(this.$tabPanels.children('div')); - this.$newTabControls.appendTo(this.$tabBar); }; diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 6370740..a2b36be 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Richard Wall <richard (at) the-moon.net> +/* Copyright (c) Richard Wall * See LICENSE for details. * * Unit tests for Jarmon diff --git a/jarmonbuild/commands.py b/jarmonbuild/commands.py index f6ed712..d60615a 100644 --- a/jarmonbuild/commands.py +++ b/jarmonbuild/commands.py @@ -1,4 +1,5 @@ -# Copyright (c) 2010 Richard Wall <richard (at) the-moon.net> +# Copyright (c) Richard Wall +# See LICENSE for details. """ Functions and Classes for automating the release of Jarmon """ |