question: private void Legends ( List < String > legends_list , List < Integer > color_code_list ) { textPaint . setColor ( Color . BLACK ) ; textPaint . setTextSize ( 20f ) ; int left = ( int ) ( graphwidth * 0.1 ) ; for ( int i = 0 ; i < legends_list . size ( ) ; i ++ ) { String label = legends_list . get ( i ) ; float text_width = textPaint . measureText ( label , 0 , label . length ( ) ) ; int color = color_code_list . get ( i ) ; if ( ! ( ( graphwidth - legendLeft ) > ( text_width + 60 ) ) ) { legendTop -= 60 ; legendLeft = left ; } addLegends ( canvas , color , legendTop , legendLeft , legendRight , legendBottom , label ) ; legendLeft += ( ( int ) text_width + 60 ) ; } }
target:  This function calculates the position for each legend