List of usage examples for org.jfree.chart.plot XYPlot getOrientation
@Override
public PlotOrientation getOrientation()
From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.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) { IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; Paint seriesPaint = getItemPaint(series, item); double value0; double value1; if (getUseYInterval()) { value0 = intervalDataset.getStartYValue(series, item); value1 = intervalDataset.getEndYValue(series, item); } else {// w w w .j a v a2 s. com value0 = getBase(); value1 = intervalDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); double x1 = intervalDataset.getStartXValue(series, item); double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double x2 = intervalDataset.getEndXValue(series, item); double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation); double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1)); double translatedHeight = Math.abs(translatedValue0 - translatedValue1); /* * With BlueDragon, this value is always false so it's safe to comment this * code out. if (this.centerBarAtStartValue) { translatedX1 -= * translatedWidth / 2; } */ PlotOrientation orientation = plot.getOrientation(); if (getMargin() > 0.0) { if (orientation == PlotOrientation.HORIZONTAL) { // BEGIN fix for horizontal bar charts that have a margin double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; translatedX1 = translatedX1 - cut / 2; // END fix for horizontal bar charts that have a margin } else if (orientation == PlotOrientation.VERTICAL) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; translatedX1 = translatedX1 + cut / 2; } } int numSeries = dataset.getSeriesCount(); double seriesBarWidth = translatedWidth / numSeries; Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1), translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth); } else if (orientation == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series, Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight); } g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) { g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(bar); } // TODO: we need something better for the item labels if (isItemLabelVisible(series, item)) { // Change parameters passed to this method to call our local version drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0); } // add an entity for the item... if (info != null) { EntityCollection entities = info.getOwner().getEntityCollection(); if (entities != 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(bar, dataset, series, item, tip, url); entities.add(entity); } } }
From source file:edu.dlnu.liuwenpeng.render.XYLineAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items. Instead of drawing separate lines, * a GeneralPath is constructed and drawn at the end of * the series painting. /*from w w w . j a v a 2 s. c o m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param plot the plot (can be used to obtain standard color information * etc). * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); State s = (State) state; // update path to reflect latest point if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.isLastPointGood()) { s.seriesPath.lineTo(x, y); } else { s.seriesPath.moveTo(x, y); } s.setLastPointGood(true); } else { s.setLastPointGood(false); } // if this is the last item, draw the path ... if (item == dataset.getItemCount(series) - 1) { // draw path drawFirstPassShape(g2, pass, series, item, s.seriesPath); } }
From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device./* www . j a v a 2 s. c om*/ * @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:gov.sandia.umf.platform.ui.jobs.Raster.java
public JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title null, // x axis label null, // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls );/*from ww w . j av a 2 s . c o m*/ chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainPannable(true); plot.setRangePannable(true); plot.setRenderer(new XYDotRenderer() { public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state, java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // Copied from org.jfree.chart.renderer.xy.XYDotRenderer.java and modified. // This would only need to be a couple of lines if they authors of jfreechart had not made dotWidth and dotHeight private members. // Yet another example of textbook OO programming gone awry. (Can anyone hear me scream?) if (!getItemVisible(series, item)) return; int dotWidth = 1; double rasterLines = rangeAxis.getRange().getLength(); int pixels = g2.getClipBounds().height; double height = pixels / rasterLines; if (height > 10) height -= 2; else if (height > 2) height -= 1; int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height))); double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Double.isNaN(y)) return; double adjx = (dotWidth - 1) / 2.0; double adjy = (dotHeight - 1) / 2.0; RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx; double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy; g2.setPaint(Color.black); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth); else g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Integer units only return chart; }
From source file:com.bdb.weather.display.windplot.WindItemRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.//from www . j a va 2 s.c o m * @param rendererState 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. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState rendererState, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // // Let the base class handle drawing the line and the shapes (passes 0 and 1). This class will handle drawing the // wind direction lines. // if (pass < 2) super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); else { if (!(dataset instanceof TimeSeriesCollection) || !showWindDirectionLines) return; if (item == 0) state.resetLastDirection(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); TimeSeriesCollection collection = (TimeSeriesCollection) dataset; TimeSeries timeSeries = collection.getSeries(series); if (!(timeSeries instanceof WindSeries)) return; WindSeries windSeries = (WindSeries) timeSeries; WindSeriesDataItem windItem = windSeries.getWindDataItem(item); double speed = windItem.getWindSpeed().doubleValue(); double time = dataset.getXValue(series, item); double dir = windItem.getWindDirection().doubleValue(); if (speed > 0.0 && dir != state.getLastDirection()) { state.setLastDirection(dir); double radians = Math.toRadians(dir - 90.0); double dirXOffset = directionLineLength * Math.cos(radians); double dirYOffset = directionLineLength * Math.sin(radians); double transTime = domainAxis.valueToJava2D(time, dataArea, xAxisLocation); double transSpeed = rangeAxis.valueToJava2D(speed, dataArea, yAxisLocation); double dirX = transTime + dirXOffset; double dirY = transSpeed + dirYOffset; // update path to reflect latest point if (!Double.isNaN(transTime) && !Double.isNaN(transSpeed)) { int x1 = (int) transTime; int y1 = (int) transSpeed; int x2 = (int) dirX; int y2 = (int) dirY; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x1 = (int) transSpeed; y1 = (int) transTime; x2 = (int) dirY; y2 = (int) dirX; } g2.setPaint(windDirectionPaint); g2.setStroke(windDirectionStroke); g2.drawLine(x1, y1, x2, y2); } } } }
From source file:edu.dlnu.liuwenpeng.render.XYLineAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items. /*from w w w . ja va 2s . co m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @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 pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.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 (!getItemVisible(series, item)) { return;/*ww w. ja v a 2s.c o m*/ } double itemXValue = dataSet.getXValue(series, item); double itemYValue = dataSet.getYValue(series, item); if (Double.isNaN(itemYValue) || Double.isNaN(itemXValue)) { return; } double currentItemX = calculateItemXPoint(series, item, dataArea, domainAxis, dataSet, plot); double currentItemY = calculateItemYPoint(series, item, dataArea, rangeAxis, dataSet, plot); int previousItemIndex = item > 0 ? item - 1 : 0; double previousItemX = calculateItemXPoint(series, previousItemIndex, dataArea, domainAxis, dataSet, plot); double previousItemY = calculateItemYPoint(series, previousItemIndex, dataArea, rangeAxis, dataSet, plot); final int lastItemIndex = dataSet.getItemCount(series) - 1; int nextItemIndex = item < lastItemIndex ? item + 1 : lastItemIndex; double nextItemX = calculateItemXPoint(series, nextItemIndex, dataArea, domainAxis, dataSet, plot); double nextItemY = calculateItemYPoint(series, nextItemIndex, dataArea, rangeAxis, dataSet, plot); double zeroRangePoint = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge()); if (isAreaAndLinePass(pass)) { XYLineFillItemRendererState rendererState = (XYLineFillItemRendererState) state; renderLineArea(g2, info, plot, series, item, rendererState, dataSet, currentItemX, currentItemY, previousItemX, previousItemY, zeroRangePoint); } else if (isShapesAndLabelsPass(pass)) { Shape entityArea = renderShapeAndLabel(g2, dataArea, plot, dataSet, series, item, itemYValue, currentItemX, currentItemY, previousItemX, previousItemY, nextItemX, nextItemY, zeroRangePoint); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, itemXValue, itemYValue, domainAxisIndex, rangeAxisIndex, currentItemX, currentItemY, plot.getOrientation()); EntityCollection entityCollection = state.getEntityCollection(); if (entityCollection != null) { addEntity(entityCollection, entityArea, dataSet, series, item, 0.0, 0.0); } } else { throw new IllegalStateException("Unknown pass: " + pass); } }
From source file:ChartUsingJava.XYSmoothLineAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items.//from w w w .j a v a2 s. com * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @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 pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } Point2D.Double point0 = new Point2D.Double(); Point2D.Double point1 = new Point2D.Double(); Point2D.Double point2 = new Point2D.Double(); Point2D.Double point3 = new Point2D.Double(); if (item == 1) { point0 = null; } else { point0.x = domainAxis.valueToJava2D(dataset.getXValue(series, item - 2), dataArea, xAxisLocation); point0.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item - 2), dataArea, yAxisLocation); } point1.x = transX0; point1.y = transY0; point2.x = transX1; point2.y = transY1; if ((item + 1) == dataset.getItemCount(series)) { point3 = null; } else { point3.x = domainAxis.valueToJava2D(dataset.getXValue(series, item + 1), dataArea, xAxisLocation); point3.y = rangeAxis.valueToJava2D(dataset.getYValue(series, item + 1), dataArea, yAxisLocation); } int steps = ((int) ((point2.x - point1.x) / 0.2) < 30) ? (int) ((point2.x - point1.x) / 0.2) : 30; Point2D.Double[] points = getBezierCurve(point0, point1, point2, point3, 1, steps); for (int i = 1; i < points.length; i++) { transX0 = points[i - 1].x; transY0 = points[i - 1].y; transX1 = points[i].x; transY1 = points[i].y; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } } }
From source file:org.trade.ui.chart.renderer.VolumeBarRenderer.java
/** * Draws the visual representation of a single data item. * //from ww w .ja v a 2 s . c o m * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the plot 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. * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D, * XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, * ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int) */ 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; } VolumeDataset volumeDataset = (VolumeDataset) dataset; VolumeItem volumeItem = (VolumeItem) volumeDataset.getSeries(series).getDataItem(item); if (volumeItem.isSide()) { this.color = Color.GREEN; } else { this.color = Color.RED; } double value0; double value1; if (this.getUseYInterval()) { value0 = volumeDataset.getStartYValue(series, item); value1 = volumeDataset.getEndYValue(series, item); } else { value0 = this.getBase(); value1 = volumeDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } if (value0 <= value1) { if (!rangeAxis.getRange().intersects(value0, value1)) { return; } } else { if (!rangeAxis.getRange().intersects(value1, value0)) { return; } } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); double bottom = Math.min(translatedValue0, translatedValue1); double top = Math.max(translatedValue0, translatedValue1); double startX = volumeItem.getPeriod().getFirstMillisecond(); if (Double.isNaN(startX)) { return; } double endX = volumeItem.getPeriod().getLastMillisecond(); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } // is there an alignment adjustment to be made? if (this.getBarAlignmentFactor() >= 0.0 && this.getBarAlignmentFactor() <= 1.0) { double x = volumeDataset.getXValue(series, item); double interval = endX - startX; startX = x - interval * this.getBarAlignmentFactor(); endX = startX + interval; } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); RectangleEdge domainEdge = plot.getDomainAxisEdge(); double xx = domainAxis.valueToJava2D(startX, dataArea, domainEdge); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; } Rectangle2D bar = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double(bottom, xx, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); bar = new Rectangle2D.Double(xx - (translatedWidth / 2), bottom, translatedWidth, top - bottom); } boolean positive = (value1 > 0.0); boolean inverted = rangeAxis.isInverted(); RectangleEdge barBase; if (orientation == PlotOrientation.HORIZONTAL) { if (positive && inverted || !positive && !inverted) { barBase = RectangleEdge.RIGHT; } else { barBase = RectangleEdge.LEFT; } } else { if (positive && !inverted || !positive && inverted) { barBase = RectangleEdge.BOTTOM; } else { barBase = RectangleEdge.TOP; } } if (getShadowsVisible()) { this.getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !this.getUseYInterval()); } this.getBarPainter().paintBar(g2, this, series, item, bar, barBase); if (isItemLabelVisible(series, item)) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0); } // update the cross hair point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); EntityCollection entities = state.getEntityCollection(); // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, null); entities.add(entity); } }
From source file:edu.dlnu.liuwenpeng.render.NewXYBarRenderer.java
/** * Draws the visual representation of a single data item. * //from w w w. j a v a2 s . c o m * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot 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; } IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double value0; double value1; if (this.useYInterval) { value0 = intervalDataset.getStartYValue(series, item); value1 = intervalDataset.getEndYValue(series, item); } else { value0 = this.base; value1 = intervalDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } if (value0 <= value1) { if (!rangeAxis.getRange().intersects(value0, value1)) { return; } } else { if (!rangeAxis.getRange().intersects(value1, value0)) { return; } } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); double bottom = Math.min(translatedValue0, translatedValue1); double top = Math.max(translatedValue0, translatedValue1); double startX = intervalDataset.getStartXValue(series, item); if (Double.isNaN(startX)) { return; } double endX = intervalDataset.getEndXValue(series, item); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); double left = Math.min(translatedStartX, translatedEndX); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; left = left + cut / 2; } Rectangle2D bar = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double(bottom, left, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); bar = new Rectangle2D.Double(left, bottom, translatedWidth, top - bottom); } /* Paint itemPaint = getItemPaint(series, item); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); */ if (dataset.getYValue(series, item) >= 0) { g2.setPaint(Color.red); } else { g2.setPaint(Color.green); } g2.fill(bar); if (isDrawBarOutline() && Math.abs(translatedEndX - translatedStartX) > 3) { Stroke stroke = getItemOutlineStroke(series, item); Paint paint = getItemOutlinePaint(series, item); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } if (isItemLabelVisible(series, item)) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0); } // update the crosshair point double x1 = (startX + endX) / 2.0; double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); EntityCollection entities = state.getEntityCollection(); if (entities != null) { addEntity(entities, bar, dataset, series, item, 0.0, 0.0); } }