Checking in a solution to making it possible to use

chart.options({}).  Instead of chaining properties,
you can pass chart properties in a hash.
Adding a optionsFunc template to utils.js, so it can reused in all chart
code.
master
Robin Hu 11 years ago
parent ce180645d1
commit 0edc568ad0

@ -56,12 +56,17 @@ svg {
var chart;
nv.addGraph(function() {
chart = nv.models.lineChart();
chart
.margin({left: 100, bottom: 100})
.x(function(d,i) { return i })
.transitionDuration(300)
;
chart = nv.models.lineChart()
.options({
margin: {left: 100, bottom: 100},
x: function(d,i) { return i},
showXAxis: true,
showYAxis: true,
transitionDuration: 250
})
;
chart.showXAxis(false);
// chart sub-models (ie. xAxis, yAxis, etc) when accessed directly, return themselves, not the parent chart, so need to chain separately
chart.xAxis
@ -72,8 +77,6 @@ nv.addGraph(function() {
.axisLabel('Voltage (v)')
.tickFormat(d3.format(',.2f'));
chart.showXAxis(true);
d3.select('#chart1 svg')
.datum(sinAndCos())
.call(chart);

@ -348,6 +348,8 @@ nv.models.lineChart = function() {
d3.rebind(chart, lines, 'defined', 'isArea', 'x', 'y', 'size', 'xScale', 'yScale', 'xDomain', 'yDomain', 'xRange', 'yRange'
, 'forceX', 'forceY', 'interactive', 'clipEdge', 'clipVoronoi', 'useVoronoi','id', 'interpolate');
chart.options = nv.utils.optionsFunc.bind(chart);
chart.margin = function(_) {
if (!arguments.length) return margin;
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;

@ -128,3 +128,25 @@ nv.utils.NaNtoZero = function(n) {
return n;
};
/*
Snippet of code you can insert into each nv.models.* to give you the ability to
do things like:
chart.options({
showXAxis: true,
tooltips: true
});
To enable in the chart:
chart.options = nv.utils.optionsFunc.bind(chart);
*/
nv.utils.optionsFunc = function(args) {
if (args) {
d3.map(args).forEach((function(key,value) {
if (typeof this[key] === "function") {
this[key](value);
}
}).bind(this));
}
return this;
};
Loading…
Cancel
Save