Skip to content

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

Feature/Improve background color assignment in treemap chart component (#3918)

Madhab Chandra Sahoo67a147bd96e7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e1b35474e..77c0743bc3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- Improved the backgrounds of the chart of the holdings tab on the home page (experimental)
- Improved the labels of the chart of the holdings tab on the home page (experimental)
- Refactored the rule thresholds in the _X-ray_ section (experimental)
- Exposed the timeout of the portfolio snapshot computation as an environment variable (`PROCESSOR_PORTFOLIO_SNAPSHOT_COMPUTATION_TIMEOUT`)
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 0b3f176769..7099b01fd2 100644
--- a/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts
+++ b/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts
@@ -91,7 +91,7 @@ export class GfTreemapChartComponent
datasets: [
{
backgroundColor(ctx) {
- const annualizedNetPerformancePercentWithCurrencyEffect =
+ let annualizedNetPerformancePercentWithCurrencyEffect =
getAnnualizedPerformancePercent({
daysInMarket: differenceInDays(
endDate,
@@ -105,6 +105,12 @@ export class GfTreemapChartComponent
)
}).toNumber();
+ // Round to 2 decimal places
+ annualizedNetPerformancePercentWithCurrencyEffect =
+ Math.round(
+ annualizedNetPerformancePercentWithCurrencyEffect * 100
+ ) / 100;
+
if (
annualizedNetPerformancePercentWithCurrencyEffect >
0.03 * GfTreemapChartComponent.HEAT_MULTIPLIER
@@ -123,8 +129,11 @@ export class GfTreemapChartComponent
} else if (annualizedNetPerformancePercentWithCurrencyEffect > 0) {
return green[3];
} else if (
- annualizedNetPerformancePercentWithCurrencyEffect === 0
+ Math.abs(annualizedNetPerformancePercentWithCurrencyEffect) === 0
) {
+ annualizedNetPerformancePercentWithCurrencyEffect = Math.abs(
+ annualizedNetPerformancePercentWithCurrencyEffect
+ );
return gray[3];
} else if (
annualizedNetPerformancePercentWithCurrencyEffect >