Skip to content

Instantly share code, notes, and snippets.

@nyurik
Created July 21, 2017 01:15
Show Gist options
  • Save nyurik/96ab0d0d19d4c3aee83b0250fbb9335c to your computer and use it in GitHub Desktop.
Save nyurik/96ab0d0d19d4c3aee83b0250fbb9335c to your computer and use it in GitHub Desktop.
{
$schema: https://vega.github.io/schema/vega/v3.0.json
_hostConfig:
{
type: map
delayRepaint: false
latitude: 52
longitude: 0
zoom: 7
}
data:
[
{
name: accidents
url:
{
index: uk_accidents
body:
{
size: 0
query:
{
bool:
{
must:
[
{
range:
{
Date: {%timefilter%: true}
}
}
]
}
}
aggs:
{
authorities:
{
terms: {field: "Local_Authority_(District).keyword", size: 10}
aggs:
{
center:
{
geo_centroid: {field: "location"}
}
roadtype:
{
terms: {field: "Road_Type.keyword", size: 10}
}
}
}
}
}
}
format: {type: "json", property: "aggregations.authorities.buckets"}
transform:
[
{
type: geopoint
projection: projection
fields: ["center.location.lon", "center.location.lat"]
}
]
}
]
scales:
[
{
name: size
type: linear
domain: {data: "accidents", field: "doc_count"}
range: [10, 20]
}
{
name: zoomscale
type: pow
domain: [2, 18]
range: [1, 3]
}
{
name: colors
type: ordinal
domain:
[
Dual carriageway
One way street
Roundabout
Single carriageway
Slip road
Unknown
]
range: {scheme: "category10"}
}
]
marks:
[
{
type: group
from:
{
facet: {name: "roadTypes", data: "accidents", field: "roadtype.buckets"}
}
data:
[
{
name: pies
source: roadTypes
transform:
[
{type: "pie", field: "doc_count"}
]
}
]
encode:
{
update:
{
width: {scale: "size", field: "doc_count"}
height: {scale: "size", field: "doc_count"}
xc: {field: "x"}
yc: {field: "y"}
}
}
marks:
[
{
from: {data: "pies"}
type: arc
encode:
{
enter:
{
x:
{
field: {group: "width"}
mult: 0.5
}
y:
{
field: {group: "height"}
mult: 0.5
}
startAngle: {field: "startAngle"}
endAngle: {field: "endAngle"}
innerRadius: {value: 0}
outerRadius:
{
signal: scale('size', parent.doc_count)*scale('zoomscale', zoom)
}
stroke: {value: "#fff"}
}
update:
{
fill: {scale: "colors", field: "key"}
}
hover:
{
fill: {value: "pink"}
}
}
}
]
}
]
legends:
[
{
fill: colors
title: Road Types
orient: none
padding: {value: 8}
titlePadding: {value: 10}
encode:
{
legend:
{
enter:
{
x: {value: 54}
y: {value: 10}
fill: {value: "#fff"}
stroke: {value: "#000"}
opacity: {value: 0.7}
}
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment