/** * Returns the content size for the title. This will reflect the fact that a text title positioned * on the left or right of a chart will be rotated 90 degrees. * * @param g2 the graphics device. * @param widthRange the width range. * @param heightRange the height range. * @return The content size. */ protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) { RectangleEdge position = getPosition(); if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) { float maxWidth = (float) widthRange.getUpperBound(); // determine the space required for the axis AxisSpace space = this.axis.reserveSpace( g2, null, new Rectangle2D.Double(0, 0, maxWidth, 100), RectangleEdge.BOTTOM, null); return new Size2D( maxWidth, this.stripWidth + this.axisOffset + space.getTop() + space.getBottom()); } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) { float maxHeight = (float) heightRange.getUpperBound(); AxisSpace space = this.axis.reserveSpace( g2, null, new Rectangle2D.Double(0, 0, 100, maxHeight), RectangleEdge.RIGHT, null); return new Size2D( this.stripWidth + this.axisOffset + space.getLeft() + space.getRight(), maxHeight); } else { throw new RuntimeException("Unrecognised position."); } }
/** Replaces the dataset and checks that the data range is as expected. */ 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); this.chart.getCategoryPlot().setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = this.chart.getCategoryPlot().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); }
/** * Shifts the range by the specified amount. * * @param base the base range (<code>null</code> not permitted). * @param delta the shift amount. * @param allowZeroCrossing a flag that determines whether or not the bounds of the range are * allowed to cross zero after adjustment. * @return A new range. */ public static Range shift(Range base, double delta, boolean allowZeroCrossing) { ParamChecks.nullNotPermitted(base, "base"); if (allowZeroCrossing) { return new Range(base.getLowerBound() + delta, base.getUpperBound() + delta); } else { return new Range( shiftWithNoZeroCrossing(base.getLowerBound(), delta), shiftWithNoZeroCrossing(base.getUpperBound(), delta)); } }
/** * Combines two ranges. This method has a special handling for Double.NaN. * * @param range1 the first range (<code>null</code> permitted). * @param range2 the second range (<code>null</code> permitted). * @return A new range (possibly <code>null</code>). * @since 1.0.15 */ public static Range combineIgnoringNaN(Range range1, Range range2) { if (range1 == null) { return range2; } if (range2 == null) { return range1; } double l = min(range1.getLowerBound(), range2.getLowerBound()); double u = max(range1.getUpperBound(), range2.getUpperBound()); return new Range(l, u); }
/** * Returns a range that includes all the values in the specified <code>range</code> AND the * specified <code>value</code>. * * @param range the range (<code>null</code> permitted). * @param value the value that must be included. * @return A range. * @since 1.0.1 */ public static Range expandToInclude(Range range, double value) { if (range == null) { return new Range(value, value); } if (value < range.getLowerBound()) { return new Range(value, range.getUpperBound()); } else if (value > range.getUpperBound()) { return new Range(range.getLowerBound(), value); } else { return range; } }
private Range trimToContentHeight(Range r) { if (r == null) { return null; } double lowerBound = 0.0; double upperBound = Double.POSITIVE_INFINITY; if (r.getLowerBound() > 0.0) { lowerBound = trimToContentHeight(r.getLowerBound()); } if (r.getUpperBound() < Double.POSITIVE_INFINITY) { upperBound = trimToContentHeight(r.getUpperBound()); } return new Range(lowerBound, upperBound); }
/** * Converts a data value to a coordinate in Java2D space, assuming that the axis runs along one * edge of the specified plotArea. Note that it is possible for the coordinate to fall outside the * plotArea. * * @param value the data value. * @param plotArea the area for plotting the data. * @param edge the axis location. * @return The Java2D coordinate. */ @Override public double valueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) { Range range = getRange(); double axisMin = switchedLog10(range.getLowerBound()); double axisMax = switchedLog10(range.getUpperBound()); double min = 0.0; double max = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { min = plotArea.getMinX(); max = plotArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { min = plotArea.getMaxY(); max = plotArea.getMinY(); } value = switchedLog10(value); if (isInverted()) { return max - (((value - axisMin) / (axisMax - axisMin)) * (max - min)); } else { return min + (((value - axisMin) / (axisMax - axisMin)) * (max - min)); } }
/** * Scales the range by the specified factor. * * @param base the base range (<code>null</code> not permitted). * @param factor the scaling factor (must be non-negative). * @return A new range. * @since 1.0.9 */ public static Range scale(Range base, double factor) { ParamChecks.nullNotPermitted(base, "base"); if (factor < 0) { throw new IllegalArgumentException("Negative 'factor' argument."); } return new Range(base.getLowerBound() * factor, base.getUpperBound() * factor); }
/** * Converts a coordinate from Java 2D space to data space. * * @param java2DValue the coordinate in Java2D space. * @param dataArea the data area. * @param edge the edge. * @return The data value. */ public double java2DToValue(double java2DValue, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); double vmax = range.getUpperBound(); double vp = getCycleBound(); double jmin = 0.0; double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmin = dataArea.getMaxY(); jmax = dataArea.getMinY(); } if (isInverted()) { double jbreak = jmax - (vmax - vp) * (jmax - jmin) / this.period; if (java2DValue >= jbreak) { return vp + (jmax - java2DValue) * this.period / (jmax - jmin); } else { return vp - (java2DValue - jmin) * this.period / (jmax - jmin); } } else { double jbreak = (vmax - vp) * (jmax - jmin) / this.period + jmin; if (java2DValue <= jbreak) { return vp + (java2DValue - jmin) * this.period / (jmax - jmin); } else { return vp - (jmax - java2DValue) * this.period / (jmax - jmin); } } }
/** * Converts a coordinate in Java2D space to the corresponding data value, assuming that the axis * runs along one edge of the specified plotArea. * * @param java2DValue the coordinate in Java2D space. * @param plotArea the area in which the data is plotted. * @param edge the axis location. * @return The data value. */ @Override public double java2DToValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) { Range range = getRange(); double axisMin = switchedLog10(range.getLowerBound()); double axisMax = switchedLog10(range.getUpperBound()); double plotMin = 0.0; double plotMax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { plotMin = plotArea.getX(); plotMax = plotArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { plotMin = plotArea.getMaxY(); plotMax = plotArea.getMinY(); } if (isInverted()) { return switchedPow10( axisMax - ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin)); } else { return switchedPow10( axisMin + ((java2DValue - plotMin) / (plotMax - plotMin)) * (axisMax - axisMin)); } }
/** Rescales the axis to ensure that all data is visible. */ @Override protected void autoAdjustRange() { Plot plot = getPlot(); if (plot == null) { return; // no plot, no data } if (plot instanceof ValueAxisPlot) { ValueAxisPlot vap = (ValueAxisPlot) plot; Range r = vap.getDataRange(this); if (r == null) { r = getDefaultAutoRange(); } long upper = Math.round(r.getUpperBound()); long lower = Math.round(r.getLowerBound()); this.first = createInstance( this.autoRangeTimePeriodClass, new Date(lower), this.timeZone, this.locale); this.last = createInstance( this.autoRangeTimePeriodClass, new Date(upper), this.timeZone, this.locale); setRange(r, false, false); } }
/** * Sets a new axis range. The period is extended to fit the range size, if necessary. * * @param range the range. * @param turnOffAutoRange switch off the auto range. * @param notify notify? * @see org.jfree.chart.axis.ValueAxis#setRange(Range, boolean, boolean) */ public void setRange(Range range, boolean turnOffAutoRange, boolean notify) { double size = range.getUpperBound() - range.getLowerBound(); if (size > this.period) { this.period = size; } super.setRange(range, turnOffAutoRange, notify); }
protected int calculateVisibleTickCount() { double unit = getTickUnit().getSize(); Range range = getRange(); return (int) ((Math.floor(range.getUpperBound() / unit) - Math.ceil(range.getLowerBound() / unit)) + NormalizedMatrixSeries.DEFAULT_SCALE_FACTOR); }
/** * Returns the maximum x-value in the dataset. * * @param includeInterval a flag that determines whether or not the x-interval is taken into * account. * @return The maximum value. */ public double getDomainUpperBound(boolean includeInterval) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getUpperBound(); } return result; }
/** * Returns the content size for the title. This will reflect the fact that a text title positioned * on the left or right of a chart will be rotated 90 degrees. * * @param g2 the graphics device. * @param widthRange the width range. * @param heightRange the height range. * @return The content size. */ protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) { RectangleEdge position = getPosition(); if (position == RectangleEdge.TOP || position == RectangleEdge.BOTTOM) { float maxWidth = (float) widthRange.getUpperBound(); g2.setFont(this.font); this.content = TextUtilities.createTextBlock( this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2)); this.content.setLineAlignment(this.textAlignment); Size2D contentSize = this.content.calculateDimensions(g2); if (this.expandToFitSpace) { return new Size2D(maxWidth, contentSize.getHeight()); } else { return contentSize; } } else if (position == RectangleEdge.LEFT || position == RectangleEdge.RIGHT) { float maxWidth = (float) heightRange.getUpperBound(); g2.setFont(this.font); this.content = TextUtilities.createTextBlock( this.text, this.font, this.paint, maxWidth, this.maximumLinesToDisplay, new G2TextMeasurer(g2)); this.content.setLineAlignment(this.textAlignment); Size2D contentSize = this.content.calculateDimensions(g2); // transpose the dimensions, because the title is rotated if (this.expandToFitSpace) { return new Size2D(contentSize.getHeight(), maxWidth); } else { return new Size2D(contentSize.height, contentSize.width); } } else { throw new RuntimeException("Unrecognised exception."); } }
/** * 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) { 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); }
/** * Creates a new range by adding margins to an existing range. * * @param range the range (<code>null</code> not permitted). * @param lowerMargin the lower margin (expressed as a percentage of the range length). * @param upperMargin the upper margin (expressed as a percentage of the range length). * @return The expanded range. */ public static Range expand(Range range, double lowerMargin, double upperMargin) { ParamChecks.nullNotPermitted(range, "range"); double length = range.getLength(); double lower = range.getLowerBound() - length * lowerMargin; double upper = range.getUpperBound() + length * upperMargin; if (lower > upper) { lower = lower / 2.0 + upper / 2.0; upper = lower; } return new Range(lower, upper); }
/** * 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). */ public Range findRangeBounds(XYDataset dataset) { if (dataset == null) { return null; } Range r = DatasetUtilities.findRangeBounds(dataset, false); if (r == null) { return null; } double offset = 0; // TODO getSeriesShape(n).getBounds().height / 2; return new Range(r.getLowerBound() + offset, r.getUpperBound() + offset); }
/** A test for bug 3072674. */ @Test public void test3072674() { DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); dataset.add(1.0, Double.NaN, "R1", "C1"); assertEquals(1.0, dataset.getRangeLowerBound(true), EPSILON); assertEquals(1.0, dataset.getRangeUpperBound(true), EPSILON); Range r = dataset.getRangeBounds(true); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.0, r.getUpperBound(), EPSILON); }
/** * Sets the range for the axis, if requested, sends an {@link AxisChangeEvent} to all registered * listeners. As a side-effect, the auto-range flag is set to <code>false</code> (optional). * * @param range the range (<code>null</code> not permitted). * @param turnOffAutoRange a flag that controls whether or not the auto range is turned off. * @param notify a flag that controls whether or not listeners are notified. */ public void setRange(Range range, boolean turnOffAutoRange, boolean notify) { long upper = Math.round(range.getUpperBound()); long lower = Math.round(range.getLowerBound()); this.first = createInstance(this.autoRangeTimePeriodClass, new Date(lower), this.timeZone, this.locale); this.last = createInstance(this.autoRangeTimePeriodClass, new Date(upper), this.timeZone, this.locale); super.setRange( new Range(this.first.getFirstMillisecond(), this.last.getLastMillisecond() + 1.0), turnOffAutoRange, notify); }
/** * Returns the range of the values in the dataset's domain, including or excluding the interval * around each x-value as specified. * * @param includeInterval a flag that determines whether or not the x-interval should be taken * into account. * @return The range. */ @Override public Range getDomainBounds(boolean includeInterval) { // first get the range without the interval, then expand it for the // interval width Range range = DatasetUtilities.findDomainBounds(this.dataset, false); if (includeInterval && range != null) { double lowerAdj = getIntervalWidth() * getIntervalPositionFactor(); double upperAdj = getIntervalWidth() - lowerAdj; range = new Range(range.getLowerBound() - lowerAdj, range.getUpperBound() + upperAdj); } return range; }
/** * 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; } }
/** Replaces the dataset and checks that it has changed as expected. */ public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue( "Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue( "Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); }
/** Returns a peak list with the top peaks defined by the parameter "threshold" */ PeakList getTopThresholdPeakList(int threshold) { PeakList selectedPeakList = (PeakList) peakListSelector.getSelectedItem(); if (selectedPeakList == null) return null; SimplePeakList newList = new SimplePeakList(selectedPeakList.getName(), selectedPeakList.getRawDataFiles()); Vector<PeakListRow> peakRows = new Vector<PeakListRow>(); Range<Double> mzRange = selectedPeakList.getRowsMZRange(); Range<Double> rtRange = selectedPeakList.getRowsRTRange(); PeakThresholdMode selectedPeakOption = (PeakThresholdMode) thresholdCombo.getSelectedItem(); if (selectedPeakOption == PeakThresholdMode.TOP_PEAKS_AREA) { XYPlot xyPlot = masterFrame.getPlot().getXYPlot(); org.jfree.data.Range yAxis = xyPlot.getRangeAxis().getRange(); org.jfree.data.Range xAxis = xyPlot.getDomainAxis().getRange(); rtRange = Range.closed(xAxis.getLowerBound(), xAxis.getUpperBound()); mzRange = Range.closed(yAxis.getLowerBound(), yAxis.getUpperBound()); } for (PeakListRow peakRow : selectedPeakList.getRows()) { if (mzRange.contains(peakRow.getAverageMZ()) && rtRange.contains(peakRow.getAverageRT())) { peakRows.add(peakRow); } } Collections.sort( peakRows, new PeakListRowSorter(SortingProperty.Intensity, SortingDirection.Descending)); if (threshold > peakRows.size()) threshold = peakRows.size(); for (int i = 0; i < threshold; i++) { newList.addRow(peakRows.elementAt(i)); } return newList; }
public double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge) { Range range = getRange(); double axisMin = range.getLowerBound(); double axisMax = range.getUpperBound(); double min = 0.0d; double max = 0.0d; if (RectangleEdge.isTopOrBottom(edge)) { min = area.getX(); max = area.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { min = area.getMaxY(); max = area.getY(); } if (isInverted()) { return axisMax - (((java2DValue - min) / (max - min)) * (axisMax - axisMin)); } return (((java2DValue - min) / (max - min)) * (axisMax - axisMin)) + axisMin; }
private void handleAxisRangeControlChanges( PropertyChangeEvent evt, AxisRangeControl axisRangeControl, ValueAxis valueAxis, Range computedAutoRange) { final String propertyName = evt.getPropertyName(); switch (propertyName) { case AxisRangeControl.PROPERTY_NAME_AUTO_MIN_MAX: if (axisRangeControl.isAutoMinMax()) { final double min = computedAutoRange.getLowerBound(); final double max = computedAutoRange.getUpperBound(); axisRangeControl.adjustComponents(min, max, 3); } break; case AxisRangeControl.PROPERTY_NAME_MIN: valueAxis.setLowerBound(axisRangeControl.getMin()); break; case AxisRangeControl.PROPERTY_NAME_MAX: valueAxis.setUpperBound(axisRangeControl.getMax()); break; } }
/** * Translates a value from data space to Java 2D space. * * @param value the data value. * @param dataArea the data area. * @param edge the edge. * @return The Java 2D value. */ public double valueToJava2D(double value, Rectangle2D dataArea, RectangleEdge edge) { Range range = getRange(); double vmin = range.getLowerBound(); double vmax = range.getUpperBound(); double vp = getCycleBound(); if ((value < vmin) || (value > vmax)) { return Double.NaN; } double jmin = 0.0; double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmax = dataArea.getMinY(); jmin = dataArea.getMaxY(); } if (isInverted()) { if (value == vp) { return this.boundMappedToLastCycle ? jmin : jmax; } else if (value > vp) { return jmax - (value - vp) * (jmax - jmin) / this.period; } else { return jmin + (vp - value) * (jmax - jmin) / this.period; } } else { if (value == vp) { return this.boundMappedToLastCycle ? jmax : jmin; } else if (value >= vp) { return jmin + (value - vp) * (jmax - jmin) / this.period; } else { return jmax - (vp - value) * (jmax - jmin) / this.period; } } }
protected double estimateMaximumTickLabelWidth(Graphics2D g2, TickUnit unit) { RectangleInsets tickLabelInsets = getTickLabelInsets(); double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight(); if (isVerticalTickLabels()) { FontRenderContext frc = g2.getFontRenderContext(); return result + ((double) getTickLabelFont().getLineMetrics("0", frc).getHeight()); } String lowerStr; String upperStr; FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { lowerStr = formatter.format(lower); upperStr = formatter.format(upper); } else { lowerStr = unit.valueToString(lower); upperStr = unit.valueToString(upper); } return result + Math.max((double) fm.stringWidth(lowerStr), (double) fm.stringWidth(upperStr)); }
/** * Constructs a new range that is based on another {@link Range}. The other range does not have to * be a {@link DateRange}. If it is not, the upper and lower bounds are evaluated as milliseconds * since midnight GMT, 1-Jan-1970. * * @param other the other range (<code>null</code> not permitted). */ public DateRange(Range other) { this(other.getLowerBound(), other.getUpperBound()); }
/** * Returns <code>true</code> if the range intersects with the specified range, and <code>false * </code> otherwise. * * @param range another range (<code>null</code> not permitted). * @return A boolean. * @since 1.0.9 */ public boolean intersects(Range range) { return intersects(range.getLowerBound(), range.getUpperBound()); }