Skip to content

Commit

Permalink
line charts wip
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Valdes <ivan@vald.es>
  • Loading branch information
ivanvc committed Feb 28, 2025
1 parent 6f2985f commit 94725be
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions tools/rw-heatmaps/pkg/chart/line_chart.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -78,54 +79,45 @@ 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.
ratios := slices.MaxFunc(datasets, func(a, b *dataset.DataSet) int {
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 {
records = append(records, d.Records[ratio])
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.
Expand Down

0 comments on commit 94725be

Please sign in to comment.