List of usage examples for org.jfree.chart.plot XYPlot draw
@Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info)
From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java
/** * @param observationCollection// ww w . ja va 2 s. c o m * @param screenW * @param screenH * @param bbox * @param selectedFeatures * the Features of Interest for which a chart shall be renderered. */ public StaticVisualization renderLayer(OXFFeatureCollection observationCollection, ParameterContainer paramCon, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures) { if (selectedFeaturesCache == null) { selectedFeaturesCache = selectedFeatures; } // before starting to render --> run garbageCollection Runtime.getRuntime().gc(); LOGGER.info("Garbage Collection done."); // -- String[] observedProperties; // which observedProperty has been used?: ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty"); if (observedPropertyPS.hasMultipleSpecifiedValues()) { observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class); } else if (observedPropertyPS.hasSingleSpecifiedValue()) { observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() }; } else { throw new IllegalArgumentException("no observedProperties found."); } // find tuples: if (obsValues4FOI == null) { obsValues4FOI = new ObservationSeriesCollection(observationCollection, selectedFeaturesCache, observedProperties, true); } ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); g.setColor(Color.BLACK); for (OXFFeature chartFeature : selectedFeaturesCache) { // // CACHING: create Plot for each "chart feature" and add it to the cache: // if (!chartCache.containsKey(chartFeature)) { Map<ITimePosition, ObservedValueTuple> timeMap = obsValues4FOI.getAllTuples(chartFeature); // draw a chart if there are tuples for the chartFeature available: if (timeMap != null) { XYPlot chart = drawChart4FOI(chartFeature.getID(), timeMap); chartCache.put(chartFeature, chart); } } // // draw the plots (which are in the cache): // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); XYPlot cachedPlot = (XYPlot) chartCache.get(chartFeature); // if there is a plot in the cache for the chartFeature -> draw it: if (cachedPlot != null) { cachedPlot.getRangeAxis().setRange((Double) obsValues4FOI.getMinimum(0), (Double) obsValues4FOI.getMaximum(0)); cachedPlot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT), null, null, null); } else { g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); } return new StaticVisualization(image); }
From source file:org.jfree.chart.plot.StackedXYPlot.java
/** * Draws the plot.//from www .j a v a 2 s. c o m * @param graphics2d the graphics device. * @param plotArea the plot plotArea (in Java2D space). * @param anchor an anchor point in Java2D space (<code>null</code> permitted). * @param parentState the state from the parent plot (<code>null</code> permitted). * @param plotRenderingInfo chart drawing information (<code>null</code> permitted). */ @Override public void draw(Graphics2D graphics2d, Rectangle2D plotArea, Point2D anchor, PlotState parentState, PlotRenderingInfo plotRenderingInfo) { if (plotRenderingInfo != null) { plotRenderingInfo.setPlotArea(plotArea); } RectangleInsets insets = getInsets(); insets.trim(plotArea); setFixedRangeAxisSpaceForSubplots(null); //calculateAxisSpace will also calculate sub-plot plotArea AxisSpace space = calculateAxisSpace(graphics2d, plotArea); Rectangle2D dataArea = space.shrink(plotArea, null); Rectangle2D[] calculatedSubPlotAreas = null; //get subplotsAreas from parent class try { calculatedSubPlotAreas = (Rectangle2D[]) FieldUtils.readField(this, "subplotAreas", true); } catch (IllegalAccessException ex) { Logger.getLogger(StackedXYPlot.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); } setFixedRangeAxisSpaceForSubplots(space); // draw all the subplots for (int i = 0; i < getSubplots().size(); i++) { XYPlot plot = (XYPlot) getSubplots().get(i); PlotRenderingInfo subplotInfo = null; if (plotRenderingInfo != null) { subplotInfo = new PlotRenderingInfo(plotRenderingInfo.getOwner()); plotRenderingInfo.addSubplotInfo(subplotInfo); } plot.draw(graphics2d, calculatedSubPlotAreas[i], anchor, parentState, subplotInfo); } if (plotRenderingInfo != null) { plotRenderingInfo.setDataArea(dataArea); } }