func gridLayout()

in pkg/display/graph/dashboard/global.go [143:197]


func gridLayout(lt layoutType) ([]container.Option, error) {
	const buttonRowHeight = 15

	buttonColWidthPerc := 99 / len(allWidgets.buttons)
	var buttonCols []grid.Element

	for _, b := range allWidgets.buttons {
		if b != nil {
			buttonCols = append(buttonCols, grid.ColWidthPerc(buttonColWidthPerc, grid.Widget(b)))
		}
	}

	rows := []grid.Element{
		grid.RowHeightPerc(buttonRowHeight, buttonCols...),
	}

	switch lt {
	case layoutMetrics:
		rows = append(rows,
			grid.RowHeightPerc(70, gauge.MetricColumnsElement(allWidgets.gauges)...),
		)

	case layoutLineChart:
		lcElements := linear.LineChartElements(allWidgets.linears)
		percentage := int(math.Min(99, float64((100-buttonRowHeight)/len(lcElements))))

		for _, e := range lcElements {
			rows = append(rows,
				grid.RowHeightPerc(percentage, e...),
			)
		}

	case layoutHeatMap:
		const heatmapColWidth = 85

		rows = append(rows,
			grid.RowHeightPerc(
				99-buttonRowHeight,
				grid.ColWidthPerc((99-heatmapColWidth)/2), // Use two empty cols to center the heatmap.
				grid.ColWidthPerc(heatmapColWidth, grid.Widget(allWidgets.heatmap)),
				grid.ColWidthPerc((99-heatmapColWidth)/2),
			),
		)
	}

	builder := grid.New()
	builder.Add(
		grid.RowHeightPerc(99, rows...),
	)
	gridOpts, err := builder.Build()
	if err != nil {
		return nil, err
	}
	return gridOpts, nil
}