epezent / implot

Immediate Mode Plotting
MIT License
4.79k stars 531 forks source link

Scatter plot with different sizes and colors #298

Open gorbatschow opened 2 years ago

gorbatschow commented 2 years ago

Hello! Just proposal. It would be great to be able to set sizes and colors as well of scattered points. scatexample

epezent commented 2 years ago

Thanks, this is definitely a goal of mine. I haven't quite figured out how to design the API, though. As it is currently designed, the API for styling scatter plots (i.e. SetNextMarkerStyle) and providing the data to scatter plots (i.e.. PlotScatter) is decoupled. I think this is a good approach for the sake of keeping the arguments passed to PlotScatter at a minimum. It gets tricky though if we want to enable per-element styling (this goes for other plot types as well). That would necessarily require ImU32* colors, float* sizes arguments somewhere. I'm not sure I'm ready to add them to PlotScatter, but SetNextMarkerStyle(ImU32* colors, float* sizes, int count) feels like a bad idea since it would require either caching the data or requiring the pointers to persist until PlotScatter.

I'm open to any suggestions!

phraktle commented 2 years ago

+1 for this feature. From an API user standpoint, it would be convenient to supply additional arrays to plotScatter with the size / color overrides.

n00bmind commented 1 year ago

+1 I'd like to be able to do something like this too.. An idea that springs to mind is have a new override for plot types that support per-element styling accepting a new type of callback returning a point + styling attributes, i.e. something like:

struct ImPlotStyledPoint
{
    double x, y;
    ImU32 col;
    // [...] potentially other attributes, with defaults to indicate 'unused'
};
typedef ImPlotStyledPoint (*ImPlotStyledGetter)(int idx, void* user_data);

IMPLOT_API void PlotScatterG(const char* label_id, ImPlotStyledGetter getter, void* data, int count, ImPlotScatterFlags flags=0);
[...]