finalizing the diagram output code