epezent / implot

Immediate Mode Plotting
MIT License
4.55k stars 503 forks source link

Colorbar labels cropped #505

Closed olivier-gerard closed 11 months ago

olivier-gerard commented 11 months ago

Hi,

I noted the first and last labels of a colorbar are cropped (see picture below), which gives a bad impression while all the rest is just great.

I suggest following change, making the colormap slightly smaller so labels can fit: in implot.cpp, void ColormapScale(...)

remove :

ImRect bb_grad(bb_frame.Min + gp.Style.PlotPadding + ImVec2(bb_grad_shift, 0),
                   bb_frame.Min + ImVec2(bar_w + gp.Style.PlotPadding.x + bb_grad_shift,
                                         frame_size.y - gp.Style.PlotPadding.y));

replaced by:

ImRect bb_grad(bb_frame.Min + gp.Style.PlotPadding + ImVec2(bb_grad_shift, label_size.y / 2.f),
                    bb_frame.Min + ImVec2(bar_w + gp.Style.PlotPadding.x + bb_grad_shift,
                                        frame_size.y - gp.Style.PlotPadding.y - label_size.y / 2.f));

image -> image, (or whith white background : image -> image )

epezent commented 11 months ago

Hi, this seems like it might be the result of using a small value for PlotPadding. As you can see, the default values have no issue...

image

... but making PlotPadding (0,0) introduces the clipping:

image

So, you can push and pop a larger value of for PlotPadding around your colorbar to achieve the same result.

olivier-gerard commented 11 months ago

Thanks for the hint ! I was pushing a small PlotPadding in order to maximize the colorbar size (and didn't imagine it would affect the labels layout), now I only push it on the X axis and it works nicely.