(function () {
  //Inject code v5.2

  var highcharts = document.createElement('script');
  var injectVersion = 6;
  var cdn = 'https://code.highcharts.com/';
  var loaded = 0;  
  var encodedUrl = encodeURI('https://https://app.everviz.com//show/s3V84Icyz');
  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"
  ];

  const inEmbedCode = window.location.pathname.indexOf('/embed/') > -1;
  const inEverviz = window.location.origin === 'https://app.everviz.com';
  const loadHighchartsModules = inEverviz && !inEmbedCode;

  var legacyElementClassName = 'highcharts-s3V84Icyz';
  var elementClassName = 'everviz-s3V84Icyz';
  var externalCSS = [
    "https://app.everviz.com/resources/css/highcharts-small-screen-annotations.css",
    "https://app.everviz.com/resources/css/highcharts-data-table.css"
  ];

  var extraScripts = [
  "https://code.highcharts.com/modules/annotations.js",
  "https://code.highcharts.com/modules/annotations-advanced.js",
  "https://app.everviz.com/resources/js/highcharts-small-screen-annotations.js",
  "https://app.everviz.com/resources/js/highcharts-scroll-animation.js",
  "https://app.everviz.com/resources/js/everviz-utils.js",
  "https://app.everviz.com/resources/js/highcharts-overrides.js",
  "https://app.everviz.com/resources/js/highcharts-resize.js",
  ];

  var options = {"title":{"style":{"fontFamily":"\"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Arial, Helvetica, sans-serif","color":"#333333","fontSize":"18px","fontWeight":"normal","fontStyle":"normal"},"text":"II-03d: Humanities Bachelor’s Degree Completions","margin":11,"y":19,"useHTML":true},"subtitle":{"style":{"fontFamily":"Lucida Sans Unicode","color":"#666666","fontSize":"14px","fontWeight":"normal","fontStyle":"normal"},"text":"<div>By Discipline, 1987–2022</div>","useHTML":true},"plotOptions":{"series":{"allowPointSelect":true,"states":{"hover":{"color":"#a4edba"},"select":{"color":"#EFFFEF","borderColor":"black","dashStyle":"dot"}},"label":{"enabled":false}},"line":{"marker":{"symbol":"circle","enabled":false},"lineWidth":3}},"credits":{"href":"humanitiesindicators.org","style":{"fontSize":"11px","cursor":"pointer","color":"#999999","fontFamily":"\"Lucida Grande\", \"Lucida Sans Unicode\", Verdana, Arial, Helvetica, sans-serif"},"text":"<div>Humanities Indicators, 2024 | American Academy of Arts &amp; Sciences</div>","useHTML":true},"colors":["#4b803e","#f47b2a","#46ad9b","#f5cb23","#7c3f00","#b80d31","#713fac","#818589","#d3556b","#1b5fab","#9ab92e","#ffa600","#b15cbb","#bb6d3e","#0fe9e3","#d3d3d3"],"series":[{"data":[],"turboThreshold":0,"type":"line","marker":{"symbol":"circle","enabled":false},"name":"Column 2","_colorIndex":0,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":1,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":2,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":3,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":4,"_symbolIndex":0},{"turboThreshold":0,"marker":{"enabled":false},"type":"line","data":[],"_colorIndex":5,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":6,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":7,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":8,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":9,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":10,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"colorByPoint":false,"type":"line","data":[],"_colorIndex":11,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":12,"_symbolIndex":0},{"turboThreshold":0,"marker":{"symbol":"circle","enabled":false},"type":"line","data":[],"_colorIndex":13,"_symbolIndex":0},{"data":[],"turboThreshold":0,"_colorIndex":14,"_symbolIndex":0,"type":"line"},{"data":[],"turboThreshold":0,"_colorIndex":15,"_symbolIndex":0,"type":"line"}],"stockTools":{"gui":{"enabled":false}},"navigation":{"bindingsClassName":"tools-container","events":{}},"pane":{"background":[]},"responsive":{"rules":[]},"chart":{"plotBorderWidth":1,"borderColor":"#ffffff","type":"line","height":620,"width":null},"yAxis":{"title":{"style":{"fontFamily":"Lucida Sans Unicode","color":"#000","fontSize":"12px","fontWeight":"bold","fontStyle":"normal"},"text":"Completions","useHTML":true},"index":0},"xAxis":{"title":{"style":{"fontFamily":"Lucida Sans Unicode","color":"#212121","fontSize":"12px","fontWeight":"bold","fontStyle":"normal"}},"index":0,"isX":true},"labels":{"items":[]},"annotations":[],"lang":{"shortMonths":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"weekdays":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"months":["January","February","March","April","May","June","July","August","September","October","November","December"],"numericSymbols":["k","M","G","T","P","E"],"thousandsSep":","},"legend":{"itemStyle":{"fontFamily":"Default","color":"#333333","fontSize":"12px","fontWeight":"normal","fontStyle":"normal","cursor":"pointer","textOverflow":"ellipsis"},"layout":"horizontal","align":"center","verticalAlign":"bottom"},"exporting":{"url":"https://api.everviz.com/export"},"tooltip":{},"caption":{"text":"To highlight a particular field, mouse over its entry in the legend.","align":"right","y":7,"margin":13,"style":{"fontFamily":"Lucida Sans Unicode","fontSize":"13px"}},"data":{"csv":";\"Archeology\";\"Area Studies\";\"Classical Studies\";\"Communication (excl. Professional)\";\"Comparative Literature\";\"Cultural, Ethnic, & Gender Studies\";\"English Language & Literature\";\"Folklore\";\"General Humanities/Liberal Studies\";\"History\";\"Languages & Lit. Other than English\";\"Linguistics\";\"Philosophy\";\"Religion\";\"Selected Interdisciplinary Studies\";\"Study of the Arts\"\n1987;67;2770;491;20431;620;524;35603;;23826;17035;10182;477;3534;2621;;2438\n1988;88;2985;524;21551;562;507;38006;;24413;18244;10000;484;3814;2309;;2516\n1989;65;3319;578;22581;701;594;41635;;26496;20136;10748;447;4146;2492;;2802\n1990;87;3755;580;24153;714;669;46286;;27901;22266;11325;531;4589;2460;;3035\n1991;92;3918;635;24666;782;860;51000;;30655;24593;12008;572;4953;2493;;3249\n1992;102;4029;719;27158;709;1193;54169;;32291;27023;12695;576;5178;2499;21;5636\n1993;95;3978;754;27333;851;1391;55223;;33501;27852;13211;553;5234;2690;25;5091\n1994;120;3931;765;26488;780;1508;53032;;33428;27607;13136;611;5085;2630;24;3960\n1995;123;3827;725;24883;744;1687;51040;;33387;26700;12615;564;4801;2697;34;5661\n1996;120;3754;743;25146;772;1887;49821;;34241;26085;12797;619;4878;2698;36;5567\n1997;136;3803;719;25704;710;1909;48526;;34840;25339;12556;577;4863;3007;38;5272\n1998;138;3720;821;26688;698;2263;48861;;35657;25859;13120;680;5155;3278;27;5539\n1999;137;3630;806;27910;746;2391;49717;;37172;24875;13675;724;5129;3452;34;5003\n2000;122;3731;852;31281;832;2485;49912;;38312;25394;13594;727;5174;3414;30;3818\n2001;141;3627;918;32384;868;2536;50367;;40339;25243;13704;757;5182;3595;40;4173\n2002;160;3774;1005;35465;807;2623;52113;;41545;26175;13728;861;5815;3741;30;4352\n2003;190;3834;1126;37886;773;2820;53423;;42763;27917;14364;893;6331;4088;32;5459\n2004;172;4011;1248;39855;819;3257;53640;;44192;29997;14912;1023;6802;4399;36;5570\n2005;175;4239;1265;40992;834;3453;54065;;45527;31593;15553;1020;7175;4465;50;5988\n2006;176;4422;1394;41035;802;3624;54771;;45101;33354;16404;1145;7472;4621;37;6342\n2007;188;4603;1483;41565;880;3712;54776;;46312;34671;16925;1290;7462;4665;41;6818\n2008;214;4803;1498;42337;804;3772;54649;;47059;34656;17542;1442;7630;4735;50;7137\n2009;226;4971;1551;43343;821;3908;55087;;47224;34922;17781;1392;7869;4716;46;7459\n2010;217;5142;1582;46173;714;3642;52805;;47318;35409;18024;1592;7881;4804;66;7671\n2011;232;5120;1538;48049;820;4198;52244;;46862;35206;18026;1714;7943;5004;84;7687\n2012;264;5252;1578;48493;759;4227;53207;5;47099;35334;17876;1950;7888;4889;73;7932\n2013;234;5028;1551;49470;938;4093;51891;9;46919;34424;17518;2014;7958;5012;50;7862\n2014;215;4581;1284;51330;813;4000;49846;17;45466;31299;16502;2086;7460;4716;57;8083\n2015;207;4249;1286;53438;762;3844;45302;17;43807;28274;15662;2111;6901;4366;56;7546\n2016;195;4063;1155;54502;713;4115;42234;13;43869;25795;14762;2119;6282;4056;47;7640\n2017;173;3729;1109;54876;722;4250;40776;16;44003;24266;14072;2089;6271;3641;56;7677\n2018;167;3593;1076;53408;702;4408;39502;10;44515;23572;13447;2075;6311;3479;34;7405\n2019;205;3563;1039;53157;677;4430;38758;10;44452;23374;13114;2106;6620;3224;61;7517\n2020;177;3393;957;52706;637;4698;37440;10;43105;23408;12999;2027;6705;2866;364;7656\n2021;170;3182;979;51795;540;4577;35157;5;42186;23119;12261;2046;6757;2841;436;7436\n2022;147;2783;950;48112;533;4189;32893;10;38192;21572;10775;1984;6380;2621;529;7602","seriesMapping":[{"x":0,"y":1,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":2,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":3,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":4,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":5,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":6,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":7,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":8,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":9,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":10,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":11,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":12,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":13,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":14,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":15,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16},{"x":0,"y":16,"archeology":1,"area_studies":2,"classical_studies":3,"communication_excl_professional":4,"comparative_literature":5,"cultural_ethnic_gender_studies":6,"english_language_literature":7,"folklore":8,"general_humanities_liberal_studies":9,"history":10,"languages_lit_other_than_english":11,"linguistics":12,"philosophy":13,"religion":14,"selected_interdisciplinary_studies":15,"study_of_the_arts":16}],"decimalPoint":".","assignDataFields":[{"labels":"A","values":"B"},{"labels":"A","values":"C"},{"labels":"A","values":"D"},{"labels":"A","values":"E"},{"labels":"A","values":"F"},{"labels":"A","values":"G"},{"labels":"A","values":"H"},{"labels":"A","values":"I"},{"labels":"A","values":"J"},{"labels":"A","values":"K"},{"labels":"A","values":"L"},{"labels":"A","values":"M"},{"labels":"A","values":"N"},{"labels":"A","values":"O"},{"labels":"A","values":"P"},{"labels":"A","values":"Q"}]}};
  var optionsStub;
  
  var templateDataSettings = {};

  var pluginCode = {};;

  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') ||
             (loadHighchartsModules && src === 'highcharts.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 modifyOptions(){
    if (options.data && !options.data.complete) {
      options.data.complete = function(chartOptions) {
        const keys = Object.keys(templateDataSettings || {});
        keys.forEach(function(key) {
          const serie = chartOptions.series[key];
          (serie.data || []).forEach(function(d, i) {
            if (templateDataSettings[key].data && templateDataSettings[key].data[i]) {
              window["everviz"].merge(d, templateDataSettings[key].data[i]);
            }
          })
        })

        if (options && options.chart && options.chart.type === 'packedbubble') {
          chartOptions.series.forEach((series) => {
            series.data = series.data.filter((point) => point.value);
          });
        }

        return chartOptions;
      }
    }
    
    optionsStub = window["everviz"].createStub(options);
    window["everviz"].merge(options, pluginCode);
    if ('Chart' === 'Map') window["everviz"].modifyMapType(options);
  }

  function createChart() {
    if(chartCreated) return;

    var hasProj4 = extraScripts.indexOf('https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js') > -1;

    if (!allScriptsIncluded() || 
      (hasProj4 && !window.proj4) || 
      !window["everviz"].merge ||
      !window["everviz"].createStub) {
      setTimeout(createChart, 200);
      return;
    }  

    modifyOptions();

    if (hasProj4) delayGen = 100;

    if (typeof window['Highcharts'] !== 'undefined') {
      
    if (window['everviz'] && window['everviz'].tooltipFormatter && 
        options.everviz && options.everviz.tooltip){
      if (!options.tooltip) options.tooltip = {};
      options.tooltip.formatter = window['everviz'].tooltipFormatter;
    }


    if (options.yAxis && options.yAxis.length === 1) options.yAxis = options.yAxis[0];
    if (options.xAxis && options.xAxis.length === 1) options.xAxis = options.xAxis[0];
    if (options.zAxis && options.zAxis.length === 1) options.zAxis = options.zAxis[0];

    /*
// Sample of extending options:
Highcharts.merge(true, options, {
    chart: {
        backgroundColor: "#bada55"
    },
    plotOptions: {
        series: {
            cursor: "pointer",
            events: {
                click: function(event) {
                    alert(this.name + " clicked\n" +
                          "Alt: " + event.altKey + "\n" +
                          "Control: " + event.ctrlKey + "\n" +
                          "Shift: " + event.shiftKey + "\n");
                }
            }
        }
    }
});
*/


      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(){
          if (window["everviz"] && window["everviz"].pendingAnim) {
            //TODO: change to using classes instead.
            //Bit of work to do there due to backward compatibility
            const elements = document.querySelectorAll(
              '#' + elementClassName + 
              ', #' + legacyElementClassName
            );
            const elementsArray = Array.prototype.slice.call(elements);
            elementsArray.forEach(function(element, elementIndex) {

              window["everviz"].updateRenderTo(optionsStub, element);
              const stubbedChart = new Highcharts.Chart(optionsStub);
              

              window["everviz"].pendingAnim({
                id: element.id + '-' + elementIndex, 
                loaded: false,
                options: options,
                appear:function(){
                  window.everviz.disconnectResizeObserver(stubbedChart);
                  window["everviz"].updateRenderTo(options, element);
                  new Highcharts.Chart(options);

                },
                element: element
              });
            });

          } else {
            const element = document.querySelector('#' + legacyElementClassName);

            if (element) new Highcharts.Chart(legacyElementClassName, options)
            else new Highcharts.Chart(elementClassName, options) 

            
          }
      }, delayGen);
    }
  }

  function check(scripts, cb) {
    if (loaded === scripts.length) {
      if (cb) {
        cb();
      } else {


        //Create first project
        if (!window.HighchartsCloud.versions ||
           (window.HighchartsCloud.versions && window.HighchartsCloud.versions.length !== window.HighchartsCloud.ondone.length)) {
             
          for (var i = 0; i < window.HighchartsCloud.ondone.length; i++) {
            try {
              window.HighchartsCloud.ondone[i]();
            } catch(e) {
              console.error(e);
            }
          }
        } else {
          if (window.HighchartsCloud.stack.length) {
            window.HighchartsCloud.stack[0]();
            window.HighchartsCloud.stack.shift();
            const shouldRenderNextChart = window.HighchartsCloud.stack.length > 0;
            if (shouldRenderNextChart) {
              window.HighchartsCloud.stack[0](true);
            }
          }
        }
        
      }
    }
  }

  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('http') >= 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(isUsingStack){
    loaded = 0;
    loadCSS();
    if (extraScripts.length > 0) {
      if (isUsingStack) {
        window.HighchartsCloud.stack[0] = createChart;
        loadScript(extraScripts[0], extraScripts);
      }
      else loadScript(extraScripts[0], extraScripts, createChart);
    } else {
      check(extraScripts);
    }
  }

  function getAllScripts(){
    var evervizScripts = [];
    var allScripts = scripts.map(function(script) {
      return 'highcharts/'+ script.replace('highcharts/highcharts.js', 'highcharts.js').replace('.js', '');
    }).concat(
      extraScripts.map(function(script) {
        if (script.indexOf('https://code.highcharts.com/') > -1) {
          return 'highcharts/'+ script.replace('https://code.highcharts.com/', '').replace('.js', '');
        } else if (script.indexOf('https://app.everviz.com/') > -1) {
          evervizScripts.push(script);
          return null;
        } else return script;
      }).filter(function(s) {
        return s !== null;
      })
    );

    allScripts.forEach(function(script) {
      if (window.HighchartsCloud.allScripts)
        window.HighchartsCloud.allScripts[script] = 1
    });

    return {
      allHighchartsScripts: allScripts,
      evervizScripts: evervizScripts
    }
  }

  function loadRequireJSScript(){
    require.config({
      packages: [{
        name: 'highcharts',
        main: 'highcharts'
      }],
      paths: {
        'highcharts': 'https://code.highcharts.com'
      }
    });

    const allScripts = getAllScripts();

    require(
      allScripts.allHighchartsScripts,
      function (Highcharts) {
        //Attach highcharts to the window for use in the everviz scripts
        window.Highcharts = Highcharts;
        if (allScripts && allScripts.evervizScripts.length) {
          require(allScripts.evervizScripts, function(){
            createChart();
            loadCSS();
          })
        } else {
          createChart();
          loadCSS();
        }
      }
    );
  }

  function loadInitialScript(){
    if (window['require'] && typeof require === "function" && typeof require.specified === "function") {
      loadRequireJSScript();
    } else {
      getAllScripts()
      loadScript(scripts[0], scripts, loadExtraScripts);
      loadCSS();
    }
  }

  if (typeof window['HighchartsCloud'] === 'undefined') {
    window.HighchartsCloud = {
      ondone: [createChart],
      stack: [createChart],
      hasWrapped: false,
      hasLoaded: false,
      externalCSS: externalCSS,
      versions: [injectVersion],
      types: ['chart'],
      allScripts: {},
      projectUUIDs: {'s3V84Icyz': 1},
    };

    loadInitialScript();

  } else {
    if (window.HighchartsCloud.externalCSS) window.HighchartsCloud.externalCSS.push(externalCSS);
    if (!window.HighchartsCloud.hasLoaded) {
      if (!window.HighchartsCloud.projectUUIDs) window.HighchartsCloud.projectUUIDs = {};

      if (!window.HighchartsCloud.projectUUIDs['s3V84Icyz']) {

        window.HighchartsCloud.projectUUIDs['s3V84Icyz'] = 1;
        window.HighchartsCloud.ondone.push(loadExtraScriptsAndMakeChart);
        if (window.HighchartsCloud.stack) {
          window.HighchartsCloud.stack.push(loadExtraScriptsAndMakeChart);
          window.HighchartsCloud.versions.push(injectVersion);
          window.HighchartsCloud.types.push('chart');
        }

      }
      if (window['require'] && typeof require === "function" && typeof require.specified === "function") {
        getAllScripts()
        loadRequireJSScript();
      }
    }
    else {
      if (window['require'] && typeof require === "function" && typeof require.specified === "function") {
        loadRequireJSScript();
      } else {
        getAllScripts()
        loadExtraScriptsAndMakeChart();
      }
    }
  }

}());
