};
DygraphLayout.prototype._evaluateLineTicks = function() {
- var i, tick, label, pos;
+ var i, tick, label, pos, v, has_tick;
this.xticks = [];
for (i = 0; i < this.xTicks_.length; i++) {
tick = this.xTicks_[i];
label = tick.label;
- pos = this.dygraph_.toPercentXCoord(tick.v);
+ has_tick = !('label_v' in tick);
+ v = has_tick ? tick.v : tick.label_v;
+ pos = this.dygraph_.toPercentXCoord(v);
if ((pos >= 0.0) && (pos < 1.0)) {
- this.xticks.push([pos, label]);
+ this.xticks.push({pos, label, has_tick});
}
}
for (var j = 0; j < axis.ticks.length; j++) {
tick = axis.ticks[j];
label = tick.label;
- pos = this.dygraph_.toPercentYCoord(tick.v, i);
+ has_tick = !('label_v' in tick);
+ v = has_tick ? tick.v : tick.label_v;
+ pos = this.dygraph_.toPercentYCoord(v, i);
if ((pos > 0.0) && (pos <= 1.0)) {
- this.yticks.push([i, pos, label]);
+ this.yticks.push({axis: i, pos, label, has_tick});
}
}
}
!g.getOptionForAxis('drawAxis', 'y2')) {
return;
}
-
+
// Round pixels to half-integer boundaries for crisper drawing.
function halfUp(x) { return Math.round(x) + 0.5; }
function halfDown(y){ return Math.round(y) - 0.5; }
if (layout.yticks && layout.yticks.length > 0) {
var num_axes = g.numAxes();
var getOptions = [makeOptionGetter('y'), makeOptionGetter('y2')];
- for (i = 0; i < layout.yticks.length; i++) {
- tick = layout.yticks[i];
- if (typeof(tick) == 'function') return; // <-- when would this happen?
+ for (var tick of layout.yticks) {
+ if (tick.label === undefined) continue; // this tick only has a grid line.
x = area.x;
var sgn = 1;
var prec_axis = 'y1';
var getAxisOption = getOptions[0];
- if (tick[0] == 1) { // right-side y-axis
+ if (tick.axis == 1) { // right-side y-axis
x = area.x + area.w;
sgn = -1;
prec_axis = 'y2';
getAxisOption = getOptions[1];
}
var fontSize = getAxisOption('axisLabelFontSize');
- y = area.y + tick[1] * area.h;
+ y = area.y + tick.pos * area.h;
/* Tick marks are currently clipped, so don't bother drawing them.
context.beginPath();
context.stroke();
*/
- label = makeDiv(tick[2], 'y', num_axes == 2 ? prec_axis : null);
+ label = makeDiv(tick.label, 'y', num_axes == 2 ? prec_axis : null);
var top = (y - fontSize / 2);
if (top < 0) top = 0;
} else {
label.style.top = top + 'px';
}
- if (tick[0] === 0) {
+ if (tick.axis === 0) {
label.style.left = (area.x - getAxisOption('axisLabelWidth') - getAxisOption('axisTickSize')) + 'px';
label.style.textAlign = 'right';
- } else if (tick[0] == 1) {
+ } else if (tick.axis == 1) {
label.style.left = (area.x + area.w +
getAxisOption('axisTickSize')) + 'px';
label.style.textAlign = 'left';
if (g.getOptionForAxis('drawAxis', 'x')) {
if (layout.xticks) {
var getAxisOption = makeOptionGetter('x');
- for (i = 0; i < layout.xticks.length; i++) {
- tick = layout.xticks[i];
- x = area.x + tick[0] * area.w;
+ for (var tick of layout.xticks) {
+ if (tick.label === undefined) continue; // this tick only has a grid line.
+ x = area.x + tick.pos * area.w;
y = area.y + area.h;
/* Tick marks are currently clipped, so don't bother drawing them.
context.stroke();
*/
- label = makeDiv(tick[1], 'x');
+ label = makeDiv(tick.label, 'x');
label.style.textAlign = 'center';
label.style.top = (y + getAxisOption('axisTickSize')) + 'px';
ticks = layout.yticks;
ctx.save();
// draw grids for the different y axes
- for (i = 0; i < ticks.length; i++) {
- var axis = ticks[i][0];
- if(drawGrid[axis]) {
+ for (var tick of ticks) {
+ if (!tick.has_tick) continue;
+ var axis = tick.axis;
+ if (drawGrid[axis]) {
ctx.save();
if (stroking[axis]) {
if (ctx.setLineDash) ctx.setLineDash(strokePattern[axis]);
ctx.lineWidth = lineWidths[axis];
x = halfUp(area.x);
- y = halfDown(area.y + ticks[i][1] * area.h);
+ y = halfDown(area.y + tick.pos * area.h);
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + area.w, y);
}
ctx.strokeStyle = g.getOptionForAxis('gridLineColor', 'x');
ctx.lineWidth = g.getOptionForAxis('gridLineWidth', 'x');
- for (i = 0; i < ticks.length; i++) {
- x = halfUp(area.x + ticks[i][0] * area.w);
+ for (var tick of ticks) {
+ if (!tick.has_tick) continue;
+ x = halfUp(area.x + tick.pos * area.w);
y = halfDown(area.y + area.h);
ctx.beginPath();
ctx.moveTo(x, y);