chart = {
const width = 900,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width-50, height-10]);
var projection = d3
.geoMercator()
.fitSize([width, height], bounding_box_01);
var path = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var path4 = d3.geoPath().projection(projection);
var path5 = d3.geoPath().projection(projection);
var g = svg.selectAll('g').attr("id", "paths");
var c = svg.selectAll("circle")
var p = svg.selectAll("polyline")
var t = svg.selectAll("text")
staticLines(path3, subways.features,"none",1,.5,"rgb(180,180,180)",'1')
staticLines(path4, parks.features,"rgb(200,225,200)",'.25','.1',"rgb(0,255,0)",'1')
function staticLines(path, data, sfill, sOpac, sW, stroke, fOpac){
g.enter().append("path")
.data(data)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)//color
.style("fill-opacity", fOpac)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)//color
}
//static points from qgis
staticCircles(restrooms.features,'1','black','1',"0",'none')
staticCircles(subway_stops.features,'2','red','1',"0",'none')
function staticCircles(data,r,sfill, sOpac, sWidth,strk){
c.enter().append('circle')
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r', r)
.style('fill', sfill)
.style('fill-opacity',sOpac)
.style("stroke", strk)
.style("stroke-width", sWidth)
}
//lines from rhino, use this on lines with no rollover
//static lines from rhino
polyline(polygon_test,'rgb(240,240,240)','1','0','none')
polyline(crust,'rgb(255,255,0)','1','2.5','black')
polyline(pep,'rgb(255,0,0)','1','1','black')
function polyline(data, sfill, sOpac, sW, stroke){
g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
//add icon to each point on google sheets
//.attr("points", chooseIcon)
g.enter().append("polyline")
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", chooseIcon) //The d attribute defines a path to be drawn, only applies to appended elements
.attr('transform',function(d){return 'translate('+projection([d.long,d.lat])[0]+','+projection([d.long,d.lat])[1]+')'})
.style("fill", 'yellow')
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", 'black')
.on("mouseover",spotText)
.on("mouseout",removeText)
function chooseIcon(d,i){
var icon = crust_icon
if(d.name=="Roberta's"){icon = pie_icon}
if(d.name=="Carmine's"){icon = pep_icon}
return icon
}
//.attr("points", pep_icon)
g.enter().append("polyline")
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", pep_icon) //The d attribute defines a path to be drawn, only applies to appended elements
.attr('transform',function(d){return 'translate('+projection([d.long,d.lat])[0]+','+projection([d.long,d.lat])[1]+')'})
.style("fill", 'red')
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", 'none')
.on("mouseover",spotText)
.on("mouseout",removeText)
/*
//points from spreadsheet
c.enter().append('circle')
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','spots')
.attr('cx',function(d) {return projection([d.long,d.lat])[0]})//this function causes its contents to be applied to each circle
.attr("cy",function(d) {return projection([d.long,d.lat])[1]})
.attr('r', 5)
.attr('fill', function(d){return d.color})
.style('fill-opacity','1')
.style("stroke-width", "1")
.on("mouseover",spotText)
.on("mouseout",removeText)
*/
function spotText(event,d){
svg
.append('text')
.attr("class","sText")
.attr('x','200')//this function causes its contents to be applied to each circle
.attr("y",'300')
.attr("font-size","10px")
.attr("font-family","helvetica")
.attr("font-weight","normal")
.attr("text-anchor","start")
.text(d.description)
svg
.append('text')
.attr("class","sText")
.attr('x',projection([d.long,d.lat])[0])//this function causes its contents to be applied to each circle
.attr("y",projection([d.long,d.lat])[1])
.attr("font-size","10px")
.attr("font-family","helvetica")
.attr("font-weight","normal")
.attr("text-anchor","start")
.text(d.description)
var wrap = svg.selectAll("text.sText")
.each(function(d, i) { wrap_text(d3.select(this), 100) });//pixel value of width of line of text
}
function removeText(){
svg.selectAll("text.sText").remove()
}
/*
//add text names of pizza spots
t.enter().append('text')
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
.attr('class','spots')
.attr('x',function(d) {return projection([d.long,d.lat])[0]})//this function causes its contents to be applied to each circle
.attr("y",function(d) {return projection([d.long,d.lat])[1]-8})
.attr("font-size","10px")
.attr("font-family","helvetica")
.attr("font-weight","bolder")
.attr("text-anchor","middle")
.text(function(d){return d.name})
*/
t.enter().append('text')
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
.attr('class','spots')
.attr('x','200')//this function causes its contents to be applied to each circle
.attr("y",function(d,i){return 100+(i*15)})
.attr("font-size","10px")
.attr("font-family","helvetica")
.attr("font-weight","bolder")
.attr("text-anchor","end")
.text(function(d){return d.name})
svg//added mutable cash value
.append('text')
.attr('x','200')
.attr("y",'80')
.attr("font-size","14px")
.attr("font-family","helvetica")
.attr("font-weight","bolder")
.attr("text-anchor","end")
.text(cash)
svg//this will be our first button
.append('rect')
.attr('x','200')
.attr('y','180')
.attr('width','100')
.attr('height','25')
.style('fill','red')
.style('stroke','black')
.on('click',function(){mutable cash = mutable cash - 35})//take money away from cash
svg//this will be our first button text
.append('text')
.attr('x','210')
.attr('y','195')
.attr("font-family","helvetica")
.attr("font-size","13px")
.attr("font-weight","500")
.style('fill','white')
.text('Haircut: $35')
p.enter().append('polyline')
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('class','spots')
.attr("points",function(d,i){return "200,"+(100+(i*15))+" "+projection([d.long,d.lat])[0]+","+(100+(i*15))+" "+projection([d.long,d.lat])[0]+","+projection([d.long,d.lat])[1]})
.style("stroke","black")
.style("stroke-dasharray","6 6")
.style("stroke-width",".5")
.style("fill","none")
return svg.node();
}