|
|
@ -6,6 +6,7 @@ nv.models.axis = function() {
|
|
|
|
axisLabelText = null,
|
|
|
|
axisLabelText = null,
|
|
|
|
showMaxMin = true, //TODO: showMaxMin should be disabled on all ordinal scaled axes
|
|
|
|
showMaxMin = true, //TODO: showMaxMin should be disabled on all ordinal scaled axes
|
|
|
|
highlightZero = true,
|
|
|
|
highlightZero = true,
|
|
|
|
|
|
|
|
rotateLabels = 0,
|
|
|
|
rotateYLabel = true;
|
|
|
|
rotateYLabel = true;
|
|
|
|
margin = {top: 0, right: 0, bottom: 0, left: 0}
|
|
|
|
margin = {top: 0, right: 0, bottom: 0, left: 0}
|
|
|
|
|
|
|
|
|
|
|
@ -69,16 +70,25 @@ nv.models.axis = function() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'bottom':
|
|
|
|
case 'bottom':
|
|
|
|
|
|
|
|
var xLabelMargin = 30;
|
|
|
|
var maxTextWidth = 30;
|
|
|
|
var maxTextWidth = 30;
|
|
|
|
if(rotateLabels){
|
|
|
|
if(rotateLabels%360){
|
|
|
|
g.selectAll('g text').each(function(d,i){
|
|
|
|
var xTicks = g.selectAll('g').select("text");
|
|
|
|
|
|
|
|
//Calculate the longest xTick width
|
|
|
|
|
|
|
|
xTicks.each(function(d,i){
|
|
|
|
var width = this.getBBox().width;
|
|
|
|
var width = this.getBBox().width;
|
|
|
|
if(width > maxTextWidth) maxTextWidth = width;
|
|
|
|
if(width > maxTextWidth) maxTextWidth = width;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//Convert to radians before calculating sin. Add 30 to margin for healthy padding.
|
|
|
|
|
|
|
|
var sin = Math.abs(Math.sin(rotateLabels*Math.PI/180));
|
|
|
|
|
|
|
|
var xLabelMargin = (sin ? sin*maxTextWidth : maxTextWidth)+30;
|
|
|
|
|
|
|
|
//Rotate all xTicks
|
|
|
|
|
|
|
|
xTicks.attr('transform', function(d,i,j) { return 'rotate(' + rotateLabels + ' 0,0)' })
|
|
|
|
|
|
|
|
.attr('text-anchor', rotateLabels%360 > 0 ? 'start' : 'end');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
axisLabel.enter().append('text').attr('class', 'nv-axislabel')
|
|
|
|
axisLabel.enter().append('text').attr('class', 'nv-axislabel')
|
|
|
|
.attr('text-anchor', 'middle')
|
|
|
|
.attr('text-anchor', 'middle')
|
|
|
|
.attr('y', maxTextWidth);
|
|
|
|
.attr('y', xLabelMargin);
|
|
|
|
var w = (scale.range().length==2) ? scale.range()[1] : (scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]));
|
|
|
|
var w = (scale.range().length==2) ? scale.range()[1] : (scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]));
|
|
|
|
axisLabel
|
|
|
|
axisLabel
|
|
|
|
.attr('x', w/2);
|
|
|
|
.attr('x', w/2);
|
|
|
@ -94,7 +104,8 @@ nv.models.axis = function() {
|
|
|
|
.select('text')
|
|
|
|
.select('text')
|
|
|
|
.attr('dy', '.71em')
|
|
|
|
.attr('dy', '.71em')
|
|
|
|
.attr('y', axis.tickPadding())
|
|
|
|
.attr('y', axis.tickPadding())
|
|
|
|
.attr('text-anchor', 'middle')
|
|
|
|
.attr('transform', function(d,i,j) { return 'rotate(' + rotateLabels + ' 0,0)' })
|
|
|
|
|
|
|
|
.attr('text-anchor', rotateLabels%360 > 0 ? 'start' : 'end')
|
|
|
|
.text(function(d,i) {
|
|
|
|
.text(function(d,i) {
|
|
|
|
return ('' + axis.tickFormat()(d)).match('NaN') ? '' : axis.tickFormat()(d)
|
|
|
|
return ('' + axis.tickFormat()(d)).match('NaN') ? '' : axis.tickFormat()(d)
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -269,6 +280,11 @@ nv.models.axis = function() {
|
|
|
|
rotateYLabel = _;
|
|
|
|
rotateYLabel = _;
|
|
|
|
return chart;
|
|
|
|
return chart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
chart.rotateLabels = function(_) {
|
|
|
|
|
|
|
|
if(!arguments.length) return rotateLabels;
|
|
|
|
|
|
|
|
rotateLabels = _;
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
|
|
|
}
|
|
|
|
chart.margin = function(_) {
|
|
|
|
chart.margin = function(_) {
|
|
|
|
if(!arguments.length) return margin;
|
|
|
|
if(!arguments.length) return margin;
|
|
|
|
margin = _;
|
|
|
|
margin = _;
|
|
|
|