Feature/improve color assignment with annualized performance in treemap chart (#3657)

* Improve color assignment

* Update changelog
This commit is contained in:
Thomas Kaul
2024-08-10 09:01:28 +02:00
committed by GitHub
parent 2bbad8f4b0
commit c34959896c
14 changed files with 112 additions and 103 deletions

View File

@@ -1,8 +1,12 @@
import { getAnnualizedPerformancePercent } from '@ghostfolio/common/calculation-helper';
import {
getAnnualizedPerformancePercent,
getIntervalFromDateRange
} from '@ghostfolio/common/calculation-helper';
import {
AssetProfileIdentifier,
PortfolioPosition
} from '@ghostfolio/common/interfaces';
import { DateRange } from '@ghostfolio/common/types';
import { CommonModule } from '@angular/common';
import {
@@ -23,7 +27,7 @@ import { ChartConfiguration } from 'chart.js';
import { LinearScale } from 'chart.js';
import { Chart } from 'chart.js';
import { TreemapController, TreemapElement } from 'chartjs-chart-treemap';
import { differenceInDays } from 'date-fns';
import { differenceInDays, max } from 'date-fns';
import { orderBy } from 'lodash';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
@@ -41,6 +45,7 @@ export class GfTreemapChartComponent
implements AfterViewInit, OnChanges, OnDestroy
{
@Input() cursor: string;
@Input() dateRange: DateRange;
@Input() holdings: PortfolioPosition[];
@Output() treemapChartClicked = new EventEmitter<AssetProfileIdentifier>();
@@ -75,6 +80,8 @@ export class GfTreemapChartComponent
private initialize() {
this.isLoading = true;
const { endDate, startDate } = getIntervalFromDateRange(this.dateRange);
const data: ChartConfiguration['data'] = <any>{
datasets: [
{
@@ -82,8 +89,11 @@ export class GfTreemapChartComponent
const annualizedNetPerformancePercentWithCurrencyEffect =
getAnnualizedPerformancePercent({
daysInMarket: differenceInDays(
new Date(),
ctx.raw._data.dateOfFirstActivity
endDate,
max([
ctx.raw._data.dateOfFirstActivity ?? new Date(0),
startDate
])
),
netPerformancePercentage: new Big(
ctx.raw._data.netPerformancePercentWithCurrencyEffect

View File

@@ -8,9 +8,9 @@
}"
/>
} @else {
@if (marketState === 'closed' && range === '1d') {
@if (marketState === 'closed' && dateRange === '1d') {
<ion-icon class="text-muted" name="pause-circle-outline" [size]="size" />
} @else if (marketState === 'delayed' && range === '1d') {
} @else if (marketState === 'delayed' && dateRange === '1d') {
<ion-icon class="text-muted" name="time-outline" [size]="size" />
} @else if (value <= -0.0005) {
<ion-icon

View File

@@ -19,9 +19,9 @@ import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
templateUrl: './trend-indicator.component.html'
})
export class GfTrendIndicatorComponent {
@Input() dateRange: DateRange;
@Input() isLoading = false;
@Input() marketState: MarketState = 'open';
@Input() range: DateRange = 'max';
@Input() size: 'large' | 'medium' | 'small' = 'small';
@Input() value = 0;