List of usage examples for org.jfree.chart ChartPanel getScreenDataArea
public Rectangle2D getScreenDataArea()
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.MultiAxesCrosshairOverlay.java
@Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea);//from www. ja v a 2 s. c om JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); Iterator iterator = this.getDomainCrosshairs().iterator(); while (iterator.hasNext()) { Crosshair ch = (Crosshair) iterator.next(); if (ch.isVisible()) { double x = ch.getValue(); double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge); if (plot.getOrientation() == PlotOrientation.VERTICAL) { drawVerticalCrosshair(g2, dataArea, xx, ch); } else { drawHorizontalCrosshair(g2, dataArea, xx, ch); } } } int rangeAxisIdx = 0; for (ArrayList<Crosshair> crosshairsForRange : rangeCrosshairs) { ValueAxis yAxis = plot.getRangeAxis(rangeAxisIdx); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(rangeAxisIdx); iterator = crosshairsForRange.iterator(); while (iterator.hasNext()) { Crosshair ch = (Crosshair) iterator.next(); if (ch.isVisible()) { double y = ch.getValue(); double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge); if (plot.getOrientation() == PlotOrientation.VERTICAL) { drawHorizontalCrosshair(g2, dataArea, yy, ch); } else { drawVerticalCrosshair(g2, dataArea, yy, ch); } } } g2.setClip(savedClip); ++rangeAxisIdx; } }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java
/** * * @param g2// ww w . ja v a 2 s . c o m * @param chartPanel */ @Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (isVisible()) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); 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))) { Logger.getLogger(getClass().getName()) .info("Peak annotation color was null or white, using color from treatment group!"); fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor(); } g2.setColor(ChartCustomizer.withAlpha(fillColor, 0.5f)); for (IPeakAnnotationDescriptor descr : peakAnnotations.getMembers()) { double x = descr.getApexTime(); double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge); double width = xAxis.valueToJava2D(1, dataArea, xAxisEdge); double mzRange = (descr.getMassValues()[descr.getMassValues().length - 1] - descr.getMassValues()[0]); double y = mzRange / 2.0d; double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge); double height = yAxis.valueToJava2D(mzRange, dataArea, yAxisEdge); AffineTransform at = AffineTransform.getTranslateInstance(xx, yy); at.concatenate(AffineTransform.getTranslateInstance(-x, -y)); Rectangle2D.Double r = new Rectangle2D.Double(xx - (width / 2.0d), yy, width, height); g2.fill(at.createTransformedShape(r)); } g2.setColor(c); g2.setClip(savedClip); } }
From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java
/** * * @param g2//from ww w .j a v a 2 s. com * @param chartPanel */ @Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (visible) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); paint(g2, plot, dataArea, xAxis, yAxis, plot.getDomainAxisEdge(), plot.getRangeAxisEdge(), chartPanel); g2.setClip(savedClip); } }
From source file:vteaexploration.plotgatetools.gates.PolygonGate.java
@Override public void createInChartSpace(ChartPanel chart) { int[] x1Points = new int[vertices.size()]; int[] y1Points = new int[vertices.size()]; double xChartPoint; double yChartPoint; for (int i = 0; i <= vertices.size() - 1; i++) { x1Points[i] = (int) ((Point2D) vertices.get(i)).getX(); y1Points[i] = (int) ((Point2D) vertices.get(i)).getY(); }/*from w ww . j a v a 2 s.c o m*/ for (int index = 0; index < x1Points.length; index++) { Rectangle2D plotArea = chart.getScreenDataArea(); XYPlot plot = (XYPlot) chart.getChart().getPlot(); xChartPoint = plot.getDomainAxis().java2DToValue(x1Points[index], plotArea, plot.getDomainAxisEdge()); yChartPoint = plot.getRangeAxis().java2DToValue(y1Points[index], plotArea, plot.getRangeAxisEdge()); this.verticesInChartSpace.add(new Point2D.Double(xChartPoint, yChartPoint)); } }
From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, ChartPanel chartPanel, boolean scale) { if (entity != null) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();//from w w w .ja v a 2s . c o m Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; if (scale) { transformed = scaleAtOrigin(entity, hoverScaleX, hoverScaleY).createTransformedShape(entity); } transformed = getTranslateInstance( entity.getBounds2D().getCenterX() - transformed.getBounds2D().getCenterX(), entity.getBounds2D().getCenterY() - transformed.getBounds2D().getCenterY()) .createTransformedShape(transformed); g2.setComposite(getInstance(AlphaComposite.SRC_OVER, fillAlpha)); g2.fill(transformed); g2.setColor(Color.DARK_GRAY); g2.draw(transformed); g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();//from w ww . j a v a 2 s .co m Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; FlatteningPathIterator iter = new FlatteningPathIterator( transformed.getPathIterator(new AffineTransform()), 1); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();//from w w w . ja v a2 s. c om Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Rectangle2D entityBounds = entity.getBounds2D(); double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge); double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge); double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge); double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge); PlotOrientation orientation = plot.getOrientation(); //transform model to origin (0,0) in model coordinates AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(), -entityBounds.getCenterY()); //transform from origin (0,0) to model location AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(), entityBounds.getCenterY()); //transform from model scale to view scale double scaleX = viewW / entityBounds.getWidth(); double scaleY = viewH / entityBounds.getHeight(); Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}", new Object[] { scaleX, scaleY }); AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY); AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f); AffineTransform modelToView = new AffineTransform(toOrigin); modelToView.preConcatenate(flipTransform); modelToView.preConcatenate(toViewScale); modelToView.preConcatenate(toViewLocation); // // if (orientation == PlotOrientation.HORIZONTAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewY, // viewX); // } else if (orientation == PlotOrientation.VERTICAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewX, // viewY); // } FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity) .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
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 . ja v a 2 s. 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:velocitekProStartAnalyzer.MainWindow.java
private void createChartPanel() { XYSeriesCollection dataset = JDBCPointDao.dataSet; JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart, true, false, false, true, false); chartPanel.setMinimumDrawWidth(0);//from w w w . j a v a 2 s . co m chartPanel.setMinimumDrawHeight(0); chartPanel.setMaximumDrawWidth(1920); chartPanel.setMaximumDrawHeight(1200); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(btnAvgSpeedChart); chartPanel.getPopupMenu().add(btnMedianSpeedChart); chartPanel.getPopupMenu().add(btnResetSpeedChart); chartPanel.getPopupMenu().addSeparator(); btnMenuSaveSubmenuForChart = new JMenu("Save"); chartPanel.getPopupMenu().add(btnMenuSaveSubmenuForChart); if (JDBCPointDao.points.isEmpty()) { btnSaveAsVCC.setEnabled(false); } saveChartAsPng(chartPanel); btnMenuSaveSubmenuForChart.add(btnSaveChartAsPngForChart); btnMenuSaveSubmenuForChart.add(btnSaveTableAsPngForChart); btnMenuSaveSubmenuForChart.add(btnSaveMapAsPngForChart); btnMenuSaveSubmenuForChart.addSeparator(); btnMenuSaveSubmenuForChart.add(btnSaveAsVCC); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } x = Math.round(x); if (SwingUtilities.isLeftMouseButton(event.getTrigger()) && event.getTrigger().isShiftDown()) { for (PointDto cord : JDBCPointDao.points) { { if (cord.getPointID() == x) { if (pointTable.getSelectionModel() == null) { for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.setRowSelectionInterval(i, i); } } } else { for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.addRowSelectionInterval(pointTable.getSelectedRow(), i); } } } pointTable.scrollRectToVisible( pointTable.getCellRect(pointTable.getSelectedRow(), 0, true)); } } } } else { for (PointDto cord : JDBCPointDao.points) { { if (cord.getPointID() == x) { if (pointTable.getSelectionModel() != null) { pointTable.getSelectionModel().clearSelection(); } for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.setRowSelectionInterval(i, i); } } pointTable.scrollRectToVisible( pointTable.getCellRect(pointTable.getSelectedRow(), 0, true)); //MainWindow.pointTable.revalidate(); } } } } } @Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x); xCrosshair.setValue(x); yCrosshair.setValue(y); x = Math.round(x); for (PointDto cord : JDBCPointDao.points) { if (cord.getPointID() == x) { mapPanel.map().removeMapMarker(mapPanel.getMapPoint()); mapPanel.setMapPoint( new MapMarkerDot(null, null, cord.getPointLatidude(), cord.getPointLongtidude())); mapPanel.setMapPoint(mapPanel.getMapPoint()); mapPanel.getMapPoint().setColor(colorMapMarkerCircle); mapPanel.getMapPoint().setBackColor(colorMapMarkerHover); mapPanel.map().addMapMarker(mapPanel.getMapPoint()); } } } }); XYPlot xyPlot = (XYPlot) chart.getPlot(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); NavigableMap<Double, PointDto> pointDtoSortedSpeedMap = new TreeMap<Double, PointDto>(); if (!JDBCPointDao.points.isEmpty()) { for (PointDto pointDto : JDBCPointDao.points) { pointDtoSortedSpeedMap.put(pointDto.getPointSpeed(), pointDto); } rangeAxis.setRange(pointDtoSortedSpeedMap.firstEntry().getKey() - 0.1, pointDtoSortedSpeedMap.lastEntry().getKey() + 0.1); } CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); chartPanel.addOverlay(crosshairOverlay); graphPanel.removeAll(); graphPanel.add(chartPanel, BorderLayout.CENTER); graphPanel.revalidate(); graphPanel.repaint(); graphMapSplitPanel.revalidate(); }