Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vegalite Keep Most Recent Data (Filter Transform)

I have the following dashboard:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Domain Breakout Breakout",
  "width": "container",
  "title": {
    "text": ["Build number by service name"],
    "align": "center",
    "dy": -10,
    "fontWeight": "bold",
    "color": "#4f597a",
    "fontSize": 13,
    "font": "Montserrat,sans-serif"
  },
  "config": {"axis": {"grid": true, "tickBand": "extent"}},
  "data": {
    "values": [
      {
        "service": "service1",
        "build": 5555,
        "env": "dev"
      },
      {
        "service": "service2",
        "build": 5555,
        "env": "test"
      },
      {
        "service": "service3",
        "build": 5555,
        "env": "staging"
      },
      {
        "service": "service4",
        "build": 5555,
        "env": "prod"
      },
      {
        "service": "service4",
        "build": 5225,
        "env": "prod"
      }
    ]
  },
  "transform": [
    {"pivot": "env", "value": "build", "groupby": ["env", "service","build"]}
  ],
  "mark": "text",
  "encoding": {
    "x": {
      "field": "env",
      "type": "ordinal",
      "sort": "descending",
      "axis": {
        "title": null,
        "labelAngle": 0,
        "labelFontWeight": "bold",
        "labelColor": "#4f597a",
        "labelFontSize": 20,
        "labelPadding": 20,
        "orient": "top"
      }
    },
    "y": {
      "field": "service",
      "type": "ordinal",
      "sort": {"field": "service", "order": "descending", "op": "sum"},
      "axis": {
        "title": null,
        "labelAngle": 0,
        "labelFontWeight": "bold",
        "labelColor": "#4f597a",
        "labelFontSize": 10,
        "labelPadding": 5
      }
    }
  },
  "layer": [
    {
      "mark": "rect",
      "width": 1000,
      "encoding": {
        "fill": {
          "legend": null,
          "field": "build",
          "type": "quantitative",
          "scale": {"range": ["#ecf9ff", "#c6efff", "#7ad9ff", "#42caff"]}
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "fontSize": 8,
        "font": "Montserrat,sans-serif",
        "align": "center"
      },
      "encoding": {"text": {"field": "build"}}
    }
  ]
}

I have a use case in which new data is inserted with the same service name and env name but with a different build number. In this case:

  {
    "service": "service4",
    "build": 5555,
    "env": "prod"
  },
  {
    "service": "service4",
    "build": 5558,
    "env": "prod"
  }

The issue is the cell [service4][prod] has to layer the "old" value and the new value.
Is there an option in vega to get the last inseted value or something similar?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Link the dash: Link

>Solution :

You can use a combination of joinaggregate and filter transform to get the max of build number. i.e. it will filter out the lower values. e.g.

 {
      "joinaggregate": [{"op": "max", "field": "build", "as": "MaxBuild"}],
      "groupby": ["service"]
    },
    {
      "filter":"datum.build >= datum.MaxBuild"
    }

enter image description here

enter image description here

Editor

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading