📄 intervalxydelegate.java
字号:
/**
* Returns the interval width. This method will return either the
* auto calculated interval width or the manually specified interval
* width, depending on the {@link #isAutoWidth()} result.
*
* @return The interval width to use.
*/
public double getIntervalWidth() {
if (isAutoWidth() && !Double.isInfinite(this.autoIntervalWidth)) {
// everything is fine: autoWidth is on, and an autoIntervalWidth
// was set.
return this.autoIntervalWidth;
}
else {
// either autoWidth is off or autoIntervalWidth was not set.
return this.fixedIntervalWidth;
}
}
/**
* Returns the start value of the x-interval for an item within a series.
*
* @param series the series index.
* @param item the item index.
*
* @return The start value of the x-interval (possibly <code>null</code>).
*
* @see #getStartXValue(int, int)
*/
public Number getStartX(int series, int item) {
Number startX = null;
Number x = this.dataset.getX(series, item);
if (x != null) {
startX = new Double(x.doubleValue()
- (getIntervalPositionFactor() * getIntervalWidth()));
}
return startX;
}
/**
* Returns the start value of the x-interval for an item within a series.
*
* @param series the series index.
* @param item the item index.
*
* @return The start value of the x-interval.
*
* @see #getStartX(int, int)
*/
public double getStartXValue(int series, int item) {
return this.dataset.getXValue(series, item)
- getIntervalPositionFactor() * getIntervalWidth();
}
/**
* Returns the end value of the x-interval for an item within a series.
*
* @param series the series index.
* @param item the item index.
*
* @return The end value of the x-interval (possibly <code>null</code>).
*
* @see #getEndXValue(int, int)
*/
public Number getEndX(int series, int item) {
Number endX = null;
Number x = this.dataset.getX(series, item);
if (x != null) {
endX = new Double(x.doubleValue()
+ ((1.0 - getIntervalPositionFactor()) * getIntervalWidth()));
}
return endX;
}
/**
* Returns the end value of the x-interval for an item within a series.
*
* @param series the series index.
* @param item the item index.
*
* @return The end value of the x-interval.
*
* @see #getEndX(int, int)
*/
public double getEndXValue(int series, int item) {
return this.dataset.getXValue(series, item)
+ (1.0 - getIntervalPositionFactor()) * getIntervalWidth();
}
/**
* Returns the minimum x-value in the dataset.
*
* @param includeInterval a flag that determines whether or not the
* x-interval is taken into account.
*
* @return The minimum value.
*/
public double getDomainLowerBound(boolean includeInterval) {
double result = Double.NaN;
Range r = getDomainBounds(includeInterval);
if (r != null) {
result = r.getLowerBound();
}
return result;
}
/**
* 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 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.
*/
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;
}
/**
* Handles events from the dataset by recalculating the interval if
* necessary.
*
* @param e the event.
*/
public void datasetChanged(DatasetChangeEvent e) {
// TODO: by coding the event with some information about what changed
// in the dataset, we could make the recalculation of the interval
// more efficient in some cases...
if (this.autoWidth) {
this.autoIntervalWidth = recalculateInterval();
}
}
/**
* Recalculate the minimum width "from scratch".
*/
private double recalculateInterval() {
double result = Double.POSITIVE_INFINITY;
int seriesCount = this.dataset.getSeriesCount();
for (int series = 0; series < seriesCount; series++) {
result = Math.min(result, calculateIntervalForSeries(series));
}
return result;
}
/**
* Calculates the interval width for a given series.
*
* @param series the series index.
*/
private double calculateIntervalForSeries(int series) {
double result = Double.POSITIVE_INFINITY;
int itemCount = this.dataset.getItemCount(series);
if (itemCount > 1) {
double prev = this.dataset.getXValue(series, 0);
for (int item = 1; item < itemCount; item++) {
double x = this.dataset.getXValue(series, item);
result = Math.min(result, x - prev);
prev = x;
}
}
return result;
}
/**
* Tests the delegate for equality with an arbitrary object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof IntervalXYDelegate)) {
return false;
}
IntervalXYDelegate that = (IntervalXYDelegate) obj;
if (this.autoWidth != that.autoWidth) {
return false;
}
if (this.intervalPositionFactor != that.intervalPositionFactor) {
return false;
}
if (this.fixedIntervalWidth != that.fixedIntervalWidth) {
return false;
}
return true;
}
/**
* @return A clone of this delegate.
*
* @throws CloneNotSupportedException if the object cannot be cloned.
*/
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -