From fce58ee0756aa051f67f59fb77501c685dfc032a Mon Sep 17 00:00:00 2001 From: epezent Date: Sun, 30 Aug 2020 11:03:25 -0500 Subject: [PATCH] add ImPlotScale, ImPlotNextItemData, BeginItem EndItem, and more --- implot.cpp | 73 ++++-------------- implot.h | 14 +++- implot_internal.h | 64 ++++++++++++++-- implot_items.cpp | 188 ++++++++++++++++++++++++++++++---------------- 4 files changed, 207 insertions(+), 132 deletions(-) diff --git a/implot.cpp b/implot.cpp index 9a5ce87..85bc6f3 100644 --- a/implot.cpp +++ b/implot.cpp @@ -360,6 +360,7 @@ void Reset(ImPlotContext* ctx) { ctx->DigitalPlotOffset = 0; // nullify plot ctx->CurrentPlot = NULL; + ctx->CurrentItem = NULL; } //----------------------------------------------------------------------------- @@ -409,13 +410,11 @@ void UpdateTransformCache() { ImHasFlag(gp.CurrentPlot->YAxis[i].Flags, ImPlotAxisFlags_Invert) ? gp.BB_Plot.Min.y : gp.BB_Plot.Max.y, ImHasFlag(gp.CurrentPlot->XAxis.Flags, ImPlotAxisFlags_Invert) ? gp.BB_Plot.Min.x : gp.BB_Plot.Max.x, ImHasFlag(gp.CurrentPlot->YAxis[i].Flags, ImPlotAxisFlags_Invert) ? gp.BB_Plot.Max.y : gp.BB_Plot.Min.y); - gp.My[i] = (gp.PixelRange[i].Max.y - gp.PixelRange[i].Min.y) / gp.CurrentPlot->YAxis[i].Range.Size(); } gp.LogDenX = ImLog10(gp.CurrentPlot->XAxis.Range.Max / gp.CurrentPlot->XAxis.Range.Min); - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - gp.LogDenY[i] = ImLog10(gp.CurrentPlot->YAxis[i].Range.Max / gp.CurrentPlot->YAxis[i].Range.Min); - } + for (int i = 0; i < IMPLOT_Y_AXES; i++) + gp.LogDenY[i] = ImLog10(gp.CurrentPlot->YAxis[i].Range.Max / gp.CurrentPlot->YAxis[i].Range.Min); gp.Mx = (gp.PixelRange[0].Max.x - gp.PixelRange[0].Min.x) / gp.CurrentPlot->XAxis.Range.Size(); } @@ -465,61 +464,6 @@ ImVec2 PlotToPixels(const ImPlotPoint& plt, int y_axis) { return PlotToPixels(plt.x, plt.y, y_axis); } -//----------------------------------------------------------------------------- -// Item Utils -//----------------------------------------------------------------------------- - -ImPlotItem* RegisterOrGetItem(const char* label_id) { - ImPlotContext& gp = *GImPlot; - ImGuiID id = ImGui::GetID(label_id); - ImPlotItem* item = gp.CurrentPlot->Items.GetOrAddByKey(id); - if (item->SeenThisFrame) - return item; - item->SeenThisFrame = true; - int idx = gp.CurrentPlot->Items.GetIndex(item); - item->ID = id; - if (ImGui::FindRenderedTextEnd(label_id, NULL) != label_id) { - gp.LegendIndices.push_back(idx); - item->NameOffset = gp.LegendLabels.size(); - gp.LegendLabels.append(label_id, label_id + strlen(label_id) + 1); - } - else { - item->Show = true; - } - if (item->Show) - gp.VisibleItemCount++; - return item; -} - -ImPlotItem* GetItem(int i) { - ImPlotContext& gp = *GImPlot; - return gp.CurrentPlot->Items.GetByIndex(gp.LegendIndices[i]); -} - -ImPlotItem* GetItem(const char* label_id) { - ImPlotContext& gp = *GImPlot; - ImGuiID id = ImGui::GetID(label_id); - return gp.CurrentPlot->Items.GetByKey(id); -} - -ImPlotItem* GetItem(const char* plot_title, const char* item_label_id) { - ImPlotState* plot = GetPlot(plot_title); - if (plot) { - ImGuiID id = ImGui::GetID(item_label_id); - return plot->Items.GetByKey(id); - } - return NULL; -} - -void BustItemCache() { - ImPlotContext& gp = *GImPlot; - for (int p = 0; p < gp.Plots.GetSize(); ++p) { - ImPlotState& plot = *gp.Plots.GetByIndex(p); - plot.ColormapIdx = 0; - plot.Items.Clear(); - } -} - //----------------------------------------------------------------------------- // Legend Utils //----------------------------------------------------------------------------- @@ -740,6 +684,17 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons gp.LockPlot = gp.X.Lock && gp.Y[0].Lock && gp.Y[1].Lock && gp.Y[2].Lock; + for (int i = 0; i < IMPLOT_Y_AXES; ++i) { + if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) + gp.Scales[i] = ImPlotScale_LinLin; + else if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) + gp.Scales[i] = ImPlotScale_LogLin; + else if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) + gp.Scales[i] = ImPlotScale_LinLog; + else if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) + gp.Scales[i] = ImPlotScale_LogLog; + } + // CONSTRAINTS ------------------------------------------------------------ ConstrainAxis(plot.XAxis); diff --git a/implot.h b/implot.h index 378b45c..a129afc 100644 --- a/implot.h +++ b/implot.h @@ -204,8 +204,8 @@ struct ImPlotStyle { float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels float DigitalBitHeight; // = 8, digital channels bit height (at y = 1.0f) in pixels float DigitalBitGap; // = 4, digital channels bit padding gap in pixels - bool AntiAliasedLines; // = false, enable global anti-aliasing on plot lines (overrides ImPlotFlags_AntiAliased) // plot styling variables + bool AntiAliasedLines; // = false, enable global anti-aliasing on plot lines (overrides ImPlotFlags_AntiAliased) float PlotBorderSize; // = 1, line thickness of border around plot area float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines ImVec2 MajorTickLen; // = 10,10 major tick lengths for X and Y axes @@ -417,6 +417,9 @@ bool IsLegendEntryHovered(const char* label_id); // Plot and Item Styling and 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) + // Provides access to plot style structure for permanant modifications to colors, sizes, etc. ImPlotStyle& GetStyle(); @@ -429,9 +432,6 @@ void StyleColorsDark(ImPlotStyle* dst = NULL); // Style colors for ImGui "Light". void StyleColorsLight(ImPlotStyle* dst = NULL); -// 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) - // Temporarily modify a plot color. Don't forget to call PopStyleColor! void PushStyleColor(ImPlotCol idx, ImU32 col); // Temporarily modify a plot color. Don't forget to call PopStyleColor! @@ -448,6 +448,12 @@ void PushStyleVar(ImPlotStyleVar idx, const ImVec2& val); // Undo temporary style modification. void PopStyleVar(int count = 1); +void SetNextItemColor(ImPlotCol idx, const ImVec4& col); +void SetNextItemColor(ImPlotCol idx, ImU32 col); +void SetNextItemColorV(int count, ...); + + + // Temporarily switch to one of the built-in colormaps. void PushColormap(ImPlotColormap colormap); // Temporarily switch to your custom colormap. The pointer data must persist until the matching call to PopColormap! diff --git a/implot_internal.h b/implot_internal.h index 294b454..25b0cde 100644 --- a/implot_internal.h +++ b/implot_internal.h @@ -143,6 +143,20 @@ struct ImArray { const int Size = N; }; +//----------------------------------------------------------------------------- +// [SECTION] ImPlot Enums +//----------------------------------------------------------------------------- + +typedef int ImPlotScale; // -> enum ImPlotScale_ + +// XY axes scaling combinations +enum ImPlotScale_ { + ImPlotScale_LinLin, // linear x, linear y + ImPlotScale_LogLin, // log x, linear y + ImPlotScale_LinLog, // linear x, log y + ImPlotScale_LogLog // log x, log y +}; + //----------------------------------------------------------------------------- // [SECTION] ImPlot Structs //----------------------------------------------------------------------------- @@ -358,11 +372,33 @@ struct ImPlotNextPlotData } }; +// Temporary data storage for upcoming item +struct ImPlotNextItemData { + ImVec4 Colors[5]; + float LineWeight; + ImPlotMarker Marker; + float MarkerSize; + float MarkerWeight; + float FillAlpha; + float ErrorBarSize; + float ErrorBarWeight; + float DigitalBitHeight; + float DigitalBitGap; + ImPlotNextItemData() { + for (int i = 0; i < 5; ++i) + Colors[i] = IMPLOT_COL_AUTO; + LineWeight = MarkerWeight = FillAlpha = ErrorBarSize = + ErrorBarSize = ErrorBarWeight = DigitalBitHeight = DigitalBitGap = -1; + Marker = -1; + } +}; + // Holds state information that must persist between calls to BeginPlot()/EndPlot() struct ImPlotContext { // Plot States ImPool Plots; ImPlotState* CurrentPlot; + ImPlotItem* CurrentItem; // Legend ImVector LegendIndices; @@ -385,6 +421,7 @@ struct ImPlotContext { float YAxisReference[IMPLOT_Y_AXES]; // Transformations and Data Extents + ImPlotScale Scales[IMPLOT_Y_AXES]; ImRect PixelRange[IMPLOT_Y_AXES]; double Mx; double My[IMPLOT_Y_AXES]; @@ -423,6 +460,7 @@ struct ImPlotContext { int DigitalPlotItemCnt; int DigitalPlotOffset; ImPlotNextPlotData NextPlotData; + ImPlotNextItemData NextItemData; ImPlotInputMap InputMap; ImPlotPoint MousePos[IMPLOT_Y_AXES]; }; @@ -461,6 +499,15 @@ void BustPlotCache(); void UpdateTransformCache(); // Extends the current plots axes so that it encompasses point p void FitPoint(const ImPlotPoint& p); +// Gets the current y-axis for the current plot +inline int GetCurrentYAxis() { return GImPlot->CurrentPlot->CurrentYAxis; } +// Gets the XY scale for the current plot and y-axis +inline ImPlotScale GetCurrentScale() { return GImPlot->Scales[GetCurrentYAxis()]; } + +// Begins a new item. Returns false if the item should not be plotted. +bool BeginItem(const char* label_id); +// Ends an item (call only if BeginItem returns true) +void EndItem(); // Register or get an existing item from the current plot ImPlotItem* RegisterOrGetItem(const char* label_id); @@ -470,9 +517,20 @@ ImPlotItem* GetItem(int i); ImPlotItem* GetItem(const char* label_id); // Gets a plot item from a specific plot ImPlotItem* GetItem(const char* plot_title, const char* item_label_id); +// Gets the current item +ImPlotItem* GetCurrentItem(); // Busts the cache for every item for every plot in the current context. void BustItemCache(); +// Get styling data for next item (call between Begin/EndItem) +const ImPlotNextItemData& GetNextItemData(); + +// Recolors an item legend icon from an the current ImPlotCol if it is not automatic (i.e. alpha != -1) +inline void TryRecolorItem(ImPlotItem* item, ImPlotCol idx) { + if (GImPlot->Style.Colors[idx].w != -1) + item->Color = GImPlot->Style.Colors[idx]; +} + // Returns the number of entries in the current legend int GetLegendCount(); // Gets the ith entry string for the current legend @@ -559,12 +617,6 @@ ImVec4 GetAutoColor(ImPlotCol idx); inline ImVec4 GetStyleColorVec4(ImPlotCol idx) {return IsColorAuto(idx) ? GetAutoColor(idx) : GImPlot->Style.Colors[idx]; } inline ImU32 GetStyleColorU32(ImPlotCol idx) { return ImGui::ColorConvertFloat4ToU32(GetStyleColorVec4(idx)); } -// Recolors an item legend icon from an the current ImPlotCol if it is not automatic (i.e. alpha != -1) -inline void TryRecolorItem(ImPlotItem* item, ImPlotCol idx) { - if (GImPlot->Style.Colors[idx].w != -1) - item->Color = GImPlot->Style.Colors[idx]; -} - // Returns true if lines will render (e.g. basic lines, bar outlines) inline bool WillLineRender() { return GImPlot->Style.Colors[ImPlotCol_Line].w != 0 && GImPlot->Style.LineWeight > 0; diff --git a/implot_items.cpp b/implot_items.cpp index 28192a2..e41c303 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -44,6 +44,92 @@ namespace ImPlot { +//----------------------------------------------------------------------------- +// Item Utils +//----------------------------------------------------------------------------- + +ImPlotItem* RegisterOrGetItem(const char* label_id) { + ImPlotContext& gp = *GImPlot; + ImGuiID id = ImGui::GetID(label_id); + ImPlotItem* item = gp.CurrentPlot->Items.GetOrAddByKey(id); + if (item->SeenThisFrame) + return item; + item->SeenThisFrame = true; + int idx = gp.CurrentPlot->Items.GetIndex(item); + item->ID = id; + if (ImGui::FindRenderedTextEnd(label_id, NULL) != label_id) { + gp.LegendIndices.push_back(idx); + item->NameOffset = gp.LegendLabels.size(); + gp.LegendLabels.append(label_id, label_id + strlen(label_id) + 1); + } + else { + item->Show = true; + } + if (item->Show) + gp.VisibleItemCount++; + return item; +} + +ImPlotItem* GetItem(int i) { + ImPlotContext& gp = *GImPlot; + return gp.CurrentPlot->Items.GetByIndex(gp.LegendIndices[i]); +} + +ImPlotItem* GetItem(const char* label_id) { + ImPlotContext& gp = *GImPlot; + ImGuiID id = ImGui::GetID(label_id); + return gp.CurrentPlot->Items.GetByKey(id); +} + +ImPlotItem* GetItem(const char* plot_title, const char* item_label_id) { + ImPlotState* plot = GetPlot(plot_title); + if (plot) { + ImGuiID id = ImGui::GetID(item_label_id); + return plot->Items.GetByKey(id); + } + return NULL; +} + +ImPlotItem* GetCurrentItem() { + ImPlotContext& gp = *GImPlot; + return gp.CurrentItem; +} + +void BustItemCache() { + ImPlotContext& gp = *GImPlot; + for (int p = 0; p < gp.Plots.GetSize(); ++p) { + ImPlotState& plot = *gp.Plots.GetByIndex(p); + plot.ColormapIdx = 0; + plot.Items.Clear(); + } +} + +// Begins a new item. Returns false if the item should not be plotted. +bool BeginItem(const char* label_id) { + ImPlotContext& gp = *GImPlot; + ImPlotItem* item = RegisterOrGetItem(label_id); + if (!item->Show) { + // reset next item data + gp.NextItemData = ImPlotNextItemData(); + return false; + } + else { + // set current item + gp.CurrentItem = item; + // stage next item data + return true; + } +} + +// Ends an item (call only if BeginItem returns true) +void EndItem() { + ImPlotContext& gp = *GImPlot; + // reset next item data + gp.NextItemData = ImPlotNextItemData(); + // set current item + gp.CurrentItem = NULL; +} + //----------------------------------------------------------------------------- // GETTERS //----------------------------------------------------------------------------- @@ -205,7 +291,7 @@ struct GetterError { // Transforms points for linear x and linear y space struct TransformerLinLin { - TransformerLinLin(int y_axis) : YAxis(y_axis) {} + TransformerLinLin() : YAxis(GetCurrentYAxis()) {} inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); } inline ImVec2 operator()(double x, double y) { @@ -219,7 +305,7 @@ struct TransformerLinLin { // Transforms points for log x and linear y space struct TransformerLogLin { - TransformerLogLin(int y_axis) : YAxis(y_axis) {} + TransformerLogLin() : YAxis(GetCurrentYAxis()) {} inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); } inline ImVec2 operator()(double x, double y) { @@ -235,7 +321,7 @@ struct TransformerLogLin { // Transforms points for linear x and log y space struct TransformerLinLog { - TransformerLinLog(int y_axis) : YAxis(y_axis) {} + TransformerLinLog() : YAxis(GetCurrentYAxis()) {} inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); } inline ImVec2 operator()(double x, double y) { @@ -250,7 +336,7 @@ struct TransformerLinLog { // Transforms points for log x and log y space struct TransformerLogLog { - TransformerLogLog(int y_axis) : YAxis(y_axis) {} + TransformerLogLog() : YAxis(GetCurrentYAxis()) {} inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); } inline ImVec2 operator()(double x, double y) { @@ -629,42 +715,34 @@ inline void PlotEx(const char* label_id, Getter getter) } ImDrawList& DrawList = *ImGui::GetWindowDrawList(); - ImPlotState* plot = gp.CurrentPlot; - const int y_axis = plot->CurrentYAxis; - PushPlotClipRect(); // render line if (getter.Count > 1 && WillLineRender()) { - ImU32 col_line = ImGui::GetColorU32(GetLineColor(item)); + const ImU32 col_line = ImGui::GetColorU32(GetLineColor(item)); const float line_weight = item->Highlight ? gp.Style.LineWeight * 2 : gp.Style.LineWeight; - if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderLineStrip(getter, TransformerLogLog(y_axis), DrawList, line_weight, col_line); - else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) - RenderLineStrip(getter, TransformerLogLin(y_axis), DrawList, line_weight, col_line); - else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderLineStrip(getter, TransformerLinLog(y_axis), DrawList, line_weight, col_line); - else - RenderLineStrip(getter, TransformerLinLin(y_axis), DrawList, line_weight, col_line); + switch (GetCurrentScale()) { + case ImPlotScale_LinLin: RenderLineStrip(getter, TransformerLinLin(), DrawList, line_weight, col_line); break; + case ImPlotScale_LogLin: RenderLineStrip(getter, TransformerLogLin(), DrawList, line_weight, col_line); break; + case ImPlotScale_LinLog: RenderLineStrip(getter, TransformerLinLog(), DrawList, line_weight, col_line); break; + case ImPlotScale_LogLog: RenderLineStrip(getter, TransformerLogLog(), DrawList, line_weight, col_line); break; + } } // render markers if (gp.Style.Marker != ImPlotMarker_None) { - const bool rend_mk_line = WillMarkerOutlineRender(); - const bool rend_mk_fill = WillMarkerFillRender(); - const ImU32 col_mk_line = ImGui::GetColorU32(GetMarkerOutlineColor(item)); - const ImU32 col_mk_fill = ImGui::GetColorU32(GetMarkerFillColor(item)); - if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderMarkers(getter, TransformerLogLog(y_axis), DrawList, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill); - else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) - RenderMarkers(getter, TransformerLogLin(y_axis), DrawList, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill); - else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderMarkers(getter, TransformerLinLog(y_axis), DrawList, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill); - else - RenderMarkers(getter, TransformerLinLin(y_axis), DrawList, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill); + const bool rend_line = WillMarkerOutlineRender(); + const bool rend_fill = WillMarkerFillRender(); + const ImU32 col_line = ImGui::GetColorU32(GetMarkerOutlineColor(item)); + const ImU32 col_fill = ImGui::GetColorU32(GetMarkerFillColor(item)); + switch (GetCurrentScale()) { + case ImPlotScale_LinLin: RenderMarkers(getter, TransformerLinLin(), DrawList, rend_line, col_line, rend_fill, col_fill); break; + case ImPlotScale_LogLin: RenderMarkers(getter, TransformerLogLin(), DrawList, rend_line, col_line, rend_fill, col_fill); break; + case ImPlotScale_LinLog: RenderMarkers(getter, TransformerLinLog(), DrawList, rend_line, col_line, rend_fill, col_fill); break; + case ImPlotScale_LogLog: RenderMarkers(getter, TransformerLogLog(), DrawList, rend_line, col_line, rend_fill, col_fill); break; + } } PopPlotClipRect(); } - // float void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) { GetterYs getter(values,count,offset,stride); @@ -681,7 +759,6 @@ void PlotLine(const char* label_id, const ImVec2* data, int count, int offset) { return PlotEx(label_id, getter); } - // double void PlotLine(const char* label_id, const double* values, int count, int offset, int stride) { GetterYs getter(values,count,offset,stride); @@ -793,20 +870,14 @@ inline void PlotShadedEx(const char* label_id, Getter1 getter1, Getter2 getter2) } ImDrawList & DrawList = *ImGui::GetWindowDrawList(); - ImPlotState* plot = gp.CurrentPlot; - const int y_axis = plot->CurrentYAxis; - ImU32 col = ImGui::GetColorU32(GetItemFillColor(item)); - PushPlotClipRect(); - if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLogLog(y_axis), col), DrawList); - else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) - RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLogLin(y_axis), col), DrawList); - else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLinLog(y_axis), col), DrawList); - else - RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLinLin(y_axis), col), DrawList); + switch (GetCurrentScale()) { + case ImPlotScale_LinLin: RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLinLin(), col), DrawList); break; + case ImPlotScale_LogLin: RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLogLin(), col), DrawList); break; + case ImPlotScale_LinLog: RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLinLog(), col), DrawList); break; + case ImPlotScale_LogLog: RenderPrimitives(ShadedRenderer(getter1,getter2,TransformerLogLog(), col), DrawList); break; + } PopPlotClipRect(); } @@ -1277,16 +1348,12 @@ void PlotHeatmapEx(const char* label_id, const T* values, int rows, int cols, T } ImDrawList& DrawList = *ImGui::GetWindowDrawList(); ImGui::PushClipRect(gp.BB_Plot.Min, gp.BB_Plot.Max, true); - ImPlotState* plot = gp.CurrentPlot; - int y_axis = plot->CurrentYAxis; - if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderHeatmap(TransformerLogLog(y_axis), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); - else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) - RenderHeatmap(TransformerLogLin(y_axis), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); - else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderHeatmap(TransformerLinLog(y_axis), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); - else - RenderHeatmap(TransformerLinLin(y_axis), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); + switch (GetCurrentScale()) { + case ImPlotScale_LinLin: RenderHeatmap(TransformerLinLin(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break; + case ImPlotScale_LogLin: RenderHeatmap(TransformerLogLin(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break; + case ImPlotScale_LinLog: RenderHeatmap(TransformerLinLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break; + case ImPlotScale_LogLog: RenderHeatmap(TransformerLogLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break; + } ImGui::PopClipRect(); } @@ -1410,19 +1477,14 @@ void PlotRectsEx(const char* label_id, Getter getter) { } ImDrawList & DrawList = *ImGui::GetWindowDrawList(); - ImPlotState* plot = gp.CurrentPlot; - const int y_axis = plot->CurrentYAxis; ImU32 col = ImGui::GetColorU32(GetItemFillColor(item)); - PushPlotClipRect(); - if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderPrimitives(RectRenderer(getter, TransformerLogLog(y_axis), col), DrawList); - else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) - RenderPrimitives(RectRenderer(getter, TransformerLogLin(y_axis), col), DrawList); - else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) - RenderPrimitives(RectRenderer(getter, TransformerLinLog(y_axis), col), DrawList); - else - RenderPrimitives(RectRenderer(getter, TransformerLinLin(y_axis), col), DrawList); + switch (GetCurrentScale()) { + case ImPlotScale_LinLin: RenderPrimitives(RectRenderer(getter, TransformerLinLin(), col), DrawList); break; + case ImPlotScale_LogLin: RenderPrimitives(RectRenderer(getter, TransformerLogLin(), col), DrawList); break; + case ImPlotScale_LinLog: RenderPrimitives(RectRenderer(getter, TransformerLinLog(), col), DrawList); break; + case ImPlotScale_LogLog: RenderPrimitives(RectRenderer(getter, TransformerLogLog(), col), DrawList); break; + } PopPlotClipRect(); }