grafana / grafonnet

Jsonnet library for generating Grafana dashboards.
https://grafana.github.io/grafonnet/
Apache License 2.0
320 stars 18 forks source link

`resolveCollapsedFlagOnRows` puts panel in wrong row #161

Closed nmyk closed 5 months ago

nmyk commented 5 months ago

Hi! I ran into issue #145 and attempted to resolve it by calling util.panel.resolveCollapsedFlagOnRows on the final panel array. This resulted in one of my panels getting moved to the wrong row.

In the following example, I expect stats a and b to be next to each other on row 1; and c, d, and e, on row 2. However, Grafana puts stat b in row 2:

local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet';
local row = g.panel.row;
local stat = g.panel.stat;

local panels = [
    row.new('row 1')
    + row.withPanels([
        stat.new('a')
        + stat.panelOptions.withGridPos(h=8, w=12),
        stat.new('b')
        + stat.panelOptions.withGridPos(h=8, w=12, x=12)
    ]),
    row.new('row 2')
    + row.withPanels([
        stat.new('c')
        + stat.panelOptions.withGridPos(h=4, w=4),
        stat.new('d')
        + stat.panelOptions.withGridPos(h=4, w=4, y=4),
        stat.new('e')
        + stat.panelOptions.withGridPos(h=8, w=20, x=4)
    ])
];

g.dashboard.new("bug report")
+ g.dashboard.withPanels(
    g.util.panel.resolveCollapsedFlagOnRows(panels)
)
Duologic commented 5 months ago

I suggest ensuring all panels and rows have x and y configured. The behavior around rows and gridPos is not very well defined in Grafana so without all the gridPos values set it may become unpredictable.