Browse Source

replace average unit price by null if zero ; line-chart don't show null values

pull/2123/head
bptrgx 2 years ago
parent
commit
6b064318be
  1. 15
      apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts
  2. 20
      libs/ui/src/lib/line-chart/line-chart.component.ts

15
apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts

@ -113,10 +113,17 @@ export class PositionDetailDialog implements OnDestroy, OnInit {
this.grossPerformancePercent = grossPerformancePercent; this.grossPerformancePercent = grossPerformancePercent;
this.historicalDataItems = historicalData.map( this.historicalDataItems = historicalData.map(
(historicalDataItem) => { (historicalDataItem) => {
this.benchmarkDataItems.push({ if (historicalDataItem.averagePrice) {
date: historicalDataItem.date, this.benchmarkDataItems.push({
value: historicalDataItem.averagePrice date: historicalDataItem.date,
}); value: historicalDataItem.averagePrice
});
} else {
this.benchmarkDataItems.push({
date: historicalDataItem.date,
value: null
});
}
return { return {
date: historicalDataItem.date, date: historicalDataItem.date,

20
libs/ui/src/lib/line-chart/line-chart.component.ts

@ -118,12 +118,10 @@ export class LineChartComponent implements AfterViewInit, OnChanges, OnDestroy {
private initialize() { private initialize() {
this.isLoading = true; this.isLoading = true;
const benchmarkPrices = [];
const labels: string[] = []; const labels: string[] = [];
const marketPrices = []; const marketPrices = [];
this.historicalDataItems?.forEach((historicalDataItem, index) => { this.historicalDataItems?.forEach((historicalDataItem) => {
benchmarkPrices.push(this.benchmarkDataItems?.[index]?.value);
labels.push(historicalDataItem.date); labels.push(historicalDataItem.date);
marketPrices.push(historicalDataItem.value); marketPrices.push(historicalDataItem.value);
}); });
@ -151,7 +149,7 @@ export class LineChartComponent implements AfterViewInit, OnChanges, OnDestroy {
{ {
borderColor: `rgb(${secondaryColorRgb.r}, ${secondaryColorRgb.g}, ${secondaryColorRgb.b})`, borderColor: `rgb(${secondaryColorRgb.r}, ${secondaryColorRgb.g}, ${secondaryColorRgb.b})`,
borderWidth: 1, borderWidth: 1,
data: benchmarkPrices, data: [],
fill: false, fill: false,
label: this.benchmarkLabel, label: this.benchmarkLabel,
pointRadius: 0 pointRadius: 0
@ -168,6 +166,20 @@ export class LineChartComponent implements AfterViewInit, OnChanges, OnDestroy {
] ]
}; };
this.historicalDataItems?.forEach((historicalDataItem, index) => {
data.datasets[0].data.push(this.benchmarkDataItems?.[index]?.value);
if (this.benchmarkDataItems?.[index]?.value === null) {
data.datasets.unshift({
borderColor: `rgb(${secondaryColorRgb.r}, ${secondaryColorRgb.g}, ${secondaryColorRgb.b})`,
borderWidth: 1,
data: Array(data.datasets[0].data.length).fill(null),
fill: false,
label: this.benchmarkLabel,
pointRadius: 0
});
}
});
if (this.chartCanvas) { if (this.chartCanvas) {
if (this.chart) { if (this.chart) {
this.chart.data = data; this.chart.data = data;

Loading…
Cancel
Save