Skip to content

Commit 48e69a3

Browse files
imikejacksonclaude
andcommitted
ENH: Fix color bar positioning to avoid overlapping with Miller index labels
Add hasColorBar parameter to annotateIPFImage() that widens the right margin when a color bar will be drawn. Reposition the color bar relative to the figure's right edge instead of using absolute canvas percentages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 04ccda9 commit 48e69a3

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

Source/EbsdLib/LaueOps/LaueOps.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -956,12 +956,15 @@ std::array<float, 2> LaueOps::adjustFigureOrigin(std::array<float, 2> figureOrig
956956
}
957957

958958
// -----------------------------------------------------------------------------
959-
UInt8ArrayType::Pointer LaueOps::annotateIPFImage(UInt8ArrayType::Pointer triangleImage, int imageDim, int canvasDim, const std::string& title, bool generateEntirePlane) const
959+
UInt8ArrayType::Pointer LaueOps::annotateIPFImage(UInt8ArrayType::Pointer triangleImage, int imageDim, int canvasDim, const std::string& title, bool generateEntirePlane,
960+
bool hasColorBar) const
960961
{
961962
const float fontPtSize = static_cast<float>(canvasDim) / 24.0f;
963+
// When a color bar will be drawn, use a wider right margin to make room
964+
float rightMargin = hasColorBar ? static_cast<float>(canvasDim / 3.5f) : static_cast<float>(canvasDim / 7.0f);
962965
const std::vector<float> margins = {
963966
fontPtSize * 3, // Top
964-
static_cast<float>(canvasDim / 7.0f), // Right
967+
rightMargin, // Right
965968
fontPtSize * 2, // Bottom
966969
static_cast<float>(canvasDim / 7.0f) // Left
967970
};
@@ -1055,11 +1058,24 @@ UInt8ArrayType::Pointer LaueOps::drawColorBar(UInt8ArrayType::Pointer image, int
10551058
// Put the existing image onto the canvas
10561059
context.draw_image(rgbaImage->getPointer(0), canvasDim, canvasDim, canvasDim * 4, 0.0f, 0.0f, static_cast<float>(canvasDim), static_cast<float>(canvasDim));
10571060

1058-
// Color bar dimensions
1059-
const float barLeft = static_cast<float>(canvasDim) * 0.80f;
1060-
const float barTop = static_cast<float>(canvasDim) * 0.15f;
1061-
const float barWidth = static_cast<float>(canvasDim) * 0.04f;
1062-
const float barHeight = static_cast<float>(canvasDim) * 0.65f;
1061+
// Color bar dimensions — positioned in the right margin area
1062+
// Compute the figure right edge using the same layout as annotateIPFImage with hasColorBar=true
1063+
float rightMargin = static_cast<float>(canvasDim / 3.5f);
1064+
float leftMargin = static_cast<float>(canvasDim / 7.0f);
1065+
float topMargin = fontPtSize * 3;
1066+
float bottomMargin = fontPtSize * 2;
1067+
int legendHeight = canvasDim - static_cast<int>(topMargin) - static_cast<int>(bottomMargin);
1068+
int legendWidth = canvasDim - static_cast<int>(rightMargin) - static_cast<int>(leftMargin);
1069+
if(legendHeight > legendWidth)
1070+
{
1071+
legendHeight = legendWidth;
1072+
}
1073+
float figureRightEdge = leftMargin + static_cast<float>(legendWidth);
1074+
1075+
const float barLeft = figureRightEdge + fontPtSize * 2.5f;
1076+
const float barTop = topMargin * 1.33f;
1077+
const float barWidth = fontPtSize * 0.8f;
1078+
const float barHeight = static_cast<float>(legendHeight) * 0.75f;
10631079

10641080
// Draw color bar segments
10651081
int colorSegments = numColors;
@@ -1211,9 +1227,9 @@ std::vector<UInt8ArrayType::Pointer> LaueOps::generateAnnotatedIPFDensity(Invers
12111227
std::string titlePrefix = config.phaseName.empty() ? "" : config.phaseName + " - ";
12121228

12131229
// Step 6: Annotate each image
1214-
UInt8ArrayType::Pointer annotated0 = annotateIPFImage(image0, imageDim, canvasDim, titlePrefix + label0, false);
1215-
UInt8ArrayType::Pointer annotated1 = annotateIPFImage(image1, imageDim, canvasDim, titlePrefix + label1, false);
1216-
UInt8ArrayType::Pointer annotated2 = annotateIPFImage(image2, imageDim, canvasDim, titlePrefix + label2, false);
1230+
UInt8ArrayType::Pointer annotated0 = annotateIPFImage(image0, imageDim, canvasDim, titlePrefix + label0, false, true);
1231+
UInt8ArrayType::Pointer annotated1 = annotateIPFImage(image1, imageDim, canvasDim, titlePrefix + label1, false, true);
1232+
UInt8ArrayType::Pointer annotated2 = annotateIPFImage(image2, imageDim, canvasDim, titlePrefix + label2, false, true);
12171233

12181234
// Step 7: Add color bars
12191235
annotated0 = drawColorBar(annotated0, canvasDim, config.numColors, globalMin, globalMax, config.normalizeMRD);

Source/EbsdLib/LaueOps/LaueOps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ class EbsdLib_EXPORT LaueOps
498498
* @param generateEntirePlane true = full circle view, false = SST only
499499
* @return RGB image (canvasDim x canvasDim, 3 components)
500500
*/
501-
UInt8ArrayType::Pointer annotateIPFImage(UInt8ArrayType::Pointer triangleImage, int imageDim, int canvasDim, const std::string& title, bool generateEntirePlane) const;
501+
UInt8ArrayType::Pointer annotateIPFImage(UInt8ArrayType::Pointer triangleImage, int imageDim, int canvasDim, const std::string& title, bool generateEntirePlane,
502+
bool hasColorBar = false) const;
502503

503504
/**
504505
* @brief Draws a color bar with min/max labels onto an existing RGB image.

0 commit comments

Comments
 (0)