1 39 40 package org.krysalis.jcharts.test; 41 42 43 import org.krysalis.jcharts.Chart; 44 import org.krysalis.jcharts.properties.PropertyException; 45 import org.krysalis.jcharts.chartData.ChartDataException; 46 import org.krysalis.jcharts.encoders.*; 47 48 import java.io.*; 49 50 51 56 public final class ChartTestDriver 57 { 58 private final static String SVG = ".svg"; 59 private final static String PNG = ".png"; 60 private final static String JPEG = ".jpg"; 61 private final static String JPEG_LEGACY = ".jpeg"; 62 final static String OUTPUT_PATH = ""; 63 64 final static String EXTENSION = PNG; 65 66 67 72 public static void main( String [] args ) throws ChartDataException, PropertyException 73 { 74 StopWatch stopWatch = new StopWatch(); 75 stopWatch.start(); 76 77 AxisChartTestBase.axisChartTest( "barChart", new BarTestDriver() ); 78 79 88 89 91 92 101 103 104 106 107 stopWatch.stop(); 108 System.out.println( stopWatch ); 109 } 110 111 112 private static void testAxisScale() 113 { 114 115 double yMax = -15; 116 double yMin = -130; 117 118 double yDelta = Math.pow( 10.0, Math.round( Math.log( yMax - yMin ) / Math.log( 10 ) ) ); 121 double yStart = yMin - (yMin % yDelta); 122 double yEnd = yMax - (yMax % yDelta) + yDelta; 123 124 System.out.println( "yDelta= " + yDelta + " yStart= " + yStart + " yEnd= " + yEnd ); 125 126 127 int segments = ( int ) ((yEnd - yStart) / yDelta); 129 130 if( segments <= 2 ) 131 { 132 yDelta = yDelta / 10.0; 134 } 135 else if( segments <= 5 ) 136 { 137 yDelta = yDelta / 4.0; 139 } 140 else if( segments <= 10 ) 141 { 142 yDelta = yDelta / 2.0; 143 } 144 145 yStart = yMin - (yMin % yDelta); 147 yEnd = yMax - (yMax % yDelta) + yDelta; 148 segments = ( int ) ((yEnd - yStart) / yDelta); 149 150 155 156 157 } 158 159 160 169 static void exportImage( Chart chart, String fileName ) throws ChartDataException, PropertyException 170 { 171 try 172 { 173 FileOutputStream fileOutputStream = new FileOutputStream( fileName ); 174 175 if( EXTENSION.equals( SVG ) ) 176 { 177 SVGEncoder.encode( chart, fileOutputStream ); 178 } 179 else if( EXTENSION.equals( PNG ) ) 180 { 181 PNGEncoder.encode( chart, fileOutputStream ); 182 } 183 else if( EXTENSION.equals( JPEG ) ) 184 { 185 JPEGEncoder.encode( chart, 1.0f, fileOutputStream ); 186 } 187 else if( EXTENSION.equals( JPEG_LEGACY ) ) 188 { 189 JPEGEncoder13.encode( chart, 1.0f, fileOutputStream ); 190 } 191 else 192 { 193 System.out.println( "unknown file type to encode: " + EXTENSION ); 194 } 195 196 fileOutputStream.flush(); 197 fileOutputStream.close(); 198 } 199 catch( FileNotFoundException fileNotFoundException ) 200 { 201 fileNotFoundException.printStackTrace(); 202 } 203 catch( IOException ioException ) 204 { 205 ioException.printStackTrace(); 206 } 207 } 208 209 210 } 211 | Popular Tags |