Skip to content

Commit

Permalink
Coerce scale output to numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 7, 2017
1 parent 52f3de2 commit 8e59287
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ function translateY(y) {
return "translate(0," + (y + 0.5) + ")";
}

function number(scale) {
return function(d) {
return +scale(d);
};
}

function center(scale) {
var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
if (scale.round()) offset = Math.round(offset);
return function(d) {
return scale(d) + offset;
return +scale(d) + offset;
};
}

Expand All @@ -43,9 +49,9 @@ function axis(orient, scale) {
format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity) : tickFormat,
spacing = Math.max(tickSizeInner, 0) + tickPadding,
range = scale.range(),
range0 = range[0] + 0.5,
range1 = range[range.length - 1] + 0.5,
position = (scale.bandwidth ? center : identity)(scale.copy()),
range0 = +range[0] + 0.5,
range1 = +range[range.length - 1] + 0.5,
position = (scale.bandwidth ? center : number)(scale.copy()),
selection = context.selection ? context.selection() : context,
path = selection.selectAll(".domain").data([null]),
tick = selection.selectAll(".tick").data(values, scale).order(),
Expand Down

0 comments on commit 8e59287

Please sign in to comment.