Changeset 566


Ignore:
Timestamp:
03/13/11 23:01:49 (2 years ago)
Author:
philsmart
Message:
 
Location:
raptor-web/trunk/src/main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/engine/ChartProcessor.java

    r561 r566  
    3333import org.jfree.chart.renderer.category.BarRenderer; 
    3434import org.jfree.data.category.DefaultCategoryDataset; 
     35import org.jfree.data.general.DefaultPieDataset; 
    3536import org.jfree.ui.RectangleEdge; 
    3637import org.jfree.ui.RectangleInsets; 
     
    5455/** 
    5556 * @author philsmart 
    56  * 
     57 *  
    5758 *         Takes a chart from the MUA, and wraps it inside the current graph view technologies (trinidad, JFreeChart) graph model 
    5859 */ 
     
    6465    private Resource baseDirectory; 
    6566 
    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 */ 
    6768    boolean flipFlopChartName; 
    68  
    69      
    7069 
    7170    public String getRootDirectory(String user) { 
     
    110109    } 
    111110 
    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 
    118115    /** 
    119116     * Will output into the root graphs directory 
     
    123120     * @return 
    124121     */ 
    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    } 
    130125 
    131126    public RaptorJFreeChartModel constructJFreeGraph(GraphPresentation graphPresentation, ChartType graphType, AggregatorGraphModel gmodel, int width, int height, String filename) { 
     
    135130        chartOptions.setGraphPresentation(graphPresentation); 
    136131        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); 
    138150    } 
    139151 
    140152    /** 
    141153     * Requires websession, as charts stored on file system specific to the current users home directory 
    142      * 
     154     *  
    143155     * @param gmodel 
    144156     * @param session 
    145157     * @return 
    146158     */ 
    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 
    150163 
    151164        // construct the graph 
     
    169182                yAxisLabel = gmodel.getPresentation().getyAxisLabel(); 
    170183        } 
    171          
    172         //initialise default, then change on condition 
     184 
     185        // initialise default, then change on condition 
    173186        PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL; 
    174         if (chartOptions.getOrientation()==ChartOptions.OrientationType.HORIZONTAL) 
     187        if (chartOptions.getOrientation() == ChartOptions.OrientationType.HORIZONTAL) 
    175188            plotOrientation = PlotOrientation.HORIZONTAL; 
    176         else if (chartOptions.getOrientation()==ChartOptions.OrientationType.VERTICAL) 
     189        else if (chartOptions.getOrientation() == ChartOptions.OrientationType.VERTICAL) 
    177190            plotOrientation = PlotOrientation.VERTICAL; 
    178          
     191 
    179192        log.debug("Graph Setup with Title {}, xAxisLabel {}, yAxisLabel {}", new Object[] { chartTitle, xAxisLabel, yAxisLabel }); 
    180193        if (chartOptions.getGraphType() == ChartType.BAR3D) 
    181194            chart = ChartFactory.createBarChart3D(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false); 
    182195        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); 
    184197        else if (chartOptions.getGraphType() == ChartType.LINE3D) 
    185198            chart = ChartFactory.createLineChart3D(chartTitle, xAxisLabel, yAxisLabel, dataset, plotOrientation, chartOptions.getGraphPresentation().getLegend(), true, false); 
     
    188201        else if (chartOptions.getGraphType() == ChartType.LINE) 
    189202            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(); 
    190210 
    191211        // setup the graph output 
    192212        if (chartOptions.getGraphPresentation() == GraphPresentation.FANCY) 
    193             fancyGraphOutput(chart); 
     213            fancyGraphOutput(chart, chartOptions); 
    194214        else if (chartOptions.getGraphPresentation() == GraphPresentation.FRONT) 
    195             frontGraphOutput(chart); 
     215            frontGraphOutput(chart, chartOptions); 
    196216 
    197217        // 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 image 
     218        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 
    203223        int ran = getRandomChartFileExtension(100); 
    204224 
    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"); 
    207227 
    208228        // png is used for screen output 
     
    210230            try { 
    211231                int padding = 5; 
    212                 log.debug("Writing PNG to {}",chartLocationPNG); 
     232                log.debug("Writing PNG to {}", chartLocationPNG); 
    213233                ImageIO.write(ChartProcessorHelper.buildChartDropShadow(chart.createBufferedImage(chartOptions.getImageWidth() - (padding * 2), chartOptions.getImageHeight() - (padding * 2)), padding), "png", new FileOutputStream(chartLocationPNG)); 
    214234            } catch (IOException e) { 
     
    223243        } 
    224244 
    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        // } 
    230250 
    231251        chartmodel.setChartLocation(chartLocationPNG); 
     
    234254    } 
    235255 
    236     private int getRandomFlipFlopChartFileExtension(){ 
    237         if (flipFlopChartName){ 
    238             flipFlopChartName=false; 
     256    private int getRandomFlipFlopChartFileExtension() { 
     257        if (flipFlopChartName) { 
     258            flipFlopChartName = false; 
    239259            return 0; 
    240         } 
    241         else { 
    242             flipFlopChartName=true; 
     260        } else { 
     261            flipFlopChartName = true; 
    243262            return 1; 
    244263        } 
    245264    } 
    246265 
    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)); 
    249268        return ran; 
    250269    } 
    251270 
    252     private void fancyGraphOutput(JFreeChart chart) { 
     271    private void fancyGraphOutput(JFreeChart chart, ChartOptions chartOptions) { 
    253272        CategoryPlot plot = (CategoryPlot) chart.getPlot(); 
    254273        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); 
    255         xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); 
     274        xAxis.setCategoryLabelPositions(chartOptions.getxLabelPosition().getLabelPosition()); 
    256275        chart.setBackgroundPaint(new Color(255, 255, 255, 0)); 
    257276        chart.setPadding(new RectangleInsets(10, 5, 5, 5)); 
     
    271290        domainAxis.setUpperMargin(0.0); 
    272291        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) { 
    279304        CategoryPlot plot = (CategoryPlot) chart.getPlot(); 
    280305        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); 
     
    287312        plot.setRangeGridlinePaint(Color.black); 
    288313        plot.setDomainGridlinePaint(Color.black); 
    289         //set the thickness of the first series 
     314        // set the thickness of the first series 
    290315        plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); 
    291316        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))); 
    293318        plot.getRenderer().setSeriesPaint(0, Color.blue); 
    294319        // axis 
     
    296321        domainAxis.setUpperMargin(0.0); 
    297322        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)); 
    300325 
    301326    } 
     
    303328    /** 
    304329     * Exports a JFreeChart to a SVG file. 
    305      * 
     330     *  
    306331     * @param chart 
    307332     *            JFreeChart to export 
     
    335360    /** 
    336361     * Exports a JFreeChart to a jpg file. 
    337      * 
     362     *  
    338363     * @param chart 
    339364     *            JFreeChart to export 
     
    360385     */ 
    361386    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()); 
    363388 
    364389        RaptorTableChartModel tableModel = new RaptorTableChartModel(); 
     
    378403        tableModel.constructTableForView(); 
    379404 
    380         //log.debug("Raptor Table model constructed, with {} rows",tableModel.getRowList().size()); 
     405        // log.debug("Raptor Table model constructed, with {} rows",tableModel.getRowList().size()); 
    381406 
    382407        return tableModel; 
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/model/ChartOptions.java

    r561 r566  
    1010import javax.faces.model.SelectItem; 
    1111 
     12import org.jfree.chart.axis.CategoryLabelPositions; 
    1213import org.slf4j.Logger; 
    1314import org.slf4j.LoggerFactory; 
     
    2829    private int xMajorGridCount; 
    2930    private int yMajorGridCount; 
    30     private ChartHeight chartHeight; 
    3131    private OrientationType orientation; 
    3232    private int imageWidth; 
    33     private int imageHeight; 
     33    private int imageHeight;    
     34     
    3435    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     
    3769    /* options for how the graph is displayed */ 
    3870    public enum GraphPresentation { 
     
    4880        } 
    4981    } 
    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     } 
    6382     
    6483    public enum OrientationType { 
     
    91110        } 
    92111 
     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; 
    93121    } 
    94122     
     
    135163    } 
    136164 
    137     public void setChartHeight(ChartHeight chartHeight) { 
    138         this.chartHeight = chartHeight; 
    139     } 
    140  
    141     /** 
    142      * used for the view to set heights as integers 
    143      *  
    144      * @param chartHeight 
    145      */ 
    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     } 
    156165 
    157166    public void setGraphType(ChartType graphType) { 
     
    196205    } 
    197206 
     207    public void setxLabelPosition(LabelPositionType xLabelPosition) { 
     208        this.xLabelPosition = xLabelPosition; 
     209    } 
     210 
     211    public LabelPositionType getxLabelPosition() { 
     212        return xLabelPosition; 
     213    } 
     214 
     215 
    198216} 
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/model/GraphModel.java

    r561 r566  
    2222public class GraphModel implements Serializable{ 
    2323 
    24  
    25  
     24        /* Generated SerialVersionUID */ 
    2625        private static final long serialVersionUID = -2803349385469406219L; 
    2726 
     
    4544        private SuggestionValues suggestionValues; 
    4645 
    47         /* for series modal panel*/ 
     46        /* Selected series modal panel*/ 
    4847        private Series selectedSeries; 
    4948 
     
    5958            chartOptions.setxMajorGridCount(-1); 
    6059            chartOptions.setyMajorGridCount(-1); 
    61             chartOptions.setChartHeight(ChartOptions.ChartHeight.MEDIUM); 
    6260            chartOptions.setOrientation(ChartOptions.OrientationType.VERTICAL); 
    6361            chartOptions.setImageWidth(1480); 
    6462            chartOptions.setImageHeight(1024); 
     63            chartOptions.setxLabelPosition(ChartOptions.LabelPositionType.UP_90); 
    6564            chartOptions.setGraphPresentation(GraphPresentation.FANCY); 
    6665            chartOptions.setGraphType(ChartType.BAR3D); 
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/service/impl/GraphServiceImpl.java

    r561 r566  
    199199        @Override 
    200200        public void rerenderGraph(WebSession websession) { 
     201            log.debug("Rerendering graph for display"); 
    201202            GraphModel model = websession.getGraphmodel(); 
    202             chartProcessor.constructJFreeGraph(model.getRawGraphModel(), model.getChartOptions()); 
     203            model.setCurrentJFreeGraph(chartProcessor.constructJFreeGraph(model.getRawGraphModel(), model.getChartOptions())); 
    203204             
    204205        } 
  • raptor-web/trunk/src/main/webapp/WEB-INF/config/web-setup.xml

    r548 r566  
    7575                <property name="triggers"> 
    7676                        <list> 
    77                         <!--  <ref local="SystemStatsQuickTrigger"/>--> 
     77                          <ref local="SystemStatsQuickTrigger"/> 
    7878                        </list> 
    7979                </property> 
     
    8585                </property> 
    8686                <property name="startDelay" value="5000"/> 
    87                 <property name="repeatInterval" value="600000"/> 
     87                <property name="repeatInterval" value="1800000"/> 
    8888        </bean> 
    8989 
  • raptor-web/trunk/src/main/webapp/WEB-INF/flows/reports/graphicalReports.xhtml

    r561 r566  
    285285                                                                opened="false"> 
    286286 
    287                                                                 <h:panelGrid columns="10"> 
     287                                                                <h:panelGrid columns="13"> 
    288288                                                                        <h:outputText value="Chart Type" /> 
    289289                                                                        <rich:comboBox selectFirstOnUpdate="false" 
     
    301301                                                                        </rich:comboBox> 
    302302                                                                        <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                                                                         
    303316                                                                        <a4j:commandButton value="refresh" action="rerenderGraph"> 
    304                                                                                 <a4j:support ajaxSingle="true" event="complete" 
     317                                                                                <a4j:support ajaxSingle="true" event="oncomplete" 
    305318                                                                                        reRender="graphImage" /> 
    306319                                                                        </a4j:commandButton> 
  • raptor-web/trunk/src/main/webapp/WEB-INF/flows/reports/startReport.xhtml

    r538 r566  
    135135 
    136136 
    137                                         <h:graphicImage 
     137                                        <h:graphicImage width="100%" 
    138138                                                rendered="#{not empty flowScope.websession.startmodel.startStatistics.headlineGraph.relativeChartLocationPath}" 
    139139                                                value="#{flowScope.websession.startmodel.startStatistics.headlineGraph.relativeChartLocationPath}" 
Note: See TracChangeset for help on using the changeset viewer.