if (ticks[i].label !== undefined) continue; // Use current label.
var tickV = ticks[i].v;
var absTickV = Math.abs(tickV);
- var label = formatter(tickV, opts, dygraph);
+ // TODO(danvk): set granularity to something appropriate here.
+ var label = formatter(tickV, 0, opts, dygraph);
if (k_labels.length > 0) {
// TODO(danvk): should this be integrated into the axisLabelFormatter?
// Round up to an appropriate unit.
}
if (chosen >= 0) {
- return Dygraph.getDateAxis(a, b, chosen, opts);
+ return Dygraph.getDateAxis(a, b, chosen, opts, dygraph);
} else {
// this can happen if self.width_ is zero.
return [];
}
};
-Dygraph.getDateAxis = function(start_time, end_time, granularity, opts) {
+Dygraph.getDateAxis = function(start_time, end_time, granularity, opts, dg) {
var formatter = opts("axisLabelFormatter");
var ticks = [];
if (granularity < Dygraph.MONTHLY) {
start_time = d.getTime();
for (var t = start_time; t <= end_time; t += spacing) {
- ticks.push({ v:t, label: formatter(new Date(t), granularity) });
+ ticks.push({ v:t,
+ label: formatter(new Date(t), granularity, opts, dg)
+ });
}
} else {
// Display a tick mark on the first of a set of months of each year.
var date_str = i + "/" + zeropad(1 + months[j]) + "/01";
var t = Dygraph.dateStrToMillis(date_str);
if (t < start_time || t > end_time) continue;
- ticks.push({ v:t, label: formatter(new Date(t), granularity) });
+ ticks.push({ v:t,
+ label: formatter(new Date(t), granularity, opts, dg)
+ });
}
}
}
* @param {Dygraph} opts An options view
* @param {Dygraph} g The dygraph object
*/
-Dygraph.numberFormatter = function(x, opts, g) {
+Dygraph.numberValueFormatter = function(x, opts, g) {
var sigFigs = opts('sigFigs');
if (sigFigs !== null) {
};
/**
+ * variant for use as an axisLabelFormatter.
+ * @private
+ */
+Dygraph.numberAxisLabelFormatter = function(x, granularity, opts, g) {
+ return Dygraph.numberValueFormatter(x, opts, g);
+};
+
+/**
* Convert a JS date (millis since epoch) to YYYY/MM/DD
* @param {Number} date The JavaScript date (ms since epoch)
* @return {String} A date of the form "YYYY/MM/DD"
},
y: {
pixelsPerLabel: 30,
- valueFormatter: Dygraph.numberFormatter,
- axisLabelFormatter: Dygraph.numberFormatter,
+ valueFormatter: Dygraph.numberValueFormatter,
+ axisLabelFormatter: Dygraph.numberAxisLabelFormatter,
ticker: null // will be set in dygraph-tickers.js
},
y2: {
pixelsPerLabel: 30,
- valueFormatter: Dygraph.numberFormatter,
- axisLabelFormatter: Dygraph.numberFormatter,
+ valueFormatter: Dygraph.numberValueFormatter,
+ axisLabelFormatter: Dygraph.numberAxisLabelFormatter,
ticker: null // will be set in dygraph-tickers.js
}
}
return html;
}
- var xvf = this.optionsViewForAxis_('x')('valueFormatter');
- var html = xvf(x) + ":";
+ var xOptView = this.optionsViewForAxis_('x');
+ var xvf = xOptView('valueFormatter');
+ var html = xvf(x, xOptView, this) + ":";
var yOptView = this.optionsViewForAxis_('y');
var fmtFunc = yOptView('valueFormatter');
this.attrs_.axes.x.ticker = Dygraph.dateTicker;
this.attrs_.axes.x.axisLabelFormatter = Dygraph.dateAxisFormatter;
} else {
- // TODO(danvk): use Dygraph.numberFormatter here?
/** @private (shut up, jsdoc!) */
this.attrs_.xValueParser = function(x) { return parseFloat(x); };
+ // TODO(danvk): use Dygraph.numberValueFormatter here?
/** @private (shut up, jsdoc!) */
this.attrs_.axes.x.valueFormatter = function(x) { return x; };
this.attrs_.axes.x.ticker = Dygraph.numericTicks;
// Some intelligent defaults for a numeric x-axis.
/** @private (shut up, jsdoc!) */
this.attrs_.axes.x.valueFormatter = function(x) { return x; };
- this.attrs_.axes.x.axisLabelFormatter = Dygraph.numberFormatter;
+ this.attrs_.axes.x.axisLabelFormatter = Dygraph.numberAxisLabelFormatter;
this.attrs_.axes.x.ticker = Dygraph.numericTicks;
return data;
}