Public
Edited
Apr 3, 2023
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
chart = ForceGraph(
{ nodes: senators, links: filteredLinks },
{
nodeId: (d) => d.member_full,
renderer: "canvas",
nodeGroup: (d) => d.party,
nodeRadius: d => 10,
nodeStrength: -100,
linkDistance: 40,
invalidation,
_this: this,
extent: [
[0, 0],
[width, height]
],
width,
height,
// nodeLabel: false,
linkStrokeWidth: (l) => w(l.value),
linkStrokeOpacity: 0.05,
nodeGroups: ["R", "D", "I"],
colors: ["#d62728", "#1f77b4", "#ff7f0e"],
drawLinksWhenAlphaIs: 0.5 // useful for larger graphs
}
)
Insert cell
senators
Insert cell
filteredLinks
Insert cell
viewof selectedParty = searchCheckbox(parties)
Insert cell
viewof politicalP = Inputs.radio(["D", "I", "R"], { label: "color" })
Insert cell
s_senators = senators.filter((item) => item.party === politicalP)
Insert cell
viewof selectedSenators = searchCheckbox(senators.map(d =>d.member_full ))
Insert cell
selectedParty
Insert cell
test = senators.filter(d => d.party === selectedParty)
Insert cell
parties = ["D", "I", "R"]
Insert cell
import {searchCheckbox} from "@john-guerra/search-checkbox"
Insert cell
ForceGraph(
{
nodes: senatorToVoteLinksNodes,
links: senatorToVoteLinks.filter(d => selectedSenators.includes(d.source))
},
{
nodeId: (d) => d.id,
renderer: "canvas",
invalidation,
_this: this,
extent: [
[0, 0],
[width, height]
],
width,
height,
// nodeLabel: false,
drawLinksWhenAlphaIs: 0.5 // useful for larger graphs
}
)
Insert cell
senatorToVoteLinksNodes = Array.from(
d3.group(senatorToVoteLinks, (d) => d.source).keys()
).concat(Array.from(d3.group(senatorToVoteLinks, (d) => d.target).keys())).map(d => ({id: d}))
Insert cell
d3.group(senators, d => d.party)
Insert cell
// convert to a network
navio(USSenateVotingData.map(v => v.members.member.map(m => ({...m, n: v.vote_number }) )).flat())
Insert cell
Insert cell
Insert cell
senators = USSenateVotingData[0].members.member.map((m) => {
const copy = { ...m , id: m.member_full};
delete copy.vote_cast;
return copy;
})
Insert cell
// viewof filteredLinks = navio(commonVotesLinks)
Insert cell
Insert cell
w = d3
.scaleLinear()
.domain(d3.extent(commonVotesLinks, (d) => d.value))
.range([0.1, 3])
Insert cell
height = 400
Insert cell
viewof selected = navio(data.contents, {
addAllAttribsIncludeObjects: true,
addAllAttribsIncludeArrays: true
})
Insert cell
data.contents
Insert cell
Table(selected)
Insert cell
df = aq.from(selected)
Insert cell
viewof authorsPapers = df
.select(["id", "authorNames"])
.unroll("authorNames")
.view()
Insert cell
viewof authorNodes = authorsPapers
.derive({ name: d => d.authorNames })
.groupby("name")
.count()
.orderby(aq.desc("count"))
.view()
Insert cell
Insert cell
import {ForceGraph} from "@john-guerra/force-directed-graph"
Insert cell
import {getCommonConnections} from "@john-guerra/get-common-connections"
Insert cell
import {navio} from "@john-guerra/navio"
Insert cell
network = ({nodes: senators, links: commonVotesLinks})
Insert cell
import {USSenateVotingData} from "@john-guerra/get-us-senate-voting-data"
Insert cell
import {Swatches} from "@d3/color-legend"
Insert cell
data = FileAttachment("UIST_2020_program.json").json()
Insert cell
import { Search, Table } from "@observablehq/inputs"
Insert cell
import { aq, op } from "@uwdata/arquero"
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