Skip to content

Conversation

@GameChaos
Copy link

@GameChaos GameChaos commented Feb 15, 2025

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

This allows for downsampling ImPlotGetter plots!
@James2022-rgb
Copy link

Thank you for this change, I hope this can be merged upstream.

@brenocq brenocq self-requested a review December 21, 2025 05:39
@brenocq brenocq added type:feat New feature or request prio:medium Medium priority status:review The task is under review labels Dec 21, 2025
@brenocq brenocq added this to the v0.18 - ImPlotSpec milestone Dec 21, 2025
Copy link
Collaborator

@brenocq brenocq left a 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
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prio:medium Medium priority status:review The task is under review type:feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants