Skip to content

Instantly share code, notes, and snippets.

@thomas-maschler
Created July 26, 2018 03:10
Show Gist options
  • Save thomas-maschler/73c60f05ba6e5ef9d2abb82b9ec94223 to your computer and use it in GitHub Desktop.
Save thomas-maschler/73c60f05ba6e5ef9d2abb82b9ec94223 to your computer and use it in GitHub Desktop.
using signal in URL
{
"$schema": "https://vega.github.io/schema/vega/v4.json",
"width": 400,
"height": 200,
"padding": 5,
"title": "population trend",
"signals": [
{
"name": "Species",
"value": "Loxodonta cyclotis",
"bind": {
"input": "select",
"options": [
"Gorilla gorilla diehli",
"Loxodonta africana",
"Loxodonta cyclotis",
"Mandrillus leucophaeus",
"Osteolaemus tetraspis",
"Ovibus moschatus",
"Pan troglodytes",
"Panthera leo",
"Panthera onca",
"Panthera pardus",
"Panthera tigris altaica ",
"Panthera tigris",
"Picoides dorsalis",
"Pteropus voeltzikowi"
]
}
},
{
"name": "Site",
"value": "Lobeke NP",
"bind": {
"input": "select",
"options": [
"Azagny NP",
"Bailly swamps",
"Bangassou Forest Reserve",
"Banyang-Mbo Forest Reserve",
"Beki-boseemetie classified forest",
"Boumba-Bek Forest Reserve",
"Bwindi Impenetrable Forest NP",
"Campo-Ma'an landscape",
"Conkouati NP",
"Dzanga Bai",
"Dzanga-Sanga/Dzanga-Ndoki NP",
"Garamba NP",
"Ivindo NP plus its southern buffer",
"Kabo",
"Kahuzi Biega NP Lowland",
"Kahuzi Biega NP Upland",
"Korup NP",
"Lac Tele",
"Lobeke NP",
"Lope NP",
"Loundougou",
"Luama-Itombwe West Area",
"Maringa-Lopori area",
"Mbam et Djerem",
"Mengame WS",
"Minkebe NP",
"Mokabi",
"Mongokele Forest Reserve",
"Mt Cameroon",
"Ngoila Mintom",
"Ngombe concession and Ntokou Pikounda NP",
"Nki Forest Reserve",
"Nouabale-Ndoki NP",
"Okapi NP",
"Pokola",
"Salonga NP",
"Tai ecosystem"
]
}
},
{
"name": "address",
"value": "https://library.wcs.org/DesktopModules/WCSVega/API/Data/PopulationMeasure?taxa=Loxodonta cyclotis&site=Lobeke NP",
"update": "'https://library.wcs.org/DesktopModules/WCSVega/API/Data/PopulationMeasure?taxa=' + Species + '&site=' + Site"
},
{
"name": "tooltip",
"value": {},
"on": [
{
"events": "rect:mouseover",
"update": "datum"
},
{
"events": "rect:mouseout",
"update": "{}"
}
]
}
],
"data": [
{
"name": "table",
"url": {
"signal": "address"
},
"format": {
"type": "json",
"parse": "auto"
}
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {
"data": "table",
"field": "surveyYear"
},
"range": "width",
"padding": 0.05,
"round": true
},
{
"name": "yscale",
"domain": {
"data": "table",
"field": "siteAbundance"
},
"nice": true,
"range": "height"
}
],
"axes": [
{
"orient": "bottom",
"scale": "xscale",
"title": "Year"
},
{
"orient": "left",
"scale": "yscale",
"title": "Number"
}
],
"marks": [
{
"type": "rect",
"from": {
"data": "table"
},
"encode": {
"enter": {
"x": {
"scale": "xscale",
"field": "surveyYear"
},
"width": {
"scale": "xscale",
"band": 1
},
"y": {
"scale": "yscale",
"field": "siteAbundance"
},
"y2": {
"scale": "yscale",
"value": 0
}
},
"update": {
"fill": {
"value": "steelblue"
}
},
"hover": {
"fill": {
"value": "grey"
}
}
}
},
{
"type": "text",
"encode": {
"enter": {
"align": {
"value": "center"
},
"baseline": {
"value": "bottom"
},
"fill": {
"value": "#333"
}
},
"update": {
"x": {
"scale": "xscale",
"signal": "tooltip.surveyYear",
"band": 0.5
},
"y": {
"scale": "yscale",
"signal": "tooltip.siteAbundance",
"offset": -2
},
"text": {
"signal": "tooltip.siteAbundance"
},
"fillOpacity": [
{
"test": "datum === tooltip",
"value": 0
},
{
"value": 1
}
]
}
}
},
{
"type": "text",
"interactive": false,
"encode": {
"enter": {
"x": {
"value": 895
},
"y": {
"value": 0
},
"fill": {
"value": "black"
},
"fontSize": {
"value": 20
},
"align": {
"value": "right"
}
},
"update": {
"text": {
"signal": "address"
}
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment