{
const height = 100
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("font-family", "Helvetica");
const xScale = d3.scaleLinear().domain([0, 1]).range([0, width / 2])
const popOutside = demoData.pop_mile - demoData.total_pop
const housingOutside = demoData.hh_mile - demoData.total_hh
const labelPositions = [width / 2 - xScale(demoData.total_hh / demoData.hh_mile), width / 2 + xScale(demoData.total_pop / demoData.pop_mile),20, width ]
const labelNumbers = [housingOutside, demoData.total_hh, demoData.total_pop, popOutside ]
svg.append('line')
.attr('x1', width / 2 )
.attr('x2', width / 2 )
.attr('y1', 0)
.attr('y2', height )
.attr('stroke', 'lightgrey')
.attr('stroke-dasharray', '2 2')
svg.append('circle')
.attr('cx', width/ 2)
.attr('cy', height / 2)
.attr('r', 20)
.attr('fill', red)
.attr('fill-opacity', .5)
svg.append('line')
.attr('x1', 20 )
.attr('x2', width )
.attr('y1', height / 2 )
.attr('y2', height / 2 )
.attr('stroke', 'grey')
svg.append('rect')
.attr('x', width / 2)
.attr('y', height / 2 - 4)
.attr('height', 8)
.attr('width', d => xScale(demoData.total_pop / demoData.pop_mile ) )
.attr('rx', 5)
.attr('fill', red)
svg.append('rect')
.attr('x', d => width / 2 - xScale(demoData.total_hh / demoData.hh_mile))
.attr('y', height / 2 - 4)
.attr('height', 8)
.attr('width', d => xScale(demoData.total_hh / demoData.hh_mile) )
.attr('rx', 5)
.attr('fill', red)
svg.append('circle')
.attr('cx', width/ 2)
.attr('cy', height / 2)
.attr('r', 8)
.attr('fill', red)
const numbers = svg.append('g')
.attr('transform', `translate(0,${height / 2 + 20})`)
.attr('font-size', '14px')
numbers
.selectAll('text')
.data(labelPositions)
.enter()
.append('text')
.attr('x', d => d)
.text((d, i) => Object.values(demoData)[i].toLocaleString('en'))
.attr('fill', (d, i) => ['total_pop', 'total_hh'].includes(Object.keys(demoData)[i]) ? red : 'black' )
.attr('font-weight', (d, i) => ['total_pop', 'total_hh'].includes(Object.keys(demoData)[i]) ? 600 : 400 )
.attr('text-anchor', (d, i) => ['pop_mile', 'total_pop'].includes(Object.keys(demoData)[i]) ? 'end' : 'start' )
const labels = svg.append('g')
.attr('transform', `translate(0,${height / 2 - 15})`)
.attr('font-size', '16px')
labels.append('text')
.attr('x', labelPositions[1])
.attr('text-anchor', 'end')
.attr('fill', red)
.text('Inside Boundary')
labels.append('text')
.attr('x', width)
.attr('text-anchor', 'end')
.text('Within 2 mi')
labels.append('text')
.attr('x', width / 2 - 5)
.attr('text-anchor', 'end')
.text('← Housing')
labels.append('text')
.attr('x', width / 2 + 5)
.text('Population →')
return svg.node()
}