summaryrefslogtreecommitdiff
path: root/qpid/java/perftests
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2012-06-15 13:57:25 +0000
committerKeith Wall <kwall@apache.org>2012-06-15 13:57:25 +0000
commit178f342319aee9f6f85545aa48e4a442b060d6b6 (patch)
treed15ebdab0a76959a77da6b85d0b104ca4b99438e /qpid/java/perftests
parentb1a8ce50c064c05db8ffe0eb7d98cf667bc3d109 (diff)
downloadqpid-python-178f342319aee9f6f85545aa48e4a442b060d6b6.tar.gz
QPID-3977: Add support for 3D bar/line charts; XY line charts, chart subtitles, and add Main-Class/Class-Path manifest entries to visualisation JAR to allow for convienient use from command line.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1350624 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests')
-rw-r--r--qpid/java/perftests/visualisation-jfc/build.xml21
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java3
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java71
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java56
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java15
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java58
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java (renamed from qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java)42
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java6
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java13
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java52
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java16
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java102
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYLineChartBuilder.java51
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java12
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java9
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java (renamed from qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java)21
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java32
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java (renamed from qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java)7
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java76
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java26
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java166
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java4
-rw-r--r--qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java (renamed from qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java)18
23 files changed, 777 insertions, 100 deletions
diff --git a/qpid/java/perftests/visualisation-jfc/build.xml b/qpid/java/perftests/visualisation-jfc/build.xml
index 6fafba0480..a9fd6c4102 100644
--- a/qpid/java/perftests/visualisation-jfc/build.xml
+++ b/qpid/java/perftests/visualisation-jfc/build.xml
@@ -19,9 +19,30 @@
<project name="visualisation-jfc" xmlns:ivy="antlib:org.apache.ivy.ant" default="build">
<property name="module.depends" value="common perftests" />
<property name="module.test.depends" value="test" />
+ <property name="module.manifest" value="true" />
<import file="../../module.xml" />
+ <!-- Overridden to produce Manifest containing Main-Class and Class-Path -->
+ <target name="jar.manifest" depends="compile" if="module.manifest">
+ <path id="class.path">
+ <fileset dir="${build.lib}" >
+ <include name="*.jar"/>
+ <exclude name="${qpid.jar.name}"/>
+ </fileset>
+ </path>
+ <pathconvert property="qpid.jar.classpath" pathsep=" " dirsep="/">
+ <path refid="class.path"/>
+ <globmapper from="${build.lib}${file.separator}*" to="*"/>
+ </pathconvert>
+
+ <jar destfile="${module.jar}" basedir="${module.classes}">
+ <manifest>
+ <attribute name="Class-Path" value="${qpid.jar.classpath}"/>
+ <attribute name="Main-Class" value="org.apache.qpid.disttest.charting.ChartingUtil"/>
+ </manifest>
+ </jar>
+ </target>
<!-- JFreeChart and JFreeCommon -->
<condition property="download.jfree.jars">
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
index 2803f2d767..8bddfd1379 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java
@@ -21,6 +21,5 @@ package org.apache.qpid.disttest.charting;
public enum ChartType
{
- LINE, BAR
-
+ LINE, LINE3D, BAR, BAR3D, XYLINE
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
index a149d1a097..f46bc45583 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java
@@ -20,11 +20,7 @@
*/
package org.apache.qpid.disttest.charting;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,11 +30,24 @@ import org.apache.qpid.disttest.charting.chartbuilder.ChartBuilder;
import org.apache.qpid.disttest.charting.chartbuilder.ChartBuilderFactory;
import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator;
-import org.jfree.chart.ChartUtilities;
+import org.apache.qpid.disttest.charting.seriesbuilder.JdbcCsvSeriesBuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.disttest.charting.writer.ChartWriter;
import org.jfree.chart.JFreeChart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Draws charts for data drawn from CSV datasources using rules described in
+ * charting definitions (.chartdef) files.
+ * <p>
+ * The following arguments are understood:
+ * </p>
+ * <ol>
+ * <li>chart-defs=<i>directory contain chartdef file(s)</i></li>
+ * <li>output-dir=<i>directory in which to produce the PNGs</i></li>
+ * </ol>
+ */
public class ChartingUtil
{
private static final Logger LOGGER = LoggerFactory.getLogger(ChartingUtil.class);
@@ -59,7 +68,7 @@ public class ChartingUtil
{
try
{
- LOGGER.debug("Starting charting");
+ LOGGER.info("Starting charting");
ChartingUtil chartingUtil = new ChartingUtil();
chartingUtil.parseArgumentsIntoConfig(args);
@@ -67,55 +76,29 @@ public class ChartingUtil
}
finally
{
- LOGGER.debug("Charting complete");
+ LOGGER.info("Charting complete");
}
}
private void produceAllCharts()
{
final String chartingDefsDir = _cliOptions.get(CHART_DEFINITIONS_PROP);
+ final File chartDirectory = new File(_cliOptions.get(OUTPUT_DIR_PROP));
+ LOGGER.info("Chart chartdef directory/file: {} output directory : {}", chartingDefsDir, chartDirectory);
+
List<ChartingDefinition> definitions = loadChartDefinitions(chartingDefsDir);
- LOGGER.debug("There are {} chart(s) to produce", definitions.size());
+ LOGGER.info("There are {} chart(s) to produce", definitions.size());
+
+ final ChartWriter writer = new ChartWriter();
+ writer.setOutputDirectory(chartDirectory);
+ final SeriesBuilder seriesBuilder = new JdbcCsvSeriesBuilder();
for (ChartingDefinition chartingDefinition : definitions)
{
- ChartBuilder chartBuilder = ChartBuilderFactory.createChartBuilder(chartingDefinition.getChartType());
+ ChartBuilder chartBuilder = ChartBuilderFactory.createChartBuilder(chartingDefinition.getChartType(), seriesBuilder);
JFreeChart chart = chartBuilder.buildChart(chartingDefinition);
- writeChartToFileSystem(chart, chartingDefinition.getChartStemName());
- }
- }
-
- private void writeChartToFileSystem(JFreeChart chart, String chartStemName)
- {
- OutputStream pngOutputStream = null;
- try
- {
-
- File pngFile = new File(chartStemName + ".png");
- pngOutputStream = new BufferedOutputStream(new FileOutputStream(pngFile));
- ChartUtilities.writeChartAsPNG(pngOutputStream, chart, 600, 400, true, 0);
- pngOutputStream.close();
-
- LOGGER.debug("Written {} chart", pngFile);
- }
- catch (IOException e)
- {
- throw new ChartingException("Failed to create chart", e);
- }
- finally
- {
- if (pngOutputStream != null)
- {
- try
- {
- pngOutputStream.close();
- }
- catch (IOException e)
- {
- throw new ChartingException("Failed to create chart", e);
- }
- }
+ writer.writeChartToFileSystem(chart, chartingDefinition.getChartStemName());
}
}
@@ -130,6 +113,4 @@ public class ChartingUtil
ArgumentParser argumentParser = new ArgumentParser();
argumentParser.parseArgumentsIntoConfig(_cliOptions, args);
}
-
-
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java
new file mode 100644
index 0000000000..491bb1c67d
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.general.Dataset;
+
+public class BarChart3DBuilder extends CategoryDataSetBasedChartBuilder
+{
+
+ public BarChart3DBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
+ boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = ChartFactory.createBarChart3D(title,
+ xAxisTitle,
+ yAxisTitle,
+ (CategoryDataset)dataset,
+ plotOrientation,
+ showLegend,
+ showToolTips,
+ showUrls);
+
+ return chart;
+ }
+
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
index 302263a604..b5c6a38067 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java
@@ -19,23 +19,30 @@
*/
package org.apache.qpid.disttest.charting.chartbuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.general.Dataset;
-public class BarChartBuilder extends DataSetBasedChartBuilder
+public class BarChartBuilder extends CategoryDataSetBasedChartBuilder
{
+ public BarChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
@Override
public JFreeChart createChartImpl(String title, String xAxisTitle,
- String yAxisTitle, final DefaultCategoryDataset dataset, PlotOrientation plotOrientation,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
boolean showLegend, boolean showToolTips, boolean showUrls)
{
JFreeChart chart = ChartFactory.createBarChart(title,
xAxisTitle,
yAxisTitle,
- dataset,
+ (CategoryDataset) dataset,
plotOrientation,
showLegend,
showToolTips,
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java
new file mode 100644
index 0000000000..def87f5840
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import java.awt.Color;
+import java.awt.GradientPaint;
+
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.title.ShortTextTitle;
+import org.jfree.data.general.Dataset;
+
+public abstract class BaseChartBuilder implements ChartBuilder
+{
+ private static final GradientPaint BLUE_GRADIENT = new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue);
+
+ public void addCommonChartAttributes(JFreeChart chart, ChartingDefinition chartingDefinition)
+ {
+ addSubtitle(chart, chartingDefinition);
+ setBackgroundColour(chart);
+ }
+
+ private void addSubtitle(JFreeChart chart, ChartingDefinition chartingDefinition)
+ {
+ if (chartingDefinition.getChartSubtitle() != null)
+ {
+ chart.addSubtitle(new ShortTextTitle(chartingDefinition.getChartSubtitle()));
+ }
+ }
+
+ private void setBackgroundColour(JFreeChart chart)
+ {
+ chart.setBackgroundPaint(BLUE_GRADIENT);
+ }
+
+ public abstract JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips,
+ boolean showUrls);
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java
index 6e2491c883..ad33da8311 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java
@@ -21,15 +21,19 @@ package org.apache.qpid.disttest.charting.chartbuilder;
import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
import org.jfree.chart.JFreeChart;
-import org.jfree.chart.axis.CategoryLabelPositions;
-import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
-public abstract class DataSetBasedChartBuilder implements ChartBuilder
+public abstract class CategoryDataSetBasedChartBuilder extends BaseChartBuilder
{
- private static final CategoryLabelPositions LABEL_POSITION = CategoryLabelPositions.UP_45;
- private static final PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL;
+ private final SeriesBuilder _seriesBuilder;
+
+ public CategoryDataSetBasedChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ _seriesBuilder = seriesBuilder;
+ }
@Override
public JFreeChart buildChart(ChartingDefinition chartingDefinition)
@@ -40,29 +44,37 @@ public abstract class DataSetBasedChartBuilder implements ChartBuilder
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
- SeriesBuilder seriesBuilder = new SeriesBuilder(new DataPointCallback()
+ _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback()
{
@Override
public void addDataPointToSeries(SeriesDefinition seriesDefinition,
Object xValue, Object yValue)
{
- String x = (String) xValue;
- double y = (Double) yValue;
+ String x = String.valueOf(xValue);
+ double y = Double.parseDouble(yValue.toString());
dataset.addValue( y, seriesDefinition.getSeriesLegend(), x);
}
+
+ @Override
+ public void beginSeries(SeriesDefinition seriesDefinition)
+ {
+ // unused
+ }
+
+ @Override
+ public void endSeries(SeriesDefinition seriesDefinition)
+ {
+ // unused
+ }
});
- seriesBuilder.build(chartingDefinition.getSeries());
+ _seriesBuilder.build(chartingDefinition.getSeries());
JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle,
- dataset, PLOT_ORIENTATION, true, false, false);
+ dataset, PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS);
- chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(LABEL_POSITION);
+ addCommonChartAttributes(chart, chartingDefinition);
return chart;
}
-
- public abstract JFreeChart createChartImpl(String title, String xAxisTitle,
- String yAxisTitle, final DefaultCategoryDataset dataset, PlotOrientation plotOrientation,
- boolean showLegend, boolean showToolTips, boolean showUrls);
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java
index c6f5ecc175..425b83596f 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java
@@ -21,10 +21,14 @@ package org.apache.qpid.disttest.charting.chartbuilder;
import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
public interface ChartBuilder
{
+ public static final boolean SHOW_URLS = false;
+ public static final boolean SHOW_TOOL_TIPS = false;
+ public static final boolean SHOW_LEGEND = true;
+ public static final PlotOrientation PLOT_ORIENTATION = PlotOrientation.VERTICAL;
public JFreeChart buildChart(ChartingDefinition chartingDefinition);
-
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
index 4c5d4fa09f..f9d5a5a0df 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java
@@ -20,18 +20,25 @@
package org.apache.qpid.disttest.charting.chartbuilder;
import org.apache.qpid.disttest.charting.ChartType;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
public class ChartBuilderFactory
{
- public static ChartBuilder createChartBuilder(ChartType chartType)
+ public static ChartBuilder createChartBuilder(ChartType chartType, SeriesBuilder seriesBuilder)
{
switch (chartType)
{
case LINE:
- return new LineChartBuilder();
+ return new LineChartBuilder(seriesBuilder);
+ case LINE3D:
+ return new LineChart3DBuilder(seriesBuilder);
case BAR:
- return new BarChartBuilder();
+ return new BarChartBuilder(seriesBuilder);
+ case BAR3D:
+ return new BarChart3DBuilder(seriesBuilder);
+ case XYLINE:
+ return new XYLineChartBuilder(seriesBuilder);
default:
throw new IllegalArgumentException("Unknown chart type " + chartType);
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java
new file mode 100644
index 0000000000..27fff12da0
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.general.Dataset;
+
+public class LineChart3DBuilder extends CategoryDataSetBasedChartBuilder
+{
+ public LineChart3DBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
+ boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = ChartFactory.createLineChart3D(title,
+ xAxisTitle,
+ yAxisTitle,
+ (CategoryDataset)dataset,
+ plotOrientation,
+ showLegend,
+ showToolTips,
+ showUrls);
+ return chart;
+ }
+
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
index 697dfdcf3e..40f3a09b6b 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java
@@ -19,22 +19,30 @@
*/
package org.apache.qpid.disttest.charting.chartbuilder;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.category.CategoryDataset;
+import org.jfree.data.general.Dataset;
-public class LineChartBuilder extends DataSetBasedChartBuilder
+public class LineChartBuilder extends CategoryDataSetBasedChartBuilder
{
+
+ public LineChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
@Override
public JFreeChart createChartImpl(String title, String xAxisTitle,
- String yAxisTitle, final DefaultCategoryDataset dataset, PlotOrientation plotOrientation,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
boolean showLegend, boolean showToolTips, boolean showUrls)
{
JFreeChart chart = ChartFactory.createLineChart(title,
xAxisTitle,
yAxisTitle,
- dataset,
+ (CategoryDataset)dataset,
plotOrientation,
showLegend,
showToolTips,
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java
new file mode 100644
index 0000000000..6814272b8e
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.jfree.chart.JFreeChart;
+import org.jfree.data.xy.DefaultXYDataset;
+
+
+public abstract class XYDataSetBasedChartBuilder extends BaseChartBuilder
+{
+ private final SeriesBuilder _seriesBuilder;
+
+ public XYDataSetBasedChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ this._seriesBuilder = seriesBuilder;
+ }
+
+ @Override
+ public JFreeChart buildChart(ChartingDefinition chartingDefinition)
+ {
+ String title = chartingDefinition.getChartTitle();
+ String xAxisTitle = chartingDefinition.getXAxisTitle();
+ String yAxisTitle = chartingDefinition.getYAxisTitle();
+
+ final DefaultXYDataset dataset = new DefaultXYDataset();
+ _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback()
+ {
+ private List<Double[]> _xyPairs = null;
+
+ @Override
+ public void beginSeries(SeriesDefinition seriesDefinition)
+ {
+ _xyPairs = new ArrayList<Double[]>();
+ }
+
+ @Override
+ public void addDataPointToSeries(SeriesDefinition seriesDefinition,
+ Object xValue, Object yValue)
+ {
+ double x = Double.parseDouble(xValue.toString());
+ double y = Double.parseDouble(yValue.toString());
+ _xyPairs.add(new Double[] {x, y});
+ }
+
+
+ @Override
+ public void endSeries(SeriesDefinition seriesDefinition)
+ {
+ double[][] seriesData = listToSeriesDataArray();
+ dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData);
+ }
+
+ private double[][] listToSeriesDataArray()
+ {
+ double[][] seriesData = new double[2][_xyPairs.size()];
+ int i = 0;
+ for (Iterator<Double[]> iterator = _xyPairs.iterator(); iterator.hasNext();)
+ {
+ Double[] xyPair = iterator.next();
+ seriesData[0][i] = xyPair[0];
+ seriesData[1][i] = xyPair[1];
+ i++;
+ }
+ return seriesData;
+ }
+ });
+
+ _seriesBuilder.build(chartingDefinition.getSeries());
+
+ JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle,
+ dataset, PLOT_ORIENTATION, SHOW_LEGEND, SHOW_TOOL_TIPS, SHOW_URLS);
+
+ addCommonChartAttributes(chart, chartingDefinition);
+
+ return chart;
+ }
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYLineChartBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYLineChartBuilder.java
new file mode 100644
index 0000000000..48b02a7c60
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYLineChartBuilder.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.general.Dataset;
+import org.jfree.data.xy.XYDataset;
+
+public class XYLineChartBuilder extends XYDataSetBasedChartBuilder
+{
+ public XYLineChartBuilder(SeriesBuilder seriesBuilder)
+ {
+ super(seriesBuilder);
+ }
+
+ @Override
+ public JFreeChart createChartImpl(String title, String xAxisTitle,
+ String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation,
+ boolean showLegend, boolean showToolTips, boolean showUrls)
+ {
+ JFreeChart chart = ChartFactory.createXYLineChart(title,
+ xAxisTitle,
+ yAxisTitle,
+ (XYDataset)dataset,
+ plotOrientation,
+ showLegend,
+ showToolTips,
+ showUrls);
+ return chart;
+ }
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
index 82b59b6d6e..04b3f7ed3b 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java
@@ -29,6 +29,7 @@ public class ChartingDefinition
private final String _chartStemName;
private final ChartType _chartType;
private final String _chartTitle;
+ private final String _chartSubtitle;
private final String _xaxisTitle;
private final String _yaxisTitle;
private final List<SeriesDefinition> _seriesDefinitions;
@@ -37,12 +38,13 @@ public class ChartingDefinition
public ChartingDefinition(final String chartStemName,
final ChartType chartType,
final String chartTitle,
- final String xaxisTitle,
- final String yaxisTitle, List<SeriesDefinition> seriesDefinitions)
+ final String chartSubtitle,
+ final String xaxisTitle, final String yaxisTitle, List<SeriesDefinition> seriesDefinitions)
{
_chartStemName = chartStemName;
_chartType = chartType;
_chartTitle = chartTitle;
+ _chartSubtitle = chartSubtitle;
_xaxisTitle = xaxisTitle;
_yaxisTitle = yaxisTitle;
_seriesDefinitions = seriesDefinitions;
@@ -58,6 +60,11 @@ public class ChartingDefinition
return _chartTitle;
}
+ public String getChartSubtitle()
+ {
+ return _chartSubtitle;
+ }
+
public String getXAxisTitle()
{
@@ -82,4 +89,5 @@ public class ChartingDefinition
return Collections.unmodifiableList(_seriesDefinitions);
}
+
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
index 8a3d313519..4cbc9318a9 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java
@@ -38,6 +38,7 @@ public class ChartingDefinitionCreator
public static final String CHART_TYPE_KEY = "chartType";
public static final String CHART_TITLE_KEY = "chartTitle";
+ public static final String CHART_SUBTITLE_KEY = "chartSubtitle";
public static final String XAXIS_TITLE_KEY = "xAxisTitle";
public static final String YAXIS_TITLE_KEY = "yAxisTitle";
@@ -80,6 +81,7 @@ public class ChartingDefinitionCreator
final ChartType chartType = ChartType.valueOf(props.getProperty(CHART_TYPE_KEY));
final String chartTitle = props.getProperty(CHART_TITLE_KEY);
+ final String chartSubtitle = props.getProperty(CHART_SUBTITLE_KEY);
final String xAxisTitle = props.getProperty(XAXIS_TITLE_KEY);
final String yAxisTitle = props.getProperty(YAXIS_TITLE_KEY);
@@ -88,9 +90,9 @@ public class ChartingDefinitionCreator
final ChartingDefinition chartDefinition = new ChartingDefinition(chartStemName,
chartType,
chartTitle,
+ chartSubtitle,
xAxisTitle,
- yAxisTitle,
- seriesDefinitions);
+ yAxisTitle, seriesDefinitions);
return chartDefinition;
}
catch (IOException e)
@@ -134,7 +136,4 @@ public class ChartingDefinitionCreator
return pathname.isFile() && pathname.getName().endsWith(CHARTDEF_FILE_EXTENSION);
}
}
-
-
-
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java
index de717792db..8b4c2ab382 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.qpid.disttest.charting.chartbuilder;
+package org.apache.qpid.disttest.charting.seriesbuilder;
import java.io.File;
import java.sql.Connection;
@@ -31,20 +31,23 @@ import java.util.List;
import org.apache.qpid.disttest.charting.ChartingException;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-public class SeriesBuilder
+public class JdbcCsvSeriesBuilder implements SeriesBuilder
{
+
static
{
registerCsvDriver();
}
- private final DataPointCallback _dataPointCallback;
+ private SeriesBuilderCallback _callback;
- public SeriesBuilder(DataPointCallback dataPointCallback)
+ @Override
+ public void setSeriesBuilderCallback(SeriesBuilderCallback callback)
{
- _dataPointCallback = dataPointCallback;
+ this._callback = callback;
}
+ @Override
public void build(List<SeriesDefinition> seriesDefinitions)
{
for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator.hasNext();)
@@ -69,13 +72,15 @@ public class SeriesBuilder
stmt = conn.createStatement();
ResultSet results = stmt.executeQuery(seriesStatement);
+ _callback.beginSeries(seriesDefinition);
while (results.next())
{
- Object xValue = results.getString(1);
- Object yValue = results.getDouble(2);
+ Object xValue = results.getObject(1);
+ Object yValue = results.getObject(2);
- _dataPointCallback.addDataPointToSeries(seriesDefinition, xValue, yValue);
+ _callback.addDataPointToSeries(seriesDefinition, xValue, yValue);
}
+ _callback.endSeries(seriesDefinition);
}
catch (SQLException e)
{
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java
new file mode 100644
index 0000000000..86e471efaf
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.seriesbuilder;
+
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+
+public interface SeriesBuilder
+{
+ void build(List<SeriesDefinition> seriesDefinitions);
+
+ void setSeriesBuilderCallback(SeriesBuilderCallback seriesBuilderCallback);
+
+} \ No newline at end of file
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java
index a47df0e8af..22c99deca0 100644
--- a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java
@@ -17,11 +17,14 @@
* under the License.
*
*/
-package org.apache.qpid.disttest.charting.chartbuilder;
+package org.apache.qpid.disttest.charting.seriesbuilder;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
-public interface DataPointCallback
+public interface SeriesBuilderCallback
{
+ public void beginSeries(SeriesDefinition seriesDefinition);
public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object xValue, Object yValue);
+ public void endSeries(SeriesDefinition seriesDefinition);
+
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java
new file mode 100644
index 0000000000..14aa5f3a37
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.writer;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.qpid.disttest.charting.ChartingException;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ChartWriter
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(ChartWriter.class);
+ private File _chartDirectory = new File(".");
+
+ public void writeChartToFileSystem(JFreeChart chart, String chartStemName)
+ {
+ OutputStream pngOutputStream = null;
+ try
+ {
+
+ File pngFile = new File(_chartDirectory, chartStemName + ".png");
+ pngOutputStream = new BufferedOutputStream(new FileOutputStream(pngFile));
+ ChartUtilities.writeChartAsPNG(pngOutputStream, chart, 600, 400, true, 0);
+ pngOutputStream.close();
+
+ LOGGER.info("Written {} chart", pngFile);
+ }
+ catch (IOException e)
+ {
+ throw new ChartingException("Failed to create chart", e);
+ }
+ finally
+ {
+ if (pngOutputStream != null)
+ {
+ try
+ {
+ pngOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ throw new ChartingException("Failed to create chart", e);
+ }
+ }
+ }
+ }
+
+ public void setOutputDirectory(final File chartDirectory)
+ {
+ _chartDirectory = chartDirectory;
+ }
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
index bdbbc4a585..e735fb58c6 100644
--- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java
@@ -19,22 +19,44 @@
*/
package org.apache.qpid.disttest.charting.chartbuilder;
+import static org.mockito.Mockito.*;
+
import org.apache.qpid.disttest.charting.ChartType;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
import junit.framework.TestCase;
public class ChartBuilderFactoryTest extends TestCase
{
+ private SeriesBuilder _seriesBuilder = mock(SeriesBuilder.class);
+
public void testLineChart()
{
- ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE);
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE, _seriesBuilder);
assertTrue(builder instanceof LineChartBuilder);
}
+ public void testLineChart3D()
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE3D, _seriesBuilder);
+ assertTrue(builder instanceof LineChart3DBuilder);
+ }
+
public void testBarChart()
{
- ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR);
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR, _seriesBuilder);
assertTrue(builder instanceof BarChartBuilder);
}
+ public void testBarChart3D()
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR3D, _seriesBuilder);
+ assertTrue(builder instanceof BarChart3DBuilder);
+ }
+
+ public void testXYLineChart()
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.XYLINE, _seriesBuilder);
+ assertTrue(builder instanceof XYLineChartBuilder);
+ }
}
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java
new file mode 100644
index 0000000000..2e97772f37
--- /dev/null
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.disttest.charting.chartbuilder;
+
+import static org.mockito.Mockito.*;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.qpid.disttest.charting.ChartType;
+import org.apache.qpid.disttest.charting.definition.ChartingDefinition;
+import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback;
+import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder;
+import org.apache.qpid.disttest.charting.writer.ChartWriter;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.title.ShortTextTitle;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the production of the different chart types. To manually
+ * verify the generated output, set the system property {@link #RETAIN_TEST_CHARTS}
+ * to prevent the automatic deletion of the test chart directory.
+ *
+ */
+public class ChartProductionTest extends TestCase
+{
+ private static final String TEST_CHARTTITLE = "TEST_CHARTTITLE";
+ private static final String TEST_CHARTSUBTITLE = "TEST_CHARTSUBTITLE";
+ private static final String TEST_XAXIS = "TEST_XAXIS";
+ private static final String TEST_YAXIS = "TEST_YAXIS";
+
+ private static final String TEST_SERIESLEGEND = "TEST_SERIESLEGEND";
+
+ private static final String SYSTEM_TMP_DIR = System.getProperty("java.io.tmpdir");
+ private static final String CHART_DIRECTORY = "charts." + System.currentTimeMillis();
+ private static final String RETAIN_TEST_CHARTS = "retainTestCharts";
+
+ private SeriesDefinition _seriesDefinition = mock(SeriesDefinition.class);
+ private ChartingDefinition _chartingDefinition = mock(ChartingDefinition.class);
+ private ChartWriter _writer = new ChartWriter();
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ when(_seriesDefinition.getSeriesLegend()).thenReturn(TEST_SERIESLEGEND);
+
+ when(_chartingDefinition.getChartTitle()).thenReturn(TEST_CHARTTITLE);
+ when(_chartingDefinition.getChartSubtitle()).thenReturn(TEST_CHARTSUBTITLE);
+ when(_chartingDefinition.getXAxisTitle()).thenReturn(TEST_XAXIS);
+ when(_chartingDefinition.getYAxisTitle()).thenReturn(TEST_YAXIS);
+ when(_chartingDefinition.getSeries()).thenReturn(Collections.singletonList(_seriesDefinition));
+
+ File chartDir = new File(SYSTEM_TMP_DIR, CHART_DIRECTORY);
+ chartDir.mkdirs();
+ if (!System.getProperties().containsKey(RETAIN_TEST_CHARTS))
+ {
+ chartDir.deleteOnExit();
+ }
+ else
+ {
+ System.out.println("Charting directory for manual observation " + chartDir);
+ }
+
+ _writer.setOutputDirectory(chartDir);
+ }
+
+ public void testBarChart() throws Exception
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR, new SampleSeriesBuilder());
+ assertChartTitlesAndWriteToFile(builder);
+ }
+
+ public void testBar3DChart() throws Exception
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR3D, new SampleSeriesBuilder());
+ assertChartTitlesAndWriteToFile(builder);
+ }
+
+ public void testLineChart() throws Exception
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE, new SampleSeriesBuilder());
+ assertChartTitlesAndWriteToFile(builder);
+ }
+
+ public void testLine3DChart() throws Exception
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE3D, new SampleSeriesBuilder());
+ assertChartTitlesAndWriteToFile(builder);
+ }
+ public void testXYLineChart() throws Exception
+ {
+ ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.XYLINE, new SampleSeriesBuilder());
+ assertChartTitlesAndWriteToFile(builder);
+ }
+
+ private void assertChartTitlesAndWriteToFile(ChartBuilder builder)
+ {
+ JFreeChart chart = builder.buildChart(_chartingDefinition);
+ assertEquals(TEST_CHARTTITLE, chart.getTitle().getText());
+ assertEquals(TEST_CHARTSUBTITLE, ((ShortTextTitle)chart.getSubtitle(1)).getText());
+ assertEquals(TEST_SERIESLEGEND, chart.getPlot().getLegendItems().get(0).getLabel());
+
+ if (chart.getPlot() instanceof XYPlot)
+ {
+ assertEquals(1, chart.getXYPlot().getDatasetCount());
+ }
+ else
+ {
+ assertEquals(1, chart.getCategoryPlot().getDatasetCount());
+ }
+
+ _writer.writeChartToFileSystem(chart, getName());
+ }
+
+ private class SampleSeriesBuilder implements SeriesBuilder
+ {
+ private SeriesBuilderCallback _dataPointCallback;
+
+ @Override
+ public void build(List<SeriesDefinition> seriesDefinitions)
+ {
+ for (Iterator<SeriesDefinition> iterator = seriesDefinitions.iterator(); iterator
+ .hasNext();)
+ {
+ SeriesDefinition seriesDefinition = iterator.next();
+ _dataPointCallback.beginSeries(seriesDefinition);
+ _dataPointCallback.addDataPointToSeries(seriesDefinition, Double.valueOf(1), Double.valueOf(1));
+ _dataPointCallback.addDataPointToSeries(seriesDefinition, Double.valueOf(2), Double.valueOf(2));
+ _dataPointCallback.addDataPointToSeries(seriesDefinition, Double.valueOf(4), Double.valueOf(4));
+ _dataPointCallback.addDataPointToSeries(seriesDefinition, Double.valueOf(5), Double.valueOf(5));
+ _dataPointCallback.addDataPointToSeries(seriesDefinition, Double.valueOf(6), Double.valueOf(3));
+ _dataPointCallback.endSeries(seriesDefinition);
+ }
+ }
+
+ @Override
+ public void setSeriesBuilderCallback(SeriesBuilderCallback dataPointCallback)
+ {
+ _dataPointCallback = dataPointCallback;
+ }
+ }
+}
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
index 80d1cc3d21..5371f3df45 100644
--- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java
@@ -20,6 +20,7 @@
package org.apache.qpid.disttest.charting.definition;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TITLE_KEY;
+import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_SUBTITLE_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TYPE_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.XAXIS_TITLE_KEY;
import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.YAXIS_TITLE_KEY;
@@ -38,6 +39,7 @@ import org.apache.qpid.disttest.charting.ChartingException;
public class ChartingDefinitionCreatorTest extends TestCase
{
private static final String TEST_CHART_TITLE = "CHART_TITLE";
+ private static final String TEST_CHART_SUBTITLE = "CHART_SUBTITLE";
private static final String TEST_XAXIS_TITLE = "XAXIS_TITLE";
private static final String TEST_YAXIS_TITLE = "YAXIS_TITLE";
private static final ChartType TEST_CHART_TYPE = ChartType.LINE;
@@ -83,6 +85,7 @@ public class ChartingDefinitionCreatorTest extends TestCase
ChartingDefinition definition1 = definitions.get(0);
assertEquals(TEST_CHART_TITLE, definition1.getChartTitle());
+ assertEquals(TEST_CHART_SUBTITLE, definition1.getChartSubtitle());
assertEquals(TEST_XAXIS_TITLE, definition1.getXAxisTitle());
assertEquals(TEST_YAXIS_TITLE, definition1.getYAxisTitle());
assertEquals(TEST_CHART_TYPE, definition1.getChartType());
@@ -121,6 +124,7 @@ public class ChartingDefinitionCreatorTest extends TestCase
Properties props = new Properties();
props.setProperty(CHART_TYPE_KEY, TEST_CHART_TYPE.name());
props.setProperty(CHART_TITLE_KEY, TEST_CHART_TITLE);
+ props.setProperty(CHART_SUBTITLE_KEY, TEST_CHART_SUBTITLE);
props.setProperty(XAXIS_TITLE_KEY, TEST_XAXIS_TITLE);
props.setProperty(YAXIS_TITLE_KEY, TEST_YAXIS_TITLE);
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java
index 1b1c9969b3..ae241b453d 100644
--- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java
+++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilderTest.java
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.qpid.disttest.charting.chartbuilder;
+package org.apache.qpid.disttest.charting.seriesbuilder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -31,14 +31,15 @@ import java.util.Collections;
import junit.framework.TestCase;
import org.apache.qpid.disttest.charting.definition.SeriesDefinition;
+import org.apache.qpid.disttest.charting.seriesbuilder.JdbcCsvSeriesBuilder;
-public class SeriesBuilderTest extends TestCase
+public class JdbcCsvSeriesBuilderTest extends TestCase
{
private static final String TEST_SERIES_1_SELECT_STATEMENT = "SELECT A, B FROM test";
private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND";
- private DataPointCallback _dataPointCallback = mock(DataPointCallback.class);
- private SeriesBuilder _seriesBuilder = new SeriesBuilder(_dataPointCallback);
+ private SeriesBuilderCallback _seriesWalkerCallback = mock(SeriesBuilderCallback.class);
+ private JdbcCsvSeriesBuilder _seriesBuilder = new JdbcCsvSeriesBuilder();
private File _testTempDir;
@@ -46,6 +47,7 @@ public class SeriesBuilderTest extends TestCase
protected void setUp() throws Exception
{
super.setUp();
+ _seriesBuilder.setSeriesBuilderCallback(_seriesWalkerCallback);
_testTempDir = createTestTemporaryDirectory();
}
@@ -56,9 +58,11 @@ public class SeriesBuilderTest extends TestCase
_seriesBuilder.build(Collections.singletonList(seriesDefinition));
- verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"elephant", (Object)2.0);
- verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"lion", (Object)3.0);
- verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"tiger", (Object)4.0);
+ verify(_seriesWalkerCallback).beginSeries(seriesDefinition);
+ verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, (Object)"elephant", (Object)"2");
+ verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, (Object)"lion", (Object)"3");
+ verify(_seriesWalkerCallback).addDataPointToSeries(seriesDefinition, (Object)"tiger", (Object)"4");
+ verify(_seriesWalkerCallback).endSeries(seriesDefinition);
}
private void createTestCsvIn(File testDir) throws Exception