chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], fleetsfile);
var path1 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path1")
.data(so.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path1)
.style("fill", "magenta")
.style("fill-opacity", ".2")
.style('stroke-opacity','.4')
.style("stroke-width", '2')
.style("stroke", "rgb(0,0,0)")
var cir = svg.selectAll("circle")
.data(nySpots)
.enter()
.append("circle")
.attr('class','nySpots')
.attr("r", "3")
.attr("cx", function(d) {return projection([d.Long,d.Lat])[0]})
.attr("cy", function(d) {return projection([d.Long,d.Lat])[1]})
.style("fill", fillColor)
.style("fill-opacity", "1")
.style('stroke-opacity','.4')
.style("stroke-width", '1')
.style("stroke", "rgb(0,0,0)")
function fillColor(d,i){
var color = "rgb(200,0,200)"
if(d.Type=="food"){color = "rgb(255,0,0)"}
if(d.Type=="game"){color = "rgb(0,0,255)"}
return color
}
cir.enter().append("circle") //use this line every time after we first create a circle variable
.data(scSteps) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
//.attr('class','outlines')
.attr("r", "6") //The d attribute defines a path to be drawn, only applies to appended elements
.attr("cx", "150")
.attr("cy", function(d,i) {return 150+(i*20)})
.style("fill", "white")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "rgb(0,0,0)")
.on("mouseover",animateMap)
.on("mouseout",stopAnimateMap)
function animateMap(event,d){//function is run on circle listening event
var tColor = "cyan"
//you'll have an if statement for each step of the supply chain
if(d == "Raw Extraction"){//everything in this if statement happens when hovering over 'raw 'extraction'
tColor = "yellow"
p.enter().append("polyline")//use this for all polylines after the first polyline
.data(truck) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.attr("class", "mouseIcon")
.attr("transform", "translate(200,200)")
.style("fill", "magenta")
.style('stroke-opacity','1')
.style("stroke-width", '0')
.style("stroke", "rgb(0,0,0)")
svg.selectAll("circle.nySpots").attr('r',changeR)
svg
.append("text")
.attr("x", "100")
.attr("y", "720")
.attr("class", "description")
.style("font-family", "Helvetica")
.style("font-weight", "bold")
.style("font-size", "10px")
.style("text-anchor", "start")
.style("fill", "black")
.style("fill-opacity", "1")
.text("Raw material extracted from the ground, shipped to production facility to be processed into usable building material")
}
if(d == "Material Processing"){//everything in this if statment happens when hovering over 'material processing'
tColor = "red"
p.enter().append("polyline")//use this for all polylines after the first polyline
.data(truck) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.attr("class", "mouseIcon")
.attr("transform", "translate(-200,-200)")
.style("fill", "cyan")
.style('stroke-opacity','1')
.style("stroke-width", '0')
.style("stroke", "rgb(0,0,0)")
svg.selectAll("circle.nySpots").attr('r',changeR2)
}
svg
.append("text")
.attr("x", "300")
.attr("y", "700")
.attr("class", "mouseText")
.style("font-family", "Helvetica")
.style("font-weight", "bold")
.style("font-size", "10px")
.style("text-anchor", "start")
.style("fill", tColor)
.style("fill-opacity", "1")
.text(d)
var wrap = svg.selectAll("text.description")
.each(function(d, i) { wrap_text(d3.select(this), 150) });//control how long the text lines are
}
function changeR(d,i){
var rad = "3"
if(d.Type=="food"){rad = "6"}
return rad
}
function changeR2(d,i){
var rad = "3"
if(d.Type=="game"){rad = "6"}
return rad
}
function stopAnimateMap(event,d){
//remove mouseover text
svg.selectAll("text.mouseText").remove() //type of obejct, then class name
svg.selectAll("polyline.mouseIcon").remove()
svg.selectAll("circle.nySpots").attr('r',"3")
svg.selectAll("text.description").remove()
}
var tx = svg.selectAll("text") //use this line every time after we first create a circle variable
.data(scSteps) //get data to define path
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
//.attr('class','outlines')
.attr("x", "165")
.attr("y", function(d,i) {return 155+(i*20)})
.style("font-family", "Helvetica")
.style("font-weight", "bold")
.style("font-size", "10px")
.style("text-anchor", "start")
.style("fill", "black")
.style("fill-opacity", "1")
.text(function(d) {return d})
var p = svg.selectAll("polyline")//use this line for the first polyline
.data(txt1) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", "rgb(0,0,0)")
.style("stroke-dasharray","4 4")
p.enter().append("polyline")//use this for all polylines after the first polyline
.data(truck) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.style("fill", "black")
.style('stroke-opacity','1')
.style("stroke-width", '0')
.style("stroke", "rgb(0,0,0)")
//.style("stroke-dasharray","4 4")
//.attr("cx", function(d) {return projection([d.long,d.lat])[0]})
return svg.node();
}