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

[v10.0.x] XYChart: Ensure color scale is field-local and synced with data updates #70481

Merged
merged 1 commit into from
Jun 21, 2023

Conversation

grafana-delivery-bot[bot]
Copy link
Contributor

Backport 3007e3b from #70480


Fixes https://github.com/grafana/support-escalations/issues/6404

there were two issues:

  1. the color scale was taken from global min/max of all number fields instead of just the color field. this is the result of doStandardCalcs() and/or getDisplayProcessor() at the PanelQueryRunner level which sets a global & shared min/max on each number field.state.range. i had to hack around this by unsetting the global range we get and re-init the displayProcessor to re-calc the field-local range.
  2. the field range that was used was always the one which existed during initial chart setup and was not kept in sync with data updates.

the correct behavior:

xy-color-test
{
  "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": 724,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "testdata",
        "uid": "PD8C576611E62080A"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "continuous-BlYlRd"
          },
          "custom": {
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "pointSize": {
              "fixed": 50
            },
            "scaleDistribution": {
              "type": "linear"
            },
            "show": "points"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "series": [
          {
            "pointColor": {
              "field": "c"
            },
            "x": "x",
            "y": "y"
          }
        ],
        "seriesMapping": "manual",
        "tooltip": {
          "mode": "single",
          "sort": "none"
        }
      },
      "targets": [
        {
          "csvContent": "x,y,c\n0,0,0\n50,50,25\n100,100,50",
          "datasource": {
            "type": "testdata",
            "uid": "PD8C576611E62080A"
          },
          "refId": "A",
          "scenarioId": "csv_content"
        }
      ],
      "title": "Panel Title",
      "type": "xychart"
    }
  ],
  "refresh": "",
  "schemaVersion": 38,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "xy-color-test",
  "uid": "aa6ab0e1-be4b-455c-b06d-a45b27ec63d4",
  "version": 2,
  "weekStart": ""
}
xychart-color-by-field.mp4

Copy link
Contributor

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

@grafanabot grafanabot added the pr/external This PR is from external contributor label Jun 21, 2023
@nmarrs nmarrs enabled auto-merge (squash) June 21, 2023 21:26
@nmarrs
Copy link
Contributor

nmarrs commented Jun 21, 2023

Not sure that we should consider the @grafana-delivery-bot as an external contributor 🤔

@nmarrs nmarrs merged commit c87b723 into v10.0.x Jun 21, 2023
18 checks passed
@nmarrs nmarrs deleted the backport-70480-to-v10.0.x branch June 21, 2023 21:33
@zerok zerok modified the milestones: 10.0.x, 10.0.2 Jun 30, 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.

None yet

4 participants