Browse Source

Fix negative zero

pull/8043/head
Thomas Kaul 2 weeks ago
parent
commit
0891533584
  1. 44
      libs/ui/src/lib/treemap-chart/treemap-chart.component.ts

44
libs/ui/src/lib/treemap-chart/treemap-chart.component.ts

@ -186,6 +186,18 @@ export class GfTreemapChartComponent
return dataset[activeElement.index]; return dataset[activeElement.index];
} }
private getRoundedValue({
precision,
value
}: {
precision: number;
value: number;
}) {
const roundedValue = round(value, precision);
return roundedValue === 0 ? 0 : roundedValue;
}
private initialize() { private initialize() {
const holdings = this.holdings(); const holdings = this.holdings();
@ -314,16 +326,11 @@ export class GfTreemapChartComponent
formatter: (context: GfTreemapScriptableContext) => { formatter: (context: GfTreemapScriptableContext) => {
const raw = context.raw as GfTreemapDataPoint; const raw = context.raw as GfTreemapDataPoint;
let netPerformancePercentWithCurrencyEffect = round( const netPerformancePercentWithCurrencyEffect =
raw._data.netPerformancePercentWithCurrencyEffect, this.getRoundedValue({
4 precision: 4,
); value: raw._data.netPerformancePercentWithCurrencyEffect
});
if (Math.abs(netPerformancePercentWithCurrencyEffect) === 0) {
netPerformancePercentWithCurrencyEffect = Math.abs(
netPerformancePercentWithCurrencyEffect
);
}
const name = raw._data.assetProfile.name; const name = raw._data.assetProfile.name;
const symbol = raw._data.assetProfile.symbol; const symbol = raw._data.assetProfile.symbol;
@ -405,12 +412,21 @@ export class GfTreemapChartComponent
const allocationInPercentage = `${(raw._data.allocationInPercentage * 100).toFixed(2)}%`; const allocationInPercentage = `${(raw._data.allocationInPercentage * 100).toFixed(2)}%`;
const name = getHoldingName(raw._data.assetProfile); const name = getHoldingName(raw._data.assetProfile);
const sign = const netPerformancePercentWithCurrencyEffect = this.getRoundedValue({
raw._data.netPerformancePercentWithCurrencyEffect > 0 ? '+' : ''; precision: 4,
value: raw._data.netPerformancePercentWithCurrencyEffect
});
const sign = netPerformancePercentWithCurrencyEffect > 0 ? '+' : '';
const netPerformanceInPercentageWithSign = `${sign}${(raw._data.netPerformancePercentWithCurrencyEffect * 100).toFixed(2)}%`; const netPerformanceInPercentageWithSign = `${sign}${(netPerformancePercentWithCurrencyEffect * 100).toFixed(2)}%`;
if (raw._data.valueInBaseCurrency !== null) { if (raw._data.valueInBaseCurrency !== null) {
const netPerformanceWithCurrencyEffect = this.getRoundedValue({
precision: 2,
value: raw._data.netPerformanceWithCurrencyEffect
});
const value = raw._data.valueInBaseCurrency; const value = raw._data.valueInBaseCurrency;
return [ return [
@ -421,7 +437,7 @@ export class GfTreemapChartComponent
})} ${this.baseCurrency()}`, })} ${this.baseCurrency()}`,
'', '',
$localize`Change` + ' (' + $localize`Performance` + ')', $localize`Change` + ' (' + $localize`Performance` + ')',
`${sign}${raw._data.netPerformanceWithCurrencyEffect.toLocaleString( `${sign}${netPerformanceWithCurrencyEffect.toLocaleString(
this.locale(), this.locale(),
{ {
maximumFractionDigits: 2, maximumFractionDigits: 2,

Loading…
Cancel
Save