diff --git a/src/lib/components/Options/ContractLookup.svelte b/src/lib/components/Options/ContractLookup.svelte index 253225b5..e2a7c803 100644 --- a/src/lib/components/Options/ContractLookup.svelte +++ b/src/lib/components/Options/ContractLookup.svelte @@ -29,6 +29,8 @@ let displayList = []; let selectGraphType = "Vol/OI"; let rawDataHistory = []; + let infoText = {}; + let tooltipTitle; const formatDate = (dateString) => { const date = new Date(dateString); @@ -205,7 +207,7 @@ }, legend: { enabled: true, - align: "left", // Positions legend at the left edge + align: $screenWidth < 640 ? "center" : "left", // Positions legend at the left edge verticalAlign: "top", // Positions legend at the top layout: "horizontal", // Align items horizontally (use 'vertical' if preferred) itemStyle: { @@ -250,6 +252,7 @@ formatter: function () { return new Date(this.value).toLocaleDateString("en-US", { month: "short", + day: "numeric", year: "numeric", }); }, @@ -257,7 +260,7 @@ tickPositioner: function () { const positions = []; const info = this.getExtremes(); - const tickCount = 5; // Reduce number of ticks displayed + const tickCount = 3; // Reduce number of ticks displayed const interval = Math.floor((info.max - info.min) / tickCount); for (let i = 0; i <= tickCount; i++) { @@ -368,7 +371,7 @@ } } - async function loadData() { + async function loadData(state: string) { isLoaded = false; optionData = data?.getData[selectedOptionType]; @@ -376,6 +379,10 @@ strikeList = [...optionData[selectedDate]]; + if (!strikeList?.includes(selectedStrike)) { + selectedStrike = strikeList?.at(0); // Set to first element if not found + } + displayList = []; rawDataHistory = []; @@ -409,8 +416,28 @@ isLoaded = true; } + async function getInfoText(parameter, title) { + tooltipTitle = title; + const cachedData = getCache(parameter, "getInfoText"); + if (cachedData) { + infoText = cachedData; + } else { + const postData = { parameter }; + const response = await fetch("/api/info-text", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(postData), + }); + + infoText = await response.json(); + setCache(parameter, infoText, "getInfoText"); + } + } + onMount(async () => { - await loadData(); + await loadData("default"); window.addEventListener("scroll", handleScroll); return () => { @@ -449,7 +476,13 @@
Date Expiration