chart = {
const width = 380,
height = 450;
const svg = d3.create("svg")
.attr("viewBox", [100, 0, width-100, height-180]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], SYDbox);
var path1 = 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.append("g").attr("id", "paths");
g.selectAll("path4") //d3 geopath
.data(SYDwater.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path4) //The d attribute defines a path to be drawn, only applies to appended elements
.style('fill', 'lavenderblush')
.style("fill-opacity", ".6")
.style('stroke-opacity','.4')
.style("stroke-width", '.25')
.style('stroke', 'maroon')
g.selectAll("path4") //d3 geopath
.data(SYDbuildings.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style('fill', 'salmon')
.style("fill-opacity", ".3")
.style('stroke-opacity','.2')
.style("stroke-width", '.15')
.style('stroke', 'maroon')
g.selectAll("path5") //d3 geopath
.data(SYDroads.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','.3')
.style("stroke-width", '.2')
.style('stroke', 'firebrick')
var c = svg.selectAll("circle") //d3 geopath
.data(SYDspots)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return projection([d.LONG,d.LAT])[0]})
.attr("cy", function(d) {return projection([d.LONG,d.LAT])[1]})
.attr('r', radvar)
.attr('fill',colorType) // add function to control color by 'type'
.attr('stroke-opacity','.55')
.attr("stroke-width", "2")
.attr('stroke', 'plum')
.style('fill-opacity','1')
.on('mouseover', spotText)
.on('mouseout', removeSpotText)
function colorType(d,i) {
var color = 'black'
if(d.CATEGORY=='Restaurant'){color = 'mediumvioletred'}
if(d.CATEGORY=='Place'){color = 'purple'}
if(d.CATEGORY=='Thing'){color = 'rgb(255,255,'+colorchange+')'}
return color
}
svg.append("rect")
.attr("x", 305)
.attr("y", 31)
.attr("height", 51)
.attr("width", 32)
.attr('stroke','black')
.attr("stroke-width", '.5')
.attr('stroke-opacity', '.4')
.style("fill", 'white');
svg.append('text')
.attr('x','310')
.attr('y','40')
.attr('font-family','Helvetica')
.attr('font-size','.2em')
.attr('text-anchor','start')
.attr('font-weight','normal')
.attr('font-style','regular')
.text("Time (hours)")
svg.append('text')
.attr('x','310')
.attr('y','50')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('text-anchor','start')
.attr('font-weight','bold')
.attr('font-style','regular')
.text(totalValues[0])
svg.append('text')
.attr('x','310')
.attr('y','65')
.attr('font-family','Helvetica')
.attr('font-size','.2em')
.attr('text-anchor','start')
.attr('font-weight','normal')
.attr('font-style','regular')
.text("Cost (AUD)")
svg.append('text')
.attr('x','310')
.attr('y','75')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('text-anchor','start')
.attr('font-weight','bold')
.attr('font-style','regular')
.text(totalValues[1])
if(totalValues[0] > 36){
svg.append("text")
//.attr('class','spotInfo')
.attr('x','190')
.attr('y','85')
.attr('font-family','Tahoma')
.attr('font-size','0.7em')
.attr('font-weight','Bold')
.attr('fill','firebrick')
.attr('text-anchor','middle')
.text('OUT OF TIME!')
}
if(totalValues[0] > 36){
svg.append("text")
//.attr('class','spotInfo')
.attr('x','190')
.attr('y','95')
.attr('font-family','Tahoma')
.attr('font-size','0.3em')
.attr('font-weight','Bold')
.attr('fill','firebrick')
.attr('text-anchor','middle')
.text('Did you really think you had all the time in the world?')
}
if(totalValues[1] > 800){
svg.append("text")
//.attr('class','spotInfo')
.attr('x','190')
.attr('y','150')
.attr('font-family','Tahoma')
.attr('font-size','0.7em')
.attr('font-weight','Bold')
.attr('fill','firebrick')
.attr('text-anchor','middle')
.text('EMPTY WALLET!')
}
if(totalValues[1] > 800){
svg.append("text")
//.attr('class','spotInfo')
.attr('x','190')
.attr('y','160')
.attr('font-family','Tahoma')
.attr('font-size','0.3em')
.attr('font-weight','Bold')
.attr('fill','firebrick')
.attr('text-anchor','middle')
.text('You wasted all your money...again. Hope it was worth it!!')
}
function spotText(event,d){
d3.select(this)
.attr('fill', 'indigo')
.attr('r', '6')
.style('stroke', 'mediumslateblue')
.style("stroke-opacity",'.65')
.style("stroke-width", '5')
svg.append("rect")
.attr('class','whitebox')
.attr("x", 245)
.attr("y", 170)
.attr("height", 30)
.attr("width", 100)
.attr('stroke','black')
.attr("stroke-width", '.5')
.attr('stroke-opacity', '.4')
.style("fill", 'white');
svg.append('text')
.attr('class','spots')
.attr('x','252')
.attr('y','183')
.attr('font-family','Helvetica')
.attr('font-size','.35em')
.attr('text-anchor','start')
.attr('font-weight','bold')
.text(d.NAME)
svg.append('text')
.attr('class','spots')
.attr('x','252')
.attr('y','191')
.attr('font-family','Helvetica')
.attr('font-size','.2em')
.attr('text-anchor','start')
.attr('font-weight','normal')
.attr('font-style','italic')
.text(d.DESCRIPTION)
svg.append('line')
.attr('class','spotLine')
.attr('x1','245')
.attr('y1','183')
.attr('x2',projection([d.LONG,d.LAT])[0])
.attr('y2','183')
.style('stroke-width','.5')
.style('stroke','black')
.style('stroke-dasharray','2 1')
svg.append('line')
.attr('class','spotLine')
.attr('x1',projection([d.LONG,d.LAT])[0])
.attr('y1','183')
.attr('x2',projection([d.LONG,d.LAT])[0])
.attr('y2',projection([d.LONG,d.LAT])[1])
.style('stroke-width','.5')
.style('stroke','black')
.style('stroke-dasharray','2 1')
}
function removeSpotText(event,d) {
d3.select(this).attr('fill', colorType)
d3.select(this).attr('r', 3)
d3.select(this).style('stroke', 'orchid')
d3.select(this).style('fill-opacity','1')
d3.select(this).style('stroke-opacity','.55')
d3.select(this).style('stroke-width', '2')
d3.selectAll('text.spots').remove()
d3.selectAll('line.spotLine').remove()
d3.selectAll('rect.whitebox').remove()
var wrap = svg.selectAll("text.spots")
.each(function(d,i) {wrap_text(d3.select(this), 100) } );
}
/*
c.enter.append('circle')// format to add additional circles
.data(spots)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return projection([d.longitude,d.latitude])[0]})
.attr("cy", function(d) {return projection([d.longitude,d.latitude])[1]})
.attr('r',3)
.attr('fill','black')
.style('fill-opacity','1')
*/
return svg.node();
}