Closed mathias-brandewinder closed 8 years ago
This part of FSharp.Charting is Windows-only anyway. I think changing Chart.Save
so that it does not open & close window is a good idea in general - if you can send a PR, that would be great!
(As far as I can see from the history, we didn't have it that way originally - so it's not that we changed the code to show the dialog in order to fix some bug.)
/cc @simra who did some work on this part, just in case he has some thoughts!
Cool, thanks for the clarification re: Windows - I'll also give some thought as to whether we might add optional arguments to save, then - for instance, setting the size, as in this case.
HI, sorry for the delay. Yes, Chart.Save was an added convenience method because a window was needed to successfully render in Windows. I added it from a sample provided by another user but was never really happy with the call because it left no room for window size and other useful optional parameters. I looked at it once to see if we could give it optional parameters but I think the blocking issue was that it's not an object method but a static class method. Definitely worth re-visiting to see if we can make that interface better.
Removing the window popup during save would also be helpful to users plotting 100+ figures in a script. Having constant window popups of very short duration makes the computer unusable during plotting.
Since the window is necessary (on Windows), the right thing to do here is to detect and re-use the existing pop-up. It will take a little resource management. Since the function is a helper we could put a small burden on the user to own the window and dispose of it when done. Thoughts?
FsLab oes this without actually showing a window: https://github.com/fslaborg/FsLab/blob/master/src/FsLab.Runner/Formatters.fs#L209
I think that approach would work here too.
That could work and I'll try to put together a pull request. The one outstanding issue is that it's still not very performant in the cases you have a lot of charts to generate. A hidden reusable control would be ideal if we could figure out the question of managing that resource.
I'll leave the PR open a few days for folks to have a look. One remaining open issue with this function is wanting to pass optional parameters like size, file format, etc.
Merged the PR. Ping me if you see any issues.
In a recent project, I needed to create and save charts from a windows service. This causes issues because - as far as I understand - Chart.Save temporarily pops a window. With some help from @tpetricek I ended up addressing the problem this way:
https://github.com/mathias-brandewinder/worldbankbot/blob/master/WorldBankBot/WorldBankBot/Twitter.fs#L157-L166
Perhaps refactoring Chart.Save using that approach might be a good idea? I don't know if the problem is important enough, and if it has implications outside of Windows. Happy to send a PR if someone can confirm it works outside of Windows.