Public
Edited
Mar 31, 2023
Insert cell
Insert cell
Insert cell
viewof selectedNodes = Inputs.radio(aq.from(papersAndAffiliations)._names)
Insert cell
Insert cell
viewof aggregateBy = Inputs.radio(aq.from(papersAndAffiliations)._names)
Insert cell
Insert cell
Insert cell
// import data as an array
dataArray = data.contents
Insert cell
//isolate criteria for link/node
papersAndAffiliations = dataArray
.map((p) =>
p.authors.map((a) => ({
paper: p.id,
author: a.personId,
affiliation: a.affiliations[0]?.institution,
city: a.affiliations[0]?.city,
country: a.affiliations[0]?.country
}))
)
.flat()
Insert cell
Insert cell
viewof test1 = get_links(papersAndAffiliations, "paper", "city")
Insert cell
test2 = aq
.from(test1)
.join(
test1,
(s, t) => s.paper === t.paper && s.city !== t.city && s.city < t.city,
[{ source: (d) => d.city }, { target: (d) => d.city }]
)
Insert cell
function getNodesHelper(data, attr) {
return papersAndAffiliationsDF.groupby(attr).count().view();
}
Insert cell
getNodesHelper(papersAndAffiliations, "affiliation")
Insert cell
function getLinksHelper(data, linkBy, nodeBy) {
return aq
.from(data)
.params({ nodeBy, linkBy })
.join(
data,
(s, t, $) =>
s[$.linkBy] === t[$.linkBy] &&
s[$.nodeBy] !== t[$.nodeBy] &&
s[$.nodeBy] < t[$.nodeBy]
// [
// { source: (d, $) => d[$.nodeBy] },
// { target: (d, $) => d[$.nodeBy] }
// ]
)
.derive({
source: (d, $) => d[$.nodeBy + "_1"],
target: (d, $) => d[$.nodeBy + "_2"]
})
.select(["source", "target"])
.groupby(["source", "target"])
.count()
.orderby(aq.desc("count"));
}
Insert cell
viewof t = getLinksHelper(aq.from(papersAndAffiliations), "paper", "affiliation").view()
// viewof t = getLinksHelper(aq.from(papersAndAffiliations), "paper", "city").view()
Insert cell
test3 = getCommonConnections({ links: test2 })
Insert cell
Insert cell
viewof institutionCityDF = aq
.from(papersAndAffiliations)
.groupby(["paper", "city"])
.count()
.view()
Insert cell
Insert cell
cityLinksFinal = getCommonConnections({ links: cityLinks })
Insert cell
viewof citiesLinksDF = getLinksHelper(
papersAndAffiliationsDF,
"paper",
"city"
).view()
Insert cell
// citylinksFinal = getLinksHelper(papersAndAffiliations, "city")
Insert cell
cityNodes = papersAndAffiliations
.map((paper) => paper.city)
.filter((source, index, self) => self.indexOf(source) === index)
Insert cell
viewof selectedCity = searchCheckbox(cityNodes)
Insert cell
viewof citiesLinksDFFiltered = citiesLinksDF.filter(
aq.escape(
(d) =>
selectedCity.includes(d.source) ||
selectedCity.includes(d.target)
)
).view()
Insert cell
viewof cityNodesDF = papersAndAffiliationsDF.groupby("city").count().view()

Insert cell
plotForceGraph(cityNodes, citiesLinksDFFiltered)
Insert cell
viewof selectedCities = searchCheckbox(cityNodes)
Insert cell
// citiesNodesDF = getNodesHelper(papersAndAffiliationsDF, "city")
viewof citiesNodesDF = papersAndAffiliationsDF.groupby("city").count().view()
// papersAndAffiliationsDF.groupby("city").count().view()
Insert cell
ForceGraph(
{
nodes: citiesNodesDF,
links: cityLinksFinal.filter((d) => selectedCities.includes(d.source))
},
{
nodeId: (d) => d,
renderer: "canvas",
invalidation,
_this: this,
extent: [
[0, 0],
[width, height]
],
width,
height,
// nodeLabel: false,
drawLinksWhenAlphaIs: 0.5 // useful for larger graphs
}
)
Insert cell
Insert cell
viewof papersAndAffiliationsDF = aq.from(papersAndAffiliations).view()
Insert cell
viewof countriesNodesDF = papersAndAffiliationsDF.groupby("country").count().view()

// papersAndAffiliations
// .map((paper) => paper.country)
// .filter((source, index, self) => self.indexOf(source) === index)
Insert cell

// aq.from(papersAndAffiliations).groupby(d => d.country).count()
Insert cell
viewof paperCountriesDF = aq
.from(papersAndAffiliations)
.groupby(["paper", "country"])
.count()
.view()
Insert cell
viewof countriesLinksDF = getLinksHelper(papersAndAffiliationsDF, "paper", "country").view()
Insert cell
// countryLinksFinal = getCommonConnections({ links: countriesLinks })
Insert cell
viewof selectedCountries = searchCheckbox(
countriesNodesDF.objects().map((d) => d.country)
)
Insert cell
viewof countriesLinksDFFiltered = countriesLinksDF.filter(
aq.escape(
(d) =>
selectedCountries.includes(d.source) ||
selectedCountries.includes(d.target)
)
).view()
Insert cell
ForceGraph(
{
nodes: countriesNodesDF.objects().map(d =>d.country),
links: countriesLinksDFFiltered.objects()
},
{
nodeId: (d) => d,
renderer: "canvas",
invalidation,
_this: this,
extent: [
[0, 0],
[width, height]
],
width,
height,
// nodeLabel: false,
drawLinksWhenAlphaIs: 0.5 // useful for larger graphs
}
)
Insert cell
Insert cell
viewof institutionLinksDF = getLinksHelper(
papersAndAffiliationsDF,
"paper",
"affiliation"
).view()
Insert cell
institutionNodes = papersAndAffiliations
.map((paper) => paper.affiliation)
.filter((source, index, self) => self.indexOf(source) === index)
Insert cell
//
viewof paperAffiliationsDF = aq
.from(papersAndAffiliations)
.groupby(["paper", "affiliation"])
.count()
.view()
Insert cell
Insert cell
Insert cell
viewof selectedUnis = searchCheckbox(institutionNodes)
Insert cell
ForceGraph(
{
nodes: institutionNodes,
links: institutionLinks.filter((d) => selectedUnis.includes(d.source))
},
{
nodeId: (d) => d,
renderer: "canvas",
invalidation,
_this: this,
extent: [
[0, 0],
[width, height]
],
width,
height,
// nodeLabel: false,
drawLinksWhenAlphaIs: 0.5 // useful for larger graphs
}
)
Insert cell
Insert cell
viewof paperAuthorsDF = aq
.from(papersAndAffiliations)
.groupby(["paper", "author"])
.count()
.view()
Insert cell
papersAndAffiliations
Insert cell
test = getCommonConnections({ links: papersAndAffiliations })
Insert cell
authorsNodes = papersAndAffiliations
.map((paper) => paper.author)
.filter((source, index, self) => self.indexOf(source) === index)
Insert cell
Insert cell
authorLinksFinal = getCommonConnections({ links: authorLinks })
Insert cell
plotForceGraph(authorsNodes, authorLinksFinal)
Insert cell
function plotForceGraph(nodes, links) {
return ForceGraph(
{
nodes: nodes,
links: links
},
{
nodeId: (d) => d,
renderer: "canvas",
invalidation,
_this: this,
extent: [
[0, 0],
[width, height]
],
width,
height,
// nodeLabel: false,
drawLinksWhenAlphaIs: 0.5 // useful for larger graphs
}
);
}
Insert cell
data = FileAttachment("UIST_2020_program (1) (1).json").json()
Insert cell
import { searchCheckbox } from "@john-guerra/search-checkbox"
Insert cell
import { ForceGraph } from "@john-guerra/force-directed-graph"
Insert cell
import { aq, op } from "@uwdata/arquero"
Insert cell
import { getCommonConnections } from "@john-guerra/get-common-connections"
Insert cell
height = 400
Insert cell
import { navio } from "@john-guerra/navio"
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