Beispiel #1
0
  /**
   * Zooms in on the current range.
   *
   * @param lowerPercent the new lower bound.
   * @param upperPercent the new upper bound.
   */
  public void zoomRange(double lowerPercent, double upperPercent) {
    double startLog = switchedLog10(getRange().getLowerBound());
    double lengthLog = switchedLog10(getRange().getUpperBound()) - startLog;
    Range adjusted;

    if (isInverted()) {
      adjusted =
          new Range(
              switchedPow10(startLog + (lengthLog * (1 - upperPercent))),
              switchedPow10(startLog + (lengthLog * (1 - lowerPercent))));
    } else {
      adjusted =
          new Range(
              switchedPow10(startLog + (lengthLog * lowerPercent)),
              switchedPow10(startLog + (lengthLog * upperPercent)));
    }

    setRange(adjusted);
  }
Beispiel #2
0
  /** Rescales the axis to ensure that all data is visible. */
  public void autoAdjustRange() {

    Plot plot = getPlot();
    if (plot == null) {
      return; // no plot, no data.
    }

    if (plot instanceof ValueAxisPlot) {
      ValueAxisPlot vap = (ValueAxisPlot) plot;

      double lower;
      Range r = vap.getDataRange(this);
      if (r == null) {
        // no real data present
        r = getDefaultAutoRange();
        lower = r.getLowerBound(); // get lower bound value
      } else {
        // actual data is present
        lower = r.getLowerBound(); // get lower bound value
        if (this.strictValuesFlag && !this.allowNegativesFlag && lower <= 0.0) {
          // strict flag set, allow-negatives not set and values <= 0
          throw new RuntimeException(
              "Values less than or equal to " + "zero not allowed with logarithmic axis");
        }
      }

      // apply lower margin by decreasing lower bound:
      final double lowerMargin;
      if (lower > 0.0 && (lowerMargin = getLowerMargin()) > 0.0) {
        // lower bound and margin OK; get log10 of lower bound
        final double logLower = (Math.log(lower) / LOG10_VALUE);
        double logAbs; // get absolute value of log10 value
        if ((logAbs = Math.abs(logLower)) < 1.0) {
          logAbs = 1.0; // if less than 1.0 then make it 1.0
        } // subtract out margin and get exponential value:
        lower = Math.pow(10, (logLower - (logAbs * lowerMargin)));
      }

      // if flag then change to log version of lowest value
      // to make range begin at a 10^n value:
      if (this.autoRangeNextLogFlag) {
        lower = computeLogFloor(lower);
      }

      if (!this.allowNegativesFlag && lower >= 0.0 && lower < SMALL_LOG_VALUE) {
        // negatives not allowed and lower range bound is zero
        lower = r.getLowerBound(); // use data range bound instead
      }

      double upper = r.getUpperBound();

      // apply upper margin by increasing upper bound:
      final double upperMargin;
      if (upper > 0.0 && (upperMargin = getUpperMargin()) > 0.0) {
        // upper bound and margin OK; get log10 of upper bound
        final double logUpper = (Math.log(upper) / LOG10_VALUE);
        double logAbs; // get absolute value of log10 value
        if ((logAbs = Math.abs(logUpper)) < 1.0) {
          logAbs = 1.0; // if less than 1.0 then make it 1.0
        } // add in margin and get exponential value:
        upper = Math.pow(10, (logUpper + (logAbs * upperMargin)));
      }

      if (!this.allowNegativesFlag && upper < 1.0 && upper > 0.0 && lower > 0.0) {
        // negatives not allowed and upper bound between 0 & 1
        // round up to nearest significant digit for bound:
        // get negative exponent:
        double expVal = Math.log(upper) / LOG10_VALUE;
        expVal = Math.ceil(-expVal + 0.001); // get positive exponent
        expVal = Math.pow(10, expVal); // create multiplier value
        // multiply, round up, and divide for bound value:
        upper = (expVal > 0.0) ? Math.ceil(upper * expVal) / expVal : Math.ceil(upper);
      } else {
        // negatives allowed or upper bound not between 0 & 1
        // if flag then change to log version of highest value to
        // make range begin at a 10^n value; else use nearest int
        upper = (this.autoRangeNextLogFlag) ? computeLogCeil(upper) : Math.ceil(upper);
      }
      // ensure the autorange is at least <minRange> in size...
      double minRange = getAutoRangeMinimumSize();
      if (upper - lower < minRange) {
        upper = (upper + lower + minRange) / 2;
        lower = (upper + lower - minRange) / 2;
        // if autorange still below minimum then adjust by 1%
        // (can be needed when minRange is very small):
        if (upper - lower < minRange) {
          double absUpper = Math.abs(upper);
          // need to account for case where upper==0.0
          double adjVal = (absUpper > SMALL_LOG_VALUE) ? absUpper / 100.0 : 0.01;
          upper = (upper + lower + adjVal) / 2;
          lower = (upper + lower - adjVal) / 2;
        }
      }

      setRange(new Range(lower, upper), false, false);
      setupSmallLogFlag(); // setup flag based on bounds values
    }
  }