When computing the graph layout, graphlib was breaking if different pieces of legend text had different heights.
It was spacing out the legend text according to the maximum height, but summing the individual heights when working out the overall size of the box. Therefore, sometimes the box drawn round the legend was too small.