Adding axisLabelDistance property to axis.js

master
Robin Hu 11 years ago
parent c6c00d4a34
commit 9315679dc7

@ -73,7 +73,8 @@ nv.addGraph(function() {
chart.yAxis
.axisLabel('Voltage (v)')
.tickFormat(d3.format(',.2f'));
.tickFormat(d3.format(',.2f'))
;
d3.select('#chart1 svg')
.datum(sinAndCos())

@ -952,6 +952,7 @@ nv.utils.optionsFunc = function(args) {
, staggerLabels = false
, isOrdinal = false
, ticks = null
, axisLabelDistance = 12 //The larger this number is, the closer the axis label is to the axis.
;
axis
@ -1143,7 +1144,7 @@ nv.utils.optionsFunc = function(args) {
axisLabel
.style('text-anchor', rotateYLabel ? 'middle' : 'end')
.attr('transform', rotateYLabel ? 'rotate(-90)' : '')
.attr('y', rotateYLabel ? (-Math.max(margin.left,width) + 12) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart
.attr('y', rotateYLabel ? (-Math.max(margin.left,width) + axisLabelDistance) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart
.attr('x', rotateYLabel ? (-scale.range()[0] / 2) : -axis.tickPadding());
if (showMaxMin) {
var axisMaxMin = wrap.selectAll('g.nv-axisMaxMin')
@ -1324,6 +1325,12 @@ nv.utils.optionsFunc = function(args) {
return chart;
};
chart.axisLabelDistance = function(_) {
if (!arguments.length) return axisLabelDistance;
axisLabelDistance = _;
return chart;
};
//============================================================

12
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -19,6 +19,7 @@ nv.models.axis = function() {
, staggerLabels = false
, isOrdinal = false
, ticks = null
, axisLabelDistance = 12 //The larger this number is, the closer the axis label is to the axis.
;
axis
@ -210,7 +211,7 @@ nv.models.axis = function() {
axisLabel
.style('text-anchor', rotateYLabel ? 'middle' : 'end')
.attr('transform', rotateYLabel ? 'rotate(-90)' : '')
.attr('y', rotateYLabel ? (-Math.max(margin.left,width) + 12) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart
.attr('y', rotateYLabel ? (-Math.max(margin.left,width) + axisLabelDistance) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart
.attr('x', rotateYLabel ? (-scale.range()[0] / 2) : -axis.tickPadding());
if (showMaxMin) {
var axisMaxMin = wrap.selectAll('g.nv-axisMaxMin')
@ -391,6 +392,12 @@ nv.models.axis = function() {
return chart;
};
chart.axisLabelDistance = function(_) {
if (!arguments.length) return axisLabelDistance;
axisLabelDistance = _;
return chart;
};
//============================================================

Loading…
Cancel
Save