{"contents":"jQuery(\n  function ($) {\n    $(\"#download\").click(function (e) {\n      e.preventDefault();\n      let charts = Highcharts.charts.filter(Boolean);\n      charts[0].downloadCSV();\n    });\n\n    let mapPath = \"/modules/custom/sec_custom_blocks/js/oasb_raising_capital_map/\";\n    let dataPath = \"/files/\";\n    let mapType;\n    let countyMode = false;\n    var showMetroMap = false;\n    const mapTypes = [\"regCF\", \"regA\", \"regD\", \"registered\"];\n\n    $(document).ready(async function () {\n      document.getElementById(\"locationSelection\").addEventListener(\"change\", filterByValue);\n\n      (function (H) {\n        H.wrap(H.Chart.prototype, \"getCSV\", function (p, useLocalDecimalPoint) {\n          // let csv = \"\";\n          let generatedHTML = \"\";\n          for (let map of mapTypes) {\n            const stateFilters = window[`${map}_filters`];\n            const countyFilters = window[`${map}_county_filters`];\n            for (let filter of stateFilters) {\n              let data = window[`${map}_${filter.key}`];\n              //csv += generateCSV(data, `${window[`${map}_mapTitle`]}(${filter.text})`);\n              generatedHTML += generateA11yTable(data, `${window[`${map}_mapTitle`]}(${filter.text})`);\n            }\n            if (countyFilters?.length) {\n              for (let filter of countyFilters) {\n                let data = window[`${map}_${filter.key}`];\n                // csv += generateCSV(data, `${window[`${map}_mapTitle`]} (County ${filter.text})`, \"county\");\n                generatedHTML += generateA11yTable(data, `${window[`${map}_mapTitle`]} (County ${filter.text})`, \"county\");\n              }\n            }\n          }\n          //return csv;\n        });\n\n      })(Highcharts);\n\n      (function (H) {\n        H.addEvent(H.Axis, \"afterInit\", function () {\n          const logarithmic = this.logarithmic;\n          if (logarithmic && this.options.allowNegativeLog) {\n            // Avoid errors on negative numbers on a log axis\n            this.positiveValuesOnly = false;\n            // Override the converter functions\n            logarithmic.log2lin = (num) => {\n              const isNegative = num < 0;\n              let adjustedNum = Math.abs(num);\n              if (adjustedNum < 10) {\n                adjustedNum += (10 - adjustedNum) / 10;\n              }\n              const result = Math.log(adjustedNum) / Math.LN10;\n              return isNegative ? -result : result;\n            };\n\n            logarithmic.lin2log = (num) => {\n              const isNegative = num < 0;\n              let result = Math.pow(10, Math.abs(num));\n              if (result < 10) {\n                result = (10 * (result - 1)) / (10 - 1);\n              }\n              return isNegative ? -result : result;\n            };\n          }\n        });\n      })(Highcharts);\n      const dataSet = await fetchDataFiles();\n      createVariables(dataSet);\n      createMapDropdown();\n      // createA11yDataTables();\n      loadMap();\n      showFilter();\n    });\n\n    async function fetchDataFiles() {\n      return Promise.all(\n        [...mapTypes, \"county\"].map((fileName) => fetch(dataPath + `${fileName.toLowerCase()}.json`).then((data) => data.json()))\n      );\n    }\n\n    function createVariables(dataSet) {\n      for (let item of dataSet) {\n        for (let [key, value] of Object.entries(item)) {\n          window[key] = value;\n        }\n      }\n    }\n\n    function createMapDropdown() {\n      const mapSelection = document.getElementById(\"mapSelection\");\n      let optionsHTML = ``;\n      for (let index = 0; index < mapTypes.length; index++) {\n        let map = mapTypes[index];\n        if (map === \"regCF\") {\n          optionsHTML += `<option value=\"${map}\" selected>${window[`${map}_mapTitle`]}</option>`;\n        } else {\n          optionsHTML += `<option value=\"${map}\" >${window[`${map}_mapTitle`]}</option>`;\n        }\n      }\n      mapSelection.innerHTML = optionsHTML;\n    }\n\n    /* function createA11yDataTables() {\n      let generatedHTML = \"\";\n      for (let map of mapTypes) {\n        const stateFilters = window[`${map}_filters`];\n        const countyFilters = window[`${map}_county_filters`];\n        for (let filter of stateFilters) {\n\n          let data = window[`${map}_${filter.key}`];\n\n          generatedHTML += generateA11yTable(data, `${window[`${map}_mapTitle`]} (${filter.text})`,`${map}_${filter.key}`);\n        }\n        if (countyFilters?.length) {\n          for (let filter of countyFilters) {\n            let data = window[`${map}_county_${filter.key}`];\n            generatedHTML += generateA11yTable(data, `${window[`${map}_mapTitle`]} (County ${filter.text})`, `${map}_county_${filter.key}`, \"county\");\n          }\n        }\n      }\n      document.getElementById(\"a11y-data-tables\").innerHTML = generatedHTML;\n\n      clearA11yTables();\n\n      document.getElementById(\"regCF_2020\").style.display = \"block\";\n    } */\n\n    function generateA11yTable(mapData, title, tableName, type = \"state\") {\n      let renderedHTML = `<table id=\"${tableName}\">`;\n\n      renderedHTML += `<caption>${title}</caption>`;\n\n      renderedHTML += type === \"state\" ? `<tr><th>State</th><th>Offerings Count</th><th>USD Raised</th></tr>` : `<tr><th>State</th><th>County</th><th>Offerings Count</th><th>USD Raised</th></tr>`;\n      if (type === \"state\") {\n      let stateMap = Highcharts.geojson(Highcharts.maps[\"countries/us/custom/us-all-territories\"]);\n      for (let row of mapData) {\n      let { code, offerings, usd } = row;\n      const { name = code } = stateMap.find((state) => state.properties[\"hc-key\"] === code) ?? {};\n      if (name) {\n      renderedHTML += `<tr><td>${name}</td><td>${offerings}</td><td>${formatNumber(usd)}</td></tr>`;\n      }\n      }\n      } else {\n      let countiesMap = Highcharts.geojson(Highcharts.maps[\"countries/us/us-all-all-highres\"]);\n      for (let row of mapData) {\n      let { code, offerings, usd } = row;\n      let st_name = code;\n      if (st_name.startsWith(\"us-\")) st_name = st_name.substr(3,2).toUpperCase();\n\n      const { name = code } = countiesMap.find((county) => county.properties[\"hc-key\"] === code) ?? {};\n      if (name) {\n        if (name) name2 = name;\n        if (name === \"us-pr-127\") name2 = \"San Juan\";\n\n      renderedHTML += `<tr><td>${st_name}</td><td>${name2}</td><td>${offerings}</td><td>${formatNumber(usd, true)}</td></tr>`;\n      }\n      }\n      }\n      renderedHTML += \"</table>\";\n      return renderedHTML;\n      }\n\n    /* function clearA11yTables() {\n      document.getElementById(`regCF_2019`).style.display = \"none\";\n      document.getElementById(`regCF_2020`).style.display = \"none\";\n      document.getElementById(`regCF_county_2019`).style.display = \"none\";\n      document.getElementById(`regCF_county_2020`).style.display = \"none\";\n      document.getElementById(`regA_2018_19`).style.display = \"none\";\n      document.getElementById(`regA_2019_20`).style.display = \"none\";\n      document.getElementById(`regD_2018_19`).style.display = \"none\";\n      document.getElementById(`regD_2019_20`).style.display = \"none\";\n      document.getElementById(`registered_2018_19`).style.display = \"none\";\n      document.getElementById(`registered_2019_20`).style.display = \"none\";\n    } */\n\n    function generateCSV(mapData, title, type = \"state\") {\n      let csv = `\"\",${title},\"\"\\r\\n\\r\\n`;\n      csv += type === \"state\" ? \"State,Offerings Count,USD Raised\\r\\n\" : \"State Code,County,Offerings Count,USD Raised\\r\\n\";\n      if (type === \"state\") {\n        let stateMap = Highcharts.geojson(Highcharts.maps[\"countries/us/custom/us-all-territories\"]);\n        for (let row of mapData) {\n          let { code, offerings, usd } = row;\n          const { name = code } = stateMap.find((state) => state.properties[\"hc-key\"] === code) ?? {};\n          if (name) {\n            csv += `${name},${offerings},${formatNumber(usd)}\\r\\n`;\n          }\n        }\n      } else {\n        let countiesMap = Highcharts.geojson(Highcharts.maps[\"countries/us/us-all-all-highres\"]);\n        for (let row of mapData) {\n          let { code, offerings, usd } = row;\n          const st_name = code;\n          const { name = code } = countiesMap.find((county) => county.properties[\"hc-key\"] === code) ?? {};\n          if (name) {\n            csv += `${st_name},${name},${offerings},${formatNumber(usd, true)}\\r\\n`;\n          }\n        }\n      }\n      csv += \"\\r\\n\";\n      return csv;\n    }\n\n    function hideFilter(filterId) {\n      document.getElementById(filterId).style.display = \"none\";\n    }\n\n    function showFilter() {\n      document.getElementById(\"stateFilter\").style.display = \"\";\n    }\n\n    function createFilter(mapType) {\n      const stateFilter = document.getElementById(\"selectedFilter\");\n      if (stateFilter) {\n        stateFilter.removeEventListener(\"change\", onFilterValueChange);\n      }\n      const stateFilterContainer = document.querySelector(\"#stateFilter .filterContainer\");\n      let filterHTML = ``;\n      let filters = !countyMode ? window[`${mapType}_filters`] : window[`${mapType}_county_filters`];\n      for (let filter of filters) {\n        const { key, text } = filter;\n        filterHTML += `<option value=\"${key}\">${text}</option>`;\n      }\n      filterHTML = `<select required name=\"selectedFilter\" class=\"usa-select\" id=\"selectedFilter\" aria-controls=\"aria-controlled-content\">${filterHTML}</select>`;\n      stateFilterContainer.innerHTML = filterHTML;\n      document.getElementById(\"selectedFilter\").addEventListener(\"change\", onFilterValueChange);\n    }\n\n    //function onFilterValueChange(e) {\n      //let { value } = e.target;\n     // if (value) {\n      //  let mapData = !countyMode ? window[`${mapType}_${value}`] : window[`${mapType}_county_${value}`];\n     //   loadMap(countyMode, mapData, false);\n     // }\n    //}\n\n    function onFilterValueChange(e){\n      let { value } = e.target;\n\n      if (value) {\n        let mapData = !countyMode ? window[`${mapType}_${value}`] : window[`${mapType}_county_${value}`];\n\n        // clearA11yTables();\n\n        if (!countyMode) {\n          mapData = window[`${mapType}_${value}`];\n\n\n\n          // document.getElementById(`${mapType}_${value}`).style.display = \"block\";\n        } else {\n          window[`${mapType}_county_${value}`];\n          // document.getElementById(`${mapType}_county_${value}`).style.display = \"block\";\n        }\n        loadMap(countyMode, mapData, false);\n      }\n    }\n\n    function filterByValue(e) {\n      const { value } = e.target;\n      showMetroMap = value === \"metro\";\n      switch (value) {\n        case \"counties\":\n        case \"metro\":\n          if (mapType == \"regCF\") {\n            loadMap(true);\n          }\n          break;\n        case \"states\":\n          loadMap();\n          break;\n        default:\n          console.log(value);\n      }\n    }\n\n    //map dropdown\n    document.getElementById(\"mapSelection\").addEventListener(\"change\", (e) => {\n      loadMap();\n    });\n\n    document.getElementById(\"stateFilter\").addEventListener(\"submit\", (event) => {\n      event.preventDefault();\n      let { selectedFilter } = event.target;\n      if (selectedFilter?.value) {\n        // clearA11yTables();\n        document.getElementById(`${mapType}_${selectedFilter.value}`).style.display = \"block\";\n        loadMap(false, window[`${mapType}_${selectedFilter.value}`], false);\n      }\n    });\n\n    document.getElementById(\"stateFilter\").addEventListener(\"reset\", (event) => {\n      loadMap(false);\n    });\n\n    function loadMap(county, mapData, initializeFilter = true) {\n      hideFilter(\"stateFilter\");\n\n      mapType = document.getElementById(\"mapSelection\").value;\n\n      if (county) {\n        countyMode = true;\n        document.querySelector(\".countiesHolder\").style.display = \"flex\";\n      } else {\n        const locationFilter = document.getElementById(\"locationSelection\");\n        locationFilter.value = \"states\";\n        countyMode = showMetroMap = false;\n        document.querySelector(\".countiesHolder\").style.display = \"none\";\n      }\n\n      if (initializeFilter) {\n        createFilter(mapType);\n      }\n\n      showFilter();\n      if (!mapData) {\n        // load the data as per the selected filter\n        const selectedFilter = document.querySelector(\"#stateFilter #selectedFilter\");\n\n        // get the name of the data obj (also name of a11y data table in html)\n        let dataNameStr = !countyMode\n          ? `${mapType}_${selectedFilter?.value}`\n          : `${mapType}_county_${selectedFilter?.value}`;\n\n        mapData = window[dataNameStr];\n        // clearA11yTables();\n        // document.getElementById(dataNameStr).style.display = \"block\";\n      }\n      let colors = window[`${mapType}_colorPalette`];\n\n      let countiesElement = document.querySelector(\"section[type=where] option[value='counties']\");\n      countiesElement.style.display = \"none\";\n\n      createLegend(mapType, colors);\n      setMethodology(mapType, countyMode);\n      const mapTitle = window[`${mapType}_mapTitle`];\n      switch (mapType) {\n        case \"regCF\":\n          initializeMap(mapData, mapTitle, colors, county);\n          countiesElement.style.display = \"\";\n          break;\n        case \"regA\":\n          initializeMap(mapData, mapTitle, colors, county);\n          break;\n        case \"regD\":\n          initializeMap(mapData, mapTitle, colors, county);\n          break;\n        case \"registered\":\n          initializeMap(mapData, mapTitle, colors, county);\n          break;\n      }\n    }\n\n    function setMethodology(mapType) {\n      const methodologyText = !countyMode ? window[`${mapType}_methodology`] : window[`${mapType}_county_methodology`];\n      document.getElementById(\"methodology-description\").innerText = methodologyText;\n    }\n\n    function createLegend(mapType, colors) {\n      let container = document.querySelector(\".colorQuantity-container\");\n      let innerHTML = `<div class=\"colorQuantity-item\">\n            <span class=\"color\" style=\"background-color: #f7f7f7\"></span>\n            <span class=\"price\">None</span>\n          </div>`;\n      let legend = !countyMode ? window[`${mapType}_legend`] : window[`${mapType}_county_legend`];\n\n      for (let index = 0; index < legend.length; index++) {\n        innerHTML += `<div class=\"colorQuantity-item\">\n            <span class=\"color\" style=\"background-color: ${colors[index]}\"></span>\n            <span class=\"price\">${legend[index]}</span>\n          </div>`;\n      }\n      container.innerHTML = innerHTML;\n    }\n\n\n\n    const formatNumber = (num, convertToMillions = false) => {\n      num = Number(num);\n      const oneB = 1000000000;\n      const oneM = 1000000;\n      const oneK = 1000;\n      if (num > 0) {\n        // convert to thousand\n        if (convertToMillions) {\n          num = num / oneM;\n        }\n        num = num * oneK;\n        if (num >= oneM) {\n          return Highcharts.numberFormat(num / oneM, 2) + \"B\";\n        } else if (num >= oneK) {\n          return Highcharts.numberFormat(num / oneK, 2) + \"M\";\n        } else {\n          return Highcharts.numberFormat(num, 2) + \"K\";\n        }\n      } else {\n        return num;\n      }\n    };\n\n    // Instantiate the map\n    async function initializeMap(mapType, mapName, colorPalette, county = false) {\n      let config = {\n        chart: {\n          map: \"countries/us/custom/us-all-territories\",\n          height: 575,\n        },\n        accessibility: {\n          point: {\n            descriptionFormatter: function (e) {\n              return e.name + \": \" + e.offerings;\n            },\n          },\n        },\n        title: { text: mapName },\n        credits: { enabled: false },\n        exporting: {\n          csv: { itemDelimiter: \";\" },\n          sourceWidth: 600,\n          sourceHeight: 500,\n          filename: \"Exported CSV\",\n          enabled: false,\n        },\n\n        legend: {\n          layout: \"horizontal\",\n          borderWidth: 0,\n          backgroundColor: \"rgba(255,255,255,0.85)\",\n          floating: true,\n          verticalAlign: \"bottom\",\n          enabled: false,\n          y: 25,\n        },\n        mapNavigation: { enabled: true },\n        colorAxis: {\n          dataClasses: [\n            { from: 0, to: 0, color: \"#f7f7f7\" },\n            { from: 1, to: 1, color: colorPalette[0] },\n            { from: 2, to: 2, color: colorPalette[1] },\n            { from: 3, to: 3, color: colorPalette[2] },\n            { from: 4, to: 6, color: colorPalette[3] },\n          ],\n        },\n        series: [\n          {\n            states: {\n              hover: {\n                color: \"#757575\",\n              },\n            },\n            cursor: \"pointer\",\n            data: mapType,\n            colorKey: \"color_code\",\n            joinBy: [\"hc-key\", \"code\"],\n            dataLabels: {\n              enabled: true,\n              formatter: function (options) {\n                const point = this.point;\n                if (this.point.code) {\n                  const pointCode = this.series.mapMap[point.code];\n\n                  if (!pointCode) {\n                    return false;\n                  }\n\n                  const properties = pointCode.properties;\n\n                  if (!(properties[\"hc-key\"] !== \"vi-6398\" && properties[\"hc-key\"] !== \"vi-6399\")) return null;\n\n                  if (properties.type === \"State\") return `${properties[\"postal-code\"]}<br>${point.offerings}`;\n\n                  if (properties.type === \"Federal District\") return `${properties[\"hasc\"].split(\".\")[1]}<br>${point.offerings}`;\n\n                  return `${properties[\"hasc\"].split(\".\")[0]}<br>${point.offerings}`;\n\n\n\n\n                  //return properties[\"hc-key\"] !== \"vi-6398\" && properties[\"hc-key\"] !== \"vi-6399\"\n                   // ? `${properties.type === \"State\" ? properties[\"postal-code\"] : properties[\"hasc\"].split(\".\")[0]}<br>${\n                     //   point.offerings\n                     // }`\n                   // : null;\n                }\n              },\n            },\n            name: \"Information\",\n            tooltip: {\n              pointFormatter: function () {\n                const point = this;\n                return `<strong>${this.properties.name}</strong>  <br/> <strong>Offerings Count:</strong> ${\n                  point.offerings\n                } <br/> <strong>USD Raised:</strong> $${formatNumber(point.usd)}`;\n              },\n            },\n          },\n        ],\n      };\n\n      // for county related\n      if (county) {\n        var countiesMap = Highcharts.geojson(Highcharts.maps[\"countries/us/us-all-all-highres\"]),\n          // Extract the line paths from the GeoJSON\n          lines = Highcharts.geojson(Highcharts.maps[\"countries/us/us-all-all-highres\"], \"mapline\"),\n          // Filter out the state borders and separator lines, we want these\n          // in separate series\n          borderLines = lines.filter((l) => l.properties[\"hc-group\"] === \"__border_lines__\"),\n          separatorLines = lines.filter((l) => l.properties[\"hc-group\"] === \"__separator_lines__\");\n\n        // Add state acronym for tooltip\n        countiesMap.forEach(function (mapPoint) {\n          mapPoint.name = mapPoint.name + \", \" + mapPoint.properties[\"hc-key\"].substr(3, 2);\n        });\n\n        config.plotOptions = {\n          mapline: {\n            showInLegend: false,\n            enableMouseTracking: false,\n          },\n        };\n        config.chart = { height: 575, marginRight: 20 }; // for the legend\n        config.legend = {\n          layout: \"vertical\",\n          align: \"right\",\n          floating: true,\n          backgroundColor:\n            // theme\n            (Highcharts.defaultOptions &&\n              Highcharts.defaultOptions.legend &&\n              Highcharts.defaultOptions.legend.backgroundColor) ||\n            \"rgba(255, 255, 255, 0.85)\",\n        };\n        config.series = [\n          {\n            mapData: countiesMap,\n            data: mapType,\n            joinBy: [\"hc-key\", \"code\"],\n            name: \"County\",\n            borderWidth: 0.5,\n\n            states: {\n              hover: {\n                color: \"#a4edba\",\n              },\n            },\n            shadow: false,\n            colorKey: \"color_code\",\n            tooltip: {\n              pointFormatter: function () {\n                const point = this;\n                const [county, state] = this.series.mapMap[point.code].name.split(\",\");\n                return `<strong>${county},${state.toUpperCase()}</strong> <br/> <strong>Offerings Count:</strong> ${\n                  point.offerings\n                } <br/> <strong>USD Raised:</strong> $${formatNumber(point.usd, true)}`;\n              },\n            },\n          },\n          {\n            type: \"mapline\",\n            name: \"State borders\",\n            data: borderLines,\n            color: \"darkgray\",\n            shadow: false,\n          },\n        ];\n        Highcharts.getJSON(mapPath + \"pr-municipalities.json\", function (geojson) {\n          // Initiate the chart\n          let prConfig = { ...config, title: \"Puerto Rico\" };\n\n          let mapData = mapType.find((item) => item?.code?.includes(\"us-pr-\"));\n          let clonedMapData = mapData ? { ...mapData } : null;\n          if (clonedMapData) {\n            clonedMapData.code = clonedMapData.code.replace(\"us-pr-\", \"\");\n          }\n          prConfig.chart = {\n            map: geojson,\n            height: 135,\n            width: 135,\n          };\n          prConfig.mapNavigation = { enabled: true };\n          prConfig.series = [\n            {\n              data: [clonedMapData],\n              joinBy: [\"COUNTY\", \"code\"],\n              name: \"County\",\n              colorKey: \"color_code\",\n              states: {\n                hover: {\n                  color: \"#a4edba\",\n                },\n              },\n              dataLabels: {\n                enabled: true,\n              },\n              mapNavigation: { enabled: true },\n              tooltip: {\n                pointFormatter: function () {\n                  const point = this;\n                  const [county, state] = [point.name, \"PR\"];\n                  return `<strong>${county}, ${state.toUpperCase()}</strong> <br/> <strong>Offerings Count:</strong> ${\n                    point.offerings\n                  } <br/> <strong>USD Raised:</strong> $${formatNumber(point.usd, true)}`;\n                },\n              },\n            },\n          ];\n          // prConfig.chart.map = geojson;\n          Highcharts.mapChart(\"countyContainer\", prConfig);\n        });\n        Highcharts.getJSON(mapPath + \"guam.json\", function (geojson) {\n          // Initiate the chart\n          let guamConfig = { ...config, title: \"Guam\" };\n\n          let mapData = mapType.find((item) => item?.code?.includes(\"us-pr-\"));\n          let clonedMapData = mapData ? { ...mapData } : null;\n          if (clonedMapData) {\n            clonedMapData.code = clonedMapData.code.replace(\"us-pr-\", \"\");\n          }\n          guamConfig.chart = {\n            map: geojson,\n            height: 50,\n            width: 50,\n          };\n          guamConfig.series = [\n            {\n              name: \"Guam\",\n              states: {\n                hover: {\n                  color: \"#a4edba\",\n                },\n              },\n              dataLabels: {\n                enabled: true,\n              },\n            },\n          ];\n          // guamConfig.chart.map = geojson;\n          Highcharts.mapChart(\"guam-countyContainer\", guamConfig);\n        });\n        Highcharts.getJSON(mapPath + \"virgin-islands.json\", function (geojson) {\n          // Initiate the chart\n          let viConfig = { ...config, title: \"Virgin Islands\" };\n\n          let mapData = mapType.find((item) => item?.code?.includes(\"us-pr-\"));\n          let clonedMapData = mapData ? { ...mapData } : null;\n          if (clonedMapData) {\n            clonedMapData.code = clonedMapData.code.replace(\"us-pr-\", \"\");\n          }\n          viConfig.chart = {\n            map: geojson,\n            height: 50,\n            width: 50,\n          };\n          viConfig.series = [\n            {\n              name: \"VI\",\n              states: {\n                hover: {\n                  color: \"#a4edba\",\n                },\n              },\n              dataLabels: {\n                enabled: true,\n              },\n            },\n          ];\n          // viConfig.chart.map = geojson;\n          Highcharts.mapChart(\"vi-countyContainer\", viConfig);\n        });\n      }\n      config.legend = {\n        enabled: false,\n      };\n\n      setTimeout(() => {\n        Highcharts.mapChart(\"container\", config);\n      }, 0);\n    }\n}\n);\n","status":{"url":"https://www.sec.gov/modules/custom/sec_custom_blocks/js/oasb_raising_capital_map/main.js","content_type":"application/javascript","content_length":24407,"http_code":200,"response_time":62}}