This commit is contained in:
MuslemRahimi 2025-01-28 12:15:06 +01:00
parent 41a4a2568e
commit 1a7e7c951f
2 changed files with 34 additions and 15 deletions

View File

@ -2,6 +2,8 @@
import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js";
import { Button } from "$lib/components/shadcn/button/index.js"; import { Button } from "$lib/components/shadcn/button/index.js";
import SEO from "$lib/components/SEO.svelte"; import SEO from "$lib/components/SEO.svelte";
import { setCache, getCache } from "$lib/store";
import { onDestroy } from "svelte";
export let data; export let data;
let rawData = data?.getData; let rawData = data?.getData;
@ -9,9 +11,13 @@
let iframeLoaded = false; let iframeLoaded = false;
let selectedFormat: "png" | "jpeg" | "svg" = "png"; let selectedFormat: "png" | "jpeg" | "svg" = "png";
let selectedTimePeriod = "1D"; let selectedTimePeriod = "1D";
let isLoaded = false; let iframeUrl: string;
async function getHeatMap() { async function getHeatMap() {
const cachedData = getCache(selectedTimePeriod, "getHeatmap");
if (cachedData) {
rawData = cachedData;
} else {
const postData = { params: selectedTimePeriod }; const postData = { params: selectedTimePeriod };
const response = await fetch("/api/heatmap", { const response = await fetch("/api/heatmap", {
method: "POST", method: "POST",
@ -22,6 +28,11 @@
}); });
rawData = await response.json(); rawData = await response.json();
setCache(selectedTimePeriod, rawData, "getHeatmap");
}
const blob = new Blob([rawData], { type: "text/html" });
iframeUrl = URL.createObjectURL(blob);
} }
async function downloadPlot(item) { async function downloadPlot(item) {
@ -68,15 +79,23 @@
} }
} }
onDestroy(() => {
if (iframeUrl) URL.revokeObjectURL(iframeUrl);
});
$: { $: {
if (selectedTimePeriod && typeof window !== "undefined") { if (selectedTimePeriod && typeof window !== "undefined") {
isLoaded = false; (async () => {
getHeatMap(); await getHeatMap();
isLoaded = true; })();
} }
} }
</script> </script>
<svelte:head>
<script src="https://cdn.plot.ly/plotly-2.18.0.min.js" defer></script>
</svelte:head>
<SEO <SEO
title="S&P 500 Stock Market Heatmap" title="S&P 500 Stock Market Heatmap"
description="A stock market heatmap showing the performance of the individual stocks, sectors and industries in the S&P500." description="A stock market heatmap showing the performance of the individual stocks, sectors and industries in the S&P500."
@ -210,7 +229,7 @@
{#if rawData} {#if rawData}
<iframe <iframe
bind:this={iframe} bind:this={iframe}
srcdoc={rawData} src={iframeUrl}
class="w-full h-screen border-none" class="w-full h-screen border-none"
on:load={() => (iframeLoaded = true)} on:load={() => (iframeLoaded = true)}
/> />

View File

@ -174,7 +174,7 @@ ${paragraphs.join("\n")}
<td class="px-1 py-1.5 text-right lg:py-2" <td class="px-1 py-1.5 text-right lg:py-2"
><a ><a
class="sm:hover:text-blue-400 text-white underline underline-offset-4" class="sm:hover:text-blue-400 text-white underline underline-offset-4"
href={`/stocks/${$stockTicker}/statistics/employees`} href={`/stocks/${$stockTicker}/profile/employees`}
>{rawData?.fullTimeEmployees >{rawData?.fullTimeEmployees
? new Intl.NumberFormat("en")?.format( ? new Intl.NumberFormat("en")?.format(
rawData?.fullTimeEmployees, rawData?.fullTimeEmployees,