Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Y axis Ticks #2028

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/models/multiBarHorizontalChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ nv.models.multiBarHorizontalChart = function() {
if (showXAxis) {
xAxis
.scale(x)
._ticks( nv.utils.calcTicksY(availableHeight/24, data) )
._ticks( nv.utils.calcTicksX(availableHeight/24, data) )
.tickSize(-availableWidth, 0);

g.select('.nv-x.nv-axis').call(xAxis);
Expand All @@ -238,7 +238,7 @@ nv.models.multiBarHorizontalChart = function() {
if (showYAxis) {
yAxis
.scale(y)
._ticks( nv.utils.calcTicksX(availableWidth/100, data) )
._ticks( nv.utils.calcTicksY(availableWidth/100, data) )
.tickSize( -availableHeight, 0);

g.select('.nv-y.nv-axis')
Expand Down
22 changes: 20 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,26 @@ nv.utils.calcTicksX = function(numTicks, data) {
returns number of ticks to actually use on Y axis, based on chart data
*/
nv.utils.calcTicksY = function(numTicks, data) {
// currently uses the same logic but we can adjust here if needed later
return nv.utils.calcTicksX(numTicks, data);
// find max number of values from all data streams
var numValues = 1;
for (var i=0; i < data.length; i += 1) {
var values = data[i] && data[i].values ? data[i].values : [];
var maxValue;
for (var j=0; j < values.length; j += 1) {
maxValue = values[j] && values[j].value ? values[j].value : 0;
numValues = maxValue > numValues ? maxValue : numValues;
}
}
nv.log("Requested number of ticks: ", numTicks);
nv.log("Calculated max values to be: ", numValues);
// make sure we don't have more ticks than values to avoid duplicates
numTicks = numTicks > numValues ? numTicks = numValues - 1 : numTicks;
// make sure we have at least one tick
numTicks = numTicks < 1 ? 1 : numTicks;
// make sure it's an integer
numTicks = Math.floor(numTicks);
nv.log("Calculating tick count as: ", numTicks);
return numTicks;
};


Expand Down