Browse Source

Task/align x-axis of dividend and investment timeline charts on analysis page (#7570)

* Align x-axis of dividend and investment timeline charts

* Update changelog
pull/7557/merge
Thomas Kaul 11 hours ago
committed by GitHub
parent
commit
dbe6a3f65f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 101
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

1
CHANGELOG.md

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Aligned the x-axis of the dividend and investment timeline charts on the analysis page
- Improved the check for duplicates in the preview step of the activities import (regardless of the account) - Improved the check for duplicates in the preview step of the activities import (regardless of the account)
- Improved the check for duplicates in the preview step of the import dividends dialog (regardless of the account) - Improved the check for duplicates in the preview step of the import dividends dialog (regardless of the account)
- Extended the activities import to reuse an existing account of the user by name and currency - Extended the activities import to reuse an existing account of the user by name and currency

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

@ -51,10 +51,11 @@ import { IonIcon } from '@ionic/angular/standalone';
import { SymbolProfile } from '@prisma/client'; import { SymbolProfile } from '@prisma/client';
import { addIcons } from 'ionicons'; import { addIcons } from 'ionicons';
import { copyOutline, ellipsisVertical } from 'ionicons/icons'; import { copyOutline, ellipsisVertical } from 'ionicons/icons';
import { isNumber, sortBy } from 'lodash'; import { isNumber, keyBy, sortBy, union } from 'lodash';
import ms from 'ms'; import ms from 'ms';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { forkJoin } from 'rxjs';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
@ -254,53 +255,75 @@ export class GfAnalysisPageComponent implements OnInit {
this.isLoadingDividendTimelineChart = true; this.isLoadingDividendTimelineChart = true;
this.isLoadingInvestmentTimelineChart = true; this.isLoadingInvestmentTimelineChart = true;
this.dataService forkJoin({
.fetchDividends({ dividends: this.dataService.fetchDividends({
filters: this.userService.getFilters(), filters: this.userService.getFilters(),
groupBy: this.mode(), groupBy: this.mode(),
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE
}) }),
.pipe(takeUntilDestroyed(this.destroyRef)) investments: this.dataService.fetchInvestments({
.subscribe(({ dividends }) => {
this.dividendsByGroup = dividends;
this.isLoadingDividendTimelineChart = false;
this.changeDetectorRef.markForCheck();
});
this.dataService
.fetchInvestments({
filters: this.userService.getFilters(), filters: this.userService.getFilters(),
groupBy: this.mode(), groupBy: this.mode(),
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE
}) })
})
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ investments, savingsRate, streaks }) => { .subscribe(
this.investmentsByGroup = investments; ({
this.savingsRatePerMonth = savingsRate; dividends: { dividends },
this.streaks = streaks; investments: { investments, savingsRate, streaks }
this.unitCurrentStreak = }) => {
this.mode() === 'year' // Expand both timelines to the union of their groups so that the
? this.streaks?.currentStreak === 1 // charts share the same axis, independent of whether a dividend or
? translate('YEAR') // an investment has been tracked in a given group
: translate('YEARS') const dividendByDate = keyBy(dividends, 'date');
: this.streaks?.currentStreak === 1 const investmentByDate = keyBy(investments, 'date');
? translate('MONTH')
: translate('MONTHS'); const dates = sortBy(
this.unitLongestStreak = union(Object.keys(dividendByDate), Object.keys(investmentByDate))
this.mode() === 'year' );
? this.streaks?.longestStreak === 1
? translate('YEAR')
: translate('YEARS')
: this.streaks?.longestStreak === 1
? translate('MONTH')
: translate('MONTHS');
this.isLoadingInvestmentTimelineChart = false;
this.changeDetectorRef.markForCheck(); 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.savingsRatePerMonth = savingsRate;
this.streaks = streaks;
this.unitCurrentStreak =
this.mode() === 'year'
? this.streaks?.currentStreak === 1
? translate('YEAR')
: translate('YEARS')
: this.streaks?.currentStreak === 1
? translate('MONTH')
: translate('MONTHS');
this.unitLongestStreak =
this.mode() === 'year'
? this.streaks?.longestStreak === 1
? translate('YEAR')
: translate('YEARS')
: this.streaks?.longestStreak === 1
? translate('MONTH')
: translate('MONTHS');
this.isLoadingDividendTimelineChart = false;
this.isLoadingInvestmentTimelineChart = false;
this.changeDetectorRef.markForCheck();
}
);
} }
private update() { private update() {

Loading…
Cancel
Save