@ -10,16 +10,16 @@ import {
ViewChild
} from '@angular/core' ;
import { primaryColorRgb } from '@ghostfolio/common/config' ;
import { PortfolioItem } from '@ghostfolio/common/interfaces' ;
import {
Chart ,
LinearScale ,
LineController ,
LineElement ,
LinearScale ,
PointElement ,
TimeScale
} from 'chart.js' ;
import { Chart } from 'chart.js' ;
import { addMonths , isAfter , parseISO , subMonths } from 'date-fns' ;
import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface' ;
@Component ( {
selector : 'gf-investment-chart' ,
@ -28,7 +28,7 @@ import { addMonths, isAfter, parseISO, subMonths } from 'date-fns';
styleUrls : [ './investment-chart.component.scss' ]
} )
export class InvestmentChartComponent implements OnChanges , OnDestroy , OnInit {
@Input ( ) portfolioItems: Portfolio Item[ ] ;
@Input ( ) investments: Investment Item[ ] ;
@ViewChild ( 'chartCanvas' ) chartCanvas ;
@ -48,7 +48,7 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy, OnInit {
public ngOnInit() { }
public ngOnChanges() {
if ( this . portfolioItem s) {
if ( this . investment s) {
this . initialize ( ) ;
}
}
@ -60,32 +60,32 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy, OnInit {
private initialize() {
this . isLoading = true ;
if ( this . portfolioItem s? . length > 0 ) {
if ( this . investment s? . length > 0 ) {
// Extend chart by three months (before)
const firstItem = this . portfolioItem s[ 0 ] ;
this . portfolioItem s. unshift ( {
const firstItem = this . investment s[ 0 ] ;
this . investment s. unshift ( {
. . . firstItem ,
date : subMonths ( parseISO ( firstItem . date ) , 3 ) . toISOString ( ) ,
investment : 0
} ) ;
// Extend chart by three months (after)
const lastItem = this . portfolioItems[ this . portfolioItem s. length - 1 ] ;
this . portfolioItem s. push ( {
const lastItem = this . investments[ this . investment s. length - 1 ] ;
this . investment s. push ( {
. . . lastItem ,
date : addMonths ( parseISO ( lastItem . date ) , 3 ) . toISOString ( )
} ) ;
}
const data = {
labels : this. portfolioItem s.map( ( position ) = > {
labels : this. investment s.map( ( position ) = > {
return position . date ;
} ) ,
datasets : [
{
borderColor : ` rgb( ${ primaryColorRgb . r } , ${ primaryColorRgb . g } , ${ primaryColorRgb . b } ) ` ,
borderWidth : 2 ,
data : this. portfolioItem s.map( ( position ) = > {
data : this. investment s.map( ( position ) = > {
return position . investment ;
} ) ,
segment : {