X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-tickers.js;h=c80bdf52320f9b7dcb24c22d4819d55ef9299a5c;hb=fefe0bfe5e8e551e1fdb886408a335139a5f8ba3;hp=64cf59f3e267cbf550b73b34d9f1a5f6600b3637;hpb=795b16307db2a673ba7aa3452f6f6b0e93baeb3a;p=dygraphs.git diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 64cf59f..c80bdf5 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -62,6 +62,14 @@ /*global Dygraph:false */ "use strict"; +Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) { + var nonLogscaleOpts = function(opt) { + if (opt === 'logscale') return false; + return opts(opt); + }; + return Dygraph.numericTicks(a, b, pixels, nonLogscaleOpts, dygraph, vals); +}; + Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { var pixels_per_tick = opts('pixelsPerLabel'); var ticks = []; @@ -160,14 +168,16 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { // Add formatted labels to the ticks. var k; var k_labels = []; + var m_labels = []; if (opts("labelsKMB")) { k = 1000; - k_labels = [ "K", "M", "B", "T" ]; + k_labels = [ "K", "M", "B", "T", "Q" ]; } if (opts("labelsKMG2")) { if (k) Dygraph.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); k = 1024; - k_labels = [ "k", "M", "G", "T" ]; + k_labels = [ "k", "M", "G", "T", "P", "E", "Z", "Y" ]; + m_labels = [ "m", "u", "n", "p", "f", "a", "z", "y" ]; } var formatter = opts('axisLabelFormatter'); @@ -182,8 +192,8 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { if (k_labels.length > 0) { // TODO(danvk): should this be integrated into the axisLabelFormatter? // Round up to an appropriate unit. - var n = k*k*k*k; - for (j = 3; j >= 0; j--, n /= k) { + var n = Math.pow(k, k_labels.length); + for (j = k_labels.length - 1; j >= 0; j--, n /= k) { if (absTickV >= n) { label = Dygraph.round_(tickV / n, opts('digitsAfterDecimal')) + k_labels[j]; @@ -191,6 +201,19 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { } } } + if(opts("labelsKMG2")){ + tickV = String(tickV.toExponential()); + if(tickV.split('e-').length === 2 && tickV.split('e-')[1] >= 3 && tickV.split('e-')[1] <= 24){ + if(tickV.split('e-')[1] % 3 > 0) { + label = Dygraph.round_(tickV.split('e-')[0] / + Math.pow(10,(tickV.split('e-')[1] % 3)), + opts('digitsAfterDecimal')); + } else { + label = Number(tickV.split('e-')[0]).toFixed(2); + } + label += m_labels[Math.floor(tickV.split('e-')[1] / 3) - 1]; + } + } ticks[i].label = label; } @@ -323,6 +346,7 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { // for this granularity. var g = spacing / 1000; var d = new Date(start_time); + d.setMilliseconds(0); var x; if (g <= 60) { // seconds x = d.getSeconds(); d.setSeconds(x - x % g);