Browse Source

Merge 548dfc1804 into 618e6c9d27

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

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

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

Loading…
Cancel
Save