org.jfree.data.Range Java Examples

The following examples show how to use org.jfree.data.Range. 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: patch1-Chart-1-jMutRepair_patch1-Chart-1-jMutRepair_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #2
Source File: TimeTableXYDataset.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the range of the values in this dataset's domain.
 * 
 * @param includeInterval  a flag that controls whether or not the
 *                         x-intervals are taken into account.
 *
 * @return The range.
 */
public Range getDomainBounds(boolean includeInterval) {
    List keys = this.values.getRowKeys();
    if (keys.isEmpty()) {
        return null;
    }
    
    TimePeriod first = (TimePeriod) keys.get(0);
    TimePeriod last = (TimePeriod) keys.get(keys.size() - 1);
    
    if (!includeInterval || this.domainIsPointsInTime) {
        return new Range(getXValue(first), getXValue(last));
    }
    else {
        return new Range(first.getStart().getTime(), 
                last.getEnd().getTime());
    }
}
 
Example #3
Source File: XYBlockRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the lower and upper bounds (range) of the x-values in the 
 * specified dataset.
 * 
 * @param dataset  the dataset (<code>null</code> permitted).
 * 
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *         
 * @see #findRangeBounds(XYDataset)
 */
public Range findDomainBounds(XYDataset dataset) {
    if (dataset != null) {
        Range r = DatasetUtilities.findDomainBounds(dataset, false);
        if (r == null) {
            return null; 
        }
        else {
            return new Range(r.getLowerBound() + this.xOffset, 
                    r.getUpperBound() + this.blockWidth + this.xOffset);
        }
    }
    else {
        return null;
    }
}
 
Example #4
Source File: StackedXYBarRenderer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 */
@Override
public Range findRangeBounds(XYDataset dataset) {
    if (dataset != null) {
        if (this.renderAsPercentages) {
            return new Range(0.0, 1.0);
        }
        else {
            return DatasetUtilities.findStackedRangeBounds(
                    (TableXYDataset) dataset);
        }
    }
    else {
        return null;
    }
}
 
Example #5
Source File: Cardumen_000_s.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 #6
Source File: BarChartTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
               + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #7
Source File: XYBarRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for the findDomainBounds method to ensure it correctly accounts 
 * for the series visibility.
 */
@Test
public void testFindDomainBounds2() {
    XYIntervalSeries s1 = new XYIntervalSeries("S1");
    s1.add(1.0, 0.5, 1.5, 10.0, 9.5, 10.5);
    s1.add(2.0, 1.9, 2.1, 20.0, 19.8, 20.3);
    XYIntervalSeries s2 = new XYIntervalSeries("S2");
    s2.add(3.0, 2.5, 3.5, 30.0, 29.5, 30.5);
    s2.add(4.0, 3.9, 4.1, 9.0, 9.0, 9.0);
    XYIntervalSeriesCollection dataset = new XYIntervalSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);
    
    XYBarRenderer renderer = new XYBarRenderer();
    Range r = renderer.findDomainBounds(dataset);
    assertEquals(0.5, r.getLowerBound(), EPSILON);
    assertEquals(4.1, r.getUpperBound(), EPSILON);
    
    renderer.setSeriesVisible(1, Boolean.FALSE);
    r = renderer.findDomainBounds(dataset);
    assertEquals(0.5, r.getLowerBound(), EPSILON);
    assertEquals(2.1, r.getUpperBound(), EPSILON);
}
 
Example #8
Source File: XYBlockRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the 
 * items from the specified dataset.
 * 
 * @param dataset  the dataset (<code>null</code> permitted).
 * 
 * @return The range (<code>null</code> if the dataset is <code>null</code> 
 *         or empty).
 *         
 * @see #findDomainBounds(XYDataset)
 */
public Range findRangeBounds(XYDataset dataset) {
    if (dataset != null) {
        Range r = DatasetUtilities.findRangeBounds(dataset, false);
        if (r == null) {
            return null; 
        }
        else {
            return new Range(r.getLowerBound() + this.yOffset, 
                    r.getUpperBound() + this.blockHeight + this.yOffset);
        }
    }
    else {
        return null;
    }
}
 
Example #9
Source File: Arja_0089_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the range of values the renderer requires to display all the
 * items from the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param includeInterval  include the y-interval if the dataset has one.
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @since 1.0.13
 */
protected Range findRangeBounds(CategoryDataset dataset,
        boolean includeInterval) {
    if (dataset == null) {
        return null;
    }
    if (getDataBoundsIncludesVisibleSeriesOnly()) {
        List visibleSeriesKeys = new ArrayList();
        int seriesCount = dataset.getRowCount();
        for (int s = 0; s < seriesCount; s++) {
            if (isSeriesVisible(s)) {
                visibleSeriesKeys.add(dataset.getRowKey(s));
            }
        }
        return DatasetUtilities.findRangeBounds(dataset,
                visibleSeriesKeys, includeInterval);
    }
    else {
        return DatasetUtilities.findRangeBounds(dataset, includeInterval);
    }
}
 
Example #10
Source File: MeterPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    MeterPlot p1 = new MeterPlot();
    MeterPlot p2 = (MeterPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // the clone and the original share a reference to the SAME dataset
    assertTrue(p1.getDataset() == p2.getDataset());

    // try a few checks to ensure that the clone is independent of the
    // original
    p1.getTickLabelFormat().setMinimumIntegerDigits(99);
    assertFalse(p1.equals(p2));
    p2.getTickLabelFormat().setMinimumIntegerDigits(99);
    assertTrue(p1.equals(p2));

    p1.addInterval(new MeterInterval("Test", new Range(1.234, 5.678)));
    assertFalse(p1.equals(p2));
    p2.addInterval(new MeterInterval("Test", new Range(1.234, 5.678)));
    assertTrue(p1.equals(p2));

}
 
Example #11
Source File: ContourPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the range for an axis.
 *
 * @param axis  the axis.
 *
 * @return The range for an axis.
 */
@Override
public Range getDataRange(ValueAxis axis) {

    if (this.dataset == null) {
        return null;
    }

    Range result = null;

    if (axis == getDomainAxis()) {
        result = DatasetUtilities.findDomainBounds(this.dataset);
    }
    else if (axis == getRangeAxis()) {
        result = DatasetUtilities.findRangeBounds(this.dataset);
    }
    return result;
}
 
Example #12
Source File: Chart_2_DatasetUtilities_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Finds the bounds of the y-values in the specified dataset, including
 * only those series that are listed in visibleSeriesKeys.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param visibleSeriesKeys  the keys for the visible series
 *     (<code>null</code> not permitted).
 * @param includeInterval  include the y-interval (if the dataset has a
 *     y-interval).
 *
 * @return The data bounds.
 *
 * @since 1.0.13
 */
public static Range findRangeBounds(CategoryDataset dataset,
        List visibleSeriesKeys, boolean includeInterval) {
    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }
    Range result = null;
    if (dataset instanceof CategoryRangeInfo) {
        CategoryRangeInfo info = (CategoryRangeInfo) dataset;
        result = info.getRangeBounds(visibleSeriesKeys, includeInterval);
    }
    else {
        result = iterateToFindRangeBounds(dataset, visibleSeriesKeys,
                includeInterval);
    }
    return result;
}
 
Example #13
Source File: Chart_2_DatasetUtilities_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the bounds of the x-values in the specified <code>dataset</code>
 * taking into account only the visible series and including any x-interval
 * if requested.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param visibleSeriesKeys  the visible series keys (<code>null</code>
 *     not permitted).
 * @param includeInterval  include the x-interval (if any)?
 *
 * @return The bounds (or <code>null</code> if the dataset contains no
 *     values.
 *
 * @since 1.0.13
 */
public static Range findDomainBounds(XYDataset dataset,
        List visibleSeriesKeys, boolean includeInterval) {
    if (dataset == null) {
        throw new IllegalArgumentException("Null 'dataset' argument.");
    }
    Range result = null;
    if (dataset instanceof XYDomainInfo) {
        XYDomainInfo info = (XYDomainInfo) dataset;
        result = info.getDomainBounds(visibleSeriesKeys, includeInterval);
    }
    else {
        result = iterateToFindDomainBounds(dataset, visibleSeriesKeys,
                includeInterval);
    }
    return result;
}
 
Example #14
Source File: StackedBarRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Some checks for the findRangeBounds() method.
 */
@Test
public void testFindRangeBounds() {
    StackedBarRenderer r = new StackedBarRenderer();
    assertNull(r.findRangeBounds(null));

    // an empty dataset should return a null range
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    assertNull(r.findRangeBounds(dataset));

    dataset.addValue(1.0, "R1", "C1");
    assertEquals(new Range(0.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(-2.0, "R1", "C2");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(null, "R1", "C3");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(2.0, "R2", "C1");
    assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset));

    dataset.addValue(null, "R2", "C2");
    assertEquals(new Range(-2.0, 3.0), r.findRangeBounds(dataset));
}
 
Example #15
Source File: DatasetUtilities.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Iterates over the data items of the xyz dataset to find
 * the z-dimension bounds.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  include the z-interval (if the dataset has a
 *     z-interval.
 *
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateZBounds(XYZDataset dataset,
        boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();

    for (int series = 0; series < seriesCount; series++) {
        int itemCount = dataset.getItemCount(series);
        for (int item = 0; item < itemCount; item++) {
            double value = dataset.getZValue(series, item);
            if (!Double.isNaN(value)) {
                minimum = Math.min(minimum, value);
                maximum = Math.max(maximum, value);
            }
        }
    }

    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    }
    else {
        return new Range(minimum, maximum);
    }
}
 
Example #16
Source File: DefaultBoxAndWhiskerXYDataset.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds an item to the dataset and sends a {@link DatasetChangeEvent} to
 * all registered listeners.
 *
 * @param date  the date (<code>null</code> not permitted).
 * @param item  the item (<code>null</code> not permitted).
 */
public void add(Date date, BoxAndWhiskerItem item) {
    this.dates.add(date);
    this.items.add(item);
    if (this.minimumRangeValue == null) {
        this.minimumRangeValue = item.getMinRegularValue();
    }
    else {
        if (item.getMinRegularValue().doubleValue()
                < this.minimumRangeValue.doubleValue()) {
            this.minimumRangeValue = item.getMinRegularValue();
        }
    }
    if (this.maximumRangeValue == null) {
        this.maximumRangeValue = item.getMaxRegularValue();
    }
    else {
        if (item.getMaxRegularValue().doubleValue()
                > this.maximumRangeValue.doubleValue()) {
            this.maximumRangeValue = item.getMaxRegularValue();
        }
    }
    this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(),
            this.maximumRangeValue.doubleValue());
    fireDatasetChanged();
}
 
Example #17
Source File: DefaultStatisticalCategoryDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getRangeBounds() method.
 */
public void testGetRangeBounds2() {
    DefaultStatisticalCategoryDataset d1 
            = new DefaultStatisticalCategoryDataset();
    d1.add(1.0, 2.0, "R1", "C1");
    assertEquals(new Range(1.0, 1.0), d1.getRangeBounds(false));
    assertEquals(new Range(-1.0, 3.0), d1.getRangeBounds(true));
    
    d1.add(10.0, 20.0, "R1", "C1");
    assertEquals(new Range(10.0, 10.0), d1.getRangeBounds(false));
    assertEquals(new Range(-10.0, 30.0), d1.getRangeBounds(true));
}
 
Example #18
Source File: AbstractChartPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Restores the auto-range calculation on the range axis.
 */

public void selectCompleteRangeBounds() {
	Plot plot = this.chart.getPlot();
	if (plot instanceof Zoomable) {
		Zoomable z = (Zoomable) plot;
		// here we tweak the notify flag on the plot so that only
		// one notification happens even though we update multiple
		// axes...
		boolean savedNotify = plot.isNotify();
		plot.setNotify(false);
		// we need to guard against this.zoomPoint being null
		Point2D zp = this.zoomPoint != null ? this.zoomPoint : new Point();
		z.zoomRangeAxes(0.0, this.info.getPlotInfo(), zp);
		plot.setNotify(savedNotify);

		if (plot instanceof XYPlot) {
			XYPlot xyPlot = (XYPlot) plot;
			Selection selectionObject = new Selection();
			for (int i = 0; i < xyPlot.getRangeAxisCount(); i++) {
				ValueAxis range = xyPlot.getRangeAxis(i);
				Range axisRange = new Range(range.getLowerBound(), range.getUpperBound());
				for (String axisName : axisNameResolver.resolveYAxis(i)) {
					selectionObject.addDelimiter(axisName, axisRange);
				}
			}
			informSelectionListener(selectionObject, null);
		}
	}
}
 
Example #19
Source File: LogAxis.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts a value on the axis scale to a Java2D coordinate relative to
 * the given {@code area}, based on the axis running along the
 * specified {@code edge}.
 *
 * @param value  the data value.
 * @param area  the area ({@code null} not permitted).
 * @param edge  the edge ({@code null} not permitted).
 *
 * @return The Java2D coordinate corresponding to {@code value}.
 */
@Override
public double valueToJava2D(double value, Rectangle2D area,
        RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());
    value = calculateLog(value);

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        max = area.getMinY();
        min = area.getMaxY();
    }
    if (isInverted()) {
        return max
               - ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    } else {
        return min
               + ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }
}
 
Example #20
Source File: TimeSeriesCollection.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the bounds for the y-values in the dataset.
 *
 * @param visibleSeriesKeys  the visible series keys.
 * @param xRange  the x-range (<code>null</code> not permitted).
 * @param includeInterval  ignored.
 *
 * @return The bounds.
 *
 * @since 1.0.14
 */
@Override
public Range getRangeBounds(List visibleSeriesKeys, Range xRange,
        boolean includeInterval) {
    Range result = null;
    Iterator iterator = visibleSeriesKeys.iterator();
    while (iterator.hasNext()) {
        Comparable seriesKey = (Comparable) iterator.next();
        TimeSeries series = getSeries(seriesKey);
        Range r = series.findValueRange(xRange, this.xPosition, 
                this.workingCalendar.getTimeZone());
        result = Range.combineIgnoringNaN(result, r);
    }
    return result;
}
 
Example #21
Source File: CategoryPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the range of data values that will be plotted against the range
 * axis.  If the dataset is <code>null</code>, this method returns
 * <code>null</code>.
 *
 * @param axis  the axis.
 *
 * @return The data range.
 */
public Range getDataRange(ValueAxis axis) {

    Range result = null;
    List mappedDatasets = new ArrayList();

    int rangeIndex = this.rangeAxes.indexOf(axis);
    if (rangeIndex >= 0) {
        mappedDatasets.addAll(datasetsMappedToRangeAxis(rangeIndex));
    }
    else if (axis == getRangeAxis()) {
        mappedDatasets.addAll(datasetsMappedToRangeAxis(0));
    }

    // iterate through the datasets that map to the axis and get the union
    // of the ranges.
    Iterator iterator = mappedDatasets.iterator();
    while (iterator.hasNext()) {
        CategoryDataset d = (CategoryDataset) iterator.next();
        CategoryItemRenderer r = getRendererForDataset(d);
        if (r != null) {
            result = Range.combine(result, r.findRangeBounds(d));
        }
    }
    return result;

}
 
Example #22
Source File: PolarPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the range for the specified axis.
 *
 * @param axis  the axis.
 *
 * @return The range.
 */
public Range getDataRange(ValueAxis axis) {
    Range result = null;
    if (this.dataset != null) {
        result = Range.combine(result, 
                DatasetUtilities.findRangeBounds(this.dataset));
    }
    return result;
}
 
Example #23
Source File: DefaultBoxAndWhiskerCategoryDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the add() method.
 */
public void testAddUpdatesCachedRange() {
    DefaultBoxAndWhiskerCategoryDataset dataset
            = new DefaultBoxAndWhiskerCategoryDataset();
    BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0,
            5.0, 6.0, 7.0, 8.0, new ArrayList());
    dataset.add(item1, "R1", "C1");

    // now overwrite this item with another
    BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5,
            5.5, 6.5, 7.5, 8.5, new ArrayList());
    dataset.add(item2, "R1", "C1");

    assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON);
    assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(),
            EPSILON);
    assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false));
}
 
Example #24
Source File: LogAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a value on the axis scale to a Java2D coordinate relative to
 * the given {@code area}, based on the axis running along the
 * specified {@code edge}.
 *
 * @param value  the data value.
 * @param area  the area ({@code null} not permitted).
 * @param edge  the edge ({@code null} not permitted).
 *
 * @return The Java2D coordinate corresponding to {@code value}.
 */
@Override
public double valueToJava2D(double value, Rectangle2D area,
        RectangleEdge edge) {

    Range range = getRange();
    double axisMin = calculateLog(range.getLowerBound());
    double axisMax = calculateLog(range.getUpperBound());
    value = calculateLog(value);

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = area.getX();
        max = area.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        max = area.getMinY();
        min = area.getMaxY();
    }
    if (isInverted()) {
        return max
               - ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    } else {
        return min
               + ((value - axisMin) / (axisMax - axisMin)) * (max - min);
    }
}
 
Example #25
Source File: ContourPlot.java    From openstock 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 #26
Source File: DatasetUtilitiesTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for the iterateRangeBounds() method.
 */
@Test
public void testIterateRangeBounds3() {
    // an empty dataset should return a null range
    XYSeriesCollection dataset = new XYSeriesCollection();
    Range r = DatasetUtilities.iterateRangeBounds(dataset);
    assertNull(r);
    XYSeries s1 = new XYSeries("S1");
    dataset.addSeries(s1);
    r = DatasetUtilities.iterateRangeBounds(dataset);
    assertNull(r);

    // a dataset with a single value
    s1.add(1.0, 1.23);
    r = DatasetUtilities.iterateRangeBounds(dataset);
    assertEquals(1.23, r.getLowerBound(), EPSILON);
    assertEquals(1.23, r.getUpperBound(), EPSILON);

    // null is ignored
    s1.add(2.0, null);
    r = DatasetUtilities.iterateRangeBounds(dataset);
    assertEquals(1.23, r.getLowerBound(), EPSILON);
    assertEquals(1.23, r.getUpperBound(), EPSILON);

    // Double.NaN DOESN'T mess things up
    s1.add(3.0, Double.NaN);
    r = DatasetUtilities.iterateRangeBounds(dataset);
    assertEquals(1.23, r.getLowerBound(), EPSILON);
    assertEquals(1.23, r.getUpperBound(), EPSILON);
}
 
Example #27
Source File: ThermometerPlot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the axis range to the current values in the rangeInfo array.
 */
protected void setAxisRange() {
    if ((this.subrange >= 0) && (this.followDataInSubranges)) {
        this.rangeAxis.setRange(
                new Range(this.subrangeInfo[this.subrange][DISPLAY_LOW],
                this.subrangeInfo[this.subrange][DISPLAY_HIGH]));
    }
    else {
        this.rangeAxis.setRange(this.lowerBound, this.upperBound);
    }
}
 
Example #28
Source File: GridArrangementTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Test arrangement with a range for the width and no height constraint.
 */
@Test
public void testRN() {
    BlockContainer c = createTestContainer1();
    RectangleConstraint constraint = RectangleConstraint.NONE.toRangeWidth(
            new Range(40.0, 60.0));
    Size2D s = c.arrange(null, constraint);
    assertEquals(60.0, s.width, EPSILON);
    assertEquals(33.0, s.height, EPSILON);
}
 
Example #29
Source File: XYBlockRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the lower and upper bounds (range) of the x-values in the
 * specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 *
 * @return The range (<code>null</code> if the dataset is <code>null</code>
 *         or empty).
 *
 * @see #findRangeBounds(XYDataset)
 */
@Override
public Range findDomainBounds(XYDataset dataset) {
    if (dataset == null) {
        return null;
    }
    Range r = DatasetUtilities.findDomainBounds(dataset, false);
    if (r == null) {
        return null;
    }
    return new Range(r.getLowerBound() + this.xOffset,
                     r.getUpperBound() + this.blockWidth + this.xOffset);
}
 
Example #30
Source File: XYBlockRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A simple test for bug 1766646.
 */
public void testBug1766646B() {
    XYBlockRenderer r = new XYBlockRenderer();
    Range range = r.findRangeBounds(null);
    assertTrue(range == null);
    DefaultXYZDataset emptyDataset = new DefaultXYZDataset();
    range = r.findRangeBounds(emptyDataset);
    assertTrue(range == null);
}