{
const height = 400
const svg = d3.select(DOM.svg(width, height))
const tooltip = d3tip()
.style('border', 'solid 1px black')
.style('background-color', 'white')
.style('border-radius', '10px')
.style('float', 'left')
.style('font-family', 'monospace')
.style('font-size', '12px')
.html(d => `
<div>
Date (date): ${moment(d.date).date()} <br/>
Streams: ${d.streams} <br/>
</div>`)
svg.call(tooltip)
const margin = { left: 70, top: 10, right: 30, bottom: 50 }
const song = _.find(spotifySongs, { trackName })
const data = spotifyDailyGlobalRanking
.filter(d => d.trackId === song.trackId && d.date.substring(0, 7) === selectedMonth)
const xScale = d3.scaleBand()
.padding(0.1)
.range([margin.left, width - margin.right])
.domain(_.range(1, moment(selectedMonth).daysInMonth() + 1))
svg.append('g')
.call(d3.axisBottom(xScale).tickFormat(d3.format('02d')))
.attr('transform', `translate(0,${height - margin.bottom})`)
const yScale = d3.scaleLinear()
.range([height - margin.bottom, margin.top])
.domain([0, d3.max(data.map(d => d.streams))])
svg.append('g')
.call(d3.axisLeft(yScale).tickFormat(d3.format('.2s')))
.attr('transform', `translate(${margin.left},0)`)
svg.append('text')
.attr('transform', `translate(${width/2},${height})`)
.style('text-anchor', 'middle')
.style('font-weight', 'bold')
.text('Date (date)')
svg.append('text')
.attr('transform', 'rotate(-90)')
.attr('y', 0)
.attr('x',0 - (height / 2))
.attr('dy', '1em')
.style('text-anchor', 'middle')
.style('font-weight', 'bold')
.text('Streams')
svg.selectAll('.bar')
.data(data)
.enter()
.append('rect')
.attr('x', d => xScale(moment(d.date).date()))
.attr('y', d => yScale(d.streams))
.attr('height', d => yScale(0) - yScale(d.streams))
.attr('width', xScale.bandwidth())
.attr('fill', 'SteelBlue')
.on('mouseover', tooltip.show)
.on('mousemove', tooltip.show)
.on('mouseout', tooltip.hide)
return svg.node()
}