List of usage examples for org.jfree.chart.renderer.category BarRenderer BAR_OUTLINE_WIDTH_THRESHOLD
double BAR_OUTLINE_WIDTH_THRESHOLD
To view the source code for org.jfree.chart.renderer.category BarRenderer BAR_OUTLINE_WIDTH_THRESHOLD.
Click Source Link
From source file:edu.cuny.jfree.chart.renderer.category.IntervalListBarRenderer.java
/** * Draws a single interval./*from w ww . j a va 2 s . co m*/ * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the data plot area. * @param plot * the plot. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). */ protected void drawInterval(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final DefaultIntervalListCategoryDataset dataset, final int row, final int column) { final int seriesCount = getRowCount(); final int categoryCount = getColumnCount(); final PlotOrientation orientation = plot.getOrientation(); double rectX = 0.0; double rectY = 0.0; final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final List list = dataset.getList(row, column); if (list == null) { return; } Interval interval = null; for (int i = 0; i < list.size(); i++) { interval = (Interval) list.get(i); if (!interval.isMeaningful()) { continue; } // Y0 double java2dValue0 = rangeAxis.valueToJava2D(interval.low, dataArea, rangeAxisLocation); // Y1 double java2dValue1 = rangeAxis.valueToJava2D(interval.high, dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { final double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; } // BAR WIDTH double rectWidth = state.getBarWidth(); // BAR HEIGHT double rectHeight = Math.abs(java2dValue1 - java2dValue0); if (orientation == PlotOrientation.HORIZONTAL) { // BAR Y rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); if (seriesCount > 1) { final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + row * (state.getBarWidth() + seriesGap); } else { rectY = rectY + row * state.getBarWidth(); } rectX = java2dValue0; rectHeight = state.getBarWidth(); rectWidth = Math.abs(java2dValue1 - java2dValue0); } else if (orientation == PlotOrientation.VERTICAL) { // BAR X rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); if (seriesCount > 1) { final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectX = rectX + row * (state.getBarWidth() + seriesGap); } else { rectX = rectX + row * state.getBarWidth(); } rectY = java2dValue0; } final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); // draw the outline... if (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD) { final Stroke stroke = getItemOutlineStroke(row, column); final Paint paint = getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if ((generator != null) && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, false); } // collect entity and tool tip information... if (state.getInfo() != null) { final EntityCollection entities = state.getInfo().getOwner().getEntityCollection(); if (entities != null) { String tip = null; final CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } final CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } } }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.renderer.HierarchicalBarRenderer.java
/** * Draws the bar for one item in the dataset. * * @param g2/* w w w. ja v a2 s.com*/ * the graphics device. * @param state * the renderer state. * @param dataArea * the plot area. * @param plot * the plot. * @param domainAxis * the domain (category) axis. * @param rangeAxis * the range (value) axis. * @param data * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = data.getValue(row, column); if (dataValue == null) { return; } // BAR X double rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); int seriesCount = this.getRowCount(); // BAR Y double value = dataValue.doubleValue(); double base = 0.0; double lclip = this.getLowerClip(); double uclip = this.getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = this.getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge edge = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); double rectY = Math.min(transY2, transY1); double rectWidth = state.getBarWidth(); double rectHeight = Math.abs(transY2 - transY1); // draw the bar... double shift = 0.0; rectWidth = 0.0; double widthFactor = 1.0; double seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - ((seriesCount - 1 - row) * shift * 2)), rectHeight); double rrX; double rrY; double rrW; double rrH; if (row == 0) { @SuppressWarnings("unchecked") Iterator it = this.datasetTree[column].getDescendants(); int numElement = -1; while (it.hasNext()) { try { Element elt = (Element) it.next(); numElement++; String name = elt.getAttributeValue("name"); dataValue = Double.valueOf(elt.getAttributeValue("avg")); // System.out.println("["+column+"] "+name+" \t--> // "+dataValue); // BAR X rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); seriesCount = this.getRowCount(); // BAR Y value = dataValue.doubleValue(); base = 0.0; lclip = this.getLowerClip(); uclip = this.getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = this.getLowerClip(); if (value >= uclip) { value = uclip; } } edge = plot.getRangeAxisEdge(); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); rectY = Math.min(transY2, transY1); rectWidth = state.getBarWidth(); rectHeight = Math.abs(transY2 - transY1); // draw the bar... shift = 0.0; rectWidth = 0.0; widthFactor = 1.0; seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } rrX = (rectX + ((seriesCount - 1 - row) * shift)); rrY = rectY; rrW = (rectWidth - ((seriesCount - 1 - row) * shift * 2)); rrH = rectHeight; // IMPORTANT NOTE : // dev attribute is used to save width of the element // min attribute is used to save X position of the element // max attribute is used to save the number of child already // managed if (numElement == 0) { elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); elt.setAttribute("max", "0"); } else { Element parent = elt.getParentElement(); // System.out.println(" Parent // "+parent.getAttributeValue("name") // + " rrX/rrW/child -> " // + parent.getAttributeValue("min")+"/" // + parent.getAttributeValue("dev")+"/" // + parent.getAttributeValue("max") ); double pW = Double.valueOf(parent.getAttributeValue("dev")); double pX = Double.valueOf(parent.getAttributeValue("min")); int numChild = Integer.valueOf(parent.getAttributeValue("max")); rrW = pW / parent.getChildren().size(); rrX = pX + (rrW * numChild); rrX += HierarchicalBarRenderer.INCLUSION_MARGIN; rrW -= (HierarchicalBarRenderer.INCLUSION_MARGIN * 2); elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); parent.setAttribute("max", "" + (numChild + 1)); } RoundRectangle2D rbar = new RoundRectangle2D.Double(rrX, rrY, rrW, rrH, HierarchicalBarRenderer.CORNER, HierarchicalBarRenderer.CORNER); Rectangle2D childSumLine = null; double childSum = Double.valueOf(elt.getAttributeValue("sum")); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(childSum, dataArea, edge); rectY = Math.min(transY2, transY1); childSum = (childSum / dataValue.doubleValue()) * rrH; if ((childSum < rrH) && (childSum > 0) && ((childSum / rrH) < 0.95)) { childSumLine = new Rectangle2D.Double(rrX, rectY, rrW, 1); } Paint itemPaint = this.getItemPaintFromName(name, this.series, column); GradientPaintTransformer t = this.getGradientPaintTransformer(); if ((t != null) && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); Color c = g2.getColor(); g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), this.alpha)); g2.fill(rbar); g2.setColor(Color.DARK_GRAY); if (childSumLine != null) { g2.fill(childSumLine); } // draw the outline... if (this.isDrawBarOutline() && (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD)) { Stroke stroke = this.getItemOutlineStroke(row, column); Paint paint = this.getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(rbar); } } } catch (ClassCastException e) { continue; } } } // //////////////////////////// // draw the item labels if there are any... double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge); CategoryItemLabelGenerator generator = this.getItemLabelGenerator(row, column); if ((generator != null) && this.isItemLabelVisible(row, column)) { this.drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = this.getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(data, row, column); } String url = null; if (this.getItemURLGenerator(row, column) != null) { url = this.getItemURLGenerator(row, column).generateURL(data, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, data, row, data.getColumnKey(column), column); entities.add(entity); } } }