Custom legend fragment formatter

If option specified then a custom fragment formatter will produce the html for the legend entries.
Still uses table format.
Changed to use DOM elements for the legend construction rather than strings.