diff options
| author | Keith Wall <kwall@apache.org> | 2012-06-15 13:57:25 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2012-06-15 13:57:25 +0000 |
| commit | 178f342319aee9f6f85545aa48e4a442b060d6b6 (patch) | |
| tree | d15ebdab0a76959a77da6b85d0b104ca4b99438e /qpid/java/perftests/visualisation-jfc/src/main | |
| parent | b1a8ce50c064c05db8ffe0eb7d98cf667bc3d109 (diff) | |
| download | qpid-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/visualisation-jfc/src/main')
18 files changed, 551 insertions, 91 deletions
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; + } +} |
