Public
Edited
May 7, 2024
Fork of Banned Books
Insert cell
Insert cell
Insert cell
Insert cell
workbook = FileAttachment("cleaned_data_banned_2023.xlsx").xlsx();
Insert cell
data1 = workbook.sheet(0, {
headers: true
// range: "A1:J10"
})
Insert cell
data1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
slice = d3.shuffle(data1).slice(0,5000) // change the right number here to show more or fewer of the 11000+ powerplants
Insert cell
Insert cell
clElem = d3.select(svgContainer).select("#layer1")
Insert cell
clusters = dvCluster(clElem,slice,500,800,"Ban",options)
Insert cell
options = ({
"classField": "Ban", // to set their class/colo
"dotScaleFactor": 1,
"strength": -0.5,
"alphaTarget": 0.1
})
Insert cell
Insert cell
Insert cell
fociOneCenter = [{x: 500, y: 500}]
Insert cell
fociBans = ({
"pending":{x: 700, y: 400},"both":{x: 200, y: 400},
"libraries":{x: 200, y: 200},"classroom":{x: 700, y: 200}
})
Insert cell
fociStates = ({
"AK":{x: 50, y: 100},"AL":{x: 700, y: 600},"AR":{x: 490, y:483},"AZ":{x: 200, y: 500},"CA":{x: 115, y: 400},
"CO":{x: 300, y: 400},"CT":{x: 850, y: 240},"DE":{x: 925, y: 325},"FL":{x: 900, y: 685},
"GA":{x: 795, y: 590},"HI":{x: 50, y: 500},"IA":{x: 490, y: 330},"ID":{x: 199, y: 199},"IL":{x: 600, y: 200},
"IN":{x: 580, y: 320},"KS":{x: 398, y: 487},"KY":{x: 580, y: 405},"LA":{x: 500, y: 600},"MA":{x: 968, y: 200},
"MD":{x: 875, y: 400},"ME":{x: 1073, y: 90},"MI":{x: 580, y: 115},"MN":{x: 490, y: 205},"MO":{x:490, y: 375},
"MS":{x: 580, y: 590},"MT":{x: 300, y: 200},"NC":{x: 690, y: 480},"ND":{x: 397, y: 200},"NE":{x: 405, y: 402},
"NH":{x: 1060, y: 310},"NJ":{x: 859, y: 320},"NM":{x: 275, y: 515},"NV":{x: 200, y: 300},"NY":{x: 868, y: 203},
"OH":{x: 700, y: 300},"OK":{x: 400, y: 595},"OR":{x: 110, y: 300},"PA":{x: 770, y: 305},"RI":{x: 925, y: 200},
"SC":{x: 780, y: 477},"SD":{x: 402, y: 315},"TN":{x: 590, y: 481},"TX":{x: 390, y: 690},"UT":{x: 200, y: 375},
"VA":{x: 770, y: 410},"VT":{x: 925, y: 200},"WA":{x: 100, y: 300},"WI":{x: 491, y: 115},"WV":{x: 688, y: 410},
"WY":{x: 300, y: 315}
})
Insert cell
fociStates1 = ({
"AK":{x: 50, y: 100},"AL":{x: 675, y: 600},"AR":{x: 475, y:500},"AZ":{x: 175, y: 500},"CA":{x: 75, y: 415},
"CO":{x: 275, y: 415},"CT":{x: 975, y: 315},"DE":{x: 975, y: 415},"FL":{x: 900, y: 790},
"GA":{x: 775, y: 600},"HI":{x: 50, y: 500},"IA":{x: 475, y: 315},"ID":{x: 175, y: 200},"IL":{x: 575, y: 200},
"IN":{x: 575, y: 315},"KS":{x: 375, y: 500},"KY":{x: 575, y: 415},"LA":{x: 475, y: 600},"MA":{x: 975, y: 200},
"MD":{x: 875, y: 415},"ME":{x: 1075, y: 100},"MI":{x: 575, y: 115},"MN":{x: 475, y: 200},"MO":{x: 475, y: 415},
"MS":{x: 575, y: 600},"MT":{x: 275, y: 200},"NC":{x: 675, y: 500},"ND":{x: 375, y: 200},"NE":{x: 375, y: 415},
"NH":{x: 1075, y: 315},"NJ":{x: 875, y: 315},"NM":{x: 275, y: 500},"NV":{x: 175, y: 315},"NY":{x: 875, y: 200},
"OH":{x: 675, y: 315},"OK":{x: 375, y: 600},"OR":{x: 75, y: 315},"PA":{x: 775, y: 315},"RI":{x: 1075, y: 415},
"SC":{x: 775, y: 500},"SD":{x: 375, y: 315},"TN":{x: 575, y: 500},"TX":{x: 375, y: 770},"UT":{x: 175, y: 415},
"VA":{x: 775, y: 415},"VT":{x: 1075, y: 200},"WA":{x: 75, y: 200},"WI":{x: 475, y: 115},"WV":{x: 675, y: 415},
"WY":{x: 275, y: 315}
})
Insert cell
Insert cell
Insert cell
labelLayer = clElem.append("g").attr("id","labels")

Insert cell
Insert cell
Insert cell
function dimAll() {clusters.style("opacity","0.05")}
Insert cell
function filter(field,value) {
dimAll();
clusters.filter(d => d["data"][field] == value).style("opacity","");
}
Insert cell
clusters.filter(d => d["data"]['Ban'] == 'libraries')
Insert cell
function showAll() {clusters.style("opacity","")}
Insert cell
highlight = (evt,d) => {
let thisElem = evt.currentTarget;
d3.select(clusters.filter(d => d["data"]["Title"] ==thisElem.data["Title"]))
.style("stroke","yellow")
.style("stroke-width","2")
.raise();
}
Insert cell
unhighlight = (evt) => {
let thisElem = evt.currentTarget;
d3.select(clusters.filter(d => d["data"]["Title"] ==thisElem.data["Title"]))
.style("stroke","")
.style("stroke-width","");
}
Insert cell
{
clusters.on("mouseover", highlight);
clusters.on("mouseout", unhighlight);
}
Insert cell
{
// register event listeners
const btns = d3.select(svgContainer).select("#controls");
const btns2 = d3.select(svgContainer).select("#banControls");
btns.select("#btn_all").on("click", () => {dvClusterMoveNodes(fociOneCenter); dvClusterFociLabels(labelLayer.raise(),fociOneCenter)});
btns.select("#btn_fuel").on("click", () => {dvClusterMoveNodes(fociBans,"Ban"); dvClusterFociLabels(labelLayer.raise(),fociBans)});
btns.select("#btn_state").on("click", () => {dvClusterMoveNodes(fociStates,"State");dvClusterFociLabels(labelLayer.raise(),fociStates1)});
btns2.select("#btn-pending").on("click", () => filter('Ban','pending'));
btns2.select("#btn-libraries").on("click", () => filter('Ban','libraries'));
btns2.select("#btn-both").on("click", () => filter('Ban','both'));
btns2.select("#btn-classroom").on("click", () => filter('Ban','classroom'));
btns.select("#btn-dimAll").on("click", dimAll);
btns2.select("#btn-showAll").on("click", showAll);
}
Insert cell
Insert cell
Insert cell
putText = (evt,d) => {
d3.select(svgContainer).select("#mytext").text("Title: " + d["data"].Title);
}
Insert cell
ttOptions = ({
title: {dataName: "Title"},
subtitle: {dataName: "Author"},
})
Insert cell
Insert cell
import {toNum, rFromArea, radiansFromDeg} from "@emfielduva/dvlib"
Insert cell
import {dvTooltip} from "@emfielduva/dvlib_ui"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more