mirror of https://github.com/ghostfolio/ghostfolio
14 changed files with 265 additions and 13 deletions
@ -0,0 +1,12 @@ |
|||||
|
:host { |
||||
|
display: block; |
||||
|
|
||||
|
.mat-mdc-dialog-content { |
||||
|
max-height: unset; |
||||
|
|
||||
|
gf-line-chart { |
||||
|
aspect-ratio: 16 / 9; |
||||
|
margin: 0 -0.5rem; |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,87 @@ |
|||||
|
import { GfDialogFooterModule } from '@ghostfolio/client/components/dialog-footer/dialog-footer.module'; |
||||
|
import { GfDialogHeaderModule } from '@ghostfolio/client/components/dialog-header/dialog-header.module'; |
||||
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
||||
|
import { DATE_FORMAT } from '@ghostfolio/common/helper'; |
||||
|
import { |
||||
|
AdminMarketDataDetails, |
||||
|
LineChartItem |
||||
|
} from '@ghostfolio/common/interfaces'; |
||||
|
import { GfLineChartComponent } from '@ghostfolio/ui/line-chart'; |
||||
|
|
||||
|
import { CommonModule } from '@angular/common'; |
||||
|
import { |
||||
|
CUSTOM_ELEMENTS_SCHEMA, |
||||
|
ChangeDetectionStrategy, |
||||
|
ChangeDetectorRef, |
||||
|
Component, |
||||
|
Inject, |
||||
|
OnDestroy, |
||||
|
OnInit |
||||
|
} from '@angular/core'; |
||||
|
import { |
||||
|
MAT_DIALOG_DATA, |
||||
|
MatDialogModule, |
||||
|
MatDialogRef |
||||
|
} from '@angular/material/dialog'; |
||||
|
import { format } from 'date-fns'; |
||||
|
import { Subject } from 'rxjs'; |
||||
|
import { takeUntil } from 'rxjs/operators'; |
||||
|
|
||||
|
import { BenchmarkDetailDialogParams } from './interfaces/interfaces'; |
||||
|
|
||||
|
@Component({ |
||||
|
changeDetection: ChangeDetectionStrategy.OnPush, |
||||
|
host: { class: 'd-flex flex-column h-100' }, |
||||
|
imports: [ |
||||
|
CommonModule, |
||||
|
GfDialogFooterModule, |
||||
|
GfDialogHeaderModule, |
||||
|
GfLineChartComponent, |
||||
|
MatDialogModule |
||||
|
], |
||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA], |
||||
|
selector: 'gf-benchmark-detail-dialog', |
||||
|
standalone: true, |
||||
|
styleUrls: ['./benchmark-detail-dialog.component.scss'], |
||||
|
templateUrl: 'benchmark-detail-dialog.html' |
||||
|
}) |
||||
|
export class GfBenchmarkDetailDialogComponent implements OnDestroy, OnInit { |
||||
|
public assetProfile: AdminMarketDataDetails['assetProfile']; |
||||
|
public historicalDataItems: LineChartItem[]; |
||||
|
|
||||
|
private unsubscribeSubject = new Subject<void>(); |
||||
|
|
||||
|
public constructor( |
||||
|
private changeDetectorRef: ChangeDetectorRef, |
||||
|
private dataService: DataService, |
||||
|
public dialogRef: MatDialogRef<GfBenchmarkDetailDialogComponent>, |
||||
|
@Inject(MAT_DIALOG_DATA) public data: BenchmarkDetailDialogParams |
||||
|
) {} |
||||
|
|
||||
|
public ngOnInit() { |
||||
|
this.dataService |
||||
|
.fetchBenchmark({ |
||||
|
dataSource: this.data.dataSource, |
||||
|
symbol: this.data.symbol |
||||
|
}) |
||||
|
.pipe(takeUntil(this.unsubscribeSubject)) |
||||
|
.subscribe(({ assetProfile, marketData }) => { |
||||
|
this.assetProfile = assetProfile; |
||||
|
|
||||
|
this.historicalDataItems = marketData.map(({ date, marketPrice }) => { |
||||
|
return { date: format(date, DATE_FORMAT), value: marketPrice }; |
||||
|
}); |
||||
|
|
||||
|
this.changeDetectorRef.markForCheck(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public onClose() { |
||||
|
this.dialogRef.close(); |
||||
|
} |
||||
|
|
||||
|
public ngOnDestroy() { |
||||
|
this.unsubscribeSubject.next(); |
||||
|
this.unsubscribeSubject.complete(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
<gf-dialog-header |
||||
|
mat-dialog-title |
||||
|
position="center" |
||||
|
[deviceType]="data.deviceType" |
||||
|
[title]="assetProfile?.name" |
||||
|
(closeButtonClicked)="onClose()" |
||||
|
/> |
||||
|
|
||||
|
<div class="flex-grow-1" mat-dialog-content> |
||||
|
<div class="container p-0"> |
||||
|
<gf-line-chart |
||||
|
benchmarkLabel="Average Unit Price" |
||||
|
class="mb-4" |
||||
|
[colorScheme]="data.colorScheme" |
||||
|
[historicalDataItems]="historicalDataItems" |
||||
|
[isAnimated]="true" |
||||
|
[locale]="data.locale" |
||||
|
[showGradient]="true" |
||||
|
[showXAxis]="true" |
||||
|
[showYAxis]="true" |
||||
|
[symbol]="data.symbol" |
||||
|
/> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
<gf-dialog-footer |
||||
|
mat-dialog-actions |
||||
|
[deviceType]="data.deviceType" |
||||
|
(closeButtonClicked)="onClose()" |
||||
|
/> |
@ -0,0 +1,11 @@ |
|||||
|
import { ColorScheme } from '@ghostfolio/common/types'; |
||||
|
|
||||
|
import { DataSource } from '@prisma/client'; |
||||
|
|
||||
|
export interface BenchmarkDetailDialogParams { |
||||
|
colorScheme: ColorScheme; |
||||
|
dataSource: DataSource; |
||||
|
deviceType: string; |
||||
|
locale: string; |
||||
|
symbol: string; |
||||
|
} |
Loading…
Reference in new issue