{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 600,
  "height": 360,
  "autosize": "fit",
  "data": [
    {
      "name": "table",
      "url": "<%= dataset_url %>"

    }
  ],
  "scales": [
    {
      "name": "yscale",
      "type": "band",
      "domain": {
        "data": "table",
        "field": "<%= data_mapper.column_1 %>"
      },
      "range": "height",
      "padding": 0.4,
      "round": true,
      "nice": true
    },
    {
      "name": "xscale",
      "domain": {
        "data": "table",
        "field": "<%= data_mapper.column_2 %>"
      },
      "nice": true,
      "range": "width"
    }
  ],
  "marks": [
    {
      "name": "bars",
      "type": "rect",
      "from": {
        "data": "table"
      },
      "encode": {
        "enter": {
          "x": {
            "scale": "xscale",
            "field": "<%= data_mapper.column_2 %>"
          },
          "height": {
            "scale": "yscale",
            "band": 1
          },
          "y": {
            "scale": "yscale",
            "field": "<%= data_mapper.column_1 %>"
          },
          "x2": {
            "scale": "xscale",
            "value": 0
          },
          "fill": {
            "signal": "datum.<%= data_mapper.column_2 %> > 0 ? 'green' : 'red'"
          }
        }
      }
    },
    {
      "name": "item_score",
      "type": "text",
      "from": {
        "data": "table"
      },
      "encode": {
        "enter": {
          "x": {
            "scale": "xscale",
            "field": "<%= data_mapper.column_2 %>"
          },
          "y": {
            "scale": "yscale",
            "field": "<%= data_mapper.column_1 %>"
          },
          "dx": {
            "signal": "datum.<%= data_mapper.column_2 %> > 0 ? 10 : -10"
          },
          "dy": {
            "signal": "bandwidth('yscale')/1.5"
          },
          "align": {
            "value": "center"
          },
          "fill": {
            "value": "#000000"
          },
          "text": {
            "field": "<%= data_mapper.column_2 %>"
          },
          "fontSize": {
            "value": 12
          }
        }
      }
    },
    {
      "name": "item_name",
      "type": "text",
      "from": {
        "data": "table"
      },
      "encode": {
        "enter": {
          "y": {
            "scale": "yscale",
            "field": "<%= data_mapper.column_1 %>"
          },
          "dy": {
            "signal": "bandwidth('yscale')/1.5"
          },
          "dx": {
            "signal": "datum.<%= data_mapper.column_2 %> > 0 ? width/2-20 : width/2+20"
          },
          "align": {
            "value": "center"
          },
          "fill": {
            "value": "#000000"
          },
          "text": {
            "field": "<%= data_mapper.column_1 %>"
          },
          "fontSize": {
            "value": 12
          }
        }
      }
    }
  ]
}
