Skip to content

Commit

Permalink
Fix for invalid axis.orient. Fixes d3#905.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Feb 6, 2013
1 parent 183060d commit 093bd84
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
10 changes: 8 additions & 2 deletions d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3317,7 +3317,7 @@
d3.svg.symbolTypes = d3_svg_symbols.keys();
var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
d3.svg.axis = function() {
var scale = d3.scale.linear(), orient = "bottom", tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, tickMajorSize = 6, tickMinorSize = 6, tickEndSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_, tickSubdivide = 0;
function axis(g) {
g.each(function() {
var g = d3.select(this);
Expand Down Expand Up @@ -3411,7 +3411,7 @@
};
axis.orient = function(x) {
if (!arguments.length) return orient;
orient = x;
orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
return axis;
};
axis.ticks = function() {
Expand Down Expand Up @@ -3449,6 +3449,12 @@
};
return axis;
};
var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
top: 1,
right: 1,
bottom: 1,
left: 1
};
function d3_svg_axisX(selection, x) {
selection.attr("transform", function(d) {
return "translate(" + x(d) + ",0)";
Expand Down
8 changes: 4 additions & 4 deletions d3.min.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/svg/axis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3.svg.axis = function() {
var scale = d3.scale.linear(),
orient = "bottom",
orient = d3_svg_axisDefaultOrient,
tickMajorSize = 6,
tickMinorSize = 6,
tickEndSize = 6,
Expand Down Expand Up @@ -135,7 +135,7 @@ d3.svg.axis = function() {

axis.orient = function(x) {
if (!arguments.length) return orient;
orient = x;
orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
return axis;
};

Expand Down Expand Up @@ -181,6 +181,9 @@ d3.svg.axis = function() {
return axis;
};

var d3_svg_axisDefaultOrient = "bottom",
d3_svg_axisOrients = {top: 1, right: 1, bottom: 1, left: 1};

function d3_svg_axisX(selection, x) {
selection.attr("transform", function(d) { return "translate(" + x(d) + ",0)"; });
}
Expand Down
8 changes: 8 additions & 0 deletions test/svg/axis-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ suite.addBatch({
var a = axis();
assert.equal(a.orient(), "bottom");
},
"defaults to bottom when an invalid orientation is specified": function(axis) {
var a = axis().orient("invalid");
assert.equal(a.orient(), "bottom");
},
"coerces to a string": function(axis) {
var a = axis().orient({toString: function() { return "left"; }});
assert.equal(a.orient(), "left");
},
"supports top orientation": function(axis) {
var a = axis().orient("top"),
g = d3.select("body").html("").append("svg:g").call(a),
Expand Down

0 comments on commit 093bd84

Please sign in to comment.