var opts = {
width: 480,
height: 320,
- axes : {
- x : {
+ axes: {
+ x: {
valueFormatter: function(x, opts, series_name, dg, row, col) {
assertEquals('number', typeof(x));
assertEquals('function', typeof(opts));
assertEquals('[Dygraph graph]', dg.toString());
assertEquals('number', typeof(row));
assertEquals('number', typeof(col));
+ assertEquals(dg, this);
return 'x' + x;
}
},
- y : {
+ y: {
valueFormatter: function(y, opts, series_name, dg, row, col) {
assertEquals('number', typeof(y));
assertEquals('function', typeof(opts));
assertEquals('[Dygraph graph]', dg.toString());
assertEquals('number', typeof(row));
assertEquals('number', typeof(col));
+ assertEquals(dg, this);
return 'y' + y;
}
}
assertEquals('[Dygraph graph]', dg.toString());
assertEquals('number', typeof(row));
assertEquals('number', typeof(col));
+ assertEquals(dg, this);
return 'x' + Util.formatDate(x);
}
},
assertEquals('[Dygraph graph]', dg.toString());
assertEquals('number', typeof(row));
assertEquals('number', typeof(col));
+ assertEquals(dg, this);
return 'y' + y;
}
}
axes : {
x : {
valueFormatter: function(x) {
+ assertEquals('[Dygraph graph]', this.toString());
return 'xvf' + x;
},
axisLabelFormatter: function(x, granularity) {
+ assertEquals('[Dygraph graph]', this.toString());
return 'x' + x;
}
},
y : {
valueFormatter: function(y) {
+ assertEquals('[Dygraph graph]', this.toString());
return 'yvf' + y;
},
axisLabelFormatter: function(y) {
+ assertEquals('[Dygraph graph]', this.toString());
return 'y' + y;
}
}
height: 320,
labels: ['x', 'y'],
valueFormatter: function(x) {
+ assertEquals('[Dygraph graph]', this);
return 'vf' + x;
},
axisLabelFormatter: function(x) {
+ assertEquals('[Dygraph graph]', this);
return 'alf' + x;
}
};
};
var taggedRecorder = function(tag) {
return function() {
- calls.push([tag].concat(killFunctions(arguments)));
+ calls.push([tag].concat([this], killFunctions(arguments)));
return '';
}
};
g.setSelection(0);
assertEquals([
// num or millis, opts, series, dygraph, row, col
- [ 'x', 0, 'fn', 'x', g, 0, 0],
- [ 'y', 1, 'fn', 'y1', g, 0, 1],
- ['y2', 2, 'fn', 'y2', g, 0, 2]
+ [ 'x', g, 0, 'fn', 'x', g, 0, 0],
+ [ 'y', g, 1, 'fn', 'y1', g, 0, 1],
+ ['y2', g, 2, 'fn', 'y2', g, 0, 2]
], calls);
calls = [];
g.setSelection(1);
assertEquals([
- [ 'x', 1, 'fn', 'x', g, 1, 0],
- [ 'y', 3, 'fn', 'y1', g, 1, 1],
- ['y2', 4, 'fn', 'y2', g, 1, 2]
+ [ 'x', g, 1, 'fn', 'x', g, 1, 0],
+ [ 'y', g, 3, 'fn', 'y1', g, 1, 1],
+ ['y2', g, 4, 'fn', 'y2', g, 1, 2]
], calls);
};
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;
}
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);
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;
// TODO(danvk): remove this use of a private API
var xOptView = g.optionsViewForAxis_('x');
var xvf = xOptView('valueFormatter');
- html = xvf(x, xOptView, labels[0], g, row, 0);
+ html = xvf.call(g, x, xOptView, labels[0], g, row, 0);
if (html !== '') {
html += ':';
}
var series = g.getPropertiesForSeries(pt.name);
var yOptView = yOptViews[series.axis - 1];
var fmtFunc = yOptView('valueFormatter');
- var yval = fmtFunc(pt.yval, yOptView, pt.name, g, row, labels.indexOf(pt.name));
+ var yval = fmtFunc.call(g, pt.yval, yOptView, pt.name, g, row, labels.indexOf(pt.name));
var cls = (pt.name == highlightSeries) ? " class='highlight'" : "";