List of usage examples for org.jfree.chart.plot XYPlot getRangeAxisEdge
public RectangleEdge getRangeAxisEdge()
From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java
/** * @see drawSecondaryPass//from w ww . jav a2 s .c om */ private void drawFeedBackNode(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, // final int series, final int item, final ValueAxis domainAxis, final Rectangle2D dataArea, final ValueAxis rangeAxis, // final CrosshairState crosshairState, final EntityCollection entities) { // get the data point... final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item); final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { g2.setPaint(getFeedbackNodePaint()); g2.fill(shape); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } drawFeedbackItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
public void draw(Graphics2D g2, ChartPanel chartPanel, XYPlot plot, Color fillColor, Collection<? extends VisualPeakAnnotation> shapes, Collection<? extends VisualPeakAnnotation> selectedShapes) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea);/*from w w w . j av a2s . c o m*/ ValueAxis xAxis = plot.getDomainAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Color c = g2.getColor(); // Color fillColor = peakAnnotations.getColor(); // if (fillColor == null || fillColor.equals(Color.WHITE) || fillColor.equals(new Color(255, 255, 255, 0))) { //// System.out.println("Peak annotation color was null or white, using color from treatment group!"); // fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor(); // } for (VisualPeakAnnotation x : shapes) { Shape s = toViewXY(x, chartPanel, x.getCenter()); switch (x.getPeakAnnotationType()) { case LINE: drawEntity(s, g2, fillColor, null, chartPanel, false, 0.1f); break; case OUTLINE: // plot.addAnnotation(new XYShapeAnnotation(x, new BasicStroke(1.0f), new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), 64), new Color(254, 254, 254, 254)), false); drawOutline(s, g2, fillColor, Color.DARK_GRAY, chartPanel, false, 0.25f); break; case POINTER: drawEntity(s, g2, fillColor, Color.DARK_GRAY, chartPanel, false, 0.25f); break; default: drawEntity(s, g2, fillColor, null, chartPanel, false, 0.1f); } } for (VisualPeakAnnotation x : selectedShapes) { Shape s = toViewXY(x, chartPanel, x.getCenter()); switch (x.getPeakAnnotationType()) { case LINE: drawEntity(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f); break; case OUTLINE: // plot.addAnnotation(new XYShapeAnnotation(x, new BasicStroke(1.0f), new Color(fillColor.getRed(),fillColor.getGreen(),fillColor.getBlue(),64), new Color(254,254,254,254)), false); drawOutline(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f); break; case POINTER: drawEntity(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f); break; default: drawEntity(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f); } } g2.setColor(c); g2.setClip(savedClip); // chartPanel.repaint(); }
From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device./* ww w. ja va 2 s . c o m*/ * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color information * etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (!getItemVisible(series, item)) { return; } XYAreaRendererState areaState = (XYAreaRendererState) state; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { y1 = 0.0; } double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge()); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... int itemCount = dataset.getItemCount(series); double x0 = dataset.getXValue(series, Math.max(item - 1, 0)); double y0 = dataset.getYValue(series, Math.max(item - 1, 0)); if (Double.isNaN(y0)) { y0 = 0.0; } double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge()); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge()); double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1)); double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1)); if (Double.isNaN(y2)) { y2 = 0.0; } double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge()); double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge()); double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); Polygon hotspot = null; if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { hotspot = new Polygon(); hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0)); hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0)); hotspot.addPoint((int) transY1, (int) transX1); hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0)); hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0)); } else { // vertical orientation hotspot = new Polygon(); hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero); hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0)); hotspot.addPoint((int) transX1, (int) transY1); hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0)); hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero); } if (item == 0) { // create a new area polygon for the series areaState.area = new Polygon(); // the first point is (x, 0) double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.area.addPoint((int) transX1, (int) zero); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.area.addPoint((int) zero, (int) transX1); } } // Add each point to Area (x, y) if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.area.addPoint((int) transX1, (int) transY1); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.area.addPoint((int) transY1, (int) transX1); } PlotOrientation orientation = plot.getOrientation(); Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(stroke); Shape shape = null; if (getPlotShapes()) { shape = getItemShape(series, item); if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } else if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } g2.draw(shape); } if (getPlotLines()) { if (item > 0) { if (plot.getOrientation() == PlotOrientation.VERTICAL) { areaState.line.setLine(transX0, transY0, transX1, transY1); } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { areaState.line.setLine(transY0, transX0, transY1, transX1); } g2.draw(areaState.line); } } // Check if the item is the last item for the series. // and number of items > 0. We can't draw an area for a single point. if (getPlotArea() && item > 0 && item == (itemCount - 1)) { if (orientation == PlotOrientation.VERTICAL) { // Add the last point (x,0) areaState.area.addPoint((int) transX1, (int) transZero); } else if (orientation == PlotOrientation.HORIZONTAL) { // Add the last point (x,0) areaState.area.addPoint((int) transZero, (int) transX1); } Paint fillPaint = getItemFillPaint(series, item); if (fillPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) fillPaint; GradientPaintTransformer t = new StandardGradientPaintTransformer(); fillPaint = t.transform(gp, areaState.area.getBounds()); } g2.setPaint(fillPaint); g2.fill(areaState.area); // draw an outline around the Area. if (isOutline()) { g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(areaState.area); } } updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation); // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null && hotspot != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url); entities.add(entity); } } }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawYIntervalPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); }//w w w . j a v a 2 s.co m IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null && line != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:nl.vu.nat.jfreechartcustom.XYBlockRenderer.java
/** * Draws the block representing the specified item. * * @param g2 the graphics device./*from w w w .ja va 2 s. c o m*/ * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { boolean bAddEntity = false; double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { z = ((XYZDataset) dataset).getZValue(series, item); } Paint p = this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { // Detect if Rectangle is smaller than 2 by 2 pixels block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setPaint(p); g2.fill(block); g2.setStroke(new BasicStroke(1.0f)); // g2.draw(block); EntityCollection entities = state.getEntityCollection(); if (entities != null && bAddEntity) { addEntity(entities, block, dataset, series, item, 0.0, 0.0); } }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of an {@link XYPlot}, with a {@link NumberAxis} for the * domain axis, a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} to draw the data items. * /* w w w . j a v a 2 s . com*/ * This method is copied from * {@link org.jfree.chart.ChartFactory#createBubbleChart(String, String, String, XYZDataset, PlotOrientation, boolean, boolean, boolean)} * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException(Messages.getString("TopChartFactory.argument")); //$NON-NLS-1$ } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS) { @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double transDomain = 0.0; double transRange = 0.0; double zero; // MOD scorreia +2L avoid points: minimal size of circle must be 1 // z = z * transX + 1; // ADD xqliu 2009-07-06 bug 8035 double zSize = getBubbleSize(z); // calculate the multiple of bubble's default size z = 0; // use bubble's default size // ~ switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero; transRange = transDomain; break; case SCALE_ON_RANGE_AXIS: zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); transDomain = transRange; break; default: double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1; transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); } transDomain = Math.abs(transDomain); transRange = Math.abs(transRange); // MODSCA 2008-11-27 enlarge ellipse by diag% of the total diagonal double diag = Math.sqrt(dataArea.getHeight() * dataArea.getHeight() + dataArea.getWidth() * dataArea.getWidth()); transDomain += diag / 100; transRange += diag / 100; Ellipse2D circle = null; // ADD xqliu 2009-07-06 bug 8035 transDomain *= zSize; transRange *= zSize; // ~ if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // add an entity if this info is being collected EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } } /** * DOC xqliu : calculate the size of bubble. for bug 8035 2009-07-06. * * @param z multiple of bubble's default size * @return */ private double getBubbleSize(double z) { if (z > 0 && z <= 10) { return 2; } else if (z > 10 && z <= 100) { return 3; } else if (z > 100) { return 4; } return 1; } }; if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Decreases the range on the vertical axis, centered about a Java2D y coordinate. * <P>//from ww w . j a v a 2 s. c o m * The range on the y axis is multiplied by zoomFactor * * @param y the y coordinate in Java2D space. * @param zoomFactor the zoomFactor < 1 == zoom in; else out. */ private void zoomVertical(final double y, final double zoomFactor) { final JFreeChart chart = this.chartPanel.getChart(); final ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); // 1. (left) Y-Axis if (chart.getPlot() instanceof XYPlot) { final XYPlot vvp = (XYPlot) chart.getPlot(); final ValueAxis primYAxis = vvp.getRangeAxis(); if (primYAxis != null) { final double anchorValue = primYAxis.java2DToValue((float) y, info.getPlotInfo().getDataArea(), vvp.getRangeAxisEdge()); if (zoomFactor < 1.0) { // zoom in primYAxis.resizeRange(zoomFactor, anchorValue); } else if (zoomFactor > 1.0) { // zoom out final Range range = new Range(this.primYMinMax[0], this.primYMinMax[1]); adjustRange(primYAxis, range, zoomFactor, anchorValue); } } // 2. (right) Y-Axis if (chart.getPlot() instanceof XYPlot) { final XYPlot xyp = (XYPlot) chart.getPlot(); final ValueAxis secYAxis = xyp.getRangeAxis(1); if (secYAxis != null) { final double anchorValue = secYAxis.java2DToValue((float) y, info.getPlotInfo().getDataArea(), xyp.getRangeAxisEdge(1)); if (zoomFactor < 1.0) { // zoom in secYAxis.resizeRange(zoomFactor, anchorValue); } else if (zoomFactor > 1.0) { // zoom out final Range range = new Range(this.secondYMinMax[0], this.secondYMinMax[1]); adjustRange(secYAxis, range, zoomFactor, anchorValue); } } } } }
From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java
/** * Translates the shape so that it displays correctly given the plot and dataArea. * * @param shape the shape to translate * @param plot the plot that will be used to translate the shape * @param dataArea the dataArea that the shape will be translated to * @return The translated shape *//*ww w. jav a2 s .c o m*/ @SuppressWarnings({ "SuspiciousNameCombination" }) protected Ellipse2D.Double translateShape(Ellipse2D.Double shape, XYPlot plot, Rectangle2D dataArea) { Ellipse2D.Double circle = null; //double x = shape.getCenterX(); //double y = shape.getCenterY(); double z = shape.getWidth(); PlotOrientation orientation = plot.getOrientation(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(shape.getX(), dataArea, domainAxisLocation); double transX2 = domainAxis.valueToJava2D(shape.getX() + shape.getWidth(), dataArea, domainAxisLocation); //The upper-left corner is the lower-left on the graph (screen origin vs. graph origin) double transY1 = rangeAxis.valueToJava2D(shape.getY() + shape.getHeight(), dataArea, rangeAxisLocation); double transY2 = rangeAxis.valueToJava2D(shape.getY(), dataArea, rangeAxisLocation); double width = z * domainAxis.getRange().getLength() * domainZoomMultiplier * SIZE_MULTIPLIER; double height = z * rangeAxis.getRange().getLength() * rangeZoomMultiplier * SIZE_MULTIPLIER; double transWidth = domainAxis.lengthToJava2D(width, dataArea, domainAxisLocation);//transX2 - transX1; double transHeight = rangeAxis.lengthToJava2D(height, dataArea, rangeAxisLocation);//transY2 - transY1; double transX = (transX1 + transX2) / 2.0; double transY = (transY1 + transY2) / 2.0; switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: transHeight = transWidth; break; case SCALE_ON_RANGE_AXIS: transWidth = transHeight; break; default: break; } transWidth = Math.abs(transWidth); transHeight = Math.abs(transHeight); if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - transWidth / 2.0, transY - transHeight / 2.0, transWidth, transHeight); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - transHeight / 2.0, transX - transWidth / 2.0, transHeight, transWidth); } return circle; }
From source file:edu.scripps.fl.curves.plot.MyXYErrorRenderer.java
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (pass == 0 && (dataset instanceof IntervalXYDataset) && getItemVisible(series, item)) { IntervalXYDataset ixyd = (IntervalXYDataset) dataset; PlotOrientation orientation = plot.getOrientation(); if (getSeriesXError(series)) { double x0 = ixyd.getStartXValue(series, item); double x1 = ixyd.getEndXValue(series, item); double y = ixyd.getYValue(series, item); org.jfree.ui.RectangleEdge edge = plot.getDomainAxisEdge(); double xx0 = domainAxis.valueToJava2D(x0, dataArea, edge); double xx1 = domainAxis.valueToJava2D(x1, dataArea, edge); double yy = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); Line2D cap1 = null;//from w ww . ja va 2 s .c om Line2D cap2 = null; double adj = capLength / 2D; Line2D line; if (orientation == PlotOrientation.VERTICAL) { line = new java.awt.geom.Line2D.Double(xx0, yy, xx1, yy); cap1 = new java.awt.geom.Line2D.Double(xx0, yy - adj, xx0, yy + adj); cap2 = new java.awt.geom.Line2D.Double(xx1, yy - adj, xx1, yy + adj); } else { line = new java.awt.geom.Line2D.Double(yy, xx0, yy, xx1); cap1 = new java.awt.geom.Line2D.Double(yy - adj, xx0, yy + adj, xx0); cap2 = new java.awt.geom.Line2D.Double(yy - adj, xx1, yy + adj, xx1); } if (errorPaint != null) g2.setPaint(errorPaint); else g2.setPaint(getItemPaint(series, item)); if (errorStroke != null) g2.setStroke(errorStroke); else g2.setStroke(getItemStroke(series, item)); g2.draw(line); g2.draw(cap1); g2.draw(cap2); } if (getSeriesYError(series)) { double y0 = ixyd.getStartYValue(series, item); double y1 = ixyd.getEndYValue(series, item); double x = ixyd.getXValue(series, item); org.jfree.ui.RectangleEdge edge = plot.getRangeAxisEdge(); double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge); double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); Line2D cap1 = null; Line2D cap2 = null; double adj = capLength / 2D; Line2D line; if (orientation == PlotOrientation.VERTICAL) { line = new java.awt.geom.Line2D.Double(xx, yy0, xx, yy1); cap1 = new java.awt.geom.Line2D.Double(xx - adj, yy0, xx + adj, yy0); cap2 = new java.awt.geom.Line2D.Double(xx - adj, yy1, xx + adj, yy1); } else { line = new java.awt.geom.Line2D.Double(yy0, xx, yy1, xx); cap1 = new java.awt.geom.Line2D.Double(yy0, xx - adj, yy0, xx + adj); cap2 = new java.awt.geom.Line2D.Double(yy1, xx - adj, yy1, xx + adj); } if (errorPaint != null) g2.setPaint(errorPaint); else g2.setPaint(getItemPaint(series, item)); if (errorStroke != null) g2.setStroke(errorStroke); else g2.setStroke(getItemStroke(series, item)); g2.draw(line); g2.draw(cap1); g2.draw(cap2); } } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Updates the preselected y-value.//from w w w. j a v a 2s . com */ private void updateYFieldValue() { // update preselected y value because range axis has been changed if (mousePosition != null) { Rectangle2D plotArea = engine.getChartPanel().getScreenDataArea(); if (engine.getChartPanel().getChart().getPlot() instanceof XYPlot) { XYPlot plot = (XYPlot) engine.getChartPanel().getChart().getPlot(); // calculate y value for (int i = 0; i < plot.getRangeAxisCount(); i++) { ValueAxis config = plot.getRangeAxis(i); if (config != null && config.getLabel() != null) { if (config.getLabel() .equals(String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()))) { double chartY = config.java2DToValue(mousePosition.getY(), plotArea, plot.getRangeAxisEdge()); yField.setText(String.valueOf(chartY)); } } } } } }