diff options
| author | Kim van der Riet <kpvdr@apache.org> | 2012-08-03 12:13:32 +0000 |
|---|---|---|
| committer | Kim van der Riet <kpvdr@apache.org> | 2012-08-03 12:13:32 +0000 |
| commit | d43d1912b376322e27fdcda551a73f9ff5487972 (patch) | |
| tree | ce493e10baa95f44be8beb5778ce51783463196d /java/perftests/visualisation-jfc/src/main | |
| parent | 04877fec0c6346edec67072d7f2d247740cf2af5 (diff) | |
| download | qpid-python-d43d1912b376322e27fdcda551a73f9ff5487972.tar.gz | |
QPID-3858: Updated branch - merged from trunk r.1368650
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/asyncstore@1368910 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/perftests/visualisation-jfc/src/main')
19 files changed, 739 insertions, 93 deletions
diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java index 2803f2d767..ed09f4a77e 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartType.java +++ b/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, STATISTICAL_BAR } diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java index a149d1a097..e00859855e 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/ChartingUtil.java +++ b/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,56 +76,32 @@ 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()); + writer.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.writeHtmlSummaryToFileSystem(); } private List<ChartingDefinition> loadChartDefinitions(String chartingDefsDir) @@ -130,6 +115,4 @@ public class ChartingUtil ArgumentParser argumentParser = new ArgumentParser(); argumentParser.parseArgumentsIntoConfig(_cliOptions, args); } - - } diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChart3DBuilder.java b/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/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java index 302263a604..b5c6a38067 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BarChartBuilder.java +++ b/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/BaseChartBuilder.java b/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/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java index 6e2491c883..a6c63f4560 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataSetBasedChartBuilder.java +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/CategoryDataSetBasedChartBuilder.java @@ -19,17 +19,23 @@ */ 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 +46,39 @@ 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) + public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object[] row) { - String x = (String) xValue; - double y = (Double) yValue; + String x = String.valueOf(row[0]); + double y = Double.parseDouble(row[1].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(CategoryLabelPositions.UP_45); - 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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java index c6f5ecc175..425b83596f 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilder.java +++ b/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java index 4c5d4fa09f..f4e11a2c4d 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactory.java @@ -20,18 +20,27 @@ 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); + case STATISTICAL_BAR: + return new StatisticalBarCharBuilder(seriesBuilder); default: throw new IllegalArgumentException("Unknown chart type " + chartType); } diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChart3DBuilder.java b/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/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java index 697dfdcf3e..40f3a09b6b 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/LineChartBuilder.java +++ b/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java new file mode 100644 index 0000000000..86c3f62e09 --- /dev/null +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/StatisticalBarCharBuilder.java @@ -0,0 +1,111 @@ +/* + * + * 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.Font; + +import org.apache.qpid.disttest.charting.definition.ChartingDefinition; +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; +import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalBarRenderer; +import org.jfree.data.general.Dataset; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; +import org.jfree.data.statistics.StatisticalCategoryDataset; + +public class StatisticalBarCharBuilder extends BaseChartBuilder +{ + private final SeriesBuilder _seriesBuilder; + + public StatisticalBarCharBuilder(SeriesBuilder seriesBuilder) + { + _seriesBuilder = seriesBuilder; + } + + @Override + public JFreeChart buildChart(ChartingDefinition chartingDefinition) + { + String title = chartingDefinition.getChartTitle(); + String xAxisTitle = chartingDefinition.getXAxisTitle(); + String yAxisTitle = chartingDefinition.getYAxisTitle(); + + final DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); + + _seriesBuilder.setSeriesBuilderCallback(new SeriesBuilderCallback() + { + @Override + public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object[] row) + { + String x = String.valueOf(row[0]); + double mean = Double.parseDouble(row[1].toString()); + double stdDev = Double.parseDouble(row[2].toString()); + dataset.add(mean, stdDev, seriesDefinition.getSeriesLegend(), x); + } + + @Override + public void beginSeries(SeriesDefinition seriesDefinition) + { + // unused + } + + @Override + public void endSeries(SeriesDefinition seriesDefinition) + { + // unused + } + + }); + + _seriesBuilder.build(chartingDefinition.getSeries()); + + JFreeChart chart = createChartImpl(title, xAxisTitle, yAxisTitle, dataset, PLOT_ORIENTATION, SHOW_LEGEND, + SHOW_TOOL_TIPS, SHOW_URLS); + + chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); + + addCommonChartAttributes(chart, chartingDefinition); + + return chart; + } + + @Override + public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, + PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) + { + CategoryAxis xAxis = new CategoryAxis(xAxisTitle); + ValueAxis yAxis = new NumberAxis(yAxisTitle); + CategoryItemRenderer renderer = new StatisticalBarRenderer(); + + CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer); + + JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true); + return chart; + } + +} diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java new file mode 100644 index 0000000000..87d61ca2ee --- /dev/null +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYDataSetBasedChartBuilder.java @@ -0,0 +1,103 @@ +/* + * 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.chart.axis.CategoryLabelPositions; +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[] row) + { + double x = Double.parseDouble(row[0].toString()); + double y = Double.parseDouble(row[1].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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/XYLineChartBuilder.java b/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/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java index 82b59b6d6e..04b3f7ed3b 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinition.java +++ b/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java index 8a3d313519..4cbc9318a9 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreator.java +++ b/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/JdbcCsvSeriesBuilder.java index de717792db..a9adce0afc 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilder.java +++ b/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();) @@ -68,14 +71,19 @@ public class SeriesBuilder stmt = conn.createStatement(); ResultSet results = stmt.executeQuery(seriesStatement); - + int columnCount = results.getMetaData().getColumnCount(); + _callback.beginSeries(seriesDefinition); while (results.next()) { - Object xValue = results.getString(1); - Object yValue = results.getDouble(2); + Object[] row = new Object[columnCount]; + for (int i = 0; i < row.length; i++) + { + row[i] = results.getObject(i+1); + } - _dataPointCallback.addDataPointToSeries(seriesDefinition, xValue, yValue); + _callback.addDataPointToSeries(seriesDefinition, row); } + _callback.endSeries(seriesDefinition); } catch (SQLException e) { diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilder.java b/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/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/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/seriesbuilder/SeriesBuilderCallback.java index a47df0e8af..7e23953fdb 100644 --- a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/chartbuilder/DataPointCallback.java +++ b/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 addDataPointToSeries(SeriesDefinition seriesDefinition, Object xValue, Object yValue); + public void beginSeries(SeriesDefinition seriesDefinition); + public void addDataPointToSeries(SeriesDefinition seriesDefinition, Object[] row); + public void endSeries(SeriesDefinition seriesDefinition); + } diff --git a/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java new file mode 100644 index 0000000000..08bdf122ba --- /dev/null +++ b/java/perftests/visualisation-jfc/src/main/java/org/apache/qpid/disttest/charting/writer/ChartWriter.java @@ -0,0 +1,139 @@ +/* + * 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.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.util.SortedSet; +import java.util.TreeSet; + +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); + + static final String SUMMARY_FILE_NAME = "chart-summary.html"; + + private File _chartDirectory = new File("."); + private SortedSet<File> _chartFiles = new TreeSet<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(); + + _chartFiles.add(pngFile); + + 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 writeHtmlSummaryToFileSystem() + { + if(_chartFiles.size() < 2) + { + LOGGER.info("Only " + _chartFiles.size() + " chart image(s) have been written so no HTML summary file will be produced"); + return; + } + + String htmlHeader = + "<html>\n" + + " <head>\n" + + " <title>Performance Charts</title>\n" + + " </head>\n" + + " <body>\n"; + + String htmlFooter = + " </body>\n" + + "</html>"; + + BufferedWriter writer = null; + try + { + File summaryFile = new File(_chartDirectory, SUMMARY_FILE_NAME); + LOGGER.debug("About to produce HTML summary file " + summaryFile.getAbsolutePath() + " from charts " + _chartFiles); + + writer = new BufferedWriter(new FileWriter(summaryFile)); + writer.write(htmlHeader); + for (File chartFile : _chartFiles) + { + writer.write(" <img src='" + chartFile.getName() + "'/>\n"); + } + writer.write(htmlFooter); + writer.close(); + } + catch (Exception e) + { + throw new ChartingException("Failed to create HTML summary file", e); + } + finally + { + if(writer != null) + { + try + { + writer.close(); + } + catch(IOException e) + { + throw new ChartingException("Failed to create HTML summary file", e); + } + } + } + } + + public void setOutputDirectory(final File chartDirectory) + { + _chartDirectory = chartDirectory; + } +} |
