|
@ -29,7 +29,9 @@ import { |
|
|
LinearScale, |
|
|
LinearScale, |
|
|
PointElement, |
|
|
PointElement, |
|
|
TimeScale, |
|
|
TimeScale, |
|
|
Tooltip |
|
|
Tooltip, |
|
|
|
|
|
BarController, |
|
|
|
|
|
BarElement |
|
|
} from 'chart.js'; |
|
|
} from 'chart.js'; |
|
|
import { addDays, isAfter, parseISO, subDays } from 'date-fns'; |
|
|
import { addDays, isAfter, parseISO, subDays } from 'date-fns'; |
|
|
|
|
|
|
|
@ -42,6 +44,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: string; |
|
|
@Input() investments: InvestmentItem[]; |
|
|
@Input() investments: InvestmentItem[]; |
|
|
@Input() isInPercent = false; |
|
|
@Input() isInPercent = false; |
|
|
@Input() locale: string; |
|
|
@Input() locale: string; |
|
@ -53,6 +56,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 +83,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 +107,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; |
|
|
}), |
|
|
}), |
|
@ -192,7 +198,7 @@ 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; |
|
|