Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Task/upgrade chartjs-chart-treemap to version 4.2.0 (#7395)

Thomas Kaul5b80e62ec8ed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d073e016bf..ac3660b81a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
+### Changed
+
+- Upgraded `chartjs-chart-treemap` from version `3.1.0` to `4.2.0`
+
### Fixed
- Skipped opening the holding detail dialog for cash positions on the allocations page, the analysis page and the portfolio holdings page
diff --git a/libs/ui/src/lib/treemap-chart/interfaces/interfaces.ts b/libs/ui/src/lib/treemap-chart/interfaces/interfaces.ts
index e8d182adb0..ffd7b0094b 100644
--- a/libs/ui/src/lib/treemap-chart/interfaces/interfaces.ts
+++ b/libs/ui/src/lib/treemap-chart/interfaces/interfaces.ts
@@ -1,6 +1,6 @@
import { PortfolioPosition } from '@ghostfolio/common/interfaces';
-import { ScriptableContext, TooltipItem } from 'chart.js';
+import { ScriptableContext } from 'chart.js';
import { TreemapDataPoint } from 'chartjs-chart-treemap';
export interface GetColorParams {
@@ -9,13 +9,10 @@ export interface GetColorParams {
positiveNetPerformancePercentsRange: { max: number; min: number };
}
-interface GfTreemapDataPoint extends TreemapDataPoint {
+export type GfTreemapDataPoint = TreemapDataPoint & {
_data: PortfolioPosition;
-}
+};
-export interface GfTreemapScriptableContext extends ScriptableContext<'treemap'> {
- raw: GfTreemapDataPoint;
-}
-export interface GfTreemapTooltipItem extends TooltipItem<'treemap'> {
- raw: GfTreemapDataPoint;
-}
+export type GfTreemapScriptableContext = ScriptableContext<'treemap'> & {
+ raw: TreemapDataPoint;
+};
diff --git a/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts b/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts
index f26d954528..54c8d7f907 100644
--- a/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts
+++ b/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts
@@ -22,7 +22,12 @@ import {
viewChild
} from '@angular/core';
import { Big } from 'big.js';
-import type { ActiveElement, ChartData, TooltipOptions } from 'chart.js';
+import type {
+ ActiveElement,
+ ChartData,
+ TooltipItem,
+ TooltipOptions
+} from 'chart.js';
import { Chart, LinearScale, Tooltip } from 'chart.js';
import { TreemapController, TreemapElement } from 'chartjs-chart-treemap';
import { isUUID } from 'class-validator';
@@ -33,8 +38,8 @@ import OpenColor from 'open-color';
import type {
GetColorParams,
- GfTreemapScriptableContext,
- GfTreemapTooltipItem
+ GfTreemapDataPoint,
+ GfTreemapScriptableContext
} from './interfaces/interfaces';
const { gray, green, red } = OpenColor;
@@ -225,7 +230,9 @@ export class GfTreemapChartComponent
datasets: [
{
backgroundColor: (context: GfTreemapScriptableContext) => {
- if (!context.raw) {
+ const raw = context.raw as GfTreemapDataPoint;
+
+ if (!raw) {
return undefined;
}
@@ -233,13 +240,10 @@ export class GfTreemapChartComponent
getAnnualizedPerformancePercent({
daysInMarket: differenceInDays(
endDate,
- max([
- context.raw._data.dateOfFirstActivity ?? new Date(0),
- startDate
- ])
+ max([raw._data.dateOfFirstActivity ?? new Date(0), startDate])
),
netPerformancePercentage: new Big(
- context.raw._data.netPerformancePercentWithCurrencyEffect
+ raw._data.netPerformancePercentWithCurrencyEffect
)
}).toNumber();
@@ -261,7 +265,9 @@ export class GfTreemapChartComponent
labels: {
align: 'left',
color: (context: GfTreemapScriptableContext) => {
- if (!context.raw) {
+ const raw = context.raw as GfTreemapDataPoint;
+
+ if (!raw) {
return undefined;
}
@@ -270,12 +276,12 @@ export class GfTreemapChartComponent
daysInMarket: differenceInDays(
endDate,
max([
- context.raw._data.dateOfFirstActivity ?? new Date(0),
+ raw._data.dateOfFirstActivity ?? new Date(0),
startDate
])
),
netPerformancePercentage: new Big(
- context.raw._data.netPerformancePercentWithCurrencyEffect
+ raw._data.netPerformancePercentWithCurrencyEffect
)
}).toNumber();
@@ -294,7 +300,9 @@ export class GfTreemapChartComponent
},
display: true,
font: [{ size: 16 }, { lineHeight: 1.5, size: 14 }],
- formatter: ({ raw }: GfTreemapScriptableContext) => {
+ formatter: (context: GfTreemapScriptableContext) => {
+ const raw = context.raw as GfTreemapDataPoint;
+
let netPerformancePercentWithCurrencyEffect = round(
raw._data.netPerformancePercentWithCurrencyEffect,
4
@@ -380,7 +388,9 @@ export class GfTreemapChartComponent
}),
// @ts-expect-error: no need to set all attributes in callbacks
callbacks: {
- label: ({ raw }: GfTreemapTooltipItem) => {
+ label: (context: TooltipItem<'treemap'>) => {
+ const raw = context.raw as GfTreemapDataPoint;
+
const allocationInPercentage = `${(raw._data.allocationInPercentage * 100).toFixed(2)}%`;
const name = raw._data.assetProfile.name;
diff --git a/package-lock.json b/package-lock.json
index 107c23c2ef..ea294d28c4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -54,7 +54,7 @@
"bull": "4.16.5",
"chart.js": "4.5.1",
"chartjs-adapter-date-fns": "3.0.0",
- "chartjs-chart-treemap": "3.1.0",
+ "chartjs-chart-treemap": "4.2.0",
"chartjs-plugin-annotation": "3.1.0",
"chartjs-plugin-datalabels": "2.2.0",
"cheerio": "1.2.0",
@@ -16124,9 +16124,9 @@
}
},
"node_modules/chartjs-chart-treemap": {
- "version": "3.1.0",
- "resolved": "https://registry.npmjs.org/chartjs-chart-treemap/-/chartjs-chart-treemap-3.1.0.tgz",
- "integrity": "sha512-0LJxj4J9sCTHmrXCFlqtoBKMJDcS7VzFeRgNBRZRwU1QSpCXJKTNk5TysPEs5/YW0XYvZoN8u44RqqLf0pAzQw==",
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/chartjs-chart-treemap/-/chartjs-chart-treemap-4.2.0.tgz",
+ "integrity": "sha512-2ghdKHbknLYEzqD2fRTbACOzEhuH/f7zI5t6dbQ3cAOS+ric4mLjll6Sxsaugy/HFU0KUftJEszYOvtay3wFSQ==",
"license": "MIT",
"peerDependencies": {
"chart.js": ">=3.0.0"
diff --git a/package.json b/package.json
index c3329e55e8..b6b572d828 100644
--- a/package.json
+++ b/package.json
@@ -98,7 +98,7 @@
"bull": "4.16.5",
"chart.js": "4.5.1",
"chartjs-adapter-date-fns": "3.0.0",
- "chartjs-chart-treemap": "3.1.0",
+ "chartjs-chart-treemap": "4.2.0",
"chartjs-plugin-annotation": "3.1.0",
"chartjs-plugin-datalabels": "2.2.0",
"cheerio": "1.2.0",