grafana / grafonnet

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

fixedColor overrides rendering two separate objects #144

Closed noobnesz closed 9 months ago

noobnesz commented 9 months ago

Hi,

So I have a grafonnet code like this:

...
local timeSeries = g.panel.timeSeries,
local fieldConfig = timeSeries.fieldConfig,
local custom = fieldConfig.defaults.custom,
local options = timeSeries.options,
local standardOptions = timeSeries.standardOptions,
local override = standardOptions.override,
local step = standardOptions.threshold.step,
...
...
+ standardOptions.withOverrides([
        // Override 1
        override.byName.new('latency_median')
        + override.byName.withPropertiesFromOptions(standardOptions.color.withMode('fixed'))
        + override.byName.withPropertiesFromOptions(standardOptions.color.withFixedColor('red')),
...

I expect grafonnet to render an override like this panel json:

"properties": [
{
 "id": "color",
 "value": {
  "mode": "fixed"
  "fixedColor": "red"
  }
},
...

But instead it renders two objects with the same id "color" inside the properties array like this:

"properties": [
          {
            "id": "color",
            "value": {
              "mode": "fixed"
            }
          },
          {
            "id": "color",
            "value": {
              "fixedColor": "red"
            }
          }
        ]

I tried using only the withFixedColor() function without withMode('fixed') and vice versa but they only render one value at a time for "id" : "color": "fixedColor": "red" and "mode": "fixed", respectively (both do not work as expected).

Am I using the correct functions for color overrides? I am using the latest grafonnet release v10.1.0 and on grafana v10.1.4.

This is related to #99 and #104.

Duologic commented 9 months ago

Can you do it like this?

 + override.byName.withPropertiesFromOptions(
  standardOptions.color.withMode('fixed')
  + standardOptions.color.withFixedColor('red')
)
noobnesz commented 9 months ago

@Duologic Thanks for being awesome as always. Not sure how I missed to do this but yes your solution solved my problem.

Thank you!

Closing this issue.