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
+
+