-
Notifications
You must be signed in to change notification settings - Fork 563
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
Custom labels with lambda #173
Comments
Not currently. But that's not a bad idea. We could easily support it. |
@kv-gits, I've add the ability to set custom tick format specifiers in #198. Does something like this support your use case, or would you still require a callback? If so, can you describe what your ideal callback signature would be, i.e. what information would you require to generate the ticks? (e.g. plot range, pixel size, etc). |
@epezent, sorry, I missed this issue. I think callback should be as it is already implemented for Y values auto lamda = [](void* data, int idx) { ... return "const char array"; }; So we could consider state of graphic e.g. scale and prepare appropriate format inside lambda. |
#294 (see also #168 (comment)) adds: // Sets the format of numeric axis labels via formatter callback. Given #value, write a label into #buff. Optionally pass user data.
void SetupAxisFormat(ImAxis axis, ImPlotFormatter formatter, void* data = NULL); where: // Callback signature for axis tick label formatter.
typedef void (*ImPlotFormatter)(double value, char* buff, int size, void* user_data); example: void MetricFormatter(double value, char* buff, int size, void* data) {
const char* unit = (const char*)data;
static double v[] = {1000000000,1000000,1000,1,0.001,0.000001,0.000000001};
static const char* p[] = {"G","M","k","","m","u","n"};
if (value == 0) {
snprintf(buff,size,"0 %s", unit);
return;
}
for (int i = 0; i < 7; ++i) {
if (fabs(value) >= v[i]) {
snprintf(buff,size,"%g %s%s",value/v[i],p[i],unit);
return;
}
}
snprintf(buff,size,"%g %s%s",value/v[6],p[6],unit);
} if (ImPlot::BeginPlot("MyPlot")) {
ImPlot::SetupAxisFormat(ImAxis_Y1, MetricFormatter, (void*)"Hz");
ImPlot::EndPlot();
} |
Is it possible to set custom label not only with predefined array, but with c++ lambda?
The text was updated successfully, but these errors were encountered: