List of usage examples for org.jfree.data Range constrain
public double constrain(double value)
From source file:org.jfree.data.RangeTest.java
/** * Tests the constrain() method for various values. *//*from w w w. j ava2s. c om*/ @Test public void testConstrain() { Range r1 = new Range(0.0, 1.0); double d = r1.constrain(0.5); assertEquals(0.5, d, 0.0000001); d = r1.constrain(0.0); assertEquals(0.0, d, 0.0000001); d = r1.constrain(1.0); assertEquals(1.0, d, 0.0000001); d = r1.constrain(-1.0); assertEquals(0.0, d, 0.0000001); d = r1.constrain(2.0); assertEquals(1.0, d, 0.0000001); d = r1.constrain(Double.POSITIVE_INFINITY); assertEquals(1.0, d, 0.0000001); d = r1.constrain(Double.NEGATIVE_INFINITY); assertEquals(0.0, d, 0.0000001); d = r1.constrain(Double.NaN); assertTrue(Double.isNaN(d)); }
From source file:org.schreibubi.JCombinations.jfreechart.XYLineAndShapeRendererExtended.java
/** * Draws a horizontal line across the chart to represent a 'range marker'. * /*from w w w . ja v a 2s. c o m*/ * @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. */ @Override public void drawRangeMarker(Graphics2D g2, XYPlot plot, ValueAxis rangeAxis, Marker marker, Rectangle2D dataArea) { if (marker instanceof ValueMarker) super.drawRangeMarker(g2, plot, rangeAxis, marker, dataArea); else if (marker instanceof IntervalMarker) super.drawRangeMarker(g2, plot, rangeAxis, marker, dataArea); else if (marker instanceof ArbitraryMarker) { ArbitraryMarker im = (ArbitraryMarker) marker; ArrayList<Double> xvals = im.getDomainVal(); ArrayList<Double> lows = im.getRangeLowValues(); ArrayList<Double> highs = im.getRangeHighValues(); sort(xvals, lows, highs); Range range = rangeAxis.getRange(); ValueAxis domainAxis = plot.getDomainAxis(); Range domain = domainAxis.getRange(); int length = xvals.size(); int[] xpoly = new int[length * 2]; int[] ypoly = new int[length * 2]; for (int i = 0; i < xvals.size(); i++) { double x = domain.constrain(xvals.get(i)); double low = range.constrain(lows.get(i)); double high = range.constrain(highs.get(i)); int low2d = (int) Math.round(rangeAxis.valueToJava2D(low, dataArea, plot.getRangeAxisEdge())); int high2d = (int) Math.round(rangeAxis.valueToJava2D(high, dataArea, plot.getRangeAxisEdge())); int x2d = (int) Math.round(domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge())); xpoly[i] = x2d; xpoly[2 * length - 1 - i] = x2d; ypoly[i] = low2d; ypoly[2 * length - 1 - i] = high2d; } PlotOrientation orientation = plot.getOrientation(); Polygon poly = null; if (orientation == PlotOrientation.HORIZONTAL) poly = new Polygon(ypoly, xpoly, length * 2); else if (orientation == PlotOrientation.VERTICAL) poly = new Polygon(xpoly, ypoly, length * 2); Paint p = im.getPaint(); if (p instanceof GradientPaint) { GradientPaint gp = (GradientPaint) p; GradientPaintTransformer t = im.getGradientPaintTransformer(); if (t != null) gp = t.transform(gp, poly); g2.setPaint(gp); } else g2.setPaint(p); g2.fill(poly); /* * String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if ( label != null ) { * Font labelFont = marker.getLabelFont(); g2.setFont( labelFont ); g2.setPaint( marker.getLabelPaint() ); * Point2D coordinates = calculateRangeMarkerTextAnchorPoint( g2, orientation, dataArea, poly, * marker.getLabelOffset(), marker.getLabelOffsetType(), anchor ); TextUtilities.drawAlignedString( label, * g2, ( float ) coordinates.getX(), ( float ) coordinates.getY(), marker.getLabelTextAnchor() ); } */ } }