Skip to content

Instantly share code, notes, and snippets.

@mrmans0n
Created September 28, 2012 09:21
Show Gist options
  • Save mrmans0n/3798841 to your computer and use it in GitHub Desktop.
Save mrmans0n/3798841 to your computer and use it in GitHub Desktop.
Calculate increment factor for graphs
// Obtenemos el factor de incremento para las graficas
- (NSInteger)calculateDividerForMaxValue:(NSNumber*)maxValue withBaseIncrement:(NSInteger)increment {
NSInteger resultDivide = [maxValue floatValue] / increment;
if (resultDivide<=kGraphMaximumHorizontalLines) {
if (resultDivide<kGraphMaximumHorizontalLines/2) {
return [self calculateDividerForMaxValue:maxValue withBaseIncrement:increment/2];
} else {
return increment;
}
}
NSInteger resultRemainder = resultDivide/kGraphMaximumHorizontalLines;
resultRemainder++;
return resultRemainder*increment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment