Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leading Markers #560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down
36 changes: 19 additions & 17 deletions implot_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
22 changes: 20 additions & 2 deletions implot_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -644,6 +645,16 @@ struct GetterError {
const int Stride;
};

template <typename _Getter>
struct GetterLast {
GetterLast(_Getter getter) : Getter(getter), Count(1) { }
template <typename I> IMPLOT_INLINE ImPlotPoint operator()(I idx) const {
return Getter(Getter.Count - 1);
}
const _Getter Getter;
const int Count;
};

//-----------------------------------------------------------------------------
// [SECTION] Fitters
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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<GetterLast<_Getter>>(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();
}
Expand Down