|
@ -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, |
|
|