chart = {
const width = 800,
height = 800;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
var g = svg.selectAll('g').attr("id", "paths");
var c = svg.selectAll('circle')
var t = svg.selectAll('text')
polyline(square_test,'red','1','1','0','black')
polyline(boat,'none','.5','1','3','blue')
function polyline(data, sfill, fillO, sOpac, sW, stroke){
g.enter().append("polyline")
.data(data)
.enter()
.append('polyline')
.attr("points", function(d){return d})
.style("fill", sfill)
.style("fill-opacity", fillO)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
var structure = phase_01
var sData = structureData[0]
//if the button is equal to phase 2, structure variable equals phase 02
if(phaseButton=="Phase 02"){structure = phase_02
sData = structureData[1]
}
if(phaseButton=="Phase 03"){structure = phase_03
sData = structureData[2]
}
g.enter().append("polyline")
.data(structure) //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
.attr('transform','translate(400 400)')
.style("fill", 'purple')
.style("fill-opacity", '1')
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", 'black')
var yVal = 300
dataText(350,yVal,sData.name)
dataText(350,yVal+20,sData.SecondProgram)
dataText(350,yVal+40,sData.housing)
dataText(350,yVal+60,sData.emCarbon)
dataText(350,yVal+80,sData.structureCLT)
dataText(350,yVal+100,sData.secondarStr)
function dataText(xVal,yVal,dataTxt){
svg
.append("text")
.attr("x",xVal)
.attr("y",yVal)
//.attr("class","pointsText")
.attr('font-weight','lighter')
.attr("font-family","helvetica")
.attr("font-size","9px")
.text(dataTxt) //needs to be a variable
}
t.enter().append('text')
.data(dataNames)
.enter()
.append("text")
.attr("x",330)
.attr("y",function(d,i){return yVal+(i*20)})
//.attr("class","pointsText")
.attr('font-weight','bold')
.attr('text-anchor','end')
.attr("font-family","helvetica")
.attr("font-size","9px")
.text(function(d){return d})
g.enter().append("polyline")
.data(rhinoLines) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d.pts}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'purple')
.style("fill-opacity", '1')
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", 'black')
.on('mouseover',rhinoText)
.on('mouseout',rhinoTextOut)
function rhinoText(event,d){
svg
.append("text")
.attr("x",200)
.attr("y",200)
.attr("class","pointsText")
.attr('font-weight','bold')
.attr("font-family","helvetica")
.attr("font-size","12px")
.text(d.zoning)
}
function rhinoTextOut(event,d){
svg.selectAll("text.pointsText").remove()
}
c.enter().append('circle')
.data(points)
.enter()
.append('circle')
.attr('cx',function(d){return d.xVal})
.attr('cy',function(d){return d.yVal})
.attr('r',ptRad)
.attr('fill',ptColor)
.on('mouseover',pointsHover)
.on('mouseout',pointsHoverOff)
function ptColor(d){
var color = 'red'
if(d.Type == 'clt'){color = 'blue'}
if(d.Type == 'other'){color = 'cyan'}
return color
}
function ptRad(d){
var radius = '4'
if(d.Type == 'clt'){radius = '8'}
return radius
}
function pointsHover(event,d){
svg
.append("rect")
.attr("x",d.xVal+20)
.attr("y",d.yVal+20)
.attr("width","120")
.attr("height","80")
.attr("class","hoverRect")
.attr("fill","rgb(200,200,200)")
.attr("stroke","black")
.attr("stroke-width","1")
svg
.append("text")
.attr("x",d.xVal+40)
.attr("y",d.yVal+40)
.attr("class","pointsText")
.attr('font-weight','bold')
.attr("font-family","helvetica")
.attr("font-size","12px")
.text(d.Name)
svg
.append("text")
.attr("x",d.xVal+40)
.attr("y",d.yVal+60)
.attr("class","pointsText")
.attr('font-weight','lighter')
.attr("font-family","helvetica")
.attr("font-size","12px")
.text(d.Description)
var wrap = svg.selectAll("text.pointsText")
.each(function(d, i) { wrap_text(d3.select(this), 80) });
}
function pointsHoverOff(event,d){
svg.selectAll('text.pointsText').remove()
svg.selectAll('rect.hoverRect').remove()
}
svg
.append("text")
.attr("x","100")
.attr("y","115")
.attr("class","hoverText")
.attr("font-family","helvetica")
.attr("font-size","12px")
.text("I love CASE 😀")
return svg.node();
}