Browse Source

Improve numerical precision in holding detail dialog

pull/3584/head
Thomas Kaul 1 year ago
parent
commit
176f127dd6
  1. 58
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
  2. 4
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html
  3. 2
      libs/common/src/lib/config.ts
  4. 25
      libs/ui/src/lib/value/value.component.ts

58
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts

@ -4,6 +4,7 @@ import { GfDialogFooterModule } from '@ghostfolio/client/components/dialog-foote
import { GfDialogHeaderModule } from '@ghostfolio/client/components/dialog-header/dialog-header.module';
import { DataService } from '@ghostfolio/client/services/data.service';
import { UserService } from '@ghostfolio/client/services/user/user.service';
import { NUMERICAL_PRECISION_THRESHOLD } from '@ghostfolio/common/config';
import { DATE_FORMAT, downloadAsFile } from '@ghostfolio/common/helper';
import {
DataProviderInfo,
@ -84,18 +85,22 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
public dataProviderInfo: DataProviderInfo;
public dataSource: MatTableDataSource<Activity>;
public dividendInBaseCurrency: number;
public dividendInBaseCurrencyPrecision = 2;
public dividendYieldPercentWithCurrencyEffect: number;
public feeInBaseCurrency: number;
public firstBuyDate: string;
public historicalDataItems: LineChartItem[];
public investment: number;
public investmentPrecision = 2;
public marketPrice: number;
public maxPrice: number;
public minPrice: number;
public netPerformance: number;
public netPerformancePrecision = 2;
public netPerformancePercent: number;
public netPerformancePercentWithCurrencyEffect: number;
public netPerformanceWithCurrencyEffect: number;
public netPerformanceWithCurrencyEffectPrecision = 2;
public quantity: number;
public quantityPrecision = 2;
public reportDataGlitchMail: string;
@ -161,10 +166,17 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
this.dataProviderInfo = dataProviderInfo;
this.dataSource = new MatTableDataSource(orders.reverse());
this.dividendInBaseCurrency = dividendInBaseCurrency;
if (this.dividendInBaseCurrency >= NUMERICAL_PRECISION_THRESHOLD) {
this.dividendInBaseCurrencyPrecision = 0;
}
this.dividendYieldPercentWithCurrencyEffect =
dividendYieldPercentWithCurrencyEffect;
this.feeInBaseCurrency = feeInBaseCurrency;
this.firstBuyDate = firstBuyDate;
this.historicalDataItems = historicalData.map(
({ averagePrice, date, marketPrice }) => {
this.benchmarkDataItems.push({
@ -178,17 +190,51 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
};
}
);
this.investment = investment;
if (this.investment >= NUMERICAL_PRECISION_THRESHOLD) {
this.investmentPrecision = 0;
}
this.marketPrice = marketPrice;
this.maxPrice = maxPrice;
this.minPrice = minPrice;
this.netPerformance = netPerformance;
if (this.netPerformance >= NUMERICAL_PRECISION_THRESHOLD) {
this.netPerformancePrecision = 0;
}
this.netPerformancePercent = netPerformancePercent;
this.netPerformancePercentWithCurrencyEffect =
netPerformancePercentWithCurrencyEffect;
this.netPerformanceWithCurrencyEffect =
netPerformanceWithCurrencyEffect;
if (
this.netPerformanceWithCurrencyEffect >=
NUMERICAL_PRECISION_THRESHOLD
) {
this.netPerformanceWithCurrencyEffectPrecision = 0;
}
this.quantity = quantity;
if (Number.isInteger(this.quantity)) {
this.quantityPrecision = 0;
} else if (this.SymbolProfile?.assetSubClass === 'CRYPTOCURRENCY') {
if (this.quantity < 1) {
this.quantityPrecision = 7;
} else if (this.quantity < 1000) {
this.quantityPrecision = 5;
} else if (this.quantity >= 10000000) {
this.quantityPrecision = 0;
}
}
this.reportDataGlitchMail = `mailto:hi@ghostfol.io?Subject=Ghostfolio Data Glitch Report&body=Hello%0D%0DI would like to report a data glitch for%0D%0DSymbol: ${SymbolProfile?.symbol}%0DData Source: ${SymbolProfile?.dataSource}%0D%0DAdditional notes:%0D%0DCan you please take a look?%0D%0DKind regards`;
this.sectors = {};
this.SymbolProfile = SymbolProfile;
@ -282,18 +328,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
}
);
if (Number.isInteger(this.quantity)) {
this.quantityPrecision = 0;
} else if (this.SymbolProfile?.assetSubClass === 'CRYPTOCURRENCY') {
if (this.quantity < 1) {
this.quantityPrecision = 7;
} else if (this.quantity < 1000) {
this.quantityPrecision = 5;
} else if (this.quantity > 10000000) {
this.quantityPrecision = 0;
}
}
this.changeDetectorRef.markForCheck();
}
);

4
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html

@ -47,6 +47,7 @@
[colorizeSign]="true"
[isCurrency]="true"
[locale]="data.locale"
[precision]="netPerformanceWithCurrencyEffectPrecision"
[unit]="data.baseCurrency"
[value]="netPerformanceWithCurrencyEffect"
>Change with currency effect</gf-value
@ -58,6 +59,7 @@
[colorizeSign]="true"
[isCurrency]="true"
[locale]="data.locale"
[precision]="netPerformancePrecision"
[unit]="data.baseCurrency"
[value]="netPerformance"
>Change</gf-value
@ -160,6 +162,7 @@
size="medium"
[isCurrency]="true"
[locale]="data.locale"
[precision]="investmentPrecision"
[unit]="data.baseCurrency"
[value]="investment"
>Investment</gf-value
@ -172,6 +175,7 @@
size="medium"
[isCurrency]="true"
[locale]="data.locale"
[precision]="dividendInBaseCurrencyPrecision"
[unit]="data.baseCurrency"
[value]="dividendInBaseCurrency"
>Dividend</gf-value

2
libs/common/src/lib/config.ts

@ -91,6 +91,8 @@ export const HEADER_KEY_TOKEN = 'Authorization';
export const MAX_CHART_ITEMS = 365;
export const MAX_TOP_HOLDINGS = 50;
export const NUMERICAL_PRECISION_THRESHOLD = 100000;
export const PROPERTY_BENCHMARKS = 'BENCHMARKS';
export const PROPERTY_BETTER_UPTIME_MONITOR_ID = 'BETTER_UPTIME_MONITOR_ID';
export const PROPERTY_COUNTRIES_OF_SUBSCRIBERS = 'COUNTRIES_OF_SUBSCRIBERS';

25
libs/ui/src/lib/value/value.component.ts

@ -58,8 +58,8 @@ export class GfValueComponent implements OnChanges {
this.formattedValue = this.absoluteValue.toLocaleString(
this.locale,
{
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
}
);
} catch {}
@ -68,8 +68,8 @@ export class GfValueComponent implements OnChanges {
this.formattedValue = (this.absoluteValue * 100).toLocaleString(
this.locale,
{
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
}
);
} catch {}
@ -77,8 +77,8 @@ export class GfValueComponent implements OnChanges {
} else if (this.isCurrency) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: 2,
minimumFractionDigits: 2
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
});
} catch {}
} else if (this.isPercent) {
@ -86,17 +86,10 @@ export class GfValueComponent implements OnChanges {
this.formattedValue = (this.value * 100).toLocaleString(
this.locale,
{
maximumFractionDigits: 2,
minimumFractionDigits: 2
}
);
} catch {}
} else if (this.precision || this.precision === 0) {
try {
this.formattedValue = this.value?.toLocaleString(this.locale, {
maximumFractionDigits: this.precision,
minimumFractionDigits: this.precision
});
}
);
} catch {}
} else {
this.formattedValue = this.value?.toLocaleString(this.locale);
@ -136,6 +129,8 @@ export class GfValueComponent implements OnChanges {
this.isNumber = false;
this.isString = false;
this.locale = this.locale || getLocale();
this.precision =
this.precision || this.precision === 0 ? this.precision : 2;
this.useAbsoluteValue = false;
}
}

Loading…
Cancel
Save