| 1757 | } |
| 1758 | |
| 1759 | void EndPlot() { |
| 1760 | IMPLOT3D_CHECK_CTX(); |
| 1761 | ImPlot3DContext& gp = *GImPlot3D; |
| 1762 | IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr, "Mismatched BeginPlot()/EndPlot()!"); |
| 1763 | ImPlot3DPlot& plot = *gp.CurrentPlot; |
| 1764 | |
| 1765 | // Move triangles from 3D draw list to ImGui draw list |
| 1766 | plot.DrawList.SortedMoveToImGuiDrawList(); |
| 1767 | |
| 1768 | // Handle data fitting |
| 1769 | if (plot.FitThisFrame) { |
| 1770 | plot.FitThisFrame = false; |
| 1771 | |
| 1772 | const bool axis_equal = ImHasFlag(plot.Flags, ImPlot3DFlags_Equal); |
| 1773 | if (!axis_equal) { |
| 1774 | // Apply fit to all axes independently |
| 1775 | for (int i = 0; i < 3; i++) { |
| 1776 | if (plot.Axes[i].FitThisFrame) { |
| 1777 | plot.Axes[i].FitThisFrame = false; |
| 1778 | plot.Axes[i].ApplyFit(); |
| 1779 | } |
| 1780 | } |
| 1781 | } else { |
| 1782 | // Find the fitted axis with the highest aspect ratio (units per NDC unit) after fit |
| 1783 | // This axis will require the most space and should be used as reference |
| 1784 | ImAxis3D ref_axis = ImAxis3D_X; |
| 1785 | double max_aspect = 0.0; |
| 1786 | |
| 1787 | // First, apply fit to all axes |
| 1788 | for (int i = 0; i < 3; i++) { |
| 1789 | if (plot.Axes[i].FitThisFrame) { |
| 1790 | plot.Axes[i].FitThisFrame = false; |
| 1791 | plot.Axes[i].ApplyFit(); |
| 1792 | |
| 1793 | // Get aspect ratio for this axis |
| 1794 | double aspect = plot.Axes[i].GetAspect(); |
| 1795 | if (aspect > max_aspect) { |
| 1796 | max_aspect = aspect; |
| 1797 | ref_axis = (ImAxis3D)i; |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | // Then, apply equal aspect constraint if enabled |
| 1803 | // This ensures data remains centered and visible |
| 1804 | plot.ApplyEqualAspect(ref_axis); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | // Lock setup if not already done |
| 1809 | SetupLock(); |
| 1810 | |
| 1811 | // Pop plot rect clipping |
| 1812 | ImGui::PopClipRect(); |
| 1813 | |
| 1814 | // Reset legend hover |
| 1815 | plot.Items.Legend.Hovered = false; |
| 1816 |
no test coverage detected