Replies: 4 comments 9 replies
-
Yes. Although including helper functions might be a good idea, text rendering is delegated to the backend in all libraries I've seen. The way you might want to treat that is too specific to the context. Many backends won't need to render their own text. For instance, an SVG backend needs to write text directly to the file. A Gnuplot backend needs to embed the text in the commands. A markdown backend probably wants to literally just put the text in there. Skia,Qt,... have their own functions for rendering text. A backend I've writing uses freetype. There are some functions that need to and do consider text extent, but I've never seen a library that automatically reduces the font size or does something about text that goes beyond the plot. The backend interfaces usually just draw the text at a given position, but we can reconsider anything we might need to improve that. I agree drawing text would improve that backend a lot. The best way to do that depends on the backend we want to implement. |
Beta Was this translation helpful? Give feedback.
-
They use the Agg PathIterator, if I'm not wrong. This could add a lot of complexity for 3d rendering though, unless we redo everything with templates, variants or type erase some stuff. If we really go for performance, there are also "4d"/"5d"/... points as each data point usually has a color and a size, and these could also go to the shader. Another solution is to replicate the data in the canvas object, with its obvious drawbacks. But many if not most canvas objects might need to replicate this data (in another format) anyway.
That's correct. Most applications for plots don't require so much performance. Unlike other C++ applications, it's usually safer to worry about making it work first and then worry about optimizations. Premature optimization in plots seems like a very low return on investment.
You're 100% right. This is definitely not how I would structure any other graphics application by default. They are just very particular reasons we had for this library. I imagine it would be best to optimize that class by class, looking at particular demands, once we have a good idea of what the points of friction with backends will be. We can come up with some kind of view object to make the transition smoother.
Can't UE integrate with some other technologies and libraries?
Some people have been suggesting Skia lately. There might be some similar options. These are 2D libraries, like Agg, but they are very productive and already take care of text rendering. The 3d transforms we need are very simple, so they could even go into the interface as a placeholder in case the user only wants to define the 2d functions. Supporting 2D-only libraries actually has the potential to simplify things a lot in regards to new backends. Maybe UE can directly integrate with one of these libraries like Skia.
I did consider ImGUI once. I do use imGui a lot for quick applications with GUIs, but I wouldn't consider it as a matplot++ backend. ImGui is structured in a very specific way with an object stack. It also needs to run on top of another backend, and some of the low-level complexity is also back. My impression is that people who don't use ImGUI already wouldn't like the integration at all. And people who use ImGui would hate it because the programming paradigm is completely different. |
Beta Was this translation helpful? Give feedback.
-
2d and 3d points in structs seem fine for that. The data points are
Yes. It seems that the main difference is that some will transform the data with shaders, so structs with points are more likely to attend both demands because we can send these points directly to vertex shaders.
On the frontend, you can push new points directly to a line plot, as usual. The backend represents a canvas. Something like an "OpenGL context" for plots. So on the backend, in the general case, I'm not sure it's possible to update the data points because once the points are drawn, the backends don't even need to store these points, like in an OpenGL context or a data structure representing a raster image. The image would only be updated if there's some user interaction (if the plot is interactive) in which case the frontend would transform the data again and it would probably need to be sent it to the backend again anyway in most cases. Maybe some kind of extensions could provide that update functionality for backends that store pre-processed data, given some alternatives to fallback, but I'm not sure this is possible for the general case. One possibility would be to have to indicator or id to tell the backend whether this is new data or data being updated. These possibilities and the best alternative for this extension will probably only become clear once we have a simpler version of the backend. They are definitely possible though.
Agreed. On the frontend, at least, we usually think of line plots or scatter plots. These are relatively easy to update incrementally. The frontend has an interface for that and the backend can implement some kind of extension for that. Other plot types (histograms, contours, maps, ...) are not as easy to update incrementally though. We can pre-process some data but we cannot update histograms in constant time because the bins depend on the distribution of the data points, which might change with new data. Both identifying the distribution and dividing the bins take linear time in the general case. Contours and maps are even more complicated. There are some heuristics to update histograms with an approximation in constant time. But there are lots of possible algorithms and parameters, and this approximation is not what users are expecting by default, so this would require some interface that would make it clear that this is an approximation. But of course we can start with line/scatter plots and incrementally improve other plot types as we need. I would probably start with simpler solution and then identify the best ways to improve that. It's just important to remember the other plot types exist, because without considering their existence we might end up trying to reimplement the frontend in the backend just to find out this doesn't generalize well in the future. |
Beta Was this translation helpful? Give feedback.
-
For every plot ( You can use this handle to manipulate the storage, properties, etc, without recreating the plot. For instance, you could use to just push new points with Actually this would be the wrong overload for emplacing points because this is |
Beta Was this translation helpful? Give feedback.
-
What is the approach, or plan, regarding text rendering? Presumably the backend interface
draw_text()
function is intended to pass strings eventually.Does the library have any existing logic for determining space requirements for titles/axis tick labels and adjusting plot/axis layouts accordingly, or is this something handled only within gnuplot itself? Realistically I suppose the text extent calculation is something that has to be done by the backend, so the interface would need a way for matplot++ to query string extents, on top of a function to actually draw it.
In the short term, I think being able to draw text, even without any layout calculations, is probably the one thing missing for additional backends to be minimally usable.
Beta Was this translation helpful? Give feedback.
All reactions