From 391e8c019e581ac781b189515be41791d147dc31 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sun, 18 Apr 2010 17:29:59 +0100 Subject: A SI tick formatter --- jrrd.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/jrrd.js b/jrrd.js index 104eccd..d49212a 100644 --- a/jrrd.js +++ b/jrrd.js @@ -191,13 +191,56 @@ jrrd.RrdQueryDsProxy.prototype.getData = function(startTime, endTime) { jrrd.Chart = function(template, options) { this.template = template; - this.options = jQuery.extend(true, {}, options); + this.options = jQuery.extend(true, {yaxis: {}}, options); this.data = []; var self = this; $('.legend tr', this.template[0]).live('click', function(e) { self.switchDataEnabled($(this).children('.legendLabel').text()); self.draw(); }); + + this.options['yaxis']['ticks'] = function(axis) { + var siPrefixes = { + 0: '', + 1: 'K', + 2: 'M', + 3: 'G', + 4: 'T' + } + var si = 0; + while(true) { + if( Math.pow(1000, si+1)*0.9 > axis.max ) { + break; + } + si++; + } + + var minVal = axis.min/Math.pow(1000, si); + 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]; + var realStep = (maxVal - minVal)/5.0; + + var stepSize, decimalPlaces = 0; + for(var i=0; i