Skip to content

Commit

Permalink
public.js.flight: add function setPrimaryFlight to set primary flight
Browse files Browse the repository at this point in the history
This will take care about rendering the contest traces later
  • Loading branch information
TobiasLohner committed Jul 15, 2012
1 parent 2cfbc7e commit c505034
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions skylines/public/js/flight.js
Expand Up @@ -387,18 +387,12 @@ function setFlightTime(time) {
// find the position indexes of all flight available.
setIndexFromTime(time);

// we'd like to have an flight within the current range as primary_flight.
if (flights[primary_flight].index == -1) {
// our current top flight is out of range. find first flight in range...
for (primary_flight in flights) if (flights[primary_flight].index != -1) break;
}
// set the primary flight
setPrimaryFlight(primary_flight);

// no flight found which is in range? return early, draw nothing.
if (flights[primary_flight].index == -1) return;

// set the top flight in the barogram
barogram.linechart.setPrimary(primary_flight);

// interpolate current height of primary_flight
var height = flights[primary_flight].h[flights[primary_flight].index] +
(flights[primary_flight].h[flights[primary_flight].index+1] - flights[primary_flight].h[flights[primary_flight].index]) *
Expand All @@ -419,6 +413,29 @@ function setFlightTime(time) {
}
}

/**
* Function: setPrimaryFlight
*
* Sets the primary flight. Try to set it to primary, fallback to another flight
*
* Parameters:
* primary - {Integer} primary flight
*/
function setPrimaryFlight(primary) {
// we'd like to have an flight within the current range as primary_flight.
if (flights[primary].index == -1) {
// our current primary flight is out of range. find first flight in range...
for (primary in flights) if (flights[primary].index != -1) break;
}

// the primary flight has changed...
if (primary_flight != primary) {
// update barogram and set primary_flight if it changed
barogram.linechart.setPrimary(primary);
primary_flight = primary;
}
}

/**
* Function: render_barogram
*
Expand Down Expand Up @@ -761,7 +778,7 @@ function hoverMap() {
var x = flights[nearest.fid].t[nearest.from] + (flights[nearest.fid].t[nearest.from+1]-flights[nearest.fid].t[nearest.from])*nearest.along;

// we expect the currently hovered flight is the top flight.
primary_flight = nearest.fid;
setPrimaryFlight(nearest.fid);

// set the map time to x
setFlightTime(x);
Expand Down

0 comments on commit c505034

Please sign in to comment.