From: Dan Vanderkam Date: Mon, 8 Aug 2011 17:40:17 +0000 (-0400) Subject: add yTicker optoin X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=bccf39df15d022c8ef45a95fea64798de5b56aa3;p=dygraphs.git add yTicker optoin --- diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 55654b8..bd9b4ef 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -6,7 +6,7 @@ * * A ticker is a function with the following interface: * - * function(a, b, pixels, pixels_per_tick, options_view, forced_values); + * function(a, b, pixels, options_view, dygraph, forced_values); * -> [ { v: tick1_v, label: tick1_label[, label_v: label_v1] }, * { v: tick2_v, label: tick2_label[, label_v: label_v2] }, * ... @@ -22,14 +22,14 @@ * millis since epoch (convertable to Date objects using "new Date(a)" and "new * Date(b)"). * - * pixels is the length of the axis in pixels and pixels_per_tick is the - * minimum amount of space to be allotted to each label. For instance, if - * pixels=400 and pixels_per_tick=40 then the ticker should return between - * zero and ten (400/40) ticks. - * * opts provides access to chart- and axis-specific options. It can be used to * access number/date formatting code/options, check for a log scale, etc. * + * pixels is the length of the axis in pixels. opts('pixelsPerLabel') is the + * minimum amount of space to be allotted to each label. For instance, if + * pixels=400 and opts('pixelsPerLabel')=40 then the ticker should return + * between zero and ten (400/40) ticks. + * * dygraph is the Dygraph object for which an axis is being constructed. * * forced_values is used for secondary y-axes. The tick positions are typically @@ -366,3 +366,6 @@ Dygraph.newGetDateAxis = function(start_time, end_time, granularity, opts) { return ticks; }; +Dygraph.DEFAULT_ATTRS.axes.x.ticker = Dygraph.newDateTicker; +Dygraph.DEFAULT_ATTRS.axes.y.ticker = Dygraph.newNumericTicks; +Dygraph.DEFAULT_ATTRS.axes.y2.ticker = Dygraph.newNumericTicks; diff --git a/dygraph.js b/dygraph.js index fdd1483..f60cf8b 100644 --- a/dygraph.js +++ b/dygraph.js @@ -239,15 +239,17 @@ Dygraph.DEFAULT_ATTRS = { pixelsPerLabel: 60, axisLabelFormatter: Dygraph.dateAxisFormatter, valueFormatter: Dygraph.dateString_, - ticker: Dygraph.newDateTicker, + ticker: null; // will be set in dygraph-tickers.js }, y: { pixelsPerLabel: 30, - valueFormatter: Dygraph.numberFormatter + valueFormatter: Dygraph.numberFormatter, + ticker: null; // will be set in dygraph-tickers.js }, y2: { pixelsPerLabel: 30, - valueFormatter: Dygraph.numberFormatter + valueFormatter: Dygraph.numberFormatter, + ticker: null; // will be set in dygraph-tickers.js } } }; @@ -2054,12 +2056,13 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { // Add ticks. By default, all axes inherit the tick positions of the // primary axis. However, if an axis is specifically marked as having // independent ticks, then that is permissible as well. - var ticker = Dygraph.newNumericTicks; // this.attr_('yTicker'); + var opts = this.optionsViewForAxis_('y' + (i ? '2' : '')); + var ticker = opts('ticker'); if (i == 0 || axis.independentTicks) { axis.ticks = ticker(axis.computedValueRange[0], axis.computedValueRange[1], - this.height_, // TODO(danvk): should be area.width - this.optionsViewForAxis_('y' + (i ? '2' : '')), + this.height_, // TODO(danvk): should be area.height + opts, this); } else { var p_axis = this.axes_[0]; @@ -2075,8 +2078,8 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { axis.ticks = ticker(axis.computedValueRange[0], axis.computedValueRange[1], - this.height_, // TODO(danvk): should be area.width - this.optionsViewForAxis_('y2'), + this.height_, // TODO(danvk): should be area.height + opts, this, tick_values); }