-
Notifications
You must be signed in to change notification settings - Fork 981
Description
As discussed in #981, the current library makes it difficult to produce high-resolution images. If large values are given for width/height then the plot will resize to the new values, with the result that text is very small, and lines are very thin. This can be corrected by manually choosing widths and sizes for all plot features, but this is tedious and does not allow for multiple image sizes to be produced without significant effort.
Ideally there would be a separation of plot dimensions from image dimensions, and adjusting the image dimensions would result in a higher resolution image without resizing. In terms of the API, the main change would be a new version of Plot.SaveFig that would allow the width/height of the output image to be specified, along with a setting that would allow the user to choose whether to resize the plot, or just change the resolution.
The implementation of this is reasonably simple, as the GDI library used for plotting does allow for general transformations between the world coordinates of the plots and the device coordinates. The only problem is that ScottPlot does not have a single location where the GDI Graphics object can be configured, except for GDI.Graphics, which does not have the information necessary to configure the Graphics transform (it is a static function).
There is another static function in GDI.Graphics which requires passing in the PlotDimensions, but many functions do not use it. I propose to include a TranformScale in PlotDimensions which can be used by GDI.Graphics(Bitmap bmp,PlotDimensions dims...) to set the ScaleTransform of the GDI Graphics object. All calls to GDI.Graphics should then be changed to use the version of the function that requires the PlotDimensions.
The Settings class would also be changes, to have two new optional properties - OutputWidth and OutputHeight. These would be used by Settings.GetPlotDimensions to configure the TranformScale of the PlotDimensions if needed.
I have made these changes in my fork and they all seem to work, and they allow high resolution images to be created. I have tested the changes in the CookBook and they do not seem to break anything (at the moment the only impact is in the new Plot.SaveFig). But I have only just started looking at ScottPlot and I don't know if there are any other impacts of my proposed changes. There were still some calls to GDI.Graphics that I couldn't change to use the version that required the PlotDimensions, so these will not have the ScaleTransform applied - these seem mostly to be associated with measuring text. I am not sure if there will be problems with these. Ideally I would have liked to remove the GDI.Graphics function that didn't have the passed in PlotDimensions but I that would have increased the scope of my changes to even more classes/functions and I am not confident enough in my understanding of the library to to that.
I have created a pull request with my changes. Feel free to reject it if you think that it's a bad idea - normally I would use a library for a while before I started submitting changes. But I really like what you have done and the image resolution problem is a show-stopper for me (I want to use the library for pdf reports that need to be printed).
Note that it would be possible to modify the resizing behavior of the WinForms/WPF/Avalonia forms to use the proposed Transform approach - this would make the demo act more like Microsoft Excel where resizing a plot window simply adjusts the resolution.