1 package hudson.util; 2 3 import org.jfree.chart.axis.CategoryAxis; 4 import org.jfree.chart.axis.ValueAxis; 5 import org.jfree.chart.entity.EntityCollection; 6 import org.jfree.chart.labels.CategoryToolTipGenerator; 7 import org.jfree.chart.plot.CategoryPlot; 8 import org.jfree.chart.renderer.AreaRendererEndType; 9 import org.jfree.chart.renderer.category.CategoryItemRendererState; 10 import org.jfree.chart.renderer.category.StackedAreaRenderer; 11 import org.jfree.chart.urls.CategoryURLGenerator; 12 import org.jfree.data.category.CategoryDataset; 13 import org.jfree.ui.RectangleEdge; 14 15 import java.awt.Graphics2D ; 16 import java.awt.Polygon ; 17 import java.awt.Paint ; 18 import java.awt.geom.Rectangle2D ; 19 20 35 public class StackedAreaRenderer2 extends StackedAreaRenderer 36 implements CategoryToolTipGenerator, CategoryURLGenerator { 37 38 public StackedAreaRenderer2() { 39 setEndType(AreaRendererEndType.TRUNCATE); 40 setItemURLGenerator(this); 41 setToolTipGenerator(this); 42 } 43 44 47 public String generateURL(CategoryDataset dataset, int row, int column) { 48 return null; 49 } 50 51 54 public String generateToolTip(CategoryDataset dataset, int row, int column) { 55 return null; 56 } 57 58 61 public Paint getItemPaint(int row, int column) { 62 return super.getItemPaint(row, column); 63 } 64 65 @Override 67 public void drawItem(Graphics2D g2, 68 CategoryItemRendererState state, 69 Rectangle2D dataArea, 70 CategoryPlot plot, 71 CategoryAxis domainAxis, 72 ValueAxis rangeAxis, 73 CategoryDataset dataset, 74 int row, 75 int column, 76 int pass) { 77 78 Number dataValue = dataset.getValue(row, column); 80 if (dataValue == null) { 81 return; 82 } 83 84 double value = dataValue.doubleValue(); 85 86 double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), 90 dataArea, plot.getDomainAxisEdge()); 91 92 double previousHeightx1 = getPreviousHeight(dataset, row, column); 93 double y1 = value + previousHeightx1; 94 RectangleEdge location = plot.getRangeAxisEdge(); 95 double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location); 96 97 g2.setPaint(getItemPaint(row, column)); 98 g2.setStroke(getItemStroke(row, column)); 99 100 EntityCollection entities = state.getEntityCollection(); 102 103 if (column == 0) { 106 if (pass == 1) { 107 if (isItemLabelVisible(row, column)) { 109 drawItemLabel(g2, plot.getOrientation(), dataset, row, column, 110 xx1, yy1, (y1 < 0.0)); 111 } 112 } 113 } else { 114 Number previousValue = dataset.getValue(row, column - 1); 115 if (previousValue != null) { 116 117 double xx0 = domainAxis.getCategoryMiddle(column - 1, 118 getColumnCount(), dataArea, plot.getDomainAxisEdge()); 119 double y0 = previousValue.doubleValue(); 120 121 122 double previousHeightx0 = getPreviousHeight(dataset, row, 125 column - 1); 126 127 y0 += previousHeightx0; 129 130 double previousHeightxx0 = rangeAxis.valueToJava2D( 132 previousHeightx0, dataArea, location); 133 double previousHeightxx1 = rangeAxis.valueToJava2D( 134 previousHeightx1, dataArea, location); 135 136 double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location); 138 139 if (pass == 0) { 140 Polygon p = new Polygon (); 142 p.addPoint((int) xx0, (int) yy0); 143 p.addPoint((int) (xx0+xx1)/2, (int) (yy0+yy1)/2); 144 p.addPoint((int) (xx0+xx1)/2, (int) (previousHeightxx0+previousHeightxx1)/2); 145 p.addPoint((int) xx0, (int) previousHeightxx0); 146 147 g2.setPaint(getItemPaint(row, column-1)); 148 g2.setStroke(getItemStroke(row, column-1)); 149 g2.fill(p); 150 151 if (entities != null) 152 addItemEntity(entities, dataset, row, column-1, p); 153 154 p = new Polygon (); 156 p.addPoint((int) xx1, (int) yy1); 157 p.addPoint((int) (xx0+xx1)/2, (int) (yy0+yy1)/2); 158 p.addPoint((int) (xx0+xx1)/2, (int) (previousHeightxx0+previousHeightxx1)/2); 159 p.addPoint((int) xx1, (int) previousHeightxx1); 160 161 g2.setPaint(getItemPaint(row, column)); 162 g2.setStroke(getItemStroke(row, column)); 163 g2.fill(p); 164 165 if (entities != null) 166 addItemEntity(entities, dataset, row, column, p); 167 } else { 168 if (isItemLabelVisible(row, column)) { 169 drawItemLabel(g2, plot.getOrientation(), dataset, row, 170 column, xx1, yy1, (y1 < 0.0)); 171 } 172 } 173 } 174 } 175 } 176 } 177 | Popular Tags |