grafana / scenes

Build Grafana dashboards directly in your Grafana app plugins.
https://grafana.com/developers/scenes
Apache License 2.0
141 stars 21 forks source link

Preset metric visibility #792

Closed korinekgergely closed 5 months ago

korinekgergely commented 5 months ago

Subtitle: Inactive state of metrics at initialization so that they remain available

Question, is it possible to predefine within a panel which metrics should be disabled (visible if you like, or grey Legend), but so that they are available later?

Attention, I do not want to hide it, them! I want them to be clickable, markable, later visible. So this solution is out of the question, because the values are no longer available. .matchFieldsWithName('Threshold CRITICAL') .overrideCustomFieldConfig('hideFrom', { "viz": true, }) .matchFieldsWithName('Threshold WARNING') .overrideCustomFieldConfig('hideFrom', { "viz": true, }) I want to make certain metrics inactive when the panel is initialized, as if the user has already clicked on them.

torkelo commented 5 months ago

you can do an override rule like this something like this

 {
        "matcher": {
          "id": "byNames",
          "options": {
            "mode": "exclude",
            "names": [
              "Request/s22"
            ],
            "prefix": "All except:",
            "readOnly": true
          }
        },
        "properties": [
          {
            "id": "custom.hideFrom",
            "value": {
              "viz": true,
              "legend": false,
              "tooltip": false
            }
          }
        ]
      }

it will show up in legend but not in viz

korinekgergely commented 5 months ago

@torkelo Thank you for your quick reply. The code I outlined does just that, but unfortunately it is not the right solution for me. I want the "viz" to be available when I click on the legend in the app. I just want to hide it by default, when the panel is displayed. So that it is available later. With your solution, when I click on the legend, I get an empty panel. This is the same that you suggested: .matchFieldsWithName('Threshold WARNING') .overrideCustomFieldConfig('hideFrom', { "viz": true, "legend": false, "tooltip": false }) It's the same as you suggest, but unfortunately it doesn't fit our ideas.

ptrkkr commented 4 months ago

Same for me I am doing the following:

builder.setOverrides((timerSeriesTable) => {
        timerSeriesTable
            .match(
                {
                    id: "byNames",
                    options: {
                        mode: "exclude",
                        names: [
                            "someLegendLabel
                        ],
                        prefix: "All except:",
                        readOnly: true
                    }
                })
            .overrideColor({
                fixedColor: "blue",
                mode: FieldColorModeId.Fixed,
            })
            .overrideCustomFieldConfig("hideFrom", {
                viz: true,
                legend: false,
                tooltip: false
            })

    })

This code disables the other legend entries by default but you can't click on it again to enable it if you want to see it. When you click on it, it looks something like this: image Before it looks like this: image

I can see that in the Grafana dashboards, something like a __systemRef is used which i don't know how i can set in scenes.

I would appreciate some help!