X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Futil%2FAsciiHistogram.java;h=7c8082f742cf7320dd86811663a50a3914a1ea57;hb=3929e5396afcdc3c79e7e4421c9fd444bb2e7a1b;hp=3d295cfcade1bae28a52ec50bfdb931eaceceefb;hpb=eee996a6476a1e3d84c07f8f690dcde3ff4b2ef5;p=jalview.git diff --git a/forester/java/src/org/forester/util/AsciiHistogram.java b/forester/java/src/org/forester/util/AsciiHistogram.java index 3d295cf..7c8082f 100644 --- a/forester/java/src/org/forester/util/AsciiHistogram.java +++ b/forester/java/src/org/forester/util/AsciiHistogram.java @@ -22,7 +22,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.util; @@ -50,7 +50,8 @@ public class AsciiHistogram { final int max_count, final int under, final int over, - final double binning_factor ) { + final double binning_factor, + final String indent ) { final double draw_factor = ( double ) max_count / size; final int counts_size = ForesterUtil.roundToInt( Math.log10( max_count ) ) + 1; if ( !ForesterUtil.isEmpty( getTitle() ) ) { @@ -59,12 +60,18 @@ public class AsciiHistogram { sb.append( ForesterUtil.LINE_SEPARATOR ); } if ( under > 0 ) { + if ( !ForesterUtil.isEmpty( indent ) ) { + sb.append( indent ); + } sb.append( "[" + under + "] " ); sb.append( ForesterUtil.LINE_SEPARATOR ); } for( int i = 0; i < bins.length; ++i ) { final int count = bins[ i ]; - final double label = ForesterUtil.round( ( min + i * ( 1.0 / binning_factor ) ), digits ); + final double label = ForesterUtil.round( ( min + ( i * ( 1.0 / binning_factor ) ) ), digits ); + if ( !ForesterUtil.isEmpty( indent ) ) { + sb.append( indent ); + } sb.append( ForesterUtil.pad( label + "", digits, '0', false ) ); sb.append( " [" + ForesterUtil.pad( count + "", counts_size, ' ', true ) + "] " ); final int s = ForesterUtil.roundToInt( count / draw_factor ); @@ -74,6 +81,9 @@ public class AsciiHistogram { sb.append( ForesterUtil.LINE_SEPARATOR ); } if ( over > 0 ) { + if ( !ForesterUtil.isEmpty( indent ) ) { + sb.append( indent ); + } sb.append( "[" + over + "] " ); sb.append( ForesterUtil.LINE_SEPARATOR ); } @@ -92,7 +102,8 @@ public class AsciiHistogram { final int number_of_bins, final char symbol, final int size, - final int digits ) { + final int digits, + final String indent ) { if ( min >= max ) { throw new IllegalArgumentException( "min [" + min + "] is larger than or equal to max [" + max + "]" ); } @@ -112,16 +123,31 @@ public class AsciiHistogram { max_count = bin; } } - drawToStringBuffer( min, symbol, size, digits, sb, bins, max_count, 0, 0, binning_factor ); + drawToStringBuffer( min, symbol, size, digits, sb, bins, max_count, 0, 0, binning_factor, indent ); return sb; } + public StringBuffer toStringBuffer( final int bins, + final char symbol, + final int size, + final int digits, + final String indent ) { + return toStringBuffer( getDescriptiveStatistics().getMin(), + getDescriptiveStatistics().getMax(), + bins, + symbol, + size, + digits, + indent ); + } + public StringBuffer toStringBuffer( final int bins, final char symbol, final int size, final int digits ) { return toStringBuffer( getDescriptiveStatistics().getMin(), getDescriptiveStatistics().getMax(), bins, symbol, size, - digits ); + digits, + null ); } }