Skip to content

Fix label clipping during rotation by adding ViewScaleFactor and reducing plot area #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 21, 2025

Problem

When rotating 3D plots, axis labels and ticks were being clipped when they extended outside the available space. Additionally, rotated axes could interfere with plot titles, creating an overlapping and unprofessional appearance.

Label clipping example 1
Label clipping example 2

Previously, users had to work around this by using ImPlot3DFlags_NoClip, which prevented clipping but allowed plot content to extend beyond proper boundaries.

Solution

This PR implements a comprehensive fix by making the plot area smaller and adding user configurability:

1. Renamed GetBoxZoom() to GetViewScale()

  • Better semantic clarity for the method's purpose
  • Updated all references throughout the codebase

2. Reduced Plot Area for More Margin

// Before: 
plot_scale = min(width, height) / 1.8f

// After:
plot_scale = min(width, height) / 2.2f * ViewScaleFactor
  • 18% smaller plot area provides more margin space
  • Prevents label clipping during rotation
  • Eliminates title interference

3. Added ViewScaleFactor Style Variable

  • New ImPlot3DStyleVar_ViewScaleFactor enum
  • Full integration with ImPlot3D's style system
  • Default value: 1.0f (maintains new behavior)
  • Supports PushStyleVar/PopStyleVar for per-plot customization

Usage Examples

// Global setting for all plots
ImPlot3D::GetStyle().ViewScaleFactor = 0.8f; // More conservative spacing

// Per-plot setting
ImPlot3D::PushStyleVar(ImPlot3DStyleVar_ViewScaleFactor, 1.2f);
if (ImPlot3D::BeginPlot("My Plot")) {
    // Plot with larger area, less margin
    ImPlot3D::EndPlot();
}
ImPlot3D::PopStyleVar();

Impact

Plot Size Old Scale New Scale Margin Increase
400px 222.22 181.82 18.18%
  • Values < 1.0f: More margin for dense plots with long labels
  • Values > 1.0f: Maximize plot area when labels are short
  • Default 1.0f: Optimal balance for most use cases

Benefits

  • No more label clipping during rotation
  • No title interference with plot content
  • User configurable via ViewScaleFactor
  • Backward compatible - existing code works without changes
  • Consistent API following ImPlot3D style patterns

The fix eliminates the need for ImPlot3DFlags_NoClip workarounds while providing users fine-grained control over the plot area vs. margin trade-off.

Fixes #133.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@brenocq brenocq changed the title [WIP] [Bug] Labels are clipped when rotating Fix: Labels are clipped when rotating Jul 21, 2025
@Copilot Copilot AI changed the title Fix: Labels are clipped when rotating Fix label clipping during rotation by adding ViewScaleFactor and reducing plot area Jul 21, 2025
@Copilot Copilot AI requested a review from brenocq July 21, 2025 05:33
Copilot finished work on behalf of brenocq July 21, 2025 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Labels are clipped when rotating
2 participants