Java Code Examples for org.jfree.chart.plot.XYPlot#getOrientation()

The following examples show how to use org.jfree.chart.plot.XYPlot#getOrientation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractXYItemRenderer.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fills a band between two values on the range axis.  This can be used to
 * color bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the range axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
@Override
public void fillRangeGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double y1 = axis.valueToJava2D(start, dataArea,
            plot.getRangeAxisEdge());
    double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(y1, y2),
            dataArea.getWidth(), Math.abs(y2 - y1));
    }
    else {
        band = new Rectangle2D.Double(Math.min(y1, y2), dataArea.getMinY(),
                Math.abs(y2 - y1), dataArea.getHeight());
    }
    Paint paint = plot.getRangeTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example 2
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fills a band between two values on the range axis.  This can be used to
 * color bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the range axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
@Override
public void fillRangeGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double y1 = axis.valueToJava2D(start, dataArea,
            plot.getRangeAxisEdge());
    double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(y1, y2),
            dataArea.getWidth(), Math.abs(y2 - y1));
    }
    else {
        band = new Rectangle2D.Double(Math.min(y1, y2), dataArea.getMinY(),
                Math.abs(y2 - y1), dataArea.getHeight());
    }
    Paint paint = plot.getRangeTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example 3
Source File: AbstractXYItemRenderer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fills a band between two values on the axis.  This can be used to color
 * bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the domain axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
@Override
public void fillDomainGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double x1 = axis.valueToJava2D(start, dataArea,
            plot.getDomainAxisEdge());
    double x2 = axis.valueToJava2D(end, dataArea,
            plot.getDomainAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(),
                Math.abs(x2 - x1), dataArea.getHeight());
    }
    else {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2),
                dataArea.getWidth(), Math.abs(x2 - x1));
    }
    Paint paint = plot.getDomainTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example 4
Source File: XYStepAreaRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Helper method which returns a value if it lies
 * inside the visible dataArea and otherwise the corresponding
 * coordinate on the border of the dataArea. The PlotOrientation
 * is taken into account.
 * Useful to avoid possible sun.dc.pr.PRException: endPath: bad path
 * which occurs when trying to draw lines/shapes which in large part
 * lie outside of the visible dataArea.
 *
 * @param value the value which shall be
 * @param dataArea  the area within which the data is being drawn.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @return <code>double</code> value inside the data area.
 */
protected static double restrictValueToDataArea(double value,
                                                XYPlot plot,
                                                Rectangle2D dataArea) {
    double min = 0;
    double max = 0;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        min = dataArea.getMinY();
        max = dataArea.getMaxY();
    }
    else if (plot.getOrientation() ==  PlotOrientation.HORIZONTAL) {
        min = dataArea.getMinX();
        max = dataArea.getMaxX();
    }
    if (value < min) {
        value = min;
    }
    else if (value > max) {
        value = max;
    }
    return value;
}
 
Example 5
Source File: XYStepAreaRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper method which returns a value if it lies
 * inside the visible dataArea and otherwise the corresponding
 * coordinate on the border of the dataArea. The PlotOrientation
 * is taken into account.
 * Useful to avoid possible sun.dc.pr.PRException: endPath: bad path
 * which occurs when trying to draw lines/shapes which in large part
 * lie outside of the visible dataArea.
 *
 * @param value the value which shall be
 * @param dataArea  the area within which the data is being drawn.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @return <code>double</code> value inside the data area.
 */
protected static double restrictValueToDataArea(double value,
                                                XYPlot plot,
                                                Rectangle2D dataArea) {
    double min = 0;
    double max = 0;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        min = dataArea.getMinY();
        max = dataArea.getMaxY();
    }
    else if (plot.getOrientation() ==  PlotOrientation.HORIZONTAL) {
        min = dataArea.getMinX();
        max = dataArea.getMaxX();
    }
    if (value < min) {
        value = min;
    }
    else if (value > max) {
        value = max;
    }
    return value;
}
 
Example 6
Source File: CustomXYAreaRenderer.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
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) {
	super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass);

	// The complete area chart is drawn when drawItem() is called for the last
	// item
	// so we need to draw all of the item labels after the last item so they'll
	// be
	// visible if they overlap the area chart.
	int itemCount = dataset.getItemCount(series);
	if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
		// this is the last item so draw the item labels
		PlotOrientation orientation = plot.getOrientation();

		for (int i = 0; i < itemCount; i++) {
			if (isItemLabelVisible(series, i)) {
				double xValue = dataset.getXValue(series, i);
				double yValue = dataset.getYValue(series, i);
				if (Double.isNaN(yValue)) {
					yValue = 0.0;
				}
				double transXValue = domainAxis.valueToJava2D(xValue, dataArea, plot.getDomainAxisEdge());
				double transYValue = rangeAxis.valueToJava2D(yValue, dataArea, plot.getRangeAxisEdge());

				double xx = transXValue;
				double yy = transYValue;
				if (orientation == PlotOrientation.HORIZONTAL) {
					xx = transYValue;
					yy = transXValue;
				}
				drawItemLabel(g2, orientation, dataset, series, i, xx, yy, (yValue < 0.0));
			}
		}
	}
}
 
Example 7
Source File: AbstractXYItemRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a line perpendicular to the domain axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @since 1.0.5
 */
public void drawDomainLine(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, 
            plot.getDomainAxisEdge());
    if (orientation.isHorizontal()) {
        line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(),
                v);
    } else if (orientation.isVertical()) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(line);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example 8
Source File: AbstractXYItemRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
public void drawRangeLine(Graphics2D g2,
                          XYPlot plot,
                          ValueAxis axis,
                          Rectangle2D dataArea,
                          double value,
                          Paint paint,
                          Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example 9
Source File: XYBoxAnnotation.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    double transX0 = domainAxis.valueToJava2D(this.x0, dataArea,
            domainEdge);
    double transY0 = rangeAxis.valueToJava2D(this.y0, dataArea, rangeEdge);
    double transX1 = domainAxis.valueToJava2D(this.x1, dataArea,
            domainEdge);
    double transY1 = rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);

    Rectangle2D box = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        box = new Rectangle2D.Double(transY0, transX1, transY1 - transY0,
                transX0 - transX1);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        box = new Rectangle2D.Double(transX0, transY1, transX1 - transX0,
                transY0 - transY1);
    }

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(box);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(box);
    }
    addEntity(info, box, rendererIndex, getToolTipText(), getURL());

}
 
Example 10
Source File: XYPlotMarker.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void updatePoint(ChartMouseEvent event) {
    if (xyDataset == null
            || xyDataset.getSeriesCount() == 0
            // This situation appears, if the dataset has changed while the overlay is still visible
            || (seriesIndex < 0 || seriesIndex >= xyDataset.getSeriesCount())) {
        if (removeOverlay()) {
            // FIXME - exception here:

            // listener.pointDeselected();

            /*
           Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
               at ProductSceneView.getRaster(ProductSceneView.java:511)
               at ProductSceneView.getProduct(ProductSceneView.java:468)
               at org.esa.snap.visat.toolviews.nav.CursorSynchronizer.removePPL(CursorSynchronizer.java:133)
               at org.esa.snap.visat.toolviews.nav.CursorSynchronizer.clearPsvOverlayMap(CursorSynchronizer.java:116)
               at org.esa.snap.visat.toolviews.nav.CursorSynchronizer.setEnabled(CursorSynchronizer.java:67)
               at org.esa.snap.visat.toolviews.stat.ProfilePlotPanel$3.pointDeselected(ProfilePlotPanel.java:211)
            */
        }
        return;
    }

    addOverlay();

    XYPlot plot = chartPanel.getChart().getXYPlot();

    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    double xView = event.getTrigger().getPoint().x;
    double xData = plot.getDomainAxis().java2DToValue(xView, dataArea, domainEdge);

    int itemCount = xyDataset.getItemCount(seriesIndex);
    for (int i = 0; i < itemCount - 1; i++) {
        double x1 = xyDataset.getXValue(seriesIndex, i);
        double x2 = xyDataset.getXValue(seriesIndex, i + 1);
        if (xData >= x1 && xData <= x2) {
            double y1 = xyDataset.getYValue(seriesIndex, i);
            double y2 = xyDataset.getYValue(seriesIndex, i + 1);
            double yData = y1 + (xData - x1) * (y2 - y1) / (x2 - x1);
            double yView = plot.getRangeAxis().valueToJava2D(yData, dataArea, rangeEdge);
            Point2D.Double viewPoint = new Point2D.Double(xView, yView);
            Point2D.Double dataPoint = new Point2D.Double(xData, yData);
            overlay.setPoint(viewPoint, dataPoint);
            listener.pointSelected(xyDataset, seriesIndex, dataPoint);
            break;
        }
    }
}
 
Example 11
Source File: XYPolygonAnnotation.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    // if we don't have at least 2 (x, y) coordinates, just return
    if (this.polygon.length < 4) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    GeneralPath area = new GeneralPath();
    double x = domainAxis.valueToJava2D(this.polygon[0], dataArea,
            domainEdge);
    double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea,
            rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        area.moveTo((float) y, (float) x);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea,
                    domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea,
                    rangeEdge);
            area.lineTo((float) y, (float) x);
        }
        area.closePath();
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        area.moveTo((float) x, (float) y);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea,
                    domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea,
                    rangeEdge);
            area.lineTo((float) x, (float) y);
        }
        area.closePath();
   }


    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(area);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(area);
    }
    addEntity(info, area, rendererIndex, getToolTipText(), getURL());

}
 
Example 12
Source File: XYBoxAnnotation.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex, PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    double transX0 = domainAxis.valueToJava2D(this.x0, dataArea,
            domainEdge);
    double transY0 = rangeAxis.valueToJava2D(this.y0, dataArea, rangeEdge);
    double transX1 = domainAxis.valueToJava2D(this.x1, dataArea,
            domainEdge);
    double transY1 = rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge);

    Rectangle2D box = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        box = new Rectangle2D.Double(transY0, transX1, transY1 - transY0,
                transX0 - transX1);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        box = new Rectangle2D.Double(transX0, transY1, transX1 - transX0,
                transY0 - transY1);
    }

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(box);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(box);
    }
    addEntity(info, box, rendererIndex, getToolTipText(), getURL());

}
 
Example 13
Source File: YIntervalRenderer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @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 (ignored here).
 */
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...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    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;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);

    g2.fill(top);
    g2.fill(bottom);

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0,
                0.0);
    }

}
 
Example 14
Source File: XYPointerAnnotation.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
        ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, 
        PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);
    double j2DX = domainAxis.valueToJava2D(getX(), dataArea, domainEdge);
    double j2DY = rangeAxis.valueToJava2D(getY(), dataArea, rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        double temp = j2DX;
        j2DX = j2DY;
        j2DY = temp;
    }
    double startX = j2DX + Math.cos(this.angle) * this.baseRadius;
    double startY = j2DY + Math.sin(this.angle) * this.baseRadius;

    double endX = j2DX + Math.cos(this.angle) * this.tipRadius;
    double endY = j2DY + Math.sin(this.angle) * this.tipRadius;

    double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength;
    double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength;

    double arrowLeftX = arrowBaseX
            + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowLeftY = arrowBaseY
            + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    double arrowRightX = arrowBaseX
            - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth;
    double arrowRightY = arrowBaseY
            - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth;

    GeneralPath arrow = new GeneralPath();
    arrow.moveTo((float) endX, (float) endY);
    arrow.lineTo((float) arrowLeftX, (float) arrowLeftY);
    arrow.lineTo((float) arrowRightX, (float) arrowRightY);
    arrow.closePath();

    g2.setStroke(this.arrowStroke);
    g2.setPaint(this.arrowPaint);
    Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY);
    g2.draw(line);
    g2.fill(arrow);

    // draw the label
    double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius
            + this.labelOffset);
    double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius
            + this.labelOffset);
    g2.setFont(getFont());
    Shape hotspot = TextUtilities.calculateRotatedStringBounds(
            getText(), g2, (float) labelX, (float) labelY, getTextAnchor(),
            getRotationAngle(), getRotationAnchor());
    if (getBackgroundPaint() != null) {
        g2.setPaint(getBackgroundPaint());
        g2.fill(hotspot);
    }
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, (float) labelX,
            (float) labelY, getTextAnchor(), getRotationAngle(),
            getRotationAnchor());
    if (isOutlineVisible()) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(hotspot);
    }

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, hotspot, rendererIndex, toolTip, url);
    }

}
 
Example 15
Source File: XYShapeRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the block representing the specified item.
 *
 * @param g2  the graphics device.
 * @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.
 */
@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) {

    Shape hotspot;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    if (Double.isNaN(x) || Double.isNaN(y)) {
        // can't draw anything
        return;
    }

    double transX = domainAxis.valueToJava2D(x, dataArea,
            plot.getDomainAxisEdge());
    double transY = rangeAxis.valueToJava2D(y, dataArea,
            plot.getRangeAxisEdge());

    PlotOrientation orientation = plot.getOrientation();

    // draw optional guide lines
    if ((pass == 0) && this.guideLinesVisible) {
        g2.setStroke(this.guideLineStroke);
        g2.setPaint(this.guideLinePaint);
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transX,
                    dataArea.getMaxX(), transX));
        }
        else {
            g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX,
                    dataArea.getMaxY()));
            g2.draw(new Line2D.Double(dataArea.getMinX(), transY,
                    dataArea.getMaxX(), transY));
        }
    }
    else if (pass == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY,
                    transX);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX,
                    transY);
        }
        hotspot = shape;
        if (shape.intersects(dataArea)) {
            //if (getItemShapeFilled(series, item)) {
                g2.setPaint(getPaint(dataset, series, item));
                g2.fill(shape);
           //}
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }

        // add an entity for the item...
        if (entities != null) {
            addEntity(entities, hotspot, dataset, series, item, transX,
                    transY);
        }
    }
}
 
Example 16
Source File: XYShapeAnnotation.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex,
                 PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.shape.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;

    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;

    //  create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f,
                0.0f, 0.0f);
        AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00,
                m12, m02);
        s = t1.createTransformedShape(this.shape);
        s = t2.createTransformedShape(s);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
        s = t.createTransformedShape(this.shape);
    }

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(s);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(s);
    }
    addEntity(info, s, rendererIndex, getToolTipText(), getURL());

}
 
Example 17
Source File: XYImageAnnotation.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex,
                 PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge
        = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge
        = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    float j2DX
        = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
    float j2DY
        = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    int w = this.image.getWidth(null);
    int h = this.image.getHeight(null);

    Rectangle2D imageRect = new Rectangle2D.Double(0, 0, w, h);
    Point2D anchorPoint = RectangleAnchor.coordinates(imageRect,
            this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    g2.drawImage(this.image, (int) xx, (int) yy, null);

    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, new Rectangle2D.Float(xx, yy, w, h), rendererIndex,
                toolTip, url);
    }
}
 
Example 18
Source File: YIntervalRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @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 (ignored here).
 */
@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) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    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;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    } else {
        throw new IllegalStateException();
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);

    g2.fill(top);
    g2.fill(bottom);

    // for item labels, we have a special case because there is the
    // possibility to draw (a) the regular item label near to just the
    // upper y-value, or (b) the regular item label near the upper y-value
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yyHigh,
                false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item,
                xx, yyLow);
    }

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0,
                0.0);
    }

}
 
Example 19
Source File: XYLineAndShapeRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the item shapes and adds chart entities (second pass). This method
 * draws the shapes which mark the item positions. If <code>entities</code>
 * is not <code>null</code> it will be populated with entity information
 * for points that fall within the data area.
 *
 * @param g2  the graphics device.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param dataArea  the area within which the data is being drawn.
 * @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).
 * @param crosshairState  the crosshair state.
 * @param entities the entity collection.
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, 
        XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis,
        CrosshairState crosshairState, EntityCollection entities) {

    Shape entityArea = null;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    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);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.fill(shape);
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                }
                else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
                (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
            rangeAxisIndex, transX1, transY1, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}
 
Example 20
Source File: XYShapeAnnotation.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the annotation.  This method is usually called by the
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis,
                 int rendererIndex,
                 PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.shape.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
    double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;

    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
    double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;

    //  create transform & transform shape
    Shape s = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f,
                0.0f, 0.0f);
        AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00,
                m12, m02);
        s = t1.createTransformedShape(this.shape);
        s = t2.createTransformedShape(s);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
        s = t.createTransformedShape(this.shape);
    }

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(s);
    }

    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(s);
    }
    addEntity(info, s, rendererIndex, getToolTipText(), getURL());

}