fixes for line graph
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-01-16 12:55:36 +11:00
parent 871904f63e
commit 588a552e4c
5 changed files with 332 additions and 226 deletions

View File

@@ -139,6 +139,8 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat
width := 1200.0
height := 260.0
plotWidth := width - 60.0
startX := 40.0
maxVal := float64(0)
for _, e := range plot {
if float64(e.VmCount) > maxVal {
@@ -154,15 +156,15 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat
if maxVal == 0 {
maxVal = 1
}
stepX := width
stepX := plotWidth
if len(plot) > 1 {
stepX = width / float64(len(plot)-1)
stepX = plotWidth / float64(len(plot)-1)
}
pointsVm := ""
pointsVcpu := ""
pointsRam := ""
for i, e := range plot {
x := 40 + float64(i)*stepX
x := startX + float64(i)*stepX
yVm := 10 + (1-(float64(e.VmCount)/maxVal))*height
yVcpu := 10 + (1-(float64(e.VcpuTotal)/maxVal))*height
yRam := 10 + (1-(float64(e.RamTotalGB)/maxVal))*height
@@ -179,7 +181,7 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat
gridX := []float64{}
if len(plot) > 1 {
for i := 0; i < len(plot); i++ {
gridX = append(gridX, 40+float64(i)*stepX)
gridX = append(gridX, startX+float64(i)*stepX)
}
}
gridY := []float64{}
@@ -199,16 +201,16 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat
stepIdx = (len(plot)-1)/maxTicks + 1
}
for idx := 0; idx < len(plot); idx += stepIdx {
x := 40 + float64(idx)*stepX
x := startX + float64(idx)*stepX
label := time.Unix(plot[idx].RawTime, 0).Local().Format("01-02 15:04")
xTicks = append(xTicks, views.ChartTick{Pos: x, Label: label})
}
if len(plot) > 1 {
lastIdx := len(plot) - 1
if (lastIdx % stepIdx) != 0 {
x := 40 + float64(lastIdx)*stepX
label := time.Unix(plot[lastIdx].RawTime, 0).Local().Format("01-02 15:04")
xTicks = append(xTicks, views.ChartTick{Pos: x, Label: label})
xLast := startX + float64(lastIdx)*stepX
labelLast := time.Unix(plot[lastIdx].RawTime, 0).Local().Format("01-02 15:04")
if len(xTicks) == 0 || xTicks[len(xTicks)-1].Pos != xLast {
xTicks = append(xTicks, views.ChartTick{Pos: xLast, Label: labelLast})
}
}
return views.VcenterChartData{