Browse Source

Feature/improve label in treemap chart for asset profiles with MANUAL data source (#5128)

* Improve label

* Update changelog
pull/5116/head^2
Thomas Kaul 2 weeks ago
committed by GitHub
parent
commit
96b4e11126
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 42
      libs/ui/src/lib/treemap-chart/treemap-chart.component.ts

1
CHANGELOG.md

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the label for asset profiles with `MANUAL` data source in the chart of the holdings tab on the home page
- Improved the language localization for Catalan (`ca`) - Improved the language localization for Catalan (`ca`)
## 2.179.0 - 2025-07-07 ## 2.179.0 - 2025-07-07

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

@ -29,6 +29,7 @@ import { ChartConfiguration } from 'chart.js';
import { LinearScale } from 'chart.js'; import { LinearScale } from 'chart.js';
import { Chart, Tooltip } from 'chart.js'; import { Chart, Tooltip } from 'chart.js';
import { TreemapController, TreemapElement } from 'chartjs-chart-treemap'; import { TreemapController, TreemapElement } from 'chartjs-chart-treemap';
import { isUUID } from 'class-validator';
import { differenceInDays, max } from 'date-fns'; import { differenceInDays, max } from 'date-fns';
import { orderBy } from 'lodash'; import { orderBy } from 'lodash';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
@ -199,18 +200,18 @@ export class GfTreemapChartComponent
const data: ChartConfiguration<'treemap'>['data'] = { const data: ChartConfiguration<'treemap'>['data'] = {
datasets: [ datasets: [
{ {
backgroundColor: (ctx) => { backgroundColor: (context) => {
let annualizedNetPerformancePercent = let annualizedNetPerformancePercent =
getAnnualizedPerformancePercent({ getAnnualizedPerformancePercent({
daysInMarket: differenceInDays( daysInMarket: differenceInDays(
endDate, endDate,
max([ max([
ctx.raw._data.dateOfFirstActivity ?? new Date(0), context.raw._data.dateOfFirstActivity ?? new Date(0),
startDate startDate
]) ])
), ),
netPerformancePercentage: new Big( netPerformancePercentage: new Big(
ctx.raw._data.netPerformancePercentWithCurrencyEffect context.raw._data.netPerformancePercentWithCurrencyEffect
) )
}).toNumber(); }).toNumber();
@ -230,18 +231,18 @@ export class GfTreemapChartComponent
key: 'allocationInPercentage', key: 'allocationInPercentage',
labels: { labels: {
align: 'left', align: 'left',
color: (ctx) => { color: (context) => {
let annualizedNetPerformancePercent = let annualizedNetPerformancePercent =
getAnnualizedPerformancePercent({ getAnnualizedPerformancePercent({
daysInMarket: differenceInDays( daysInMarket: differenceInDays(
endDate, endDate,
max([ max([
ctx.raw._data.dateOfFirstActivity ?? new Date(0), context.raw._data.dateOfFirstActivity ?? new Date(0),
startDate startDate
]) ])
), ),
netPerformancePercentage: new Big( netPerformancePercentage: new Big(
ctx.raw._data.netPerformancePercentWithCurrencyEffect context.raw._data.netPerformancePercentWithCurrencyEffect
) )
}).toNumber(); }).toNumber();
@ -259,11 +260,11 @@ export class GfTreemapChartComponent
}, },
display: true, display: true,
font: [{ size: 16 }, { lineHeight: 1.5, size: 14 }], font: [{ size: 16 }, { lineHeight: 1.5, size: 14 }],
formatter: (ctx) => { formatter: ({ raw }) => {
// Round to 4 decimal places // Round to 4 decimal places
let netPerformancePercentWithCurrencyEffect = let netPerformancePercentWithCurrencyEffect =
Math.round( Math.round(
ctx.raw._data.netPerformancePercentWithCurrencyEffect * 10000 raw._data.netPerformancePercentWithCurrencyEffect * 10000
) / 10000; ) / 10000;
if (Math.abs(netPerformancePercentWithCurrencyEffect) === 0) { if (Math.abs(netPerformancePercentWithCurrencyEffect) === 0) {
@ -272,8 +273,11 @@ export class GfTreemapChartComponent
); );
} }
const name = raw._data.name;
const symbol = raw._data.symbol;
return [ return [
ctx.raw._data.symbol, isUUID(symbol) ? (name ?? symbol) : symbol,
`${netPerformancePercentWithCurrencyEffect > 0 ? '+' : ''}${(netPerformancePercentWithCurrencyEffect * 100).toFixed(2)}%` `${netPerformancePercentWithCurrencyEffect > 0 ? '+' : ''}${(netPerformancePercentWithCurrencyEffect * 100).toFixed(2)}%`
]; ];
}, },
@ -341,19 +345,17 @@ export class GfTreemapChartComponent
locale: this.locale locale: this.locale
}), }),
callbacks: { callbacks: {
label: (context) => { label: ({ raw }) => {
const allocationInPercentage = `${((context.raw._data.allocationInPercentage as number) * 100).toFixed(2)}%`; const allocationInPercentage = `${((raw._data.allocationInPercentage as number) * 100).toFixed(2)}%`;
const name = context.raw._data.name; const name = raw._data.name;
const sign = const sign =
context.raw._data.netPerformancePercentWithCurrencyEffect > 0 raw._data.netPerformancePercentWithCurrencyEffect > 0 ? '+' : '';
? '+' const symbol = raw._data.symbol;
: '';
const symbol = context.raw._data.symbol;
const netPerformanceInPercentageWithSign = `${sign}${(context.raw._data.netPerformancePercentWithCurrencyEffect * 100).toFixed(2)}%`; const netPerformanceInPercentageWithSign = `${sign}${(raw._data.netPerformancePercentWithCurrencyEffect * 100).toFixed(2)}%`;
if (context.raw._data.valueInBaseCurrency !== null) { if (raw._data.valueInBaseCurrency !== null) {
const value = context.raw._data.valueInBaseCurrency as number; const value = raw._data.valueInBaseCurrency as number;
return [ return [
`${name ?? symbol} (${allocationInPercentage})`, `${name ?? symbol} (${allocationInPercentage})`,
@ -363,7 +365,7 @@ export class GfTreemapChartComponent
})} ${this.baseCurrency}`, })} ${this.baseCurrency}`,
'', '',
$localize`Change` + ' (' + $localize`Performance` + ')', $localize`Change` + ' (' + $localize`Performance` + ')',
`${sign}${context.raw._data.netPerformanceWithCurrencyEffect.toLocaleString( `${sign}${raw._data.netPerformanceWithCurrencyEffect.toLocaleString(
this.locale, this.locale,
{ {
maximumFractionDigits: 2, maximumFractionDigits: 2,

Loading…
Cancel
Save