diff --git a/src/lib/components/AnalystEstimate.svelte b/src/lib/components/AnalystEstimate.svelte index 4e65c624..3106049f 100644 --- a/src/lib/components/AnalystEstimate.svelte +++ b/src/lib/components/AnalystEstimate.svelte @@ -28,11 +28,40 @@ let lowEPSList = []; let highEPSList = []; + let highRevenueGrowthList = []; + let revenueGrowthList = []; let epsGrowthList = []; let displayData = "Revenue"; + function computeGrowthSingleList(data, actualList) { + let lastNonNull = actualList + ?.filter((value) => value !== null) + .slice(-1)[0]; + const newList = data; + newList?.unshift(lastNonNull); + // Remove leading null values + while (newList?.length > 0 && newList[0] === null) { + newList?.shift(); + } + + let growthPercentages = []; + + for (let i = 1; i < newList?.length; i++) { + let previous = newList[i - 1]; + let current = newList[i]; + + // Check if previous or current is null to avoid NaN results + if (previous !== null && current !== null) { + let growth = (((current - previous) / previous) * 100)?.toFixed(2); + growthPercentages.push(Number(growth)); // Convert to number + } + } + + return growthPercentages; + } + function computeGrowthList(tableActualRevenue, tableForecastRevenue) { return tableActualRevenue?.map((item, index) => { // If it's the first item or the list is empty, return null @@ -292,6 +321,7 @@ avgRevenueList = avgList?.slice(currentYearIndex) || []; lowRevenueList = lowList?.slice(currentYearIndex) || []; highRevenueList = highList?.slice(currentYearIndex) || []; + highRevenueGrowthList = highList?.slice(currentYearIndex) || []; } else if (dataType === "EPS") { let currentYearIndex = dates?.findIndex((date) => date === searchString); @@ -695,7 +725,7 @@