From 4fc30a69119c761e194b5845a61d8148974a2611 Mon Sep 17 00:00:00 2001 From: Kenrick Tandrian <60643640+KenTandrian@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:30:07 +0700 Subject: [PATCH] Task/align chart data array types with LineChartItem and make groupBy optional (#7996) Align chart data array types with LineChartItem and make groupBy optional --- .../account-detail-dialog.component.ts | 18 +++++++---- .../investment-chart.component.ts | 2 +- .../analysis/analysis-page.component.ts | 32 +++++++++++-------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts index 44f7280473..c95dfe7bc4 100644 --- a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts +++ b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts @@ -10,7 +10,7 @@ import { DATE_FORMAT, downloadAsFile } from '@ghostfolio/common/helper'; import { AccountBalancesResponse, Activity, - HistoricalDataItem, + LineChartItem, PortfolioPosition, User } from '@ghostfolio/common/interfaces'; @@ -99,7 +99,7 @@ export class GfAccountDetailDialogComponent implements OnInit { protected equity: number | null; protected equityPrecision = 2; protected hasPermissionToDeleteAccountBalance: boolean; - protected historicalDataItems: HistoricalDataItem[]; + protected historicalDataItems: LineChartItem[]; protected holdings: PortfolioPosition[]; protected interestInBaseCurrency: number; protected interestInBaseCurrencyPrecision = 2; @@ -364,12 +364,16 @@ export class GfAccountDetailDialogComponent implements OnInit { portfolioPerformance.chart && portfolioPerformance.chart.length > 0 ) { - this.historicalDataItems = portfolioPerformance.chart.map( - ({ date, netWorth, netWorthInPercentage }) => ({ - date, - value: isNumber(netWorth) ? netWorth : netWorthInPercentage + this.historicalDataItems = portfolioPerformance.chart + .map(({ date, netWorth, netWorthInPercentage }) => { + return { + date, + value: isNumber(netWorth) ? netWorth : netWorthInPercentage + }; }) - ); + .filter((item): item is LineChartItem => { + return isNumber(item.value); + }); } else { this.historicalDataItems = this.accountBalances.map( ({ date, valueInBaseCurrency }) => { diff --git a/apps/client/src/app/components/investment-chart/investment-chart.component.ts b/apps/client/src/app/components/investment-chart/investment-chart.component.ts index a1dc6a28f9..34500422ed 100644 --- a/apps/client/src/app/components/investment-chart/investment-chart.component.ts +++ b/apps/client/src/app/components/investment-chart/investment-chart.component.ts @@ -59,7 +59,7 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy { @Input() public benchmarkDataLabel = ''; @Input() public colorScheme?: ColorScheme; @Input() public currency?: string; - @Input() public groupBy: GroupBy; + @Input() public groupBy?: GroupBy; @Input() public historicalDataItems: LineChartItem[] = []; @Input() public isInPercentage?: boolean = false; @Input() public isLoading = false; diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts index 880753cce5..a08c9d9d52 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -7,8 +7,8 @@ import { } from '@ghostfolio/common/config'; import { canOpenHoldingDetail } from '@ghostfolio/common/helper'; import { - HistoricalDataItem, InvestmentItem, + LineChartItem, PortfolioInvestmentsResponse, PortfolioPerformance, PortfolioPosition, @@ -79,7 +79,7 @@ import { forkJoin } from 'rxjs'; }) export class GfAnalysisPageComponent implements OnInit { protected benchmark?: Partial; - protected benchmarkDataItems: HistoricalDataItem[] = []; + protected benchmarkDataItems: LineChartItem[] = []; protected readonly benchmarks: Partial[]; protected bottom3: PortfolioPosition[]; protected dividendsByGroup: InvestmentItem[]; @@ -101,8 +101,8 @@ export class GfAnalysisPageComponent implements OnInit { ]; protected performance: PortfolioPerformance; protected readonly PerformanceCalculationType = PerformanceCalculationType; - protected performanceDataItems: HistoricalDataItem[]; - protected performanceDataItemsInPercentage: HistoricalDataItem[]; + protected performanceDataItems: LineChartItem[]; + protected performanceDataItemsInPercentage: LineChartItem[]; protected readonly portfolioEvolutionDataLabel = $localize`Investment`; protected precision = 2; protected savingsRatePerMonth: number | undefined; @@ -378,18 +378,24 @@ export class GfAnalysisPageComponent implements OnInit { }); } - this.performanceDataItems.push({ + const value = isNumber(valueWithCurrencyEffect) + ? valueWithCurrencyEffect + : valueInPercentage; + + if (isNumber(value)) { + this.performanceDataItems.push({ + date, + value + }); + } + } + + if (isNumber(netPerformanceInPercentageWithCurrencyEffect)) { + this.performanceDataItemsInPercentage.push({ date, - value: isNumber(valueWithCurrencyEffect) - ? valueWithCurrencyEffect - : valueInPercentage + value: netPerformanceInPercentageWithCurrencyEffect }); } - - this.performanceDataItemsInPercentage.push({ - date, - value: netPerformanceInPercentageWithCurrencyEffect - }); } if (