Skip to content
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

Linked Axes #109

Closed
epezent opened this issue Sep 3, 2020 · 12 comments
Closed

Linked Axes #109

epezent opened this issue Sep 3, 2020 · 12 comments

Comments

@epezent
Copy link
Owner

epezent commented Sep 3, 2020

I'm considering an axis linking system so that drag on one plot will cause another plot to drag (see #53 (comment) and #94 (comment)). It is currently possible by exploiting GetPlotLimits and SetNextPlotLimts, but setting up a bidirectional system is more difficult.

Implementation details aside, what do folks think of something like this:

double xmin, xmax, ymin, ymax;

ImPlot::LinkNextAxes(&xmin,&xmax,&ymin,&ymax);
if (ImPlot::BeginPlot("Plot A")) { 
    ...
    ImPlot::EndPlot(); 
}

ImPlot::LinkNextAxes(&xmin,&xmax,&ymin,&ymax);
if (ImPlot::BeginPlot("Plot B")) { 
    ...
    ImPlot::EndPlot(); 
}

The pointer values will be used to set the next plot limits, and if any drag input is taken, it will update them accordingly so the changes can propagate to other plots. NULL could be passed for axes not linked. I haven't thought it out completely, but this is the most flexible and elegant solution I can come up with for now.

@PeterJohnson, @ozlb ...thoughts?

@PeterJohnson
Copy link
Contributor

I like it.

@hoffstadt
Copy link

I also like this idea. That would certainly be a unique and useful feature.

@Prinkesh
Copy link

Prinkesh commented Sep 3, 2020

I implemented this by wrapping BeginPlot() .. EndPlot()calls under new method BeginSubPlot()...EndSubPlot() . where subplot method hold the shared axis states of all children plots and all the child plot uses pointer to the parent axis state instead of a local copy . If there is no subplot parent for a plot then a local axis state is created for the plot .

One can define in the BeginSubPlot call what axis is to be shared .

So to share X axis one can write in this manner

if (ImPlot::BeginSubPlot("X Shared", ImSubPlot_ShareAxisX)) {
   if (ImPlot::BeginPlot("Plot A")) { 
    ...
    ImPlot::EndPlot(); 
   }

   if (ImPlot::BeginPlot("Plot B")) { 
    ...
    ImPlot::EndPlot(); 
   }
   ImPlot::EndSubPlot();
}
 

@PeterJohnson
Copy link
Contributor

I like how generic the original proposed solution is, e.g. I can have linked plots in separate windows, or separated by non-linked plots.

@ozlb
Copy link
Contributor

ozlb commented Sep 3, 2020

I like @epezent solution; in my applications I will probably “link” always x-axis and never y-axis (do you need up to 3 of ymin/ymax !?)

I don’t like the name “link”, i will use synchronized or “sync” but this is definitely not a big deal for me.

@epezent
Copy link
Owner Author

epezent commented Sep 3, 2020

I have this working in the linked-axes branch if anyone wants to give it a try. I'll merge later today after more testing.

I like this system because:

  1. you can link any number of plots/axes
  2. they don't have to be the same axis between plots (e.g. link an X to a Y if you please)
  3. it can be used for other purposes such as externally controlled axis limits

linked

@ozlb
Copy link
Contributor

ozlb commented Sep 3, 2020

Great!
What happens when while dragging the other plot Is hovered?

@epezent
Copy link
Owner Author

epezent commented Sep 4, 2020

You mean like this? Nothing, as would be expected.

link-hov

@ozlb
Copy link
Contributor

ozlb commented Sep 4, 2020

Great! It behaves like this because the drag operation is passing from one plot to the next or because it’s kept active in plot where it starts?

@epezent
Copy link
Owner Author

epezent commented Sep 4, 2020

The latter

@ozlb
Copy link
Contributor

ozlb commented Sep 4, 2020

The latter

I was wondering to close PR #98 but not yet ...

@epezent
Copy link
Owner Author

epezent commented Sep 6, 2020

Merged!

@epezent epezent closed this as completed Sep 6, 2020
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

No branches or pull requests

5 participants