Skip to content

Instantly share code, notes, and snippets.

@kanitw
Created November 30, 2015 21:46
Show Gist options
  • Save kanitw/79cbd4c2e913956138bc to your computer and use it in GitHub Desktop.
Save kanitw/79cbd4c2e913956138bc to your computer and use it in GitHub Desktop.
{
"width": 200,
"height": 200,
"padding": "auto",
"data": [
{
"name": "source",
"url": "data/cars.json",
"format": {"type": "json","parse": {"Acceleration": "number"}},
"transform": [
{
"type": "filter",
"test": "datum.Acceleration!==null"
}
]
},
{
"name": "summary",
"source": "source",
"transform": [
{
"type": "aggregate",
"groupby": ["Cylinders"],
"summarize": {"Acceleration": ["mean"]}
}
]
},
{
"name": "layout",
"source": "summary",
"transform": [
{
"type": "aggregate",
"summarize": [{"field": "Cylinders","ops": ["distinct"]}]
},
{
"type": "formula",
"field": "cellWidth",
"expr": "(datum.distinct_Cylinders + 1) * 21"
}
]
}
],
"marks": [
{
"name": "root",
"type": "group",
"from": {"data": "layout"},
"properties": {
"update": {
"width": {"field": "cellWidth"},
"height": {"value": 200}
}
},
"marks": [
{
"type": "rect",
"properties": {
"update": {
"xc": {"scale": "x","field": "Cylinders"},
"width": {"value": 21,"offset": -1},
"y": {"scale": "y","field": "mean_Acceleration"},
"y2": {"field": {"group": "height"}},
"fill": {"value": "#4682b4"}
}
},
"from": {"data": "summary"}
}
],
"scales": [
{
"name": "x",
"type": "ordinal",
"domain": {
"data": "summary",
"field": "Cylinders",
"sort": true
},
"rangeMin": 0,
"rangeMax": {"data": "layout","field": "cellWidth"},
"round": true,
"clamp": true,
"bandWidth": 21,
"padding": 1,
"points": true
},
{
"name": "y",
"type": "linear",
"domain": {
"data": "summary",
"field": "mean_Acceleration",
"sort": true
},
"rangeMin": 200,
"rangeMax": 0,
"round": true,
"clamp": true,
"nice": true
}
],
"axes": [
{
"type": "x",
"scale": "x",
"grid": false,
"ticks": 5,
"title": "Cylinders",
"properties": {
"labels": {
"angle": {"value": 270},
"align": {"value": "right"},
"baseline": {"value": "middle"},
"text": {"template": "{{ datum.data | truncate:25}}"}
}
}
},
{
"type": "y",
"scale": "y",
"format": "s",
"grid": true,
"layer": "back",
"title": "MEAN(Acceleration)"
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment