Skip to content
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 Axis Formatter Function #292

Closed
hexvalid opened this issue Aug 2, 2024 · 4 comments
Closed

Custom Axis Formatter Function #292

hexvalid opened this issue Aug 2, 2024 · 4 comments

Comments

@hexvalid
Copy link

hexvalid commented Aug 2, 2024

Hi. Can I use custom axis formatter like that:

ImPlot::SetupAxisFormat(ImAxis_X1, secondFormatter); //<-- example
//...
int secondFormatter(double value, char* buff, int size, void* data)
{
    static double v[]      = {3600000,60000,1000,1,0.001,0.000001};
    static const char* p[] = {"h","m","s","ms","us","ns"};
    if (value == 0) {
        return snprintf(buff,size,"0s");
    }
    for (int i = 0; i < 6; ++i) {
        if (fabs(value) >= v[i]) {
            return snprintf(buff,size,"%g%s",value/v[i],p[i]);
        }
    }
    return snprintf(buff,size,"%g%s",value/v[5],p[5]);
}

I couldn't find anything else other than this function:

imgui.PlotSetupAxisFormatStr(imgui.AxisX1,"%.0f second timestamp")
@gucio321
Copy link
Collaborator

gucio321 commented Aug 3, 2024

Unfortunately not yet.
There is a dedicated issue for that #224

@gucio321

This comment was marked as duplicate.

@gucio321
Copy link
Collaborator

heh, its just missimplemented.
The first argument to our callbacks is not userData itself but it is *Context

    const char* (*Platform_GetClipboardTextFn)(ImGuiContext* ctx);
    void (*Platform_SetClipboardTextFn)(ImGuiContext* ctx, const char* text);
    void* Platform_ClipboardUserData;

@gucio321
Copy link
Collaborator

gucio321 commented Nov 4, 2024

@hexvalid this is fixed - see PlotSetupAxisFormatPlotFormatterV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants