I'm very new in js, I'm working on project for wingsuit pilots (track analyzer).
On page I implement range selector and few charts, so user can select which part of data he want to analyze.
Problem is - sometime user change range from both frontiers, so in that case he waits when finish first calculation and second.
Question is - is there any way to stop execution block of code if user iterate with range slider? I'll be very appreciate for directions to approach this task.
you can visit this page and try it for better understanding - try to change range twice without wait for charts and data update.
EDIT: When user finish with range slider it calls callback function, where I implemented calculations and charts update. Range selector also has onChange callback. So is there any way to stop execution one function from another one? Or may be I should call same function with parameter and do something?
Range slider initializing:
$(document).ready(function() {
$("#range_selector").ionRangeSlider({
min: max_height,
max: 0,
type: 'double',
step: 50,
prettify: false,
hasGrid: true,
from: max_height,
to: 0,
onFinish: function (obj) { // callback is called on slider action is finished
range_from = obj.fromNumber;
range_to = obj.toNumber;
set_chart_data();
}
});
Here is computing loop:
for (var index in charts_data) {
var current_point = charts_data[index];
var point = {};
isLast = true;
if (current_point.elevation <= max_val && current_point.elevation >= min_val) {
point = clone(current_point);
// Корректировка выбранного диапазона
if (isFirst) {
isFirst = false;
if (current_point.elevation != max_val && charts_data.hasOwnProperty(index-1)) {
point.elevation_diff = max_val - current_point.elevation;
var k = point.elevation_diff / current_point.elevation_diff;
point.distance = Math.round(current_point.distance * k);
point.fl_time = Math.round(current_point.fl_time * k);
}
}
isLast = false;
dist += point.distance;
elev += point.elevation_diff;
elev_data.push([fl_time, Math.round(elev)]);
dist_data.push([fl_time, dist]);
heights_data.push([fl_time, Math.round(point.elevation)]);
h_speed.push([fl_time, point.h_speed]);
v_speed.push([fl_time, point.v_speed]);
gr.push([fl_time, point.glrat]);
fl_time += point.fl_time;
min_h_speed = min_h_speed == 0 || min_h_speed > point.h_speed ? point.h_speed : min_h_speed;
max_h_speed = max_h_speed == 0 || max_h_speed < point.h_speed ? point.h_speed : max_h_speed;
min_v_speed = min_v_speed == 0 || min_v_speed > point.v_speed ? point.v_speed : min_v_speed;
max_v_speed = max_v_speed == 0 || max_v_speed < point.v_speed ? point.v_speed : max_v_speed;
min_gr = min_gr == 0 || min_gr > point.glrat ? point.glrat : min_gr;
max_gr = max_gr == 0 || max_gr < point.glrat ? point.glrat : max_gr;
}
if (isLast && elev_data.length > 0) {
if (current_point.elevation <= min_val && charts_data.hasOwnProperty(index - 1)) {
point = clone(current_point);
prev_point = charts_data[index - 1];
point.elevation_diff = prev_point.elevation - min_val;
var k = point.elevation_diff / current_point.elevation_diff;
point.fl_time = current_point.fl_time * k;
point.elevation = min_val;
point.distance = Math.round(current_point.distance * k);
dist += point.distance;
elev += point.elevation_diff;
elev_data.push([fl_time, Math.round(elev)]);
dist_data.push([fl_time, dist]);
heights_data.push([fl_time, Math.round(point.elevation)]);
h_speed.push([fl_time, point.h_speed]);
v_speed.push([fl_time, point.v_speed]);
gr.push([fl_time, point.glrat]);
}
break;
}
}