{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "description": "Minimum and maxmimum horsepower of cars from different origins.",
  "background": "white",
  "padding": 5,
  "height": 200,
  "style": "cell",
  "data": [
    {
      "name": "source_0",
      "url": "data/cars.json",
      "format": {"type": "json", "parse": {"Horsepower": "number"}},
      "transform": [
        {
          "type": "aggregate",
          "groupby": ["Origin"],
          "ops": ["min", "max"],
          "fields": ["Horsepower", "Horsepower"],
          "as": ["min_Horsepower", "max_Horsepower"]
        },
        {
          "type": "filter",
          "expr": "isValid(datum[\"min_Horsepower\"]) && isFinite(+datum[\"min_Horsepower\"])"
        }
      ]
    }
  ],
  "signals": [
    {"name": "x_step", "value": 20},
    {"name": "width", "update": "bandspace(domain('x').length, 0, 0) * x_step"}
  ],
  "marks": [
    {
      "name": "marks",
      "type": "rule",
      "style": ["rule"],
      "from": {"data": "source_0"},
      "encode": {
        "update": {
          "stroke": {"value": "black"},
          "description": {
            "signal": "\"Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"]) + \"; Min of Horsepower: \" + (format(datum[\"min_Horsepower\"], \"\")) + \"; Max of Horsepower: \" + (format(datum[\"max_Horsepower\"], \"\"))"
          },
          "x": {"scale": "x", "field": "Origin", "band": 0.5},
          "y": {"scale": "y", "field": "min_Horsepower"},
          "y2": {"scale": "y", "field": "max_Horsepower"}
        }
      }
    }
  ],
  "scales": [
    {
      "name": "x",
      "type": "band",
      "domain": {"data": "source_0", "field": "Origin", "sort": true},
      "range": {"step": {"signal": "x_step"}},
      "paddingInner": 0,
      "paddingOuter": 0
    },
    {
      "name": "y",
      "type": "linear",
      "domain": {
        "data": "source_0",
        "fields": ["min_Horsepower", "max_Horsepower"]
      },
      "range": [{"signal": "height"}, 0],
      "nice": true,
      "zero": true
    }
  ],
  "axes": [
    {
      "scale": "y",
      "orient": "left",
      "gridScale": "x",
      "grid": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "domain": false,
      "labels": false,
      "aria": false,
      "maxExtent": 0,
      "minExtent": 0,
      "ticks": false,
      "zindex": 0
    },
    {
      "scale": "x",
      "orient": "bottom",
      "grid": false,
      "title": "Origin",
      "labelAlign": "right",
      "labelAngle": 270,
      "labelBaseline": "middle",
      "zindex": 0
    },
    {
      "scale": "y",
      "orient": "left",
      "grid": false,
      "title": "Min of Horsepower, Max of Horsepower",
      "labelOverlap": true,
      "tickCount": {"signal": "ceil(height/40)"},
      "zindex": 0
    }
  ]
}