From 768dc16727572ae4b93b76a538f9b8a6d4f8b7c0 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sat, 15 Oct 2022 16:28:00 +0200 Subject: [PATCH] Refactoring --- .../src/app/portfolio/portfolio.controller.ts | 23 ++++++++- .../src/app/portfolio/portfolio.service.ts | 7 ++- .../benchmark-comparator.component.html | 10 +--- .../benchmark-comparator.component.ts | 8 --- .../benchmark-comparator.module.ts | 2 - .../investment-chart.component.ts | 2 +- .../analysis/analysis-page.component.ts | 9 ++-- .../portfolio/analysis/analysis-page.html | 49 ++++++++++++++----- apps/client/src/locales/messages.de.xlf | 44 ++++++++++------- apps/client/src/locales/messages.es.xlf | 44 ++++++++++------- apps/client/src/locales/messages.it.xlf | 44 ++++++++++------- apps/client/src/locales/messages.nl.xlf | 44 ++++++++++------- apps/client/src/locales/messages.xlf | 41 +++++++++------- .../portfolio-performance.interface.ts | 1 + 14 files changed, 199 insertions(+), 129 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 946f7090e..abff3a420 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -38,6 +38,7 @@ import { } from '@nestjs/common'; import { REQUEST } from '@nestjs/core'; import { AuthGuard } from '@nestjs/passport'; +import Big from 'big.js'; import { StatusCodes, getReasonPhrase } from 'http-status-codes'; import { PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface'; @@ -249,9 +250,29 @@ export class PortfolioController { this.request.user.Settings.settings.viewMode === 'ZEN' || this.userService.isRestrictedView(this.request.user) ) { + performanceInformation.chart = performanceInformation.chart.map( + ({ date, netPerformanceInPercentage, totalInvestment, value }) => { + return { + date, + netPerformanceInPercentage, + totalInvestment: new Big(totalInvestment) + .div(performanceInformation.performance.totalInvestment) + .toNumber(), + value: new Big(value) + .div(performanceInformation.performance.currentValue) + .toNumber() + }; + } + ); + performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance, - ['currentGrossPerformance', 'currentNetPerformance', 'currentValue'] + [ + 'currentGrossPerformance', + 'currentNetPerformance', + 'currentValue', + 'totalInvestment' + ] ); } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 80c556424..1a22f8f4b 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -911,7 +911,8 @@ export class PortfolioService { currentGrossPerformancePercent: 0, currentNetPerformance: 0, currentNetPerformancePercent: 0, - currentValue: 0 + currentValue: 0, + totalInvestment: 0 } }; } @@ -932,6 +933,7 @@ export class PortfolioService { let currentNetPerformance = currentPositions.netPerformance; let currentNetPerformancePercent = currentPositions.netPerformancePercentage; + const totalInvestment = currentPositions.totalInvestment; // if (currentGrossPerformance.mul(currentGrossPerformancePercent).lt(0)) { // // If algebraic sign is different, harmonize it @@ -986,7 +988,8 @@ export class PortfolioService { currentGrossPerformancePercent: currentGrossPerformancePercent.toNumber(), currentNetPerformance: currentNetPerformance.toNumber(), - currentNetPerformancePercent: currentNetPerformancePercent.toNumber() + currentNetPerformancePercent: currentNetPerformancePercent.toNumber(), + totalInvestment: totalInvestment.toNumber() } }; } diff --git a/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.html b/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.html index 1e5ca601c..95b7e272f 100644 --- a/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.html +++ b/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.html @@ -1,4 +1,4 @@ -
+
Performance @@ -31,14 +31,6 @@
-
- -
(); - @Output() dateRangeChanged = new EventEmitter(); @ViewChild('chartCanvas') chartCanvas; public chart: Chart; - public dateRangeOptions = ToggleComponent.DEFAULT_DATE_RANGE_OPTIONS; public constructor() { Chart.register( @@ -86,10 +82,6 @@ export class BenchmarkComparatorComponent implements OnChanges, OnDestroy { this.benchmarkChanged.next(symbolProfileId); } - public onChangeDateRange(dateRange: DateRange) { - this.dateRangeChanged.next(dateRange); - } - public ngOnDestroy() { this.chart?.destroy(); } diff --git a/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.module.ts b/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.module.ts index bc455ebc2..16440d3a3 100644 --- a/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.module.ts +++ b/apps/client/src/app/components/benchmark-comparator/benchmark-comparator.module.ts @@ -2,7 +2,6 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MatSelectModule } from '@angular/material/select'; -import { GfToggleModule } from '@ghostfolio/client/components/toggle/toggle.module'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { BenchmarkComparatorComponent } from './benchmark-comparator.component'; @@ -13,7 +12,6 @@ import { BenchmarkComparatorComponent } from './benchmark-comparator.component'; imports: [ CommonModule, FormsModule, - GfToggleModule, MatSelectModule, NgxSkeletonLoaderModule, ReactiveFormsModule diff --git a/apps/client/src/app/components/investment-chart/investment-chart.component.ts b/apps/client/src/app/components/investment-chart/investment-chart.component.ts index 2f838a368..cebc0f146 100644 --- a/apps/client/src/app/components/investment-chart/investment-chart.component.ts +++ b/apps/client/src/app/components/investment-chart/investment-chart.component.ts @@ -153,7 +153,7 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy { data: this.benchmarkDataItems.map(({ date, value }) => { return { x: parseDate(date), - y: value + y: this.isInPercent ? value * 100 : value }; }), fill: false, diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts index b89566e02..3b81390d9 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -1,4 +1,5 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; +import { ToggleComponent } from '@ghostfolio/client/components/toggle/toggle.component'; import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; @@ -26,6 +27,7 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { public benchmarkDataItems: HistoricalDataItem[] = []; public benchmarks: Partial[]; public bottom3: Position[]; + public dateRangeOptions = ToggleComponent.DEFAULT_DATE_RANGE_OPTIONS; public daysInMarket: number; public deviceType: string; public firstOrderDate: Date; @@ -33,10 +35,9 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { public investments: InvestmentItem[]; public investmentsByMonth: InvestmentItem[]; public isLoadingBenchmarkComparator: boolean; - public mode: GroupBy; + public mode: GroupBy = 'month'; public modeOptions: ToggleOption[] = [ - { label: $localize`Monthly`, value: 'month' }, - { label: $localize`Accumulating`, value: undefined } + { label: $localize`Monthly`, value: 'month' } ]; public performanceDataItems: HistoricalDataItem[]; public performanceDataItemsInPercentage: HistoricalDataItem[]; @@ -173,7 +174,7 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { }); this.dataService - .fetchPositions({ range: 'max' }) + .fetchPositions({ range: this.user?.settings?.dateRange }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ positions }) => { const positionsSorted = sortBy( diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html index 1ab82f9ad..f4624414f 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html @@ -1,5 +1,13 @@
-

Analysis

+

Analysis

+
+ +
@@ -96,25 +103,18 @@
-
+
- Investment Timeline + Portfolio Evolution
-
+
+
+
+ +
+
+
+
+ Investment Timeline + +
+ +
+
diff --git a/apps/client/src/locales/messages.de.xlf b/apps/client/src/locales/messages.de.xlf index fe4b2d223..0de31b1cd 100644 --- a/apps/client/src/locales/messages.de.xlf +++ b/apps/client/src/locales/messages.de.xlf @@ -1722,7 +1722,7 @@ Zeitstrahl der Investitionen apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 105 + 140 @@ -1730,7 +1730,7 @@ Gewinner apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 26 + 33 @@ -1738,7 +1738,7 @@ Verlierer apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 62 + 69 @@ -2054,7 +2054,7 @@ Portfolio apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 107 + 99 apps/client/src/app/pages/public/public-page-routing.module.ts @@ -2498,15 +2498,7 @@ Monatlich apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 38 - - - - Accumulating - Aufsummiert - - apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 39 + 40 @@ -2514,11 +2506,11 @@ Einlage apps/client/src/app/components/investment-chart/investment-chart.component.ts - 132 + 139 libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 276 + 279 @@ -2526,7 +2518,7 @@ Verzinsung libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 286 + 289 @@ -2534,7 +2526,7 @@ Ersparnisse libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 296 + 299 @@ -2646,7 +2638,7 @@ Benchmark apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 116 + 108 @@ -2721,6 +2713,22 @@ 212 + + Total Amount + Gesamtbetrag + + apps/client/src/app/components/investment-chart/investment-chart.component.ts + 160 + + + + Portfolio Evolution + Portfolio Wertentwicklung + + apps/client/src/app/pages/portfolio/analysis/analysis-page.html + 112 + + diff --git a/apps/client/src/locales/messages.es.xlf b/apps/client/src/locales/messages.es.xlf index 363fb7c2a..493631105 100644 --- a/apps/client/src/locales/messages.es.xlf +++ b/apps/client/src/locales/messages.es.xlf @@ -1723,7 +1723,7 @@ Cronología de la inversión apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 105 + 140 @@ -1731,7 +1731,7 @@ Lo mejor apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 26 + 33 @@ -1739,7 +1739,7 @@ Lo peor apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 62 + 69 @@ -2055,7 +2055,7 @@ Cartera apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 107 + 99 apps/client/src/app/pages/public/public-page-routing.module.ts @@ -2483,15 +2483,7 @@ Ahorros libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 296 - - - - Accumulating - Acumulando - - apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 39 + 299 @@ -2507,7 +2499,7 @@ Interés libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 286 + 289 @@ -2515,11 +2507,11 @@ Depósito apps/client/src/app/components/investment-chart/investment-chart.component.ts - 132 + 139 libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 276 + 279 @@ -2535,7 +2527,7 @@ Mensual apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 38 + 40 @@ -2631,7 +2623,7 @@ Benchmark apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 116 + 108 @@ -2722,6 +2714,22 @@ 212 + + Total Amount + Total Amount + + apps/client/src/app/components/investment-chart/investment-chart.component.ts + 160 + + + + Portfolio Evolution + Portfolio Evolution + + apps/client/src/app/pages/portfolio/analysis/analysis-page.html + 112 + + diff --git a/apps/client/src/locales/messages.it.xlf b/apps/client/src/locales/messages.it.xlf index acde0f426..3170073ac 100644 --- a/apps/client/src/locales/messages.it.xlf +++ b/apps/client/src/locales/messages.it.xlf @@ -1723,7 +1723,7 @@ Cronologia degli investimenti apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 105 + 140 @@ -1731,7 +1731,7 @@ In alto apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 26 + 33 @@ -1739,7 +1739,7 @@ In basso apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 62 + 69 @@ -2055,7 +2055,7 @@ Portafoglio apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 107 + 99 apps/client/src/app/pages/public/public-page-routing.module.ts @@ -2483,15 +2483,7 @@ Risparmio libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 296 - - - - Accumulating - Accumulo - - apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 39 + 299 @@ -2507,7 +2499,7 @@ Interesse libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 286 + 289 @@ -2515,11 +2507,11 @@ Deposito apps/client/src/app/components/investment-chart/investment-chart.component.ts - 132 + 139 libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 276 + 279 @@ -2535,7 +2527,7 @@ Mensile apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 38 + 40 @@ -2631,7 +2623,7 @@ Benchmark apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 116 + 108 @@ -2722,6 +2714,22 @@ 212 + + Total Amount + Total Amount + + apps/client/src/app/components/investment-chart/investment-chart.component.ts + 160 + + + + Portfolio Evolution + Portfolio Evolution + + apps/client/src/app/pages/portfolio/analysis/analysis-page.html + 112 + + diff --git a/apps/client/src/locales/messages.nl.xlf b/apps/client/src/locales/messages.nl.xlf index 70bac87e0..bb45a5fd9 100644 --- a/apps/client/src/locales/messages.nl.xlf +++ b/apps/client/src/locales/messages.nl.xlf @@ -1722,7 +1722,7 @@ Tijdlijn investeringen apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 105 + 140 @@ -1730,7 +1730,7 @@ Top apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 26 + 33 @@ -1738,7 +1738,7 @@ Onder apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 62 + 69 @@ -2054,7 +2054,7 @@ Portefeuille apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 107 + 99 apps/client/src/app/pages/public/public-page-routing.module.ts @@ -2482,15 +2482,7 @@ Besparingen libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 296 - - - - Accumulating - Accumuleren - - apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 39 + 299 @@ -2506,7 +2498,7 @@ Rente libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 286 + 289 @@ -2514,11 +2506,11 @@ Storting apps/client/src/app/components/investment-chart/investment-chart.component.ts - 132 + 139 libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 276 + 279 @@ -2534,7 +2526,7 @@ Maandelijks apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 38 + 40 @@ -2630,7 +2622,7 @@ Benchmark apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 116 + 108 @@ -2721,6 +2713,22 @@ 212 + + Total Amount + Total Amount + + apps/client/src/app/components/investment-chart/investment-chart.component.ts + 160 + + + + Portfolio Evolution + Portfolio Evolution + + apps/client/src/app/pages/portfolio/analysis/analysis-page.html + 112 + + diff --git a/apps/client/src/locales/messages.xlf b/apps/client/src/locales/messages.xlf index e8620fc8d..a9003dc11 100644 --- a/apps/client/src/locales/messages.xlf +++ b/apps/client/src/locales/messages.xlf @@ -1547,21 +1547,21 @@ Investment Timeline apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 105 + 140 Top apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 26 + 33 Bottom apps/client/src/app/pages/portfolio/analysis/analysis-page.html - 62 + 69 @@ -1842,7 +1842,7 @@ Portfolio apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 107 + 99 apps/client/src/app/pages/public/public-page-routing.module.ts @@ -2220,14 +2220,7 @@ Savings libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 296 - - - - Accumulating - - apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 39 + 299 @@ -2241,18 +2234,18 @@ Interest libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 286 + 289 Deposit apps/client/src/app/components/investment-chart/investment-chart.component.ts - 132 + 139 libs/ui/src/lib/fire-calculator/fire-calculator.component.ts - 276 + 279 @@ -2266,7 +2259,7 @@ Monthly apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts - 38 + 40 @@ -2351,7 +2344,7 @@ Benchmark apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts - 116 + 108 @@ -2431,6 +2424,20 @@ 195 + + Total Amount + + apps/client/src/app/components/investment-chart/investment-chart.component.ts + 160 + + + + Portfolio Evolution + + apps/client/src/app/pages/portfolio/analysis/analysis-page.html + 112 + + diff --git a/libs/common/src/lib/interfaces/portfolio-performance.interface.ts b/libs/common/src/lib/interfaces/portfolio-performance.interface.ts index 670d69018..5a4f91023 100644 --- a/libs/common/src/lib/interfaces/portfolio-performance.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-performance.interface.ts @@ -5,4 +5,5 @@ export interface PortfolioPerformance { currentNetPerformance: number; currentNetPerformancePercent: number; currentValue: number; + totalInvestment: number; }