X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=dygraph-tickers.js;h=0f6b1ab092eeb3c367075d7995452df927b98cb6;hb=26ee953643ccd2d32e38e6b60b20e6a01c1dc9ba;hp=654877b7259fd93209a33b19f99cb17781f72d43;hpb=c17e11738cb5603fafcdc84527114502312344c4;p=dygraphs.git diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 654877b..0f6b1ab 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -198,7 +198,7 @@ Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { for (i = 0; i < ticks.length; i++) { if (ticks[i].label !== undefined) continue; // Use current label. // TODO(danvk): set granularity to something appropriate here. - ticks[i].label = formatter(ticks[i].v, 0, opts, dygraph); + ticks[i].label = formatter.call(dygraph, ticks[i].v, 0, opts, dygraph); } return ticks; @@ -233,14 +233,15 @@ Dygraph.HOURLY = 10; Dygraph.TWO_HOURLY = 11; Dygraph.SIX_HOURLY = 12; Dygraph.DAILY = 13; -Dygraph.WEEKLY = 14; -Dygraph.MONTHLY = 15; -Dygraph.QUARTERLY = 16; -Dygraph.BIANNUAL = 17; -Dygraph.ANNUAL = 18; -Dygraph.DECADAL = 19; -Dygraph.CENTENNIAL = 20; -Dygraph.NUM_GRANULARITIES = 21; +Dygraph.TWO_DAILY = 14; +Dygraph.WEEKLY = 15; +Dygraph.MONTHLY = 16; +Dygraph.QUARTERLY = 17; +Dygraph.BIANNUAL = 18; +Dygraph.ANNUAL = 19; +Dygraph.DECADAL = 20; +Dygraph.CENTENNIAL = 21; +Dygraph.NUM_GRANULARITIES = 22; // Date components enumeration (in the order of the arguments in Date) // TODO: make this an @enum @@ -254,7 +255,19 @@ Dygraph.DATEFIELD_MS = 6; Dygraph.NUM_DATEFIELDS = 7; -/** @type {Array.<{datefield:number, step:number, spacing:number}>} */ +/** + * The value of datefield will start at an even multiple of "step", i.e. + * if datefield=SS and step=5 then the first tick will be on a multiple of 5s. + * + * For granularities <= HOURLY, ticks are generated every `spacing` ms. + * + * At coarser granularities, ticks are generated by incrementing `datefield` by + * `step`. In this case, the `spacing` value is only used to estimate the + * number of ticks. It should roughly correspond to the spacing between + * adjacent ticks. + * + * @type {Array.<{datefield:number, step:number, spacing:number}>} + */ Dygraph.TICK_PLACEMENT = []; Dygraph.TICK_PLACEMENT[Dygraph.SECONDLY] = {datefield: Dygraph.DATEFIELD_SS, step: 1, spacing: 1000 * 1}; Dygraph.TICK_PLACEMENT[Dygraph.TWO_SECONDLY] = {datefield: Dygraph.DATEFIELD_SS, step: 2, spacing: 1000 * 2}; @@ -270,6 +283,7 @@ Dygraph.TICK_PLACEMENT[Dygraph.HOURLY] = {datefield: Dygraph.DATEFIELD_ Dygraph.TICK_PLACEMENT[Dygraph.TWO_HOURLY] = {datefield: Dygraph.DATEFIELD_HH, step: 2, spacing: 1000 * 3600 * 2}; Dygraph.TICK_PLACEMENT[Dygraph.SIX_HOURLY] = {datefield: Dygraph.DATEFIELD_HH, step: 6, spacing: 1000 * 3600 * 6}; Dygraph.TICK_PLACEMENT[Dygraph.DAILY] = {datefield: Dygraph.DATEFIELD_D, step: 1, spacing: 1000 * 86400}; +Dygraph.TICK_PLACEMENT[Dygraph.TWO_DAILY] = {datefield: Dygraph.DATEFIELD_D, step: 2, spacing: 1000 * 86400 * 2}; Dygraph.TICK_PLACEMENT[Dygraph.WEEKLY] = {datefield: Dygraph.DATEFIELD_D, step: 7, spacing: 1000 * 604800}; Dygraph.TICK_PLACEMENT[Dygraph.MONTHLY] = {datefield: Dygraph.DATEFIELD_M, step: 1, spacing: 1000 * 7200 * 365.2524}; // 1e3 * 60 * 60 * 24 * 365.2524 / 12 Dygraph.TICK_PLACEMENT[Dygraph.QUARTERLY] = {datefield: Dygraph.DATEFIELD_M, step: 3, spacing: 1000 * 21600 * 365.2524}; // 1e3 * 60 * 60 * 24 * 365.2524 / 4 @@ -400,7 +414,7 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { } while (tick_time <= end_time) { ticks.push({ v: tick_time, - label: formatter(tick_date, granularity, opts, dg) + label: formatter.call(dg, tick_date, granularity, opts, dg) }); tick_time += spacing; tick_date = new Date(tick_time); @@ -415,7 +429,7 @@ Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) { if (granularity >= Dygraph.DAILY || accessors.getHours(tick_date) % step === 0) { ticks.push({ v: tick_time, - label: formatter(tick_date, granularity, opts, dg) + label: formatter.call(dg, tick_date, granularity, opts, dg) }); } date_array[datefield] += step;