speed up heatmap
This commit is contained in:
parent
f1e1ecc2ac
commit
058468c1b6
@ -12,27 +12,40 @@
|
|||||||
let selectedFormat: "png" | "jpeg" | "svg" = "png";
|
let selectedFormat: "png" | "jpeg" | "svg" = "png";
|
||||||
let selectedTimePeriod = "1D";
|
let selectedTimePeriod = "1D";
|
||||||
let iframeUrl: string;
|
let iframeUrl: string;
|
||||||
|
let loading = true;
|
||||||
|
|
||||||
async function getHeatMap() {
|
async function getHeatMap() {
|
||||||
const cachedData = getCache(selectedTimePeriod, "getHeatmap");
|
loading = true;
|
||||||
if (cachedData) {
|
try {
|
||||||
rawData = cachedData;
|
const cachedData = getCache(selectedTimePeriod, "getHeatmap");
|
||||||
} else {
|
if (cachedData) {
|
||||||
const postData = { params: selectedTimePeriod };
|
rawData = cachedData;
|
||||||
const response = await fetch("/api/heatmap", {
|
} else {
|
||||||
method: "POST",
|
const postData = { params: selectedTimePeriod };
|
||||||
headers: {
|
const response = await fetch("/api/heatmap", {
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
headers: {
|
||||||
body: JSON.stringify(postData),
|
"Content-Type": "application/json",
|
||||||
});
|
},
|
||||||
|
body: JSON.stringify(postData),
|
||||||
|
});
|
||||||
|
|
||||||
rawData = await response.json();
|
rawData = await response.json();
|
||||||
setCache(selectedTimePeriod, rawData, "getHeatmap");
|
setCache(selectedTimePeriod, rawData, "getHeatmap");
|
||||||
|
}
|
||||||
|
|
||||||
|
const htmlContent = rawData;
|
||||||
|
|
||||||
|
const blob = new Blob([htmlContent], { type: "text/html" });
|
||||||
|
if (iframeUrl) {
|
||||||
|
URL.revokeObjectURL(iframeUrl);
|
||||||
|
}
|
||||||
|
iframeUrl = URL.createObjectURL(blob);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error loading heatmap:", error);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blob = new Blob([rawData], { type: "text/html" });
|
|
||||||
iframeUrl = URL.createObjectURL(blob);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadPlot(item) {
|
async function downloadPlot(item) {
|
||||||
@ -92,10 +105,6 @@
|
|||||||
}
|
}
|
||||||
</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."
|
||||||
@ -226,12 +235,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full min-h-screen bg-[#09090B] overflow-hidden">
|
<div class="w-full min-h-screen bg-[#09090B] overflow-hidden">
|
||||||
|
{#if loading}
|
||||||
|
<div class="flex justify-center items-center h-[50vh]">
|
||||||
|
<div
|
||||||
|
class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-primary"
|
||||||
|
></div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if rawData}
|
{#if rawData}
|
||||||
<iframe
|
<iframe
|
||||||
bind:this={iframe}
|
bind:this={iframe}
|
||||||
src={iframeUrl}
|
src={iframeUrl}
|
||||||
class="w-full h-screen border-none"
|
class="w-full h-screen border-none {loading ? 'hidden' : ''}"
|
||||||
on:load={() => (iframeLoaded = true)}
|
on:load={() => {
|
||||||
|
iframeLoaded = true;
|
||||||
|
loading = false;
|
||||||
|
}}
|
||||||
|
loading="eager"
|
||||||
|
title="S&P 500 Heatmap"
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@ -240,3 +262,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
iframe {
|
||||||
|
transition: opacity 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user