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

Method autoLegendPosition

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

The position code of the legend position where the smallest amount of foreground pixels is covered

(int width, int height, int frameThickness)

Source from the content-addressed store, hash-verified

4123
4124 /** The position code of the legend position where the smallest amount of foreground pixels is covered */
4125 int autoLegendPosition(int width, int height, int frameThickness) {
4126 int background = ip instanceof ColorProcessor ? (0xffffff) : (ip.isInvertedLut() ? 0 : 0xff);
4127 int grid = ip instanceof ColorProcessor ? (gridColor.getRGB() & 0xffffff) : ip.getBestIndex(gridColor);
4128 int bestPosition = 0;
4129 int minCoveredPixels = Integer.MAX_VALUE;
4130 for (int positionCode : new int[]{TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT}) {
4131 Rectangle rect = legendRect(positionCode, width, height, frameThickness);
4132 int coveredPixels = 0;
4133 for (int y = rect.y - frameThickness/2; y <= rect.y + rect.height + frameThickness/2; y++)
4134 for (int x = rect.x - frameThickness/2; x <= rect.x + rect.width + frameThickness/2; x++) {
4135 int pixel = ip.getPixel(x, y) & 0xffffff;
4136 if (pixel != background && pixel != grid)
4137 coveredPixels ++;
4138 }
4139 if (coveredPixels < minCoveredPixels) {
4140 minCoveredPixels = coveredPixels;
4141 bestPosition = positionCode;
4142 }
4143 }
4144 return bestPosition;
4145 }
4146
4147 /** Returns the x, y coordinates at the cursor position or the nearest point as a String */
4148 @AstroImageJ(reason = "Fix coordinate lookup for scaled coordinates", modified = true)

Callers 1

drawLegendMethod · 0.95

Calls 5

legendRectMethod · 0.95
getRGBMethod · 0.80
isInvertedLutMethod · 0.45
getBestIndexMethod · 0.45
getPixelMethod · 0.45

Tested by

no test coverage detected