Browse Source

refactoring

pull/6054/head
David Requeno 2 weeks ago
parent
commit
9b6237702b
  1. 23
      libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts

23
libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts

@ -1,6 +1,6 @@
import { getTooltipOptions } from '@ghostfolio/common/chart-helper'; import { getTooltipOptions } from '@ghostfolio/common/chart-helper';
import { UNKNOWN_KEY } from '@ghostfolio/common/config'; import { UNKNOWN_KEY } from '@ghostfolio/common/config';
import { getLocale, getTextColor } from '@ghostfolio/common/helper'; import { getLocale, getSum, getTextColor } from '@ghostfolio/common/helper';
import { import {
AssetProfileIdentifier, AssetProfileIdentifier,
PortfolioPosition PortfolioPosition
@ -196,22 +196,23 @@ export class GfPortfolioProportionChartComponent
// If data is in percent format and total is less than 100%, // If data is in percent format and total is less than 100%,
// allocate the remaining percentage to UNKNOWN_KEY // allocate the remaining percentage to UNKNOWN_KEY
if (this.isInPercent) { if (this.isInPercent) {
let totalValue = new Big(0); const totalValueInPercentage = getSum(
Object.values(chartData).map(({ value }) => {
for (const symbol in chartData) { return value;
totalValue = totalValue.plus(chartData[symbol].value); })
} );
const remainingPercentage = new Big(1).minus(totalValue); const unknownValueInPercentage = new Big(1).minus(totalValueInPercentage);
if (remainingPercentage.gt(0)) { if (unknownValueInPercentage.gt(0)) {
if (chartData[UNKNOWN_KEY]) { if (chartData[UNKNOWN_KEY]) {
chartData[UNKNOWN_KEY].value = chartData[UNKNOWN_KEY].value = chartData[UNKNOWN_KEY].value.plus(
chartData[UNKNOWN_KEY].value.plus(remainingPercentage); unknownValueInPercentage
);
} else { } else {
chartData[UNKNOWN_KEY] = { chartData[UNKNOWN_KEY] = {
name: UNKNOWN_KEY, name: UNKNOWN_KEY,
value: remainingPercentage value: unknownValueInPercentage
}; };
} }
} }

Loading…
Cancel
Save