List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:com.rapidminer.gui.plotter.charts.DistributionPlotter.java
@Override public void updatePlotter() { JFreeChart chart = null;/* w ww .ja v a2 s .c o m*/ Attribute attr = null; if (plotColumn != -1 && createFromModel) { attr = model.getTrainingHeader().getAttributes().get(model.getAttributeNames()[plotColumn]); } if (attr != null && attr.isNominal() && attr.getMapping().getValues().size() > MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES) { // showing no chart because of too many different values chart = new JFreeChart(new Plot() { private static final long serialVersionUID = 1L; @Override public String getPlotType() { return "empty"; } @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { String msg = I18N.getGUILabel("plotter_panel.too_many_nominals", "Distribution Plotter", DistributionPlotter.MAX_NUMBER_OF_DIFFERENT_NOMINAL_VALUES); g2.setColor(Color.BLACK); g2.setFont(g2.getFont().deriveFont(g2.getFont().getSize() * 1.35f)); g2.drawChars(msg.toCharArray(), 0, msg.length(), 50, (int) (area.getHeight() / 2 + 0.5d)); } }); AbstractChartPanel panel = getPlotterPanel(); // Chart Panel Settings if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } else { preparePlots(); if (!createFromModel && (groupColumn < 0 || plotColumn < 0)) { CategoryDataset dataset = new DefaultCategoryDataset(); chart = ChartFactory.createBarChart(null, // chart title "Not defined", // x axis label RANGE_AXIS_NAME, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); } else { try { if (model.isDiscrete(translateToModelColumn(plotColumn))) { chart = createNominalChart(); } else { chart = createNumericalChart(); } } catch (Exception e) { // do nothing - just do not draw the chart } } if (chart != null) { chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... Plot commonPlot = chart.getPlot(); commonPlot.setBackgroundPaint(Color.WHITE); if (commonPlot instanceof XYPlot) { XYPlot plot = (XYPlot) commonPlot; plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if (dataTable != null) { if (dataTable.isDate(plotColumn) || dataTable.isDateTime(plotColumn)) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(plotColumn)); domainAxis.setTimeZone(com.rapidminer.tools.Tools.getPreferredTimeZone()); plot.setDomainAxis(domainAxis); } else { NumberAxis numberAxis = new NumberAxis(dataTable.getColumnName(plotColumn)); plot.setDomainAxis(numberAxis); } } plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); // ranging if (dataTable != null) { Range range = getRangeForDimension(plotColumn); if (range != null) { plot.getDomainAxis().setRange(range, true, false); } range = getRangeForName(RANGE_AXIS_NAME); if (range != null) { plot.getRangeAxis().setRange(range, true, false); } } // rotate labels if (isLabelRotating()) { plot.getDomainAxis().setTickLabelsVisible(true); plot.getDomainAxis().setVerticalTickLabels(true); } } else if (commonPlot instanceof CategoryPlot) { CategoryPlot plot = (CategoryPlot) commonPlot; plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.getRangeAxis().setLabelFont(LABEL_FONT_BOLD); plot.getRangeAxis().setTickLabelFont(LABEL_FONT); plot.getDomainAxis().setLabelFont(LABEL_FONT_BOLD); plot.getDomainAxis().setTickLabelFont(LABEL_FONT); } // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } AbstractChartPanel panel = getPlotterPanel(); // Chart Panel Settings if (panel == null) { panel = createPanel(chart); } else { panel.setChart(chart); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); } } }
From source file:de.codesourcery.planning.swing.PlanningCanvas.java
private BoundingBox renderFactoryTitle(IFactory f, RenderContext ctx, boolean layoutOnly) { final String label = labelProvider.getLabel(f); if (StringUtils.isBlank(label)) { return null; }//from ww w. j av a 2 s . co m final int x = ctx.viewport.getX(); final int y = ctx.currentY; final Rectangle2D stringBounds = ctx.getLabelBounds(label); ctx.currentY += stringBounds.getHeight() + ctx.options.getFactoryTitleYOffset(); if (!layoutOnly) { ctx.drawLabel(x, y, label); return null; } return createBoundingBox(x, y, stringBounds).incHeight(ctx.options.getFactoryTitleYOffset()); // include Y offset in bounding box }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public SwingDirectGC(Graphics2D gc, Rectangle2D rect, int iconsize, int xOffset, int yOffset) throws KettleException { this.image = null; this.gc = gc; this.observer = null; this.stepImages = SwingGUIResource.getInstance().getStepImages(); this.entryImages = SwingGUIResource.getInstance().getEntryImages(); this.iconsize = iconsize; this.area = new Point((int) rect.getWidth(), (int) rect.getHeight()); this.xOffset = xOffset; this.yOffset = yOffset; init();//from www .j a v a 2 s .c om }
From source file:org.gumtree.vis.awt.CompositePanel.java
@Override public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) { Rectangle2D compositeBounds = getBounds(); double xRatio = area.getWidth() / compositeBounds.getWidth(); double yRatio = area.getHeight() / compositeBounds.getHeight(); for (IPlot plot : plotList) { if (plot instanceof JPanel) { Rectangle2D plotBounds = ((JPanel) plot).getBounds(); Rectangle2D newArea = new Rectangle2D.Double(area.getMinX() + plotBounds.getMinX() * xRatio, area.getMinY() + plotBounds.getMinY() * yRatio, plotBounds.getWidth() * xRatio, plotBounds.getHeight() * yRatio); plot.draw(g2, newArea, shiftX, shiftY); }/*from w ww. j av a 2 s.c o m*/ } }
From source file:ucar.unidata.idv.control.chart.MyScatterPlot.java
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer).//w w w .ja v a 2s.c om * a * @param g2 the graphics device. * @param dataArea the data area * @param index which data set * @param info collects chart drawing information (<code>null</code> * permitted). * @param crosshairState crosshairState * * @return did something */ public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { if (index >= series.size()) { return false; } XYDataset dataset = getDataset(index); g2.setStroke(new BasicStroke()); // getRendererForDataset(dataset).getSeriesStroke(0)); ScatterPlotChartWrapper.MyRenderer renderer = (ScatterPlotChartWrapper.MyRenderer) getRendererForDataset( dataset); g2.setPaint(renderer.getSeriesPaint(0)); int shape = renderer.shape; PlotOrientation orientation = getOrientation(); int seenCnt = 0; int xx = (int) dataArea.getMinX(); int ww = (int) dataArea.getWidth(); int yy = (int) dataArea.getMaxY(); int hh = (int) dataArea.getHeight(); ValueAxis rangeAxis = getRangeAxisForDataset(index); ValueAxis domainAxis = getDomainAxisForDataset(index); double domainMin = domainAxis.getLowerBound(); double domainLength = domainAxis.getUpperBound() - domainMin; double rangeMin = rangeAxis.getLowerBound(); double rangeLength = rangeAxis.getUpperBound() - rangeMin; int boxWidth = 6; double[][] data = (double[][]) series.get(index); double[] d1 = data[0]; double[] d2 = data[1]; int size = d1.length; Hashtable seen = new Hashtable(); int lastX = 0; int lastY = 0; //TODO: Check for clipping //TODO: Try to create a GeneralPath with the points //and cal g2.draw just once GeneralPath path = new GeneralPath(); long t1 = System.currentTimeMillis(); for (int i = 0; i < size; i++) { int transX = (int) (xx + ww * (d1[i] - domainMin) / domainLength); int transY = (int) (yy - hh * (d2[i] - rangeMin) / rangeLength); Object key = transX + "_" + transY; if (seen.get(key) != null) { seenCnt++; continue; } seen.put(key, key); if (crosshairState != null) { crosshairState.updateCrosshairPoint(d1[i], d2[i], transX, transY, orientation); } switch (shape) { case LineState.SHAPE_VLINE: if (i > 1) { g2.drawLine(lastX, lastY, transX, transY); } lastX = transX; lastY = transY; case LineState.SHAPE_POINT: path.append(new Rectangle((int) transX, (int) transY, 1, 1), false); break; case LineState.SHAPE_LARGEPOINT: path.append(new Rectangle((int) transX, (int) transY, 2, 2), false); break; case LineState.SHAPE_RECTANGLE: path.append( new Rectangle((int) transX - boxWidth / 2, (int) transY - boxWidth / 2, boxWidth, boxWidth), false); break; case LineState.SHAPE_X: g2.drawLine(transX - boxWidth / 2, transY - boxWidth / 2, transX + boxWidth - boxWidth / 2, transY + boxWidth - boxWidth / 2); g2.drawLine(transX + boxWidth - boxWidth / 2, transY - boxWidth / 2, transX - boxWidth / 2, transY + boxWidth - boxWidth / 2); break; case LineState.SHAPE_PLUS: g2.drawLine(transX + boxWidth / 2, transY, transX + boxWidth / 2, transY + boxWidth); g2.drawLine(transX, transY + boxWidth / 2, transX + boxWidth, transY + boxWidth / 2); break; } } g2.fill(path); long t2 = System.currentTimeMillis(); // System.out.println ("time:" + (t2-t1)); return true; }
From source file:extern.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a horizontal orientation. * * @param g2 the graphics device./*from w ww . j a v a 2 s . c o m*/ * @param state the renderer state. * @param dataArea the data area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param visibleRow the visible row index. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, AsymmetricStatisticalCategoryDataset dataset, int visibleRow, int row, int column) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); // BAR Y double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); int seriesCount = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + visibleRow * (state.getBarWidth() + seriesGap); } else { rectY = rectY + visibleRow * state.getBarWidth(); } // BAR X Number meanValue = dataset.getMeanValue(row, column); if (meanValue == null) { return; } double value = meanValue.doubleValue(); double base = 0.0; double lclip = getLowerClip(); double uclip = 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 = getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation); double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation); double rectX = Math.min(transY2, transY1); double rectHeight = state.getBarWidth(); double rectWidth = Math.abs(transY2 - transY1); Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); Paint itemPaint = getItemPaint(row, column); GradientPaintTransformer t = getGradientPaintTransformer(); if (t != null && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); // draw the outline... if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } // CI lines Number n = dataset.getUpperValue(row, column); Number m = dataset.getLowerValue(row, column); if (n != null && m != null) { double valueUpperDelta = n.doubleValue(); double valueLowerDelta = m.doubleValue(); double highVal = rangeAxis.valueToJava2D(valueUpperDelta, dataArea, yAxisLocation); double lowVal = rangeAxis.valueToJava2D(valueLowerDelta, dataArea, yAxisLocation); if (this.errorIndicatorPaint != null) { g2.setPaint(this.errorIndicatorPaint); } else { g2.setPaint(getItemOutlinePaint(row, column)); } if (this.errorIndicatorStroke != null) { g2.setStroke(this.errorIndicatorStroke); } else { g2.setStroke(getItemOutlineStroke(row, column)); } Line2D line = null; line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d); g2.draw(line); line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75); g2.draw(line); line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75); g2.draw(line); } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:net.fenyo.gnetwatch.GUI.BasicComponent.java
/** * Paints axis./*from w ww .ja va2s. co m*/ * @param none. * @return long current time displayed at the axis bottom. */ // AWT thread private long paintAxis() { backing_g.setColor(new Color(50, 50, 50)); backing_g.fillRect(axis_margin_left, axis_margin_top, dimension.width - axis_margin_left - axis_margin_right + 1, dimension.height - axis_margin_top - axis_margin_bottom + 1); backing_g.setColor(Color.YELLOW); backing_g.drawLine(axis_margin_left, dimension.height - axis_margin_bottom, dimension.width - axis_margin_right, dimension.height - axis_margin_bottom); backing_g.drawLine(axis_margin_left, axis_margin_top, axis_margin_left, dimension.height - axis_margin_bottom); backing_g.setColor(Color.YELLOW.darker()); backing_g.drawLine(axis_margin_left + 1, axis_margin_top, dimension.width - axis_margin_right, axis_margin_top); backing_g.drawLine(dimension.width - axis_margin_right, axis_margin_top, dimension.width - axis_margin_right, dimension.height - axis_margin_bottom - 1); int vinterval_pos = dimension.height - axis_margin_bottom - pixels_per_vinterval; backing_g.setColor(Color.YELLOW.darker().darker().darker()); while (vinterval_pos + 9 * (pixels_per_vinterval / 10) > axis_margin_top) { int cpt = 10; while (--cpt > 0) if (vinterval_pos + cpt * (pixels_per_vinterval / 10) > axis_margin_top) backing_g.drawLine(axis_margin_left + 1, vinterval_pos + cpt * (pixels_per_vinterval / 10), dimension.width - axis_margin_right - 1, vinterval_pos + cpt * (pixels_per_vinterval / 10)); vinterval_pos -= pixels_per_vinterval; } final long now; if (manual_mode) now = manual_now; else now = System.currentTimeMillis(); final long time_to_display = now - now % _getDelayPerInterval(); final int pixels_offset = (pixels_per_interval * (int) (now % _getDelayPerInterval())) / (int) _getDelayPerInterval(); final int last_interval_pos = dimension.width - axis_margin_right - pixels_offset; backing_g.setClip(axis_margin_left, 0, dimension.width - axis_margin_left - axis_margin_right, dimension.height); int current_interval_pos = last_interval_pos + pixels_per_interval; long current_time_to_display = time_to_display + _getDelayPerInterval(); boolean stop = false; while (stop == false) { backing_g.setColor(Color.YELLOW.darker()); backing_g.drawLine(current_interval_pos, axis_margin_top, current_interval_pos, dimension.height - axis_margin_bottom + std_separator); int cpt = 10; backing_g.setColor(Color.YELLOW.darker().darker().darker()); while (--cpt > 0) if (current_interval_pos - cpt * (pixels_per_interval / 10) > axis_margin_left) backing_g.drawLine(current_interval_pos - cpt * (pixels_per_interval / 10), axis_margin_top + 1, current_interval_pos - cpt * (pixels_per_interval / 10), dimension.height - axis_margin_bottom - 1); final String current_time_str = formatTime(current_time_to_display); final String current_date_str = formatDate(current_time_to_display); final TextLayout current_layout = new TextLayout(current_time_str, backing_g.getFont(), backing_g.getFontRenderContext()); final TextLayout current_layout_date = new TextLayout(current_date_str, backing_g.getFont(), backing_g.getFontRenderContext()); final Rectangle2D current_bounds = current_layout.getBounds(); final Rectangle2D current_bounds_date = current_layout_date.getBounds(); backing_g.setColor(Color.YELLOW.darker()); backing_g.drawString(current_time_str, current_interval_pos - (int) (current_bounds.getWidth() / 2), dimension.height - axis_margin_bottom + (int) current_bounds.getHeight() + 2 * std_separator); backing_g.setColor(Color.YELLOW.darker().darker()); backing_g.drawString(current_date_str, current_interval_pos - (int) (current_bounds_date.getWidth() / 2), 3 + ((int) current_bounds.getHeight()) + dimension.height - axis_margin_bottom + (int) current_bounds.getHeight() + 2 * std_separator); if (current_interval_pos - current_bounds.getWidth() / 2 < axis_margin_left) stop = true; current_interval_pos -= pixels_per_interval; current_time_to_display -= _getDelayPerInterval(); } backing_g.setClip(null); vinterval_pos = dimension.height - axis_margin_bottom - pixels_per_vinterval; int value = value_per_vinterval; while (vinterval_pos > axis_margin_top) { backing_g.setColor(Color.YELLOW.darker()); backing_g.drawLine(axis_margin_left - std_separator, vinterval_pos, dimension.width - axis_margin_right, vinterval_pos); final String value_str; if (value >= 1000000) value_str = "" + value / 1000000 + "M"; else if (value >= 1000) value_str = "" + value / 1000 + "k"; else value_str = "" + value; final TextLayout current_layout = new TextLayout(value_str, backing_g.getFont(), backing_g.getFontRenderContext()); final Rectangle2D current_bounds = current_layout.getBounds(); backing_g.setColor(Color.YELLOW.darker()); backing_g.drawString(value_str, axis_margin_left - (int) current_bounds.getWidth() - 2 * std_separator, vinterval_pos + (int) (current_bounds.getHeight() / 2)); vinterval_pos -= pixels_per_vinterval; value += value_per_vinterval; } return now; }
From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java
public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) { state = STATE_RUNNING;/* w w w . j a va2 s . co m*/ gridWidth = (int) dataArea.getWidth(); gridHeight = (int) dataArea.getHeight(); //imageX,imageY correspond to point(0,0) int imageX = (int) dataArea.getX() + 1; int imageY = (int) dataArea.getY() + 1; DataBufferInt dataBuffer; image = new BufferedImage(gridWidth, gridHeight, BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); grid = ((DataBufferInt) raster.getDataBuffer()).getData(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); xEpsilon = Math.abs((domainAxis.getUpperBound() - domainAxis.getLowerBound()) / (double) gridWidth); yEpsilon = Math.abs((rangeAxis.getUpperBound() - rangeAxis.getLowerBound()) / (double) gridHeight); int numPoints = gridHeight * gridWidth; int index = 0; int rate = numPoints / 100; if (justClearedSet) { if (criticalSetFound) { this.clearDisplay(); g2.drawImage(image, null, imageX, imageY); } justClearedSet = false; return; } if (!notYetRendered) { plotCopiedDisplay(); g2.drawImage(image, null, imageX, imageY); } notYetRendered = false; if (criticalSetFound && !findCriticalSetAgain) { if (this.chooseSegmentsSet) chooseSegments(g2, image, imageX, imageY); if (this.plotAttractorSet) plotAttractor(g2, image, imageX, imageY); if (this.iterateChosenSegmentsSet) iterateChosenSegments(g2, image, imageX, imageY); if (this.hideAttractorSet) hideAttractor(g2, image, imageX, imageY); } else { this.disableAllActionsExceptStop(); det = new AbsorbingAreaRenderer.ImplicitDeterminant(gridWidth, gridHeight, epsilon, g2, image, imageX, imageY); gridBackup = new int[grid.length]; copyDisplay(); criticalSetFound = true; findCriticalSetAgain = false; g2.drawImage(image, null, imageX, imageY); this.enableAllActionsExceptStop(); } }
From source file:de.codesourcery.planning.swing.DateAxis.java
public BoundingBox render(ITimelineCallback callback, boolean layoutOnly) { final Calendar cal = Calendar.getInstance(); cal.setTime(startDate);//w w w .j a v a2 s . c o m cal.set(Calendar.MILLISECOND, 0); Date currentDate = cal.getTime(); final Date endDate = duration.addTo(startDate); BoundingBox lastLabel = null; final int labelSpacing = 10; final Graphics2D graphics = callback.getGraphics(); final int fontHeight = graphics.getFontMetrics().getHeight(); final double scalingFactor = getXScalingFactor(callback.getBoundingBox()); final BoundingBox box = callback.getBoundingBox(); double x = callback.getBoundingBox().getX(); final int tickToLabelSpacing = 2; final int tickLength = fontHeight; final int axisHeight = fontHeight + tickLength + tickToLabelSpacing; final double xIncrement = Math.floor(tickDuration.toSeconds() * scalingFactor); final Color oldColor = graphics.getColor(); // while (currentDate.compareTo(endDate) <= 0) { final int currentX = (int) Math.floor(x); if (lastLabel == null || lastLabel.getMaxX() < x) { final String labelText = callback.getLabelProvider().getTimelineLabel(currentDate); if (!StringUtils.isBlank(labelText)) { final Rectangle2D stringBounds = callback.getStringBounds(labelText); if (!layoutOnly) { graphics.setColor(Color.BLACK); // draw tick final Stroke oldStroke = graphics.getStroke(); graphics.setStroke(new BasicStroke(2.0f)); graphics.drawLine(currentX, box.getY() + axisHeight, currentX, box.getY() + fontHeight + tickToLabelSpacing); graphics.setStroke(oldStroke); // draw label callback.drawString(Color.BLACK, currentX, box.getY(), labelText); } final BoundingBox labelBox = new BoundingBox(currentX, box.getY(), currentX + (int) stringBounds.getWidth() + labelSpacing, box.getY() + (int) stringBounds.getHeight()); if (lastLabel == null) { lastLabel = labelBox; } else { lastLabel.add(labelBox); } } } else { // draw short tick if (!layoutOnly) { final int halfTickHeight = (int) Math.floor(tickLength / 2.0d); graphics.drawLine(currentX, box.getY() + axisHeight, currentX, box.getY() + axisHeight - halfTickHeight); } } // draw part of axis if (!layoutOnly) { graphics.drawLine((int) x, box.getY() + axisHeight, (int) (x + xIncrement), box.getY() + axisHeight); } x += xIncrement; currentDate = tickDuration.addTo(currentDate); } callback.getGraphics().setColor(oldColor); final BoundingBox result = lastLabel != null ? lastLabel : new BoundingBox(0, 0, 0, 0); result.incHeight(axisHeight); return result; }
From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a horizontal orientation. * // w ww .java2 s .co m * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data 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 drawHorizontalItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) { // nothing is drawn for null... //added this test block, Rinke final Number v = dataset.getValue(row, column); if (v == null) { return; } final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); // BAR Y double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); final int seriesCount = getRowCount(); final int categoryCount = getColumnCount(); if (seriesCount > 1) { final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + row * (state.getBarWidth() + seriesGap); } else { rectY = rectY + row * state.getBarWidth(); } // BAR X final Number meanValue = dataset.getMeanValue(row, column); double value = meanValue.doubleValue(); double base = 0.0; final double lclip = getLowerClip(); final double uclip = 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 = getLowerClip(); if (value >= uclip) { value = uclip; } } final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation); final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation); final double rectX = Math.min(transY2, transY1); final double rectHeight = state.getBarWidth(); final double rectWidth = Math.abs(transY2 - transY1); final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (state.getBarWidth() > 3) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // ********** BLOCK WITH CHANGES RELATIVE TO StatisticalBarRenderere ********************* // standard deviation lines final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset; final Number highValRaw = asymmDataset.getUpperValue(row, column); final Number lowValRaw = asymmDataset.getLowerValue(row, column); if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation); final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation); // *************************** end of block with changes ****************************** if (getErrorIndicatorPaint() != null) { g2.setPaint(getErrorIndicatorPaint()); } else { g2.setPaint(getItemOutlinePaint(row, column)); } Line2D line = null; line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d); g2.draw(line); line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75); g2.draw(line); line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75); g2.draw(line); } final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected final EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }