(function () {
  //Inject code v5.2

  var highcharts = document.createElement('script');
  var injectVersion = 5;
  var cdn = 'https://code.highcharts.com/';
  var loaded = 0;  
  var encodedUrl = encodeURI('https://https://app.everviz.com//show/poJKK7-DS');
  var chartCreated = false;
  var chart = 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-poJKK7-DS';
  var elementClassName = 'everviz-poJKK7-DS';
  var externalCSS = [
    "https://app.everviz.com/static/fonts/gordita/style.css",
    "https://app.everviz.com/resources/css/highcharts-data-table.css"
  ];

  var extraScripts = [
  "https://code.highcharts.com/maps/modules/map.js",
  "https://code.highcharts.com/mapdata/index.js?1",
  "https://code.highcharts.com/modules/tilemap.js",
  "https://code.highcharts.com/modules/pattern-fill.js",
  "https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js",
  "https://app.everviz.com/resources/js/everviz-tooltip-helper.js",
  "https://code.highcharts.com/mapdata/countries/us/us-all.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",
  ];

  var options = {"colors":["#FF495E","#28277E","#6D5BD1","#F9DCE7","#AEC8FA","#DDD8F5"],"chart":{"style":{"fontFamily":"gordita"},"map":"countries/us/us-all"},"title":{"text":"<div><strong>States Where DEI Legislation Has Been Introduced, Been Approved, or Failed</strong></div>","align":"left","style":{"color":"#00234a","fontSize":"26px"},"useHTML":true},"subtitle":{"text":"<div>Hover over states for Bill details.</div>","align":"left","useHTML":true,"style":{"fontSize":"12px","color":"#4d4d4d"}},"credits":{"text":"","href":""},"plotOptions":{"series":{"borderRadius":2,"pointPadding":0.01,"groupPadding":0.05,"borderWidth":1,"shadow":false,"marker":{"enabled":false},"lineWidth":1,"states":{"select":{"color":"#EFFFEF","borderColor":"black","dashStyle":"dot"}},"label":{"enabled":false},"allowPointSelect":true,"dataLabels":{"enabled":false,"format":"{point.name}"}}},"legend":{"align":"left","verticalAlign":"top","itemMarginBottom":10,"x":0,"symbolRadius":2,"layout":"horizontal","enabled":true},"mapNavigation":{"enabled":true},"xAxis":{"visible":false},"yAxis":{"visible":false},"colorAxis":[{"dataClasses":[{"from":0,"to":0,"color":"#e22944","name":"On watch"},{"from":1,"to":1,"color":"#00234a","name":"Bills Introduced or Approved"},{"from":2,"to":2,"color":"#0ca6a5","name":"No Bills"}]}],"series":[{"data":[],"turboThreshold":0,"type":"map"},{"data":[],"turboThreshold":0,"type":"mapline"}],"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"]},"caption":{"text":"<div><em>*Note: States that are \"on watch\" have not formally introduced or proposed DEI bills as of April 2023, but have begun digging into the allocation of state funds on DEI programs at public institutions.</em></div>","style":{"color":"#4d4d4d"},"useHTML":true},"tooltip":{"enabled":true,"headerFormat":"<div><strong>{point.name}</strong></div>","footerFormat":"","useHTML":true,"style":{"color":null,"fontWeight":null,"fontSize":null},"pointFormat":"<div><strong style=\"font-size: 12px; color: rgb(0, 0, 0);\">Bill Details:</strong><span style=\"font-size: 12px; color: rgb(0, 0, 0);\"> {point.extra}</span></div>"},"everviz":{"tooltip":{"useEvervizHelper":true,"options":{"vars":{}}}},"exporting":{"enabled":false},"accessibility":{"description":"This is a United States map with different colors for states where DEI legislation has been introduced, been approved, or failed. In pink are the states that are on watch for submitting legislation soon, in dark blue are states that have introduced or passed legislation, and in teal are states that have not introduced or passed legislation. "},"data":{"csv":"\"Key\";\"Bill(s)\";\"State Abbreviations\";\"Status of Bill(s)\"\n\"us-ak\";2;\"AK\";\"No bills\"\n\"us-al\";1;\"AL\";\"House Bill 7 (Indefinitely postponed)\"\n\"us-ar\";1;\"AR\";\"Senate Bill 71 (Died in the Senate on May 1)\"\n\"us-az\";1;\"AZ\";\"Senate Bill 1694 (Introduced)\"\n\"us-ca\";2;\"CA\";\"No bills\"\n\"us-co\";2;\"CO\";\"No bills\"\n\"us-ct\";2;\"CT\";\"No bills\"\n\"us-dc\";2;\"DC\";\"No bills\"\n\"us-de\";2;\"DE\";\"No bills\"\n\"us-fl\";1;\"FL\";\"House Bill 999/Senate Bill 266, House Bill 931/Senate Bill 958 (SB 266 and HB 931 signed into law)\"\n\"us-ga\";1;\"GA\";\"Senate Bill 261 (Dead)\"\n\"us-hi\";2;\"HI\";\"No bills\"\n\"us-ia\";1;\"IA\";\"Senate File 81, House File 616/House Study Bill 218 (Introduced)\"\n\"us-id\";2;\"ID\";\"No bills\"\n\"us-il\";2;\"IL\";\"No bills\"\n\"us-in\";1;\"IN\";\"House Bill 1338 (Introduced)\"\n\"us-ks\";1;\"KS\";\"Senate Bill 155 budget bill (Passed in the House and the Senate but parts of the bill related to higher ed were line-item vetoed by state's governor), House Bill 2460 (Introduced in March)\"\n\"us-ky\";2;\"KY\";\"No bills\"\n\"us-la\";1;\"LA\";\"Senate Bill 128 (Introduced)\"\n\"us-ma\";2;\"MA\";\"No bills\"\n\"us-md\";2;\"MD\";\"No bills\"\n\"us-me\";2;\"ME\";\"No bills\"\n\"us-mi\";2;\"MI\";\"No bills\"\n\"us-mn\";2;\"MN\";\"No bills\"\n\"us-mo\";1;\"MO\";\"Senate Bill 410, House Bill 75, Senate Bill 680, House Bill 1196 (Introduced)\"\n\"us-ms\";0;\"MS\";\"On watch\"\n\"us-mt\";1;\"MT\";\"Senate Bill 222 (Died in Standing Committee)\"\n\"us-nc\";1;\"NC\";\"House Bill 607 (Passed in the House)\"\n\"us-nd\";1;\"ND\";\"Senate Bill 2247 (Signed into law)\"\n\"us-ne\";1;\"NE\";\"Senate Bill 283 (Introduced and moved to Legislative Research as a study)\"\n\"us-nh\";2;\"NH\";\"No bills\"\n\"us-nj\";2;\"NJ\";\"No bills\"\n\"us-nm\";2;\"NM\";\"No bills\"\n\"us-nv\";2;\"NV\";\"No bills\"\n\"us-ny\";2;\"NY\";\"No bills\"\n\"us-oh\";1;\"OH\";\"Senate Bill 83/House Bill 151, House Bill 33 (Introduced)\"\n\"us-ok\";1;\"OK\";\"Senate Bill 870, Senate Bill 1008 (Introduced)\"\n\"us-or\";1;\"OR\";\"House Bill 2430/House Bill 2475 (Introduced)\"\n\"us-pa\";2;\"PA\";\"No bills\"\n\"us-ri\";2;\"RI\";\"No bills\"\n\"us-sc\";1;\"SC\";\"House Bill 4290, House Bill 4289 (Introduced)\"\n\"us-sd\";1;\"SD\";\"House Bill 1012 (Signed into law)\"\n\"us-tn\";1;\"TN\";\"House Bill 0571 (Introduced), House Bill 1376 (Signed into law)\"\n\"us-tx\";1;\"TX\";\"House Bill 1 (HB 1 in final legislative approval), House Bill 1006, House Bill 1046, House Bill 3164, House Bill 5001/Senate Bill 2313, House Bill 5127/Senate Bill 17, House Bill 5140, Senate Bill 16 (Passed in the Senate)\"\n\"us-ut\";1;\"UT\";\"House Bill 451, Senate Bill 283 (HB 451 failed to pass before the end of the legislative session, SB 283 was pulled from the legislative session in February just four days after it was introduced)\"\n\"us-va\";2;\"VA\";\"No bills\"\n\"us-vt\";2;\"VT\";\"No bills\"\n\"us-wa\";2;\"WA\";\"No bills\"\n\"us-wi\";2;\"WI\";\"No bills\"\n\"us-wv\";1;\"WV\";\"House Bill 3503 (Failed to pass before the end of the legislative session)\"\n\"us-wy\";2;\"WY\";\"No bills\"","seriesMapping":[{"hc-key":0,"value":1,"x":1,"label":2,"extra":3},{"hc-key":0,"value":1,"x":1}]},"stockTools":{"gui":{"enabled":false}}};
  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 ('Map' === '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);
              chart = new Highcharts.Map(optionsStub);
              

              window["everviz"].pendingAnim({
                id: element.id + '-' + elementIndex, 
                loaded: false,
                options: options,
                appear:function(){
                  window["everviz"].updateRenderTo(options, element);
                  chart = new Highcharts.Map(options); 

                },
                element: element
              });
            });

          } else {
            const element = document.querySelector('#' + legacyElementClassName);

            if (element) chart = new Highcharts.Map(legacyElementClassName, options);  
            else chart = new Highcharts.Map(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: {'poJKK7-DS': 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['poJKK7-DS']) {

        window.HighchartsCloud.projectUUIDs['poJKK7-DS'] = 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();
      }
    }
  }

}());
