{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 600,
  "height": 360,
  "autosize": "fit",
  "data": [
    {
      "name": "pyramid_data1",
      "url": "<%= dataset_url %>",
      "transform": [
        {
          "type": "stack",
          "groupby": [
            "<%= data_mapper.column_1 %>"
          ],
          "sort": {
            "field": "<%= data_mapper.column_2 %>"
          },
          "field": "<%= data_mapper.column_2 %>",
          "offset": "center",
          "as": [
            "amount1",
            "amount2"
          ]
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "py_xscale",
      "type": "linear",
      "domain": {
        "data": "pyramid_data1",
        "field": "amount2"
      },
      "range": "width"
    },
    {
      "name": "py_yscale",
      "type": "band",
      "domain": {
        "data": "pyramid_data1",
        "field": "<%= data_mapper.column_1 %>"
      },
      "range": "height"
    }
  ],
  "marks": [
    {
      "name": "bars",
      "type": "rect",
      "from": {
        "data": "pyramid_data1"
      },
      "encode": {
        "enter": {
          "y": {
            "scale": "py_yscale",
            "field": "<%= data_mapper.column_1 %>"
          },
          "height": {
            "scale": "py_yscale",
            "band": 0.7
          },
          "x": {
            "scale": "py_xscale",
            "field": "amount1"
          },
          "x2": {
            "scale": "py_xscale",
            "field": "amount2"
          },
          "fill": {
            "value": "#FEC44F"
          }
        }
      }
    },
    {
      "name": "items_text",
      "type": "text",
      "from": {
        "data": "bars"
      },
      "encode": {
        "enter": {
          "x": {
            "field": "x"
          },
          "y": {
            "field": "y"
          },
          "dx": {
            "value": -20
          },
          "dy": {
            "value": 10
          },
          "fill": {
            "value": "black"
          },
          "title": {
            "value": "<%= data_mapper.column_1 %>"
          },
          "align": {
            "value": "center"
          },
          "baseline": {
            "value": "top"
          },
          "text": {
            "field": "datum['<%= data_mapper.column_1 %>']"
          }
        }
      }
    },
    {
      "name": "numbers",
      "type": "text",
      "from": {
        "data": "bars"
      },
      "encode": {
        "enter": {
          "x": {
            "field": "x",
            "offset": {
              "field": "width"
            }
          },
          "y": {
            "field": "y",
            "offset": {
              "field": "height"
            }
          },
          "dx": {
            "value": 15
          },
          "dy": {
            "value": -7
          },
          "fill": {
            "value": "black"
          },
          "title": {
            "value": "category"
          },
          "align": {
            "value": "center"
          },
          "baseline": {
            "value": "bottom"
          },
          "text": {
            "field": "datum['<%= data_mapper.column_2 %>']"
          }
        }
      }
    }
  ]
}
