Fix block prediction chart when no or few data is available

This commit is contained in:
nymkappa 2022-07-15 12:01:21 +02:00
parent c6f33310e5
commit 16c6f030db
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04

View File

@ -98,7 +98,21 @@ export class BlockPredictionGraphComponent implements OnInit {
} }
prepareChartOptions(data) { prepareChartOptions(data) {
let title: object;
if (data.length === 0) {
title = {
textStyle: {
color: 'grey',
fontSize: 15
},
text: $localize`No data to display yet. Try again later.`,
left: 'center',
top: 'center'
};
}
this.chartOptions = { this.chartOptions = {
title: data.length === 0 ? title : undefined,
animation: false, animation: false,
grid: { grid: {
top: 30, top: 30,
@ -133,14 +147,13 @@ export class BlockPredictionGraphComponent implements OnInit {
return tooltip; return tooltip;
} }
}, },
xAxis: { xAxis: data.length === 0 ? undefined : {
name: formatterXAxisLabel(this.locale, this.timespan), name: formatterXAxisLabel(this.locale, this.timespan),
nameLocation: 'middle', nameLocation: 'middle',
nameTextStyle: { nameTextStyle: {
padding: [10, 0, 0, 0], padding: [10, 0, 0, 0],
}, },
type: 'category', type: 'category',
boundaryGap: false,
axisLine: { onZero: true }, axisLine: { onZero: true },
axisLabel: { axisLabel: {
formatter: val => formatterXAxisTimeCategory(this.locale, this.timespan, parseInt(val, 10)), formatter: val => formatterXAxisTimeCategory(this.locale, this.timespan, parseInt(val, 10)),
@ -152,7 +165,7 @@ export class BlockPredictionGraphComponent implements OnInit {
}, },
data: data.map(prediction => prediction[0]) data: data.map(prediction => prediction[0])
}, },
yAxis: [ yAxis: data.length === 0 ? undefined : [
{ {
type: 'value', type: 'value',
axisLabel: { axisLabel: {
@ -170,7 +183,7 @@ export class BlockPredictionGraphComponent implements OnInit {
}, },
}, },
], ],
series: [ series: data.length === 0 ? undefined : [
{ {
zlevel: 0, zlevel: 0,
name: $localize`Match rate`, name: $localize`Match rate`,
@ -183,9 +196,10 @@ export class BlockPredictionGraphComponent implements OnInit {
})), })),
type: 'bar', type: 'bar',
barWidth: '90%', barWidth: '90%',
barMaxWidth: 50,
}, },
], ],
dataZoom: [{ dataZoom: data.length === 0 ? undefined : [{
type: 'inside', type: 'inside',
realtime: true, realtime: true,
zoomLock: true, zoomLock: true,