function hover(svg, bar) {
const textOffset = 45
const tooltip = svg.append('g')
.attr('class', 'tooltip')
.style('display', 'none')
const hoverBox = tooltip.append('rect')
.attr('width', 30)
.attr('height', 30)
.attr('fill', 'white')
.style('opacity', 0.5)
const text = tooltip.append('text')
.attr('x', textOffset)
.attr('dy', '12em')
.style('text-anchor', 'start')
.attr('font-size', '73px')
.attr('font-weight', 'bold')
bar
.on('mouseover', () => {
tooltip.style('display', null)
let { width } = text.node().getBBox()
hoverBox.attr('width', `${ width + textOffset+10 }px`)
})
.on('mouseout', () => tooltip.style('display', 'none'))
.on('mousemove', function(d) {
let xPosition = d3.mouse(this)[0] - 15
let yPosition = d3.mouse(this)[1] - 25
let index = datumIndexByXCoord(d3.mouse(this)[0])
tooltip.attr('transform', `translate( ${ xPosition }, ${ yPosition })`)
tooltip.select('text').text(`${ d.key }: ${ d[index][1] - d[index][0] }`)
})
}