Skip to content

Commit

Permalink
example: airport connections
Browse files Browse the repository at this point in the history
  • Loading branch information
brucala committed Jul 4, 2023
1 parent 3823e76 commit 0229dcd
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions docs/examples/interactive/airport_connections.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ---
# cover: assets/airport_connections.png
# author: bruno
# description: Connections among US Airports
# ---

using Deneb

usa = Data(
url="https://vega.github.io/vega-datasets/data/us-10m.json",
format=(type=:topojson, feature=:states),
)
flights = Data(url="https://vega.github.io/vega-datasets/data/flights-airport.csv")
airports = (
data=(; url="https://vega.github.io/vega-datasets/data/airports.csv"),
key=:iata,
fields=[:state, :latitude, :longitude],
)


base = projection("albersUsa") * vlspec(width=750, height=500)

background = usa * Mark(
:geoshape, fill=:lightgray, stroke=:white
)

connections = flights * Mark(:rule, opacity=0.35) * transform_filter(
(param=:org, empty=false),
) * transform_lookup(
:origin, airports,
) * transform_lookup(
:destination, airports; as=[:state, :lat2, :lon2],
) * Encoding(
longitude=:longitude,
latitude=:latitude,
longitude2=:lon2,
latitude2=:lat2,
)

points = flights * Mark(:circle) * select_point(
:org, on=:mouseover, nearest=true, fields=[:origin], empty=false,
) * transform_aggregate(
routes="count()",
groupby=:origin,
) * transform_lookup(
:origin, airports,
) * transform_filter(
"datum.state !== 'PR' && datum.state !== 'VI'"
)* Encoding(
longitude=:longitude,
latitude=:latitude,
size=field("routes:Q", scale=(; range=[0, 1000]), legend=nothing),
order=field("routes:Q", sort="descending"),
tooltip=[field("origin:N"), field("routes:Q")],
)


chart = base * (background + connections + points)

# save cover #src
save("assets/airport_connections.png", chart) #src

0 comments on commit 0229dcd

Please sign in to comment.