chart = {
const scale = 3
const textOffset = 10
var data = data_gen(csv,["TREE", "MOUNTAIN"]);
const links = data.links.map(d => Object.create(d));
const nodes = data.nodes.map(d => Object.create(d));
var i;
for (i=0; i < nodes.length; i++){
if(nodes[i].__proto__.id == "BARN" || nodes[i].__proto__.id == "BRIDGE" || nodes[i].__proto__.id == "BUILDING" || nodes[i].__proto__.id == "CABIN" || nodes[i].__proto__.id == "DOCK" || nodes[i].__proto__.id == "FARM" || nodes[i].__proto__.id == "LIGHTHOUSE" || nodes[i].__proto__.id == "MILL" || nodes[i].__proto__.id == "STRUCTURE" || nodes[i].__proto__.id == "WINDMILL" || nodes[i].__proto__.id == "FENCE" || nodes[i].__proto__.id == "PATH" || nodes[i].__proto__.id == "FIRE") {
nodes[i].__proto__.group = "1";}
if(nodes[i].__proto__.id == "PERSON" || nodes[i].__proto__.id == "PORTRAIT"){
nodes[i].__proto__.group = "2";}
if(nodes[i].__proto__.id == "CLOUDS" || nodes[i].__proto__.id == "FOG" || nodes[i].__proto__.id == "SNOW"){
nodes[i].__proto__.group = "3";}
if(nodes[i].__proto__.id == "BUSHES" || nodes[i].__proto__.id == "CACTUS" || nodes[i].__proto__.id == "FLOWERS" || nodes[i].__proto__.id == "GRASS" || nodes[i].__proto__.id == "TREE"){
nodes[i].__proto__.group = "4";}
if(nodes[i].__proto__.id == "BEACH" || nodes[i].__proto__.id == "LAKE" || nodes[i].__proto__.id == "OCEAN" || nodes[i].__proto__.id == "WATERFALL" || nodes[i].__proto__.id == "WAVES" || nodes[i].__proto__.id == "BOAT" || nodes[i].__proto__.id == "RIVER"){
nodes[i].__proto__.group = "5";}
if(nodes[i].__proto__.id == "NIGHT" || nodes[i].__proto__.id == "MOON" || nodes[i].__proto__.id == "SUN" || nodes[i].__proto__.id == "AURORA_BOREALIS"){
nodes[i].__proto__.group = "6";}
if(nodes[i].__proto__.id == "HILLS" || nodes[i].__proto__.id == "MOUNTAIN" || nodes[i].__proto__.id == "RIVER ROCKS" || nodes[i].__proto__.id == "CLIFF" || nodes[i].__proto__.id == "ROCKS"){
nodes[i].__proto__.group = "7";}
}
console.log(nodes);
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.id))
.force("charge", d3.forceManyBody().strength(-800))
.force("center", d3.forceCenter(width / 2, height / 2));
const svg = d3.create("svg")
.attr("viewBox", [0, -30, width, height]);
/* .force("x", d3.forceX())
.force("y", d3.forceY());
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height]);
*/
const link = svg.append("g")
.attr("stroke", "#999")
.attr("stroke-opacity", .8)
.selectAll("line")
.data(links)
.join("line")
.attr("stroke-width", d => Math.sqrt(d.value));
const node = svg.append("g")
.selectAll(".node")
.data(nodes)
.join("g")
.attr("class", "node")
.attr("fill", color)
.call(drag(simulation));
/*
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("r", 7)
.attr("fill", color)
.call(drag(simulation));
*/
const circle = node.append("circle")
.attr("r", 5)
.attr("fill", "#000000")
.call(drag(simulation));
const text = node.append("text")
.text(d => d.id)
.attr("font-family", "Arial")
.attr("font-size", "12px")
.attr("stroke", "#00000");
simulation.on("tick", () => {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
text
.attr("x", d => d.x+textOffset)
.attr("y", d => d.y);
circle
.attr("cx", d => d.x)
.attr("cy", d => d.y);
});
invalidation.then(() => simulation.stop());
//highlights paths
node.on("mouseover", function(d) {
var thisNode = d.id
d3.selectAll(".circleNode").attr("r", 6);
d3.select(this).attr("r", 12);
link.attr("opacity", function(d) {
return (d.source.id == thisNode || d.target.id == thisNode) ? 1 : 0.1
});
});
return svg.node();
}