{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "width": 600,
  "height": 360,
  "autosize": "fit",
  "signals": [
    {
      "name": "colorChange",
      "value": "Positive",
      "bind": {
        "input": "radio",
        "options": [
          "Negative",
          "Positive"
        ]
      }
    }
  ],
  "data": [
    {
      "name": "data_table",
      "url": "<%= absolute_url %>data/wordcloud.json",
      "transform": [
        {
          "type": "extent",
          "field": "<%= data_mapper.column_2 %>",
          "signal": "P_extent"
        },
        {
          "type": "extent",
          "field": "['<%= data_mapper.column_3 %>']",
          "signal": "N_extent"
        },
        {
          "type": "wordcloud",
          "size": [
            {
              "signal": "width"
            },
            {
              "signal": "height"
            }
          ],
          "text": {
            "field": "<%= data_mapper.column_1 %>"
          },
          "rotate": 0,
          "fontSizeRange": [
            25,
            50
          ],
          "font": "Roboto"
        }
      ]
    }
  ],
  "scales": [
    {
      "name": "scales_color",
      "type": "ordinal",
      "domain": {
        "data": "data_table",
        "field": "<%= data_mapper.column_1 %>"
      },
      "range": {
        "scheme": {
          "signal": "colorChange == 'Negative'? 'reds': 'greens'"
        }
      }
    }
  ],
  "marks": [
    {
      "type": "text",
      "from": {
        "data": "data_table"
      },
      "encode": {
        "enter": {
          "text": {
            "field": "<%= data_mapper.column_1 %>"
          },
          "align": {
            "value": "center"
          },
          "baseline": {
            "value": "alphabetic"
          },
          "fillOpacity": {
            "value": 1
          }
        },
        "update": {
          "x": {
            "field": "x"
          },
          "y": {
            "field": "y"
          },
          "fill": {
            "scale": "scales_color",
            "field": "<%= data_mapper.column_1 %>"
          },
          "fontSize": {
            "signal": "colorChange == 'Positive' ? (datum['<%= data_mapper.column_2 %>']/P_extent[0]) * 2 : (datum['<%= data_mapper.column_3 %>']/N_extent[0]) * 2"
          }
        },
        "hover": {
          "zindex": 100,
          "fontSize": {
            "value": 30
          },
          "fill": {
            "value": "black"
          }
        }
      }
    }
  ]
}