Changeset 566
- Timestamp:
- 03/13/11 23:01:49 (2 years ago)
- Location:
- raptor-web/trunk/src/main
- Files:
-
- 7 edited
-
java/uk/ac/cardiff/raptorweb/engine/ChartProcessor.java (modified) (18 diffs)
-
java/uk/ac/cardiff/raptorweb/model/ChartOptions.java (modified) (6 diffs)
-
java/uk/ac/cardiff/raptorweb/model/GraphModel.java (modified) (3 diffs)
-
java/uk/ac/cardiff/raptorweb/service/impl/GraphServiceImpl.java (modified) (1 diff)
-
webapp/WEB-INF/config/web-setup.xml (modified) (2 diffs)
-
webapp/WEB-INF/flows/reports/graphicalReports.xhtml (modified) (2 diffs)
-
webapp/WEB-INF/flows/reports/startReport.xhtml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/engine/ChartProcessor.java
r561 r566 33 33 import org.jfree.chart.renderer.category.BarRenderer; 34 34 import org.jfree.data.category.DefaultCategoryDataset; 35 import org.jfree.data.general.DefaultPieDataset; 35 36 import org.jfree.ui.RectangleEdge; 36 37 import org.jfree.ui.RectangleInsets; … … 54 55 /** 55 56 * @author philsmart 56 * 57 * 57 58 * Takes a chart from the MUA, and wraps it inside the current graph view technologies (trinidad, JFreeChart) graph model 58 59 */ … … 64 65 private Resource baseDirectory; 65 66 66 /* allows chart name flip flop, to stop the browser from rendering an image from cache */67 /* allows chart name flip flop, to stop the browser from rendering an image from cache */ 67 68 boolean flipFlopChartName; 68 69 70 69 71 70 public String getRootDirectory(String user) { … … 110 109 } 111 110 112 113 114 public RaptorJFreeChartModel constructJFreeGraph(AggregatorGraphModel gmodel, String user, ChartOptions chartOptions){ 115 return doConstructJFreeGraphBar(gmodel, chartOptions,user,null); 116 } 117 111 public RaptorJFreeChartModel constructJFreeGraph(AggregatorGraphModel gmodel, String user, ChartOptions chartOptions) { 112 return doConstructJFreeGraphCategory(gmodel, chartOptions, user, null); 113 } 114 118 115 /** 119 116 * Will output into the root graphs directory … … 123 120 * @return 124 121 */ 125 public RaptorJFreeChartModel constructJFreeGraph(AggregatorGraphModel gmodel, ChartOptions chartOptions){ 126 return doConstructJFreeGraphBar(gmodel, chartOptions,"",null); 127 } 128 129 122 public RaptorJFreeChartModel constructJFreeGraph(AggregatorGraphModel gmodel, ChartOptions chartOptions) { 123 return doConstructJFreeGraphCategory(gmodel, chartOptions, "", null); 124 } 130 125 131 126 public RaptorJFreeChartModel constructJFreeGraph(GraphPresentation graphPresentation, ChartType graphType, AggregatorGraphModel gmodel, int width, int height, String filename) { … … 135 130 chartOptions.setGraphPresentation(graphPresentation); 136 131 chartOptions.setGraphType(graphType); 137 return doConstructJFreeGraphBar( gmodel, chartOptions,"",filename); 132 chartOptions.setOrientation(ChartOptions.OrientationType.VERTICAL); 133 return doConstructJFreeGraphCategory(gmodel, chartOptions, "", filename); 134 } 135 136 private RaptorJFreeChartModel doConstructJFreeGraphPie(AggregatorGraphModel gmodel, ChartOptions chartOptions, String user, String filename) { 137 log.info("Creating graph {} with presentation {} (legend {}), width={} height={}", new Object[] { chartOptions.getGraphType(), chartOptions.getGraphPresentation(), chartOptions.getGraphPresentation().getLegend(), 138 chartOptions.getImageWidth(), chartOptions.getImageHeight() }); 139 140 final DefaultPieDataset dataset = new DefaultPieDataset(); 141 142 for (int j = 0; j < gmodel.getSeriesLabels().size(); j++) { 143 for (int i = 0; i < gmodel.getGroupLabels().size(); i++) { 144 dataset.setValue(gmodel.getGroupLabels().get(i),gmodel.getYValues().get(j).get(i)); 145 } 146 } 147 148 final JFreeChart chart = ChartFactory.createPieChart3D( "Pie Chart 3D Demo 1", dataset, true, true, false); 149 return doConstructChartPresentation(chart, chartOptions,user,filename); 138 150 } 139 151 140 152 /** 141 153 * Requires websession, as charts stored on file system specific to the current users home directory 142 * 154 * 143 155 * @param gmodel 144 156 * @param session 145 157 * @return 146 158 */ 147 private RaptorJFreeChartModel doConstructJFreeGraphBar(AggregatorGraphModel gmodel, ChartOptions chartOptions, String user, String filename) { 148 log.info("Creating graph {} with presentation {} (legend {}), width={} height={}", new Object[] { chartOptions.getGraphType(), chartOptions.getGraphPresentation(), chartOptions.getGraphPresentation().getLegend(), chartOptions.getImageWidth(), chartOptions.getImageHeight() }); 149 RaptorJFreeChartModel chartmodel = new RaptorJFreeChartModel(); 159 private RaptorJFreeChartModel doConstructJFreeGraphCategory(AggregatorGraphModel gmodel, ChartOptions chartOptions, String user, String filename) { 160 log.info("Creating graph {} with presentation {} (legend {}), width={} height={}", new Object[] { chartOptions.getGraphType(), chartOptions.getGraphPresentation(), chartOptions.getGraphPresentation().getLegend(), 161 chartOptions.getImageWidth(), chartOptions.getImageHeight() }); 162 150 163 151 164 // construct the graph … … 169 182 yAxisLabel = gmodel.getPresentation().getyAxisLabel(); 170 183 } 171 172 // initialise default, then change on condition184 185 // initialise default, then change on condition 173 186 PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; 174 if (chartOptions.getOrientation() ==ChartOptions.OrientationType.HORIZONTAL)187 if (chartOptions.getOrientation() == ChartOptions.OrientationType.HORIZONTAL) 175 188 plotOrientation = PlotOrientation.HORIZONTAL; 176 else if (chartOptions.getOrientation() ==ChartOptions.OrientationType.VERTICAL)189 else if (chartOptions.getOrientation() == ChartOptions.OrientationType.VERTICAL) 177 190 plotOrientation = PlotOrientation.VERTICAL; 178 191 179 192 log.debug("Graph Setup with Title {}, xAxisLabel {}, yAxisLabel {}", new Object[] { chartTitle, xAxisLabel, yAxisLabel }); 180 193 if (chartOptions.getGraphType() == ChartType.BAR3D) 181 194 chart = ChartFactory.createBarChart3D(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false); 182 195 else if (chartOptions.getGraphType() == ChartType.AREA) 183 chart = ChartFactory.createAreaChart(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false);196 chart = ChartFactory.createAreaChart(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false); 184 197 else if (chartOptions.getGraphType() == ChartType.LINE3D) 185 198 chart = ChartFactory.createLineChart3D(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false); … … 188 201 else if (chartOptions.getGraphType() == ChartType.LINE) 189 202 chart = ChartFactory.createLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false); 203 204 return doConstructChartPresentation(chart, chartOptions,user,filename); 205 206 } 207 208 private RaptorJFreeChartModel doConstructChartPresentation(JFreeChart chart, ChartOptions chartOptions, String filename, String user){ 209 RaptorJFreeChartModel chartmodel = new RaptorJFreeChartModel(); 190 210 191 211 // setup the graph output 192 212 if (chartOptions.getGraphPresentation() == GraphPresentation.FANCY) 193 fancyGraphOutput(chart );213 fancyGraphOutput(chart, chartOptions); 194 214 else if (chartOptions.getGraphPresentation() == GraphPresentation.FRONT) 195 frontGraphOutput(chart );215 frontGraphOutput(chart, chartOptions); 196 216 197 217 // save the graph 198 String endingFilename ="";199 if (filename !=null)200 endingFilename =filename;201 202 // must create a random number, if the image url does not change, the browser uses the cached image218 String endingFilename = ""; 219 if (filename != null) 220 endingFilename = filename; 221 222 // must create a random number, if the image url does not change, the browser uses the cached image 203 223 int ran = getRandomChartFileExtension(100); 204 224 205 File chartLocation = new File(getRootDirectory(user) + "/raptor-graphs-main" +endingFilename+".svg");206 File chartLocationPNG = new File(getRootDirectory(user) + "/raptor-graphs-main" +endingFilename+ran+".png");225 File chartLocation = new File(getRootDirectory(user) + "/raptor-graphs-main" + endingFilename + ".svg"); 226 File chartLocationPNG = new File(getRootDirectory(user) + "/raptor-graphs-main" + endingFilename + ran + ".png"); 207 227 208 228 // png is used for screen output … … 210 230 try { 211 231 int padding = 5; 212 log.debug("Writing PNG to {}", chartLocationPNG);232 log.debug("Writing PNG to {}", chartLocationPNG); 213 233 ImageIO.write(ChartProcessorHelper.buildChartDropShadow(chart.createBufferedImage(chartOptions.getImageWidth() - (padding * 2), chartOptions.getImageHeight() - (padding * 2)), padding), "png", new FileOutputStream(chartLocationPNG)); 214 234 } catch (IOException e) { … … 223 243 } 224 244 225 //try {226 //exportChartAsSVG(chart, new Rectangle(800, 600), chartLocation);227 //} catch (IOException e) {228 //log.error("Could not save SVG File {}", e.getMessage());229 //}245 // try { 246 // exportChartAsSVG(chart, new Rectangle(800, 600), chartLocation); 247 // } catch (IOException e) { 248 // log.error("Could not save SVG File {}", e.getMessage()); 249 // } 230 250 231 251 chartmodel.setChartLocation(chartLocationPNG); … … 234 254 } 235 255 236 private int getRandomFlipFlopChartFileExtension() {237 if (flipFlopChartName) {238 flipFlopChartName =false;256 private int getRandomFlipFlopChartFileExtension() { 257 if (flipFlopChartName) { 258 flipFlopChartName = false; 239 259 return 0; 240 } 241 else { 242 flipFlopChartName=true; 260 } else { 261 flipFlopChartName = true; 243 262 return 1; 244 263 } 245 264 } 246 265 247 private int getRandomChartFileExtension(int upperLimit) {248 int ran = ((int) (Math.random()*upperLimit));266 private int getRandomChartFileExtension(int upperLimit) { 267 int ran = ((int) (Math.random() * upperLimit)); 249 268 return ran; 250 269 } 251 270 252 private void fancyGraphOutput(JFreeChart chart ) {271 private void fancyGraphOutput(JFreeChart chart, ChartOptions chartOptions) { 253 272 CategoryPlot plot = (CategoryPlot) chart.getPlot(); 254 273 CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); 255 xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_90);274 xAxis.setCategoryLabelPositions(chartOptions.getxLabelPosition().getLabelPosition()); 256 275 chart.setBackgroundPaint(new Color(255, 255, 255, 0)); 257 276 chart.setPadding(new RectangleInsets(10, 5, 5, 5)); … … 271 290 domainAxis.setUpperMargin(0.0); 272 291 domainAxis.setLowerMargin(0.0); 273 domainAxis.setLabelFont(new Font("SansSerif",Font.PLAIN,10)); 274 domainAxis.setTickLabelFont(new Font("SansSerif",Font.PLAIN,10)); 275 276 } 277 278 private void frontGraphOutput(JFreeChart chart) { 292 domainAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); 293 domainAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 10)); 294 295 } 296 297 /** 298 * Should only be used by graphs on the front page (dashboard) as it has certain uncostomisable options 299 * 300 * @param chart 301 * @param chartOptions 302 */ 303 private void frontGraphOutput(JFreeChart chart, ChartOptions chartOptions) { 279 304 CategoryPlot plot = (CategoryPlot) chart.getPlot(); 280 305 CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); … … 287 312 plot.setRangeGridlinePaint(Color.black); 288 313 plot.setDomainGridlinePaint(Color.black); 289 // set the thickness of the first series314 // set the thickness of the first series 290 315 plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); 291 316 plot.setForegroundAlpha(0.7f); 292 plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white , 1f, 1f, new Color(210,210,210)));317 plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1f, 1f, new Color(210, 210, 210))); 293 318 plot.getRenderer().setSeriesPaint(0, Color.blue); 294 319 // axis … … 296 321 domainAxis.setUpperMargin(0.0); 297 322 domainAxis.setLowerMargin(0.0); 298 domainAxis.setLabelFont(new Font("SansSerif", Font.PLAIN,7));299 domainAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN,7));323 domainAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 7)); 324 domainAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); 300 325 301 326 } … … 303 328 /** 304 329 * Exports a JFreeChart to a SVG file. 305 * 330 * 306 331 * @param chart 307 332 * JFreeChart to export … … 335 360 /** 336 361 * Exports a JFreeChart to a jpg file. 337 * 362 * 338 363 * @param chart 339 364 * JFreeChart to export … … 360 385 */ 361 386 public RaptorTableChartModel constructRaptorTableChartModel(AggregatorGraphModel gmodel) { 362 log.info("Constructing Raptor Table for {}", gmodel.getPresentation().getGraphTitle());387 log.info("Constructing Raptor Table for {}", gmodel.getPresentation().getGraphTitle()); 363 388 364 389 RaptorTableChartModel tableModel = new RaptorTableChartModel(); … … 378 403 tableModel.constructTableForView(); 379 404 380 // log.debug("Raptor Table model constructed, with {} rows",tableModel.getRowList().size());405 // log.debug("Raptor Table model constructed, with {} rows",tableModel.getRowList().size()); 381 406 382 407 return tableModel; -
raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/model/ChartOptions.java
r561 r566 10 10 import javax.faces.model.SelectItem; 11 11 12 import org.jfree.chart.axis.CategoryLabelPositions; 12 13 import org.slf4j.Logger; 13 14 import org.slf4j.LoggerFactory; … … 28 29 private int xMajorGridCount; 29 30 private int yMajorGridCount; 30 private ChartHeight chartHeight;31 31 private OrientationType orientation; 32 32 private int imageWidth; 33 private int imageHeight; 33 private int imageHeight; 34 34 35 private GraphPresentation graphPresentation; 35 36 36 private LabelPositionType xLabelPosition; 37 38 /* the orientation of labels, mapped to JFreeChart <code>CategoryLabelPositions</code> */ 39 public enum LabelPositionType{ 40 UP_45(CategoryLabelPositions.UP_45, "45 Degree Up"), UP_90(CategoryLabelPositions.UP_90, "90 Degree Up"), 41 DOWN_45(CategoryLabelPositions.DOWN_45, "45 Degree Down"),DOWN_90(CategoryLabelPositions.DOWN_90, "90 Degree Down"), 42 STANDARD(CategoryLabelPositions.STANDARD, "Standard"); 43 44 private CategoryLabelPositions labelPosition; 45 private String label; 46 47 LabelPositionType(CategoryLabelPositions labelPosition, String label){ 48 this.setLabelPosition(labelPosition); 49 } 50 51 public void setLabel(String label) { 52 this.label = label; 53 } 54 55 public String getLabel() { 56 return label; 57 } 58 59 public void setLabelPosition(CategoryLabelPositions labelPosition) { 60 this.labelPosition = labelPosition; 61 } 62 63 public CategoryLabelPositions getLabelPosition() { 64 return labelPosition; 65 } 66 67 } 68 37 69 /* options for how the graph is displayed */ 38 70 public enum GraphPresentation { … … 48 80 } 49 81 } 50 51 public enum ChartHeight {52 SMALL(700), MEDIUM(1100), LARGE(1700);53 private int heightInPx;54 55 ChartHeight(int heightInPx) {56 this.heightInPx = heightInPx;57 }58 59 int getHeightInPx() {60 return heightInPx;61 }62 }63 82 64 83 public enum OrientationType { … … 91 110 } 92 111 112 } 113 114 public SelectItem[] getLabelPositionsTypeList() { 115 SelectItem[] items = new SelectItem[LabelPositionType.values().length]; 116 int i = 0; 117 for (LabelPositionType t : LabelPositionType.values()) { 118 items[i++] = new SelectItem(t, t.getLabel()); 119 } 120 return items; 93 121 } 94 122 … … 135 163 } 136 164 137 public void setChartHeight(ChartHeight chartHeight) {138 this.chartHeight = chartHeight;139 }140 141 /**142 * used for the view to set heights as integers143 *144 * @param chartHeight145 */146 public void setChartHeight(int chartHeight) {147 for (ChartHeight thisHeight : ChartHeight.values()) {148 if (thisHeight.getHeightInPx() == chartHeight)149 this.chartHeight = thisHeight;150 }151 }152 153 public int getChartHeight() {154 return chartHeight.getHeightInPx();155 }156 165 157 166 public void setGraphType(ChartType graphType) { … … 196 205 } 197 206 207 public void setxLabelPosition(LabelPositionType xLabelPosition) { 208 this.xLabelPosition = xLabelPosition; 209 } 210 211 public LabelPositionType getxLabelPosition() { 212 return xLabelPosition; 213 } 214 215 198 216 } -
raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/model/GraphModel.java
r561 r566 22 22 public class GraphModel implements Serializable{ 23 23 24 25 24 /* Generated SerialVersionUID */ 26 25 private static final long serialVersionUID = -2803349385469406219L; 27 26 … … 45 44 private SuggestionValues suggestionValues; 46 45 47 /* forseries modal panel*/46 /* Selected series modal panel*/ 48 47 private Series selectedSeries; 49 48 … … 59 58 chartOptions.setxMajorGridCount(-1); 60 59 chartOptions.setyMajorGridCount(-1); 61 chartOptions.setChartHeight(ChartOptions.ChartHeight.MEDIUM);62 60 chartOptions.setOrientation(ChartOptions.OrientationType.VERTICAL); 63 61 chartOptions.setImageWidth(1480); 64 62 chartOptions.setImageHeight(1024); 63 chartOptions.setxLabelPosition(ChartOptions.LabelPositionType.UP_90); 65 64 chartOptions.setGraphPresentation(GraphPresentation.FANCY); 66 65 chartOptions.setGraphType(ChartType.BAR3D); -
raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/service/impl/GraphServiceImpl.java
r561 r566 199 199 @Override 200 200 public void rerenderGraph(WebSession websession) { 201 log.debug("Rerendering graph for display"); 201 202 GraphModel model = websession.getGraphmodel(); 202 chartProcessor.constructJFreeGraph(model.getRawGraphModel(), model.getChartOptions());203 model.setCurrentJFreeGraph(chartProcessor.constructJFreeGraph(model.getRawGraphModel(), model.getChartOptions())); 203 204 204 205 } -
raptor-web/trunk/src/main/webapp/WEB-INF/config/web-setup.xml
r548 r566 75 75 <property name="triggers"> 76 76 <list> 77 <!-- <ref local="SystemStatsQuickTrigger"/>-->77 <ref local="SystemStatsQuickTrigger"/> 78 78 </list> 79 79 </property> … … 85 85 </property> 86 86 <property name="startDelay" value="5000"/> 87 <property name="repeatInterval" value=" 600000"/>87 <property name="repeatInterval" value="1800000"/> 88 88 </bean> 89 89 -
raptor-web/trunk/src/main/webapp/WEB-INF/flows/reports/graphicalReports.xhtml
r561 r566 285 285 opened="false"> 286 286 287 <h:panelGrid columns="1 0">287 <h:panelGrid columns="13"> 288 288 <h:outputText value="Chart Type" /> 289 289 <rich:comboBox selectFirstOnUpdate="false" … … 301 301 </rich:comboBox> 302 302 <rich:spacer width="10px" /> 303 <h:outputText value="Height in pixels" /> 304 <h:inputText value="#{flowScope.websession.graphmodel.chartOptions.imageHeight}"/> 305 <rich:spacer width="10px" /> 306 <h:outputText value="Label Position" /> 307 <rich:comboBox selectFirstOnUpdate="false" 308 defaultLabel="Enter some value" 309 value="#{flowScope.websession.graphmodel.chartOptions.xLabelPosition}"> 310 <f:selectItems 311 value="#{flowScope.websession.graphmodel.chartOptions.labelPositionsTypeList}" /> 312 </rich:comboBox> 313 314 <rich:spacer width="10px" /> 315 303 316 <a4j:commandButton value="refresh" action="rerenderGraph"> 304 <a4j:support ajaxSingle="true" event=" complete"317 <a4j:support ajaxSingle="true" event="oncomplete" 305 318 reRender="graphImage" /> 306 319 </a4j:commandButton> -
raptor-web/trunk/src/main/webapp/WEB-INF/flows/reports/startReport.xhtml
r538 r566 135 135 136 136 137 <h:graphicImage 137 <h:graphicImage width="100%" 138 138 rendered="#{not empty flowScope.websession.startmodel.startStatistics.headlineGraph.relativeChartLocationPath}" 139 139 value="#{flowScope.websession.startmodel.startStatistics.headlineGraph.relativeChartLocationPath}"
Note: See TracChangeset
for help on using the changeset viewer.
