Published
Edited
Apr 20, 2021
Insert cell
Insert cell
Insert cell
Table(Pinfl)
Insert cell
Insert cell
Pinfl = FileAttachment("PUK.csv").csv()
Insert cell
Insert cell
influencersCsv = d3.csvParse(await FileAttachment("Infl with stats@2.csv").text(), d3.autoType)
Insert cell
Insert cell
Insert cell
mpCsv = d3.csvParse(await FileAttachment("MP attributes.csv").text(), d3.autoType)
Insert cell
influencers = influencersCsv.map(d => d[""])
Insert cell
Insert cell
Insert cell
inflConnectedTo = Array.from(new Set(primaryLinks.map(d => d['source']).concat(primaryLinks.map(d => d['target']))))
Insert cell
highlightInflConnectedTo = Array.from(new Set(highlightPrimaryLinks.map(d => d['source']).concat(highlightPrimaryLinks.map(d => d['target']))))
Insert cell
displayNodes = data.nodes.filter(d => (inflConnectedTo.includes(d['id'])))
Insert cell
function isConnectedTo(d) {
const hlL = displayLinks.filter(o => (d.includes(o.source))|| d.includes(o.target))
return Array.from(new Set(hlL.map(d => d['source']).concat(hlL.map(d => d['target']))))
}
Insert cell
isConnectedTo("sunny_hundal")
Insert cell
Insert cell
Insert cell
Insert cell
height = 680
Insert cell
function getNodeSize(d) {
if (influencers.includes(d.id)) {
return inflNodeSize(d['MP followers'])
}
if(mpCsv.map(d => d["Name"]).includes(d.name)){
let i = mpCsv.filter(a => a["Name"] == d.name)[0]
return 5 //mpNodeSize(i["Number of accounts following"])
}
}
Insert cell
function getColor(d) {
if (influencers.includes(d.id)) {
return "grey"
}
if(mpCsv.map(d => d["Name"]).includes(d.name)){
return d.colour
}
}
Insert cell
inflNodeSize = d3.scaleLinear()
.domain([0, d3.max(influencersCsv.map(d => d["MP followers"]))])
.range([10, 20])
Insert cell
mpNodeSize = d3.scaleLinear()
.domain([0, d3.max(mpCsv.map(d => d["Number of accounts following"]))])
.range([6, 20])
Insert cell
forceScale = d3.scaleLinear()
.domain(d3.extent(displayLinks.map(d => d.weight)))
.range([0, 0.7])
Insert cell
distanceScale = d3.scaleLog()
.domain(d3.extent(displayLinks.map(d => d.weight)))
.range([80, 30])
Insert cell
weightScale = d3.scaleLog()
.domain(d3.extent(displayLinks.map(d => d.weight)))
.range([0.1, 5])
Insert cell
colors = ['#b2182b', '#ef8a62', '#fddbc7', '#f7f7f7', '#d1e5f0', '#67a9cf', '#2166ac']
// dark red to dark blue
Insert cell
colorScale = d3.scaleSequentialQuantile(d3.interpolateRdYlBu)
.domain(d3.range(0, 1.1, 0.1))
Insert cell
ramp(colorScale)
Insert cell
crunch = d3.scaleLinear()
.domain([-1, 1])
.range([0, 1])
Insert cell
Insert cell
Insert cell
import {Radio, Range, Search, Select, Table, html} from "@observablehq/inputs"
Insert cell
d3 = require("d3@6")
Insert cell
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