Skip to content

Instantly share code, notes, and snippets.

@tjws052009
Last active March 24, 2021 06:51
Show Gist options
  • Save tjws052009/2d5eb49feeb0ec08fb984cf1c2f3485c to your computer and use it in GitHub Desktop.
Save tjws052009/2d5eb49feeb0ec08fb984cf1c2f3485c to your computer and use it in GitHub Desktop.
Vega experiment
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 500,
"height": 500,
"title": "Test heatmap",
"data": [
{
"name": "input",
"values": [
{"x": 0, "y": 0, "val": 0},
{"x": 0, "y": 1, "val": 1},
{"x": 0, "y": 2, "val": 3},
{"x": 1, "y": 0, "val": 0},
{"x": 1, "y": 1, "val": 3},
{"x": 1, "y": 2, "val": 3},
{"x": 2, "y": 0, "val": 1},
{"x": 2, "y": 1, "val": 4},
{"x": 2, "y": 2, "val": 5}
]
}
],
"signals": [
{"name": "rectwidth", "update": "width / 3"},
{"name": "rectheight", "update": "height / 3"},
{"name": "xrange", "update": "[0, width]"},
{"name": "yrange", "update": "[height, 0]"}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "input", "field": "x"},
"range": {"signal": "xrange"}
},
{
"name": "yscale",
"type": "band",
"domain": {"data": "input", "field": "y"},
"range": {"signal": "yrange"}
},
{
"name": "color",
"domain": {"data": "input", "field": "val"},
"type": "linear",
"range": {"scheme": "orangered"}
}
],
"axes": [
{"scale": "xscale", "orient": "bottom", "tickMinStep": 1},
{"scale": "yscale", "orient": "left", "tickMinStep": 1}
],
"marks": [
{
"type": "rect",
"from": {"data": "input"},
"encode": {
"enter": {
"fill": {"scale": "color", "field": "val"},
"x": {"scale": "xscale", "field": "x"},
"y": {"scale": "yscale", "field": "y"}
},
"update": {
"width": {"signal": "rectwidth"},
"height": {"signal": "rectheight"}
}
}
},
{
"type": "text",
"from": {"data": "input"},
"encode": {
"enter": {
"align": {"value": "center"},
"baseline": {"value": "middle"},
"text": {"field": "val"},
"fontSize": {"value": 20},
"x": {"scale": "xscale", "field": "x"},
"y": {"scale": "yscale", "field": "y"},
"dx": {"signal": "rectwidth / 2"},
"dy": {"signal": "rectheight / 2"}
}
}
}
]
}