diff --git a/implot.h b/implot.h index 30543312..bcbcc0a0 100644 --- a/implot.h +++ b/implot.h @@ -108,6 +108,7 @@ typedef int ImPlotCol; // -> enum ImPlotCol_ typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_ typedef int ImPlotScale; // -> enum ImPlotScale_ typedef int ImPlotMarker; // -> enum ImPlotMarker_ +typedef int ImPlotMarkerMode; // -> enum ImPlotMarkerMode_ typedef int ImPlotColormap; // -> enum ImPlotColormap_ typedef int ImPlotLocation; // -> enum ImPlotLocation_ typedef int ImPlotBin; // -> enum ImPlotBin_ @@ -422,6 +423,11 @@ enum ImPlotMarker_ { ImPlotMarker_COUNT }; +enum ImPlotMarkerMode_ { + ImPlotMarkerMode_All = -1, // default: markers on all data points + ImPlotMarkerMode_Head // marker only on the leading data point +}; + // Built-in colormaps enum ImPlotColormap_ { ImPlotColormap_Deep = 0, // a.k.a. seaborn deep (qual=true, n=10) (default) @@ -1119,7 +1125,7 @@ IMPLOT_API void SetNextLineStyle(const ImVec4& col = IMPLOT_AUTO_COL, float weig // Set the fill color for the next item only. IMPLOT_API void SetNextFillStyle(const ImVec4& col = IMPLOT_AUTO_COL, float alpha_mod = IMPLOT_AUTO); // Set the marker style for the next item only. -IMPLOT_API void SetNextMarkerStyle(ImPlotMarker marker = IMPLOT_AUTO, float size = IMPLOT_AUTO, const ImVec4& fill = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO, const ImVec4& outline = IMPLOT_AUTO_COL); +IMPLOT_API void SetNextMarkerStyle(ImPlotMarker marker = IMPLOT_AUTO, float size = IMPLOT_AUTO, const ImVec4& fill = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO, const ImVec4& outline = IMPLOT_AUTO_COL, ImPlotMarkerMode mode = IMPLOT_AUTO); // Set the error bar style for the next item only. IMPLOT_API void SetNextErrorBarStyle(const ImVec4& col = IMPLOT_AUTO_COL, float size = IMPLOT_AUTO, float weight = IMPLOT_AUTO); diff --git a/implot_internal.h b/implot_internal.h index cd05478f..ebbae424 100644 --- a/implot_internal.h +++ b/implot_internal.h @@ -1173,29 +1173,31 @@ struct ImPlotNextPlotData // Temporary data storage for upcoming item struct ImPlotNextItemData { - ImVec4 Colors[5]; // ImPlotCol_Line, ImPlotCol_Fill, ImPlotCol_MarkerOutline, ImPlotCol_MarkerFill, ImPlotCol_ErrorBar - float LineWeight; - ImPlotMarker Marker; - float MarkerSize; - float MarkerWeight; - float FillAlpha; - float ErrorBarSize; - float ErrorBarWeight; - float DigitalBitHeight; - float DigitalBitGap; - bool RenderLine; - bool RenderFill; - bool RenderMarkerLine; - bool RenderMarkerFill; - bool HasHidden; - bool Hidden; - ImPlotCond HiddenCond; + ImVec4 Colors[5]; // ImPlotCol_Line, ImPlotCol_Fill, ImPlotCol_MarkerOutline, ImPlotCol_MarkerFill, ImPlotCol_ErrorBar + float LineWeight; + ImPlotMarker Marker; + float MarkerSize; + float MarkerWeight; + ImPlotMarkerMode MarkerMode; + float FillAlpha; + float ErrorBarSize; + float ErrorBarWeight; + float DigitalBitHeight; + float DigitalBitGap; + bool RenderLine; + bool RenderFill; + bool RenderMarkerLine; + bool RenderMarkerFill; + bool HasHidden; + bool Hidden; + ImPlotCond HiddenCond; ImPlotNextItemData() { Reset(); } void Reset() { for (int i = 0; i < 5; ++i) Colors[i] = IMPLOT_AUTO_COL; LineWeight = MarkerSize = MarkerWeight = FillAlpha = ErrorBarSize = ErrorBarWeight = DigitalBitHeight = DigitalBitGap = IMPLOT_AUTO; Marker = IMPLOT_AUTO; + MarkerMode = IMPLOT_AUTO; HasHidden = Hidden = false; } }; diff --git a/implot_items.cpp b/implot_items.cpp index 1871d15c..6cb6ce58 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -331,13 +331,14 @@ void SetNextFillStyle(const ImVec4& col, float alpha) { gp.NextItemData.FillAlpha = alpha; } -void SetNextMarkerStyle(ImPlotMarker marker, float size, const ImVec4& fill, float weight, const ImVec4& outline) { +void SetNextMarkerStyle(ImPlotMarker marker, float size, const ImVec4& fill, float weight, const ImVec4& outline, ImPlotMarkerMode mode) { ImPlotContext& gp = *GImPlot; gp.NextItemData.Marker = marker; gp.NextItemData.Colors[ImPlotCol_MarkerFill] = fill; gp.NextItemData.MarkerSize = size; gp.NextItemData.Colors[ImPlotCol_MarkerOutline] = outline; gp.NextItemData.MarkerWeight = weight; + gp.NextItemData.MarkerMode = mode; } void SetNextErrorBarStyle(const ImVec4& col, float size, float weight) { @@ -644,6 +645,16 @@ struct GetterError { const int Stride; }; +template +struct GetterLast { + GetterLast(_Getter getter) : Getter(getter), Count(1) { } + template IMPLOT_INLINE ImPlotPoint operator()(I idx) const { + return Getter(Getter.Count - 1); + } + const _Getter Getter; + const int Count; +}; + //----------------------------------------------------------------------------- // [SECTION] Fitters //----------------------------------------------------------------------------- @@ -1607,7 +1618,14 @@ void PlotLineEx(const char* label_id, const _Getter& getter, ImPlotLineFlags fla } const ImU32 col_line = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerOutline]); const ImU32 col_fill = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerFill]); - RenderMarkers<_Getter>(getter, s.Marker, s.MarkerSize, s.RenderMarkerFill, col_fill, s.RenderMarkerLine, col_line, s.MarkerWeight); + if (s.MarkerMode == ImPlotMarkerMode_Head) { + GetterLast<_Getter> gf(getter); + RenderMarkers>(gf, s.Marker, s.MarkerSize, s.RenderMarkerFill, col_fill, s.RenderMarkerLine, col_line, s.MarkerWeight); + } + else { + RenderMarkers<_Getter>(getter, s.Marker, s.MarkerSize, s.RenderMarkerFill, col_fill, s.RenderMarkerLine, col_line, s.MarkerWeight); + + } } EndItem(); }