private void renderLabels ( Graphics2D g2 , double fontSize ) { int numCategories = confusion . getNumRows ( ) ; int longestLabel = 0 ; if ( renderLabels ) { for ( int i = 0 ; i < numCategories ; i ++ ) { longestLabel = Math . max ( longestLabel , labels . get ( i ) . length ( ) ) ; } } Font fontLabel = new Font ( "monospaced" , Font . BOLD , ( int ) ( 0.055 * longestLabel * fontSize + 0.5 ) ) ; g2 . setFont ( fontLabel ) ; FontMetrics metrics = g2 . getFontMetrics ( fontLabel ) ; // clear the background g2 . setColor ( Color . WHITE ) ; g2 . fillRect ( gridWidth , 0 , viewWidth - gridWidth , viewHeight ) ; // draw the text g2 . setColor ( Color . BLACK ) ; for ( int i = 0 ; i < numCategories ; i ++ ) { String label = labels . get ( i ) ; int y0 = i * gridHeight / numCategories ; int y1 = ( i + 1 ) * gridHeight / numCategories ; Rectangle2D r = metrics . getStringBounds ( label , null ) ; float adjX = ( float ) ( r . getX ( ) * 2 + r . getWidth ( ) ) / 2.0f ; float adjY = ( float ) ( r . getY ( ) * 2 + r . getHeight ( ) ) / 2.0f ; float x = ( ( viewWidth + gridWidth ) / 2f - adjX ) ; float y = ( ( y1 + y0 ) / 2f - adjY ) ; g2 . drawString ( label , x , y ) ; } }
Renders the names on each category to the side of the confusion matrix