Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.dbcharts;
  
  
  import java.awt.Color;
 import java.awt.Font;
 import java.awt.Paint;
 import java.awt.Shape;
 import java.util.List;
 
 
 public class DbChartAction  implements Action
 {
     private static final Logger logger=Logger.getLoggerDbChartAction.class.getCanonicalName());
 //    private final AbstractProject<?,?> project;
     private final DbChartPublisher publisher;
    
    
All plots share the same JFreeChart drawing supplier object.
 
     private static final DrawingSupplier supplier = new DefaultDrawingSupplier(
             // the plot data points are a small diamond shape 
             new Shape[] { new Polygon(new int[] {3, 0, -3, 0},
                     new int[] {0, 4, 0, -4}, 4) }
     );
     
     public DbChartActionAbstractProject<?,?> projectDbChartPublisher publisher )
     {        
         super();
         .info"DbChartAction created for project:"+project);
 //  /      this.project = project;
         this. = publisher;
     }
 
     public String getDisplayName()
     {
        // return "Db Chart";
         return null;
     }
 
     public String getIconFileName()
     {
         return null;//"folder.gif";
     }
     
     public String getUrlName()
     {
         return "dbCharts";
     }
 
     
   
     public List<ChartgetCharts(){
         .info"getCharts().size="+.getCharts().size() );
         return .getCharts();
     }
     
     public Chart getChartByName(String name){
         for(Chart c:getCharts()){
             if (name.equalsc.name )){
                 return c;
             }
         }
         return null;
     }
            
    
Display the trend map. Delegates to the the associated ResultAction.

Parameters:
request Stapler request
response Stapler response
Throws:
java.io.IOException in case of an error
java.sql.SQLException
java.lang.ClassNotFoundException
    public void doTrendMap(final StaplerRequest requestfinal StaplerResponse responsethrows IOExceptionClassNotFoundExceptionSQLException {
        Chart chartParams=getChartByNamerequest.getParameter"chart" ) );
        JFreeChart chart=buildChart(chartParams);        
        
        ChartRenderingInfo info = new ChartRenderingInfo();
        chart.createBufferedImage(chartParams.width,chartParams.height,info);
     
        EntityCollection entities = info.getEntityCollection();
        if (entities != null) {
            int count = entities.getEntityCount();
            for (int i = count - 1; i >= 0; i--) {
                ChartEntity entity = entities.getEntity(i);
                .info("Entity "+entity);
                if (entity instanceof CategoryItemEntity ){
                   CategoryItemEntity cie=(CategoryItemEntityentity;
                   .info(" - area:"+cie.getArea().getBounds());
                   .info(" - shapeCords:"+cie.getShapeCoords());
                   .info(" - columnKey:"+cie.getColumnKey() +" "+cie.getColumnKey().getClass().toString());
                   .info(" - rowKey:"+cie.getRowKey()+" "+cie.getRowKey().getClass().toString());
                   .info(" - columnIndex:"+cie.getDataset().getColumnIndexcie.getColumnKey() ));
                   .info(" - rowIndex:"+cie.getDataset().getRowIndexcie.getRowKey() ));
                }                
            }
        }
        
        Rectangle dataArea=info.getPlotInfo().getDataArea().getBounds();
        .info("chartArea:"+info.getChartArea());
        .info("dataArea:"+dataArea);
        .info("plotArea:"+info.getPlotInfo().getPlotArea());
        
        
        
        final int categoriesCount=chart.getCategoryPlot().getCategories().size();
        StringBuilder[] buffers=new StringBuilder[categoriesCount];
        Integer[] starts=new Integer[categoriesCount];
        Integer[] ends=new Integer[categoriesCount];
        
        
        if (entities != null) {
            int count = entities.getEntityCount();
            for (int i = count - 1; i >= 0; i--) {
                ChartEntity entity = entities.getEntity(i);
                if (entity instanceof CategoryItemEntity ){
                   CategoryItemEntity cie=(CategoryItemEntityentity;
                   int columnIndex=cie.getDataset().getColumnIndexcie.getColumnKey() );
                   int rowIndex=cie.getDataset().getRowIndexcie.getRowKey() );
                   
                   if (buffers[columnIndex]==null){
                       buffers[columnIndex]=new StringBuilder(cie.getColumnKey()+": ");
                       starts[columnIndex]=cie.getArea().getBounds().;
                       ends[columnIndex]=cie.getArea().getBounds().+cie.getArea().getBounds().;
                   }                   
                   buffers[columnIndex].append(" "+cie.getRowKey()+"="+cie.getDataset().getValuerowIndex,columnIndex));
                   
                }                
            }
        }
         
        
        response.setContentType("text/plain;charset=UTF-8");
        
        PrintWriter ps=response.getWriter();
        ps.println("<map id='map' name='map'>");
        int last_start=dataArea.getBounds().;
        
        for(int i=0; i<categoriesCounti++){
            int new_last_start=
                (i<categoriesCount-1)?
                    (ends[i]+starts[i+1])/2
                    :(ends[i]+dataArea.x+dataArea.width)/2;
            
            ps.print(" <area shape='rect' coords='"
                     +last_start+","+dataArea.y+","
                     +new_last_start+","
                     +(dataArea.y+dataArea.height)+"' ");
           ps.print(" title='"+ImageMapUtilities.htmlEscape(buffers[i].toString())+"'");
           ps.println(" alt='' nohref='nohref' />");
           
           last_start=new_last_start;
            
        }
        ps.println("</map>");
    }

    
Display the trend graph. Delegates to the the associated ResultAction.

Parameters:
request Stapler request
response Stapler response
Throws:
java.io.IOException in case of an error in ResultAction#doGraph(StaplerRequest , StaplerResponse , int )
    public void doTrend(final StaplerRequest requestfinal StaplerResponse responsethrows IOException {
        Chart c=getChartByNamerequest.getParameter("chart" ) );
        try
        {
            ChartUtil.generateGraph(
                    request,
                    response,
                    buildChart(c),
                    c.width,
                    c.height);
        }
        catch ( ClassNotFoundException e )
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch ( SQLException e )
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    {        
        dataset.executeQuery(c.sqlQuery);
        JFreeChart chart=ChartFactory.createLineChartc.titlec.categoryAxisLabel,c.valuesAxisLabeldataset
                                                              .truetruefalse );
        final CategoryPlot plot = chart.getCategoryPlot();
        plot.setDomainGridlinePaint(.);
        plot.setRangeGridlinePaint(.);
        plot.setDrawingSupplier();
        plot.setBackgroundPaint. );
        
        chart.setBackgroundPaint. );
        chart.getTitle().setFontnew Font
                chart.getTitle().getFont().getName(), 
                chart.getTitle().getFont().getStyle(), 
                12 ) );
        
        CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
        plot.setDomainAxis(domainAxis);
        domainAxis.setMaximumCategoryLabelWidthRatio( 0.4f );
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        domainAxis.setCategoryMargin(0.0);
        plot.setInsets(new RectangleInsets(0,0,0,5.0));
        return chart;
    }
    
New to GrepCode? Check out our FAQ X