bugfixing graph and dashboard for forecast page

This commit is contained in:
MuslemRahimi 2024-09-17 22:21:10 +02:00
parent ca161da28c
commit ee822b3b6d
2 changed files with 37 additions and 14 deletions

View File

@ -22,10 +22,19 @@
let displayData = "Revenue"; let displayData = "Revenue";
function findIndex(data) { function findIndex(data) {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
return data.findIndex((item) => item.date > currentYear && item.revenue === null);
} // Find the index where the item's date is greater than or equal to the current year and revenue is null
const index = data.findIndex((item) => item.date > currentYear && item.revenue === null);
// Check if there is any item for the current year with non-null revenue
const hasNonNullRevenue = data.some((item) => item.date === currentYear && item.revenue !== null);
// Add +1 to the index if the condition is met
return index !== -1 && hasNonNullRevenue ? index + 1 : index;
}
function changeStatement(event) { function changeStatement(event) {
displayData = event.target.value; displayData = event.target.value;
@ -63,35 +72,33 @@
if (filteredData) { if (filteredData) {
filteredData.forEach((item, index) => { filteredData.forEach((item, index) => {
const date = item.date?.toString().slice(-2); const date = item.date?.toString().slice(-2);
const isBeforeStopIndex = index < stopIndex; const isAfterStartIndex = stopIndex <= index+1;
const isAfterStartIndex = index >= stopIndex -2;
dates.push(`FY${date}`); dates.push(`FY${date}`);
switch (displayData) { switch (displayData) {
case "Revenue": case "Revenue":
valueList.push(isBeforeStopIndex ? item.revenue : null); valueList.push(item.revenue);
avgList.push(isAfterStartIndex ? item.estimatedRevenueAvg : null); avgList.push(isAfterStartIndex ? item.estimatedRevenueAvg : null);
lowList.push(isAfterStartIndex ? item.estimatedRevenueLow : null); lowList.push(isAfterStartIndex ? item.estimatedRevenueLow : null);
highList.push(isAfterStartIndex ? item.estimatedRevenueHigh : null); highList.push(isAfterStartIndex ? item.estimatedRevenueHigh : null);
break; break;
case "Net Income": case "Net Income":
valueList.push(isBeforeStopIndex ? item.netIncome : null); valueList.push(item.netIncome);
avgList.push(isAfterStartIndex ? item.estimatedNetIncomeAvg : null); avgList.push(isAfterStartIndex ? item.estimatedNetIncomeAvg : null);
lowList.push(isAfterStartIndex ? item.estimatedNetIncomeLow : null); lowList.push(isAfterStartIndex ? item.estimatedNetIncomeLow : null);
highList.push(isAfterStartIndex ? item.estimatedNetIncomeHigh : null); highList.push(isAfterStartIndex ? item.estimatedNetIncomeHigh : null);
break; break;
case "EBITDA": case "EBITDA":
valueList.push(isBeforeStopIndex ? item.ebitda : null); valueList.push(item.ebitda);
avgList.push(isAfterStartIndex ? item.estimatedEbitdaAvg : null); avgList.push(isAfterStartIndex ? item.estimatedEbitdaAvg : null);
lowList.push(isAfterStartIndex ? item.estimatedEbitdaLow : null); lowList.push(isAfterStartIndex ? item.estimatedEbitdaLow : null);
highList.push(isAfterStartIndex ? item.estimatedEbitdaHigh : null); highList.push(isAfterStartIndex ? item.estimatedEbitdaHigh : null);
break; break;
case "EPS": case "EPS":
valueList.push(isBeforeStopIndex ? item.eps : null); valueList.push(item.eps);
avgList.push(isAfterStartIndex ? item.estimatedEpsAvg : null); avgList.push(isAfterStartIndex ? item.estimatedEpsAvg : null);
lowList.push(isAfterStartIndex ? item.estimatedEpsLow : null); lowList.push(isAfterStartIndex ? item.estimatedEpsLow : null);
highList.push(isAfterStartIndex ? item.estimatedEpsHigh : null); highList.push(isAfterStartIndex ? item.estimatedEpsHigh : null);
break; break;
default: default:
break; break;
} }

View File

@ -8,11 +8,26 @@
let changeNetIncome = 0; let changeNetIncome = 0;
let changeEBITDA = 0; let changeEBITDA = 0;
let changeEPS = 0; let changeEPS = 0;
function findIndex(data) {
const currentYear = new Date().getFullYear(); function findIndex(data) {
return data?.findIndex((item) => item?.date > currentYear && item?.revenue === null); const currentYear = new Date().getFullYear();
// Find the index where the item's date is greater than the current year and revenue is null
const index = data?.findIndex((item) => item?.date > currentYear && item?.revenue === null);
// If index is found and there is at least one item in the data for the current year with non-null revenue
if (index !== -1) {
const hasNonNullRevenue = data?.some((item) => item?.date === currentYear && item?.revenue !== null);
// Add +1 to the index if the condition is met
return hasNonNullRevenue ? index + 1 : index;
} }
return index; // Return the index or -1 if not found
}
const calculateChange = (current, previous) => { const calculateChange = (current, previous) => {
if (previous !== undefined && previous !== 0) { if (previous !== undefined && previous !== 0) {
const change = ((Math.abs(current) / Math.abs(previous)) - 1) * 100; const change = ((Math.abs(current) / Math.abs(previous)) - 1) * 100;
@ -27,6 +42,7 @@
if (data?.getAnalystEstimate?.length !== 0) { if (data?.getAnalystEstimate?.length !== 0) {
index = findIndex(data?.getAnalystEstimate); index = findIndex(data?.getAnalystEstimate);
// Calculate changes using the helper function // Calculate changes using the helper function
const estimatedRevenueAvg = data?.getAnalystEstimate[index - 1]?.estimatedRevenueAvg; const estimatedRevenueAvg = data?.getAnalystEstimate[index - 1]?.estimatedRevenueAvg;
const revenue = data?.getAnalystEstimate[index - 2]?.revenue; const revenue = data?.getAnalystEstimate[index - 2]?.revenue;