From 838ca5958fcf8e89db23f740fb1bf1737652237c Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Tue, 14 Jul 2026 09:57:57 +0700 Subject: [PATCH] feat(ui): implement input signal --- .../treemap-chart/treemap-chart.component.ts | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) 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 1fdac5c5d..eb0265af3 100644 --- a/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts +++ b/libs/ui/src/lib/treemap-chart/treemap-chart.component.ts @@ -15,7 +15,7 @@ import { ChangeDetectionStrategy, Component, ElementRef, - Input, + input, OnChanges, OnDestroy, output, @@ -50,12 +50,12 @@ const { gray, green, red } = OpenColor; export class GfTreemapChartComponent implements AfterViewInit, OnChanges, OnDestroy { - @Input() baseCurrency: string; - @Input() colorScheme: ColorScheme; - @Input() cursor: string; - @Input() dateRange: DateRange; - @Input() holdings: PortfolioPosition[] | undefined; - @Input() locale = getLocale(); + public readonly baseCurrency = input.required(); + public readonly colorScheme = input.required(); + public readonly cursor = input.required(); + public readonly dateRange = input.required(); + public readonly holdings = input(); + public readonly locale = input(getLocale()); public readonly treemapChartClicked = output(); @@ -68,6 +68,7 @@ export class GfTreemapChartComponent public constructor() { Chart.register(LinearScale, Tooltip, TreemapController, TreemapElement); } + public ngAfterViewInit() { this.initialize(); } @@ -154,17 +155,19 @@ export class GfTreemapChartComponent } private initialize() { - if (!this.holdings) { + const holdings = this.holdings(); + + if (!holdings) { return; } this.isLoading = true; const { endDate, startDate } = getIntervalFromDateRange({ - dateRange: this.dateRange + dateRange: this.dateRange() }); - const netPerformancePercentsWithCurrencyEffect = this.holdings.map( + const netPerformancePercentsWithCurrencyEffect = holdings.map( ({ dateOfFirstActivity, netPerformancePercentWithCurrencyEffect }) => { return getAnnualizedPerformancePercent({ daysInMarket: differenceInDays( @@ -300,7 +303,7 @@ export class GfTreemapChartComponent }, spacing: 1, // @ts-expect-error: should be PortfolioPosition[] - tree: this.holdings + tree: this.holdings() } ] }; @@ -338,9 +341,9 @@ export class GfTreemapChartComponent } catch {} }, onHover: (event, chartElement) => { - if (this.cursor) { + if (this.cursor()) { (event.native?.target as HTMLElement).style.cursor = - chartElement[0] ? this.cursor : 'default'; + chartElement[0] ? this.cursor() : 'default'; } }, plugins: { @@ -358,9 +361,9 @@ export class GfTreemapChartComponent private getTooltipPluginConfiguration(): Partial> { return { ...getTooltipOptions({ - colorScheme: this.colorScheme, - currency: this.baseCurrency, - locale: this.locale + colorScheme: this.colorScheme(), + currency: this.baseCurrency(), + locale: this.locale() }), // @ts-expect-error: no need to set all attributes in callbacks callbacks: { @@ -380,19 +383,19 @@ export class GfTreemapChartComponent return [ `${name ?? symbol} (${allocationInPercentage})`, - `${value?.toLocaleString(this.locale, { + `${value?.toLocaleString(this.locale(), { maximumFractionDigits: 2, minimumFractionDigits: 2 - })} ${this.baseCurrency}`, + })} ${this.baseCurrency()}`, '', $localize`Change` + ' (' + $localize`Performance` + ')', `${sign}${raw._data.netPerformanceWithCurrencyEffect.toLocaleString( - this.locale, + this.locale(), { maximumFractionDigits: 2, minimumFractionDigits: 2 } - )} ${this.baseCurrency} (${netPerformanceInPercentageWithSign})` + )} ${this.baseCurrency()} (${netPerformanceInPercentageWithSign})` ]; } else { return [