{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "An interactive visualization of connections among major U.S. airports in 2008. Based on a U.S. airports example by Mike Bostock.", "background": "white", "padding": 5, "width": 900, "height": 500, "data": [ {"name": "org_store"}, { "name": "source_0", "url": "data/us-10m.json", "format": {"type": "topojson", "feature": "states"} }, { "name": "source_1", "url": "data/flights-airport.csv", "format": {"type": "csv"} }, {"name": "source_2", "url": "data/airports.csv", "format": {"type": "csv"}}, { "name": "data_0", "source": "source_1", "transform": [ { "type": "filter", "expr": "length(data(\"org_store\")) && vlSelectionTest(\"org_store\", datum)" }, { "type": "lookup", "from": "source_2", "key": "iata", "fields": ["origin"], "values": ["latitude", "longitude"] }, { "type": "lookup", "from": "source_2", "key": "iata", "fields": ["destination"], "values": ["latitude", "longitude"], "as": ["lat2", "lon2"] }, { "type": "geojson", "fields": ["longitude", "latitude"], "signal": "layer_1_geojson_0" }, { "type": "geojson", "fields": ["lon2", "lat2"], "signal": "layer_1_geojson_1" }, { "type": "geopoint", "projection": "projection", "fields": ["longitude", "latitude"], "as": ["layer_1_x", "layer_1_y"] }, { "type": "geopoint", "projection": "projection", "fields": ["lon2", "lat2"], "as": ["layer_1_x2", "layer_1_y2"] } ] }, { "name": "data_1", "source": "source_1", "transform": [ { "type": "aggregate", "groupby": ["origin"], "ops": ["count"], "fields": [null], "as": ["routes"] }, { "type": "lookup", "from": "source_2", "key": "iata", "fields": ["origin"], "values": ["state", "latitude", "longitude"] }, { "type": "filter", "expr": "datum.state !== 'PR' && datum.state !== 'VI'" }, { "type": "geojson", "fields": ["longitude", "latitude"], "signal": "layer_2_geojson_0" }, { "type": "geopoint", "projection": "projection", "fields": ["longitude", "latitude"], "as": ["layer_2_x", "layer_2_y"] }, { "type": "filter", "expr": "isValid(datum[\"routes\"]) && isFinite(+datum[\"routes\"])" } ] } ], "projections": [ { "name": "projection", "size": {"signal": "[width, height]"}, "fit": { "signal": "[data('source_0'), layer_1_geojson_0, layer_1_geojson_1, layer_2_geojson_0]" }, "type": "albersUsa" } ], "signals": [ { "name": "unit", "value": {}, "on": [ {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} ] }, { "name": "org", "update": "vlSelectionResolve(\"org_store\", \"union\", true, true)" }, { "name": "org_tuple", "on": [ { "events": [ { "source": "scope", "type": "mouseover", "markname": "layer_2_voronoi" } ], "update": "datum && item().mark.marktype !== 'group' ? {unit: \"layer_2\", fields: org_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"origin\"]]} : null", "force": true }, {"events": [{"source": "view", "type": "dblclick"}], "update": "null"} ] }, {"name": "org_tuple_fields", "value": [{"type": "E", "field": "origin"}]}, { "name": "org_toggle", "value": false, "on": [ { "events": [ { "source": "scope", "type": "mouseover", "markname": "layer_2_voronoi" } ], "update": "event.shiftKey" }, {"events": [{"source": "view", "type": "dblclick"}], "update": "false"} ] }, { "name": "org_modify", "on": [ { "events": {"signal": "org_tuple"}, "update": "modify(\"org_store\", org_toggle ? null : org_tuple, org_toggle ? null : true, org_toggle ? org_tuple : null)" } ] } ], "marks": [ { "name": "layer_0_marks", "type": "shape", "style": ["geoshape"], "interactive": false, "from": {"data": "source_0"}, "encode": { "update": { "fill": {"value": "#ddd"}, "stroke": {"value": "#fff"}, "strokeWidth": {"value": 1}, "ariaRoleDescription": {"value": "geoshape"} } }, "transform": [{"type": "geoshape", "projection": "projection"}] }, { "name": "layer_1_marks", "type": "rule", "style": ["rule"], "interactive": false, "from": {"data": "data_0"}, "encode": { "update": { "opacity": {"value": 0.35}, "stroke": {"value": "#000"}, "description": { "signal": "\"longitude: \" + (format(datum[\"longitude\"], \"\")) + \"; lon2: \" + (format(datum[\"lon2\"], \"\")) + \"; latitude: \" + (format(datum[\"latitude\"], \"\")) + \"; lat2: \" + (format(datum[\"lat2\"], \"\"))" }, "x": {"field": "layer_1_x"}, "x2": {"field": "layer_1_x2"}, "y": {"field": "layer_1_y"}, "y2": {"field": "layer_1_y2"} } } }, { "name": "layer_2_marks", "type": "symbol", "style": ["circle"], "sort": {"field": ["datum[\"routes\"]"], "order": ["descending"]}, "interactive": true, "from": {"data": "data_1"}, "encode": { "update": { "opacity": {"value": 0.7}, "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "circle"}, "description": { "signal": "\"longitude: \" + (format(datum[\"longitude\"], \"\")) + \"; latitude: \" + (format(datum[\"latitude\"], \"\")) + \"; routes: \" + (format(datum[\"routes\"], \"\"))" }, "x": {"field": "layer_2_x"}, "y": {"field": "layer_2_y"}, "size": {"scale": "size", "field": "routes"}, "shape": {"value": "circle"} } } }, { "name": "layer_2_voronoi", "type": "path", "interactive": true, "from": {"data": "layer_2_marks"}, "encode": { "update": { "fill": {"value": "transparent"}, "strokeWidth": {"value": 0.35}, "stroke": {"value": "transparent"}, "isVoronoi": {"value": true} } }, "transform": [ { "type": "voronoi", "x": {"expr": "datum.datum.x || 0"}, "y": {"expr": "datum.datum.y || 0"}, "size": [{"signal": "width"}, {"signal": "height"}] } ] } ], "scales": [ { "name": "size", "type": "linear", "domain": {"data": "data_1", "field": "routes"}, "range": [0, 1000], "zero": true } ] }