Skip to content

Instantly share code, notes, and snippets.

@maartenzam
Created June 1, 2017 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maartenzam/e504c47913bed4afa1e01fcb74aca0a9 to your computer and use it in GitHub Desktop.
Save maartenzam/e504c47913bed4afa1e01fcb74aca0a9 to your computer and use it in GitHub Desktop.
Scale a Vega area marker
{
"$schema": "https://vega.github.io/schema/vega/v3.0.json",
"width": 800,
"height": 400,
"padding": 5,
"signals": [
{
"name": "defined", "value": true,
"bind": {"input": "checkbox"}
},
{
"name": "interpolate", "value": "linear",
"bind": {
"input": "select",
"options": [
"basis",
"cardinal",
"catmull-rom",
"linear",
"monotone",
"natural",
"step",
"step-after",
"step-before"
]
}
},
{
"name": "tension", "value": 0,
"bind": {"input": "range", "min": 0, "max": 1, "step": 0.05}
},
{
"name": "w", "value": 300,
"bind": {"input": "range", "min": 100, "max": 800, "step": 1}
},
{
"name": "h", "value": 400,
"bind": {"input": "range", "min": 10, "max": 400, "step": 1}
}
],
"data": [
{
"name": "table",
"values": [
{"u": 1, "v": 28}, {"u": 2, "v": 55},
{"u": 3, "v": 42}, {"u": 4, "v": 34},
{"u": 5, "v": 36}, {"u": 6, "v": 48}
]
}
],
"scales": [
{
"name": "xscale",
"type": "linear",
"range": {"signal": "[0,w]" },
"zero": false,
"domain": {"data": "table", "field": "u"}
},
{
"name": "yscale",
"type": "linear",
"range": {"signal": "[h,0]" },
"nice": true,
"zero": true,
"domain": {"data": "table", "field": "v"}
}
],
"marks": [
{
"type": "area",
"from": {"data": "table"},
"encode": {
"enter": {
"fill": {"value": "blue"}
},
"update": {
"x": {"scale": "xscale", "field": "u"},
"y": {"scale": "yscale", "field": "v"},
"y2": {"scale": "yscale", "value": "0"},
"defined": {"signal": "defined || datum.u !== 3"},
"interpolate": {"signal": "interpolate"},
"tension": {"signal": "tension"},
"opacity": {"value": 1}
},
"hover": {
"opacity": {"value": 0.5}
}
}
}
]
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Vega scale area marker</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega/3.0.0-beta.32/vega.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-lite/2.0.0-beta.3/vega-lite.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vega-embed/3.0.0-beta.14/vega-embed.js"></script>
</head>
<body>
<div id="vis"></div>
<script>
var opt = {
"renderer" : "svg",
"actions" : {export: true, source: false, editor: false},
}
vega.embed('#vis', 'area.json', opt);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment