Java Code Examples for org.jfree.chart.plot.ValueAxisPlot#getDataRange()

The following examples show how to use org.jfree.chart.plot.ValueAxisPlot#getDataRange() . 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: PeriodAxis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Rescales the axis to ensure that all data is visible.
 */
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.last = createInstance(this.autoRangeTimePeriodClass, 
                new Date(upper), this.timeZone);
        setRange(r, false, false);
    }

}
 
Example 2
Source File: PeriodAxis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Rescales the axis to ensure that all data is visible.
 */
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);
    }

}
 
Example 3
Source File: PeriodAxis.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 4
Source File: PeriodAxis.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 5
Source File: PeriodAxis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 6
Source File: PeriodAxis.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 7
Source File: PeriodAxis.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }

}
 
Example 8
Source File: LogAxis.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.
 */
@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();
        }

        double upper = r.getUpperBound();
        double lower = Math.max(r.getLowerBound(), this.smallestValue);
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = Math.max(upper - fixedAutoRange, this.smallestValue);
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
            }

            // apply the margins - these should apply to the exponent range
            double logUpper = calculateLog(upper);
            double logLower = calculateLog(lower);
            double logRange = logUpper - logLower;
            logUpper = logUpper + getUpperMargin() * logRange;
            logLower = logLower - getLowerMargin() * logRange;
            upper = calculateValueNoINF(logUpper);
            lower = calculateValueNoINF(logLower);
        }
        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 9
Source File: NumberAxis.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);
        }

        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 10
Source File: LogAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.
 */
@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();
        }

        double upper = r.getUpperBound();
        double lower = Math.max(r.getLowerBound(), this.smallestValue);
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = Math.max(upper - fixedAutoRange, this.smallestValue);
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
            }

            // apply the margins - these should apply to the exponent range
            double logUpper = calculateLog(upper);
            double logLower = calculateLog(lower);
            double logRange = logUpper - logLower;
            logUpper = logUpper + getUpperMargin() * logRange;
            logLower = logLower - getLowerMargin() * logRange;
            upper = calculateValueNoINF(logUpper);
            lower = calculateValueNoINF(logLower);
        }
        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 11
Source File: NumberAxis.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);
        }

        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 12
Source File: NumberAxis.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);
        }

        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 13
Source File: LogAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.
 */
@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();
        }

        double upper = r.getUpperBound();
        double lower = Math.max(r.getLowerBound(), this.smallestValue);
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = Math.max(upper - fixedAutoRange, this.smallestValue);
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
            }

            // apply the margins - these should apply to the exponent range
            double logUpper = calculateLog(upper);
            double logLower = calculateLog(lower);
            double logRange = logUpper - logLower;
            logUpper = logUpper + getUpperMargin() * logRange;
            logLower = logLower - getLowerMargin() * logRange;
            upper = calculateValueNoINF(logUpper);
            lower = calculateValueNoINF(logLower);
        }
        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 14
Source File: NumberAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Rescales the axis to ensure that all data is visible.
 */
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();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);
        }

        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 15
Source File: NumberAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);
        }

        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 16
Source File: LogAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.
 */
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();
        }

        double upper = r.getUpperBound();
        double lower = Math.max(r.getLowerBound(), this.smallestValue);
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = Math.max(upper - fixedAutoRange, this.smallestValue);
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
            }

            // apply the margins - these should apply to the exponent range
            double logUpper = calculateLog(upper);
            double logLower = calculateLog(lower);
            double logRange = logUpper - logLower;
            logUpper = logUpper + getUpperMargin() * logRange;
            logLower = logLower - getLowerMargin() * logRange;
            upper = calculateValue(logUpper);
            lower = calculateValue(logLower);
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 17
Source File: NumberAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Rescales the axis to ensure that all data is visible.
 */
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();
        }
        
        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);                   
        }
        
        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 18
Source File: LogAxis.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.
 */
@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();
        }

        double upper = r.getUpperBound();
        double lower = Math.max(r.getLowerBound(), this.smallestValue);
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = Math.max(upper - fixedAutoRange, this.smallestValue);
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
            }

            // apply the margins - these should apply to the exponent range
            double logUpper = calculateLog(upper);
            double logLower = calculateLog(lower);
            double logRange = logUpper - logLower;
            logUpper = logUpper + getUpperMargin() * logRange;
            logLower = logLower - getLowerMargin() * logRange;
            upper = calculateValueNoINF(logUpper);
            lower = calculateValueNoINF(logLower);
        }
        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 19
Source File: LogAxis.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adjusts the axis range to match the data range that the axis is
 * required to display.
 */
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();
        }
        
        double upper = r.getUpperBound();
        double lower = Math.max(r.getLowerBound(), this.smallestValue);
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = Math.max(upper - fixedAutoRange, this.smallestValue);
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
            }

            // apply the margins - these should apply to the exponent range
            double logUpper = calculateLog(upper);
            double logLower = calculateLog(lower);
            double logRange = logUpper - logLower;
            logUpper = logUpper + getUpperMargin() * logRange;
            logLower = logLower - getLowerMargin() * logRange;
            upper = calculateValue(logUpper);
            lower = calculateValue(logLower);
        }

        setRange(new Range(lower, upper), false, false);
    }

}
 
Example 20
Source File: NumberAxis.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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();
        }

        double upper = r.getUpperBound();
        double lower = r.getLowerBound();
        if (this.rangeType == RangeType.POSITIVE) {
            lower = Math.max(0.0, lower);
            upper = Math.max(0.0, upper);
        }
        else if (this.rangeType == RangeType.NEGATIVE) {
            lower = Math.min(0.0, lower);
            upper = Math.min(0.0, upper);
        }

        if (getAutoRangeIncludesZero()) {
            lower = Math.min(lower, 0.0);
            upper = Math.max(upper, 0.0);
        }
        double range = upper - lower;

        // if fixed auto range, then derive lower bound...
        double fixedAutoRange = getFixedAutoRange();
        if (fixedAutoRange > 0.0) {
            lower = upper - fixedAutoRange;
        }
        else {
            // ensure the autorange is at least <minRange> in size...
            double minRange = getAutoRangeMinimumSize();
            if (range < minRange) {
                double expand = (minRange - range) / 2;
                upper = upper + expand;
                lower = lower - expand;
                if (lower == upper) { // see bug report 1549218
                    double adjust = Math.abs(lower) / 10.0;
                    lower = lower - adjust;
                    upper = upper + adjust;
                }
                if (this.rangeType == RangeType.POSITIVE) {
                    if (lower < 0.0) {
                        upper = upper - lower;
                        lower = 0.0;
                    }
                }
                else if (this.rangeType == RangeType.NEGATIVE) {
                    if (upper > 0.0) {
                        lower = lower - upper;
                        upper = 0.0;
                    }
                }
            }

            if (getAutoRangeStickyZero()) {
                if (upper <= 0.0) {
                    upper = Math.min(0.0, upper + getUpperMargin() * range);
                }
                else {
                    upper = upper + getUpperMargin() * range;
                }
                if (lower >= 0.0) {
                    lower = Math.max(0.0, lower - getLowerMargin() * range);
                }
                else {
                    lower = lower - getLowerMargin() * range;
                }
            }
            else {
                upper = upper + getUpperMargin() * range;
                lower = lower - getLowerMargin() * range;
            }
        }

        setRange(new Range(lower, upper), false, false);
    }

}