{
const svg = d3.create('svg')
.attr('width', visWidth + margin.left + margin.right)
.attr('height', visHeight + margin.top + margin.bottom);
const g = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
g.append('g')
.attr('transform', `translate(0, ${visHeight})`)
.call(boroughXAxis)
g.append('g')
.call(boroughYAxis)
g.append('g')
.selectAll('g')
.data(stack)
.join('g')
.attr('fill', d => colorStack(d.key))
.selectAll('rect')
.data( d => d)
.join('rect')
.attr('x', d => {
console.log('what did I do here?');
console.log(d);
return boroughX(d.data.borough)})
.attr('y', d => boroughY(d[1]))
.attr('height', d=>boroughY(d[0]) - boroughY(d[1]))
.attr('width', boroughX.bandwidth())
g.append('g')
.attr('class', 'legend')
.selectAll('rect')
.data(stack)
.enter()
.append('rect')
.attr('x', 0)
.attr('y', function(d,i){
return i * 18;
})
.attr('width', 12)
.attr('height', 12)
.attr('fill', function(d,i){
console.log(colorStack(i));
return colorStack(i);
})
.selectAll('text')
.data(stack)
.enter()
.append('text')
.text(function(d){
return d.key;
})
.attr('x', 15)
.attr('y', function(d, i){
return i * 18;
})
.attr('text-anchor', 'start')
.attr('alignment-baseline', 'hanging');
return Object.assign(svg.node(), {scales: {colorStack}});
}