ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.68k stars 10.25k forks source link

Support for advanced plots/graphs #1729

Open dmccloskey opened 6 years ago

dmccloskey commented 6 years ago

I noticed on the feature/roadmap list an item for plots/graphs. I would be interested in seeing several common chart types that are currently not available (i.e., scatter, pie, box and whiskers, heatmap, etc.,) that could then be integrated with the rest of the ImGui framework to create a dynamic dashboard.

Where would you recommend a contributing developer to start on adding in this type of support? I would imagine support for defining axes, tick marks, legends, scales, color scales, and the like would be a pre-requisite for any advanced plotting and graphing functionality.

ocornut commented 6 years ago

Hello Douglas,

I would suggest checking the old topics marked with the plot/graph to get few ideas. This is generally a wide topic so I don't really have much answers now. My rough intuition was to create a structure that would hold temporary state, and provide a bunch of helpers that the user can combine manually and freely:

ImGuiPlotter plotter("id");
plotter.CalcRanges() ?
plotter.DrawGrid()
plotter.PlotLines(data, color, ...)
// query hovered position, etc.
plotter.PlotLines(data, color, ...)

(Consider this a dumb example, it's only there to suggest that we can't possibly fit everything in a single function call).

The system would use the window storage or custom global storage to persist information e.g. allowing user to scroll/scale the view or interact with it in various way.

This is probably a thing that needs to be iterated on a lot and for a while before finding the right sweet spot. I reckon I could come up with a nice prototype if I spent a week on it. You could give it a try, would be happy to see results out of it!

Having an exhaustive, ideal list of every desirable features would be good so we can refer to it while designing the system.

I think this could perfectly be implemented/iterated in a separate file, taking advantage of imgui_internal.h access to private data structures/functions. Depending on how useful and how big it becomes, we may consider either integrating it in the default imgui distribution (either merged in imgui.cpp or a different file), or possibly making it an official extension. As imgui is growing those questions will come back for a few other features. The main thing to pay attention to is to work with the same coding style as the regular imgui library (e.g. no dependency on STL, being mindful of performances and memory allocations).

dmccloskey commented 6 years ago

List of plotting library features

list inspired by d3.js and matplotlib

Common plot components

Chart types

Chart components

Layout types

dmccloskey commented 6 years ago

Hi Omar,

Thanks for those pointers. This will definitely be something that will need quite a few iterations. There are some very nice plotting libraries out already that one can take inspiration from (e.g., matplotlib or several of the plotting libraries sitting on top of d3.js).

I can start taking some shots at it over the next few weeks. Your reviews/comments on the code when the time comes will be greatly appreciated

dmccloskey commented 6 years ago

Hi Omar,

I had a few questions that I did not see on the wiki:

  1. coding style: would you approve of the use of templates? I don't think have seen any in your code base so far.
  2. code quality: are there any unit tests or suggestions for incorporating unit tests for debugging? There are some math related additions (e.g., bspline interpolation) where a couple of simple unit tests would be great for basic sanity checking.

This is the branch that I will be adding the code to: https://github.com/dmccloskey/imgui/tree/feature/imguiplotter. The plot code will be added to the file "imgui_plot.h" and "imgui_plot.c". The only sections in the main code base that I see additions being made to are in the IMGUI_DEFINE_MATH_OPERATORS section of "imgui_internal.h".

There is not much new to report at the moment. It is mostly an outline, but if you do find time to peruse the code, any feedback is more than welcome. In particular, your thoughts on what you think the interfaces should look like if they differ from what you would envision.

ocornut commented 6 years ago

Hello Douglas,

Thanks! Quick feedback:

Omar

dmccloskey commented 6 years ago

Hi Omar,

Thank you for your feedback. Your comments are greatly appreciated.

I have made some changes based on your comments. I have also constructed a “minimal” (and quite buggy) scatter plot example as a means to prototype classes and user interfaces exposed by “imgui_plot.h” so far. The example is in the directory “examples/sdl_opengl2_plot_example”. This folder (and any other lingering files from prototyping) will of course be deleted prior to submitting any merge request.

I wanted to check in on the following:

  1. If my changes are inline with your previous comments
  2. I wanted to inquire about some odd behavior I am getting when using DrawList. In the example, I call methods of class ImPlot2D called ShowXAxisTop and ShowLegend. However, they are never rendered. The method bodies are executed, but it looks like nothing is rendered to the window. Is there a simple mistake that I am making? Whatever the problem is, I am completely baffled at this point.

Douglas

ss

dmccloskey commented 6 years ago

@ocornut by any chance would you have time to chat over Gitter or over e.g., Skype? I have several questions that I think could be addressed quite quickly.

Best,

Douglas

ocornut commented 6 years ago

@dmccloskey Send me an e-mail. My e-mail is in the README.

dmccloskey commented 6 years ago

A workable scatter plot with tooltip, a legend, axes, ticks, and 1 axis label - the other axis label should be available in the next iteration ;).

ss

sashabel commented 6 years ago

Hello, it this feature going to be merged in the master ? I am really waiting for the advanced plotting (especially 3d and multiline). It would be also nice to include optionally a background image (suppose a map) so I could plot a function on top of it.

epezent commented 4 years ago

@dmccloskey and others: I've been working on a plotting API you may be interested in.

See https://github.com/ocornut/imgui/issues/3173 or ImPlot

dmccloskey commented 4 years ago

@epezent That is is awesome! I see some similarities in the code to what we were developing, but notable quite a bit more polished and importantly ready to use. I look forward to giving it a run.