{
const data = _.filter(diffByState, d => d.difference > 0)
const numSlides = 2
const margin = {left: width * 0.5, top: 80, right: 80, bottom: 80}
const xScale = d3.scaleBand().domain(_.map(data, 'state'))
.range([margin.left, numSlides * width - margin.right])
.padding(0.2)
const maxRemoved = d3.max(data, d => d.removed)
const yScale = d3.scaleLinear().domain([0, maxRemoved])
.range([height - margin.bottom, margin.top])
const heightScale = d3.scaleLinear().domain([0, maxRemoved])
.range([0, height - margin.top - margin.bottom])
const bandwidth = xScale.bandwidth()
let render = _.map(data, d => {
return {
x: xScale(d.state), y: height - margin.bottom,
width: bandwidth,
bars: [
{
x: bandwidth * 0.35, width: bandwidth * 0.65,
y: yScale(d.removed), height: heightScale(d.removed),
pattern: true, color: 'gray', text: d3.format(',')(d.removed), fill: true,
},
{
x: 0, width: bandwidth * 0.65,
y: yScale(d.margin), height: heightScale(d.margin),
color: d.party === 'D' ? 'blue' : 'red', fill: true, text: d3.format(',')(d.margin),
},
],
text: d.state,
}
})
const svg = renderBars(render)
return scrollSVG(svg.node())
}