<commit_before>// Begin wrapper
(function() {
    
var configLoaded = $.getJSON('data.json').promise();
var app = Sammy('#main', function() {});

var documentLoaded = (function() {
  var d = $.Deferred();
  $(document).ready(function() {
    d.resolve();
  });
  return d;
})();

var indicatorImage = (function() {
  function img(imgName) {
    return $('<img />').attr('src', 'images/'+imgName+'.png')[0].outerHTML;
  }
  return {
    'grazing': img('grazing'),
    'sugarcane-grain': img('cane-grain'),
    'sugarcane': img('cane'),
    'grain': img('grain'),
    'horticulture': img('banana'),
    'groundcover': img('groundcover'),
    'nitrogen': img('beaker'),
    'sediment': img('beaker'),
    'pesticides': img('beaker')
  };
})();

var template = (function IIFE() {
  var templates = {};
  $(function whenDocumentLoads() {
    $('script[id^="tmpl-"]').each(function(i, e) {
      var templateName = $(e).attr('id').replace(/^tmpl-/,"");
      var tmpl = e.innerHTML;
      templates[templateName] = Hogan.compile(tmpl);
    });
  });
  return function template(templateName, context) {
    if (templates[templateName]) {
      return templates[templateName].render(context, templates)
    }
    throw new Error('Template "'+templateName+'" not found.');
  };
})();

var getFill = (function IIFE() {
  var fills;
  function getFillsFromCSS() {
    function getFillFromCSS(conditionClasses) {
      var $testEl = $('<div/>').addClass('condition '+conditionClasses);
      $testEl.appendTo('body');
      var bgc = $testEl.css('background-color');
      $testEl.remove();
      return bgc;
    };
    return {
      'Very good': {
        'normal': getFillFromCSS('very-good'),
        'active': getFillFromCSS('very-good active')
      },
      'Good': {
        'normal': getFillFromCSS('good'),
        'active': getFillFromCSS('good active'),
      },
      'Moderate': {
        'normal': getFillFromCSS('moderate'),
        'active': getFillFromCSS('moderate active'),
      },
      'Poor': {
        'normal': getFillFromCSS('poor'),
        'active': getFillFromCSS('poor active'),
      },
      'Very poor': {
        'normal': getFillFromCSS('very-poor'),
        'active': getFillFromCSS('very-poor active')
      }
    };
  }
  return function getFillImpl(v) {
    if (!fills) {
      fills = getFillsFromCSS();
    }
    if (fills[v]) {
      return fills[v];
    } else {
      return { normal: '#e5e5e5', active: '#e5e5e5' };
    }
  }
})();

function getMarineStyle(data) {
  return Object.keys(data).reduce(function(lr, region) {
    var values = data[region];
    return lr.concat(Object.keys(values).reduce(function(li, indicator) {
      var value = values[indicator].qualitative;
      return li.concat(
        '.marine-chart.'+region+' #'+indicator+" { fill: "+getFill(value).normal+"; pointer-events: all; }",
        '.marine-chart.'+region+' #'+indicator+':hover, .marine-chart.'+region+' #'+indicator+".active { fill: "+getFill(value).active+"; cursor: pointer; }"
      );
    }, []));
  }, []).join("\n");
}

var otherInfographicYears = [];

var deferredsBeforeStart = {
  'regions':   $.Deferred(),
  'marineSVG': $.Deferred(),
  'yearLinks': $.Deferred(),
};
var promisesBeforeStart = Object.keys(deferredsBeforeStart).map(function (k) {
  return deferredsBeforeStart[k].promise();
});


var routesCreated = $.when(configLoaded).done(function(config) {
  var reportFinalYear = config['reportYears'].match(/\d{4}$/g)[0];
    
  Sammy('#main', function() {
    var gbrBreadcrumb = { 
      name: 'Great Barrier Reef',
      href: '#/'
    };
      
    // Default lander
    this.get('#/', function() {
      // this context is a Sammy.EventContext
      this.$element() // $('#main')
          .html(template('home', {
        baseYear: config['baseYear'],
        reportYears: config['reportYears'],
        reportFinalYear: reportFinalYear,
        otherYears: otherInfographicYears,
        isMostRecent: otherInfographicYears.every(function(v) {
          return v.year < config['reportYears'];
        }),
        fullReportUrl: config['fullReportCardURL']
      }));
      this.trigger('region:show', 'gbr');
    });
    
    this.get('#/management', function() {
      this.$element()
          .html(template('management-select', {
            breadcrumbs: [<commit_msg>Using "and" instead of a dash in infographic titles.<commit_after>// Begin wrapper
(function() {
    
var configLoaded = $.getJSON('data.json').promise();
var app = Sammy('#main', function() {});

var documentLoaded = (function() {
  var d = $.Deferred();
  $(document).ready(function() {
    d.resolve();
  });
  return d;
})();

var indicatorImage = (function() {
  function img(imgName) {
    return $('<img />').attr('src', 'images/'+imgName+'.png')[0].outerHTML;
  }
  return {
    'grazing': img('grazing'),
    'sugarcane-grain': img('cane-grain'),
    'sugarcane': img('cane'),
    'grain': img('grain'),
    'horticulture': img('banana'),
    'groundcover': img('groundcover'),
    'nitrogen': img('beaker'),
    'sediment': img('beaker'),
    'pesticides': img('beaker')
  };
})();

var template = (function IIFE() {
  var templates = {};
  $(function whenDocumentLoads() {
    $('script[id^="tmpl-"]').each(function(i, e) {
      var templateName = $(e).attr('id').replace(/^tmpl-/,"");
      var tmpl = e.innerHTML;
      templates[templateName] = Hogan.compile(tmpl);
    });
  });
  return function template(templateName, context) {
    if (templates[templateName]) {
      return templates[templateName].render(context, templates)
    }
    throw new Error('Template "'+templateName+'" not found.');
  };
})();

var getFill = (function IIFE() {
  var fills;
  function getFillsFromCSS() {
    function getFillFromCSS(conditionClasses) {
      var $testEl = $('<div/>').addClass('condition '+conditionClasses);
      $testEl.appendTo('body');
      var bgc = $testEl.css('background-color');
      $testEl.remove();
      return bgc;
    };
    return {
      'Very good': {
        'normal': getFillFromCSS('very-good'),
        'active': getFillFromCSS('very-good active')
      },
      'Good': {
        'normal': getFillFromCSS('good'),
        'active': getFillFromCSS('good active'),
      },
      'Moderate': {
        'normal': getFillFromCSS('moderate'),
        'active': getFillFromCSS('moderate active'),
      },
      'Poor': {
        'normal': getFillFromCSS('poor'),
        'active': getFillFromCSS('poor active'),
      },
      'Very poor': {
        'normal': getFillFromCSS('very-poor'),
        'active': getFillFromCSS('very-poor active')
      }
    };
  }
  return function getFillImpl(v) {
    if (!fills) {
      fills = getFillsFromCSS();
    }
    if (fills[v]) {
      return fills[v];
    } else {
      return { normal: '#e5e5e5', active: '#e5e5e5' };
    }
  }
})();

function getMarineStyle(data) {
  return Object.keys(data).reduce(function(lr, region) {
    var values = data[region];
    return lr.concat(Object.keys(values).reduce(function(li, indicator) {
      var value = values[indicator].qualitative;
      return li.concat(
        '.marine-chart.'+region+' #'+indicator+" { fill: "+getFill(value).normal+"; pointer-events: all; }",
        '.marine-chart.'+region+' #'+indicator+':hover, .marine-chart.'+region+' #'+indicator+".active { fill: "+getFill(value).active+"; cursor: pointer; }"
      );
    }, []));
  }, []).join("\n");
}

var otherInfographicYears = [];

var deferredsBeforeStart = {
  'regions':   $.Deferred(),
  'marineSVG': $.Deferred(),
  'yearLinks': $.Deferred(),
};
var promisesBeforeStart = Object.keys(deferredsBeforeStart).map(function (k) {
  return deferredsBeforeStart[k].promise();
});


var routesCreated = $.when(configLoaded).done(function(config) {
  var reportFinalYear = config['reportYears'].match(/\d{4}$/g)[0];
    
  Sammy('#main', function() {
    var gbrBreadcrumb = { 
      name: 'Great Barrier Reef',
      href: '#/'
    };
      
    // Default lander
    this.get('#/', function() {
      // this context is a Sammy.EventContext
      this.$element() // $('#main')
          .html(template('home', {
        baseYear: config['baseYear'],
        reportYears: config['reportYears'].replace("-", " and "),
        reportFinalYear: reportFinalYear,
        otherYears: otherInfographicYears,
        isMostRecent: otherInfographicYears.every(function(v) {
          return v.year < config['reportYears'];
        }),
        fullReportUrl: config['fullReportCardURL']
      }));
      this.trigger('region:show', 'gbr');
    });
    
    this.get('#/management', function() {
      this.$element()
          .html(template('management-select', {
            breadcrumbs: [
{'fraction_non_alphanumeric': 0.19229442208165612, 'fraction_numerical': 0.0020701552616446232, 'mean_word_length': 3.09609043805935, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4714698', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2784, 'n_words': 507}