List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Applies any scaling that is in effect for the chart drawing to the given rectangle. * /*from w w w. j a va2 s .c o m*/ * @param rect * the rectangle. * @return A new scaled rectangle. */ public Rectangle2D scale(Rectangle2D rect) { Insets insets = getInsets(); double x = rect.getX() * getScaleX() + insets.left; double y = rect.getY() * this.getScaleY() + insets.top; double w = rect.getWidth() * this.getScaleX(); double h = rect.getHeight() * this.getScaleY(); return new Rectangle2D.Double(x, y, w, h); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Returns the data area for the chart (the area inside the axes) with the current scaling * applied (that is, the area as it appears on screen). * /*from w ww . j a v a 2 s . c om*/ * @return The scaled data area. */ public Rectangle2D getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Insets insets = getInsets(); double x = dataArea.getX() * this.scaleX + insets.left; double y = dataArea.getY() * this.scaleY + insets.top; double w = dataArea.getWidth() * this.scaleX; double h = dataArea.getHeight() * this.scaleY; return new Rectangle2D.Double(x, y, w, h); }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Applies any scaling that is in effect for the chart drawing to the * given rectangle.//from w ww .j a v a 2s . c o m * * @param rect the rectangle (<code>null</code> not permitted). * * @return A new scaled rectangle. */ public Rectangle2D scale(Rectangle2D rect) { Insets insets = getInsets(); double x = rect.getX() * getScaleX() + insets.left; double y = rect.getY() * getScaleY() + insets.top; double w = rect.getWidth() * getScaleX(); double h = rect.getHeight() * getScaleY(); return new Rectangle2D.Double(x, y, w, h); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, but allowing for the * insets (which will be non-zero if a border has been set for this component). To increase * performance (at the expense of memory), an off-screen buffer image can be used. * //from w w w. j ava 2 s .co m * @param g * the graphics device for drawing on. */ public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = new BufferedImage(this.chartBufferWidth, this.chartBufferHeight, BufferedImage.TYPE_INT_RGB); //this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); -by Max // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; } // do we need to redraw the buffer? if (this.refreshBuffer) { Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } this.refreshBuffer = false; } // zap the buffer onto the panel... g2.drawImage(this.chartBuffer, insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); } // Redraw the zoom rectangle (if present) drawZoomRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Zooms in on a selected region.//from w w w .ja va2 s .c o m * * @param selection * the selected region. */ public void zoom(Rectangle2D selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D( new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) { double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight(); double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight(); Plot p = this.chart.getPlot(); if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin); } else { z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } } } }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *///from w w w . ja v a 2 s. c om public void paintComponent(Graphics g) { super.paintComponent(g); if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if (this.useBuffer) { // if buffer is being refreshed, it needs clearing unless it is // new - use the following flag to track this... boolean clearBuffer = true; // do we need to resize the buffer? if ((this.chartBuffer == null) || (this.chartBufferWidth != available.getWidth()) || (this.chartBufferHeight != available.getHeight())) { this.chartBufferWidth = (int) available.getWidth(); this.chartBufferHeight = (int) available.getHeight(); this.chartBuffer = createImage(this.chartBufferWidth, this.chartBufferHeight); // GraphicsConfiguration gc = g2.getDeviceConfiguration(); // this.chartBuffer = gc.createCompatibleImage( // this.chartBufferWidth, this.chartBufferHeight, // Transparency.TRANSLUCENT); this.refreshBuffer = true; clearBuffer = false; // buffer is new, no clearing required } // do we need to redraw the buffer? if (this.refreshBuffer) { this.refreshBuffer = false; // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, this.chartBufferWidth, this.chartBufferHeight); Graphics2D bufferG2 = (Graphics2D) this.chartBuffer.getGraphics(); if (clearBuffer) { bufferG2.clearRect(0, 0, this.chartBufferWidth, this.chartBufferHeight); } if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); bufferG2.transform(st); this.chart.draw(bufferG2, chartArea, this.anchor, this.info); bufferG2.setTransform(saved); } else { this.chart.draw(bufferG2, bufferArea, this.anchor, this.info); } } // zap the buffer onto the panel... g2.drawImage(this.chartBuffer, insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); } // Redraw the zoom rectangle (if present) drawZoomRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) { // g2.setPaint(Color.white); // g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight())); // if (getChart() != null) { //// Image chartImage = getChart().createBufferedImage((int) area.getWidth(), //// (int) area.getHeight()); //// g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), //// this); // getChart().draw(g2, area, getAnchor(), null); // ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, // null, getChart()); // }//w w w .j a v a 2s. co m double widthRatio = area.getWidth() / getWidth(); double heightRatio = area.getHeight() / getHeight(); double overallRatio = 1; overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio; XYPlot plot = (XYPlot) getChart().getPlot(); Font domainFont = plot.getDomainAxis().getLabelFont(); int domainSize = domainFont.getSize(); Font rangeFont = plot.getRangeAxis().getLabelFont(); int rangeSize = rangeFont.getSize(); TextTitle titleBlock = getChart().getTitle(); Font titleFont = null; int titleSize = 0; if (titleBlock != null) { titleFont = titleBlock.getFont(); titleSize = titleFont.getSize(); getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio))); } Font domainScaleFont = plot.getDomainAxis().getTickLabelFont(); int domainScaleSize = domainScaleFont.getSize(); Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont(); int rangeScaleSize = rangeScaleFont.getSize(); plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio))); plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio))); plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio))); plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio))); LegendTitle legend = getChart().getLegend(); Font legendFont = null; int legendFontSize = 0; if (legend != null) { legendFont = legend.getItemFont(); legendFontSize = legendFont.getSize(); legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio))); } Rectangle2D chartArea = (Rectangle2D) area.clone(); getChart().getPadding().trim(chartArea); if (titleBlock != null) { AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition()); } Axis scaleAxis = null; Font scaleAxisFont = null; int scaleAxisFontSize = 0; for (Object object : getChart().getSubtitles()) { Title title = (Title) object; if (title instanceof PaintScaleLegend) { scaleAxis = ((PaintScaleLegend) title).getAxis(); scaleAxisFont = scaleAxis.getTickLabelFont(); scaleAxisFontSize = scaleAxisFont.getSize(); scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio))); } AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition()); } AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea); Rectangle2D dataArea = axisSpace.shrink(chartArea, null); getChart().getXYPlot().getInsets().trim(dataArea); getChart().getXYPlot().getAxisOffset().trim(dataArea); // Rectangle2D screenArea = getScreenDataArea(); // Rectangle2D visibleArea = getVisibleRect(); // Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, // screenArea.getMinY() * overallRatio + y, // printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), // printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight()); getChart().draw(g2, area, getAnchor(), null); ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio); ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart()); ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart()); plot.getDomainAxis().setLabelFont(domainFont); plot.getRangeAxis().setLabelFont(rangeFont); if (titleBlock != null) { titleBlock.setFont(titleFont); } if (legend != null) { legend.setItemFont(legendFont); } plot.getDomainAxis().setTickLabelFont(domainScaleFont); plot.getRangeAxis().setTickLabelFont(rangeScaleFont); if (scaleAxis != null) { scaleAxis.setTickLabelFont(scaleAxisFont); } // System.out.println("print " + titleBlock.getText() + // " at [" + area.getX() + ", " + area.getY() + ", " + // area.getWidth() + ", " + area.getHeight() + "]"); }
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. * //from w ww .j a va 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:com.isti.traceview.common.TraceViewChartPanel.java
/** * Handles a 'mouse released' event. On Windows, we need to check if this is a popup trigger, * but only if we haven't already been tracking a zoom rectangle. * /*from w ww .j a v a 2 s . c o m*/ * @param e * information about the event. */ public void mouseReleased(MouseEvent e) { if (this.zoomRectangle != null) { boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance; if (zoomTrigger1 || zoomTrigger2) { if ((hZoom && (e.getX() < this.zoomPoint.getX())) || (vZoom && (e.getY() < this.zoomPoint.getY()))) { restoreAutoBounds(); } else { double x, y, w, h; Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY()); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { x = this.zoomPoint.getX(); y = screenDataArea.getMinY(); w = Math.min(this.zoomRectangle.getWidth(), screenDataArea.getMaxX() - this.zoomPoint.getX()); h = screenDataArea.getHeight(); } else if (!hZoom) { x = screenDataArea.getMinX(); y = this.zoomPoint.getY(); w = screenDataArea.getWidth(); h = Math.min(this.zoomRectangle.getHeight(), screenDataArea.getMaxY() - this.zoomPoint.getY()); } else { x = this.zoomPoint.getX(); y = this.zoomPoint.getY(); w = Math.min(this.zoomRectangle.getWidth(), screenDataArea.getMaxX() - this.zoomPoint.getX()); h = Math.min(this.zoomRectangle.getHeight(), screenDataArea.getMaxY() - this.zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { // Erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); drawZoomRectangle(g2); g2.dispose(); this.zoomPoint = null; this.zoomRectangle = null; } } else if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Zooms in on a selected region./* w w w . j ava 2s.c o m*/ * * @param selection the selected region. */ public void zoom(Rectangle2D selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D( new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) { double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight(); double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight(); Plot p = this.chart.getPlot(); if (p instanceof Zoomable) { // save previous ranges for use later when zooming out if (p instanceof XYPlot && rangeHistory.empty()) { XYPlot xyPlot = (XYPlot) p; rangeHistory.push(xyPlot.getDomainAxis().getRange()); rangeHistory.push(xyPlot.getRangeAxis().getRange()); } Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin); } else { z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } // save current ranges for use later when zooming out if (p instanceof XYPlot) { XYPlot xyPlot = (XYPlot) p; rangeHistory.push(xyPlot.getDomainAxis().getRange()); rangeHistory.push(xyPlot.getRangeAxis().getRange()); } } } }