factor out svg outputting code