/* Raw JS */ const ALLOWED_D3_VARIANTS = { production: "http://www.cy118119.com/TemplatePackage/contrib/libs/d3/latest/d3.min.js", intranet: "https://intranet.cdc.gov/TemplatePackage/contrib/libs/d3/latest/d3.min.js", cdnjs: "https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js", }; function loadScript(src) { return new Promise((resolve, reject) => { let script = document.createElement("script"); script.onload = () => resolve(); script.onerror = () => reject(new Error(`Could not load ${src}`)); script.src = src; script.async = false; document.body.appendChild(script); }); } // Reload the page if the hash changes window.addEventListener("hashchange", () => { window.location.reload(); }); window.addEventListener("load", async () => { let [ disease, state, // Default variant is 'production' d3_variant = "production", ] = decodeURIComponent(window.location.hash?.substring(1))?.split("-"); // This is a workaround because of a WCMS behavior that strips hashes from iframes. // See cdcent/cfa-dev-site#148 if (!disease || !state) { if (window.location.href.match("chart-flu")) { disease = "flu"; } if (window.location.href.match("chart-covid")) { disease = "covid"; } state = StateRtTimeseriesChart.US_OVERALL_NAME; } // Check d3 variant and load it if (!ALLOWED_D3_VARIANTS[d3_variant]) { throw new Error( `Tried to load d3 but ${d3_variant} is not a valid option. Options include: ${Object.keys( ALLOWED_D3_VARIANTS, ).join(", ")}`, ); } await loadScript(ALLOWED_D3_VARIANTS[d3_variant]); if (!d3) { throw new Error(`Could not load d3.`); } // Create the chart if (!StateRtTimeseriesChart.VALID_DISEASES.includes(disease) || !state) { throw new Error( `URL must contain one of ${StateRtTimeseriesChart.VALID_DISEASES.join( ", ", )} and state name after the hash separated by a - (e.g., #covid-Arizona)`, ); } StateRtTimeseriesChart.create( document.getElementById("chart-"+disease), disease, state, ); }); /* End Raw JS */ 国产精品久久久久久一级毛片