embed({
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
width: 500,
height: 300,
layer: [
{
data: {
url: "https://mjlobo.github.io/teaching/eivp/departements.json",
format: {
type: "topojson",
feature: "departements"
}
},
projection: {
type: "mercator"
},
mark: {
type: "geoshape",
fill: "lightgray",
stroke: "white"
}
},
{
data: {
values: trainsByStations.objects()
},
params: [{name: "paintbrush",select: {type: "point", "on": "mouseover", "fields": ["arrival_station"]}, "nearest": true}],
transform: [
{aggregate: [{op: "count", as: "routes"}], groupby: ["arrival_station"]},
{
lookup: "arrival_station",
from: {
data: {values: gares.objects()},
key: "LIBELLE",
fields: ["X_WGS84", "Y_WGS84"]
}
},
{filter: "datum.X_WGS84 != null && datum.Y_WGS84 != null"}
],
projection: {
type: "mercator"
},
mark: {type: "point"},
encoding: {
longitude: {
field: "X_WGS84",
type: "quantitative"
},
latitude: {
field: "Y_WGS84",
type: "quantitative"
},
tooltip: {field: "arrival_station", "type": "nominal"},
size: {
condition: {"param": "paintbrush", "value": 300, "empty": false},
value: 50
},
color: {"value": "steelblue"}
}
},
{
data: {
values: trainsByStations.objects()
},
transform: [
{
lookup: "departure_station",
from: {
data: {values: gares.objects()},
key: "LIBELLE",
fields: ["X_WGS84", "Y_WGS84"],
},
//as: ["X_WGS84_departure", "Y_WGS84_departure"]
},
{
lookup: "arrival_station",
from: {
data: {values: gares.objects()},
key: "LIBELLE",
fields: ["X_WGS84", "Y_WGS84"],
},
as: ["X_WGS84_arrival", "Y_WGS84_arrival"]
},
{
filter: {
param: "paintbrush",
//"empty": false
}
},
{filter: "datum.X_WGS84!= null && datum.Y_WGS84 != null && datum.X_WGS84_arrival!= null && datum.Y_WGS84_arrival != null"},
],
projection: {
type: "mercator"
},
mark: "rule",
encoding: {
longitude: {
field: "X_WGS84",
type: "quantitative"
},
latitude: {
field: "Y_WGS84",
type: "quantitative"
},
longitude2: {
field: "X_WGS84_arrival",
type: "quantitative"
},
latitude2: {
field: "Y_WGS84_arrival",
type: "quantitative"
},
// color: {"value": "steelblue"},
color: {
field: "total_num_trips",
type: "quantitative"
}
}
}
]
})