diff --git a/tools/rw-heatmaps/pkg/chart/line_chart.go b/tools/rw-heatmaps/pkg/chart/line_chart.go index 2415793e09c..a9964bfe21d 100644 --- a/tools/rw-heatmaps/pkg/chart/line_chart.go +++ b/tools/rw-heatmaps/pkg/chart/line_chart.go @@ -1,4 +1,4 @@ -// Copyright 2024 The etcd Authors +// Copyright 2025 The etcd Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,8 +56,9 @@ func plotLineChart(datasets []*dataset.DataSet, title string) *vgimg.Canvas { return len(max.GetSortedRatios()) }() - // Make a nx1 grid of heatmaps. - rows, cols := ratiosLength, 1 + // Make a nx1 grid of line charts. + const cols = 1 + rows := ratiosLength // Set the width and height of the canvas. width, height := 30*vg.Centimeter, 15*font.Length(ratiosLength)*vg.Centimeter @@ -78,10 +79,9 @@ func plotLineChart(datasets []*dataset.DataSet, title string) *vgimg.Canvas { } plots := make([][]*plot.Plot, rows) - legends := make([][]plot.Legend, rows) + legends := make([]plot.Legend, rows) for i := range plots { plots[i] = make([]*plot.Plot, cols) - legends[i] = make([]plot.Legend, cols) } // Load records into the grid. @@ -89,8 +89,7 @@ func plotLineChart(datasets []*dataset.DataSet, title string) *vgimg.Canvas { return cmp.Compare(len(a.GetSortedRatios()), len(b.GetSortedRatios())) }).GetSortedRatios() - row, col := 0, 0 - for _, ratio := range ratios { + for row, ratio := range ratios { var records [][]dataset.DataRecord var fileNames []string for _, d := range datasets { @@ -98,34 +97,27 @@ func plotLineChart(datasets []*dataset.DataSet, title string) *vgimg.Canvas { fileNames = append(fileNames, d.FileName) } p, l := plotIndividualLineChart(fmt.Sprintf("R/W Ratio %0.04f", ratio), records, fileNames) - plots[row][col] = p - legends[row][col] = l - - if col++; col == cols { - col = 0 - row++ - } + plots[row] = []*plot.Plot{p} + legends[row] = l } // Fill the canvas with the plots and legends. canvases := plot.Align(plots, t, dc) for i := 0; i < rows; i++ { - for j := 0; j < cols; j++ { - // Continue if there is no plot in the current cell (incomplete data). - if plots[i][j] == nil { - continue - } - - l := legends[i][j] - r := l.Rectangle(canvases[i][j]) - legendWidth := r.Max.X - r.Min.X - // Adjust the legend down a little. - l.YOffs = plots[i][j].Title.TextStyle.FontExtents().Height * 3 - l.Draw(canvases[i][j]) - - c := draw.Crop(canvases[i][j], 0, -legendWidth-vg.Millimeter, 0, 0) - plots[i][j].Draw(c) + // Continue if there is no plot in the current cell (incomplete data). + if plots[i][0] == nil { + continue } + + l := legends[i] + r := l.Rectangle(canvases[i][cols]) + legendWidth := r.Max.X - r.Min.X + // Adjust the legend down a little. + l.YOffs = plots[i][0].Title.TextStyle.FontExtents().Height * 3 + l.Draw(canvases[i][0]) + + c := draw.Crop(canvases[i][cols], 0, -legendWidth-vg.Millimeter, 0, 0) + plots[i][0].Draw(c) } // Add the title and parameter legend.