-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add SetupAxisTicks for configuring custom ticks #55
Conversation
Thanks for the addition @HeresJ0nny! I personally didn't know about this I pushed a commit to fix the code syntax. We use
I added the
Awesome!
Thank you!! Finally, it would be great to add a demo using We can use this demo from ImPlot as inspiration void Demo_TickLabels() {
static bool custom_fmt = true;
static bool custom_ticks = false;
static bool custom_labels = true;
ImGui::Checkbox("Show Custom Format", &custom_fmt);
ImGui::SameLine();
ImGui::Checkbox("Show Custom Ticks", &custom_ticks);
if (custom_ticks) {
ImGui::SameLine();
ImGui::Checkbox("Show Custom Labels", &custom_labels);
}
const double pi = 3.14;
const char* pi_str[] = {"PI"};
static double yticks[] = {100,300,700,900};
static const char* ylabels[] = {"One","Three","Seven","Nine"};
static double yticks_aux[] = {0.2,0.4,0.6};
static const char* ylabels_aux[] = {"A","B","C","D","E","F"};
if (ImPlot::BeginPlot("##Ticks")) {
ImPlot::SetupAxesLimits(2.5,5,0,1000);
ImPlot::SetupAxis(ImAxis_Y2, nullptr, ImPlotAxisFlags_AuxDefault);
ImPlot::SetupAxis(ImAxis_Y3, nullptr, ImPlotAxisFlags_AuxDefault);
if (custom_fmt) {
ImPlot::SetupAxisFormat(ImAxis_X1, "%g ms");
ImPlot::SetupAxisFormat(ImAxis_Y1, MetricFormatter, (void*)"Hz");
ImPlot::SetupAxisFormat(ImAxis_Y2, "%g dB");
ImPlot::SetupAxisFormat(ImAxis_Y3, MetricFormatter, (void*)"m");
}
if (custom_ticks) {
ImPlot::SetupAxisTicks(ImAxis_X1, &pi,1,custom_labels ? pi_str : nullptr, true);
ImPlot::SetupAxisTicks(ImAxis_Y1, yticks, 4, custom_labels ? ylabels : nullptr, false);
ImPlot::SetupAxisTicks(ImAxis_Y2, yticks_aux, 3, custom_labels ? ylabels_aux : nullptr, false);
ImPlot::SetupAxisTicks(ImAxis_Y3, 0, 1, 6, custom_labels ? ylabels_aux : nullptr, false);
}
ImPlot::EndPlot();
}
}
|
Update: Enhanced SetupAxisTicks and Demo Integration1. 2. Template Function Addition: 3. Demo Integration:
Initially, I had omitted
I want to apologize for not adhering to the clang-format guidelines in my earlier contribution. It was an oversight on my part, and I appreciate the adjustments that were made to ensure the codebase remains consistent and well-structured. This time, I made sure to review the formatting carefully, and I hope everything is now correct and meets your expectations. Thank you! |
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 @HeresJ0nny! Thanks for implementing the demo :)
Since you implemented the range variant of SetupAxisTicks
(thanks for that!), I also added it to the demo.
I removed the TempDouble1
and TempDouble2
from the context since they are not really needed at this point.
Initially, I had omitted keep_default due to concerns about overlapping tick labels when using custom ticks, as the current implementation does not check for sufficient space between labels. However, its inclusion of course ensures full parity with ImPlot.
Oooh I see! Year there is still some work needed to get the axes ticks looking good...
I want to apologize for not adhering to the clang-format guidelines in my earlier contribution.
No problemo :)
I think this PR is ready for merge, let me know if you agree with my changes and we can merge it!
Thank you for your updates and feedback! Adding the range variant of I also appreciate you removing I’m fully satisfied with the changes you’ve made, and I believe the PR is now in excellent shape for merging. Thank you once again for your collaboration and support throughout this process! Best regards! |
Add SetupAxisTicks to ImPlot3D
This pull request introduces the
SetupAxisTicks
feature to ImPlot3D, bringing functionality similar to ImPlot's implementation. Key changes and improvements include:1. Addition of
SetupAxisTicks
:A new function SetupAxisTicks has been implemented for ImPlot3D, closely mirroring the behavior in ImPlot.
The only exception is the handling of the
ShowDefaultTicks
boolean, which is automatically set when using SetupAxisTicks. Future updates could expand its configurability if needed.2. Axis Reset Refactoring:
The axis reset logic has been moved into
BeginPlot
for better initialization and consistency.A
Reset()
method has been added to the axis struct, making it easier to manage axis state during plot setup.3. Custom Tick Rendering Improvements:
Added checks in the rendering logic for grid lines, tick markers, and tick labels to ensure that custom ticks outside the axis range are not rendered. This ensures proper handling and prevents visual inconsistencies.