Public
Edited
May 5, 2024
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
workbook = FileAttachment("cleaned_data_banned.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,2000) // change the right number here to show more or fewer of the 11000+ powerplants
Insert cell
Insert cell
clElem = d3.select(svgContainer)
Insert cell
clusters = dvCluster(clElem,slice,500,800,"Ban",options)
Insert cell
options = ({
"classField": "Ban", // to set their class/colo
"dotScaleFactor": 3,
"strength": -0.5,
"alphaTarget": 0.1
})
Insert cell
Insert cell
Insert cell
fociOneCenter = [{x: 600, y: 600}]
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: 100, y: 400},
"CO":{x: 290, y: 400},"CT":{x: 925, y: 250},"DE":{x: 925, y: 325},"FL":{x: 900, y: 700},
"GA":{x: 790, y: 590},"HI":{x: 50, y: 500},"IA":{x: 485, y: 315},"ID":{x: 192, y: 192},"IL":{x: 600, y: 200},
"IN":{x: 580, y: 310},"KS":{x: 395, y: 485},"KY":{x: 580, y: 405},"LA":{x: 500, y: 600},"MA":{x: 970, y: 195},
"MD":{x: 875, y: 400},"ME":{x: 1073, y: 90},"MI":{x: 580, y: 105},"MN":{x: 490, y: 200},"MO":{x:490, y: 380},
"MS":{x: 580, y: 590},"MT":{x: 300, y: 200},"NC":{x: 685, y: 480},"ND":{x: 390, y: 195},"NE":{x: 398, y: 402},
"NH":{x: 970, y: 310},"NJ":{x: 868, y: 310},"NM":{x: 275, y: 515},"NV":{x: 200, y: 300},"NY":{x: 875, y: 200},
"OH":{x: 700, y: 300},"OK":{x: 390, y: 590},"OR":{x: 100, y: 300},"PA":{x: 780, y: 295},"RI":{x: 925, y: 200},
"SC":{x: 780, y: 477},"SD":{x: 390, y: 308},"TN":{x: 585, y: 485},"TX":{x: 390, y: 700},"UT":{x: 200, y: 375},
"VA":{x: 780, y: 400},"VT":{x: 925, y: 200},"WA":{x: 100, y: 300},"WI":{x: 488, y: 105},"WV":{x: 688, y: 410},
"WY":{x: 290, y: 305}
})
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
nodes = nodesFromLinks(links)
Insert cell
elem = d3.select(svgContainer).select("#layer1")
Insert cell
dvNetworkGraph(elem,links,1000,500)
Insert cell
highlight = (evt,d) => {
let mousedoverElem = evt.currentTarget;

d3.select(mousedoverElem).filter(d => d["data"]["title"] == d["data"]["title"]).style("stroke","blue").style("stroke-width","3px"); // give it a yellow stroke when we highlight it

//putText(evt,d); // and while were at is, let's call putText also using the same event and data.
}
Insert cell
Insert cell
Insert cell
{
// register event listeners
const btns = d3.select(svgContainer).select("#controls");
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)});
d3.select(svgContainer).select("#layer1").selectAll(".mycircle")
.data(slice)
.join("circle")
.classed("mycircle", true)
.attr("cx",d => d.value * 100)
.attr("cy", 150)
.attr("r", d => d.value * 10)
.style("fill","steelblue")
.on("mouseover", highlight)
}
Insert cell
Insert cell
Insert cell
import {toNum, rFromArea, radiansFromDeg} from "@emfielduva/dvlib"
Insert cell
import {nodesFromLinks, dvNetworkGraph} with {nodes} from "@emfielduva/dvlib_layout"
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