Merge branch 'development' of https://github.com/novus/nvd3 into development

master
Tyler Wolf 11 years ago
commit deed5470f3

@ -1503,6 +1503,9 @@ nv.models.cumulativeLineChart = function() {
, width = null , width = null
, height = null , height = null
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, tooltips = true , tooltips = true
, showControls = true , showControls = true
, rescaleY = true , rescaleY = true
@ -1525,7 +1528,7 @@ nv.models.cumulativeLineChart = function() {
.tickPadding(7) .tickPadding(7)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
; ;
//============================================================ //============================================================
@ -1764,6 +1767,10 @@ nv.models.cumulativeLineChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
// Show error if series goes below 100% // Show error if series goes below 100%
var tempDisabled = data.filter(function(d) { return d.tempDisabled }); var tempDisabled = data.filter(function(d) { return d.tempDisabled });
@ -1859,26 +1866,29 @@ nv.models.cumulativeLineChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
//Suggest how many ticks based on the chart width and D3 should listen (70 is the optimal number for MM/DD/YY dates) .scale(x)
.ticks( Math.min(data[0].values.length,availableWidth/70) ) //Suggest how many ticks based on the chart width and D3 should listen (70 is the optimal number for MM/DD/YY dates)
.tickSize(-availableHeight, 0); .ticks( Math.min(data[0].values.length,availableWidth/70) )
.tickSize(-availableHeight, 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
}
yAxis
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis')) if (showYAxis) {
.call(yAxis); yAxis
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis'))
.call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -2095,6 +2105,25 @@ nv.models.cumulativeLineChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.tooltips = function(_) { chart.tooltips = function(_) {
if (!arguments.length) return tooltips; if (!arguments.length) return tooltips;
tooltips = _; tooltips = _;
@ -2512,6 +2541,9 @@ nv.models.discreteBarChart = function() {
, width = null , width = null
, height = null , height = null
, color = nv.utils.getColor() , color = nv.utils.getColor()
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, staggerLabels = false , staggerLabels = false
, tooltips = true , tooltips = true
, tooltip = function(key, x, y, e, graph) { , tooltip = function(key, x, y, e, graph) {
@ -2531,7 +2563,7 @@ nv.models.discreteBarChart = function() {
.tickFormat(function(d) { return d }) .tickFormat(function(d) { return d })
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickFormat(d3.format(',.1f')) .tickFormat(d3.format(',.1f'))
; ;
@ -2617,6 +2649,11 @@ nv.models.discreteBarChart = function() {
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -2650,33 +2687,37 @@ nv.models.discreteBarChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( availableWidth / 100 ) .scale(x)
.tickSize(-availableHeight, 0); .ticks( availableWidth / 100 )
.tickSize(-availableHeight, 0);
g.select('.nv-x.nv-axis') g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')'); .attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')');
//d3.transition(g.select('.nv-x.nv-axis')) //d3.transition(g.select('.nv-x.nv-axis'))
g.select('.nv-x.nv-axis').transition().duration(0) g.select('.nv-x.nv-axis').transition().duration(0)
.call(xAxis); .call(xAxis);
var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); var xTicks = g.select('.nv-x.nv-axis').selectAll('g');
if (staggerLabels) { if (staggerLabels) {
xTicks xTicks
.selectAll('text') .selectAll('text')
.attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 == 0 ? '5' : '17') + ')' }) .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 == 0 ? '5' : '17') + ')' })
}
} }
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis')) d3.transition(g.select('.nv-y.nv-axis'))
.call(yAxis); .call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -2757,6 +2798,25 @@ nv.models.discreteBarChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.staggerLabels = function(_) { chart.staggerLabels = function(_) {
if (!arguments.length) return staggerLabels; if (!arguments.length) return staggerLabels;
staggerLabels = _; staggerLabels = _;
@ -7011,6 +7071,9 @@ nv.models.multiBarChart = function() {
, color = nv.utils.defaultColor() , color = nv.utils.defaultColor()
, showControls = true , showControls = true
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, reduceXTicks = true // if false a tick will show for every data point , reduceXTicks = true // if false a tick will show for every data point
, staggerLabels = false , staggerLabels = false
, rotateLabels = 0 , rotateLabels = 0
@ -7039,7 +7102,7 @@ nv.models.multiBarChart = function() {
.tickFormat(function(d) { return d }) .tickFormat(function(d) { return d })
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickFormat(d3.format(',.1f')) .tickFormat(d3.format(',.1f'))
; ;
@ -7187,6 +7250,10 @@ nv.models.multiBarChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
// Main Chart Component(s) // Main Chart Component(s)
@ -7211,67 +7278,71 @@ nv.models.multiBarChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( availableWidth / 100 ) .scale(x)
.tickSize(-availableHeight, 0); .ticks( availableWidth / 100 )
.tickSize(-availableHeight, 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g');
xTicks g.select('.nv-x.nv-axis')
.selectAll('line, text') .attr('transform', 'translate(0,' + y.range()[0] + ')');
.style('opacity', 1) d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
if (staggerLabels) { var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g');
var getTranslate = function(x,y) {
return "translate(" + x + "," + y + ")";
};
var staggerUp = 5, staggerDown = 17; //pixels to stagger by
// Issue #140
xTicks xTicks
.selectAll("text") .selectAll('line, text')
.attr('transform', function(d,i,j) { .style('opacity', 1)
return getTranslate(0, (j % 2 == 0 ? staggerUp : staggerDown));
}); if (staggerLabels) {
var getTranslate = function(x,y) {
return "translate(" + x + "," + y + ")";
};
var staggerUp = 5, staggerDown = 17; //pixels to stagger by
// Issue #140
xTicks
.selectAll("text")
.attr('transform', function(d,i,j) {
return getTranslate(0, (j % 2 == 0 ? staggerUp : staggerDown));
});
var totalInBetweenTicks = d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length;
g.selectAll(".nv-x.nv-axis .nv-axisMaxMin text")
.attr("transform", function(d,i) {
return getTranslate(0, (i === 0 || totalInBetweenTicks % 2 !== 0) ? staggerDown : staggerUp);
});
}
var totalInBetweenTicks = d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length; if (reduceXTicks)
g.selectAll(".nv-x.nv-axis .nv-axisMaxMin text") xTicks
.attr("transform", function(d,i) { .filter(function(d,i) {
return getTranslate(0, (i === 0 || totalInBetweenTicks % 2 !== 0) ? staggerDown : staggerUp); return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0;
}); })
} .selectAll('text, line')
.style('opacity', 0);
if(rotateLabels)
xTicks
.selectAll('text')
.attr('transform', 'rotate(' + rotateLabels + ' 0,0)')
.attr('text-anchor', rotateLabels > 0 ? 'start' : 'end');
g.select('.nv-x.nv-axis').selectAll('g.nv-axisMaxMin text')
.style('opacity', 1);
}
if (reduceXTicks)
xTicks
.filter(function(d,i) {
return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0;
})
.selectAll('text, line')
.style('opacity', 0);
if(rotateLabels)
xTicks
.selectAll('text')
.attr('transform', 'rotate(' + rotateLabels + ' 0,0)')
.attr('text-anchor', rotateLabels > 0 ? 'start' : 'end');
g.select('.nv-x.nv-axis').selectAll('g.nv-axisMaxMin text')
.style('opacity', 1);
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis')) d3.transition(g.select('.nv-y.nv-axis'))
.call(yAxis); .call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -7438,6 +7509,25 @@ nv.models.multiBarChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.reduceXTicks= function(_) { chart.reduceXTicks= function(_) {
if (!arguments.length) return reduceXTicks; if (!arguments.length) return reduceXTicks;
reduceXTicks = _; reduceXTicks = _;
@ -10549,13 +10639,15 @@ nv.models.scatterChart = function() {
, showDistX = false , showDistX = false
, showDistY = false , showDistY = false
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, showControls = !!d3.fisheye , showControls = !!d3.fisheye
, fisheye = 0 , fisheye = 0
, pauseFisheye = false , pauseFisheye = false
, tooltips = true , tooltips = true
, tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' } , tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' }
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' } , tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
//, tooltip = function(key, x, y) { return '<h3>' + key + '</h3>' }
, tooltip = null , tooltip = null
, state = {} , state = {}
, defaultState = null , defaultState = null
@ -10572,7 +10664,7 @@ nv.models.scatterChart = function() {
.tickPadding(10) .tickPadding(10)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickPadding(10) .tickPadding(10)
; ;
distX distX
@ -10738,6 +10830,10 @@ nv.models.scatterChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
// Main Chart Component(s) // Main Chart Component(s)
@ -10776,24 +10872,27 @@ nv.models.scatterChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
if (showXAxis) {
xAxis
.scale(x)
.ticks( xAxis.ticks() && xAxis.ticks().length ? xAxis.ticks() : availableWidth / 100 )
.tickSize( -availableHeight , 0);
xAxis g.select('.nv-x.nv-axis')
.scale(x) .attr('transform', 'translate(0,' + y.range()[0] + ')')
.ticks( xAxis.ticks() && xAxis.ticks().length ? xAxis.ticks() : availableWidth / 100 ) .call(xAxis);
.tickSize( -availableHeight , 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
}
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( yAxis.ticks() && yAxis.ticks().length ? yAxis.ticks() : availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( yAxis.ticks() && yAxis.ticks().length ? yAxis.ticks() : availableHeight / 36 )
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis') g.select('.nv-y.nv-axis')
.call(yAxis); .call(yAxis);
}
if (showDistX) { if (showDistX) {
@ -10823,7 +10922,8 @@ nv.models.scatterChart = function() {
gEnter.select('.nv-distWrap').append('g') gEnter.select('.nv-distWrap').append('g')
.attr('class', 'nv-distributionY'); .attr('class', 'nv-distributionY');
g.select('.nv-distributionY') g.select('.nv-distributionY')
.attr('transform', 'translate(-' + distY.size() + ',0)') .attr('transform',
'translate(' + (rightAlignYAxis ? availableWidth : -distY.size() ) + ',0)')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distY); .call(distY);
} }
@ -10861,8 +10961,12 @@ nv.models.scatterChart = function() {
g.select('.nv-scatterWrap') g.select('.nv-scatterWrap')
.call(scatter); .call(scatter);
g.select('.nv-x.nv-axis').call(xAxis); if (showXAxis)
g.select('.nv-y.nv-axis').call(yAxis); g.select('.nv-x.nv-axis').call(xAxis);
if (showYAxis)
g.select('.nv-y.nv-axis').call(yAxis);
g.select('.nv-distributionX') g.select('.nv-distributionX')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distX); .call(distX);
@ -11071,6 +11175,26 @@ nv.models.scatterChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.fisheye = function(_) { chart.fisheye = function(_) {
if (!arguments.length) return fisheye; if (!arguments.length) return fisheye;
fisheye = _; fisheye = _;
@ -11161,6 +11285,9 @@ nv.models.scatterPlusLineChart = function() {
, showDistX = false , showDistX = false
, showDistY = false , showDistY = false
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, showControls = !!d3.fisheye , showControls = !!d3.fisheye
, fisheye = 0 , fisheye = 0
, pauseFisheye = false , pauseFisheye = false
@ -11169,7 +11296,6 @@ nv.models.scatterPlusLineChart = function() {
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' } , tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
, tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>' , tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>'
+ '<p>' + date + '</p>' } + '<p>' + date + '</p>' }
//, tooltip = null
, state = {} , state = {}
, defaultState = null , defaultState = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
@ -11185,7 +11311,7 @@ nv.models.scatterPlusLineChart = function() {
.tickPadding(10) .tickPadding(10)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickPadding(10) .tickPadding(10)
; ;
distX distX
@ -11315,6 +11441,11 @@ nv.models.scatterPlusLineChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -11399,23 +11530,26 @@ nv.models.scatterPlusLineChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( xAxis.ticks() ? xAxis.ticks() : availableWidth / 100 ) .scale(x)
.tickSize( -availableHeight , 0); .ticks( xAxis.ticks() ? xAxis.ticks() : availableWidth / 100 )
.tickSize( -availableHeight , 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
}
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( yAxis.ticks() ? yAxis.ticks() : availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( yAxis.ticks() ? yAxis.ticks() : availableHeight / 36 )
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis') g.select('.nv-y.nv-axis')
.call(yAxis); .call(yAxis);
}
if (showDistX) { if (showDistX) {
@ -11445,7 +11579,7 @@ nv.models.scatterPlusLineChart = function() {
gEnter.select('.nv-distWrap').append('g') gEnter.select('.nv-distWrap').append('g')
.attr('class', 'nv-distributionY'); .attr('class', 'nv-distributionY');
g.select('.nv-distributionY') g.select('.nv-distributionY')
.attr('transform', 'translate(-' + distY.size() + ',0)') .attr('transform', 'translate(' + (rightAlignYAxis ? availableWidth : -distY.size() ) + ',0)')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distY); .call(distY);
} }
@ -11483,8 +11617,13 @@ nv.models.scatterPlusLineChart = function() {
g.select('.nv-scatterWrap') g.select('.nv-scatterWrap')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(scatter); .call(scatter);
g.select('.nv-x.nv-axis').call(xAxis);
g.select('.nv-y.nv-axis').call(yAxis); if (showXAxis)
g.select('.nv-x.nv-axis').call(xAxis);
if (showYAxis)
g.select('.nv-y.nv-axis').call(yAxis);
g.select('.nv-distributionX') g.select('.nv-distributionX')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distX); .call(distX);
@ -11693,6 +11832,25 @@ nv.models.scatterPlusLineChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.fisheye = function(_) { chart.fisheye = function(_) {
if (!arguments.length) return fisheye; if (!arguments.length) return fisheye;
fisheye = _; fisheye = _;
@ -12574,6 +12732,9 @@ nv.models.stackedAreaChart = function() {
, color = nv.utils.defaultColor() // a function that takes in d, i and returns color , color = nv.utils.defaultColor() // a function that takes in d, i and returns color
, showControls = true , showControls = true
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, tooltips = true , tooltips = true
, tooltip = function(key, x, y, e, graph) { , tooltip = function(key, x, y, e, graph) {
return '<h3>' + key + '</h3>' + return '<h3>' + key + '</h3>' +
@ -12594,7 +12755,7 @@ nv.models.stackedAreaChart = function() {
.tickPadding(7) .tickPadding(7)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
; ;
stacked.scatter stacked.scatter
.pointActive(function(d) { .pointActive(function(d) {
@ -12758,6 +12919,10 @@ nv.models.stackedAreaChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
// Main Chart Component(s) // Main Chart Component(s)
@ -12777,28 +12942,32 @@ nv.models.stackedAreaChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( availableWidth / 100 ) .scale(x)
.tickSize( -availableHeight, 0); .ticks( availableWidth / 100 )
.tickSize( -availableHeight, 0);
g.select('.nv-x.nv-axis') g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + availableHeight + ')'); .attr('transform', 'translate(0,' + availableHeight + ')');
//d3.transition(g.select('.nv-x.nv-axis'))
g.select('.nv-x.nv-axis') g.select('.nv-x.nv-axis')
.transition().duration(0) .transition().duration(0)
.call(xAxis); .call(xAxis);
}
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks(stacked.offset() == 'wiggle' ? 0 : availableHeight / 36) .scale(y)
.tickSize(-availableWidth, 0) .ticks(stacked.offset() == 'wiggle' ? 0 : availableHeight / 36)
.setTickFormat(stacked.offset() == 'expand' ? d3.format('%') : yAxisTickFormat); .tickSize(-availableWidth, 0)
.setTickFormat(stacked.offset() == 'expand' ? d3.format('%') : yAxisTickFormat);
//d3.transition(g.select('.nv-y.nv-axis'))
g.select('.nv-y.nv-axis') g.select('.nv-y.nv-axis')
.transition().duration(0) .transition().duration(0)
.call(yAxis); .call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -12996,6 +13165,25 @@ nv.models.stackedAreaChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.tooltip = function(_) { chart.tooltip = function(_) {
if (!arguments.length) return tooltip; if (!arguments.length) return tooltip;
tooltip = _; tooltip = _;

12
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -17,6 +17,9 @@ nv.models.cumulativeLineChart = function() {
, width = null , width = null
, height = null , height = null
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, tooltips = true , tooltips = true
, showControls = true , showControls = true
, rescaleY = true , rescaleY = true
@ -39,7 +42,7 @@ nv.models.cumulativeLineChart = function() {
.tickPadding(7) .tickPadding(7)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
; ;
//============================================================ //============================================================
@ -278,6 +281,10 @@ nv.models.cumulativeLineChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
// Show error if series goes below 100% // Show error if series goes below 100%
var tempDisabled = data.filter(function(d) { return d.tempDisabled }); var tempDisabled = data.filter(function(d) { return d.tempDisabled });
@ -373,26 +380,29 @@ nv.models.cumulativeLineChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
//Suggest how many ticks based on the chart width and D3 should listen (70 is the optimal number for MM/DD/YY dates) .scale(x)
.ticks( Math.min(data[0].values.length,availableWidth/70) ) //Suggest how many ticks based on the chart width and D3 should listen (70 is the optimal number for MM/DD/YY dates)
.tickSize(-availableHeight, 0); .ticks( Math.min(data[0].values.length,availableWidth/70) )
.tickSize(-availableHeight, 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis')
d3.transition(g.select('.nv-x.nv-axis')) .attr('transform', 'translate(0,' + y.range()[0] + ')');
.call(xAxis); d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
}
yAxis
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis')) if (showYAxis) {
.call(yAxis); yAxis
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis'))
.call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -609,6 +619,25 @@ nv.models.cumulativeLineChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.tooltips = function(_) { chart.tooltips = function(_) {
if (!arguments.length) return tooltips; if (!arguments.length) return tooltips;
tooltips = _; tooltips = _;

@ -14,6 +14,9 @@ nv.models.discreteBarChart = function() {
, width = null , width = null
, height = null , height = null
, color = nv.utils.getColor() , color = nv.utils.getColor()
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, staggerLabels = false , staggerLabels = false
, tooltips = true , tooltips = true
, tooltip = function(key, x, y, e, graph) { , tooltip = function(key, x, y, e, graph) {
@ -33,7 +36,7 @@ nv.models.discreteBarChart = function() {
.tickFormat(function(d) { return d }) .tickFormat(function(d) { return d })
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickFormat(d3.format(',.1f')) .tickFormat(d3.format(',.1f'))
; ;
@ -119,6 +122,11 @@ nv.models.discreteBarChart = function() {
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -152,33 +160,37 @@ nv.models.discreteBarChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( availableWidth / 100 ) .scale(x)
.tickSize(-availableHeight, 0); .ticks( availableWidth / 100 )
.tickSize(-availableHeight, 0);
g.select('.nv-x.nv-axis') g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')'); .attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')');
//d3.transition(g.select('.nv-x.nv-axis')) //d3.transition(g.select('.nv-x.nv-axis'))
g.select('.nv-x.nv-axis').transition().duration(0) g.select('.nv-x.nv-axis').transition().duration(0)
.call(xAxis); .call(xAxis);
var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); var xTicks = g.select('.nv-x.nv-axis').selectAll('g');
if (staggerLabels) { if (staggerLabels) {
xTicks xTicks
.selectAll('text') .selectAll('text')
.attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 == 0 ? '5' : '17') + ')' }) .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 == 0 ? '5' : '17') + ')' })
}
} }
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis')) d3.transition(g.select('.nv-y.nv-axis'))
.call(yAxis); .call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -259,6 +271,25 @@ nv.models.discreteBarChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.staggerLabels = function(_) { chart.staggerLabels = function(_) {
if (!arguments.length) return staggerLabels; if (!arguments.length) return staggerLabels;
staggerLabels = _; staggerLabels = _;

@ -18,6 +18,9 @@ nv.models.multiBarChart = function() {
, color = nv.utils.defaultColor() , color = nv.utils.defaultColor()
, showControls = true , showControls = true
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, reduceXTicks = true // if false a tick will show for every data point , reduceXTicks = true // if false a tick will show for every data point
, staggerLabels = false , staggerLabels = false
, rotateLabels = 0 , rotateLabels = 0
@ -46,7 +49,7 @@ nv.models.multiBarChart = function() {
.tickFormat(function(d) { return d }) .tickFormat(function(d) { return d })
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickFormat(d3.format(',.1f')) .tickFormat(d3.format(',.1f'))
; ;
@ -194,6 +197,10 @@ nv.models.multiBarChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
// Main Chart Component(s) // Main Chart Component(s)
@ -218,67 +225,71 @@ nv.models.multiBarChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( availableWidth / 100 ) .scale(x)
.tickSize(-availableHeight, 0); .ticks( availableWidth / 100 )
.tickSize(-availableHeight, 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g'); g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.nv-x.nv-axis'))
.call(xAxis);
xTicks var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g');
.selectAll('line, text')
.style('opacity', 1)
if (staggerLabels) {
var getTranslate = function(x,y) {
return "translate(" + x + "," + y + ")";
};
var staggerUp = 5, staggerDown = 17; //pixels to stagger by
// Issue #140
xTicks xTicks
.selectAll("text") .selectAll('line, text')
.attr('transform', function(d,i,j) { .style('opacity', 1)
return getTranslate(0, (j % 2 == 0 ? staggerUp : staggerDown));
}); if (staggerLabels) {
var getTranslate = function(x,y) {
var totalInBetweenTicks = d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length; return "translate(" + x + "," + y + ")";
g.selectAll(".nv-x.nv-axis .nv-axisMaxMin text") };
.attr("transform", function(d,i) {
return getTranslate(0, (i === 0 || totalInBetweenTicks % 2 !== 0) ? staggerDown : staggerUp); var staggerUp = 5, staggerDown = 17; //pixels to stagger by
}); // Issue #140
xTicks
.selectAll("text")
.attr('transform', function(d,i,j) {
return getTranslate(0, (j % 2 == 0 ? staggerUp : staggerDown));
});
var totalInBetweenTicks = d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length;
g.selectAll(".nv-x.nv-axis .nv-axisMaxMin text")
.attr("transform", function(d,i) {
return getTranslate(0, (i === 0 || totalInBetweenTicks % 2 !== 0) ? staggerDown : staggerUp);
});
}
if (reduceXTicks)
xTicks
.filter(function(d,i) {
return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0;
})
.selectAll('text, line')
.style('opacity', 0);
if(rotateLabels)
xTicks
.selectAll('text')
.attr('transform', 'rotate(' + rotateLabels + ' 0,0)')
.attr('text-anchor', rotateLabels > 0 ? 'start' : 'end');
g.select('.nv-x.nv-axis').selectAll('g.nv-axisMaxMin text')
.style('opacity', 1);
} }
if (reduceXTicks) if (showYAxis) {
xTicks yAxis
.filter(function(d,i) { .scale(y)
return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0; .ticks( availableHeight / 36 )
}) .tickSize( -availableWidth, 0);
.selectAll('text, line')
.style('opacity', 0);
if(rotateLabels)
xTicks
.selectAll('text')
.attr('transform', 'rotate(' + rotateLabels + ' 0,0)')
.attr('text-anchor', rotateLabels > 0 ? 'start' : 'end');
g.select('.nv-x.nv-axis').selectAll('g.nv-axisMaxMin text')
.style('opacity', 1);
yAxis d3.transition(g.select('.nv-y.nv-axis'))
.scale(y) .call(yAxis);
.ticks( availableHeight / 36 ) }
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis'))
.call(yAxis);
//------------------------------------------------------------ //------------------------------------------------------------
@ -445,6 +456,25 @@ nv.models.multiBarChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.reduceXTicks= function(_) { chart.reduceXTicks= function(_) {
if (!arguments.length) return reduceXTicks; if (!arguments.length) return reduceXTicks;
reduceXTicks = _; reduceXTicks = _;

@ -25,13 +25,15 @@ nv.models.scatterChart = function() {
, showDistX = false , showDistX = false
, showDistY = false , showDistY = false
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, showControls = !!d3.fisheye , showControls = !!d3.fisheye
, fisheye = 0 , fisheye = 0
, pauseFisheye = false , pauseFisheye = false
, tooltips = true , tooltips = true
, tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' } , tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' }
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' } , tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
//, tooltip = function(key, x, y) { return '<h3>' + key + '</h3>' }
, tooltip = null , tooltip = null
, state = {} , state = {}
, defaultState = null , defaultState = null
@ -48,7 +50,7 @@ nv.models.scatterChart = function() {
.tickPadding(10) .tickPadding(10)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickPadding(10) .tickPadding(10)
; ;
distX distX
@ -214,6 +216,10 @@ nv.models.scatterChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
// Main Chart Component(s) // Main Chart Component(s)
@ -252,24 +258,27 @@ nv.models.scatterChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
if (showXAxis) {
xAxis
.scale(x)
.ticks( xAxis.ticks() && xAxis.ticks().length ? xAxis.ticks() : availableWidth / 100 )
.tickSize( -availableHeight , 0);
xAxis g.select('.nv-x.nv-axis')
.scale(x) .attr('transform', 'translate(0,' + y.range()[0] + ')')
.ticks( xAxis.ticks() && xAxis.ticks().length ? xAxis.ticks() : availableWidth / 100 ) .call(xAxis);
.tickSize( -availableHeight , 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
}
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( yAxis.ticks() && yAxis.ticks().length ? yAxis.ticks() : availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( yAxis.ticks() && yAxis.ticks().length ? yAxis.ticks() : availableHeight / 36 )
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis') g.select('.nv-y.nv-axis')
.call(yAxis); .call(yAxis);
}
if (showDistX) { if (showDistX) {
@ -299,7 +308,8 @@ nv.models.scatterChart = function() {
gEnter.select('.nv-distWrap').append('g') gEnter.select('.nv-distWrap').append('g')
.attr('class', 'nv-distributionY'); .attr('class', 'nv-distributionY');
g.select('.nv-distributionY') g.select('.nv-distributionY')
.attr('transform', 'translate(-' + distY.size() + ',0)') .attr('transform',
'translate(' + (rightAlignYAxis ? availableWidth : -distY.size() ) + ',0)')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distY); .call(distY);
} }
@ -337,8 +347,12 @@ nv.models.scatterChart = function() {
g.select('.nv-scatterWrap') g.select('.nv-scatterWrap')
.call(scatter); .call(scatter);
g.select('.nv-x.nv-axis').call(xAxis); if (showXAxis)
g.select('.nv-y.nv-axis').call(yAxis); g.select('.nv-x.nv-axis').call(xAxis);
if (showYAxis)
g.select('.nv-y.nv-axis').call(yAxis);
g.select('.nv-distributionX') g.select('.nv-distributionX')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distX); .call(distX);
@ -547,6 +561,26 @@ nv.models.scatterChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.fisheye = function(_) { chart.fisheye = function(_) {
if (!arguments.length) return fisheye; if (!arguments.length) return fisheye;
fisheye = _; fisheye = _;

@ -23,6 +23,9 @@ nv.models.scatterPlusLineChart = function() {
, showDistX = false , showDistX = false
, showDistY = false , showDistY = false
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, showControls = !!d3.fisheye , showControls = !!d3.fisheye
, fisheye = 0 , fisheye = 0
, pauseFisheye = false , pauseFisheye = false
@ -31,7 +34,6 @@ nv.models.scatterPlusLineChart = function() {
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' } , tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
, tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>' , tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>'
+ '<p>' + date + '</p>' } + '<p>' + date + '</p>' }
//, tooltip = null
, state = {} , state = {}
, defaultState = null , defaultState = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
@ -47,7 +49,7 @@ nv.models.scatterPlusLineChart = function() {
.tickPadding(10) .tickPadding(10)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
.tickPadding(10) .tickPadding(10)
; ;
distX distX
@ -177,6 +179,11 @@ nv.models.scatterPlusLineChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -261,23 +268,26 @@ nv.models.scatterPlusLineChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( xAxis.ticks() ? xAxis.ticks() : availableWidth / 100 ) .scale(x)
.tickSize( -availableHeight , 0); .ticks( xAxis.ticks() ? xAxis.ticks() : availableWidth / 100 )
.tickSize( -availableHeight , 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')')
.call(xAxis);
}
yAxis if (showYAxis) {
.scale(y) yAxis
.ticks( yAxis.ticks() ? yAxis.ticks() : availableHeight / 36 ) .scale(y)
.tickSize( -availableWidth, 0); .ticks( yAxis.ticks() ? yAxis.ticks() : availableHeight / 36 )
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis') g.select('.nv-y.nv-axis')
.call(yAxis); .call(yAxis);
}
if (showDistX) { if (showDistX) {
@ -307,7 +317,7 @@ nv.models.scatterPlusLineChart = function() {
gEnter.select('.nv-distWrap').append('g') gEnter.select('.nv-distWrap').append('g')
.attr('class', 'nv-distributionY'); .attr('class', 'nv-distributionY');
g.select('.nv-distributionY') g.select('.nv-distributionY')
.attr('transform', 'translate(-' + distY.size() + ',0)') .attr('transform', 'translate(' + (rightAlignYAxis ? availableWidth : -distY.size() ) + ',0)')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distY); .call(distY);
} }
@ -345,8 +355,13 @@ nv.models.scatterPlusLineChart = function() {
g.select('.nv-scatterWrap') g.select('.nv-scatterWrap')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(scatter); .call(scatter);
g.select('.nv-x.nv-axis').call(xAxis);
g.select('.nv-y.nv-axis').call(yAxis); if (showXAxis)
g.select('.nv-x.nv-axis').call(xAxis);
if (showYAxis)
g.select('.nv-y.nv-axis').call(yAxis);
g.select('.nv-distributionX') g.select('.nv-distributionX')
.datum(data.filter(function(d) { return !d.disabled })) .datum(data.filter(function(d) { return !d.disabled }))
.call(distX); .call(distX);
@ -555,6 +570,25 @@ nv.models.scatterPlusLineChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.fisheye = function(_) { chart.fisheye = function(_) {
if (!arguments.length) return fisheye; if (!arguments.length) return fisheye;
fisheye = _; fisheye = _;

@ -18,6 +18,9 @@ nv.models.stackedAreaChart = function() {
, color = nv.utils.defaultColor() // a function that takes in d, i and returns color , color = nv.utils.defaultColor() // a function that takes in d, i and returns color
, showControls = true , showControls = true
, showLegend = true , showLegend = true
, showXAxis = true
, showYAxis = true
, rightAlignYAxis = false
, tooltips = true , tooltips = true
, tooltip = function(key, x, y, e, graph) { , tooltip = function(key, x, y, e, graph) {
return '<h3>' + key + '</h3>' + return '<h3>' + key + '</h3>' +
@ -38,7 +41,7 @@ nv.models.stackedAreaChart = function() {
.tickPadding(7) .tickPadding(7)
; ;
yAxis yAxis
.orient('left') .orient((rightAlignYAxis) ? 'right' : 'left')
; ;
stacked.scatter stacked.scatter
.pointActive(function(d) { .pointActive(function(d) {
@ -202,6 +205,10 @@ nv.models.stackedAreaChart = function() {
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
if (rightAlignYAxis) {
g.select(".nv-y.nv-axis")
.attr("transform", "translate(" + availableWidth + ",0)");
}
//------------------------------------------------------------ //------------------------------------------------------------
// Main Chart Component(s) // Main Chart Component(s)
@ -221,28 +228,32 @@ nv.models.stackedAreaChart = function() {
//------------------------------------------------------------ //------------------------------------------------------------
// Setup Axes // Setup Axes
xAxis if (showXAxis) {
.scale(x) xAxis
.ticks( availableWidth / 100 ) .scale(x)
.tickSize( -availableHeight, 0); .ticks( availableWidth / 100 )
.tickSize( -availableHeight, 0);
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + availableHeight + ')'); g.select('.nv-x.nv-axis')
//d3.transition(g.select('.nv-x.nv-axis')) .attr('transform', 'translate(0,' + availableHeight + ')');
g.select('.nv-x.nv-axis')
.transition().duration(0) g.select('.nv-x.nv-axis')
.call(xAxis); .transition().duration(0)
.call(xAxis);
yAxis }
.scale(y)
.ticks(stacked.offset() == 'wiggle' ? 0 : availableHeight / 36) if (showYAxis) {
.tickSize(-availableWidth, 0) yAxis
.setTickFormat(stacked.offset() == 'expand' ? d3.format('%') : yAxisTickFormat); .scale(y)
.ticks(stacked.offset() == 'wiggle' ? 0 : availableHeight / 36)
//d3.transition(g.select('.nv-y.nv-axis')) .tickSize(-availableWidth, 0)
g.select('.nv-y.nv-axis') .setTickFormat(stacked.offset() == 'expand' ? d3.format('%') : yAxisTickFormat);
.transition().duration(0)
.call(yAxis);
g.select('.nv-y.nv-axis')
.transition().duration(0)
.call(yAxis);
}
//------------------------------------------------------------ //------------------------------------------------------------
@ -440,6 +451,25 @@ nv.models.stackedAreaChart = function() {
return chart; return chart;
}; };
chart.showXAxis = function(_) {
if (!arguments.length) return showXAxis;
showXAxis = _;
return chart;
};
chart.showYAxis = function(_) {
if (!arguments.length) return showYAxis;
showYAxis = _;
return chart;
};
chart.rightAlignYAxis = function(_) {
if(!arguments.length) return rightAlignYAxis;
rightAlignYAxis = _;
yAxis.orient( (_) ? 'right' : 'left');
return chart;
};
chart.tooltip = function(_) { chart.tooltip = function(_) {
if (!arguments.length) return tooltip; if (!arguments.length) return tooltip;
tooltip = _; tooltip = _;

Loading…
Cancel
Save