(function () {
  //Inject code v3.0.3

  var highcharts = document.createElement('script');

  var cdn = 'https://code.highcharts.com/';
  var loaded = 0;  
  var encodedUrl = encodeURI('https://https://app.everviz.com//show/QcRrTDMw5');
  var chartCreated = false;
  var delayGen = 0;
  var scripts = [
    "highcharts.js",
    "modules/stock.js",
    "highcharts-more.js",
    "highcharts-3d.js",
    "modules/data.js",
    "modules/exporting.js",
    "modules/funnel.js",
    "modules/solid-gauge.js",
    "modules/export-data.js",
    "modules/accessibility.js"
    /* "modules/series-label.js" */
  ];

  var externalCSS = [
      ];

  var extraScripts = [
  "https://code.highcharts.com/modules/annotations.js"
  ,"https://code.highcharts.com/modules/annotations-advanced.js"
  ];

  var options = {"title":{"text":"Demand for H-2A Visas has Tripled Over Last Decade","align":"left","x":10,"useHTML":true},"subtitle":{"text":"Count of H-2A Positions Certified by State, 2007-2016","align":"left","x":10},"colors":["#028dff","#ce3f28","#13915b","#0464a5","#fe5f3a","#00dcd5","#ffcd20","#aa44f5","#20e1a3"],"legend":{"align":"left","verticalAlign":"top","itemMarginBottom":10,"x":0,"symbolRadius":2,"useHTML":true,"floating":false},"plotOptions":{"series":{"marker":{"enabled":false},"lineWidth":3,"stacking":"normal"}},"chart":{"polar":false},"credits":{"text":"USDA Economic Research Service, \"Farm Labor\"","href":"https://www.ers.usda.gov/topics/farm-economy/farm-labor/"},"series":[{"data":[],"turboThreshold":0,"_colorIndex":0,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":1,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":2,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":3,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":4,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":5,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":6,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":7,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":8,"_symbolIndex":0,"type":"column"},{"data":[],"turboThreshold":0,"_colorIndex":9,"_symbolIndex":0,"type":"column","color":"#3196f9"},{"data":[],"turboThreshold":0,"_colorIndex":10,"_symbolIndex":0,"type":"column","color":"#bfbfbf"}],"xAxis":{"opposite":false,"reversed":false},"annotations":[],"yAxis":{"title":{"useHTML":true,"text":"Positions Certified (in thousands)"}},"data":{"csv":"null;AR;AZ;NY;KY;LA;NC;CA;WA;GA;FL;Other States\n2007;2,914;1,956;4,039;4,891;5,170;8,822;2,173;1,794;6,983;4,411;31,664\n2008;3,222;6,160;4,194;5,852;5,933;9,127;2,929;2,573;6,488;5,852;37,795\n2009;3,022;3,861;4,299;5,754;6,696;8,728;2,812;1,984;6,654;5,823;36,339\n2010;2,998;4,305;3,872;5,452;6,788;9,793;2,629;3,013;4,874;4,515;30,910\n2011;2,472;2,110;3,938;4,692;7,342;9,137;1,598;3,194;6,793;5,741;30,084\n2012;2,701;2,375;3,632;4,754;6,771;10,498;2,862;4,443;8,227;6,945;32,038\n2013;2,802;2,964;4,699;5,813;6,588;12,386;4,199;6,240;9,268;9,971;32,936\n2014;2,504;3,751;4,680;6,753;7,214;15,135;6,043;9,064;10,387;13,519;37,595\n2015;2,552;3,713;5,039;6,710;7,787;17,487;8,591;11,774;14,393;17,942;43,477\n2016;3,114;5,391;5,522;6,779;8,301;19,786;11,106;13,649;17,392;22,828;51,833\n2017;3,148;6,060;6,870;7,403;8,875;20,738;15,232;18,571;23,421;25,303;64,469\n2018;3,538;7,497;7,634;7,589;10,079;21,885;18,908;24,862;32,364;30,462;77,998\n2019;3,958;5,647;8,104;8,315;10,788;21,706;23,321;26,226;29,480;33,598;86,567","seriesMapping":[{"x":0,"y":1},{"x":0,"y":2},{"x":0,"y":3},{"x":0,"y":4},{"x":0,"y":5},{"x":0,"y":6},{"x":0,"y":7},{"x":0,"y":8},{"x":0,"y":9},{"x":0,"y":10},{"x":0,"y":11}]},"stockTools":{"gui":{"enabled":false}}};
  
  var templateDataSettings = {};

  var pluginCode = {};;

  if (options.data) {
    options.data.complete = function(options) {
      const keys = Object.keys(templateDataSettings || {});
      keys.forEach(function(key) {
        const serie = options.series[key];
        (serie.data || []).forEach(function(d, i) {
          if (templateDataSettings[key].data && templateDataSettings[key].data[i]) {
            merge(d, templateDataSettings[key].data[i]);
          }
        })
      })  
      return options;
    }
  }

  merge(options, pluginCode);

  function isNull(what){return(typeof what==='undefined'||what===null)}
  function isStr(what){return(typeof what==='string'||what instanceof String)}
  function isNum(what){return!isNaN(parseFloat(what))&&isFinite(what)}
  function isFn(what){return(what&&(typeof what==='function')||(what instanceof Function))}
  function isArr(what){return(!isNull(what)&&what.constructor.toString().indexOf('Array')>-1)}
  function isBool(what){return(what===!0||what===!1)}
  function isBasic(what){return!isArr(what)&&(isStr(what)||isNum(what)||isBool(what)||isFn(what))}
  function isObj(what){return what&&what.constructor.toString().indexOf('Object')>-1}
  function isEmptyObjectArray(arr){return isObj(arr[0])&&arr.some(function(b){return Object.keys(b).length===0})}
  function merge(a,b){if(!a||!b)return a||b;Object.keys(b).forEach(function(bk){if(isNull(b[bk])||isBasic(b[bk])){a[bk]=b[bk]}else if(isArr(b[bk])){if(isEmptyObjectArray(b[bk]))return;a[bk]=[];b[bk].forEach(function(i){if(isNull(i)||isBasic(i)){a[bk].push(i)}else{a[bk].push(merge(isArr(i)?[]:{},i))}})}else{a[bk]=a[bk]||{};merge(a[bk],b[bk])}});return a}

  function isScriptAlreadyIncluded(src){
    var scripts = document.getElementsByTagName("script");
    for (var i = 0; i < scripts.length; i++) {
      if (scripts[i].hasAttribute('src')) {
        const scriptTag = scripts[i].getAttribute('src') || '';
        if ((scriptTag.indexOf(src) >= 0) || 
            (scriptTag.indexOf('highcharts.src.js') > -1 && src === 'highcharts.js') ||
            ((scriptTag.indexOf('stock/highstock.js') > -1) && src === 'modules/highstock.js')) {
          return true;
        }
      }
    }
    return false;
  }

  function loadCSS() {
    var cssLength = externalCSS.length;
    for(var i=0; i < cssLength; i++) {
      var css = document.createElement('link');
      css.rel  = 'stylesheet';
      css.type = "text/css";
      css.href = externalCSS[i];
      document.body.appendChild(css);
    }
  }

  function allScriptsIncluded(){
    var allScripts = scripts.concat(extraScripts);
    var haveAllScriptsBeenIncluded = true;
    var scriptsToUse = document.getElementsByTagName("script");
    for(var n=0;n<allScripts.length;n++) {
      if (!isScriptAlreadyIncluded(allScripts[n], scriptsToUse)) {
        haveAllScriptsBeenIncluded = false;
        break;
      }
    }
    return haveAllScriptsBeenIncluded;
  }

  function createChart() {
    if(chartCreated) return;
    var hasProj4 = extraScripts.includes('https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js');
    if (!allScriptsIncluded() || 
      (hasProj4 && !window.proj4)) {
      setTimeout(createChart, 200);
      return;
    }  

    if (hasProj4) delayGen = 100;

    if (typeof window['Highcharts'] !== 'undefined') {
      

      if (options && (options.lang || options.global)) {
        Highcharts.setOptions({
          global: options.global || {},
          lang: options.lang || {}
        });
      }

      if (Highcharts.Annotation) {
        Highcharts.Annotation.ControlPoint.prototype.redraw = function (animation) {
          this.graphic[animation ? 'animate' : 'attr'](
              this.options.positioner ? this.options.positioner.call(this, this.target) : null
          );
        };
      }
      
      chartCreated = true;
      window.HighchartsCloud.hasLoaded = true; 
      setTimeout(function(){
        new Highcharts.Chart('highcharts-QcRrTDMw5', options);     
      }, delayGen);
    }
  }

  function check(scripts, cb) {
    if (loaded === scripts.length) {
      if (cb) {
        cb();
      } else {
        for (var i = 0; i < window.HighchartsCloud.ondone.length; i++) {
          try {
            window.HighchartsCloud.ondone[i]();
          } catch(e) {
            console.error(e);
          }
        }
      }
    }
  }

  function loadScript(s, scripts, cb) {
    if (!s) next();
    
    function next() {
      ++loaded;
      if (loaded < scripts.length) {
        loadScript(scripts[loaded], scripts, cb);
      }
      check(scripts, cb);
    }

    if (isScriptAlreadyIncluded(s)) {
      return next();
    }

    var n = document.createElement('script');

    n.onload = function () {
      next();
    };

    if (s.indexOf('https') >= 0) {
      n.src = s;
    } else {
      n.src = cdn + s;
    }
    document.body.appendChild(n);
  }

  function loadExtraScripts(){
    if (extraScripts.length > 0) {
      loaded = 0;
      loadScript(extraScripts[0], extraScripts);
    } else {
      check(scripts);
    }
  }

  function loadExtraScriptsAndMakeChart(){
    loaded = 0;
    loadCSS();
    if (extraScripts.length > 0) {
      loadScript(extraScripts[0], extraScripts, createChart);
    } else {
      check(extraScripts);
    }
  }

  if (typeof window['HighchartsCloud'] === 'undefined') {
    window.HighchartsCloud = {
      ondone: [createChart],
      hasWrapped: false,
      hasLoaded: false
    };

    loadScript(scripts[0], scripts, loadExtraScripts);
    loadCSS();

  } else {
    if (!window.HighchartsCloud.hasLoaded) window.HighchartsCloud.ondone.push(loadExtraScriptsAndMakeChart);
    else loadExtraScriptsAndMakeChart();
  }

}());
