|
|
|
@ -51,10 +51,11 @@ import { IonIcon } from '@ionic/angular/standalone'; |
|
|
|
import { SymbolProfile } from '@prisma/client'; |
|
|
|
import { addIcons } from 'ionicons'; |
|
|
|
import { copyOutline, ellipsisVertical } from 'ionicons/icons'; |
|
|
|
import { isNumber, sortBy } from 'lodash'; |
|
|
|
import { isNumber, keyBy, sortBy, union } from 'lodash'; |
|
|
|
import ms from 'ms'; |
|
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
|
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
|
import { forkJoin } from 'rxjs'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
|
@ -254,32 +255,51 @@ export class GfAnalysisPageComponent implements OnInit { |
|
|
|
this.isLoadingDividendTimelineChart = true; |
|
|
|
this.isLoadingInvestmentTimelineChart = true; |
|
|
|
|
|
|
|
this.dataService |
|
|
|
.fetchDividends({ |
|
|
|
forkJoin({ |
|
|
|
dividends: this.dataService.fetchDividends({ |
|
|
|
filters: this.userService.getFilters(), |
|
|
|
groupBy: this.mode(), |
|
|
|
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE |
|
|
|
}), |
|
|
|
investments: this.dataService.fetchInvestments({ |
|
|
|
filters: this.userService.getFilters(), |
|
|
|
groupBy: this.mode(), |
|
|
|
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE |
|
|
|
}) |
|
|
|
}) |
|
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
|
.subscribe(({ dividends }) => { |
|
|
|
this.dividendsByGroup = dividends; |
|
|
|
.subscribe( |
|
|
|
({ |
|
|
|
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)) |
|
|
|
); |
|
|
|
|
|
|
|
this.isLoadingDividendTimelineChart = false; |
|
|
|
this.dividendsByGroup = dates.map((date) => { |
|
|
|
return { |
|
|
|
date, |
|
|
|
investment: dividendByDate[date]?.investment ?? 0 |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
this.investmentsByGroup = dates.map((date) => { |
|
|
|
return { |
|
|
|
date, |
|
|
|
investment: investmentByDate[date]?.investment ?? 0 |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
this.dataService |
|
|
|
.fetchInvestments({ |
|
|
|
filters: this.userService.getFilters(), |
|
|
|
groupBy: this.mode(), |
|
|
|
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE |
|
|
|
}) |
|
|
|
.pipe(takeUntilDestroyed(this.destroyRef)) |
|
|
|
.subscribe(({ investments, savingsRate, streaks }) => { |
|
|
|
this.investmentsByGroup = investments; |
|
|
|
this.savingsRatePerMonth = savingsRate; |
|
|
|
this.streaks = streaks; |
|
|
|
|
|
|
|
this.unitCurrentStreak = |
|
|
|
this.mode() === 'year' |
|
|
|
? this.streaks?.currentStreak === 1 |
|
|
|
@ -288,6 +308,7 @@ export class GfAnalysisPageComponent implements OnInit { |
|
|
|
: this.streaks?.currentStreak === 1 |
|
|
|
? translate('MONTH') |
|
|
|
: translate('MONTHS'); |
|
|
|
|
|
|
|
this.unitLongestStreak = |
|
|
|
this.mode() === 'year' |
|
|
|
? this.streaks?.longestStreak === 1 |
|
|
|
@ -297,10 +318,12 @@ export class GfAnalysisPageComponent implements OnInit { |
|
|
|
? translate('MONTH') |
|
|
|
: translate('MONTHS'); |
|
|
|
|
|
|
|
this.isLoadingDividendTimelineChart = false; |
|
|
|
this.isLoadingInvestmentTimelineChart = false; |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private update() { |
|
|
|
|