List of usage examples for org.jfree.chart.plot ValueAxisPlot getDataRange
public Range getDataRange(ValueAxis axis);
From source file:org.kalypso.ogc.sensor.diagview.jfreechart.NumberAxisDefault.java
/** * Rescales the axis to ensure that all data is visible. *//*from w w w . j ava2s .c om*/ @Override protected void autoAdjustRange() { final Plot plot = getPlot(); if (plot == null) { return; // no plot, no data } if (plot instanceof ValueAxisPlot) { final ValueAxisPlot vap = (ValueAxisPlot) plot; Range r = vap.getDataRange(this); if (r == null) { r = new Range(DEFAULT_LOWER_BOUND, DEFAULT_UPPER_BOUND); } double upper = r.getUpperBound(); double lower = r.getLowerBound(); if (autoRangeIncludesZero()) { lower = Math.min(lower, 0.0); upper = Math.max(upper, 0.0); } final double range = upper - lower; // if fixed auto range, then derive lower bound... final double fixedAutoRange = getFixedAutoRange(); if (fixedAutoRange > 0.0) { lower = upper - fixedAutoRange; } else { // ensure the autorange is at least <minRange> in size... final double minRange = getAutoRangeMinimumSize(); if (range < minRange) { // double expand = ( minRange - range ) / 2; upper = minRange; // upper + expand; lower = 0; // getlower - expand; } if (autoRangeStickyZero()) { 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; } } if (m_min != null && lower > m_min.doubleValue()) lower = m_min.doubleValue(); if (m_max != null && upper < m_max.doubleValue()) upper = m_max.doubleValue(); setRange(new Range(lower, upper), false, false); } }
From source file:org.jfree.experimental.chart.axis.LogAxis.java
/** * Adjusts the axis range to match the data range that the axis is * required to display.//from w w w . j a v a2 s.com */ 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(); 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 // upper = upper + getUpperMargin() * range; // lower = lower - getLowerMargin() * range; } setRange(new Range(lower, upper), false, false); } }
From source file:userinterface.graph.PrismLogarithmicAxis.java
/** * Adjusts the axis range to match the data range that the axis is * required to display.//from w ww.j a v a2 s. co m */ 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(); 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 //upper = upper + getUpperMargin() * range; //lower = lower - getLowerMargin() * range; } setRange(new Range(lower, upper), false, false); } }
From source file:org.gumtree.vis.plot1d.LogarithmizableAxis.java
/** * Rescales the axis to ensure that all data is visible. *//* w w w . j a va2 s . c om*/ public void autoAdjustLogRange() { 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))); } // skip values = 0 for log scale. if (lower < 10.0 && lower == 0) { double minPositive = Double.NaN; if (plot instanceof XYPlot) { XYDataset dataset = ((XYPlot) plot).getDataset(); if (dataset instanceof XYErrorDataset) { minPositive = ((XYErrorDataset) dataset).getMinPositiveValue(); } } if (!Double.isNaN(minPositive)) { lower = minPositive < SMALL_LOG_VALUE ? SMALL_LOG_VALUE : minPositive; final double margin; if (lower > 0.0 && (margin = 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 * margin))); } } } //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 if (upper < 1.0 && upper > 0.0) { 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.round(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(Math.min(lower, upper), Math.max(lower, upper)), false, false); if (lower <= upper) { setRange(new Range(lower, upper), false, false); } setupSmallLogFlag(); //setup flag based on bounds values } }