X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-tickers.js;h=155afb05241d4ab2ff7dae3f698968f4543324a3;hb=7bd1be5b6eb3ee09d7da9bb1ab7cd1b3ad5974bd;hp=4b4d9dd138c3e1739ceb3c87fc288433ff8693ab;hpb=9a4fd029e0cfd7ed2d89b54659df5e2d6b8b5d9d;p=dygraphs.git diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 4b4d9dd..155afb0 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -386,15 +386,27 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { var check_dst = (spacing >= Dygraph.SHORT_SPACINGS[Dygraph.TWO_HOURLY]); for (t = start_time; t <= end_time; t += spacing) { - var d = new Date(t); + d = new Date(t); // This ensures that we stay on the same hourly "rhythm" across // daylight savings transitions. Without this, the ticks could get off // by an hour. See tests/daylight-savings.html or issue 147. if (check_dst && d.getTimezoneOffset() != start_offset_min) { - t += (d.getTimezoneOffset() - start_offset_min) * 60 * 1000; + var delta_min = d.getTimezoneOffset() - start_offset_min; + t += delta_min * 60 * 1000; d = new Date(t); start_offset_min = d.getTimezoneOffset(); + + // Check whether we've backed into the previous timezone again. + // This can happen during a "spring forward" transition. In this case, + // it's best to skip this tick altogether (we may be shooting for a + // non-existent time like the 2AM that's skipped) and go to the next + // one. + if (new Date(t + spacing).getTimezoneOffset() != start_offset_min) { + t += spacing; + d = new Date(t); + start_offset_min = d.getTimezoneOffset(); + } } ticks.push({ v:t, @@ -447,11 +459,13 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { // 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; +if (Dygraph && + Dygraph.DEFAULT_ATTRS && + Dygraph.DEFAULT_ATTRS['axes'] && + Dygraph.DEFAULT_ATTRS['axes']['x'] && + Dygraph.DEFAULT_ATTRS['axes']['y'] && + 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; +}