Added legend functionality