Browse Source

Merge 548dfc1804 into 618e6c9d27

pull/7034/merge
Matt Van Horn 18 hours ago
committed by GitHub
parent
commit
139a0c6d54
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 69
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts
  2. 12
      apps/client/src/app/pages/portfolio/analysis/analysis-page.html

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

@ -96,7 +96,8 @@ export class GfAnalysisPageComponent implements OnInit {
protected isLoadingInvestmentTimelineChart: boolean; protected isLoadingInvestmentTimelineChart: boolean;
protected isLoadingPerformanceTimelineChart: boolean; protected isLoadingPerformanceTimelineChart: boolean;
protected isLoadingPortfolioPrompt: boolean; protected isLoadingPortfolioPrompt: boolean;
protected readonly mode = signal<GroupBy>('month'); protected readonly dividendGroupBy = signal<GroupBy>('month');
protected readonly investmentGroupBy = signal<GroupBy>('month');
protected readonly modeOptions: ToggleOption<GroupBy>[] = [ protected readonly modeOptions: ToggleOption<GroupBy>[] = [
{ label: $localize`Monthly`, value: 'month' }, { label: $localize`Monthly`, value: 'month' },
{ label: $localize`Yearly`, value: 'year' } { label: $localize`Yearly`, value: 'year' }
@ -142,7 +143,7 @@ export class GfAnalysisPageComponent implements OnInit {
return undefined; return undefined;
} }
return this.mode() === 'year' return this.investmentGroupBy() === 'year'
? this.savingsRatePerMonth * 12 ? this.savingsRatePerMonth * 12
: this.savingsRatePerMonth; : this.savingsRatePerMonth;
} }
@ -186,8 +187,13 @@ export class GfAnalysisPageComponent implements OnInit {
}); });
} }
protected onChangeGroupBy(aMode: GroupBy) { protected onChangeDividendGroupBy(aMode: GroupBy) {
this.mode.set(aMode); this.dividendGroupBy.set(aMode);
this.fetchDividendsAndInvestments();
}
protected onChangeInvestmentGroupBy(aMode: GroupBy) {
this.investmentGroupBy.set(aMode);
this.fetchDividendsAndInvestments(); this.fetchDividendsAndInvestments();
} }
@ -248,12 +254,12 @@ export class GfAnalysisPageComponent implements OnInit {
forkJoin({ forkJoin({
dividends: this.dataService.fetchDividends({ dividends: this.dataService.fetchDividends({
filters: this.userService.getFilters(), filters: this.userService.getFilters(),
groupBy: this.mode(), groupBy: this.dividendGroupBy(),
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE
}), }),
investments: this.dataService.fetchInvestments({ investments: this.dataService.fetchInvestments({
filters: this.userService.getFilters(), filters: this.userService.getFilters(),
groupBy: this.mode(), groupBy: this.investmentGroupBy(),
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE
}) })
}) })
@ -263,35 +269,40 @@ export class GfAnalysisPageComponent implements OnInit {
dividends: { dividends }, dividends: { dividends },
investments: { investments, savingsRate, streaks } investments: { investments, savingsRate, streaks }
}) => { }) => {
// Expand both timelines to the union of their groups so that the if (this.dividendGroupBy() === this.investmentGroupBy()) {
// charts share the same axis, independent of whether a dividend or // Expand both timelines to the union of their groups so that the
// an investment has been tracked in a given group // charts share the same axis, independent of whether a dividend or
const dividendByDate = keyBy(dividends, 'date'); // an investment has been tracked in a given group
const investmentByDate = keyBy(investments, 'date'); const dividendByDate = keyBy(dividends, 'date');
const investmentByDate = keyBy(investments, 'date');
const dates = sortBy(
union(Object.keys(dividendByDate), Object.keys(investmentByDate)) const dates = sortBy(
); union(Object.keys(dividendByDate), Object.keys(investmentByDate))
);
this.dividendsByGroup = dates.map((date) => { this.dividendsByGroup = dates.map((date) => {
return { return {
date, date,
investment: dividendByDate[date]?.investment ?? 0 investment: dividendByDate[date]?.investment ?? 0
}; };
}); });
this.investmentsByGroup = dates.map((date) => { this.investmentsByGroup = dates.map((date) => {
return { return {
date, date,
investment: investmentByDate[date]?.investment ?? 0 investment: investmentByDate[date]?.investment ?? 0
}; };
}); });
} else {
this.dividendsByGroup = dividends;
this.investmentsByGroup = investments;
}
this.savingsRatePerMonth = savingsRate; this.savingsRatePerMonth = savingsRate;
this.streaks = streaks; this.streaks = streaks;
this.unitCurrentStreak = this.unitCurrentStreak =
this.mode() === 'year' this.investmentGroupBy() === 'year'
? this.streaks?.currentStreak === 1 ? this.streaks?.currentStreak === 1
? translate('YEAR') ? translate('YEAR')
: translate('YEARS') : translate('YEARS')
@ -300,7 +311,7 @@ export class GfAnalysisPageComponent implements OnInit {
: translate('MONTHS'); : translate('MONTHS');
this.unitLongestStreak = this.unitLongestStreak =
this.mode() === 'year' this.investmentGroupBy() === 'year'
? this.streaks?.longestStreak === 1 ? this.streaks?.longestStreak === 1
? translate('YEAR') ? translate('YEAR')
: translate('YEARS') : translate('YEARS')

12
apps/client/src/app/pages/portfolio/analysis/analysis-page.html

@ -508,10 +508,10 @@
</div> </div>
<gf-toggle <gf-toggle
class="d-none d-lg-block" class="d-none d-lg-block"
[defaultValue]="mode()" [defaultValue]="investmentGroupBy()"
[isLoading]="false" [isLoading]="false"
[options]="modeOptions" [options]="modeOptions"
(valueChange)="onChangeGroupBy($event.value)" (valueChange)="onChangeInvestmentGroupBy($event.value)"
/> />
</div> </div>
@if (streaks) { @if (streaks) {
@ -543,7 +543,7 @@
[benchmarkDataLabel]="investmentTimelineDataLabel" [benchmarkDataLabel]="investmentTimelineDataLabel"
[colorScheme]="user?.settings?.colorScheme" [colorScheme]="user?.settings?.colorScheme"
[currency]="user?.settings?.baseCurrency" [currency]="user?.settings?.baseCurrency"
[groupBy]="mode()" [groupBy]="investmentGroupBy()"
[isInPercentage]="showValuesInPercentage()" [isInPercentage]="showValuesInPercentage()"
[isLoading]="isLoadingInvestmentTimelineChart" [isLoading]="isLoadingInvestmentTimelineChart"
[locale]="user?.settings?.locale" [locale]="user?.settings?.locale"
@ -566,10 +566,10 @@
</div> </div>
<gf-toggle <gf-toggle
class="d-none d-lg-block" class="d-none d-lg-block"
[defaultValue]="mode()" [defaultValue]="dividendGroupBy()"
[isLoading]="false" [isLoading]="false"
[options]="modeOptions" [options]="modeOptions"
(valueChange)="onChangeGroupBy($event.value)" (valueChange)="onChangeDividendGroupBy($event.value)"
/> />
</div> </div>
<div class="chart-container"> <div class="chart-container">
@ -579,7 +579,7 @@
[benchmarkDataLabel]="dividendTimelineDataLabel" [benchmarkDataLabel]="dividendTimelineDataLabel"
[colorScheme]="user?.settings?.colorScheme" [colorScheme]="user?.settings?.colorScheme"
[currency]="user?.settings?.baseCurrency" [currency]="user?.settings?.baseCurrency"
[groupBy]="mode()" [groupBy]="dividendGroupBy()"
[isInPercentage]="showValuesInPercentage()" [isInPercentage]="showValuesInPercentage()"
[isLoading]="isLoadingDividendTimelineChart" [isLoading]="isLoadingDividendTimelineChart"
[locale]="user?.settings?.locale" [locale]="user?.settings?.locale"

Loading…
Cancel
Save