calculate graph height correctly when legend is shown or hidden