X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-tickers.js;h=b91b82f2411d383412a14387134e30f7c2170294;hb=966ac3fa0de18a7b5ddefe4aba6938d8358ea0cf;hp=46fe765d409324b2d2200556ae46f8754b314944;hpb=758a629f806fa73483f730fb343013acd0ace078;p=dygraphs.git diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 46fe765..b91b82f 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 = []; @@ -199,15 +207,7 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { Dygraph.dateTicker = function(a, b, pixels, opts, dygraph, vals) { - var pixels_per_tick = opts('pixelsPerLabel'); - var chosen = -1; - for (var i = 0; i < Dygraph.NUM_GRANULARITIES; i++) { - var num_ticks = Dygraph.numDateTicks(a, b, i); - if (pixels / num_ticks >= pixels_per_tick) { - chosen = i; - break; - } - } + var chosen = Dygraph.pickDateTickGranularity(a, b, pixels, opts); if (chosen >= 0) { return Dygraph.getDateAxis(a, b, chosen, opts, dygraph); @@ -277,6 +277,27 @@ Dygraph.PREFERRED_LOG_TICK_VALUES = function() { return vals; }(); +/** + * Determine the correct granularity of ticks on a date axis. + * + * @param {Number} a Left edge of the chart (ms) + * @param {Number} b Right edge of the chart (ms) + * @param {Number} pixels Size of the chart in the relevant dimension (width). + * @param {Function} opts Function mapping from option name -> value. + * @return {Number} The appropriate axis granularity for this chart. See the + * enumeration of possible values in dygraph-tickers.js. + */ +Dygraph.pickDateTickGranularity = function(a, b, pixels, opts) { + var pixels_per_tick = opts('pixelsPerLabel'); + for (var i = 0; i < Dygraph.NUM_GRANULARITIES; i++) { + var num_ticks = Dygraph.numDateTicks(a, b, i); + if (pixels / num_ticks >= pixels_per_tick) { + return i; + } + } + return -1; +}; + Dygraph.numDateTicks = function(start_time, end_time, granularity) { if (granularity < Dygraph.MONTHLY) { // Generate one tick mark for every fixed interval of time.