-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[discreteBarChart] Fix y axis ticks number calculation. #2105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,11 +450,33 @@ 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 | ||
returns number of ticks to actually use on Y axis, based on chart data | ||
*/ | ||
nv.utils.calcTicksY = function(numTicks, data, getY) { | ||
if (getY) { | ||
// find max number of values from all data streams | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is incorrect |
||
var numValues = 1; | ||
for (var i=0; i < data.length; i += 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code fails linting guidelines |
||
var values = data[i] && data[i].values ? data[i].values : []; | ||
var maxValue; | ||
for (var j=0; j < values.length; j += 1) { | ||
maxValue = values[j] && getY(values[j]) ? getY(values[j]): 0; | ||
numValues = maxValue > numValues ? maxValue : numValues; | ||
} | ||
} | ||
nv.log("Requested number of ticks: ", numTicks); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debugging code should be removed |
||
nv.log("Calculated max values to be: ", numValues); | ||
// make sure we don't have more ticks than values to avoid duplicates | ||
numTicks = numTicks > numValues ? 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; | ||
} else { | ||
return nv.utils.calcTicksX(numTicks, data); | ||
} | ||
}; | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be unit tests for this function