View Javadoc
1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: ChartReporter.java,v 1.3 2003/03/05 04:31:56 michaelh Exp $ 20 */ 21 22 package juju.reattore.perfcap.reporter.impl; 23 24 import java.util.*; 25 import java.io.*; 26 import java.net.*; 27 28 import com.jrefinery.chart.*; 29 import com.jrefinery.data.*; 30 31 import org.apache.commons.beanutils.BeanUtils; 32 33 import juju.reattore.perfcap.reporter.Reporter; 34 import juju.reattore.perfcap.var.Variable; 35 import juju.reattore.perfcap.tester.Results; 36 37 /*** Generates a XY chart with multiple series from the input data. 38 39 @tag chartreporter 40 @group Reporter 41 */ 42 public class ChartReporter 43 implements Reporter { 44 45 private String filter; 46 private String out; 47 48 private int width = 400; 49 private int height = 300; 50 private String title = "Chart Title"; 51 private String xAxisTitle = "X"; 52 private String yAxisTitle = "Y"; 53 54 private Map series = new LinkedHashMap(); 55 private XYSeriesCollection col = new XYSeriesCollection(); 56 57 /*** Width of the output image in pixels. 58 59 @param argWidth Value to assign to this.width 60 @default 400 61 */ 62 public void setWidth(int argWidth) { 63 this.width = argWidth; 64 } 65 66 /*** Height of the output image in pixels. 67 68 @param argHeight Value to assign to this.height 69 @default 300 70 */ 71 public void setHeight(int argHeight) { 72 this.height = argHeight; 73 } 74 75 /*** Title to place on the chart. 76 77 @param argTitle Value to assign to this.title 78 @default Chart Title 79 */ 80 public void setTitle(String argTitle) { 81 this.title = argTitle; 82 } 83 84 /*** Title of the X (horizontal) axis. 85 86 @param argXAxisTitle Value to assign to this.xAxisTitle 87 @default X 88 */ 89 public void setXAxisTitle(String argXAxisTitle) { 90 this.xAxisTitle = argXAxisTitle; 91 } 92 93 /*** Title of the Y (vertical) axis. 94 95 @param argYAxisTitle Value to assign to this.yAxisTitle 96 @default Y 97 */ 98 public void setYAxisTitle(String argYAxisTitle) { 99 this.yAxisTitle = argYAxisTitle; 100 } 101 102 /*** The property from the test results. 103 104 @param filter The Bean name of the property. 105 */ 106 public void setFilter(String filter) { 107 filter = "".equals(filter) ? null : filter; 108 this.filter = filter; 109 } 110 111 /*** Name of the file to write to. 112 113 @param out Name of the file. 114 */ 115 public void setOut(String out) { 116 this.out = out; 117 } 118 119 private Number toNumber(Object obj) 120 throws NumberFormatException { 121 122 if (obj instanceof Number) { 123 return (Number)obj; 124 } 125 else { 126 return new Double(obj.toString()); 127 } 128 } 129 130 /*** @see Reporter */ 131 public void add(List ind, Results res) 132 throws Exception { 133 134 Variable var = (Variable)ind.get(0); 135 136 XYSeries se = (XYSeries)series.get(var.getValue()); 137 138 if (se == null) { 139 se = new XYSeries(var.getValue().toString()); 140 series.put(var.getValue(), se); 141 142 col.addSeries(se); 143 } 144 145 Object val; 146 147 if (filter != null) { 148 val = BeanUtils.getProperty(res, filter); 149 } 150 else { 151 /* PENDING */ 152 val = new Integer(0); 153 } 154 155 se.add(toNumber(((Variable)ind.get(1)).getValue()), toNumber(val)); 156 } 157 158 /*** @see Reporter */ 159 public void end() 160 throws Exception { 161 162 JFreeChart chart = ChartFactory.createLineXYChart(title, 163 xAxisTitle, 164 yAxisTitle, 165 col, 166 true, 167 false, 168 false); 169 170 171 ChartUtilities.saveChartAsPNG(new File(out), 172 chart, 173 width, height); 174 } 175 }

This page was automatically generated by Maven