Skip to content

Instantly share code, notes, and snippets.

@RamonGilabert
Created March 1, 2019 17:21
Show Gist options
  • Save RamonGilabert/291e2ba4fa2dfc309c68c6b2bf641d6a to your computer and use it in GitHub Desktop.
Save RamonGilabert/291e2ba4fa2dfc309c68c6b2bf641d6a to your computer and use it in GitHub Desktop.
Graph Calculation
function Graph(top_point, bottom_point) {
const increments = [2.5, 5, 10];
const difference = top_point - bottom_point
const value = difference / 4;
var selected_increment = 0;
var iteration = 0
var multiplier = 1;
var gap = 0;
var bottom_graph = 0;
var top_graph = 0;
while(selected_increment == 0) {
increment = increments[iteration] * multiplier;
if (value - increment < 0) {
gap = increment * 4;
bottom_graph = Math.floor(bottom_point / increment) * increment;
top_graph = bottom_graph + gap;
if (top_graph > top_point && bottom_graph < bottom_point) {
selected_increment = increment;
break;
}
}
iteration = iteration + 1;
if (iteration == increments.length) {
iteration = 0;
multiplier = multiplier * 10;
}
}
console.log('The top and bottom point is [' + top_point + ', ' + bottom_point + ']');
console.log('The point is [' + top_graph + ', ' + bottom_graph + ']');
console.log('The increment is ' + selected_increment);
console.log(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment