|
|
|
@ -1,20 +1,21 @@ |
|
|
|
import { |
|
|
|
getTooltipOptions, |
|
|
|
getChartBorderColor, |
|
|
|
getChartElementsOptions, |
|
|
|
getTimeAxisOptions, |
|
|
|
getValueAxisOptions, |
|
|
|
getVerticalHoverLinePlugin, |
|
|
|
getZeroLineAnnotation, |
|
|
|
transformTickToAbbreviation |
|
|
|
} from '@ghostfolio/common/chart-helper'; |
|
|
|
import { primaryColorRgb, secondaryColorRgb } from '@ghostfolio/common/config'; |
|
|
|
import { |
|
|
|
getBackgroundColor, |
|
|
|
getDateFormatString, |
|
|
|
getLocale, |
|
|
|
getTextColor, |
|
|
|
parseDate |
|
|
|
} from '@ghostfolio/common/helper'; |
|
|
|
import { getLocale, parseDate } from '@ghostfolio/common/helper'; |
|
|
|
import { LineChartItem } from '@ghostfolio/common/interfaces'; |
|
|
|
import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface'; |
|
|
|
import { ColorScheme, GroupBy } from '@ghostfolio/common/types'; |
|
|
|
import { registerChartConfiguration } from '@ghostfolio/ui/chart'; |
|
|
|
import { |
|
|
|
getTimeSeriesTooltipOptions, |
|
|
|
registerChartConfiguration |
|
|
|
} from '@ghostfolio/ui/chart'; |
|
|
|
|
|
|
|
import { |
|
|
|
ChangeDetectionStrategy, |
|
|
|
@ -175,16 +176,7 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
|
data: chartData, |
|
|
|
options: { |
|
|
|
animation: false, |
|
|
|
elements: { |
|
|
|
line: { |
|
|
|
tension: 0 |
|
|
|
}, |
|
|
|
point: { |
|
|
|
hoverBackgroundColor: getBackgroundColor(this.colorScheme), |
|
|
|
hoverRadius: 2, |
|
|
|
radius: 0 |
|
|
|
} |
|
|
|
}, |
|
|
|
elements: getChartElementsOptions(this.colorScheme), |
|
|
|
interaction: { intersect: false, mode: 'index' }, |
|
|
|
maintainAspectRatio: true, |
|
|
|
plugins: { |
|
|
|
@ -212,13 +204,7 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
|
value: this.savingsRate |
|
|
|
} |
|
|
|
: undefined, |
|
|
|
yAxis: { |
|
|
|
borderColor: `rgba(${getTextColor(this.colorScheme)}, 0.1)`, |
|
|
|
borderWidth: 1, |
|
|
|
scaleID: 'y', |
|
|
|
type: 'line', |
|
|
|
value: 0 |
|
|
|
} |
|
|
|
yAxis: getZeroLineAnnotation(this.colorScheme) |
|
|
|
} |
|
|
|
}, |
|
|
|
legend: { |
|
|
|
@ -226,54 +212,23 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
|
}, |
|
|
|
tooltip: this.getTooltipPluginConfiguration(), |
|
|
|
verticalHoverLine: { |
|
|
|
color: `rgba(${getTextColor(this.colorScheme)}, 0.1)` |
|
|
|
color: getChartBorderColor(this.colorScheme) |
|
|
|
} |
|
|
|
}, |
|
|
|
responsive: true, |
|
|
|
scales: { |
|
|
|
x: { |
|
|
|
border: { |
|
|
|
color: `rgba(${getTextColor(this.colorScheme)}, 0.1)`, |
|
|
|
width: this.groupBy ? 0 : 1 |
|
|
|
}, |
|
|
|
display: true, |
|
|
|
grid: { |
|
|
|
display: false |
|
|
|
}, |
|
|
|
type: 'time', |
|
|
|
time: { |
|
|
|
tooltipFormat: getDateFormatString(this.locale), |
|
|
|
unit: 'year' |
|
|
|
} |
|
|
|
}, |
|
|
|
y: { |
|
|
|
border: { |
|
|
|
display: false |
|
|
|
}, |
|
|
|
x: getTimeAxisOptions({ |
|
|
|
borderWidth: this.groupBy ? 0 : 1, |
|
|
|
colorScheme: this.colorScheme, |
|
|
|
locale: this.locale |
|
|
|
}), |
|
|
|
y: getValueAxisOptions({ |
|
|
|
colorScheme: this.colorScheme, |
|
|
|
display: !this.isInPercentage, |
|
|
|
grid: { |
|
|
|
color: ({ scale, tick }) => { |
|
|
|
if ( |
|
|
|
tick.value === 0 || |
|
|
|
tick.value === scale.max || |
|
|
|
tick.value === scale.min |
|
|
|
) { |
|
|
|
return `rgba(${getTextColor(this.colorScheme)}, 0.1)`; |
|
|
|
} |
|
|
|
|
|
|
|
return 'transparent'; |
|
|
|
} |
|
|
|
}, |
|
|
|
position: 'right', |
|
|
|
ticks: { |
|
|
|
callback: (value: number) => { |
|
|
|
return transformTickToAbbreviation(value); |
|
|
|
}, |
|
|
|
display: true, |
|
|
|
mirror: true, |
|
|
|
z: 1 |
|
|
|
} |
|
|
|
tickCallback: (tickValue) => { |
|
|
|
return transformTickToAbbreviation(Number(tickValue)); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
plugins: [ |
|
|
|
@ -289,19 +244,13 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy { |
|
|
|
private getTooltipPluginConfiguration(): Partial< |
|
|
|
TooltipOptions<'bar' | 'line'> |
|
|
|
> { |
|
|
|
return { |
|
|
|
...getTooltipOptions({ |
|
|
|
return getTimeSeriesTooltipOptions<'bar' | 'line'>({ |
|
|
|
colorScheme: this.colorScheme, |
|
|
|
currency: this.isInPercentage ? undefined : this.currency, |
|
|
|
groupBy: this.groupBy, |
|
|
|
locale: this.isInPercentage ? undefined : this.locale, |
|
|
|
unit: this.isInPercentage ? '%' : undefined |
|
|
|
}), |
|
|
|
mode: 'index', |
|
|
|
position: 'top', |
|
|
|
xAlign: 'center', |
|
|
|
yAlign: 'bottom' |
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private isInFuture<T>(aContext: ScriptableLineSegmentContext, aValue: T) { |
|
|
|
|