|
|
@ -26,6 +26,7 @@ import { |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { |
|
|
import { |
|
|
Chart, |
|
|
Chart, |
|
|
|
|
|
ChartTypeRegistry, |
|
|
Filler, |
|
|
Filler, |
|
|
LinearScale, |
|
|
LinearScale, |
|
|
LineController, |
|
|
LineController, |
|
|
@ -33,6 +34,7 @@ import { |
|
|
PointElement, |
|
|
PointElement, |
|
|
TimeScale, |
|
|
TimeScale, |
|
|
Tooltip, |
|
|
Tooltip, |
|
|
|
|
|
TooltipOptions, |
|
|
TooltipPosition |
|
|
TooltipPosition |
|
|
} from 'chart.js'; |
|
|
} from 'chart.js'; |
|
|
import 'chartjs-adapter-date-fns'; |
|
|
import 'chartjs-adapter-date-fns'; |
|
|
@ -117,9 +119,9 @@ export class GfLineChartComponent |
|
|
|
|
|
|
|
|
private initialize() { |
|
|
private initialize() { |
|
|
this.isLoading = true; |
|
|
this.isLoading = true; |
|
|
const benchmarkPrices = []; |
|
|
const benchmarkPrices: number[] = []; |
|
|
const labels: string[] = []; |
|
|
const labels: string[] = []; |
|
|
const marketPrices = []; |
|
|
const marketPrices: number[] = []; |
|
|
|
|
|
|
|
|
this.historicalDataItems?.forEach((historicalDataItem, index) => { |
|
|
this.historicalDataItems?.forEach((historicalDataItem, index) => { |
|
|
benchmarkPrices.push(this.benchmarkDataItems?.[index]?.value); |
|
|
benchmarkPrices.push(this.benchmarkDataItems?.[index]?.value); |
|
|
@ -171,25 +173,26 @@ export class GfLineChartComponent |
|
|
if (this.chartCanvas) { |
|
|
if (this.chartCanvas) { |
|
|
if (this.chart) { |
|
|
if (this.chart) { |
|
|
this.chart.data = data; |
|
|
this.chart.data = data; |
|
|
|
|
|
|
|
|
|
|
|
if (!this.chart.options.plugins) { |
|
|
|
|
|
this.chart.options.plugins = {}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.chart.options.plugins.tooltip = |
|
|
this.chart.options.plugins.tooltip = |
|
|
this.getTooltipPluginConfiguration() as unknown; |
|
|
this.getTooltipPluginConfiguration(); |
|
|
this.chart.options.animation = |
|
|
this.chart.options.animation = this.isAnimated && { |
|
|
this.isAnimated && |
|
|
x: this.getAnimationConfigurationForAxis({ labels, axis: 'x' }), |
|
|
({ |
|
|
y: this.getAnimationConfigurationForAxis({ labels, axis: 'y' }) |
|
|
x: this.getAnimationConfigurationForAxis({ labels, axis: 'x' }), |
|
|
}; |
|
|
y: this.getAnimationConfigurationForAxis({ labels, axis: 'y' }) |
|
|
|
|
|
} as unknown); |
|
|
|
|
|
this.chart.update(); |
|
|
this.chart.update(); |
|
|
} else { |
|
|
} else { |
|
|
this.chart = new Chart(this.chartCanvas.nativeElement, { |
|
|
this.chart = new Chart(this.chartCanvas.nativeElement, { |
|
|
data, |
|
|
data, |
|
|
options: { |
|
|
options: { |
|
|
animation: |
|
|
animation: this.isAnimated && { |
|
|
this.isAnimated && |
|
|
x: this.getAnimationConfigurationForAxis({ labels, axis: 'x' }), |
|
|
({ |
|
|
y: this.getAnimationConfigurationForAxis({ labels, axis: 'y' }) |
|
|
x: this.getAnimationConfigurationForAxis({ labels, axis: 'x' }), |
|
|
}, |
|
|
y: this.getAnimationConfigurationForAxis({ labels, axis: 'y' }) |
|
|
|
|
|
} as unknown), |
|
|
|
|
|
aspectRatio: 16 / 9, |
|
|
aspectRatio: 16 / 9, |
|
|
elements: { |
|
|
elements: { |
|
|
point: { |
|
|
point: { |
|
|
@ -208,7 +211,7 @@ export class GfLineChartComponent |
|
|
verticalHoverLine: { |
|
|
verticalHoverLine: { |
|
|
color: `rgba(${getTextColor(this.colorScheme)}, 0.1)` |
|
|
color: `rgba(${getTextColor(this.colorScheme)}, 0.1)` |
|
|
} |
|
|
} |
|
|
} as unknown, |
|
|
}, |
|
|
scales: { |
|
|
scales: { |
|
|
x: { |
|
|
x: { |
|
|
border: { |
|
|
border: { |
|
|
@ -317,7 +320,9 @@ export class GfLineChartComponent |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private getTooltipPluginConfiguration() { |
|
|
private getTooltipPluginConfiguration< |
|
|
|
|
|
T extends keyof ChartTypeRegistry |
|
|
|
|
|
>(): Partial<TooltipOptions<T>> { |
|
|
return { |
|
|
return { |
|
|
...getTooltipOptions({ |
|
|
...getTooltipOptions({ |
|
|
colorScheme: this.colorScheme, |
|
|
colorScheme: this.colorScheme, |
|
|
@ -326,7 +331,7 @@ export class GfLineChartComponent |
|
|
unit: this.unit |
|
|
unit: this.unit |
|
|
}), |
|
|
}), |
|
|
mode: 'index', |
|
|
mode: 'index', |
|
|
position: 'top' as unknown, |
|
|
position: 'top', |
|
|
xAlign: 'center', |
|
|
xAlign: 'center', |
|
|
yAlign: 'bottom' |
|
|
yAlign: 'bottom' |
|
|
}; |
|
|
}; |
|
|
|