Issue #68 updated axis model to standard format

master-patched
Bob Monteverde 12 years ago
parent 8349dea0aa
commit 9d4b0fb6a7

@ -296,38 +296,60 @@ nv.utils.pjax = function(links, content) {
}
nv.models.axis = function() {
//Default Settings
var width = 60, //only used for tickLabel currently
height = 60, //only used for tickLabel currently
scale = d3.scale.linear(),
axisLabelText = null,
showMaxMin = true, //TODO: showMaxMin should be disabled on all ordinal scaled axes
highlightZero = true,
rotateLabels = 0,
rotateYLabel = true,
margin = {top: 0, right: 0, bottom: 0, left: 0},
ticks = null;
//============================================================
// Public Variables with Default Settings
//------------------------------------------------------------
var margin = {top: 0, right: 0, bottom: 0, left: 0}
, width = 60 //only used for tickLabel currently
, height = 60 //only used for tickLabel currently
, scale = d3.scale.linear()
, axisLabelText = null
, showMaxMin = true //TODO: showMaxMin should be disabled on all ordinal scaled axes
, highlightZero = true
, rotateLabels = 0
, rotateYLabel = true
, ticks = null
;
//============================================================
//============================================================
// Private Variables
//------------------------------------------------------------
var axis = d3.svg.axis()
.scale(scale)
.orient('bottom')
.tickFormat(function(d) { return d }), //TODO: decide if we want to keep this
scale0;
.tickFormat(function(d) { return d }) //TODO: decide if we want to keep this
, scale0;
//============================================================
function chart(selection) {
selection.each(function(data) {
var container = d3.select(this);
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('g.nv-wrap.nv-axis').data([data]);
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-axis');
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
if (ticks !== null) {
//------------------------------------------------------------
if (ticks !== null)
axis.ticks(ticks);
} else if (axis.orient() == 'top' || axis.orient() == 'bottom') {
else if (axis.orient() == 'top' || axis.orient() == 'bottom')
axis.ticks(Math.abs(scale.range()[1] - scale.range()[0]) / 100);
}
//TODO: consider calculating width/height based on whether or not label is added, for reference in charts using this component
@ -527,18 +549,28 @@ nv.models.axis = function() {
.filter(function(d) { return !parseFloat(Math.round(d*100000)/1000000) }) //this is because sometimes the 0 tick is a very small fraction, TODO: think of cleaner technique
.classed('zero', true);
//store old scales for use in transitions on update
scale0 = scale.copy();
});
return chart;
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
d3.rebind(chart, axis, 'orient', 'tickValues', 'tickSubdivide', 'tickSize', 'tickPadding', 'tickFormat');
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands'); //these are also accessible by chart.scale(), but added common ones directly for ease of use
chart.margin = function(_) {
if(!arguments.length) return margin;
margin = _;
return chart;
}
chart.width = function(_) {
if (!arguments.length) return width;
width = _;
@ -582,21 +614,21 @@ nv.models.axis = function() {
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands');
return chart;
}
chart.rotateYLabel = function(_) {
if(!arguments.length) return rotateYLabel;
rotateYLabel = _;
return chart;
if(!arguments.length) return rotateYLabel;
rotateYLabel = _;
return chart;
}
chart.rotateLabels = function(_) {
if(!arguments.length) return rotateLabels;
rotateLabels = _;
return chart;
}
chart.margin = function(_) {
if(!arguments.length) return margin;
margin = _;
return chart;
}
//============================================================
return chart;
}

2
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,36 +1,58 @@
nv.models.axis = function() {
//Default Settings
var width = 60, //only used for tickLabel currently
height = 60, //only used for tickLabel currently
scale = d3.scale.linear(),
axisLabelText = null,
showMaxMin = true, //TODO: showMaxMin should be disabled on all ordinal scaled axes
highlightZero = true,
rotateLabels = 0,
rotateYLabel = true,
margin = {top: 0, right: 0, bottom: 0, left: 0},
ticks = null;
//============================================================
// Public Variables with Default Settings
//------------------------------------------------------------
var margin = {top: 0, right: 0, bottom: 0, left: 0}
, width = 60 //only used for tickLabel currently
, height = 60 //only used for tickLabel currently
, scale = d3.scale.linear()
, axisLabelText = null
, showMaxMin = true //TODO: showMaxMin should be disabled on all ordinal scaled axes
, highlightZero = true
, rotateLabels = 0
, rotateYLabel = true
, ticks = null
;
//============================================================
//============================================================
// Private Variables
//------------------------------------------------------------
var axis = d3.svg.axis()
.scale(scale)
.orient('bottom')
.tickFormat(function(d) { return d }), //TODO: decide if we want to keep this
scale0;
.tickFormat(function(d) { return d }) //TODO: decide if we want to keep this
, scale0;
//============================================================
function chart(selection) {
selection.each(function(data) {
var container = d3.select(this);
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('g.nv-wrap.nv-axis').data([data]);
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-axis');
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
if (ticks !== null) {
//------------------------------------------------------------
if (ticks !== null)
axis.ticks(ticks);
} else if (axis.orient() == 'top' || axis.orient() == 'bottom') {
else if (axis.orient() == 'top' || axis.orient() == 'bottom')
axis.ticks(Math.abs(scale.range()[1] - scale.range()[0]) / 100);
}
//TODO: consider calculating width/height based on whether or not label is added, for reference in charts using this component
@ -230,18 +252,28 @@ nv.models.axis = function() {
.filter(function(d) { return !parseFloat(Math.round(d*100000)/1000000) }) //this is because sometimes the 0 tick is a very small fraction, TODO: think of cleaner technique
.classed('zero', true);
//store old scales for use in transitions on update
scale0 = scale.copy();
});
return chart;
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
d3.rebind(chart, axis, 'orient', 'tickValues', 'tickSubdivide', 'tickSize', 'tickPadding', 'tickFormat');
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands'); //these are also accessible by chart.scale(), but added common ones directly for ease of use
chart.margin = function(_) {
if(!arguments.length) return margin;
margin = _;
return chart;
}
chart.width = function(_) {
if (!arguments.length) return width;
width = _;
@ -285,21 +317,21 @@ nv.models.axis = function() {
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands');
return chart;
}
chart.rotateYLabel = function(_) {
if(!arguments.length) return rotateYLabel;
rotateYLabel = _;
return chart;
if(!arguments.length) return rotateYLabel;
rotateYLabel = _;
return chart;
}
chart.rotateLabels = function(_) {
if(!arguments.length) return rotateLabels;
rotateLabels = _;
return chart;
}
chart.margin = function(_) {
if(!arguments.length) return margin;
margin = _;
return chart;
}
//============================================================
return chart;
}

Loading…
Cancel
Save