diff --git a/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte b/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte index 1637fc9a..b10641c8 100644 --- a/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte @@ -23,26 +23,26 @@ import { init, use } from 'echarts/core' let changePercentageYearAgo = 0; let timePeriod = 'threeYears'; -function computeYearOverYearChange(data) { - if (data.length < 2) { - return null; // Not enough data to compute change +function computeYearOverYearChange(rawData) { + if (rawData.length < 2) { + return null; // Not enough rawData to compute change } // Step 1: Get the last entry in the list - const lastEntry = data[data.length - 1]; + const lastEntry = rawData[rawData.length - 1]; const lastDate = new Date(lastEntry.date); - const lastMarketCap = lastEntry.marketCap; + const lastMarketCap = data?.getStockQuote?.marketCap; // Step 2: Find the entry closest to one year before the last date let closestEntry = null; - for (let i = data.length - 2; i >= 0; i--) { - const entryDate = new Date(data[i].date); + for (let i = rawData.length - 2; i >= 0; i--) { + const entryDate = new Date(rawData[i].date); const oneYearAgo = new Date(lastDate); oneYearAgo.setFullYear(lastDate.getFullYear() - 1); // Check if the entry is close to one year ago if (entryDate <= oneYearAgo) { - closestEntry = data[i]; + closestEntry = rawData[i]; break; } } @@ -302,7 +302,7 @@ async function plotData()