1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 15:47:26 -04:00

reorganize header

This commit is contained in:
epezent 2020-08-22 23:26:49 -05:00
parent 9b8270d939
commit db16011e73
5 changed files with 138 additions and 138 deletions

View File

@ -423,7 +423,7 @@ const char* GetLegendLabel(int i) {
void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImVector<ImPlotTick> &out) { void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImVector<ImPlotTick> &out) {
const double nice_range = NiceNum(range.Size() * 0.99, false); const double nice_range = NiceNum(range.Size() * 0.99, false);
const double interval = NiceNum(nice_range / (nMajor - 1), true); const double interval = NiceNum(nice_range / (nMajor - 1), true);
const double graphmin = floor(range.Min / interval) * interval; const double graphmin = floor(range.Min / interval) * interval;
const double graphmax = ceil(range.Max / interval) * interval; const double graphmax = ceil(range.Max / interval) * interval;
for (double major = graphmin; major < graphmax + 0.5 * interval; major += interval) { for (double major = graphmin; major < graphmax + 0.5 * interval; major += interval) {
@ -434,7 +434,7 @@ void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImVector<
if (range.Contains(minor)) if (range.Contains(minor))
out.push_back(ImPlotTick(minor, false, true)); out.push_back(ImPlotTick(minor, false, true));
} }
} }
} }
void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImVector<ImPlotTick>& out) { void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImVector<ImPlotTick>& out) {
@ -463,12 +463,12 @@ void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImVector<ImPlotTi
double minor = major1 + i * interval; double minor = major1 + i * interval;
if (minor >= (range.Min - DBL_EPSILON) && minor <= (range.Max + DBL_EPSILON)) if (minor >= (range.Min - DBL_EPSILON) && minor <= (range.Max + DBL_EPSILON))
out.push_back(ImPlotTick(minor, false, false)); out.push_back(ImPlotTick(minor, false, false));
} }
} }
} }
} }
void AddCustomTicks(const double* values, const char** labels, int n, ImVector<ImPlotTick>& ticks, ImGuiTextBuffer& buffer) { void AddTicksCustom(const double* values, const char** labels, int n, ImVector<ImPlotTick>& ticks, ImGuiTextBuffer& buffer) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
ImPlotTick tick(values[i],false, true); ImPlotTick tick(values[i],false, true);
tick.BufferOffset = buffer.size(); tick.BufferOffset = buffer.size();
@ -735,7 +735,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
const float pad_top = title_size.x > 0.0f ? txt_height + IMPLOT_LABEL_PAD : 0; const float pad_top = title_size.x > 0.0f ? txt_height + IMPLOT_LABEL_PAD : 0;
const float pad_bot = (gp.X.HasLabels ? txt_height + IMPLOT_LABEL_PAD : 0) + (x_label ? txt_height + IMPLOT_LABEL_PAD : 0); const float pad_bot = (gp.X.HasLabels ? txt_height + IMPLOT_LABEL_PAD : 0) + (x_label ? txt_height + IMPLOT_LABEL_PAD : 0);
const float pad_left = (y_label ? txt_height + IMPLOT_LABEL_PAD : 0) const float pad_left = (y_label ? txt_height + IMPLOT_LABEL_PAD : 0)
+ (gp.Y[0].HasLabels ? max_label_widths[0] + IMPLOT_LABEL_PAD : 0); + (gp.Y[0].HasLabels ? max_label_widths[0] + IMPLOT_LABEL_PAD : 0);
const float pad_right = ((gp.Y[1].Present && gp.Y[1].HasLabels) ? max_label_widths[1] + IMPLOT_LABEL_PAD : 0) const float pad_right = ((gp.Y[1].Present && gp.Y[1].HasLabels) ? max_label_widths[1] + IMPLOT_LABEL_PAD : 0)
+ ((gp.Y[1].Present && gp.Y[2].Present) ? IMPLOT_LABEL_PAD + IMPLOT_MINOR_SIZE : 0) + ((gp.Y[1].Present && gp.Y[2].Present) ? IMPLOT_LABEL_PAD + IMPLOT_MINOR_SIZE : 0)
+ ((gp.Y[2].Present && gp.Y[2].HasLabels) ? max_label_widths[2] + IMPLOT_LABEL_PAD : 0); + ((gp.Y[2].Present && gp.Y[2].HasLabels) ? max_label_widths[2] + IMPLOT_LABEL_PAD : 0);
@ -757,10 +757,10 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// y axis regions bb and hover // y axis regions bb and hover
ImRect yAxisRegion_bb[IMPLOT_Y_AXES]; ImRect yAxisRegion_bb[IMPLOT_Y_AXES];
yAxisRegion_bb[0] = ImRect(ImVec2(gp.BB_Frame.Min.x, gp.BB_Plot.Min.y), ImVec2(gp.BB_Plot.Min.x, gp.BB_Plot.Max.y)); yAxisRegion_bb[0] = ImRect(ImVec2(gp.BB_Frame.Min.x, gp.BB_Plot.Min.y), ImVec2(gp.BB_Plot.Min.x, gp.BB_Plot.Max.y));
yAxisRegion_bb[1] = gp.Y[2].Present yAxisRegion_bb[1] = gp.Y[2].Present
? ImRect(gp.BB_Plot.GetTR(), ImVec2(gp.YAxisReference[2], gp.BB_Plot.Max.y)) ? ImRect(gp.BB_Plot.GetTR(), ImVec2(gp.YAxisReference[2], gp.BB_Plot.Max.y))
: ImRect(gp.BB_Plot.GetTR(), ImVec2(gp.BB_Frame.Max.x, gp.BB_Plot.Max.y)); : ImRect(gp.BB_Plot.GetTR(), ImVec2(gp.BB_Frame.Max.x, gp.BB_Plot.Max.y));
yAxisRegion_bb[2] = ImRect(ImVec2(gp.YAxisReference[2], gp.BB_Plot.Min.y), ImVec2(gp.BB_Frame.Max.x, gp.BB_Plot.Max.y)); yAxisRegion_bb[2] = ImRect(ImVec2(gp.YAxisReference[2], gp.BB_Plot.Min.y), ImVec2(gp.BB_Frame.Max.x, gp.BB_Plot.Max.y));
for (int i = 0; i < IMPLOT_Y_AXES; ++i) { for (int i = 0; i < IMPLOT_Y_AXES; ++i) {
@ -860,14 +860,14 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
} }
} }
if (IO.MouseDragMaxDistanceSqr[0] > 5) { if (IO.MouseDragMaxDistanceSqr[0] > 5) {
if (direction == 0) if (direction == 0)
ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed); ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed);
else if (direction == (1 << 1)) else if (direction == (1 << 1))
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
else if (direction == (1 << 2)) else if (direction == (1 << 2))
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
else else
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
} }
} }
// start drag // start drag
@ -965,10 +965,10 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// end query // end query
if (plot.Querying && (IO.MouseReleased[gp.InputMap.QueryButton] || IO.MouseReleased[gp.InputMap.BoxSelectButton])) { if (plot.Querying && (IO.MouseReleased[gp.InputMap.QueryButton] || IO.MouseReleased[gp.InputMap.BoxSelectButton])) {
plot.Querying = false; plot.Querying = false;
if (plot.QueryRect.GetWidth() > 2 && plot.QueryRect.GetHeight() > 2) if (plot.QueryRect.GetWidth() > 2 && plot.QueryRect.GetHeight() > 2)
plot.Queried = true; plot.Queried = true;
else else
plot.Queried = false; plot.Queried = false;
} }
// begin query // begin query
@ -1004,8 +1004,8 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
if ( IO.MouseDoubleClicked[gp.InputMap.FitButton] && gp.Hov_Frame && (plot.XAxis.HoveredTot || any_hov_y_axis_region) && !hov_legend && !hov_query ) { if ( IO.MouseDoubleClicked[gp.InputMap.FitButton] && gp.Hov_Frame && (plot.XAxis.HoveredTot || any_hov_y_axis_region) && !hov_legend && !hov_query ) {
gp.FitThisFrame = true; gp.FitThisFrame = true;
gp.FitX = plot.XAxis.HoveredTot; gp.FitX = plot.XAxis.HoveredTot;
for (int i = 0; i < IMPLOT_Y_AXES; i++) for (int i = 0; i < IMPLOT_Y_AXES; i++)
gp.FitY[i] = plot.YAxis[i].HoveredTot; gp.FitY[i] = plot.YAxis[i].HoveredTot;
} }
// fit from FitNextPlotAxes // fit from FitNextPlotAxes
if (gp.NextPlotData.FitX) { if (gp.NextPlotData.FitX) {
@ -1063,11 +1063,11 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
col_min.w *= ImClamp(ImRemap(density, 0.1f, 0.2f, 1.0f, 0.0f), 0.0f, 1.0f); col_min.w *= ImClamp(ImRemap(density, 0.1f, 0.2f, 1.0f, 0.0f), 0.0f, 1.0f);
ImU32 col_min32 = ImGui::ColorConvertFloat4ToU32(col_min); ImU32 col_min32 = ImGui::ColorConvertFloat4ToU32(col_min);
for (int t = 0; t < gp.XTicks.Size; t++) { for (int t = 0; t < gp.XTicks.Size; t++) {
ImPlotTick& xt = gp.XTicks[t]; ImPlotTick& xt = gp.XTicks[t];
if (xt.Major) if (xt.Major)
DrawList.AddLine(ImVec2(xt.PixelPos, gp.BB_Plot.Min.y), ImVec2(xt.PixelPos, gp.BB_Plot.Max.y), gp.Col_X.Major, 1); DrawList.AddLine(ImVec2(xt.PixelPos, gp.BB_Plot.Min.y), ImVec2(xt.PixelPos, gp.BB_Plot.Max.y), gp.Col_X.Major, 1);
else if (density < 0.2f) else if (density < 0.2f)
DrawList.AddLine(ImVec2(xt.PixelPos, gp.BB_Plot.Min.y), ImVec2(xt.PixelPos, gp.BB_Plot.Max.y), col_min32, 1); DrawList.AddLine(ImVec2(xt.PixelPos, gp.BB_Plot.Min.y), ImVec2(xt.PixelPos, gp.BB_Plot.Max.y), col_min32, 1);
} }
} }
@ -1346,7 +1346,7 @@ void EndPlot() {
ImVec2 p2(x_loc + 5, gp.BB_Plot.Max.y + 5); ImVec2 p2(x_loc + 5, gp.BB_Plot.Max.y + 5);
DrawList.AddRect(p1, p2, ImGui::GetColorU32(ImGuiCol_DragDropTarget), 0.0f, ImDrawCornerFlags_All, 2.0f); DrawList.AddRect(p1, p2, ImGui::GetColorU32(ImGuiCol_DragDropTarget), 0.0f, ImDrawCornerFlags_All, 2.0f);
} }
} }
} }
PushPlotClipRect(); PushPlotClipRect();
@ -1478,7 +1478,7 @@ void EndPlot() {
ImBufferWriter writer(buffer, sizeof(buffer)); ImBufferWriter writer(buffer, sizeof(buffer));
// x // x
if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale)) { if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale)) {
writer.Write("%.3E", gp.MousePos[0].x); writer.Write("%.3E", gp.MousePos[0].x);
} }
else { else {
@ -1486,7 +1486,7 @@ void EndPlot() {
writer.Write("%.*f", Precision(range_x), gp.MousePos[0].x); writer.Write("%.*f", Precision(range_x), gp.MousePos[0].x);
} }
// y1 // y1
if (ImHasFlag(plot.YAxis[0].Flags, ImPlotAxisFlags_LogScale)) { if (ImHasFlag(plot.YAxis[0].Flags, ImPlotAxisFlags_LogScale)) {
writer.Write(",%.3E", gp.MousePos[0].y); writer.Write(",%.3E", gp.MousePos[0].y);
} }
else { else {
@ -1495,7 +1495,7 @@ void EndPlot() {
} }
// y2 // y2
if (ImHasFlag(plot.Flags, ImPlotFlags_YAxis2)) { if (ImHasFlag(plot.Flags, ImPlotFlags_YAxis2)) {
if (ImHasFlag(plot.YAxis[1].Flags, ImPlotAxisFlags_LogScale)) { if (ImHasFlag(plot.YAxis[1].Flags, ImPlotAxisFlags_LogScale)) {
writer.Write(",(%.3E)", gp.MousePos[1].y); writer.Write(",(%.3E)", gp.MousePos[1].y);
} }
else { else {
@ -1505,7 +1505,7 @@ void EndPlot() {
} }
// y3 // y3
if (ImHasFlag(plot.Flags, ImPlotFlags_YAxis3)) { if (ImHasFlag(plot.Flags, ImPlotFlags_YAxis3)) {
if (ImHasFlag(plot.YAxis[2].Flags, ImPlotAxisFlags_LogScale)) { if (ImHasFlag(plot.YAxis[2].Flags, ImPlotAxisFlags_LogScale)) {
writer.Write(",(%.3E)", gp.MousePos[2].y); writer.Write(",(%.3E)", gp.MousePos[2].y);
} }
else { else {
@ -1551,8 +1551,8 @@ void EndPlot() {
ImGui::EndPopup(); ImGui::EndPopup();
} }
if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && plot.XAxis.HoveredExt && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend) if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && plot.XAxis.HoveredExt && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend)
ImGui::OpenPopup("##XContext"); ImGui::OpenPopup("##XContext");
if (ImGui::BeginPopup("##XContext")) { if (ImGui::BeginPopup("##XContext")) {
ImGui::Text("X-Axis"); ImGui::Separator(); ImGui::Text("X-Axis"); ImGui::Separator();
ShowAxisContextMenu(gp.X); ShowAxisContextMenu(gp.X);
@ -1561,8 +1561,8 @@ void EndPlot() {
for (int i = 0; i < IMPLOT_Y_AXES; ++i) { for (int i = 0; i < IMPLOT_Y_AXES; ++i) {
ImGui::PushID(i); ImGui::PushID(i);
if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && plot.YAxis[i].HoveredExt && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend) if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && plot.YAxis[i].HoveredExt && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend)
ImGui::OpenPopup("##YContext"); ImGui::OpenPopup("##YContext");
if (ImGui::BeginPopup("##YContext")) { if (ImGui::BeginPopup("##YContext")) {
if (i == 0) { if (i == 0) {
ImGui::Text("Y-Axis"); ImGui::Separator(); ImGui::Text("Y-Axis"); ImGui::Separator();
@ -1637,7 +1637,7 @@ void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels, b
ImPlotContext& gp = *GImPlot; ImPlotContext& gp = *GImPlot;
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksX() needs to be called before BeginPlot()!"); IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksX() needs to be called before BeginPlot()!");
gp.NextPlotData.ShowDefaultTicksX = show_default; gp.NextPlotData.ShowDefaultTicksX = show_default;
AddCustomTicks(values, labels, n_ticks, gp.XTicks, gp.XTickLabels); AddTicksCustom(values, labels, n_ticks, gp.XTicks, gp.XTickLabels);
} }
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char** labels, bool show_default) { void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char** labels, bool show_default) {
@ -1652,7 +1652,7 @@ void SetNextPlotTicksY(const double* values, int n_ticks, const char** labels, b
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksY() needs to be called before BeginPlot()!"); IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksY() needs to be called before BeginPlot()!");
IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES"); IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES");
gp.NextPlotData.ShowDefaultTicksY[y_axis] = show_default; gp.NextPlotData.ShowDefaultTicksY[y_axis] = show_default;
AddCustomTicks(values, labels, n_ticks, gp.YTicks[y_axis], gp.YTickLabels[y_axis]); AddTicksCustom(values, labels, n_ticks, gp.YTicks[y_axis], gp.YTickLabels[y_axis]);
} }
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char** labels, bool show_default, int y_axis) { void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char** labels, bool show_default, int y_axis) {

142
implot.h
View File

@ -49,7 +49,7 @@ enum ImPlotFlags_ {
ImPlotFlags_Highlight = 1 << 2, // plot items will be highlighted when their legend entry is hovered ImPlotFlags_Highlight = 1 << 2, // plot items will be highlighted when their legend entry is hovered
ImPlotFlags_BoxSelect = 1 << 3, // the user will be able to box-select with right-mouse ImPlotFlags_BoxSelect = 1 << 3, // the user will be able to box-select with right-mouse
ImPlotFlags_Query = 1 << 4, // the user will be able to draw query rects with middle-mouse ImPlotFlags_Query = 1 << 4, // the user will be able to draw query rects with middle-mouse
ImPlotFlags_ContextMenu = 1 << 5, // the user will be able to open a context menu with double-right click ImPlotFlags_ContextMenu = 1 << 5, // the user will be able to open context menus with double-right click
ImPlotFlags_Crosshairs = 1 << 6, // the default mouse cursor will be replaced with a crosshair when hovered ImPlotFlags_Crosshairs = 1 << 6, // the default mouse cursor will be replaced with a crosshair when hovered
ImPlotFlags_AntiAliased = 1 << 7, // plot lines will be software anti-aliased (not recommended, prefer MSAA) ImPlotFlags_AntiAliased = 1 << 7, // plot lines will be software anti-aliased (not recommended, prefer MSAA)
ImPlotFlags_NoChild = 1 << 8, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications) ImPlotFlags_NoChild = 1 << 8, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications)
@ -69,7 +69,7 @@ enum ImPlotAxisFlags_ {
ImPlotAxisFlags_LogScale = 1 << 6, // a logartithmic (base 10) axis scale will be used ImPlotAxisFlags_LogScale = 1 << 6, // a logartithmic (base 10) axis scale will be used
ImPlotAxisFlags_Scientific = 1 << 7, // scientific notation will be used for tick labels if displayed (WIP, not very good yet) ImPlotAxisFlags_Scientific = 1 << 7, // scientific notation will be used for tick labels if displayed (WIP, not very good yet)
ImPlotAxisFlags_Default = ImPlotAxisFlags_GridLines | ImPlotAxisFlags_TickMarks | ImPlotAxisFlags_TickLabels, ImPlotAxisFlags_Default = ImPlotAxisFlags_GridLines | ImPlotAxisFlags_TickMarks | ImPlotAxisFlags_TickLabels,
ImPlotAxisFlags_Auxiliary = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_GridLines, ImPlotAxisFlags_Auxiliary = ImPlotAxisFlags_TickMarks | ImPlotAxisFlags_TickLabels,
}; };
// Plot styling colors. // Plot styling colors.
@ -82,10 +82,10 @@ enum ImPlotCol_ {
ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg) ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg)
ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg) ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg)
ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Text) ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Text)
ImPlotCol_XAxis, // x-axis grid/label color (defaults to 25% ImGuiCol_Text) ImPlotCol_XAxis, // x-axis grid/label color (defaults to ImGuiCol_Text)
ImPlotCol_YAxis, // y-axis grid/label color (defaults to 25% ImGuiCol_Text) ImPlotCol_YAxis, // y-axis grid/label color (defaults to ImGuiCol_Text)
ImPlotCol_YAxis2, // 2nd y-axis grid/label color (defaults to 25% ImGuiCol_Text) ImPlotCol_YAxis2, // 2nd y-axis grid/label color (defaults to ImGuiCol_Text)
ImPlotCol_YAxis3, // 3rd y-axis grid/label color (defaults to 25% ImGuiCol_Text) ImPlotCol_YAxis3, // 3rd y-axis grid/label color (defaults to ImGuiCol_Text)
ImPlotCol_Selection, // box-selection color (defaults to yellow) ImPlotCol_Selection, // box-selection color (defaults to yellow)
ImPlotCol_Query, // box-query color (defaults to green) ImPlotCol_Query, // box-query color (defaults to green)
ImPlotCol_COUNT ImPlotCol_COUNT
@ -93,10 +93,10 @@ enum ImPlotCol_ {
// Plot styling variables. // Plot styling variables.
enum ImPlotStyleVar_ { enum ImPlotStyleVar_ {
ImPlotStyleVar_LineWeight, // float, line weight in pixels ImPlotStyleVar_LineWeight, // float, plot item line weight in pixels
ImPlotStyleVar_Marker, // int, marker specification ImPlotStyleVar_Marker, // int, marker specification
ImPlotStyleVar_MarkerSize, // float, marker size in pixels (roughly the marker's "radius") ImPlotStyleVar_MarkerSize, // float, marker size in pixels (roughly the marker's "radius")
ImPlotStyleVar_MarkerWeight, // float, outline weight of markers in pixels ImPlotStyleVar_MarkerWeight, // float, plot outline weight of markers in pixels
ImPlotStyleVar_FillAlpha, // float, alpha modifier applied to all plot item fills ImPlotStyleVar_FillAlpha, // float, alpha modifier applied to all plot item fills
ImPlotStyleVar_ErrorBarSize, // float, error bar whisker width in pixels ImPlotStyleVar_ErrorBarSize, // float, error bar whisker width in pixels
ImPlotStyleVar_ErrorBarWeight, // float, error bar whisker weight in pixels ImPlotStyleVar_ErrorBarWeight, // float, error bar whisker weight in pixels
@ -109,16 +109,16 @@ enum ImPlotStyleVar_ {
// Marker specifications. You can combine this with binary OR, e.g. ImPlotMarker_Circle | ImPlotMarker_Cross. // Marker specifications. You can combine this with binary OR, e.g. ImPlotMarker_Circle | ImPlotMarker_Cross.
enum ImPlotMarker_ { enum ImPlotMarker_ {
ImPlotMarker_None = 1 << 0, // no marker ImPlotMarker_None = 1 << 0, // no marker
ImPlotMarker_Circle = 1 << 1, // a circle marker will be rendered at each point ImPlotMarker_Circle = 1 << 1, // a circle marker
ImPlotMarker_Square = 1 << 2, // a square maker will be rendered at each point ImPlotMarker_Square = 1 << 2, // a square maker
ImPlotMarker_Diamond = 1 << 3, // a diamond marker will be rendered at each point ImPlotMarker_Diamond = 1 << 3, // a diamond marker
ImPlotMarker_Up = 1 << 4, // an upward-pointing triangle marker will up rendered at each point ImPlotMarker_Up = 1 << 4, // an upward-pointing triangle marker
ImPlotMarker_Down = 1 << 5, // an downward-pointing triangle marker will up rendered at each point ImPlotMarker_Down = 1 << 5, // an downward-pointing triangle marker
ImPlotMarker_Left = 1 << 6, // an leftward-pointing triangle marker will up rendered at each point ImPlotMarker_Left = 1 << 6, // an leftward-pointing triangle marker
ImPlotMarker_Right = 1 << 7, // an rightward-pointing triangle marker will up rendered at each point ImPlotMarker_Right = 1 << 7, // an rightward-pointing triangle marker
ImPlotMarker_Cross = 1 << 8, // a cross marker will be rendered at each point (not filled) ImPlotMarker_Cross = 1 << 8, // a cross marker (not fillable)
ImPlotMarker_Plus = 1 << 9, // a plus marker will be rendered at each point (not filled) ImPlotMarker_Plus = 1 << 9, // a plus marker (not fillable)
ImPlotMarker_Asterisk = 1 << 10, // a asterisk marker will be rendered at each point (not filled) ImPlotMarker_Asterisk = 1 << 10, // a asterisk marker (not fillable)
}; };
// Built-in colormaps // Built-in colormaps
@ -234,6 +234,7 @@ bool BeginPlot(const char* title_id,
ImPlotAxisFlags y_flags = ImPlotAxisFlags_Default, ImPlotAxisFlags y_flags = ImPlotAxisFlags_Default,
ImPlotAxisFlags y2_flags = ImPlotAxisFlags_Auxiliary, ImPlotAxisFlags y2_flags = ImPlotAxisFlags_Auxiliary,
ImPlotAxisFlags y3_flags = ImPlotAxisFlags_Auxiliary); ImPlotAxisFlags y3_flags = ImPlotAxisFlags_Auxiliary);
// Only call EndPlot() if BeginPlot() returns true! Typically called at the end // Only call EndPlot() if BeginPlot() returns true! Typically called at the end
// of an if statement conditioned on BeginPlot(). // of an if statement conditioned on BeginPlot().
void EndPlot(); void EndPlot();
@ -251,7 +252,7 @@ void PlotLine(const char* label_id, const ImVec2* data, int count, int offset =
void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset = 0); void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset = 0);
void PlotLine(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0); void PlotLine(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0);
// Plots a standard 2D scatter plot. // Plots a standard 2D scatter plot. Default marker is ImPlotMarker_Circle.
void PlotScatter(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); void PlotScatter(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float));
void PlotScatter(const char* label_id, const double* values, int count, int offset = 0, int stride = sizeof(double)); void PlotScatter(const char* label_id, const double* values, int count, int offset = 0, int stride = sizeof(double));
void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float));
@ -276,7 +277,7 @@ void PlotBars(const char* label_id, const float* xs, const float* ys, int count,
void PlotBars(const char* label_id, const double* xs, const double* ys, int count, double width, int offset = 0, int stride = sizeof(double)); void PlotBars(const char* label_id, const double* xs, const double* ys, int count, double width, int offset = 0, int stride = sizeof(double));
void PlotBars(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double width, int offset = 0); void PlotBars(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double width, int offset = 0);
// Plots a horizontal bar graph. # height and # shift are in Y units. // Plots a horizontal bar graph. #height and #shift are in Y units.
void PlotBarsH(const char* label_id, const float* values, int count, float height = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float)); void PlotBarsH(const char* label_id, const float* values, int count, float height = 0.67f, float shift = 0, int offset = 0, int stride = sizeof(float));
void PlotBarsH(const char* label_id, const double* values, int count, double height = 0.67f, double shift = 0, int offset = 0, int stride = sizeof(double)); void PlotBarsH(const char* label_id, const double* values, int count, double height = 0.67f, double shift = 0, int offset = 0, int stride = sizeof(double));
void PlotBarsH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset = 0, int stride = sizeof(float)); void PlotBarsH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset = 0, int stride = sizeof(float));
@ -295,15 +296,15 @@ void PlotErrorBarsH(const char* label_id, const double* xs, const double* ys, co
void PlotErrorBarsH(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); void PlotErrorBarsH(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float));
void PlotErrorBarsH(const char* label_id, const double* xs, const double* ys, const double* neg, const double* pos, int count, int offset = 0, int stride = sizeof(double)); void PlotErrorBarsH(const char* label_id, const double* xs, const double* ys, const double* neg, const double* pos, int count, int offset = 0, int stride = sizeof(double));
// Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. // Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels.
void PlotPieChart(const char** label_ids, const float* values, int count, float x, float y, float radius, bool normalize = false, const char* label_fmt = "%.1f", float angle0 = 90); void PlotPieChart(const char** label_ids, const float* values, int count, float x, float y, float radius, bool normalize = false, const char* label_fmt = "%.1f", float angle0 = 90);
void PlotPieChart(const char** label_ids, const double* values, int count, double x, double y, double radius, bool normalize = false, const char* label_fmt = "%.1f", double angle0 = 90); void PlotPieChart(const char** label_ids, const double* values, int count, double x, double y, double radius, bool normalize = false, const char* label_fmt = "%.1f", double angle0 = 90);
// Plots a 2D heatmap chart. Values are expected to be in row-major order. label_fmt can be set to NULL for no labels. // Plots a 2D heatmap chart. Values are expected to be in row-major order. #label_fmt can be set to NULL for no labels.
void PlotHeatmap(const char* label_id, const float* values, int rows, int cols, float scale_min, float scale_max, const char* label_fmt = "%.1f", const ImPlotPoint& bounds_min = ImPlotPoint(0,0), const ImPlotPoint& bounds_max = ImPlotPoint(1,1)); void PlotHeatmap(const char* label_id, const float* values, int rows, int cols, float scale_min, float scale_max, const char* label_fmt = "%.1f", const ImPlotPoint& bounds_min = ImPlotPoint(0,0), const ImPlotPoint& bounds_max = ImPlotPoint(1,1));
void PlotHeatmap(const char* label_id, const double* values, int rows, int cols, double scale_min, double scale_max, const char* label_fmt = "%.1f", const ImPlotPoint& bounds_min = ImPlotPoint(0,0), const ImPlotPoint& bounds_max = ImPlotPoint(1,1)); void PlotHeatmap(const char* label_id, const double* values, int rows, int cols, double scale_min, double scale_max, const char* label_fmt = "%.1f", const ImPlotPoint& bounds_min = ImPlotPoint(0,0), const ImPlotPoint& bounds_max = ImPlotPoint(1,1));
// Plots digital data. // Plots digital data. Digital plots do not respond to y drag or zoom, and are always referenced to the bottom of the plot.
void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float));
void PlotDigital(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double)); void PlotDigital(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double));
void PlotDigital(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0); void PlotDigital(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0);
@ -312,10 +313,46 @@ void PlotDigital(const char* label_id, ImPlotPoint (*getter)(void* data, int idx
void PlotText(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0)); void PlotText(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0));
void PlotText(const char* text, double x, double y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0)); void PlotText(const char* text, double x, double y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0));
//-----------------------------------------------------------------------------
// Plot Utils
//-----------------------------------------------------------------------------
// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first (left) Y axis.
void SetPlotYAxis(int y_axis);
// Set the axes range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked.
void SetNextPlotLimits(double x_min, double x_max, double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once);
// Set the X axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the X axis limits will be locked.
void SetNextPlotLimitsX(double x_min, double x_max, ImGuiCond cond = ImGuiCond_Once);
// Set the Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the Y axis limits will be locked.
void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once, int y_axis = 0);
// Fits the next plot axes to all plotted data if they are unlocked (equivalent to double-clicks).
void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true);
// Set the X axis ticks and optionally the labels for the next plot.
void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false);
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char** labels = NULL, bool show_default = false);
// Set the Y axis ticks and optionally the labels for the next plot.
void SetNextPlotTicksY(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false, int y_axis = 0);
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char** labels = NULL, bool show_default = false, int y_axis = 0);
// Convert pixels to a position in the current plot's coordinate system. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
ImPlotPoint PixelsToPlot(const ImVec2& pix, int y_axis = -1);
ImPlotPoint PixelsToPlot(float x, float y, int y_axis = -1);
// Convert a position in the current plot's coordinate system to pixels. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
ImVec2 PlotToPixels(const ImPlotPoint& plt, int y_axis = -1);
ImVec2 PlotToPixels(double x, double y, int y_axis = -1);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Plot Queries // Plot Queries
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Get the current Plot position (top-left) in pixels.
ImVec2 GetPlotPos();
// Get the curent Plot size in pixels.
ImVec2 GetPlotSize();
// Returns true if the plot area in the current plot is hovered. // Returns true if the plot area in the current plot is hovered.
bool IsPlotHovered(); bool IsPlotHovered();
// Returns true if the XAxis plot area in the current plot is hovered. // Returns true if the XAxis plot area in the current plot is hovered.
@ -333,13 +370,6 @@ ImPlotLimits GetPlotQuery(int y_axis = -1);
// Returns true if a plot item legend entry is hovered. // Returns true if a plot item legend entry is hovered.
bool IsLegendEntryHovered(const char* label_id); bool IsLegendEntryHovered(const char* label_id);
//-----------------------------------------------------------------------------
// Plot Input Mapping
//-----------------------------------------------------------------------------
// Allows changing how keyboard/mouse interaction works.
ImPlotInputMap& GetInputMap();
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Plot Styling and Colormaps // Plot Styling and Colormaps
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -347,7 +377,7 @@ ImPlotInputMap& GetInputMap();
// Provides access to plot style structure for permanant modifications to colors, sizes, etc. // Provides access to plot style structure for permanant modifications to colors, sizes, etc.
ImPlotStyle& GetStyle(); ImPlotStyle& GetStyle();
// Special color used to indicate that a style color should be deduced automatically from defaults or colormaps. // Special color used to indicate that a style color should be deduced automatically from ImGui style or ImPlot colormaps.
#define IMPLOT_COL_AUTO ImVec4(0,0,0,-1) #define IMPLOT_COL_AUTO ImVec4(0,0,0,-1)
// Temporarily modify a plot color. Don't forget to call PopStyleColor! // Temporarily modify a plot color. Don't forget to call PopStyleColor!
@ -368,8 +398,8 @@ void PopStyleVar(int count = 1);
// Temporarily switch to one of the built-in colormaps. // Temporarily switch to one of the built-in colormaps.
void PushColormap(ImPlotColormap colormap); void PushColormap(ImPlotColormap colormap);
// Temporarily switch to your custom colormap. The pointer data must persist until the matching call to PopColormap. // Temporarily switch to your custom colormap. The pointer data must persist until the matching call to PopColormap!
void PushColormap(const ImVec4* colormap, int size); void PushColormap(const ImVec4* colormap, int size);
// Undo temporary colormap modification. // Undo temporary colormap modification.
void PopColormap(int count = 1); void PopColormap(int count = 1);
// Permanently sets a custom colormap. The colors will be copied to internal memory. Prefer PushColormap instead of calling this each frame. // Permanently sets a custom colormap. The colors will be copied to internal memory. Prefer PushColormap instead of calling this each frame.
@ -388,46 +418,16 @@ ImVec4 NextColormapColor();
// Returns a null terminated string name for a built-in colormap // Returns a null terminated string name for a built-in colormap
const char* GetColormapName(ImPlotColormap colormap); const char* GetColormapName(ImPlotColormap colormap);
//----------------------------------------------------------------------------- // Renders a vertical color scale using the current color map.
// Plot Utils
//-----------------------------------------------------------------------------
// Set the axes range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked.
void SetNextPlotLimits(double x_min, double x_max, double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once);
// Set the X axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the X axis limits will be locked.
void SetNextPlotLimitsX(double x_min, double x_max, ImGuiCond cond = ImGuiCond_Once);
// Set the Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the Y axis limits will be locked.
void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once, int y_axis = 0);
// Fits the next plot axes to all plotted data if they are unlocked (equivalent to double-clicks).
void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true);
// Set the X axis ticks and optionally the labels for the next plot.
void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false);
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char** labels = NULL, bool show_default = false);
// Set the Y axis ticks and optionally the labels for the next plot.
void SetNextPlotTicksY(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false, int y_axis = 0);
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char** labels = NULL, bool show_default = false, int y_axis = 0);
// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first (left) Y axis.
void SetPlotYAxis(int y_axis);
// Get the current Plot position (top-left) in pixels.
ImVec2 GetPlotPos();
// Get the curent Plot size in pixels.
ImVec2 GetPlotSize();
// Convert pixels to a position in the current plot's coordinate system. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
ImPlotPoint PixelsToPlot(const ImVec2& pix, int y_axis = -1);
ImPlotPoint PixelsToPlot(float x, float y, int y_axis = -1);
// Convert a position in the current plot's coordinate system to pixels. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
ImVec2 PlotToPixels(const ImPlotPoint& plt, int y_axis = -1);
ImVec2 PlotToPixels(double x, double y, int y_axis = -1);
// Renders a vertical color scale using the current color map
void ShowColormapScale(double scale_min, double scale_max, float height); void ShowColormapScale(double scale_min, double scale_max, float height);
//-----------------------------------------------------------------------------
// Miscellaneous
//-----------------------------------------------------------------------------
// Allows changing how keyboard/mouse interaction works.
ImPlotInputMap& GetInputMap();
// Push clip rect for rendering to current plot area. // Push clip rect for rendering to current plot area.
void PushPlotClipRect(); void PushPlotClipRect();
// Pop plot clip rect. // Pop plot clip rect.

View File

@ -36,14 +36,14 @@ namespace MyImPlot {
// Examples for passing custom function pointers to ImPlot in Custom Getters section. // Examples for passing custom function pointers to ImPlot in Custom Getters section.
struct WaveData { struct WaveData {
double X, Amp, Freq, Offset; double X, Amp, Freq, Offset;
WaveData(double x, double amp, double freq, double offset) { X = x; Amp = amp; Freq = freq; Offset = offset; } WaveData(double x, double amp, double freq, double offset) { X = x; Amp = amp; Freq = freq; Offset = offset; }
}; };
ImPlotPoint SineWave(void* wave_data, int idx); ImPlotPoint SineWave(void* wave_data, int idx);
ImPlotPoint SawWave(void* wave_data, int idx); ImPlotPoint SawWave(void* wave_data, int idx);
ImPlotPoint Spiral(void*, int idx); ImPlotPoint Spiral(void*, int idx);
// Example for Tables section. Generates a quick and simple shaded line plot. See implementation at bottom. // Example for Tables section. Generates a quick and simple shaded line plot. See implementation at bottom.
void Sparkline(const char* id, const float* values, int count, float min_v, float max_v, int offset, const ImVec4& col, const ImVec2& size); void Sparkline(const char* id, const float* values, int count, float min_v, float max_v, int offset, const ImVec4& col, const ImVec2& size);
// Example for Custom Plotters and Tooltips section. Plots a candlestick chart for financial data. See implementation at bottom. // Example for Custom Plotters and Tooltips section. Plots a candlestick chart for financial data. See implementation at bottom.
void PlotCandlestick(const char* label_id, const double* xs, const double* opens, const double* closes, const double* lows, const double* highs, int count, bool tooltip = true, float width_percent = 0.25f, ImVec4 bullCol = ImVec4(0,1,0,1), ImVec4 bearCol = ImVec4(1,0,0,1)); void PlotCandlestick(const char* label_id, const double* xs, const double* opens, const double* closes, const double* lows, const double* highs, int count, bool tooltip = true, float width_percent = 0.25f, ImVec4 bullCol = ImVec4(0,1,0,1), ImVec4 bearCol = ImVec4(1,0,0,1));
} // namespace MyImPlot } // namespace MyImPlot
@ -153,7 +153,7 @@ void ShowDemoWindow(bool* p_open) {
ImGui::EndMenuBar(); ImGui::EndMenuBar();
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
ImGui::Text("ImPlot says hello. (0.5 WIP)"); ImGui::Text("ImPlot says hello. (%s)", IMPLOT_VERSION);
if (ImGui::CollapsingHeader("Help")) { if (ImGui::CollapsingHeader("Help")) {
ImGui::Text("USER GUIDE:"); ImGui::Text("USER GUIDE:");
ImGui::BulletText("Left click and drag within the plot area to pan X and Y axes."); ImGui::BulletText("Left click and drag within the plot area to pan X and Y axes.");
@ -472,7 +472,7 @@ void ShowDemoWindow(bool* p_open) {
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) { if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
// two methods of plotting Data // two methods of plotting Data
// as ImVec2* (or ImPlot*): // as ImVec2* (or ImPlot*):
ImPlot::PlotLine("Data 1", &rdata1.Data[0], rdata1.Data.size()); ImPlot::PlotLine("Data 1", &rdata1.Data[0], rdata1.Data.size());
// as float*, float* (or double*, double*) // as float*, float* (or double*, double*)
ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(t_float)); ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(t_float));
ImPlot::EndPlot(); ImPlot::EndPlot();
@ -612,7 +612,7 @@ void ShowDemoWindow(bool* p_open) {
ImGui::ColorEdit4("##Col2", &y2_col.x, ImGuiColorEditFlags_NoInputs); ImGui::ColorEdit4("##Col2", &y2_col.x, ImGuiColorEditFlags_NoInputs);
ImGui::SameLine(); ImGui::SameLine();
ImGui::ColorEdit4("##Col3", &y3_col.x, ImGuiColorEditFlags_NoInputs); ImGui::ColorEdit4("##Col3", &y3_col.x, ImGuiColorEditFlags_NoInputs);
// you can fit axes programatically // you can fit axes programatically
ImGui::SameLine(); if (ImGui::Button("Fit X")) ImPlot::FitNextPlotAxes(true, false, false, false); ImGui::SameLine(); if (ImGui::Button("Fit X")) ImPlot::FitNextPlotAxes(true, false, false, false);
ImGui::SameLine(); if (ImGui::Button("Fit Y")) ImPlot::FitNextPlotAxes(false, true, false, false); ImGui::SameLine(); if (ImGui::Button("Fit Y")) ImPlot::FitNextPlotAxes(false, true, false, false);
ImGui::SameLine(); if (ImGui::Button("Fit Y2")) ImPlot::FitNextPlotAxes(false, false, true, false); ImGui::SameLine(); if (ImGui::Button("Fit Y2")) ImPlot::FitNextPlotAxes(false, false, true, false);
@ -936,7 +936,7 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Checkbox("Animate",&anim); ImGui::Checkbox("Animate",&anim);
if (anim) if (anim)
offset = (offset + 1) % 100; offset = (offset + 1) % 100;
if (ImGui::BeginTable("##table", 3, flags, ImVec2(-1,0))) { if (ImGui::BeginTable("##table", 3, flags, ImVec2(-1,0))) {
ImGui::TableSetupColumn("Electrode", ImGuiTableColumnFlags_WidthFixed, 75.0f); ImGui::TableSetupColumn("Electrode", ImGuiTableColumnFlags_WidthFixed, 75.0f);
ImGui::TableSetupColumn("Voltage", ImGuiTableColumnFlags_WidthFixed, 75.0f); ImGui::TableSetupColumn("Voltage", ImGuiTableColumnFlags_WidthFixed, 75.0f);
ImGui::TableSetupColumn("EMG Signal"); ImGui::TableSetupColumn("EMG Signal");
@ -1110,7 +1110,7 @@ void ShowDemoWindow(bool* p_open) {
MyImPlot::PlotCandlestick("GOOGL",dates, opens, closes, lows, highs, 218, tooltip, 0.25f, bullCol, bearCol); MyImPlot::PlotCandlestick("GOOGL",dates, opens, closes, lows, highs, 218, tooltip, 0.25f, bullCol, bearCol);
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Benchmark")) { if (ImGui::CollapsingHeader("Benchmark")) {
static const int n_items = 100; static const int n_items = 100;
@ -1163,11 +1163,11 @@ ImPlotPoint Spiral(void*, int idx) {
float n = (r - a) / b; // number of revolutions float n = (r - a) / b; // number of revolutions
double th = 2 * n * 3.14; // angle double th = 2 * n * 3.14; // angle
float Th = float(th * idx / (1000 - 1)); float Th = float(th * idx / (1000 - 1));
return ImPlotPoint(0.5f+(a + b*Th / (2.0f * (float) 3.14))*Cos(Th), return ImPlotPoint(0.5f+(a + b*Th / (2.0f * (float) 3.14))*Cos(Th),
0.5f + (a + b*Th / (2.0f * (float)3.14))*Sin(Th)); 0.5f + (a + b*Th / (2.0f * (float)3.14))*Sin(Th));
} }
// Example for Tables section. Generates a quick and simple shaded line plot. See implementation at bottom. // Example for Tables section. Generates a quick and simple shaded line plot. See implementation at bottom.
void Sparkline(const char* id, const float* values, int count, float min_v, float max_v, int offset, const ImVec4& col, const ImVec2& size) { void Sparkline(const char* id, const float* values, int count, float min_v, float max_v, int offset, const ImVec4& col, const ImVec2& size) {
ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(0,0)); ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(0,0));
ImPlot::SetNextPlotLimits(0, count - 1, min_v, max_v, ImGuiCond_Always); ImPlot::SetNextPlotLimits(0, count - 1, min_v, max_v, ImGuiCond_Always);
@ -1197,25 +1197,25 @@ void Sparkline(const char* id, const float* values, int count, float min_v, floa
namespace MyImPlot { namespace MyImPlot {
int BinarySearch(const double* arr, int l, int r, double x) { int BinarySearch(const double* arr, int l, int r, double x) {
if (r >= l) { if (r >= l) {
int mid = l + (r - l) / 2; int mid = l + (r - l) / 2;
if (arr[mid] == x) if (arr[mid] == x)
return mid; return mid;
if (arr[mid] > x) if (arr[mid] > x)
return BinarySearch(arr, l, mid - 1, x); return BinarySearch(arr, l, mid - 1, x);
return BinarySearch(arr, mid + 1, r, x); return BinarySearch(arr, mid + 1, r, x);
} }
return -1; return -1;
} }
void PlotCandlestick(const char* label_id, const double* xs, const double* opens, const double* closes, const double* lows, const double* highs, int count, bool tooltip, float width_percent, ImVec4 bullCol, ImVec4 bearCol) { void PlotCandlestick(const char* label_id, const double* xs, const double* opens, const double* closes, const double* lows, const double* highs, int count, bool tooltip, float width_percent, ImVec4 bullCol, ImVec4 bearCol) {
// get current implot context // get current implot context
ImPlotContext* implot = ImPlot::GetCurrentContext(); ImPlotContext* implot = ImPlot::GetCurrentContext();
// register item // register item
ImPlotItem* item = ImPlot::RegisterOrGetItem(label_id); ImPlotItem* item = ImPlot::RegisterOrGetItem(label_id);
// override legend icon color // override legend icon color
item->Color = ImVec4(1,1,1,1); item->Color = ImVec4(1,1,1,1);
// return if item not shown (i.e. hidden by legend button) // return if item not shown (i.e. hidden by legend button)
if (!item->Show) if (!item->Show)
return; return;

View File

@ -435,7 +435,7 @@ ImPlotState* GetPlot(const char* title);
// Gets the current plot from the current ImPlotContext // Gets the current plot from the current ImPlotContext
ImPlotState* GetCurrentPlot(); ImPlotState* GetCurrentPlot();
// Updates plot-to-pixel space transformation variables for the current plot // Updates plot-to-pixel space transformation variables for the current plot.
void UpdateTransformCache(); void UpdateTransformCache();
// Extends the current plots axes so that it encompasses point p // Extends the current plots axes so that it encompasses point p
void FitPoint(const ImPlotPoint& p); void FitPoint(const ImPlotPoint& p);
@ -461,7 +461,7 @@ void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImVector<
// Populates a list of ImPlotTicks with logarithmic space and formatted ticks // Populates a list of ImPlotTicks with logarithmic space and formatted ticks
void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImVector<ImPlotTick>& out); void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImVector<ImPlotTick>& out);
// Populates a list of ImPlotTicks with custom spaced and labeled ticks // Populates a list of ImPlotTicks with custom spaced and labeled ticks
void AddCustomTicks(const double* values, const char** labels, int n, ImVector<ImPlotTick>& ticks, ImGuiTextBuffer& buffer); void AddTicksCustom(const double* values, const char** labels, int n, ImVector<ImPlotTick>& ticks, ImGuiTextBuffer& buffer);
// Creates label information for a list of ImPlotTick // Creates label information for a list of ImPlotTick
void LabelTicks(ImVector<ImPlotTick> &ticks, bool scientific, ImGuiTextBuffer& buffer); void LabelTicks(ImVector<ImPlotTick> &ticks, bool scientific, ImGuiTextBuffer& buffer);
// Gets the widest visible (i.e. ShowLabel = true) label size from a list of ticks // Gets the widest visible (i.e. ShowLabel = true) label size from a list of ticks

View File

@ -126,9 +126,9 @@ struct GetterImVec2 {
Count = count; Count = count;
Offset = count ? ImPosMod(offset, count) : 0; Offset = count ? ImPosMod(offset, count) : 0;
} }
inline ImPlotPoint operator()(int idx) { inline ImPlotPoint operator()(int idx) {
idx = ImPosMod(Offset + idx, Count); idx = ImPosMod(Offset + idx, Count);
return ImPlotPoint(Data[idx].x, Data[idx].y); return ImPlotPoint(Data[idx].x, Data[idx].y);
} }
const ImVec2* Data; const ImVec2* Data;
int Count; int Count;
@ -142,9 +142,9 @@ struct GetterImPlotPoint {
Count = count; Count = count;
Offset = count ? ImPosMod(offset, count) : 0; Offset = count ? ImPosMod(offset, count) : 0;
} }
inline ImPlotPoint operator()(int idx) { inline ImPlotPoint operator()(int idx) {
idx = ImPosMod(Offset + idx, Count); idx = ImPosMod(Offset + idx, Count);
return Data[idx]; return Data[idx];
} }
const ImPlotPoint* Data; const ImPlotPoint* Data;
int Count; int Count;
@ -159,9 +159,9 @@ struct GetterFuncPtrImPlotPoint {
Count = count; Count = count;
Offset = count ? ImPosMod(offset, count) : 0; Offset = count ? ImPosMod(offset, count) : 0;
} }
inline ImPlotPoint operator()(int idx) { inline ImPlotPoint operator()(int idx) {
idx = ImPosMod(Offset + idx, Count); idx = ImPosMod(Offset + idx, Count);
return getter(Data, idx); return getter(Data, idx);
} }
ImPlotPoint (*getter)(void* data, int idx); ImPlotPoint (*getter)(void* data, int idx);
void* Data; void* Data;