Skip to content

Commit

Permalink
fix cell rendering issue in earnings view
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz committed Nov 3, 2024
1 parent 01fdfac commit fc9c779
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/app/seasonal/[symbol]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ async function getEarningsView(symbol: string) {
const closePercentage = ((data[ix].close - lp) / lp);
const openPercentage = ((data[ix].open - lp) / lp);

const nextOpenPercentage = data.length > ix ? ((data[ix + 1].open - data[ix].close) / data[ix].close) : undefined;
const nextClosePercentage = data.length > ix ? ((data[ix + 1].close - data[ix].close) / data[ix].close) : undefined;
const nextOpen = data.length > ix ? data[ix + 1].open : undefined;
const nextClose = data.length > ix ? data[ix + 1].close : undefined;
const nextOpenPercentage = data.length > ix + 1 ? ((data[ix + 1].open - data[ix].close) / data[ix].close) : undefined;
const nextClosePercentage = data.length > ix + 1 ? ((data[ix + 1].close - data[ix].close) / data[ix].close) : undefined;
const nextOpen = data.length > ix + 1 ? data[ix + 1].open : undefined;
const nextClose = data.length > ix + 1 ? data[ix + 1].close : undefined;

entries.push({
open: data[ix].open,
Expand Down
21 changes: 17 additions & 4 deletions src/components/HistoricalSeason.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,27 @@ const cssFn = (v: any) => {
return v > 0 ? 'positive' : 'negative';
}



export const EarningsSeasonComponent = (props: { data: EarningsSeason[], symbol: string, mode: string }) => {
const { data } = props;
const cellRenderer = (price?: number, change?: number) => {
let returnValue = '';
if (price) {
returnValue += currencyFormatter(price);
if (change) {
returnValue += ` (${percentageFormatter(change)})`;
}
}
return returnValue;
}

const columns: GridColDef<EarningsSeason>[] = [
{ field: 'date', headerName: 'Date' },
{ field: 'openPercentage', headerName: 'Open', type: 'number', valueFormatter: (v: number, row) => `${currencyFormatter(row.open)} (${percentageFormatter(v)})`, width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'closePercentage', headerName: 'Close', type: 'number', valueFormatter: (v: number, row) => `${currencyFormatter(row.close)} (${percentageFormatter(v)})`, width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'nextOpenPercentage', headerName: 'Next Day Open', type: 'number', valueFormatter: (v: number, row) => `${currencyFormatter(row.nextOpen || 0)} (${percentageFormatter(v)})`, width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'nextClosePercentage', headerName: 'Next Day Close', type: 'number', valueFormatter: (v: number, row) => `${currencyFormatter(row.nextClose || 0)} (${percentageFormatter(v)})`, width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'openPercentage', headerName: 'Open', type: 'number', valueFormatter: (v: number, row) => cellRenderer(row.open, v), width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'closePercentage', headerName: 'Close', type: 'number', valueFormatter: (v: number, row) => cellRenderer(row.close, v), width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'nextOpenPercentage', headerName: 'Next Day Open', type: 'number', valueFormatter: (v: number, row) => cellRenderer(row.nextOpen, v), width: 160, cellClassName: ({ value }) => cssFn(value) },
{ field: 'nextClosePercentage', headerName: 'Next Day Close', type: 'number', valueFormatter: (v: number, row) => cellRenderer(row.nextClose, v), width: 160, cellClassName: ({ value }) => cssFn(value) },
];
return data.length > 0 ? <DataGrid
sx={{
Expand Down

0 comments on commit fc9c779

Please sign in to comment.