org.jfree.ui.RectangleEdge Java Examples

The following examples show how to use org.jfree.ui.RectangleEdge. 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: NumberAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Test the translation of Java2D values to data values.
 */
@Test
public void testTranslateJava2DToValue() {
    NumberAxis axis = new NumberAxis();
    axis.setRange(50.0, 100.0);
    Rectangle2D dataArea = new Rectangle2D.Double(10.0, 50.0, 400.0, 300.0);
    double y1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);
    assertEquals(y1, 95.8333333, EPSILON);
    double y2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);
    assertEquals(y2, 95.8333333, EPSILON);
    double x1 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);
    assertEquals(x1, 58.125, EPSILON);
    double x2 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);
    assertEquals(x2, 58.125, EPSILON);
    axis.setInverted(true);
    double y3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.LEFT);
    assertEquals(y3, 54.1666667, EPSILON);
    double y4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.RIGHT);
    assertEquals(y4, 54.1666667, EPSILON);
    double x3 = axis.java2DToValue(75.0, dataArea, RectangleEdge.TOP);
    assertEquals(x3, 91.875, EPSILON);
    double x4 = axis.java2DToValue(75.0, dataArea, RectangleEdge.BOTTOM);
    assertEquals(x4, 91.875, EPSILON);
}
 
Example #2
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private void legendPositionChanged(LegendPosition legendPosition) {
	JFreeChart chart = getCurrentChart();
	if (chart != null) {
		LegendTitle legend = chart.getLegend();
		RectangleEdge position = legendPosition.getPosition();
		if (legend != null) {
			if (position != null) {
				legend.setPosition(position);
			} else {
				while (chart.getLegend() != null) {
					chart.removeLegend();
				}
			}
		} else {
			if (position != null) {
				resetLegend();
			}
		}
	}
}
 
Example #3
Source File: StandardXYBarPainter.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 */
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base) {

    Paint itemPaint = renderer.getItemPaint(row, column);
    GradientPaintTransformer t = renderer.getGradientPaintTransformer();
    if (t != null && itemPaint instanceof GradientPaint) {
        itemPaint = t.transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
           // && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}
 
Example #4
Source File: CategoryAxis.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the size (width or height, depending on the location of the
 * axis) of a category.
 *
 * @param categoryCount  the number of categories.
 * @param area  the area within which the categories will be drawn.
 * @param edge  the axis location.
 *
 * @return The category size.
 */
protected double calculateCategorySize(int categoryCount, Rectangle2D area,
        RectangleEdge edge) {
    double result;
    double available = 0.0;

    if ((edge == RectangleEdge.TOP) || (edge == RectangleEdge.BOTTOM)) {
        available = area.getWidth();
    }
    else if ((edge == RectangleEdge.LEFT)
            || (edge == RectangleEdge.RIGHT)) {
        available = area.getHeight();
    }
    if (categoryCount > 1) {
        result = available * (1 - getLowerMargin() - getUpperMargin()
                 - getCategoryMargin());
        result = result / categoryCount;
    }
    else {
        result = available * (1 - getLowerMargin() - getUpperMargin());
    }
    return result;
}
 
Example #5
Source File: BorderArrangementTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This test is for a particular bug that arose just prior to the release
 * of JFreeChart 1.0.10.  A BorderArrangement with LEFT, CENTRE and RIGHT
 * blocks that is too wide, by default, for the available space, wasn't
 * shrinking the centre block as expected.
 */
@Test  
public void testBugX() {
    RectangleConstraint constraint = new RectangleConstraint(
            new Range(0.0, 200.0), new Range(0.0, 100.0));
    BlockContainer container = new BlockContainer(new BorderArrangement());
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();

    container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(30.0, 6.0));
    Size2D size = container.arrange(g2, constraint);
    assertEquals(60.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);

    container.clear();
    container.add(new EmptyBlock(10.0, 6.0), RectangleEdge.LEFT);
    container.add(new EmptyBlock(20.0, 6.0), RectangleEdge.RIGHT);
    container.add(new EmptyBlock(300.0, 6.0));
    size = container.arrange(g2, constraint);
    assertEquals(200.0, size.width, EPSILON);
    assertEquals(6.0, size.height, EPSILON);
}
 
Example #6
Source File: BorderArrangement.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a block to the arrangement manager at the specified edge.
 * 
 * @param block  the block (<code>null</code> permitted).
 * @param key  the edge (an instance of {@link RectangleEdge}) or 
 *             <code>null</code> for the center block.
 */
public void add(Block block, Object key) {
    
    if (key == null) {
        this.centerBlock = block;
    }
    else {
        RectangleEdge edge = (RectangleEdge) key;
        if (edge == RectangleEdge.TOP) {
            this.topBlock = block;
        }
        else if (edge == RectangleEdge.BOTTOM) {
            this.bottomBlock = block;
        }
        else if (edge == RectangleEdge.LEFT) {
            this.leftBlock = block;
        }
        else if (edge == RectangleEdge.RIGHT) {
            this.rightBlock = block;
        }
    }
}
 
Example #7
Source File: LogarithmicAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check the translation java2D to value for left, right, and center point.
 *
 * @param edge  the edge.
 * @param plotArea  the plot area.
 */
 private void checkPointsToValue(RectangleEdge edge, Rectangle2D plotArea) {
     assertEquals("Right most point on the axis should be end of range.",
             this.axis.getUpperBound(), this.axis.java2DToValue(
             plotArea.getX() + plotArea.getWidth(), plotArea, edge),
             EPSILON);

     assertEquals("Left most point on the axis should be beginning of "
             + "range.", this.axis.getLowerBound(),
             this.axis.java2DToValue(plotArea.getX(), plotArea, edge),
             EPSILON);

     assertEquals("Center point on the axis should geometric mean of the "
             + "bounds.", Math.sqrt(this.axis.getUpperBound()
             * this.axis.getLowerBound()), this.axis.java2DToValue(
             plotArea.getX() + (plotArea.getWidth() / 2), plotArea, edge),
             EPSILON);
}
 
Example #8
Source File: Axis.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws an axis line at the current cursor position and edge.
 *
 * @param g2  the graphics device.
 * @param cursor  the cursor position.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawAxisLine(Graphics2D g2, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    Line2D axisLine = null;
    double x = dataArea.getX();
    double y = dataArea.getY();
    if (edge == RectangleEdge.TOP) {
        axisLine = new Line2D.Double(x, cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.BOTTOM) {
        axisLine = new Line2D.Double(x, cursor, dataArea.getMaxX(), cursor);
    } else if (edge == RectangleEdge.LEFT) {
        axisLine = new Line2D.Double(cursor, y, cursor, dataArea.getMaxY());
    } else if (edge == RectangleEdge.RIGHT) {
        axisLine = new Line2D.Double(cursor, y, cursor, dataArea.getMaxY());
    }
    g2.setPaint(this.axisLinePaint);
    g2.setStroke(this.axisLineStroke);
    Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, 
            RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.draw(axisLine);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, saved);
}
 
Example #9
Source File: CyclicNumberAxis.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the anchor point for a tick.
 *
 * @param tick  the tick.
 * @param cursor  the cursor.
 * @param dataArea  the data area.
 * @param edge  the side on which the axis is displayed.
 *
 * @return The anchor point.
 */
@Override
protected float[] calculateAnchorPoint(ValueTick tick, double cursor,
        Rectangle2D dataArea, RectangleEdge edge) {
    if (tick instanceof CycleBoundTick) {
        boolean mapsav = this.boundMappedToLastCycle;
        this.boundMappedToLastCycle
            = ((CycleBoundTick) tick).mapToLastCycle;
        float[] ret = super.calculateAnchorPoint(
            tick, cursor, dataArea, edge
        );
        this.boundMappedToLastCycle = mapsav;
        return ret;
    }
    return super.calculateAnchorPoint(tick, cursor, dataArea, edge);
}
 
Example #10
Source File: GradientXYBarPainter.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 * @param pegShadow  peg the shadow to the base of the bar?
 */
@Override
public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base,
        boolean pegShadow) {

    // handle a special case - if the bar colour has alpha == 0, it is
    // invisible so we shouldn't draw any shadow
    Paint itemPaint = renderer.getItemPaint(row, column);
    if (itemPaint instanceof Color) {
        Color c = (Color) itemPaint;
        if (c.getAlpha() == 0) {
            return;
        }
    }

    RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(),
            renderer.getShadowYOffset(), base, pegShadow);
    g2.setPaint(Color.gray);
    g2.fill(shadow);

}
 
Example #11
Source File: CategoryPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a range crosshair.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 *
 * @see #drawDomainCrosshair(Graphics2D, Rectangle2D, PlotOrientation, int,
 *      Comparable, Comparable, Stroke, Paint)
 *
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea,
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
    }
    else {
        double yy = axis.valueToJava2D(value, dataArea,
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy,
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);

}
 
Example #12
Source File: CategoryLabelPositions.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the category label position specification for an axis at the
 * given location.
 *
 * @param edge  the axis location.
 *
 * @return The category label position specification.
 */
public CategoryLabelPosition getLabelPosition(RectangleEdge edge) {
    CategoryLabelPosition result = null;
    if (edge == RectangleEdge.TOP) {
        result = this.positionForAxisAtTop;
    }
    else if (edge == RectangleEdge.BOTTOM) {
        result = this.positionForAxisAtBottom;
    }
    else if (edge == RectangleEdge.LEFT) {
        result = this.positionForAxisAtLeft;
    }
    else if (edge == RectangleEdge.RIGHT) {
        result = this.positionForAxisAtRight;
    }
    return result;
}
 
Example #13
Source File: MultiplePiePlot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new plot.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public MultiplePiePlot(CategoryDataset dataset) {
    super();
    setDataset(dataset);
    PiePlot piePlot = new PiePlot(null);
    piePlot.setIgnoreNullValues(true);
    this.pieChart = new JFreeChart(piePlot);
    this.pieChart.removeLegend();
    this.dataExtractOrder = TableOrder.BY_COLUMN;
    this.pieChart.setBackgroundPaint(null);
    TextTitle seriesTitle = new TextTitle("Series Title",
            new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    this.pieChart.setTitle(seriesTitle);
    this.aggregatedItemsKey = "Other";
    this.aggregatedItemsPaint = Color.lightGray;
    this.sectionPaints = new HashMap();
    this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
}
 
Example #14
Source File: AxisSpace.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds space to the top, bottom, left or right edge of the plot area.
 *
 * @param space  the space (in Java2D units).
 * @param edge  the edge (<code>null</code> not permitted).
 */
public void add(double space, RectangleEdge edge) {
    ParamChecks.nullNotPermitted(edge, "edge");
    if (edge == RectangleEdge.TOP) {
        this.top += space;
    }
    else if (edge == RectangleEdge.BOTTOM) {
        this.bottom += space;
    }
    else if (edge == RectangleEdge.LEFT) {
        this.left += space;
    }
    else if (edge == RectangleEdge.RIGHT) {
        this.right += space;
    }
    else {
        throw new IllegalStateException("Unrecognised 'edge' argument.");
    }
}
 
Example #15
Source File: StandardXYBarPainter.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints a single bar instance.
 *
 * @param g2  the graphics target.
 * @param renderer  the renderer.
 * @param row  the row index.
 * @param column  the column index.
 * @param bar  the bar
 * @param base  indicates which side of the rectangle is the base of the
 *              bar.
 */
@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row,
        int column, RectangularShape bar, RectangleEdge base) {

    Paint itemPaint = renderer.getItemPaint(row, column);
    GradientPaintTransformer t = renderer.getGradientPaintTransformer();
    if (t != null && itemPaint instanceof GradientPaint) {
        itemPaint = t.transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
           // && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}
 
Example #16
Source File: CategoryLabelPositions.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a new instance based on an existing instance but with the right
 * position changed.
 *
 * @param base  the base (<code>null</code> not permitted).
 * @param right  the right position (<code>null</code> not permitted).
 *
 * @return A new instance (never <code>null</code>).
 */
public static CategoryLabelPositions replaceRightPosition(
        CategoryLabelPositions base, CategoryLabelPosition right) {

    ParamChecks.nullNotPermitted(base, "base");
    ParamChecks.nullNotPermitted(right, "right");
    return new CategoryLabelPositions(
        base.getLabelPosition(RectangleEdge.TOP),
        base.getLabelPosition(RectangleEdge.BOTTOM),
        base.getLabelPosition(RectangleEdge.LEFT),
        right);
}
 
Example #17
Source File: ContourPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a vertical line on the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawDomainMarker(Graphics2D g2,
                             ContourPlot plot,
                             ValueAxis domainAxis,
                             Marker marker,
                             Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = domainAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double x = domainAxis.valueToJava2D(value, dataArea,
                RectangleEdge.BOTTOM);
        Line2D line = new Line2D.Double(x, dataArea.getMinY(), x,
                dataArea.getMaxY());
        Paint paint = marker.getOutlinePaint();
        Stroke stroke = marker.getOutlineStroke();
        g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
        g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
        g2.draw(line);
    }

}
 
Example #18
Source File: ImageTitle.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new image title.
 *
 * @param image  the image ({@code null} not permitted).
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 */
public ImageTitle(Image image, RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment) {

    this(image, image.getHeight(null), image.getWidth(null),
            position, horizontalAlignment, verticalAlignment,
            Title.DEFAULT_PADDING);
}
 
Example #19
Source File: CategoryTextAnnotation.java    From buffer_bci with GNU General Public License v3.0 5 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.
 */
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea,
        CategoryAxis domainAxis, ValueAxis rangeAxis) {

    CategoryDataset dataset = plot.getDataset();
    int catIndex = dataset.getColumnIndex(this.category);
    int catCount = dataset.getColumnCount();

    float anchorX = 0.0f;
    float anchorY = 0.0f;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        anchorY = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea,
                domainEdge);
        anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea,
                rangeEdge);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        anchorX = (float) domainAxis.getCategoryJava2DCoordinate(
                this.categoryAnchor, catIndex, catCount, dataArea,
                domainEdge);
        anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea,
                rangeEdge);
    }
    g2.setFont(getFont());
    g2.setPaint(getPaint());
    TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
            getTextAnchor(), getRotationAngle(), getRotationAnchor());

}
 
Example #20
Source File: TitleTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    // use the TextTitle class because it is a concrete subclass
    Title t1 = new TextTitle();
    Title t2 = new TextTitle();
    assertEquals(t1, t2);

    t1.setPosition(RectangleEdge.LEFT);
    assertFalse(t1.equals(t2));
    t2.setPosition(RectangleEdge.LEFT);
    assertTrue(t1.equals(t2));

    t1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    assertFalse(t1.equals(t2));
    t2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    assertTrue(t1.equals(t2));

    t1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    assertFalse(t1.equals(t2));
    t2.setVerticalAlignment(VerticalAlignment.BOTTOM);
    assertTrue(t1.equals(t2));

    t1.setVisible(false);
    assertFalse(t1.equals(t2));
    t2.setVisible(false);
    assertTrue(t1.equals(t2));
}
 
Example #21
Source File: PeriodAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the tick marks for the axis.
 * 
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarks(Graphics2D g2, AxisState state, 
                             Rectangle2D dataArea, 
                             RectangleEdge edge) {
    if (RectangleEdge.isTopOrBottom(edge)) {
        drawTickMarksHorizontal(g2, state, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        drawTickMarksVertical(g2, state, dataArea, edge);
    }
}
 
Example #22
Source File: CandlestickRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method
 * will be called before the first item is rendered, giving the renderer
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {

    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
        // Absolute value, since the relative x
        // positions are reversed for horizontal orientation

    // calculate the highest volume in the dataset...
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount();
             series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series);
                 item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }

            }
        }
    }

    return new XYItemRendererState(info);
}
 
Example #23
Source File: DateAxis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Selects an appropriate tick value for the axis.  The strategy is to
 * display as many ticks as possible (selected from an array of 'standard'
 * tick units) without the labels overlapping.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param edge  the axis location.
 */
protected void selectAutoTickUnit(Graphics2D g2, Rectangle2D dataArea,
        RectangleEdge edge) {

    if (RectangleEdge.isTopOrBottom(edge)) {
        selectHorizontalAutoTickUnit(g2, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        selectVerticalAutoTickUnit(g2, dataArea, edge);
    }

}
 
Example #24
Source File: LogAxis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates the positions of the tick labels for the axis, storing the
 * results in the tick label list (ready for drawing).
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the area in which the plot should be drawn.
 * @param edge  the location of the axis.
 *
 * @return A list of ticks.
 */
@Override
public List refreshTicks(Graphics2D g2, AxisState state,
        Rectangle2D dataArea, RectangleEdge edge) {
    List result = new java.util.ArrayList();
    if (RectangleEdge.isTopOrBottom(edge)) {
        result = refreshTicksHorizontal(g2, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        result = refreshTicksVertical(g2, dataArea, edge);
    }
    return result;
}
 
Example #25
Source File: ModifiedPlot.java    From chipster with MIT License 5 votes vote down vote up
/**
 * Draws a horizontal line across the chart to represent a 'range marker'.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param rangeAxis  the range axis.
 * @param marker  the marker line.
 * @param dataArea  the axis data area.
 */
public void drawRangeMarker(Graphics2D g2,
                            ModifiedPlot plot,
                            ValueAxis rangeAxis,
                            Marker marker,
                            Rectangle2D dataArea) {

    if (marker instanceof ValueMarker) {
        ValueMarker vm = (ValueMarker) marker;
        double value = vm.getValue();
        Range range = rangeAxis.getRange();
        if (!range.contains(value)) {
            return;
        }

        double y = rangeAxis.valueToJava2D(
            value, dataArea, RectangleEdge.LEFT
        );
        Line2D line = new Line2D.Double(
            dataArea.getMinX(), y, dataArea.getMaxX(), y
        );
        Paint paint = marker.getOutlinePaint();
        Stroke stroke = marker.getOutlineStroke();
        g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
        g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
        g2.draw(line);
    }

}
 
Example #26
Source File: TextTitle.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a the title horizontally within the specified area.  This method
 * will be called from the {@link #draw(Graphics2D, Rectangle2D) draw}
 * method.
 *
 * @param g2  the graphics device.
 * @param area  the area for the title.
 */
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlockAnchor anchor = null;
    float x = 0.0f;
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    if (horizontalAlignment == HorizontalAlignment.LEFT) {
        x = (float) titleArea.getX();
        anchor = TextBlockAnchor.TOP_LEFT;
    }
    else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        x = (float) titleArea.getMaxX();
        anchor = TextBlockAnchor.TOP_RIGHT;
    }
    else if (horizontalAlignment == HorizontalAlignment.CENTER) {
        x = (float) titleArea.getCenterX();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float y = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP) {
        y = (float) titleArea.getY();
    }
    else if (position == RectangleEdge.BOTTOM) {
        y = (float) titleArea.getMaxY();
        if (horizontalAlignment == HorizontalAlignment.LEFT) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        }
        else if (horizontalAlignment == HorizontalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        }
        else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        }
    }
    this.content.draw(g2, x, y, anchor);
}
 
Example #27
Source File: LogAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Selects an appropriate tick value for the axis.  The strategy is to
 * display as many ticks as possible (selected from an array of 'standard'
 * tick units) without the labels overlapping.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param edge  the axis location.
 *
 * @since 1.0.7
 */
protected void selectHorizontalAutoTickUnit(Graphics2D g2,
        Rectangle2D dataArea, RectangleEdge edge) {

    // select a tick unit that is the next one bigger than the current
    // (log) range divided by 50
    Range range = getRange();
    double logAxisMin = calculateLog(Math.max(this.smallestValue, 
            range.getLowerBound()));
    double logAxisMax = calculateLog(range.getUpperBound());
    double size = (logAxisMax - logAxisMin) / 50;
    TickUnitSource tickUnits = getStandardTickUnits();
    TickUnit candidate = tickUnits.getCeilingTickUnit(size);
    TickUnit prevCandidate = candidate;
    boolean found = false;
    while (!found) {
    // while the tick labels overlap and there are more tick sizes available,
        // choose the next bigger label
        this.tickUnit = (NumberTickUnit) candidate;
        double tickLabelWidth = estimateMaximumTickLabelWidth(g2, 
                candidate);
        // what is the available space for one unit?
        double candidateWidth = exponentLengthToJava2D(candidate.getSize(), 
                dataArea, edge);
        if (tickLabelWidth < candidateWidth) {
            found = true;
        } else if (Double.isNaN(candidateWidth)) {
            candidate = prevCandidate;
            found = true;
        } else {
            prevCandidate = candidate;
            candidate = tickUnits.getLargerTickUnit(prevCandidate);
            if (candidate.equals(prevCandidate)) {
                found = true;  // there are no more candidates
            }
        }
    } 
    setTickUnit((NumberTickUnit) candidate, false, false);
}
 
Example #28
Source File: CustomXYStepRenderer.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);

	// draw the item label if there is one...
	if (isItemLabelVisible(series, item)) {
		// get the data point...
		double x1 = dataset.getXValue(series, item);
		double y1 = dataset.getYValue(series, item);
		if (Double.isNaN(y1)) {
			return;
		}

		RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
		RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
		double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
		double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

		double xx = transX1;
		double yy = transY1;
		PlotOrientation orientation = plot.getOrientation();
		if (orientation == PlotOrientation.HORIZONTAL) {
			xx = transY1;
			yy = transX1;
		}
		drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
	}
}
 
Example #29
Source File: DateAxis.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Selects an appropriate tick value for the axis.  The strategy is to
 * display as many ticks as possible (selected from an array of 'standard'
 * tick units) without the labels overlapping.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area defined by the axes.
 * @param edge  the axis location.
 */
protected void selectAutoTickUnit(Graphics2D g2, 
                                  Rectangle2D dataArea,
                                  RectangleEdge edge) {

    if (RectangleEdge.isTopOrBottom(edge)) {
        selectHorizontalAutoTickUnit(g2, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        selectVerticalAutoTickUnit(g2, dataArea, edge);
    }

}
 
Example #30
Source File: PeriodAxis.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the tick marks for the axis.
 *
 * @param g2  the graphics device.
 * @param state  the axis state.
 * @param dataArea  the data area.
 * @param edge  the edge.
 */
protected void drawTickMarks(Graphics2D g2, AxisState state, 
        Rectangle2D dataArea, RectangleEdge edge) {
    if (RectangleEdge.isTopOrBottom(edge)) {
        drawTickMarksHorizontal(g2, state, dataArea, edge);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        drawTickMarksVertical(g2, state, dataArea, edge);
    }
}