Skip to content

Instantly share code, notes, and snippets.

@nyurik
Created May 9, 2018 03:14
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 nyurik/789fcac0beafa803708c2afcfd8c45ab to your computer and use it in GitHub Desktop.
Save nyurik/789fcac0beafa803708c2afcfd8c45ab to your computer and use it in GitHub Desktop.
{
$schema: https://vega.github.io/schema/vega/v3.0.json
config: {
kibana: {type: "map", latitude: 25, longitude: -70, zoom: 3}
}
data: [
{
name: table
url: {
index: kibana_sample_data_flights
%context%: true
// Uncomment to enable time filtering
// %timefield%: timestamp
body: {
size: 0
aggs: {
origins: {
terms: {field: "OriginAirportID", size: 10000}
aggs: {
originLocation: {
top_hits: {
size: 1
_source: {
includes: ["OriginLocation", "Origin"]
}
}
}
distinations: {
terms: {field: "DestAirportID", size: 10000}
aggs: {
destLocation: {
top_hits: {
size: 1
_source: {
includes: ["DestLocation"]
}
}
}
}
}
}
}
}
}
}
format: {property: "aggregations.origins.buckets"}
transform: [
{
type: geopoint
projection: projection
fields: [
originLocation.hits.hits[0]._source.OriginLocation.lon
originLocation.hits.hits[0]._source.OriginLocation.lat
]
}
]
}
{
name: selectedDatum
on: [
{trigger: "!selected", remove: true}
{trigger: "selected", insert: "selected"}
]
}
]
signals: [
{
name: selected
value: null
on: [
{events: "@airport:mouseover", update: "datum"}
{events: "@airport:mouseout", update: "null"}
]
}
]
scales: [
{
name: airportSize
type: linear
domain: {data: "table", field: "doc_count"}
range: [
{signal: "zoom*zoom*0.2+1"}
{signal: "zoom*zoom*10+1"}
]
}
]
marks: [
{
type: group
from: {
facet: {
name: facetedDatum
data: selectedDatum
field: distinations.buckets
}
}
data: [
{
name: facetDatumElems
source: facetedDatum
transform: [
{
type: geopoint
projection: projection
fields: [
destLocation.hits.hits[0]._source.DestLocation.lon
destLocation.hits.hits[0]._source.DestLocation.lat
]
}
{type: "formula", expr: "{x:parent.x, y:parent.y}", as: "source"}
{type: "formula", expr: "{x:datum.x, y:datum.y}", as: "target"}
{type: "linkpath", shape: "diagonal"}
]
}
]
scales: [
{
name: lineThickness
type: linear
domain: {data: "facetDatumElems", field: "doc_count"}
range: [1, 8]
}
{
name: lineOpacity
type: linear
domain: {data: "facetDatumElems", field: "doc_count"}
range: [0.2, 0.8]
}
]
marks: [
{
from: {data: "facetDatumElems"}
type: path
interactive: false
encode: {
update: {
path: {field: "path"}
stroke: {value: "black"}
strokeWidth: {scale: "lineThickness", field: "doc_count"}
strokeOpacity: {scale: "lineOpacity", field: "doc_count"}
}
}
}
]
}
{
name: airport
type: symbol
from: {data: "table"}
encode: {
update: {
size: {scale: "airportSize", field: "doc_count"}
xc: {signal: "datum.x"}
yc: {signal: "datum.y"}
tooltip: {
signal: "{title: datum.originLocation.hits.hits[0]._source.Origin + ' (' + datum.key + ')', connnections: length(datum.distinations.buckets), flights: datum.doc_count}"
}
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment