Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package hudson.plugins.dbcharts;
  
  
  import java.awt.Rectangle;
 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;
     
     public DbChartActionAbstractProject projectDbChartPublisher publisher )
     {        
         super();
         .info"DbChartAction created for project:"+project);
         this. = project;
         this. = publisher;
     }
 
     public String getDisplayName()
     {
         return "Db Chart";
     }
 
     public String getIconFileName()
     {
         return "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().;
//                       rectangles[columnIndex]=new Rectangle(
//                           cie.getArea().getBounds().x,dataArea.y,
//                           cie.getArea().getBounds().width,dataArea.height);
                   }                   
                   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>");
        //<area shape="poly" coords="498,27,497,30,495,30,492,30,492,27,492,25,495,24,497,25,498,27,498,27" title="(2*valueDouble, 2009-08-29 19:10:00.0) = 0,678" alt="" nohref="nohref"/>
        
        
        //response.getWriter()
        //info.getPlotInfo().getDataArea();
        
//        ChartUtil.generateClickableMap(
//                request,
//                response,
//                buildChart(chartParams),
//                CHART_WIDTH,
//                CHART_HEIGHT);
    }

    
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 {
        //AbstractBuild<?,?> lastBuild = this.getLastFinishedBuild();
        //CcccBuildAction lastAction = lastBuild.getAction(CcccBuildAction.class);
        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();
        }
    }
    {
        //Connection connection=Connection.
     //   JDBCCategoryDataset dataset=new JDBCCategoryDataset("jdbc:mysql://localhost/test1","com.mysql.jdbc.Driver","root","");
        
        dataset.executeQuery(c.sqlQuery);
        //dataset.
        JFreeChart chart=ChartFactory.createLineChartc.titlec.categoryAxisLabel,c.valuesAxisLabeldataset
                                                              .truetruefalse );
        final CategoryPlot plot = chart.getCategoryPlot();
        
//        LineAndShapeRenderer ar = new LineAndShapeRenderer() {
            
            
//            @Override
//            public String generateURL(CategoryDataset dataset, int row, int column) {
//                NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
//                return relPath+label.build.getNumber()+"/testReport/";
//            }
            
            
//            @Override
//            public String generateToolTip(CategoryDataset dataset, int row, int column) {
//                NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
//                AbstractTestResultAction a = label.build.getAction(AbstractTestResultAction.class);
//                switch (row) {
//                    case 0:
//                        return String.valueOf(Messages.AbstractTestResultAction_fail(a.getFailCount()));
//                    case 1:
//                        return String.valueOf(Messages.AbstractTestResultAction_skip(a.getSkipCount()));
//                    default:
//                        return String.valueOf(Messages.AbstractTestResultAction_test(a.getTotalCount()));
//                }
//            }
//        };
//        plot.setRenderer(ar);
        
        CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
        plot.setDomainAxis(domainAxis);
        domainAxis.setMaximumCategoryLabelWidthRatio( 0.4f );
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        domainAxis.setCategoryMargin(0.0);
        //final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
//        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        plot.setInsets(new RectangleInsets(0,0,0,5.0));
        
        //chart.
        return chart;
    }
    
New to GrepCode? Check out our FAQ X