cytoscape legend fix and refactor #3435

#3435