epezent / implot

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

SetupAxisLinks refuses change if new Range.Min > old Range.Max #478

Closed olivier-gerard closed 11 months ago

olivier-gerard commented 1 year ago

Hello, I am using SetupAxisLinks() to change the type of physical quantity used for an axis (my data can be plot against time or distance, with mathematical conversion between both X axis). At each frame I multiply the X axis data by the correct factor to scale it to the selected physical quantity. If the graph is zoomed on a specific area I keep it when changing of X axis unit (eg let's say I zoomed on a peak at 49mm, when changing of unit the plot remains centered on the same peak, which is now located at 68 us). To do this I store the limits of the plot and when changing of physical quantity I multiply it by the correct factor and SetupAxisLinks() does the job.

This works pretty well, but fails in one case. When changing axis limits from eg [20, 30] to [35, 70] the min change is refused. This is due to the sequential checking in ImPlotAxis::PullLinks and the new min being larger than the old max (35 > 30 so Range.Max - _min is negative). Would it be possible to have PullLinks() applying both min and max values at the same time, if both are defined ?

Regards Olivier

olivier-gerard commented 1 year ago

Hi, Here is my fix, not creating a pull request for a 2-lines change.

In implot_internal.h, replace

void PullLinks() {
        if (LinkedMin) { SetMin(*LinkedMin,true); }
        if (LinkedMax) { SetMax(*LinkedMax,true); }
    }

by

    void PullLinks() {
        if (LinkedMin && LinkedMax) { SetRange(*LinkedMin, *LinkedMax); }
        else if (LinkedMin) { SetMin(*LinkedMin,true); }
        else if (LinkedMax) { SetMax(*LinkedMax,true); }
    }

It would be nice if you could incorporate it br Olivier

epezent commented 11 months ago

https://github.com/epezent/implot/commit/e3eab27545650c6ee70fa4acf115ea76f88d7af3