MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getMinAndMax

Method getMinAndMax

ij/src/main/java/ij/gui/Plot.java:2369–2408  ·  view source on GitHub ↗

Gets the minimum and maximum values from the first XY_DATA or ARROWS plotObject or all such plotObjects; axisRangeFlags determine for which axis to calculate the min&max (X_RANGE for x axis, Y_RANGE for y axis); for the other axes the limit is taken from defaultMinMax Array elements returned are xMi

(boolean allObjects, int axisRangeFlags)

Source from the content-addressed store, hash-verified

2367 * Array elements returned are xMin, xMax, yMin, yMax. Also sets enlargeRange to tell which limits should be enlarged
2368 * beyond the minimum or maximum of the data */
2369 double[] getMinAndMax(boolean allObjects, int axisRangeFlags) {
2370 boolean invertedXAxis = currentMinMax[1] < currentMinMax[0];
2371 boolean invertedYAxis = currentMinMax[3] < currentMinMax[2];
2372 double xSign = invertedXAxis ? -1 : 1;
2373 double ySign = invertedYAxis ? -1 : 1;
2374 double[] allMinMax = new double[]{xSign*Double.MAX_VALUE, -xSign*Double.MAX_VALUE, ySign*Double.MAX_VALUE, -ySign*Double.MAX_VALUE};
2375 for (int i=0; i<allMinMax.length; i++)
2376 if (((axisRangeFlags>>i/2) & 1)==0) //keep default min & max for this axis
2377 allMinMax[i] = defaultMinMax[i];
2378 enlargeRange = new int[allMinMax.length];
2379 for (PlotObject plotObject : allPlotObjects) {
2380 if ((plotObject.type == PlotObject.XY_DATA || plotObject.type == PlotObject.ARROWS) && !plotObject.hasFlag(PlotObject.HIDDEN)) {
2381 getMinAndMax(allMinMax, enlargeRange, plotObject, axisRangeFlags);
2382 if (!allObjects) break;
2383 }
2384 }
2385 if ((axisRangeFlags & X_RANGE) != 0) {
2386 String[] xCats = labelsInBraces('x'); // if we have categories at the axis, make some space for this text
2387 if (xCats != null) {
2388 allMinMax[0] = Math.min(allMinMax[0], -0.5);
2389 allMinMax[1] = Math.min(allMinMax[1], xCats.length+0.5);
2390 }
2391 }
2392 if ((axisRangeFlags & Y_RANGE) != 0) {
2393 String[] yCats = labelsInBraces('y');
2394 if (yCats != null) {
2395 allMinMax[2] = Math.min(allMinMax[2], -0.5);
2396 allMinMax[3] = Math.min(allMinMax[3], yCats.length+0.5);
2397 }
2398 }
2399 if (allMinMax[0]==Double.MAX_VALUE && allMinMax[1]==-Double.MAX_VALUE) { // no x values at all? keep previous
2400 allMinMax[0] = defaultMinMax[0];
2401 allMinMax[1] = defaultMinMax[1];
2402 }
2403 if (allMinMax[2]==Double.MAX_VALUE && allMinMax[3]==-Double.MAX_VALUE) { // no y values at all? keep previous
2404 allMinMax[2] = defaultMinMax[2];
2405 allMinMax[3] = defaultMinMax[3];
2406 }
2407 return allMinMax;
2408 }
2409
2410 /** Enlarges the current minimum and maximum ranges to include the data range of the last plotObject added,
2411 * if it is an XY_DATA or ARROWS plotObject.

Callers 4

setLimitsNoUpdateMethod · 0.95
setLimitsToFitMethod · 0.95
getInitialMinAndMaxMethod · 0.95

Calls 4

labelsInBracesMethod · 0.95
hasFlagMethod · 0.65
minMethod · 0.45
absMethod · 0.45

Tested by

no test coverage detected