<commit_before>/**
 * flights
 *
 * Array of flight objects. (see addFlight method)
 */
var flights = [];

var flot;

var highlighted_flight_sfid;
var highlighted_flight_phase = null;

/*
 * Global time, can be:
 * null -> no time is set, don't show barogram crosshair/plane position
 * -1 -> always show the latest time/fix for each flight
 * >= 0 -> show the associated time in the barogram and on the map
 */
var default_time = null;
var global_time = default_time;

/**
 * colors
 *
 * List of colors for flight path display
 */
//var colors = ['#bf2fa2', '#2f69bf', '#d63a35', '#d649ff'];
var colors = ['#004bbd', '#bf0099', '#cf7c00', '#ff0000', '#00c994', '#ffff00'];
var contest_colors = {'olc_plus classic': '#ff2c73',
                      'olc_plus triangle': '#9f14ff'};

/**
 * Function initOpenLayers
 *
 * Initialize the map and add airspace and flight path layers.
 */

function initFlightLayer() {
  var default_style = new OpenLayers.Style({
    strokeColor: '${color}',
    strokeWidth: 2,
    graphicZIndex: 1000
  });

  var contest_style = new OpenLayers.Style({
    strokeColor: '${color}',
    strokeWidth: 2,
    strokeDashstyle: 'dash',
    graphicZIndex: 1500
  });

  var plane_style = new OpenLayers.Style({
    // Set the external graphic and background graphic images.
    externalGraphic: '${getGraphic}',
    // Makes sure the background graphic is placed correctly relative
    // to the external graphic.
    graphicXOffset: -20,
    graphicYOffset: -8,
    graphicWidth: 40,
    graphicHeight: 24,
    rotation: '${rotation}',
    // Set the z-indexes of both graphics to make sure the background
    // graphics stay in the background (shadows on top of markers looks
    // odd; let's not do that).
    graphicZIndex: 2000
  }, {
    context: {
      getGraphic: function(feature) {
        var msie_8 = $.browser.msie && (parseInt($.browser.version, 10) < 9);
        var normal_glider = msie_8 ? '/images/glider_symbol_msie.png': '/images/glider_symbol.png';
        return normal_glider;
      }
    }
  });

  var hidden_style = new OpenLayers.Style({
    display: 'none'
  });

  var flightPathLayer = new OpenLayers.Layer.Vector('Flight', {
    styleMap: new OpenLayers.StyleMap({
      'default': default_style,
      'contest': contest_style,
      'plane': plane_style,
      'hidden': hidden_style
    }),
    rendererOptions: {
        zIndexing: true
    },
    displayInLayerSwitcher: false
  });

  map.addLayer(flightPathLayer);

  map.events.register('move', this, function() {
    initRedrawLayer(flightPathLayer);
  });

  map.events.register('moveend', this, updateFlotScale);
}

function updateFlotScale() {
  var first_t = 999999;
  var last_t = 0;

  // circle throu all flights
  for (var fid = 0; fid < flights.length; fid++) {
    var flight = flights[fid];
    var geometries = flight.geo.partitionedGeometries;

    // if flight is not in viewport continue.
    if (geometries.length == 0)
      continue;

    // show barogram of all trace parts visible
    var length = geometries.length;
    var comp_length = geometries[length - 1].components.length;
    var first = geometries[0].components[0].originalIndex;
    var last = geometries[length - 1].components[comp_length - 1].originalIndex;

    // get first and last time which should be the bounds of the barogram
    if (flight.t[first] < first_t)
      first_t = flight.t[first];

    if (flight.t[last] > last_t)
     last_t = flight.t[last];
  }

  var opt = flot.getOptions();
  opt.yaxes[0].min = opt.yaxes[0].max = null;
  if (last_t == 0) {
    opt.xaxes[0].min = opt.xaxes[0].max = null;
  } else {
    opt.xaxes[0].min = first_t * 1000;
    opt.xaxes[0].max = last_t * 1000;
  }

  flot.setupGrid();
  flot.draw();
}<commit_msg>flight.js: Only access geometries.length once<commit_after>/**
 * flights
 *
 * Array of flight objects. (see addFlight method)
 */
var flights = [];

var flot;

var highlighted_flight_sfid;
var highlighted_flight_phase = null;

/*
 * Global time, can be:
 * null -> no time is set, don't show barogram crosshair/plane position
 * -1 -> always show the latest time/fix for each flight
 * >= 0 -> show the associated time in the barogram and on the map
 */
var default_time = null;
var global_time = default_time;

/**
 * colors
 *
 * List of colors for flight path display
 */
//var colors = ['#bf2fa2', '#2f69bf', '#d63a35', '#d649ff'];
var colors = ['#004bbd', '#bf0099', '#cf7c00', '#ff0000', '#00c994', '#ffff00'];
var contest_colors = {'olc_plus classic': '#ff2c73',
                      'olc_plus triangle': '#9f14ff'};

/**
 * Function initOpenLayers
 *
 * Initialize the map and add airspace and flight path layers.
 */

function initFlightLayer() {
  var default_style = new OpenLayers.Style({
    strokeColor: '${color}',
    strokeWidth: 2,
    graphicZIndex: 1000
  });

  var contest_style = new OpenLayers.Style({
    strokeColor: '${color}',
    strokeWidth: 2,
    strokeDashstyle: 'dash',
    graphicZIndex: 1500
  });

  var plane_style = new OpenLayers.Style({
    // Set the external graphic and background graphic images.
    externalGraphic: '${getGraphic}',
    // Makes sure the background graphic is placed correctly relative
    // to the external graphic.
    graphicXOffset: -20,
    graphicYOffset: -8,
    graphicWidth: 40,
    graphicHeight: 24,
    rotation: '${rotation}',
    // Set the z-indexes of both graphics to make sure the background
    // graphics stay in the background (shadows on top of markers looks
    // odd; let's not do that).
    graphicZIndex: 2000
  }, {
    context: {
      getGraphic: function(feature) {
        var msie_8 = $.browser.msie && (parseInt($.browser.version, 10) < 9);
        var normal_glider = msie_8 ? '/images/glider_symbol_msie.png': '/images/glider_symbol.png';
        return normal_glider;
      }
    }
  });

  var hidden_style = new OpenLayers.Style({
    display: 'none'
  });

  var flightPathLayer = new OpenLayers.Layer.Vector('Flight', {
    styleMap: new OpenLayers.StyleMap({
      'default': default_style,
      'contest': contest_style,
      'plane': plane_style,
      'hidden': hidden_style
    }),
    rendererOptions: {
        zIndexing: true
    },
    displayInLayerSwitcher: false
  });

  map.addLayer(flightPathLayer);

  map.events.register('move', this, function() {
    initRedrawLayer(flightPathLayer);
  });

  map.events.register('moveend', this, updateFlotScale);
}

function updateFlotScale() {
  var first_t = 999999;
  var last_t = 0;

  // circle throu all flights
  for (var fid = 0; fid < flights.length; fid++) {
    var flight = flights[fid];
    var geometries = flight.geo.partitionedGeometries;

    // if flight is not in viewport continue.
    var length = geometries.length;
    if (length == 0)
      continue;

    // show barogram of all trace parts visible
    var comp_length = geometries[length - 1].components.length;
    var first = geometries[0].components[0].originalIndex;
    var last = geometries[length - 1].components[comp_length - 1].originalIndex;

    // get first and last time which should be the bounds of the barogram
    if (flight.t[first] < first_t)
      first_t = flight.t[first];

    if (flight.t[last] > last_t)
     last_t = flight.t[last];
  }

  var opt = flot.getOptions();
  opt.yaxes[0].min = opt.yaxes[0].max = null;
  if (last_t == 0) {
    opt.xaxes[0].min = opt.xaxes[0].max = null;
  } else {
    opt.xaxes[0].min = first_t * 1000;
    opt.xaxes[0].max = last_t * 1000;
  }

  flot.setupGrid();
  flot.draw();
}
{'fraction_non_alphanumeric': 0.13131715081575807, 'fraction_numerical': 0.025467568643056108, 'mean_word_length': 3.0668824163969797, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5368366', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2444, 'n_words': 690}