added spacing parameter; refcatoring:extracted LegendImageWriter