-
Notifications
You must be signed in to change notification settings - Fork 631
Add offset and stride to ImPlotGetter plots #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This allows for downsampling ImPlotGetter plots!
|
Thank you for this change, I hope this can be merged upstream. |
brenocq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @GameChaos! Thanks for working on this feature. I left a small comment regarding the name change.
I recommend also modifying the Demo_CustomDataAndGetters in implot_demo.cpp to showcase your feature :)
| IMPLOT_TMP void PlotLine(const char* label_id, const T* values, int count, double xscale=1, double xstart=0, ImPlotLineFlags flags=0, int offset=0, int stride=sizeof(T)); | ||
| IMPLOT_TMP void PlotLine(const char* label_id, const T* xs, const T* ys, int count, ImPlotLineFlags flags=0, int offset=0, int stride=sizeof(T)); | ||
| IMPLOT_API void PlotLineG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotLineFlags flags=0); | ||
| IMPLOT_API void PlotLineG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotLineFlags flags=0, int offset=0, int stride=1); // offset and stride aren't in bytes, they act on the index, ie: idx * offset + stride |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree using offset/stride can be a bit misleading, I would recommend idx_offset/idx_stride here
| { } | ||
| template <typename I> IMPLOT_INLINE ImPlotPoint operator()(I idx) const { | ||
| return Getter(idx, Data); | ||
| return Getter(idx * Stride + Offset, Data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with the byte-wise offset/stride, it would be better to do something like (idx * Stride + Offset) % Count.
This allows for downsampling ImPlotGetter plots, like the "Time Series" demo in implot_demo.cpp.
Stride and offset don't feel like the right words though, because instead of being a byte offset/stride, they offset/stride the index instead.
Some code I've used this for (apologies in advance): https://codeberg.org/GameChaos/amogus/src/commit/e176744987894a8938b59c6a6124938b7f4cdde4/code/amogus.cpp#L1582-L1597