legend function