SiegeLord / RustGnuplot

A Rust library for drawing plots, powered by Gnuplot.
GNU Lesser General Public License v3.0
407 stars 46 forks source link

Interactive gnuplot window #33

Closed birktj closed 4 years ago

birktj commented 5 years ago

When using fg.show() a nice gnuplot window pops up and everything is good until I try to zoom or move around or in any way interact with the window. As far as I understand this is normal behavior when using the -p gnuplot parameter.

I think it would be better to use pause mouse close as the last command instead of -p. This command keeps the gnuplot process running until the window is closed and is probably better than -p since the window becomes interactive.

Currently I am using this workaround, but if you agree I think this would be a nice addition to the library.

let p = Command::new("gnuplot")
    .arg("/dev/stdin")
    .stdin(Stdio::piped())
    .spawn().unwrap();

let mut stdin = p.stdin.unwrap();
fig.echo(&mut stdin);
stdin.write_all(b"pause mouse close\n").unwrap();
SiegeLord commented 5 years ago

I tried this out here and there and my conclusion is that it's not quite true universally. Some terminals definitely support interactivity without pause mouse close. I wanted to add it by default, but it breaks two features:

There's probably a way to get it working (perhaps as an option?), but for now I'll not add this in.

To make your life easier, however, I added a method on Figure struct: set_post_commands, so you can do:

fig.set_post_commands("pause mouse close");
fig.show();
birktj commented 5 years ago

That's perfectly fine. Thank you for looking into it and with the new method this almost becomes a non-issue.

gdesmott commented 5 years ago

Hi there,

I've tried your workaround as I'm facing the same issue but get this error message:

gnuplot> pause mouse clone
                     ^
         line 0: expecting string

Am I missing something? I'm using gnuplot 5.0 and version 0.0.30 of the crate.

thanks!

birktj commented 5 years ago

I think that your problem is that it should be pause mouse close, not pause mouse clone

gdesmott commented 5 years ago

Oh indeed, no idea how I screwed that, thanks! :)

I no longer get the error but controls from the gnuplot_qt window are still not working.

wucke13 commented 4 years ago

Controls stall working if gnuplot is closed. Try adding loop{} to the end of the scop which calls fig.show().

gdesmott commented 4 years ago

Doesn't seem to help, controls are still not working.

SiegeLord commented 4 years ago

Hmm, I can't seem to reproduce this. I added fg.set_post_commands("pause mouse close"); and with the qt terminal, I could toggle the grid without issue. I'm using gnuplot 5.2 patchlevel 8.

gdesmott commented 4 years ago

Strange, I'm using the same gnuplot version.

Could you please provide the test case you are using (or even add it as an examples to the repo) so we are sure to try running the same code?

SiegeLord commented 4 years ago

With 52016af471eb77087665379fc367ec213a68f481, calling show issues pause mouse close internally, so by default the plots remain interactive. You can test this out with most of the examples, e.g. cargo run --example lines_points_3d