From: Adam Vartanian Date: Thu, 22 Dec 2011 21:42:17 +0000 (-0500) Subject: Extract the granularity-picking code of the date ticker into a new function. X-Git-Tag: v1.0.0~272^2~8 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=85fca6d588b66e04ee0fa8b0bf0401c95b4fa148;p=dygraphs.git Extract the granularity-picking code of the date ticker into a new function. --- diff --git a/dygraph-tickers.js b/dygraph-tickers.js index a17519e..ae0e40f 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -193,15 +193,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.pickTickGranularity(a, b, pixels, opts); if (chosen >= 0) { return Dygraph.getDateAxis(a, b, chosen, opts, dygraph); @@ -271,6 +263,17 @@ Dygraph.PREFERRED_LOG_TICK_VALUES = function() { return vals; }(); +Dygraph.pickTickGranularity = 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.