Dygraph.AXIS_LINE_WIDTH = 0.3;
Dygraph.LOG_SCALE = 10;
-Dygraph.LOG_BASE_E_OF_TEN = Math.log(Dygraph.LOG_SCALE);
+Dygraph.LN_TEN = Math.log(Dygraph.LOG_SCALE);
Dygraph.log10 = function(x) {
- return Math.log(x) / Dygraph.LOG_BASE_E_OF_TEN;
+ return Math.log(x) / Dygraph.LN_TEN;
}
// Default attribute values.
delimiter: ',',
- logScale: false,
sigma: 2.0,
errorBars: false,
fractions: false,
/**
* Convert from data x coordinates to canvas/div X coordinate.
* If specified, do this conversion for the coordinate system of a particular
- * axis. Uses the first axis by default.
- * returns a single value or null if x is null.
+ * axis.
+ * Returns a single value or null if x is null.
*/
Dygraph.prototype.toDomXCoord = function(x) {
if (x == null) {
if (pct == null) {
return null;
}
+ var area = this.plotter_.area;
return area.y + pct * area.h;
}
var area = this.plotter_.area;
var yRange = this.yAxisRange(axis);
- if (!this.attr_("logscale")) {
+ if (!axis.logscale) {
return yRange[0] + (area.h - y) / area.h * (yRange[1] - yRange[0]);
} else {
// Computing the inverse of toDomCoord.
if (y == null) {
return null;
}
+ if (typeof(axis) == "undefined") axis = 0;
var area = this.plotter_.area;
var yRange = this.yAxisRange(axis);
var pct;
- if (!this.attr_("logscale")) {
+ if (!this.axes_[axis].logscale) {
// yrange[1] - y is unit distance from the bottom.
// yrange[1] - yrange[0] is the scale of the range.
// (yRange[1] - y) / (yRange[1] - yRange[0]) is the % from the bottom.
var axis = g.axes_[i];
var maxValue = axis.draggingValue + y_frac * axis.dragValueRange;
var minValue = maxValue - axis.dragValueRange;
- console.log(axis.draggingValue, axis.dragValueRange, minValue, maxValue, y_frac);
axis.valueWindow = [ minValue, maxValue ];
}
}
* Add ticks when the x axis has numbers on it (instead of dates)
* TODO(konigsberg): Update comment.
*
- * @param {Number} startDate Start of the date window (millis since epoch)
- * @param {Number} endDate End of the date window (millis since epoch)
+ * @param {Number} minV minimum value
+ * @param {Number} maxV maximum value
* @param self
* @param {function} attribute accessor function.
* @return {Array.<Object>} Array of {label, value} tuples.
ticks.push({v: vals[i]});
}
} else {
- if (self.attr_("logscale")) {
+ if (axis_props && attr("logscale")) {
// As opposed to the other ways for computing ticks, we're just going
// for nearby values. There's no reasonable way to scale the values
// (unless we want to show strings like "log(" + x + ")") in which case
// so compute height / pixelsPerTick and move on.
var pixelsPerTick = attr('pixelsPerYLabel');
+ // NOTE(konigsberg): Dan, should self.height_ be self.plotter_.area.h?
var nTicks = Math.floor(self.height_ / pixelsPerTick);
var vv = minV;
* number of axes, rolling averages, etc.
*/
Dygraph.prototype.predraw_ = function() {
- // TODO(danvk): move more computations out of drawGraph_ and into here.
+ // TODO(danvk): movabilitye more computations out of drawGraph_ and into here.
this.computeYAxes_();
// Create a new plotter.
var seriesName = this.attr_("labels")[i];
var connectSeparatedPoints = this.attr_('connectSeparatedPoints', i);
+ var logScale = this.attr_('logscale', i);
var series = [];
for (var j = 0; j < data.length; j++) {
- if (data[j][i] != null || !connectSeparatedPoints) {
- var date = data[j][0];
- series.push([date, data[j][i]]);
+ var date = data[j][0];
+ var point = data[j][i];
+ if (logScale) {
+ // On the log scale, points less than zero do not exist.
+ // This will create a gap in the chart. Note that this ignores
+ // connectSeparatedPoints.
+ if (point < 0) {
+ point = null;
+ }
+ series.push([date, point]);
+ } else {
+ if (point != null || !connectSeparatedPoints) {
+ series.push([date, point]);
+ }
}
}
'pixelsPerYLabel',
'yAxisLabelWidth',
'axisLabelFontSize',
- 'axisTickSize'
+ 'axisTickSize',
+ 'logscale'
];
// Copy global axis options over to the first axis.
// Compute extreme values, a span and tick marks for each axis.
for (var i = 0; i < this.axes_.length; i++) {
- var isLogScale = this.attr_("logscale");
var axis = this.axes_[i];
if (axis.valueWindow) {
// This is only set if the user has zoomed on the y-axis. It is never set
var maxAxisY;
var minAxisY;
- if (isLogScale) {
+ if (axis.logscale) {
var maxAxisY = maxY + 0.1 * span;
var minAxisY = minY;
} else {