Published
Edited
Aug 28, 2020
Insert cell
Insert cell
Insert cell
Insert cell
// Here the query is constructed as a Javascript object which is easier to view and edit in this notebook. The json version is printed below
filterCountryGermany = ({
exactSearch: [ { column: ["location"]}, "Germany" ]
})
Insert cell
Insert cell
recordsGermany = getDataFiltered(filterCountryGermany)
Insert cell
vl.markCircle()
.data(recordsGermany.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
filterDatasetsByName = ({
exactSearch: [
{ systemColumn: ["name"] },
"COVID-19 complete dataset by Our World In Data"
]
})
Insert cell
Insert cell
datasetsNameSearchResult = getDatasetsFiltered(filterDatasetsByName)
Insert cell
datasetsNameSearchResult.results[0]
Insert cell
Insert cell
Insert cell
searchAnyWhereUnited = ({
searchAnywhere: [ "United" ]
})
Insert cell
Insert cell
searchAnywhereUnited = getDataFiltered(searchAnyWhereUnited)
Insert cell
vl.markCircle()
.data(searchAnywhereUnited.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
filterExactCountryUnitedStates = ({
exactSearch: [ { column: ["location"]}, "United States" ]
})
Insert cell
Insert cell
recordsExactUnitedStates = getDataFiltered(filterExactCountryUnitedStates)
Insert cell
vl.markCircle()
.data(recordsExactUnitedStates.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
filterFuzzyCountryStates = ({
fuzzySearch: [ { column: ["location"]}, "States" ]
})
Insert cell
Insert cell
recordsFuzzyCountryStates = getDataFiltered(filterFuzzyCountryStates)
Insert cell
vl.markCircle()
.data(recordsFuzzyCountryStates.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
Insert cell
filterEquals100Cases = ({
eq: [ { column: ["new_cases"]}, 100 ]
})
Insert cell
Insert cell
recordsEquals100Cases = getDataFiltered(filterEquals100Cases)
Insert cell
vl.markCircle()
.data(recordsEquals100Cases.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
filterGt50000Cases = ({
gt: [ { column: ["new_cases"]}, 50000 ]
})
Insert cell
Insert cell
recordsGt50000Cases = getDataFiltered(filterGt50000Cases)
Insert cell
vl.markCircle()
.data(recordsGt50000Cases.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
Insert cell
filterLt50CasesGermany = ({
and: [
{lt: [ { column: ["new_cases"]}, 50]},
{exactSearch: [ { column: ["location"]}, "Germany"]}
]
})
Insert cell
Insert cell
recordsLt50CasesGermany = getDataFiltered(filterLt50CasesGermany)
Insert cell
vl.markCircle()
.data(recordsLt50CasesGermany.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
keywordsContainsUsa = ({contains: [ {"column": ["keywords"]}, ["covid-19"] ] })

Insert cell
Insert cell
datasetsWithKeywordUsa = getDatasetsFilteredWithMapping(keywordsContainsUsa, [{name: "keywords", jsonPath: "$.keywords[*]", dataType: "xsd:string"}])
Insert cell
Insert cell
Insert cell
operatorNot = ({not: [ {lt: [{"column": ["new_cases"]}, 50000 ]}] })
Insert cell
Insert cell
operatorNotCases = getDataFiltered(operatorNot)
Insert cell
vl.markCircle()
.data(operatorNotCases.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
md`##### And/Or`
Insert cell
andOrOperators = ({
and: [
{gt: [ { column: ["new_cases"]}, 2000]},
{or: [
{ exactSearch: [ { column: ["location"]}, "Germany"]},
{ exactSearch: [ { column: ["location"]}, "Italy"]}
]}
]
})
Insert cell
JSON.stringify(andOrOperators)
Insert cell
operatorAndOrCases = getDataFiltered(andOrOperators)
Insert cell
vl.markCircle()
.data(operatorAndOrCases.results.map(record => record.data))
.encode(
vl.x().field("date").type("temporal"),
vl.y().field("new_cases").type("quantitative"),
vl.color().field("location")
)
.render()
Insert cell
Insert cell
similarityCutoffSearch = ({
gt: [{ tanimotoSimilarity: ["c1ccccc1", { column: ["SMILES"] }] }, 0.4]
})
Insert cell
Insert cell
similaritySearchResponse = getChemicalDataFiltered(similarityCutoffSearch)
Insert cell
Insert cell
substructureSearch = ({
substructureSearch: ["c1ccccc1", { column: ["SMILES"] }]
})
Insert cell
Insert cell
substructureSearchResponse = getChemicalDataFiltered(substructureSearch)
Insert cell
Insert cell
castFilter = ({
gt: [{cast: [{ column: ["new_cases"] }, "xsd:integer"]}, 50000]
})
Insert cell
Insert cell
castedNewCasesData = getDataFiltered(castFilter)
Insert cell
Insert cell
edelweissUrl = "https://api.edelweissdata.com"
Insert cell
datasetUrl = "https://api.edelweissdata.com/datasets/b55b229d-6338-4e41-a507-0cf4d3297b54/versions/latest/data"
Insert cell
chemicalDatasetUrl = "https://api.edelweissdata.com/datasets/2940e662-0ba1-4d8a-927d-03689808e99d/versions/1/data"
Insert cell
getDataFiltered = function(query) {
const encodedQuery = JSON.stringify({condition: query})
let url = new URL(datasetUrl)
url.searchParams.append('query', encodedQuery);
return fetch(url).then(response => response.json())
}
Insert cell
getChemicalDataFiltered = function(query) {
const encodedQuery = JSON.stringify({condition: query})
let url = new URL(chemicalDatasetUrl)
url.searchParams.append('query', encodedQuery);
return fetch(url).then(response => response.json())
}

Insert cell
getDatasetsFiltered = function(query) {
const encodedQuery = JSON.stringify({condition: query})
let url = new URL(`${edelweissUrl}/datasets`)
url.searchParams.append('query', encodedQuery);
return fetch(url).then(response => response.json())
}
Insert cell
getDatasetsFilteredWithMapping = function(query, mapping) {
const encodedQuery = JSON.stringify({condition: query, columns: mapping})
let url = new URL(`${edelweissUrl}/datasets`)
url.searchParams.append('query', encodedQuery);
return fetch(url).then(response => response.json())
}
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more