You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by wo...@apache.org on 2005/11/16 05:24:13 UTC

svn commit: r344877 - in /jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter: report/ report/gui/ testelement/

Author: woolfel
Date: Tue Nov 15 20:24:07 2005
New Revision: 344877

URL: http://svn.apache.org/viewcvs?rev=344877&view=rev
Log:
changed BarChart to use AxisGraph, since that class already reders bar charts

Modified:
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/DataSet.java
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/ReportChart.java
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/gui/BarChartGui.java
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/AbstractChart.java
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/BarChart.java
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/JTLData.java
    jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/LineGraph.java

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/DataSet.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/DataSet.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/DataSet.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/DataSet.java Tue Nov 15 20:24:07 2005
@@ -18,6 +18,7 @@
 package org.apache.jmeter.report;
 
 import java.util.Date;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.jmeter.visualizers.SamplingStatCalculator;
@@ -89,6 +90,13 @@
      * @return
      */
     public SamplingStatCalculator getStatistics(String url);
+    /**
+     * Convienance method for getting all the SamplingStatCalculator for
+     * a given URL.
+     * @param urls
+     * @return
+     */
+    public List getStats(List urls);
     /**
      * Classes implementing the method should load the data from
      * the target location. It doesn't necessarily have to be a

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/ReportChart.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/ReportChart.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/ReportChart.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/ReportChart.java Tue Nov 15 20:24:07 2005
@@ -17,17 +17,16 @@
  */
 package org.apache.jmeter.report;
 
+import java.util.List;
 import javax.swing.JComponent;
 
 
 public interface ReportChart {
     /**
-     * The idea is a report table will be passed to a ReportChart
-     * TestElement. The ReportChart is responsible for choosing which
-     * columns/rows it needs and generate a chart for it. The chart
-     * object is a JComponent.
-     * @param element
+     * The method takes a list of the DataSet items. It is up to the chart
+     * class to extract the data and use it to render a graphic.
+     * @param list of DataSet 
      * @return
      */
-	JComponent renderChart(ReportTable element);
+	JComponent renderChart(List data);
 }

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/gui/BarChartGui.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/gui/BarChartGui.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/gui/BarChartGui.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/report/gui/BarChartGui.java Tue Nov 15 20:24:07 2005
@@ -46,6 +46,9 @@
     private JLabeledTextField caption = 
         new JLabeledTextField(JMeterUtils.getResString("report_chart_caption"),
                 Color.white);
+    private JLabeledTextField url = 
+        new JLabeledTextField(JMeterUtils.getResString("report_bar_graph_url"),
+                Color.white);
 
     private JLabeledChoice yItems = new JLabeledChoice();
 	private JLabeledChoice xItems = new JLabeledChoice();
@@ -100,6 +103,7 @@
         options.add(ypanel);
         options.add(yAxisLabel);
         options.add(caption);
+        options.add(url);
         
         add(pane,BorderLayout.NORTH);
         add(options,BorderLayout.CENTER);
@@ -119,6 +123,7 @@
 		bc.setXLabel(xAxisLabel.getText());
 		bc.setYLabel(yAxisLabel.getText());
         bc.setCaption(caption.getText());
+        bc.setURL(url.getText());
 	}
 	
     public void configure(TestElement element) {
@@ -129,6 +134,7 @@
         xAxisLabel.setText(bc.getXLabel());
         yAxisLabel.setText(bc.getYLabel());
         caption.setText(bc.getCaption());
+        url.setText(bc.getURL());
     }
     
 }

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/AbstractChart.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/AbstractChart.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/AbstractChart.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/AbstractChart.java Tue Nov 15 20:24:07 2005
@@ -17,10 +17,12 @@
  */
 package org.apache.jmeter.testelement;
 
+import java.awt.image.BufferedImage;
+import java.util.List;
+
 import javax.swing.JComponent;
 
 import org.apache.jmeter.report.ReportChart;
-import org.apache.jmeter.report.ReportTable;
 
 /**
  * The general idea of the chart graphs information for a table.
@@ -37,6 +39,10 @@
     public static final String REPORT_CHART_Y_LABEL = "ReportChart.chart.y.label";
     public static final String REPORT_CHART_TITLE = "ReportChart.chart.title";
     public static final String REPORT_CHART_CAPTION = "ReportChart.chart.caption";
+    
+    public static final int DEFAULT_WIDTH = 300;
+    public static final int DEFAULT_HEIGHT = 250;
+    protected BufferedImage image = null;
 
     public AbstractChart() {
 		super();
@@ -119,5 +125,21 @@
      * 3. pass the data to the chart library
      * 4. return the generated chart
      */
-	public abstract JComponent renderChart(ReportTable element);
+	public abstract JComponent renderChart(List data);
+    
+    /**
+     * this makes it easy to get the bufferedImage
+     * @return
+     */
+    public BufferedImage getBufferedImage() {
+        return this.image;
+    }
+    
+    /**
+     * in case an user wants set the bufferdImage
+     * @param img
+     */
+    public void setBufferedImage(BufferedImage img) {
+        this.image = img;
+    }
 }

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/BarChart.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/BarChart.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/BarChart.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/BarChart.java Tue Nov 15 20:24:07 2005
@@ -17,30 +17,18 @@
  */
 package org.apache.jmeter.testelement;
 
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Paint;
+import java.awt.Dimension;
+import java.awt.image.BufferedImage;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
 import javax.swing.JComponent;
-import javax.swing.JPanel;
 
 import org.apache.jmeter.report.DataSet;
+import org.apache.jmeter.visualizers.AxisGraph;
 import org.apache.jmeter.visualizers.SamplingStatCalculator;
 
-import org.jCharts.axisChart.AxisChart;
-import org.jCharts.chartData.AxisChartDataSet;
-import org.jCharts.chartData.DataSeries;
-import org.jCharts.properties.AxisProperties;
-import org.jCharts.properties.BarChartProperties;
-import org.jCharts.properties.ChartProperties;
-import org.jCharts.properties.LegendProperties;
-import org.jCharts.types.ChartType;
-
-
 /**
  * The class is reponsible for returning 
  * @author pete
@@ -73,6 +61,7 @@
         for (int idx=0; idx < data.size(); idx++) {
             SamplingStatCalculator stat = (SamplingStatCalculator)data.get(idx);
             dataset[0][idx] = getValue(stat);
+            // System.out.println("data=" + dataset[0][idx]);
         }
         return dataset;
     }
@@ -82,12 +71,12 @@
         ArrayList xlabels = new ArrayList();
         Iterator itr = data.iterator();
         while (itr.hasNext()) {
-            DataSet ds = (DataSet)itr.next();
-            SamplingStatCalculator ss = ds.getStatistics(this.getURL());
+            DataSet item = (DataSet)itr.next();
+            SamplingStatCalculator ss = item.getStatistics(this.getURL());
             if (ss != null) {
                 // we add the entry
                 dset.add(ss);
-                xlabels.add(ds.getDataSource());
+                xlabels.add(item.getDataSource());
             }
         }
         double[][] dbset = convertToDouble(dset);
@@ -96,37 +85,22 @@
     
     public JComponent renderGraphics(double[][] data, String[] xAxisLabels) {
         String title = this.getTitle();
-        String xAxisTitle = this.getXAxis();
-        String yAxisTitle = this.getYAxis();
-        String yAxisLabel = this.getYLabel();
-        int width = 350;
-        int height = 300;
-        Graphics g;
-        JPanel panel = new JPanel();
-        try {
-            
-            DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
-            
-            String[] legendLabels= { yAxisLabel };
-            Paint[] paints = new Paint[]{ Color.blue.darker() };
-            BarChartProperties barChartProperties= new BarChartProperties();
-            AxisChartDataSet axisChartDataSet =
-                new AxisChartDataSet(
-                        data, legendLabels, paints, ChartType.BAR, barChartProperties );
-            dataSeries.addIAxisPlotDataSet( axisChartDataSet );
-
-            ChartProperties chartProperties= new ChartProperties();
-            AxisProperties axisProperties= new AxisProperties();
-            axisProperties.setXAxisLabelsAreVertical(true);
-            LegendProperties legendProperties= new LegendProperties();
-            AxisChart axisChart = new AxisChart( 
-                    dataSeries, chartProperties, axisProperties, 
-                    legendProperties, width, height );
-            axisChart.setGraphics2D((Graphics2D) panel.getGraphics());
-            axisChart.render();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        AxisGraph panel = new AxisGraph();
+        panel.setTitle(this.getTitle());
+        panel.setData(data);
+        panel.setXAxisLabels(xAxisLabels);
+        panel.setYAxisLabels(this.getYLabel());
+        panel.setXAxisTitle(this.getXAxis());
+        panel.setYAxisTitle(this.getYAxis());
+        // we should make this configurable eventually
+        int width = 400;
+        int height = 400;
+        panel.setPreferredSize(new Dimension(width,height));
+        panel.setSize(new Dimension(width,height));
+        panel.setWidth(width);
+        panel.setHeight(width);
+        setBufferedImage(new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB));
+        panel.paintComponent(this.getBufferedImage().createGraphics());
         return panel;
     }
     

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/JTLData.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/JTLData.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/JTLData.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/JTLData.java Tue Nov 15 20:24:07 2005
@@ -178,8 +178,6 @@
             this.endTimestamp = sample.getEndTime();
         }
         // now add the samples to the HashMap
-        System.out.println("label=" + sample.getSampleLabel());
-        System.out.println("url=" + sample.getURL());
         String url = sample.getSampleLabel();
         if (url == null) {
             url = sample.getURL().toString();
@@ -192,7 +190,6 @@
             this.data.put(url,row);
         }
         row.addSample(sample);
-        System.out.println(" count=" + row.getCount());
     }
     
     /**

Modified: jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/LineGraph.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/LineGraph.java?rev=344877&r1=344876&r2=344877&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/LineGraph.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/reports/org/apache/jmeter/testelement/LineGraph.java Tue Nov 15 20:24:07 2005
@@ -17,13 +17,38 @@
  */
 package org.apache.jmeter.testelement;
 
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Paint;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.util.List;
+
 import javax.swing.JComponent;
+import javax.swing.JPanel;
 
-import org.apache.jmeter.report.ReportTable;
+import org.jCharts.axisChart.AxisChart;
+import org.jCharts.chartData.AxisChartDataSet;
+import org.jCharts.chartData.DataSeries;
+import org.jCharts.properties.AxisProperties;
+import org.jCharts.properties.ChartProperties;
+import org.jCharts.properties.LegendProperties;
+import org.jCharts.properties.LineChartProperties;
+import org.jCharts.properties.PointChartProperties;
+import org.jCharts.types.ChartType;
 
 public class LineGraph extends AbstractChart {
 
     public static final String REPORT_CHART_URLS = "ReportChart.chart.urls";
+    public static final Shape[] SHAPE_ARRAY = {PointChartProperties.SHAPE_CIRCLE,
+            PointChartProperties.SHAPE_DIAMOND,PointChartProperties.SHAPE_SQUARE,
+            PointChartProperties.SHAPE_TRIANGLE};
+    
+    protected int width = 350;
+    protected int height = 250;
+    
+    protected int shape_counter = 0;
 
 	public LineGraph() {
 		super();
@@ -37,8 +62,92 @@
         setProperty(REPORT_CHART_URLS,urls);
     }
     
-	public JComponent renderChart(ReportTable element) {
-		return null;
+	public JComponent renderChart(List dataset) {
+        
+        return renderGraphics(null);
 	}
 
+    public JComponent renderGraphics(double[][] data) {
+        String title = this.getTitle();
+        String xAxisTitle = this.getXAxis();
+        String yAxisTitle = this.getYAxis();
+        String yAxisLabel = this.getYLabel();
+        String[] xAxisLabels = {this.getXLabel() };
+        Graphics g;
+        JPanel panel = new JPanel();
+        
+        DataSeries dataSeries = new DataSeries( xAxisLabels, xAxisTitle, yAxisTitle, title );
+        
+        String[] legendLabels= { yAxisLabel };
+        Paint[] paints= new Paint[]{ Color.blue.darker() };
+        Shape[] shapes = createShapes(data.length);
+        Stroke[] lstrokes = createStrokes(data.length);
+        LineChartProperties lineChartProperties= new LineChartProperties(lstrokes,shapes);
+
+        try {
+            AxisChartDataSet axisChartDataSet= new AxisChartDataSet( data, 
+                    legendLabels, 
+                    paints, 
+                    ChartType.LINE, 
+                    lineChartProperties );
+            dataSeries.addIAxisPlotDataSet( axisChartDataSet );
+
+            ChartProperties chartProperties= new ChartProperties();
+            AxisProperties axisProperties= new AxisProperties();
+            LegendProperties legendProperties= new LegendProperties();
+
+            AxisChart axisChart = new AxisChart( dataSeries, 
+                    chartProperties, 
+                    axisProperties, 
+                    legendProperties, 
+                    width, 
+                    height );
+        } catch (Exception e) {
+            
+        }
+
+        return panel;
+    }
+    
+    /**
+     * Since we only have 4 shapes, the method will start with the
+     * first shape and keep cycling through the shapes in order.
+     * @param count
+     * @return
+     */
+    public Shape[] createShapes(int count) {
+        Shape[] shapes = new Shape[count];
+        for (int idx=0; idx < count; idx++) {
+            shapes[idx] = nextShape();
+        }
+        return shapes;
+    }
+    
+    /**
+     * Return the next shape
+     * @return
+     */
+    public Shape nextShape() {
+        if (shape_counter >= (SHAPE_ARRAY.length - 1)) {
+            shape_counter = 0;
+        }
+        return SHAPE_ARRAY[shape_counter];
+    }
+    
+    /**
+     * 
+     * @param count
+     * @return
+     */
+    public Stroke[] createStrokes(int count) {
+        Stroke[] str = new Stroke[count];
+        for (int idx=0; idx < count; idx++) {
+            str[idx] = nextStroke();
+        }
+        return str;
+    }
+    
+    public Stroke nextStroke() {
+        return new BasicStroke(1.5f);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org