|
@ -22,7 +22,10 @@ import { |
|
|
transformTickToAbbreviation |
|
|
transformTickToAbbreviation |
|
|
} from '@ghostfolio/common/helper'; |
|
|
} from '@ghostfolio/common/helper'; |
|
|
import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface'; |
|
|
import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface'; |
|
|
|
|
|
import { GroupBy } from '@ghostfolio/common/types'; |
|
|
import { |
|
|
import { |
|
|
|
|
|
BarController, |
|
|
|
|
|
BarElement, |
|
|
Chart, |
|
|
Chart, |
|
|
LineController, |
|
|
LineController, |
|
|
LineElement, |
|
|
LineElement, |
|
@ -42,6 +45,7 @@ import { addDays, isAfter, parseISO, subDays } from 'date-fns'; |
|
|
export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
@Input() currency: string; |
|
|
@Input() currency: string; |
|
|
@Input() daysInMarket: number; |
|
|
@Input() daysInMarket: number; |
|
|
|
|
|
@Input() groupBy: GroupBy; |
|
|
@Input() investments: InvestmentItem[]; |
|
|
@Input() investments: InvestmentItem[]; |
|
|
@Input() isInPercent = false; |
|
|
@Input() isInPercent = false; |
|
|
@Input() locale: string; |
|
|
@Input() locale: string; |
|
@ -53,6 +57,8 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
|
|
|
|
|
|
public constructor() { |
|
|
public constructor() { |
|
|
Chart.register( |
|
|
Chart.register( |
|
|
|
|
|
BarController, |
|
|
|
|
|
BarElement, |
|
|
LinearScale, |
|
|
LinearScale, |
|
|
LineController, |
|
|
LineController, |
|
|
LineElement, |
|
|
LineElement, |
|
@ -78,7 +84,7 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
private initialize() { |
|
|
private initialize() { |
|
|
this.isLoading = true; |
|
|
this.isLoading = true; |
|
|
|
|
|
|
|
|
if (this.investments?.length > 0) { |
|
|
if (!this.groupBy && this.investments?.length > 0) { |
|
|
// Extend chart by 5% of days in market (before)
|
|
|
// Extend chart by 5% of days in market (before)
|
|
|
const firstItem = this.investments[0]; |
|
|
const firstItem = this.investments[0]; |
|
|
this.investments.unshift({ |
|
|
this.investments.unshift({ |
|
@ -102,13 +108,14 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const data = { |
|
|
const data = { |
|
|
labels: this.investments.map((position) => { |
|
|
labels: this.investments.map((investmentItem) => { |
|
|
return position.date; |
|
|
return investmentItem.date; |
|
|
}), |
|
|
}), |
|
|
datasets: [ |
|
|
datasets: [ |
|
|
{ |
|
|
{ |
|
|
|
|
|
backgroundColor: `rgb(${primaryColorRgb.r}, ${primaryColorRgb.g}, ${primaryColorRgb.b})`, |
|
|
borderColor: `rgb(${primaryColorRgb.r}, ${primaryColorRgb.g}, ${primaryColorRgb.b})`, |
|
|
borderColor: `rgb(${primaryColorRgb.r}, ${primaryColorRgb.g}, ${primaryColorRgb.b})`, |
|
|
borderWidth: 2, |
|
|
borderWidth: this.groupBy ? 0 : 2, |
|
|
data: this.investments.map((position) => { |
|
|
data: this.investments.map((position) => { |
|
|
return position.investment; |
|
|
return position.investment; |
|
|
}), |
|
|
}), |
|
@ -137,6 +144,7 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
this.chart = new Chart(this.chartCanvas.nativeElement, { |
|
|
this.chart = new Chart(this.chartCanvas.nativeElement, { |
|
|
data, |
|
|
data, |
|
|
options: { |
|
|
options: { |
|
|
|
|
|
animation: false, |
|
|
elements: { |
|
|
elements: { |
|
|
line: { |
|
|
line: { |
|
|
tension: 0 |
|
|
tension: 0 |
|
@ -192,12 +200,12 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
plugins: [getVerticalHoverLinePlugin(this.chartCanvas)], |
|
|
plugins: [getVerticalHoverLinePlugin(this.chartCanvas)], |
|
|
type: 'line' |
|
|
type: this.groupBy ? 'bar' : 'line' |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.isLoading = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getTooltipPluginConfiguration() { |
|
|
private getTooltipPluginConfiguration() { |
|
|