X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-tickers.js;h=0e18394da0519253a801d0fd012ebcdc1c88f503;hb=2fd143d3e284124506b00e4afa9e29f9de636543;hp=6ad31027f6b8f0d9e92a5c8fa4ec0c9ac0ac906f;hpb=0cd1ad15aefb3bd6507886e4cbba0d7587a56610;p=dygraphs.git diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 6ad3102..0e18394 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -87,16 +87,6 @@ Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) { /** @type {Dygraph.Ticker} */ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { - // This masks some numeric issues in older versions of Firefox, - // where 1.0/Math.pow(10,2) != Math.pow(10,-2). - /** @type {function(number,number):number} */ - var pow = function(base, exp) { - if (exp < 0) { - return 1.0 / Math.pow(base, -exp); - } - return Math.pow(base, exp); - }; - var pixels_per_tick = /** @type{number} */(opts('pixelsPerLabel')); var ticks = []; var i, j, tickV, nTicks; @@ -201,58 +191,13 @@ 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", "Q" ]; - } - if (opts("labelsKMG2")) { - if (k) Dygraph.warn("Setting both labelsKMB and labelsKMG2. Pick one!"); - k = 1024; - k_labels = [ "k", "M", "G", "T", "P", "E", "Z", "Y" ]; - m_labels = [ "m", "u", "n", "p", "f", "a", "z", "y" ]; - } - - k = k || 1; // If neither option is specified. - var formatter = /**@type{AxisLabelFormatter}*/(opts('axisLabelFormatter')); // Add labels to the ticks. - var digitsAfterDecimal = /** @type{number} */(opts('digitsAfterDecimal')); for (i = 0; i < ticks.length; i++) { if (ticks[i].label !== undefined) continue; // Use current label. - tickV = ticks[i].v; - var absTickV = Math.abs(tickV); // TODO(danvk): set granularity to something appropriate here. - var label = formatter(tickV, 0, opts, dygraph); - if (k_labels.length > 0) { - // TODO(danvk): should this be integrated into the axisLabelFormatter? - // Round up to an appropriate unit. - var n = pow(k, k_labels.length); - for (j = k_labels.length - 1; j >= 0; j--, n /= k) { - if (absTickV >= n) { - label = Dygraph.round_(tickV / n, digitsAfterDecimal) + k_labels[j]; - break; - } - } - } - 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] / - pow(10,(tickV.split('e-')[1] % 3)), - 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; + ticks[i].label = formatter(ticks[i].v, 0, opts, dygraph); } return ticks; @@ -479,7 +424,13 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { return ticks; }; -// These are set here so that this file can be included after dygraph.js. +// These are set here so that this file can be included after dygraph.js +// or independently. +Dygraph.DEFAULT_ATTRS = Dygraph.DEFAULT_ATTRS || {}; +Dygraph.DEFAULT_ATTRS['axes'] = Dygraph.DEFAULT_ATTRS['axes'] || {}; +Dygraph.DEFAULT_ATTRS['axes']['x'] = Dygraph.DEFAULT_ATTRS['axes']['x'] || {}; +Dygraph.DEFAULT_ATTRS['axes']['y'] = Dygraph.DEFAULT_ATTRS['axes']['y'] || {}; +Dygraph.DEFAULT_ATTRS['axes']['y2'] = Dygraph.DEFAULT_ATTRS['axes']['y2'] || {}; Dygraph.DEFAULT_ATTRS['axes']['x']['ticker'] = Dygraph.dateTicker; Dygraph.DEFAULT_ATTRS['axes']['y']['ticker'] = Dygraph.numericTicks; Dygraph.DEFAULT_ATTRS['axes']['y2']['ticker'] = Dygraph.numericTicks;