Java Code Examples for org.jfree.chart.plot.PlotOrientation#VERTICAL

The following examples show how to use org.jfree.chart.plot.PlotOrientation#VERTICAL . 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: Elixir_000_t.java    From coming with MIT License 6 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 (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot 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 2
Source File: Cardumen_000_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Calculates the (x, y) coordinates for drawing the label for a marker on
 * the range axis.
 *
 * @param g2  the graphics device.
 * @param orientation  the plot orientation.
 * @param dataArea  the data area.
 * @param markerArea  the rectangle surrounding the marker.
 * @param markerOffset  the marker offset.
 * @param labelOffsetType  the label offset type.
 * @param anchor  the label anchor.
 *
 * @return The coordinates for drawing the marker label.
 */
protected Point2D calculateDomainMarkerTextAnchorPoint(Graphics2D g2,
                                  PlotOrientation orientation,
                                  Rectangle2D dataArea,
                                  Rectangle2D markerArea,
                                  RectangleInsets markerOffset,
                                  LengthAdjustmentType labelOffsetType,
                                  RectangleAnchor anchor) {

    Rectangle2D anchorRect = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                LengthAdjustmentType.CONTRACT, labelOffsetType);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorRect = markerOffset.createAdjustedRectangle(markerArea,
                labelOffsetType, LengthAdjustmentType.CONTRACT);
    }
    return RectangleAnchor.coordinates(anchorRect, anchor);

}
 
Example 3
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 4
Source File: Elixir_000_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Adds an entity to the collection.
 *
 * @param entities  the entity collection being populated.
 * @param hotspot  the entity area (if <code>null</code> a default will be
 *              used).
 * @param dataset  the dataset.
 * @param row  the series.
 * @param column  the item.
 * @param selected  is the item selected?
 * @param entityX  the entity's center x-coordinate in user space (only
 *                 used if <code>area</code> is <code>null</code>).
 * @param entityY  the entity's center y-coordinate in user space (only
 *                 used if <code>area</code> is <code>null</code>).
 *
 * @since 1.2.0
 */
protected void addEntity(EntityCollection entities, Shape hotspot,
        CategoryDataset dataset, int row, int column, boolean selected,
        double entityX, double entityY) {
    if (!getItemCreateEntity(row, column, selected)) {
        return;
    }
    Shape s = hotspot;
    if (hotspot == null) {
        double r = getDefaultEntityRadius();
        double w = r * 2;
        if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
            s = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
        }
        else {
            s = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
        }
    }
    String tip = null;
    CategoryToolTipGenerator generator = getToolTipGenerator(row, column,
            selected);
    if (generator != null) {
        tip = generator.generateToolTip(dataset, row, column);
    }
    String url = null;
    CategoryURLGenerator urlster = getURLGenerator(row, column, selected);
    if (urlster != null) {
        url = urlster.generateURL(dataset, row, column);
    }
    CategoryItemEntity entity = new CategoryItemEntity(s, tip, url,
            dataset, dataset.getRowKey(row), dataset.getColumnKey(column));
    entities.add(entity);
}
 
Example 5
Source File: AbstractXYItemRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a grid line against 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.
 */
@Override
public void drawDomainGridLine(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value) {

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

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

    Paint paint = plot.getDomainGridlinePaint();
    Stroke stroke = plot.getDomainGridlineStroke();
    g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
    g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_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 6
Source File: patch1-Chart-1-jMutRepair_patch1-Chart-1-jMutRepair_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Adds an entity to the collection.
 *
 * @param entities  the entity collection being populated.
 * @param hotspot  the entity area (if <code>null</code> a default will be
 *              used).
 * @param dataset  the dataset.
 * @param row  the series.
 * @param column  the item.
 * @param selected  is the item selected?
 * @param entityX  the entity's center x-coordinate in user space (only
 *                 used if <code>area</code> is <code>null</code>).
 * @param entityY  the entity's center y-coordinate in user space (only
 *                 used if <code>area</code> is <code>null</code>).
 *
 * @since 1.2.0
 */
protected void addEntity(EntityCollection entities, Shape hotspot,
        CategoryDataset dataset, int row, int column, boolean selected,
        double entityX, double entityY) {
    if (!getItemCreateEntity(row, column, selected)) {
        return;
    }
    Shape s = hotspot;
    if (hotspot == null) {
        double r = getDefaultEntityRadius();
        double w = r * 2;
        if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
            s = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
        }
        else {
            s = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
        }
    }
    String tip = null;
    CategoryToolTipGenerator generator = getToolTipGenerator(row, column,
            selected);
    if (generator != null) {
        tip = generator.generateToolTip(dataset, row, column);
    }
    String url = null;
    CategoryURLGenerator urlster = getURLGenerator(row, column, selected);
    if (urlster != null) {
        url = urlster.generateURL(dataset, row, column);
    }
    CategoryItemEntity entity = new CategoryItemEntity(s, tip, url,
            dataset, dataset.getRowKey(row), dataset.getColumnKey(column));
    entities.add(entity);
}
 
Example 7
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.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.
 */
@Override
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);
    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: LayeredBarRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the bar width and stores it in the renderer state.
 * 
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot, 
                                 Rectangle2D dataArea, 
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    // calculate the bar width - this calculation differs from the
    // BarRenderer calculation because the bars are layered on top of one
    // another, so there is effectively only one bar per category for
    // the purpose of the bar width calculation
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() 
            - domainAxis.getUpperMargin() - categoryMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (dataset.getColumnCount()), 
                    maxWidth));
        } 
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
 
Example 9
Source File: BoxAndWhiskerRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the data.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     CategoryItemRendererState state,
                     Rectangle2D dataArea,
                     CategoryPlot plot,
                     CategoryAxis domainAxis,
                     ValueAxis rangeAxis,
                     CategoryDataset dataset,
                     int row,
                     int column,
                     int pass) {
                         
    if (!(dataset instanceof BoxAndWhiskerCategoryDataset)) {
        throw new IllegalArgumentException(
                "BoxAndWhiskerRenderer.drawItem() : the data should be " 
                + "of type BoxAndWhiskerCategoryDataset only.");
    }

    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        drawHorizontalItem(g2, state, dataArea, plot, domainAxis, 
                rangeAxis, dataset, row, column);
    } 
    else if (orientation == PlotOrientation.VERTICAL) {
        drawVerticalItem(g2, state, dataArea, plot, domainAxis, 
                rangeAxis, dataset, row, column);
    }
    
}
 
Example 10
Source File: AbstractCategoryItemRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds an entity to the collection.
 *
 * @param entities  the entity collection being populated.
 * @param hotspot  the entity area (if <code>null</code> a default will be
 *              used).
 * @param dataset  the dataset.
 * @param row  the series.
 * @param column  the item.
 * @param entityX  the entity's center x-coordinate in user space (only
 *                 used if <code>area</code> is <code>null</code>).
 * @param entityY  the entity's center y-coordinate in user space (only
 *                 used if <code>area</code> is <code>null</code>).
 *
 * @since 1.0.13
 */
protected void addEntity(EntityCollection entities, Shape hotspot,
                         CategoryDataset dataset, int row, int column,
                         double entityX, double entityY) {
    if (!getItemCreateEntity(row, column)) {
        return;
    }
    Shape s = hotspot;
    if (hotspot == null) {
        double r = getDefaultEntityRadius();
        double w = r * 2;
        if (getPlot().getOrientation() == PlotOrientation.VERTICAL) {
            s = new Ellipse2D.Double(entityX - r, entityY - r, w, w);
        }
        else {
            s = new Ellipse2D.Double(entityY - r, entityX - r, w, w);
        }
    }
    String tip = null;
    CategoryToolTipGenerator generator = getToolTipGenerator(row, column);
    if (generator != null) {
        tip = generator.generateToolTip(dataset, row, column);
    }
    String url = null;
    CategoryURLGenerator urlster = getItemURLGenerator(row, column);
    if (urlster != null) {
        url = urlster.generateURL(dataset, row, column);
    }
    CategoryItemEntity entity = new CategoryItemEntity(s, tip, url,
            dataset, dataset.getRowKey(row), dataset.getColumnKey(column));
    entities.add(entity);
}
 
Example 11
Source File: BarRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
protected void calculateBarWidth(CategoryPlot plot,
                                 Rectangle2D dataArea,
                                 int rendererIndex,
                                 CategoryItemRendererState state) {

    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = state.getVisibleSeriesCount() >= 0
                ? state.getVisibleSeriesCount() : dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin()
                                 - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}
 
Example 12
Source File: BoxAndWhiskerRenderer.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the data (must be an instance of
 *                 {@link BoxAndWhiskerCategoryDataset}).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
    Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
    ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
    int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }

    if (!(dataset instanceof BoxAndWhiskerCategoryDataset)) {
        throw new IllegalArgumentException(
                "BoxAndWhiskerRenderer.drawItem() : the data should be "
                + "of type BoxAndWhiskerCategoryDataset only.");
    }

    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        drawHorizontalItem(g2, state, dataArea, plot, domainAxis,
                rangeAxis, dataset, row, column);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        drawVerticalItem(g2, state, dataArea, plot, domainAxis,
                rangeAxis, dataset, row, column);
    }

}
 
Example 13
Source File: ChartJFreeChartOutputScatter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createChart(final IScope scope) {
	super.createChart(scope);

	jfreedataset.add(0, new XYIntervalSeriesCollection());
	PlotOrientation orientation = PlotOrientation.VERTICAL;
	if (reverse_axes) {
		orientation = PlotOrientation.HORIZONTAL;
	}

	switch (type) {
		case SERIES_CHART:
		case XY_CHART:
		case SCATTER_CHART:
			chart = ChartFactory.createXYLineChart(getName(), "", "",
					(XYIntervalSeriesCollection) jfreedataset.get(0), orientation, true, false, false);
			break;
		case BOX_WHISKER_CHART: {
			chart = ChartFactory.createBoxAndWhiskerChart(getName(), "Time", "Value",
					(BoxAndWhiskerCategoryDataset) jfreedataset.get(0), true);
			chart.setBackgroundPaint(new Color(249, 231, 236));

			break;
		}

	}

}
 
Example 14
Source File: StackedBarRenderer3D.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the bar width and stores it in the renderer state.
 *
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param rendererIndex  the renderer index.
 * @param state  the renderer state.
 */
@Override
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea,
        int rendererIndex, CategoryItemRendererState state) {

    // calculate the bar width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset data = plot.getDataset(rendererIndex);
    if (data != null) {
        PlotOrientation orientation = plot.getOrientation();
        double space = 0.0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        int columns = data.getColumnCount();
        double categoryMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }

        double used = space * (1 - domainAxis.getLowerMargin()
                                 - domainAxis.getUpperMargin()
                                 - categoryMargin);
        if (columns > 0) {
            state.setBarWidth(Math.min(used / columns, maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }

}
 
Example 15
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 16
Source File: Cardumen_000_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a marker for the domain axis.
 *
 * @param g2  the graphics device (not <code>null</code>).
 * @param plot  the plot (not <code>null</code>).
 * @param axis  the range axis (not <code>null</code>).
 * @param marker  the marker to be drawn (not <code>null</code>).
 * @param dataArea  the area inside the axes (not <code>null</code>).
 *
 * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker,
 *     Rectangle2D)
 */
public void drawDomainMarker(Graphics2D g2,
                             CategoryPlot plot,
                             CategoryAxis axis,
                             CategoryMarker marker,
                             Rectangle2D dataArea) {

    Comparable category = marker.getKey();
    CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this));
    int columnIndex = dataset.getColumnIndex(category);
    if (columnIndex < 0) {
        return;
    }

    final Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(
            AlphaComposite.SRC_OVER, marker.getAlpha()));

    PlotOrientation orientation = plot.getOrientation();
    Rectangle2D bounds = null;
    if (marker.getDrawAsLine()) {
        double v = axis.getCategoryMiddle(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Line2D line = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line = new Line2D.Double(dataArea.getMinX(), v,
                    dataArea.getMaxX(), v);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            line = new Line2D.Double(v, dataArea.getMinY(), v,
                    dataArea.getMaxY());
        }
        g2.setPaint(marker.getPaint());
        g2.setStroke(marker.getStroke());
        g2.draw(line);
        bounds = line.getBounds2D();
    }
    else {
        double v0 = axis.getCategoryStart(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        double v1 = axis.getCategoryEnd(columnIndex,
                dataset.getColumnCount(), dataArea,
                plot.getDomainAxisEdge());
        Rectangle2D area = null;
        if (orientation == PlotOrientation.HORIZONTAL) {
            area = new Rectangle2D.Double(dataArea.getMinX(), v0,
                    dataArea.getWidth(), (v1 - v0));
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            area = new Rectangle2D.Double(v0, dataArea.getMinY(),
                    (v1 - v0), dataArea.getHeight());
        }
        g2.setPaint(marker.getPaint());
        g2.fill(area);
        bounds = area;
    }

    String label = marker.getLabel();
    RectangleAnchor anchor = marker.getLabelAnchor();
    if (label != null) {
        Font labelFont = marker.getLabelFont();
        g2.setFont(labelFont);
        g2.setPaint(marker.getLabelPaint());
        Point2D coordinates = calculateDomainMarkerTextAnchorPoint(
                g2, orientation, dataArea, bounds, marker.getLabelOffset(),
                marker.getLabelOffsetType(), anchor);
        TextUtilities.drawAlignedString(label, g2,
                (float) coordinates.getX(), (float) coordinates.getY(),
                marker.getLabelTextAnchor());
    }
    g2.setComposite(savedComposite);
}
 
Example 17
Source File: IntervalBarRenderer.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
  * Draws a single interval.
  *
  * @param g2  the graphics device.
  * @param state  the renderer state.
  * @param dataArea  the data plot area.
  * @param plot  the plot.
  * @param domainAxis  the domain axis.
  * @param rangeAxis  the range axis.
  * @param dataset  the data.
  * @param row  the row index (zero-based).
  * @param column  the column index (zero-based).
  */
 protected void drawInterval(Graphics2D g2,
                             CategoryItemRendererState state,
                             Rectangle2D dataArea,
                             CategoryPlot plot,
                             CategoryAxis domainAxis,
                             ValueAxis rangeAxis,
                             IntervalCategoryDataset dataset,
                             int row,
                             int column) {

    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    double rectX = 0.0;
    double rectY = 0.0;

    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    // Y0
    Number value0 = dataset.getEndValue(row, column);
    if (value0 == null) {
        return;
    }
    double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(),
            dataArea, rangeAxisLocation);

    // Y1
    Number value1 = dataset.getStartValue(row, column);
    if (value1 == null) {
        return;
    }
    double java2dValue1 = rangeAxis.valueToJava2D(
            value1.doubleValue(), dataArea, rangeAxisLocation);

    if (java2dValue1 < java2dValue0) {
        double temp = java2dValue1;
        java2dValue1 = java2dValue0;
        java2dValue0 = temp;
    }

    // BAR WIDTH
    double rectWidth = state.getBarWidth();

    // BAR HEIGHT
    double rectHeight = Math.abs(java2dValue1 - java2dValue0);

    RectangleEdge barBase = RectangleEdge.LEFT;
    if (orientation == PlotOrientation.HORIZONTAL) {
        // BAR Y
        rectX = java2dValue0;
        rectY = calculateBarW0(getPlot(), orientation, dataArea, 
                domainAxis, state, visibleRow, column);
        rectHeight = state.getBarWidth();
        rectWidth = Math.abs(java2dValue1 - java2dValue0);
        barBase = RectangleEdge.LEFT;
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        // BAR X
        rectX = calculateBarW0(getPlot(), orientation, dataArea, 
                domainAxis, state, visibleRow, column);
        rectY = java2dValue0;
        barBase = RectangleEdge.BOTTOM;
    }
    Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth,
            rectHeight);
    BarPainter painter = getBarPainter();
    if (getShadowsVisible()) {
        painter.paintBarShadow(g2, this, row, column, bar, barBase, false);
    }
    getBarPainter().paintBar(g2, this, row, column, bar, barBase);

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row,
            column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar,
                false);
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        addItemEntity(entities, dataset, row, column, bar);
    }

}
 
Example 18
Source File: BoxAndWhiskerRenderer.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialises the renderer.  This method gets called once at the start of
 * the process of drawing a chart.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area in which the data is to be plotted.
 * @param plot  the plot.
 * @param rendererIndex  the renderer index.
 * @param info  collects chart rendering information for return to caller.
 *
 * @return The renderer state.
 */
@Override
public CategoryItemRendererState initialise(Graphics2D g2, 
        Rectangle2D dataArea, CategoryPlot plot, int rendererIndex,
        PlotRenderingInfo info) {

    CategoryItemRendererState state = super.initialise(g2, dataArea, plot,
            rendererIndex, info);
    // calculate the box width
    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin()
                                 - domainAxis.getUpperMargin()
                                 - categoryMargin - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (dataset.getColumnCount()
                    * dataset.getRowCount()), maxWidth));
        }
        else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
    return state;

}
 
Example 19
Source File: ScatterRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area in which the data is drawn.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state,
        Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
        ValueAxis rangeAxis, CategoryDataset dataset, int row, int column,
        int pass) {

    // do nothing if item is not visible
    if (!getItemVisible(row, column)) {
        return;
    }
    int visibleRow = state.getVisibleSeriesIndex(row);
    if (visibleRow < 0) {
        return;
    }
    int visibleRowCount = state.getVisibleSeriesCount();

    PlotOrientation orientation = plot.getOrientation();

    MultiValueCategoryDataset d = (MultiValueCategoryDataset) dataset;
    List values = d.getValues(row, column);
    if (values == null) {
        return;
    }
    int valueCount = values.size();
    for (int i = 0; i < valueCount; i++) {
        // current data point...
        double x1;
        if (this.useSeriesOffset) {
            x1 = domainAxis.getCategorySeriesMiddle(column, 
                    dataset.getColumnCount(), visibleRow, visibleRowCount,
                    this.itemMargin, dataArea, plot.getDomainAxisEdge());
        }
        else {
            x1 = domainAxis.getCategoryMiddle(column, getColumnCount(),
                    dataArea, plot.getDomainAxisEdge());
        }
        Number n = (Number) values.get(i);
        double value = n.doubleValue();
        double y1 = rangeAxis.valueToJava2D(value, dataArea,
                plot.getRangeAxisEdge());

        Shape shape = getItemShape(row, column);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
        }
        if (getItemShapeFilled(row, column)) {
            if (this.useFillPaint) {
                g2.setPaint(getItemFillPaint(row, column));
            }
            else {
                g2.setPaint(getItemPaint(row, column));
            }
            g2.fill(shape);
        }
        if (this.drawOutlines) {
            if (this.useOutlinePaint) {
                g2.setPaint(getItemOutlinePaint(row, column));
            }
            else {
                g2.setPaint(getItemPaint(row, column));
            }
            g2.setStroke(getItemOutlineStroke(row, column));
            g2.draw(shape);
        }
    }

}
 
Example 20
Source File: CategoryStepRenderer.java    From SIMVA-SoS with Apache License 2.0 3 votes vote down vote up
/**
 * Draws a line taking into account the specified orientation.
 * <p>
 * In version 1.0.5, the signature of this method was changed by the
 * addition of the 'state' parameter.  This is an incompatible change, but
 * is considered a low risk because it is unlikely that anyone has
 * subclassed this renderer.  If this *does* cause trouble for you, please
 * report it as a bug.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param orientation  the plot orientation.
 * @param x0  the x-coordinate for the start of the line.
 * @param y0  the y-coordinate for the start of the line.
 * @param x1  the x-coordinate for the end of the line.
 * @param y1  the y-coordinate for the end of the line.
 */
protected void drawLine(Graphics2D g2, State state,
        PlotOrientation orientation, double x0, double y0, double x1,
        double y1) {

    if (orientation == PlotOrientation.VERTICAL) {
        state.line.setLine(x0, y0, x1, y1);
        g2.draw(state.line);
    }
    else if (orientation == PlotOrientation.HORIZONTAL) {
        state.line.setLine(y0, x0, y1, x1); // switch x and y
        g2.draw(state.line);
    }

}