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

add ImPlotScale, ImPlotNextItemData, BeginItem EndItem, and more

This commit is contained in:
epezent 2020-08-30 11:03:25 -05:00
parent 02e3226e51
commit fce58ee075
4 changed files with 207 additions and 132 deletions

View File

@ -360,6 +360,7 @@ void Reset(ImPlotContext* ctx) {
ctx->DigitalPlotOffset = 0; ctx->DigitalPlotOffset = 0;
// nullify plot // nullify plot
ctx->CurrentPlot = NULL; 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->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->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); 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.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); gp.LogDenX = ImLog10(gp.CurrentPlot->XAxis.Range.Max / gp.CurrentPlot->XAxis.Range.Min);
for (int i = 0; i < IMPLOT_Y_AXES; i++) { 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.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(); 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); 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 // 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; 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 ------------------------------------------------------------ // CONSTRAINTS ------------------------------------------------------------
ConstrainAxis(plot.XAxis); ConstrainAxis(plot.XAxis);

View File

@ -204,8 +204,8 @@ struct ImPlotStyle {
float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels float ErrorBarWeight; // = 1.5, error bar whisker weight in pixels
float DigitalBitHeight; // = 8, digital channels bit height (at y = 1.0f) 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 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 // 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 PlotBorderSize; // = 1, line thickness of border around plot area
float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines float MinorAlpha; // = 0.25 alpha multiplier applied to minor axis grid lines
ImVec2 MajorTickLen; // = 10,10 major tick lengths for X and Y axes 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 // 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. // Provides access to plot style structure for permanant modifications to colors, sizes, etc.
ImPlotStyle& GetStyle(); ImPlotStyle& GetStyle();
@ -429,9 +432,6 @@ void StyleColorsDark(ImPlotStyle* dst = NULL);
// Style colors for ImGui "Light". // Style colors for ImGui "Light".
void StyleColorsLight(ImPlotStyle* dst = NULL); 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! // Temporarily modify a plot color. Don't forget to call PopStyleColor!
void PushStyleColor(ImPlotCol idx, ImU32 col); void PushStyleColor(ImPlotCol idx, ImU32 col);
// Temporarily modify a plot color. Don't forget to call PopStyleColor! // 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. // Undo temporary style modification.
void PopStyleVar(int count = 1); 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. // 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!

View File

@ -143,6 +143,20 @@ struct ImArray {
const int Size = N; 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 // [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() // Holds state information that must persist between calls to BeginPlot()/EndPlot()
struct ImPlotContext { struct ImPlotContext {
// Plot States // Plot States
ImPool<ImPlotState> Plots; ImPool<ImPlotState> Plots;
ImPlotState* CurrentPlot; ImPlotState* CurrentPlot;
ImPlotItem* CurrentItem;
// Legend // Legend
ImVector<int> LegendIndices; ImVector<int> LegendIndices;
@ -385,6 +421,7 @@ struct ImPlotContext {
float YAxisReference[IMPLOT_Y_AXES]; float YAxisReference[IMPLOT_Y_AXES];
// Transformations and Data Extents // Transformations and Data Extents
ImPlotScale Scales[IMPLOT_Y_AXES];
ImRect PixelRange[IMPLOT_Y_AXES]; ImRect PixelRange[IMPLOT_Y_AXES];
double Mx; double Mx;
double My[IMPLOT_Y_AXES]; double My[IMPLOT_Y_AXES];
@ -423,6 +460,7 @@ struct ImPlotContext {
int DigitalPlotItemCnt; int DigitalPlotItemCnt;
int DigitalPlotOffset; int DigitalPlotOffset;
ImPlotNextPlotData NextPlotData; ImPlotNextPlotData NextPlotData;
ImPlotNextItemData NextItemData;
ImPlotInputMap InputMap; ImPlotInputMap InputMap;
ImPlotPoint MousePos[IMPLOT_Y_AXES]; ImPlotPoint MousePos[IMPLOT_Y_AXES];
}; };
@ -461,6 +499,15 @@ void BustPlotCache();
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);
// 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 // Register or get an existing item from the current plot
ImPlotItem* RegisterOrGetItem(const char* label_id); ImPlotItem* RegisterOrGetItem(const char* label_id);
@ -470,9 +517,20 @@ ImPlotItem* GetItem(int i);
ImPlotItem* GetItem(const char* label_id); ImPlotItem* GetItem(const char* label_id);
// Gets a plot item from a specific plot // Gets a plot item from a specific plot
ImPlotItem* GetItem(const char* plot_title, const char* item_label_id); 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. // Busts the cache for every item for every plot in the current context.
void BustItemCache(); 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 // Returns the number of entries in the current legend
int GetLegendCount(); int GetLegendCount();
// Gets the ith entry string for the current legend // 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 ImVec4 GetStyleColorVec4(ImPlotCol idx) {return IsColorAuto(idx) ? GetAutoColor(idx) : GImPlot->Style.Colors[idx]; }
inline ImU32 GetStyleColorU32(ImPlotCol idx) { return ImGui::ColorConvertFloat4ToU32(GetStyleColorVec4(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) // Returns true if lines will render (e.g. basic lines, bar outlines)
inline bool WillLineRender() { inline bool WillLineRender() {
return GImPlot->Style.Colors[ImPlotCol_Line].w != 0 && GImPlot->Style.LineWeight > 0; return GImPlot->Style.Colors[ImPlotCol_Line].w != 0 && GImPlot->Style.LineWeight > 0;

View File

@ -44,6 +44,92 @@
namespace ImPlot { 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 // GETTERS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -205,7 +291,7 @@ struct GetterError {
// Transforms points for linear x and linear y space // Transforms points for linear x and linear y space
struct TransformerLinLin { 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()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
inline ImVec2 operator()(double x, double y) { inline ImVec2 operator()(double x, double y) {
@ -219,7 +305,7 @@ struct TransformerLinLin {
// Transforms points for log x and linear y space // Transforms points for log x and linear y space
struct TransformerLogLin { 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()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
inline ImVec2 operator()(double x, double y) { inline ImVec2 operator()(double x, double y) {
@ -235,7 +321,7 @@ struct TransformerLogLin {
// Transforms points for linear x and log y space // Transforms points for linear x and log y space
struct TransformerLinLog { 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()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
inline ImVec2 operator()(double x, double y) { inline ImVec2 operator()(double x, double y) {
@ -250,7 +336,7 @@ struct TransformerLinLog {
// Transforms points for log x and log y space // Transforms points for log x and log y space
struct TransformerLogLog { 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()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
inline ImVec2 operator()(double x, double 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(); ImDrawList& DrawList = *ImGui::GetWindowDrawList();
ImPlotState* plot = gp.CurrentPlot;
const int y_axis = plot->CurrentYAxis;
PushPlotClipRect(); PushPlotClipRect();
// render line // render line
if (getter.Count > 1 && WillLineRender()) { 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; 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)) switch (GetCurrentScale()) {
RenderLineStrip(getter, TransformerLogLog(y_axis), DrawList, line_weight, col_line); case ImPlotScale_LinLin: RenderLineStrip(getter, TransformerLinLin(), DrawList, line_weight, col_line); break;
else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLin: RenderLineStrip(getter, TransformerLogLin(), DrawList, line_weight, col_line); break;
RenderLineStrip(getter, TransformerLogLin(y_axis), DrawList, line_weight, col_line); case ImPlotScale_LinLog: RenderLineStrip(getter, TransformerLinLog(), DrawList, line_weight, col_line); break;
else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLog: RenderLineStrip(getter, TransformerLogLog(), DrawList, line_weight, col_line); break;
RenderLineStrip(getter, TransformerLinLog(y_axis), DrawList, line_weight, col_line); }
else
RenderLineStrip(getter, TransformerLinLin(y_axis), DrawList, line_weight, col_line);
} }
// render markers // render markers
if (gp.Style.Marker != ImPlotMarker_None) { if (gp.Style.Marker != ImPlotMarker_None) {
const bool rend_mk_line = WillMarkerOutlineRender(); const bool rend_line = WillMarkerOutlineRender();
const bool rend_mk_fill = WillMarkerFillRender(); const bool rend_fill = WillMarkerFillRender();
const ImU32 col_mk_line = ImGui::GetColorU32(GetMarkerOutlineColor(item)); const ImU32 col_line = ImGui::GetColorU32(GetMarkerOutlineColor(item));
const ImU32 col_mk_fill = ImGui::GetColorU32(GetMarkerFillColor(item)); const ImU32 col_fill = ImGui::GetColorU32(GetMarkerFillColor(item));
if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) switch (GetCurrentScale()) {
RenderMarkers(getter, TransformerLogLog(y_axis), DrawList, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill); case ImPlotScale_LinLin: RenderMarkers(getter, TransformerLinLin(), DrawList, rend_line, col_line, rend_fill, col_fill); break;
else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLin: RenderMarkers(getter, TransformerLogLin(), DrawList, rend_line, col_line, rend_fill, col_fill); break;
RenderMarkers(getter, TransformerLogLin(y_axis), DrawList, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill); case ImPlotScale_LinLog: RenderMarkers(getter, TransformerLinLog(), DrawList, rend_line, col_line, rend_fill, col_fill); break;
else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLog: RenderMarkers(getter, TransformerLogLog(), DrawList, rend_line, col_line, rend_fill, col_fill); break;
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);
} }
PopPlotClipRect(); PopPlotClipRect();
} }
// float // float
void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) { void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) {
GetterYs<float> getter(values,count,offset,stride); GetterYs<float> 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); return PlotEx(label_id, getter);
} }
// double // double
void PlotLine(const char* label_id, const double* values, int count, int offset, int stride) { void PlotLine(const char* label_id, const double* values, int count, int offset, int stride) {
GetterYs<double> getter(values,count,offset,stride); GetterYs<double> getter(values,count,offset,stride);
@ -793,20 +870,14 @@ inline void PlotShadedEx(const char* label_id, Getter1 getter1, Getter2 getter2)
} }
ImDrawList & DrawList = *ImGui::GetWindowDrawList(); ImDrawList & DrawList = *ImGui::GetWindowDrawList();
ImPlotState* plot = gp.CurrentPlot;
const int y_axis = plot->CurrentYAxis;
ImU32 col = ImGui::GetColorU32(GetItemFillColor(item)); ImU32 col = ImGui::GetColorU32(GetItemFillColor(item));
PushPlotClipRect(); PushPlotClipRect();
if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) switch (GetCurrentScale()) {
RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLog>(getter1,getter2,TransformerLogLog(y_axis), col), DrawList); case ImPlotScale_LinLin: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLinLin>(getter1,getter2,TransformerLinLin(), col), DrawList); break;
else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLin: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLin>(getter1,getter2,TransformerLogLin(), col), DrawList); break;
RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLin>(getter1,getter2,TransformerLogLin(y_axis), col), DrawList); case ImPlotScale_LinLog: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLinLog>(getter1,getter2,TransformerLinLog(), col), DrawList); break;
else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLog: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLog>(getter1,getter2,TransformerLogLog(), col), DrawList); break;
RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLinLog>(getter1,getter2,TransformerLinLog(y_axis), col), DrawList); }
else
RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLinLin>(getter1,getter2,TransformerLinLin(y_axis), col), DrawList);
PopPlotClipRect(); PopPlotClipRect();
} }
@ -1277,16 +1348,12 @@ void PlotHeatmapEx(const char* label_id, const T* values, int rows, int cols, T
} }
ImDrawList& DrawList = *ImGui::GetWindowDrawList(); ImDrawList& DrawList = *ImGui::GetWindowDrawList();
ImGui::PushClipRect(gp.BB_Plot.Min, gp.BB_Plot.Max, true); ImGui::PushClipRect(gp.BB_Plot.Min, gp.BB_Plot.Max, true);
ImPlotState* plot = gp.CurrentPlot; switch (GetCurrentScale()) {
int y_axis = plot->CurrentYAxis; case ImPlotScale_LinLin: RenderHeatmap(TransformerLinLin(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLin: RenderHeatmap(TransformerLogLin(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
RenderHeatmap(TransformerLogLog(y_axis), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); case ImPlotScale_LinLog: RenderHeatmap(TransformerLinLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLog: RenderHeatmap(TransformerLogLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
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);
ImGui::PopClipRect(); ImGui::PopClipRect();
} }
@ -1410,19 +1477,14 @@ void PlotRectsEx(const char* label_id, Getter getter) {
} }
ImDrawList & DrawList = *ImGui::GetWindowDrawList(); ImDrawList & DrawList = *ImGui::GetWindowDrawList();
ImPlotState* plot = gp.CurrentPlot;
const int y_axis = plot->CurrentYAxis;
ImU32 col = ImGui::GetColorU32(GetItemFillColor(item)); ImU32 col = ImGui::GetColorU32(GetItemFillColor(item));
PushPlotClipRect(); PushPlotClipRect();
if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) switch (GetCurrentScale()) {
RenderPrimitives(RectRenderer<Getter,TransformerLogLog>(getter, TransformerLogLog(y_axis), col), DrawList); case ImPlotScale_LinLin: RenderPrimitives(RectRenderer<Getter,TransformerLinLin>(getter, TransformerLinLin(), col), DrawList); break;
else if (ImHasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLin: RenderPrimitives(RectRenderer<Getter,TransformerLogLin>(getter, TransformerLogLin(), col), DrawList); break;
RenderPrimitives(RectRenderer<Getter,TransformerLogLin>(getter, TransformerLogLin(y_axis), col), DrawList); case ImPlotScale_LinLog: RenderPrimitives(RectRenderer<Getter,TransformerLinLog>(getter, TransformerLinLog(), col), DrawList); break;
else if (ImHasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) case ImPlotScale_LogLog: RenderPrimitives(RectRenderer<Getter,TransformerLogLog>(getter, TransformerLogLog(), col), DrawList); break;
RenderPrimitives(RectRenderer<Getter,TransformerLinLog>(getter, TransformerLinLog(y_axis), col), DrawList); }
else
RenderPrimitives(RectRenderer<Getter,TransformerLinLin>(getter, TransformerLinLin(y_axis), col), DrawList);
PopPlotClipRect(); PopPlotClipRect();
} }