Browse Source

Task/align chart data array types with LineChartItem and make groupBy optional (#7996)

Align chart data array types with LineChartItem and make groupBy optional
pull/8006/head
Kenrick Tandrian 6 days ago
committed by GitHub
parent
commit
4fc30a6911
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 14
      apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts
  2. 2
      apps/client/src/app/components/investment-chart/investment-chart.component.ts
  3. 20
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

14
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 { import {
AccountBalancesResponse, AccountBalancesResponse,
Activity, Activity,
HistoricalDataItem, LineChartItem,
PortfolioPosition, PortfolioPosition,
User User
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
@ -99,7 +99,7 @@ export class GfAccountDetailDialogComponent implements OnInit {
protected equity: number | null; protected equity: number | null;
protected equityPrecision = 2; protected equityPrecision = 2;
protected hasPermissionToDeleteAccountBalance: boolean; protected hasPermissionToDeleteAccountBalance: boolean;
protected historicalDataItems: HistoricalDataItem[]; protected historicalDataItems: LineChartItem[];
protected holdings: PortfolioPosition[]; protected holdings: PortfolioPosition[];
protected interestInBaseCurrency: number; protected interestInBaseCurrency: number;
protected interestInBaseCurrencyPrecision = 2; protected interestInBaseCurrencyPrecision = 2;
@ -364,12 +364,16 @@ export class GfAccountDetailDialogComponent implements OnInit {
portfolioPerformance.chart && portfolioPerformance.chart &&
portfolioPerformance.chart.length > 0 portfolioPerformance.chart.length > 0
) { ) {
this.historicalDataItems = portfolioPerformance.chart.map( this.historicalDataItems = portfolioPerformance.chart
({ date, netWorth, netWorthInPercentage }) => ({ .map(({ date, netWorth, netWorthInPercentage }) => {
return {
date, date,
value: isNumber(netWorth) ? netWorth : netWorthInPercentage value: isNumber(netWorth) ? netWorth : netWorthInPercentage
};
}) })
); .filter((item): item is LineChartItem => {
return isNumber(item.value);
});
} else { } else {
this.historicalDataItems = this.accountBalances.map( this.historicalDataItems = this.accountBalances.map(
({ date, valueInBaseCurrency }) => { ({ date, valueInBaseCurrency }) => {

2
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 benchmarkDataLabel = '';
@Input() public colorScheme?: ColorScheme; @Input() public colorScheme?: ColorScheme;
@Input() public currency?: string; @Input() public currency?: string;
@Input() public groupBy: GroupBy; @Input() public groupBy?: GroupBy;
@Input() public historicalDataItems: LineChartItem[] = []; @Input() public historicalDataItems: LineChartItem[] = [];
@Input() public isInPercentage?: boolean = false; @Input() public isInPercentage?: boolean = false;
@Input() public isLoading = false; @Input() public isLoading = false;

20
apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

@ -7,8 +7,8 @@ import {
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { canOpenHoldingDetail } from '@ghostfolio/common/helper'; import { canOpenHoldingDetail } from '@ghostfolio/common/helper';
import { import {
HistoricalDataItem,
InvestmentItem, InvestmentItem,
LineChartItem,
PortfolioInvestmentsResponse, PortfolioInvestmentsResponse,
PortfolioPerformance, PortfolioPerformance,
PortfolioPosition, PortfolioPosition,
@ -79,7 +79,7 @@ import { forkJoin } from 'rxjs';
}) })
export class GfAnalysisPageComponent implements OnInit { export class GfAnalysisPageComponent implements OnInit {
protected benchmark?: Partial<SymbolProfile>; protected benchmark?: Partial<SymbolProfile>;
protected benchmarkDataItems: HistoricalDataItem[] = []; protected benchmarkDataItems: LineChartItem[] = [];
protected readonly benchmarks: Partial<SymbolProfile>[]; protected readonly benchmarks: Partial<SymbolProfile>[];
protected bottom3: PortfolioPosition[]; protected bottom3: PortfolioPosition[];
protected dividendsByGroup: InvestmentItem[]; protected dividendsByGroup: InvestmentItem[];
@ -101,8 +101,8 @@ export class GfAnalysisPageComponent implements OnInit {
]; ];
protected performance: PortfolioPerformance; protected performance: PortfolioPerformance;
protected readonly PerformanceCalculationType = PerformanceCalculationType; protected readonly PerformanceCalculationType = PerformanceCalculationType;
protected performanceDataItems: HistoricalDataItem[]; protected performanceDataItems: LineChartItem[];
protected performanceDataItemsInPercentage: HistoricalDataItem[]; protected performanceDataItemsInPercentage: LineChartItem[];
protected readonly portfolioEvolutionDataLabel = $localize`Investment`; protected readonly portfolioEvolutionDataLabel = $localize`Investment`;
protected precision = 2; protected precision = 2;
protected savingsRatePerMonth: number | undefined; protected savingsRatePerMonth: number | undefined;
@ -378,19 +378,25 @@ export class GfAnalysisPageComponent implements OnInit {
}); });
} }
const value = isNumber(valueWithCurrencyEffect)
? valueWithCurrencyEffect
: valueInPercentage;
if (isNumber(value)) {
this.performanceDataItems.push({ this.performanceDataItems.push({
date, date,
value: isNumber(valueWithCurrencyEffect) value
? valueWithCurrencyEffect
: valueInPercentage
}); });
} }
}
if (isNumber(netPerformanceInPercentageWithCurrencyEffect)) {
this.performanceDataItemsInPercentage.push({ this.performanceDataItemsInPercentage.push({
date, date,
value: netPerformanceInPercentageWithCurrencyEffect value: netPerformanceInPercentageWithCurrencyEffect
}); });
} }
}
if ( if (
this.deviceType() === 'mobile' && this.deviceType() === 'mobile' &&

Loading…
Cancel
Save