function set_chart_data() {
var dist_data = [],
elev_data = [],
heights_data = [],
h_speed = [],
v_speed = [],
gr = [],
avg_h_speed = 0,
avg_v_speed = 0,
avg_gr = 0,
min_h_speed = 0,
max_h_speed = 0,
min_v_speed = 0,
max_v_speed = 0,
min_gr = 0,
max_gr = 0,
fl_time = 0,
dist = 0,
elev = 0;
max_val = typeof range_from !== 'undefined' ? range_from : 100000;
min_val = typeof range_to !== 'undefined' ? range_to : 0;
var isFirst = true,
isLast = false;
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);
point.elevation = current_point.elevation;
point.v_speed = current_point.v_speed;
point.h_speed = current_point.h_speed;
}
}
isLast = false;
dist += point.distance;
elev += point.elevation_diff;
elev_data.push([fl_time, elev]);
dist_data.push([fl_time, dist]);
heights_data.push([fl_time, 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.distance = Math.round(current_point.distance * k);
dist += point.distance;
elev += point.elevation_diff;
elev_data.push([fl_time, elev]);
dist_data.push([fl_time, dist]);
heights_data.push([fl_time, 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;
}
}
var ed_chart = $('#elevation_distance_chart').highcharts();
ed_chart.series[0].setData(elev_data);
ed_chart.series[1].setData(dist_data);
ed_chart.series[2].setData(heights_data);
var sp_chart = $('#speeds_chart').highcharts();
sp_chart.series[0].setData(h_speed);
sp_chart.series[1].setData(v_speed);
var gr_chart = $('#glideratio_chart').highcharts();
gr_chart.series[0].setData(gr);
var ad_chart = $('#all_data_chart').highcharts();
ad_chart.series[0].setData(h_speed);
ad_chart.series[1].setData(v_speed);
ad_chart.series[2].setData(gr);
ad_chart.series[3].setData(heights_data);
ad_chart.series[4].setData(dist_data);
ad_chart.series[5].setData(elev_data);
$('#dd_distance').text(dist.toString() + ' м');
$('#dd_elevation').text(elev.toString() + ' м');
$('#dd_fl_time').text(fl_time.toString() + ' с');
$('#p_min_v_speed').text(min_v_speed.toFixed(0) + '...');
$('#p_max_v_speed').text('...' + max_v_speed.toFixed(0));
$('#p_avg_v_speed').text(Math.round(elev / fl_time * 3.6));
$('#p_min_h_speed').text(min_h_speed.toFixed(0) + '...');
$('#p_max_h_speed').text('...' + max_h_speed.toFixed(0));
$('#p_avg_h_speed').text(Math.round(dist / fl_time * 3.6).toString());
$('#p_min_gr').text(min_gr.toFixed(2) + '...');
$('#p_max_gr').text('...' + max_gr.toFixed(2));
$('#p_avg_gr').text((dist / elev).toFixed(2));
};