Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram: Respect min/max panel settings for x-axis #62273

Merged
merged 4 commits into from May 10, 2023

Conversation

leeoniya
Copy link
Contributor

@leeoniya leeoniya commented Jan 27, 2023

Fixes #62237

histogram-min-max.json
{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 672,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "testdata",
        "uid": "PD8C576611E62080A"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 15,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "title": "Panel Title",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "datasource",
        "uid": "-- Dashboard --"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "fillOpacity": 50,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineWidth": 1
          },
          "mappings": [],
          "max": 120,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 15,
        "w": 12,
        "x": 12,
        "y": 0
      },
      "id": 2,
      "options": {
        "bucketOffset": 0,
        "bucketSize": 2,
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        }
      },
      "targets": [
        {
          "datasource": {
            "type": "datasource",
            "uid": "-- Dashboard --"
          },
          "panelId": 1,
          "refId": "A"
        }
      ],
      "title": "Panel Title",
      "type": "histogram"
    }
  ],
  "refresh": "",
  "schemaVersion": 38,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "histogram-min-max",
  "uid": "bacbfa77-99ef-4bca-a029-4a0b60107f52",
  "version": 4,
  "weekStart": ""
}
histogram-limits.mp4

@grafanabot
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@grafanabot grafanabot added the stale Issue with no recent activity label Feb 26, 2023
@justinsmalley
Copy link

I hope this is not forgotten about. This is an important change for myself and many others. I am still using old graph panel histograms due to this missing functionality, however it looks like that will be deprecated soon. #63732

@grafanabot grafanabot removed the stale Issue with no recent activity label Mar 1, 2023
@grafanabot
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@grafanabot grafanabot added stale Issue with no recent activity and removed stale Issue with no recent activity labels Apr 1, 2023
@SEngelnkemper
Copy link

SEngelnkemper commented Apr 23, 2023

Why are you actually ignoring this obvious bug?

@kustrun
Copy link

kustrun commented May 5, 2023

This fix was not released yet?

@leeoniya
Copy link
Contributor Author

leeoniya commented May 5, 2023

for everyone here, can you tell me if/how you expect this to work any differently than simply pre-filtering your data using https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/transform-data/#filter-data-by-value

this is pretty much the question we're struggling to understand to see whether this approach should offer anything meaningfully different or should be identical and we just apply that transformation internally.

e.g. what do you expect legend calcs to read when you apply these limits in the panel? should they be full range or filtered range?

@leeoniya
Copy link
Contributor Author

leeoniya commented May 5, 2023

e.g. what do you expect legend calcs to read when you apply these limits in the panel? should they be full range or filtered range?

actually i should be more specific here. the legend calcs always happen before the data hits the panel. so they will always be full range. would you find it confusing that your min/max/avg in the legend do not correspond to the min/max limits you set in the panel?

if you think this is confusing, then we would have to re-calculate the legend stats a second time based on the panel's min/max filters, which is currently not legend behavior that occurs in any existing panel. this incongruity is why the PR has not simply been merged.

@justinsmalley
Copy link

My use case is that I want to set the max and min to levels outside the normal operating range.

As an example, imagine the output of solar panel. In full light, it can output 200W. On a cloudy day, it may only output a max of 100W. If I was to plot these a low light day and a full light day on a histogram without the same x-axis max value, the histogram would look roughly similar each day. But in reality, the behaviours are very different. Once the defined max and min x axis values are available, you could know if its a poor light day if the peak is further to the left, and a good light day if the peak is further to the right. There could also be two peaks if it suddenly turned very cloudy halfway through the day.

image

In summary, setting a max and min on the x-axis allows you to get a feeling for not only the distribution, but also the mean and standard deviation.

Regarding the legend, I haven't put any thought into that, especially with respect to applying transformations.

@leeoniya
Copy link
Contributor Author

leeoniya commented May 5, 2023

thanks. yeah, that makes sense. what's being asked for in https://community.grafana.com/t/does-min-and-max-standard-options-work-with-histograms/75380/3 is a combo of this. (grow the max and clip the min).

it sounds like if you want the legend to reflect any limits smaller than data min/max, then you should use transformations, and this PR should land as-is. so for the case linked above it would be transform/filter out values < 20, and then set panel to min: 20, max: 70.

@leeoniya leeoniya added this to the 10.0.0 milestone May 10, 2023
@leeoniya leeoniya changed the title Histogram: respect min/max panel settings for x-axis Histogram: Respect min/max panel settings for x-axis May 10, 2023
@leeoniya leeoniya marked this pull request as ready for review May 10, 2023 05:17
@leeoniya leeoniya requested a review from a team as a code owner May 10, 2023 05:17
@leeoniya leeoniya merged commit 8f8baf1 into main May 10, 2023
28 checks passed
@leeoniya leeoniya deleted the leeoniya/histogram-respect-min-max branch May 10, 2023 15:52
grafanabot pushed a commit that referenced this pull request May 10, 2023
grafanabot pushed a commit that referenced this pull request May 10, 2023
leeoniya added a commit that referenced this pull request May 10, 2023
Histogram: Respect min/max panel settings for x-axis (#62273)

(cherry picked from commit 8f8baf1)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
leeoniya added a commit that referenced this pull request May 10, 2023
Histogram: Respect min/max panel settings for x-axis (#62273)

(cherry picked from commit 8f8baf1)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
@zerok zerok modified the milestones: 10.0.0, 10.0.0-preview, 10.1.x May 31, 2023
@ricky-undeadcoders ricky-undeadcoders modified the milestones: 10.1.x, 10.1.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Histogram Visualization (min and max) option does not work
8 participants