From 646ee7271a27dce5309d3829ed654baefcaf7518 Mon Sep 17 00:00:00 2001 From: David Requeno <108202767+DavidReque@users.noreply.github.com> Date: Fri, 12 Dec 2025 13:22:24 -0600 Subject: [PATCH] Bugfix/allocate remaining percentage to unknown data in portfolio proportion chart (#6054) * Allocate remaining percentage to unknown data in portfolio proportion chart * Update changelog --- CHANGELOG.md | 4 +++ .../portfolio-proportion-chart.component.ts | 26 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ceb94a11..f86d7c01a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved the notification module to `@ghostfolio/ui` - Improved the language localization for German (`de`) +### Fixed + +- Fixed a calculation issue that resulted in the incorrect assignment of unknown data in the portfolio proportion chart component + ## 2.222.0 - 2025-12-07 ### Added diff --git a/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts b/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts index 2d8a03ac0..fb11897eb 100644 --- a/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts +++ b/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts @@ -1,6 +1,6 @@ import { getTooltipOptions } from '@ghostfolio/common/chart-helper'; import { UNKNOWN_KEY } from '@ghostfolio/common/config'; -import { getLocale, getTextColor } from '@ghostfolio/common/helper'; +import { getLocale, getSum, getTextColor } from '@ghostfolio/common/helper'; import { AssetProfileIdentifier, PortfolioPosition @@ -193,6 +193,30 @@ export class GfPortfolioProportionChartComponent }); } + if (this.isInPercent) { + const totalValueInPercentage = getSum( + Object.values(chartData).map(({ value }) => { + return value; + }) + ); + + const unknownValueInPercentage = new Big(1).minus(totalValueInPercentage); + + if (unknownValueInPercentage.gt(0)) { + // If total is below 100%, allocate the remaining percentage to UNKNOWN_KEY + if (chartData[UNKNOWN_KEY]) { + chartData[UNKNOWN_KEY].value = chartData[UNKNOWN_KEY].value.plus( + unknownValueInPercentage + ); + } else { + chartData[UNKNOWN_KEY] = { + name: UNKNOWN_KEY, + value: unknownValueInPercentage + }; + } + } + } + let chartDataSorted = Object.entries(chartData) .sort((a, b) => { return a[1].value.minus(b[1].value).toNumber();