mirror of
https://github.com/gwm17/implot.git
synced 2024-11-23 02:38:53 -05:00
finish up item styling changes
This commit is contained in:
parent
3e21d841a2
commit
71bf19b4c4
18
implot.cpp
18
implot.cpp
|
@ -1484,15 +1484,17 @@ void EndPlot() {
|
||||||
col_hl_txt = ImGui::GetColorU32(col_txt);
|
col_hl_txt = ImGui::GetColorU32(col_txt);
|
||||||
}
|
}
|
||||||
ImU32 iconColor;
|
ImU32 iconColor;
|
||||||
|
ImVec4 item_color = item->Color;
|
||||||
|
item_color.w = 1;
|
||||||
if (hov_legend && icon_bb.Contains(IO.MousePos)) {
|
if (hov_legend && icon_bb.Contains(IO.MousePos)) {
|
||||||
ImVec4 colAlpha = item->Color;
|
ImVec4 colAlpha = item_color;
|
||||||
colAlpha.w = 0.5f;
|
colAlpha.w = 0.5f;
|
||||||
iconColor = item->Show ? ImGui::GetColorU32(colAlpha)
|
iconColor = item->Show ? ImGui::GetColorU32(colAlpha)
|
||||||
: ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f);
|
: ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f);
|
||||||
if (IO.MouseClicked[0])
|
if (IO.MouseClicked[0])
|
||||||
item->Show = !item->Show;
|
item->Show = !item->Show;
|
||||||
} else {
|
} else {
|
||||||
iconColor = item->Show ? ImGui::GetColorU32(item->Color) : col_txt_dis;
|
iconColor = item->Show ? ImGui::GetColorU32(item_color) : col_txt_dis;
|
||||||
}
|
}
|
||||||
DrawList.AddRectFilled(icon_bb.Min, icon_bb.Max, iconColor, 1);
|
DrawList.AddRectFilled(icon_bb.Min, icon_bb.Max, iconColor, 1);
|
||||||
const char* label = GetLegendLabel(i);
|
const char* label = GetLegendLabel(i);
|
||||||
|
@ -2192,7 +2194,7 @@ void ShowColormapScale(double scale_min, double scale_max, float height) {
|
||||||
ImGui::ItemSize(bb_frame);
|
ImGui::ItemSize(bb_frame);
|
||||||
if (!ImGui::ItemAdd(bb_frame, 0, &bb_frame))
|
if (!ImGui::ItemAdd(bb_frame, 0, &bb_frame))
|
||||||
return;
|
return;
|
||||||
ImGui::RenderFrame(bb_frame.Min, bb_frame.Max, ImGui::GetColorU32(ImGuiCol_FrameBg));
|
ImGui::RenderFrame(bb_frame.Min, bb_frame.Max, GetStyleColorU32(ImPlotCol_FrameBg));
|
||||||
ImRect bb_grad(bb_frame.Min + gp.Style.PlotPadding, bb_frame.Min + ImVec2(bar_w + gp.Style.PlotPadding.x, height - gp.Style.PlotPadding.y));
|
ImRect bb_grad(bb_frame.Min + gp.Style.PlotPadding, bb_frame.Min + ImVec2(bar_w + gp.Style.PlotPadding.x, height - gp.Style.PlotPadding.y));
|
||||||
|
|
||||||
int num_cols = GetColormapSize();
|
int num_cols = GetColormapSize();
|
||||||
|
@ -2203,18 +2205,20 @@ void ShowColormapScale(double scale_min, double scale_max, float height) {
|
||||||
ImU32 col2 = ImGui::GetColorU32(GetColormapColor(num_cols - 1 - (i+1)));
|
ImU32 col2 = ImGui::GetColorU32(GetColormapColor(num_cols - 1 - (i+1)));
|
||||||
DrawList.AddRectFilledMultiColor(rect.Min, rect.Max, col1, col1, col2, col2);
|
DrawList.AddRectFilledMultiColor(rect.Min, rect.Max, col1, col1, col2, col2);
|
||||||
}
|
}
|
||||||
ImU32 col_border = gp.Style.Colors[ImPlotCol_PlotBorder].w == -1 ? ImGui::GetColorU32(ImGuiCol_Text, 0.5f) : ImGui::GetColorU32(gp.Style.Colors[ImPlotCol_PlotBorder]);
|
ImVec4 col_tik4 = ImGui::GetStyleColorVec4(ImGuiCol_Text);
|
||||||
|
col_tik4.w *= 0.25f;
|
||||||
|
const ImU32 col_tick = ImGui::GetColorU32(col_tik4);
|
||||||
|
|
||||||
ImGui::PushClipRect(bb_frame.Min, bb_frame.Max, true);
|
ImGui::PushClipRect(bb_frame.Min, bb_frame.Max, true);
|
||||||
for (int i = 0; i < ticks.Size; ++i) {
|
for (int i = 0; i < ticks.Size; ++i) {
|
||||||
float ypos = ImRemap((float)ticks.Ticks[i].PlotPos, (float)range.Max, (float)range.Min, bb_grad.Min.y, bb_grad.Max.y);
|
float ypos = ImRemap((float)ticks.Ticks[i].PlotPos, (float)range.Max, (float)range.Min, bb_grad.Min.y, bb_grad.Max.y);
|
||||||
if (ypos < bb_grad.Max.y - 2 && ypos > bb_grad.Min.y + 2)
|
if (ypos < bb_grad.Max.y - 2 && ypos > bb_grad.Min.y + 2)
|
||||||
DrawList.AddLine(ImVec2(bb_grad.Max.x-1, ypos), ImVec2(bb_grad.Max.x - (ticks.Ticks[i].Major ? 10.0f : 5.0f), ypos), col_border, 1.0f);
|
DrawList.AddLine(ImVec2(bb_grad.Max.x-1, ypos), ImVec2(bb_grad.Max.x - (ticks.Ticks[i].Major ? 10.0f : 5.0f), ypos), col_tick, 1.0f);
|
||||||
DrawList.AddText(ImVec2(bb_grad.Max.x-1, ypos) + ImVec2(txt_off, -ticks.Ticks[i].LabelSize.y * 0.5f), ImGui::GetColorU32(ImGuiCol_Text), ticks.GetLabel(i));
|
DrawList.AddText(ImVec2(bb_grad.Max.x-1, ypos) + ImVec2(txt_off, -ticks.Ticks[i].LabelSize.y * 0.5f), GetStyleColorU32(ImPlotCol_TitleText), ticks.GetLabel(i));
|
||||||
}
|
}
|
||||||
ImGui::PopClipRect();
|
ImGui::PopClipRect();
|
||||||
|
|
||||||
DrawList.AddRect(bb_grad.Min, bb_grad.Max, col_border);
|
DrawList.AddRect(bb_grad.Min, bb_grad.Max, GetStyleColorU32(ImPlotCol_PlotBorder));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
75
implot.h
75
implot.h
|
@ -33,7 +33,7 @@
|
||||||
#define IMPLOT_VERSION "0.5 WIP"
|
#define IMPLOT_VERSION "0.5 WIP"
|
||||||
// Indicates variable should deduced automatically.
|
// Indicates variable should deduced automatically.
|
||||||
#define IMPLOT_AUTO -1
|
#define IMPLOT_AUTO -1
|
||||||
// Special color used to indicate that a style color should be deduced automatically from ImGui style or ImPlot colormaps.
|
// Special color used to indicate that a color should be deduced automatically.
|
||||||
#define IMPLOT_AUTO_COL ImVec4(0,0,0,-1)
|
#define IMPLOT_AUTO_COL ImVec4(0,0,0,-1)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -82,13 +82,13 @@ enum ImPlotAxisFlags_ {
|
||||||
|
|
||||||
// Plot styling colors.
|
// Plot styling colors.
|
||||||
enum ImPlotCol_ {
|
enum ImPlotCol_ {
|
||||||
// item related colors
|
// item styling colors
|
||||||
ImPlotCol_Line, // plot line/outline color (defaults to next unused color in current colormap)
|
ImPlotCol_Line, // plot line/outline color (defaults to next unused color in current colormap)
|
||||||
ImPlotCol_Fill, // plot fill color for bars (defaults to the current line color)
|
ImPlotCol_Fill, // plot fill color for bars (defaults to the current line color)
|
||||||
ImPlotCol_MarkerOutline, // marker outline color (defaults to the current line color)
|
ImPlotCol_MarkerOutline, // marker outline color (defaults to the current line color)
|
||||||
ImPlotCol_MarkerFill, // marker fill color (defaults to the current line color)
|
ImPlotCol_MarkerFill, // marker fill color (defaults to the current line color)
|
||||||
ImPlotCol_ErrorBar, // error bar color (defaults to ImGuiCol_Text)
|
ImPlotCol_ErrorBar, // error bar color (defaults to ImGuiCol_Text)
|
||||||
// plot related colors
|
// plot styling colors
|
||||||
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_Border)
|
ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Border)
|
||||||
|
@ -142,7 +142,7 @@ enum ImPlotStyleVar_ {
|
||||||
|
|
||||||
// Marker specifications.
|
// Marker specifications.
|
||||||
enum ImPlotMarker_ {
|
enum ImPlotMarker_ {
|
||||||
ImPlotMarker_None, // no marker
|
ImPlotMarker_None = -1, // no marker
|
||||||
ImPlotMarker_Circle, // a circle marker
|
ImPlotMarker_Circle, // a circle marker
|
||||||
ImPlotMarker_Square, // a square maker
|
ImPlotMarker_Square, // a square maker
|
||||||
ImPlotMarker_Diamond, // a diamond marker
|
ImPlotMarker_Diamond, // a diamond marker
|
||||||
|
@ -275,8 +275,8 @@ void SetCurrentContext(ImPlotContext* ctx);
|
||||||
// Starts a 2D plotting context. If this function returns true, EndPlot() must
|
// Starts a 2D plotting context. If this function returns true, EndPlot() must
|
||||||
// be called, e.g. "if (BeginPlot(...)) { ... EndPlot(); }". #title_id must
|
// be called, e.g. "if (BeginPlot(...)) { ... EndPlot(); }". #title_id must
|
||||||
// be unique. If you need to avoid ID collisions or don't want to display a
|
// be unique. If you need to avoid ID collisions or don't want to display a
|
||||||
// title in the plot, use double hashes (e.g. "MyPlot##Hidden"). If #x_label
|
// title in the plot, use double hashes (e.g. "MyPlot##Hidden" or "##NoTitle").
|
||||||
// and/or #y_label are provided, axes labels will be displayed.
|
// If #x_label and/or #y_label are provided, axes labels will be displayed.
|
||||||
bool BeginPlot(const char* title_id,
|
bool BeginPlot(const char* title_id,
|
||||||
const char* x_label = NULL,
|
const char* x_label = NULL,
|
||||||
const char* y_label = NULL,
|
const char* y_label = NULL,
|
||||||
|
@ -401,6 +401,9 @@ ImVec2 PlotToPixels(double x, double y, int y_axis = IMPLOT_AUTO);
|
||||||
// Plot Queries
|
// Plot Queries
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Use these functions to retrieve information about the current plot. They
|
||||||
|
// MUST be called between BeginPlot and EndPlot!
|
||||||
|
|
||||||
// Get the current Plot position (top-left) in pixels.
|
// Get the current Plot position (top-left) in pixels.
|
||||||
ImVec2 GetPlotPos();
|
ImVec2 GetPlotPos();
|
||||||
// Get the curent Plot size in pixels.
|
// Get the curent Plot size in pixels.
|
||||||
|
@ -423,7 +426,7 @@ ImPlotLimits GetPlotQuery(int y_axis = IMPLOT_AUTO);
|
||||||
bool IsLegendEntryHovered(const char* label_id);
|
bool IsLegendEntryHovered(const char* label_id);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Plot and Item Styling and Colormaps
|
// Plot and Item Styling
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -438,19 +441,14 @@ 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);
|
||||||
|
|
||||||
// Set the line color and weight for the next item only.
|
// Use PushStyleX to temporarily modify your ImPlotStyle. The modification
|
||||||
void SetNextLineStyle(const ImVec4& col, float weight = IMPLOT_AUTO);
|
// will last until the matching call to PopStyleX. You MUST call a pop for
|
||||||
// Set the fill color for the next item only.
|
// every push, otherwise you will leak memory! This behaves just like ImGui.
|
||||||
void SetNextFillStyle(const ImVec4& col, float alpha_mod = IMPLOT_AUTO);
|
|
||||||
// Set the marker style for the next item only.
|
|
||||||
void SetNextMarkerStyle(ImPlotMarker marker, const ImVec4& fill = IMPLOT_AUTO_COL, float size = IMPLOT_AUTO, const ImVec4& outline = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO);
|
|
||||||
// Set the error bar style for the next item only.
|
|
||||||
void SetNextErrorBarStyle(const ImVec4& col, float size = IMPLOT_AUTO, float weight = IMPLOT_AUTO);
|
|
||||||
|
|
||||||
// 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);
|
||||||
void PushStyleColor(ImPlotCol idx, const ImVec4& col);
|
void PushStyleColor(ImPlotCol idx, const ImVec4& col);
|
||||||
// Undo temporary color modification.
|
// Undo temporary color modification. Undo multiple pushes at once by increasing count.
|
||||||
void PopStyleColor(int count = 1);
|
void PopStyleColor(int count = 1);
|
||||||
|
|
||||||
// Temporarily modify a style variable of float type. Don't forget to call PopStyleVar!
|
// Temporarily modify a style variable of float type. Don't forget to call PopStyleVar!
|
||||||
|
@ -459,9 +457,39 @@ void PushStyleVar(ImPlotStyleVar idx, float val);
|
||||||
void PushStyleVar(ImPlotStyleVar idx, int val);
|
void PushStyleVar(ImPlotStyleVar idx, int val);
|
||||||
// Temporarily modify a style variable of ImVec2 type. Don't forget to call PopStyleVar!
|
// Temporarily modify a style variable of ImVec2 type. Don't forget to call PopStyleVar!
|
||||||
void PushStyleVar(ImPlotStyleVar idx, const ImVec2& val);
|
void PushStyleVar(ImPlotStyleVar idx, const ImVec2& val);
|
||||||
// Undo temporary style modification.
|
// Undo temporary style modification. Undo multiple pushes at once by increasing count.
|
||||||
void PopStyleVar(int count = 1);
|
void PopStyleVar(int count = 1);
|
||||||
|
|
||||||
|
// The following can be used to modify the style of the next plot item ONLY. They do
|
||||||
|
// NOT require calls to PopStyleX. Leave style attributes you don't want modified to
|
||||||
|
// IMPLOT_AUTO or IMPLOT_AUTO_COL. Automatic styles will be deduced from the current
|
||||||
|
// values in the your ImPlotStyle or from Colormap data.
|
||||||
|
|
||||||
|
// Set the line color and weight for the next item only.
|
||||||
|
void SetNextLineStyle(const ImVec4& col = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO);
|
||||||
|
// Set the fill color for the next item only.
|
||||||
|
void SetNextFillStyle(const ImVec4& col = IMPLOT_AUTO_COL, float alpha_mod = IMPLOT_AUTO);
|
||||||
|
// Set the marker style for the next item only.
|
||||||
|
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);
|
||||||
|
// Set the error bar style for the next item only.
|
||||||
|
void SetNextErrorBarStyle(const ImVec4& col = IMPLOT_AUTO_COL, float size = IMPLOT_AUTO, float weight = IMPLOT_AUTO);
|
||||||
|
|
||||||
|
// Returns the null terminated string name for an ImPlotCol.
|
||||||
|
const char* GetStyleColorName(ImPlotCol color);
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Colormaps
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Item styling is based on Colormaps when the relevant ImPlotCol is set to
|
||||||
|
// IMPLOT_AUTO_COL (default). Several built in colormaps are available and can be
|
||||||
|
// toggled in the demo. You can push/pop or set your own colormaps as well.
|
||||||
|
|
||||||
|
// The Colormap data will be ignored and a custom color will be used if you have either:
|
||||||
|
// 1) Modified an item style color in your ImPlotStyle to anything but IMPLOT_AUTO_COL.
|
||||||
|
// 2) Pushed an item style color using PushStyleColor().
|
||||||
|
// 3) Set the next item style with a SetNextXStyle function.
|
||||||
|
|
||||||
// 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!
|
||||||
|
@ -472,23 +500,18 @@ void PopColormap(int count = 1);
|
||||||
void SetColormap(const ImVec4* colormap, int size);
|
void SetColormap(const ImVec4* colormap, int size);
|
||||||
// Permanently switch to one of the built-in colormaps. If samples is greater than 1, the map will be linearly resampled. Don't call this each frame.
|
// Permanently switch to one of the built-in colormaps. If samples is greater than 1, the map will be linearly resampled. Don't call this each frame.
|
||||||
void SetColormap(ImPlotColormap colormap, int samples = 0);
|
void SetColormap(ImPlotColormap colormap, int samples = 0);
|
||||||
|
|
||||||
// Returns the size of the current colormap.
|
// Returns the size of the current colormap.
|
||||||
int GetColormapSize();
|
int GetColormapSize();
|
||||||
// Returns a color from the Color map given an index >= 0 (modulo will be performed)
|
// Returns a color from the Color map given an index >= 0 (modulo will be performed).
|
||||||
ImVec4 GetColormapColor(int index);
|
ImVec4 GetColormapColor(int index);
|
||||||
// Linearly interpolates a color from the current colormap given t between 0 and 1.
|
// Linearly interpolates a color from the current colormap given t between 0 and 1.
|
||||||
ImVec4 LerpColormap(float t);
|
ImVec4 LerpColormap(float t);
|
||||||
// Returns the next unused colormap color and advances the colormap. Can be used to skip colors if desired.
|
// Returns the next unused colormap color and advances the colormap. Can be used to skip colors if desired.
|
||||||
ImVec4 NextColormapColor();
|
ImVec4 NextColormapColor();
|
||||||
|
// Renders a vertical color scale using the current color map. Call this outside of Begin/EndPlot.
|
||||||
// Retusn the null terminated string name for a ImPlotCol
|
|
||||||
const char* GetStyleColorName(ImPlotCol color);
|
|
||||||
// Returns a null terminated string name for a built-in colormap
|
|
||||||
const char* GetColormapName(ImPlotColormap colormap);
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
// Returns a null terminated string name for a built-in colormap.
|
||||||
|
const char* GetColormapName(ImPlotColormap colormap);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
|
|
167
implot_demo.cpp
167
implot_demo.cpp
|
@ -236,9 +236,7 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
xs2[i] = i * 0.1f;
|
xs2[i] = i * 0.1f;
|
||||||
ys2[i] = xs2[i] * xs2[i];
|
ys2[i] = xs2[i] * xs2[i];
|
||||||
}
|
}
|
||||||
static float weight = ImPlot::GetStyle().LineWeight;
|
|
||||||
ImGui::BulletText("Anti-aliasing can be enabled from the plot's context menu (see Help).");
|
ImGui::BulletText("Anti-aliasing can be enabled from the plot's context menu (see Help).");
|
||||||
|
|
||||||
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
|
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
|
||||||
ImPlot::PlotLine("sin(x)", xs1, ys1, 1001);
|
ImPlot::PlotLine("sin(x)", xs1, ys1, 1001);
|
||||||
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle);
|
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle);
|
||||||
|
@ -322,11 +320,10 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
|
|
||||||
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL)) {
|
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL)) {
|
||||||
ImPlot::PlotScatter("Data 1", xs1, ys1, 100);
|
ImPlot::PlotScatter("Data 1", xs1, ys1, 100);
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 6);
|
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
|
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
|
ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
|
||||||
|
ImPlot::SetNextMarkerStyle(ImPlotMarker_Square, 6, ImVec4(0,1,0,0.5f), IMPLOT_AUTO, ImVec4(0,1,0,1));
|
||||||
ImPlot::PlotScatter("Data 2", xs2, ys2, 50);
|
ImPlot::PlotScatter("Data 2", xs2, ys2, 50);
|
||||||
ImPlot::PopStyleVar(3);
|
ImPlot::PopStyleVar();
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,19 +345,19 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
ImPlot::SetNextPlotLimits(-0.5, 9.5, 0, 110, ImGuiCond_Always);
|
ImPlot::SetNextPlotLimits(-0.5, 9.5, 0, 110, ImGuiCond_Always);
|
||||||
ImPlot::SetNextPlotTicksX(positions, 10, labels);
|
ImPlot::SetNextPlotTicksX(positions, 10, labels);
|
||||||
}
|
}
|
||||||
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score",
|
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score" : "Student", horz ? "Student" : "Score",
|
||||||
ImVec2(-1,0), ImPlotFlags_Default, ImPlotAxisFlags_Default,
|
ImVec2(-1,0), ImPlotFlags_Default, ImPlotAxisFlags_Default,
|
||||||
horz ? ImPlotAxisFlags_Default | ImPlotAxisFlags_Invert : ImPlotAxisFlags_Default))
|
horz ? ImPlotAxisFlags_Default | ImPlotAxisFlags_Invert : ImPlotAxisFlags_Default))
|
||||||
{
|
{
|
||||||
if (horz) {
|
if (horz) {
|
||||||
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
||||||
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
|
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
|
||||||
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2f, 0.2f);
|
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2f, 0.2f);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
||||||
ImPlot::PlotBars("Final Exam", final, 10, 0.2f, 0);
|
ImPlot::PlotBars("Final Exam", final, 10, 0.2f, 0);
|
||||||
ImPlot::PlotBars("Course Grade", grade, 10, 0.2f, 0.2f);
|
ImPlot::PlotBars("Course Grade", grade, 10, 0.2f, 0.2f);
|
||||||
}
|
}
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
|
@ -375,29 +372,25 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
static t_float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
|
static t_float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
|
||||||
static t_float err3[5] = {0.09f, 0.14f, 0.09f, 0.12f, 0.16f};
|
static t_float err3[5] = {0.09f, 0.14f, 0.09f, 0.12f, 0.16f};
|
||||||
static t_float err4[5] = {0.02f, 0.08f, 0.15f, 0.05f, 0.2f};
|
static t_float err4[5] = {0.02f, 0.08f, 0.15f, 0.05f, 0.2f};
|
||||||
static float size = ImPlot::GetStyle().ErrorBarSize;
|
|
||||||
static float weight = ImPlot::GetStyle().ErrorBarWeight;
|
|
||||||
ImGui::DragFloat("Error Bar Size", &size, 0.1f, 0, 10,"%.2f px");
|
|
||||||
ImGui::DragFloat("Error Bar Weight",&weight,0.01f,1,3,"%.2f px");
|
|
||||||
|
|
||||||
ImPlot::SetNextPlotLimits(0, 6, 0, 10);
|
ImPlot::SetNextPlotLimits(0, 6, 0, 10);
|
||||||
if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL)) {
|
if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL)) {
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_ErrorBarSize, size);
|
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_ErrorBarWeight, weight);
|
|
||||||
ImPlot::PlotBars("Bar", xs, bar, 5, 0.5f);
|
ImPlot::PlotBars("Bar", xs, bar, 5, 0.5f);
|
||||||
// error bars can be grouped with the associated item by using the same label ID
|
|
||||||
ImPlot::PlotErrorBars("Bar", xs, bar, err1, 5);
|
ImPlot::PlotErrorBars("Bar", xs, bar, err1, 5);
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
|
||||||
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(1));
|
ImPlot::SetNextErrorBarStyle(ImPlot::GetColormapColor(1), 0);
|
||||||
ImPlot::PlotErrorBars("Line", xs, lin1, err1, err2, 5);
|
ImPlot::PlotErrorBars("Line", xs, lin1, err1, err2, 5);
|
||||||
|
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle);
|
||||||
ImPlot::PlotLine("Line", xs, lin1, 5);
|
ImPlot::PlotLine("Line", xs, lin1, 5);
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
|
|
||||||
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(2));
|
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(2));
|
||||||
ImPlot::PlotErrorBars("Scatter", xs, lin2, err2, 5);
|
ImPlot::PlotErrorBars("Scatter", xs, lin2, err2, 5);
|
||||||
ImPlot::PlotErrorBarsH("Scatter", xs, lin2, err3, err4, 5);
|
ImPlot::PlotErrorBarsH("Scatter", xs, lin2, err3, err4, 5);
|
||||||
|
ImPlot::PopStyleColor();
|
||||||
ImPlot::PlotScatter("Scatter", xs, lin2, 5);
|
ImPlot::PlotScatter("Scatter", xs, lin2, 5);
|
||||||
ImPlot::PopStyleVar(4);
|
|
||||||
ImPlot::PopStyleColor(2);
|
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,7 +455,7 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
|
|
||||||
ImPlot::PushColormap(map);
|
ImPlot::PushColormap(map);
|
||||||
SetNextPlotTicksX(0 + 1.0/14.0, 1 - 1.0/14.0, 7, xlabels);
|
SetNextPlotTicksX(0 + 1.0/14.0, 1 - 1.0/14.0, 7, xlabels);
|
||||||
SetNextPlotTicksY(1- 1.0/14.0, 0 + 1.0/14.0, 7, ylabels);
|
SetNextPlotTicksY(1 - 1.0/14.0, 0 + 1.0/14.0, 7, ylabels);
|
||||||
if (ImPlot::BeginPlot("##Heatmap1",NULL,NULL,ImVec2(225,225),0,axes_flags,axes_flags)) {
|
if (ImPlot::BeginPlot("##Heatmap1",NULL,NULL,ImVec2(225,225),0,axes_flags,axes_flags)) {
|
||||||
ImPlot::PlotHeatmap("heat",values1[0],7,7,scale_min,scale_max);
|
ImPlot::PlotHeatmap("heat",values1[0],7,7,scale_min,scale_max);
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
|
@ -514,7 +507,7 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
// 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*) with stride of 2 * sizeof
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -531,37 +524,30 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
t_float xs[2] = {1,4};
|
t_float xs[2] = {1,4};
|
||||||
t_float ys[2] = {10,11};
|
t_float ys[2] = {10,11};
|
||||||
|
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, mk_size);
|
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, mk_weight);
|
|
||||||
// filled markers
|
// filled markers
|
||||||
for (int m = 1; m < ImPlotMarker_COUNT; ++m) {
|
for (int m = 1; m < ImPlotMarker_COUNT; ++m) {
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, m);
|
|
||||||
ImGui::PushID(m);
|
ImGui::PushID(m);
|
||||||
|
ImPlot::SetNextMarkerStyle(m, mk_size, IMPLOT_AUTO_COL, mk_weight);
|
||||||
ImPlot::PlotLine("##Filled", xs, ys, 2);
|
ImPlot::PlotLine("##Filled", xs, ys, 2);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
ImPlot::PopStyleVar();
|
|
||||||
ys[0]--; ys[1]--;
|
ys[0]--; ys[1]--;
|
||||||
}
|
}
|
||||||
xs[0] = 6; xs[1] = 9; ys[0] = 10; ys[1] = 11;
|
xs[0] = 6; xs[1] = 9; ys[0] = 10; ys[1] = 11;
|
||||||
// open markers
|
// open markers
|
||||||
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0));
|
|
||||||
for (int m = 1; m < ImPlotMarker_COUNT; ++m) {
|
for (int m = 1; m < ImPlotMarker_COUNT; ++m) {
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, m);
|
|
||||||
ImGui::PushID(m);
|
ImGui::PushID(m);
|
||||||
|
ImPlot::SetNextMarkerStyle(m, mk_size, ImVec4(0,0,0,0), mk_weight);
|
||||||
ImPlot::PlotLine("##Open", xs, ys, 2);
|
ImPlot::PlotLine("##Open", xs, ys, 2);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
ImPlot::PopStyleVar();
|
|
||||||
ys[0]--; ys[1]--;
|
ys[0]--; ys[1]--;
|
||||||
}
|
}
|
||||||
ImPlot::PopStyleColor();
|
|
||||||
ImPlot::PopStyleVar(2);
|
|
||||||
|
|
||||||
ImPlot::PlotText("Filled Markers", 2.5f, 6.0f);
|
ImPlot::PlotText("Filled Markers", 2.5f, 6.0f);
|
||||||
ImPlot::PlotText("Open Markers", 7.5f, 6.0f);
|
ImPlot::PlotText("Open Markers", 7.5f, 6.0f);
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,0,1,1));
|
ImPlot::PushStyleColor(ImPlotCol_InlayText, ImVec4(1,0,1,1));
|
||||||
ImPlot::PlotText("Vertical Text", 5.0f, 6.0f, true);
|
ImPlot::PlotText("Vertical Text", 5.0f, 6.0f, true);
|
||||||
ImGui::PopStyleColor();
|
ImPlot::PopStyleColor();
|
||||||
|
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
|
@ -649,7 +635,6 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
ImPlotPoint pt = ImPlot::GetPlotMousePos();
|
ImPlotPoint pt = ImPlot::GetPlotMousePos();
|
||||||
data.push_back(t_float2((t_float)pt.x, (t_float)pt.y));
|
data.push_back(t_float2((t_float)pt.x, (t_float)pt.y));
|
||||||
}
|
}
|
||||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond);
|
|
||||||
if (data.size() > 0)
|
if (data.size() > 0)
|
||||||
ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(t_float));
|
ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(t_float));
|
||||||
if (ImPlot::IsPlotQueried() && data.size() > 0) {
|
if (ImPlot::IsPlotQueried() && data.size() > 0) {
|
||||||
|
@ -666,10 +651,10 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
if (cnt > 0) {
|
if (cnt > 0) {
|
||||||
avg.x = avg.x / cnt;
|
avg.x = avg.x / cnt;
|
||||||
avg.y = avg.y / cnt;
|
avg.y = avg.y / cnt;
|
||||||
|
ImPlot::SetNextMarkerStyle(ImPlotMarker_Square);
|
||||||
ImPlot::PlotScatter("Average", &avg.x, &avg.y, 1);
|
ImPlot::PlotScatter("Average", &avg.x, &avg.y, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImPlot::PopStyleVar();
|
|
||||||
range = ImPlot::GetPlotLimits();
|
range = ImPlot::GetPlotLimits();
|
||||||
query = ImPlot::GetPlotQuery();
|
query = ImPlot::GetPlotQuery();
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
|
@ -1042,8 +1027,8 @@ void ShowDemoWindow(bool* p_open) {
|
||||||
ImVec2 rmin = ImPlot::PlotToPixels(ImPlotPoint(0.25f, 0.75f));
|
ImVec2 rmin = ImPlot::PlotToPixels(ImPlotPoint(0.25f, 0.75f));
|
||||||
ImVec2 rmax = ImPlot::PlotToPixels(ImPlotPoint(0.75f, 0.25f));
|
ImVec2 rmax = ImPlot::PlotToPixels(ImPlotPoint(0.75f, 0.25f));
|
||||||
ImPlot::PushPlotClipRect();
|
ImPlot::PushPlotClipRect();
|
||||||
ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
|
ImPlot::GetPlotDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
|
||||||
ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
|
ImPlot::GetPlotDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
|
||||||
ImPlot::PopPlotClipRect();
|
ImPlot::PopPlotClipRect();
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
|
@ -1197,63 +1182,55 @@ int BinarySearch(const double* arr, int l, int r, double x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// begin plot item
|
||||||
ImPlotContext* implot = ImPlot::GetCurrentContext();
|
if (ImPlot::BeginItem(label_id)) {
|
||||||
// register item
|
// override legend icon color
|
||||||
ImPlotItem* item = ImPlot::RegisterOrGetItem(label_id);
|
ImPlot::GetCurrentItem()->Color = ImVec4(1,1,1,1);
|
||||||
// override legend icon color
|
// fit data if requested
|
||||||
item->Color = ImVec4(1,1,1,1);
|
if (ImPlot::FitThisFrame()) {
|
||||||
// return if item not shown (i.e. hidden by legend button)
|
for (int i = 0; i < count; ++i) {
|
||||||
if (!item->Show)
|
ImPlot::FitPoint(ImPlotPoint(xs[i], lows[i]));
|
||||||
return;
|
ImPlot::FitPoint(ImPlotPoint(xs[i], highs[i]));
|
||||||
// fit data if requested
|
}
|
||||||
if (implot->FitThisFrame) {
|
|
||||||
for (int i = 0; i < count; ++i) {
|
|
||||||
ImPlot::FitPoint(ImPlotPoint(xs[i], lows[i]));
|
|
||||||
ImPlot::FitPoint(ImPlotPoint(xs[i], highs[i]));
|
|
||||||
}
|
}
|
||||||
}
|
// get ImGui window DrawList
|
||||||
// get ImGui window DrawList
|
ImDrawList* draw_list = ImPlot::GetPlotDrawList();
|
||||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
// calc real value width
|
||||||
// push clip rect for the current plot
|
double half_width = count > 1 ? (xs[1] - xs[0]) * width_percent : width_percent;
|
||||||
ImPlot::PushPlotClipRect();
|
// render data
|
||||||
// calc real value width
|
for (int i = 0; i < count; ++i) {
|
||||||
double half_width = count > 1 ? (xs[1] - xs[0]) * width_percent : width_percent;
|
ImVec2 open_pos = ImPlot::PlotToPixels(xs[i] - half_width, opens[i]);
|
||||||
// render data
|
ImVec2 close_pos = ImPlot::PlotToPixels(xs[i] + half_width, closes[i]);
|
||||||
for (int i = 0; i < count; ++i) {
|
ImVec2 low_pos = ImPlot::PlotToPixels(xs[i], lows[i]);
|
||||||
ImVec2 open_pos = ImPlot::PlotToPixels(xs[i] - half_width, opens[i]);
|
ImVec2 high_pos = ImPlot::PlotToPixels(xs[i], highs[i]);
|
||||||
ImVec2 close_pos = ImPlot::PlotToPixels(xs[i] + half_width, closes[i]);
|
ImU32 color = ImGui::GetColorU32(opens[i] > closes[i] ? bearCol : bullCol);
|
||||||
ImVec2 low_pos = ImPlot::PlotToPixels(xs[i], lows[i]);
|
draw_list->AddLine(low_pos, high_pos, color);
|
||||||
ImVec2 high_pos = ImPlot::PlotToPixels(xs[i], highs[i]);
|
draw_list->AddRectFilled(open_pos, close_pos, color);
|
||||||
ImU32 color = ImGui::GetColorU32(opens[i] > closes[i] ? bearCol : bullCol);
|
}
|
||||||
draw_list->AddLine(low_pos, high_pos, color);
|
// custom tool
|
||||||
draw_list->AddRectFilled(open_pos, close_pos, color);
|
if (ImPlot::IsPlotHovered() && tooltip) {
|
||||||
}
|
ImPlotPoint mouse = ImPlot::GetPlotMousePos();
|
||||||
// pop clip rect for the current plot
|
mouse.x = round(mouse.x);
|
||||||
ImPlot::PopPlotClipRect();
|
float tool_l = ImPlot::PlotToPixels(mouse.x - half_width * 1.5, mouse.y).x;
|
||||||
// custom tool
|
float tool_r = ImPlot::PlotToPixels(mouse.x + half_width * 1.5, mouse.y).x;
|
||||||
if (!ImPlot::IsPlotHovered() || !tooltip)
|
float tool_t = ImPlot::GetPlotPos().y;
|
||||||
return;
|
float tool_b = tool_t + ImPlot::GetPlotSize().y;
|
||||||
ImPlotPoint mouse = ImPlot::GetPlotMousePos();
|
draw_list->AddRectFilled(ImVec2(tool_l, tool_t), ImVec2(tool_r, tool_b), IM_COL32(0,255,255,64));
|
||||||
mouse.x = round(mouse.x);
|
// find mouse location index
|
||||||
float tool_l = ImPlot::PlotToPixels(mouse.x - half_width * 1.5, mouse.y).x;
|
int idx = BinarySearch(xs, 0, count - 1, mouse.x);
|
||||||
float tool_r = ImPlot::PlotToPixels(mouse.x + half_width * 1.5, mouse.y).x;
|
// render tool tip (won't be affected by plot clip rect)
|
||||||
float tool_t = ImPlot::GetPlotPos().y;
|
if (idx != -1) {
|
||||||
float tool_b = tool_t + ImPlot::GetPlotSize().y;
|
ImGui::BeginTooltip();
|
||||||
ImPlot::PushPlotClipRect();
|
ImGui::Text("Day: %.0f", xs[idx]);
|
||||||
draw_list->AddRectFilled(ImVec2(tool_l, tool_t), ImVec2(tool_r, tool_b), IM_COL32(0,255,255,64));
|
ImGui::Text("Open: $%.2f", opens[idx]);
|
||||||
ImPlot::PopPlotClipRect();
|
ImGui::Text("Close: $%.2f", closes[idx]);
|
||||||
// find mouse location index
|
ImGui::Text("Low: $%.2f", lows[idx]);
|
||||||
int idx = BinarySearch(xs, 0, count - 1, mouse.x);
|
ImGui::Text("High: $%.2f", highs[idx]);
|
||||||
// render tool tip
|
ImGui::EndTooltip();
|
||||||
if (idx != -1) {
|
}
|
||||||
ImGui::BeginTooltip();
|
}
|
||||||
ImGui::Text("Day: %.0f", xs[idx]);
|
// end plot item
|
||||||
ImGui::Text("Open: $%.2f", opens[idx]);
|
ImPlot::EndItem();
|
||||||
ImGui::Text("Close: $%.2f", closes[idx]);
|
|
||||||
ImGui::Text("Low: $%.2f", lows[idx]);
|
|
||||||
ImGui::Text("High: $%.2f", highs[idx]);
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -299,7 +299,6 @@ struct ImPlotItem
|
||||||
{
|
{
|
||||||
ImGuiID ID;
|
ImGuiID ID;
|
||||||
ImVec4 Color;
|
ImVec4 Color;
|
||||||
ImPlotMarker Marker;
|
|
||||||
int NameOffset;
|
int NameOffset;
|
||||||
bool Show;
|
bool Show;
|
||||||
bool Highlight;
|
bool Highlight;
|
||||||
|
@ -308,7 +307,6 @@ struct ImPlotItem
|
||||||
ImPlotItem() {
|
ImPlotItem() {
|
||||||
ID = 0;
|
ID = 0;
|
||||||
Color = ImPlot::NextColormapColor();
|
Color = ImPlot::NextColormapColor();
|
||||||
Marker = ImPlotMarker_None;
|
|
||||||
NameOffset = -1;
|
NameOffset = -1;
|
||||||
Show = true;
|
Show = true;
|
||||||
SeenThisFrame = false;
|
SeenThisFrame = false;
|
||||||
|
@ -335,7 +333,6 @@ struct ImPlotState
|
||||||
bool Queried;
|
bool Queried;
|
||||||
bool DraggingQuery;
|
bool DraggingQuery;
|
||||||
int ColormapIdx;
|
int ColormapIdx;
|
||||||
int MarkerIdx;
|
|
||||||
int CurrentYAxis;
|
int CurrentYAxis;
|
||||||
|
|
||||||
ImPlotState() {
|
ImPlotState() {
|
||||||
|
@ -625,55 +622,6 @@ inline ImU32 GetStyleColorU32(ImPlotCol idx) { return ImGui::ColorConvertFloat
|
||||||
// Returns white or black text given background color
|
// Returns white or black text given background color
|
||||||
inline ImU32 CalcTextColor(const ImVec4& bg) { return (bg.x * 0.299 + bg.y * 0.587 + bg.z * 0.114) > 0.729 ? IM_COL32_BLACK : IM_COL32_WHITE; }
|
inline ImU32 CalcTextColor(const ImVec4& bg) { return (bg.x * 0.299 + bg.y * 0.587 + bg.z * 0.114) > 0.729 ? IM_COL32_BLACK : IM_COL32_WHITE; }
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if fills will render (e.g. shaded plots, bar fills)
|
|
||||||
inline bool WillFillRender() {
|
|
||||||
return GImPlot->Style.Colors[ImPlotCol_Fill].w != 0 && GImPlot->Style.FillAlpha > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if marker outlines will render
|
|
||||||
inline bool WillMarkerOutlineRender() {
|
|
||||||
return GImPlot->Style.Colors[ImPlotCol_MarkerOutline].w != 0 && GImPlot->Style.MarkerWeight > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns true if mark fill will render
|
|
||||||
inline bool WillMarkerFillRender() {
|
|
||||||
return GImPlot->Style.Colors[ImPlotCol_MarkerFill].w != 0 && GImPlot->Style.FillAlpha > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the line color for an item
|
|
||||||
inline ImVec4 GetLineColor(ImPlotItem* item) {
|
|
||||||
return IsColorAuto(ImPlotCol_Line) ? item->Color : GImPlot->Style.Colors[ImPlotCol_Line];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the fill color for an item
|
|
||||||
inline ImVec4 GetItemFillColor(ImPlotItem* item) {
|
|
||||||
ImVec4 col = IsColorAuto(ImPlotCol_Fill) ? item->Color : GImPlot->Style.Colors[ImPlotCol_Fill];
|
|
||||||
col.w *= GImPlot->Style.FillAlpha;
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the marker outline color for an item
|
|
||||||
inline ImVec4 GetMarkerOutlineColor(ImPlotItem* item) {
|
|
||||||
return IsColorAuto(ImPlotCol_MarkerOutline) ? GetLineColor(item) : GImPlot->Style.Colors[ImPlotCol_MarkerOutline];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the marker fill color for an item
|
|
||||||
inline ImVec4 GetMarkerFillColor(ImPlotItem* item) {
|
|
||||||
ImVec4 col = IsColorAuto(ImPlotCol_MarkerFill) ? GetLineColor(item) :GImPlot->Style.Colors[ImPlotCol_MarkerFill];
|
|
||||||
col.w *= GImPlot->Style.FillAlpha;
|
|
||||||
return col;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the error bar color
|
|
||||||
inline ImVec4 GetErrorBarColor() {
|
|
||||||
return GetStyleColorVec4(ImPlotCol_ErrorBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] Internal / Experimental Plotters
|
// [SECTION] Internal / Experimental Plotters
|
||||||
// No guarantee of forward compatibility here!
|
// No guarantee of forward compatibility here!
|
||||||
|
|
101
implot_items.cpp
101
implot_items.cpp
|
@ -143,11 +143,12 @@ bool BeginItem(const char* label_id, ImPlotCol recolor_from) {
|
||||||
s.DigitalBitGap = s.DigitalBitGap < 0 ? gp.Style.DigitalBitGap : s.DigitalBitGap;
|
s.DigitalBitGap = s.DigitalBitGap < 0 ? gp.Style.DigitalBitGap : s.DigitalBitGap;
|
||||||
// apply alpha modifier(s)
|
// apply alpha modifier(s)
|
||||||
s.Colors[ImPlotCol_Fill].w *= s.FillAlpha;
|
s.Colors[ImPlotCol_Fill].w *= s.FillAlpha;
|
||||||
s.Colors[ImPlotCol_MarkerFill].w *= s.FillAlpha;
|
// s.Colors[ImPlotCol_MarkerFill].w *= s.FillAlpha; // TODO: this should be separate, if it at all
|
||||||
// apply highlight mods
|
// apply highlight mods
|
||||||
if (item->Highlight) {
|
if (item->Highlight) {
|
||||||
s.LineWeight *= 2;
|
s.LineWeight *= 2;
|
||||||
s.MarkerWeight *= 2;
|
s.MarkerWeight *= 2;
|
||||||
|
// TODO: highlight fills?
|
||||||
}
|
}
|
||||||
// set render flags
|
// set render flags
|
||||||
s.RenderLine = s.Colors[ImPlotCol_Line].w > 0 && s.LineWeight > 0;
|
s.RenderLine = s.Colors[ImPlotCol_Line].w > 0 && s.LineWeight > 0;
|
||||||
|
@ -183,7 +184,7 @@ void SetNextFillStyle(const ImVec4& col, float alpha) {
|
||||||
gp.NextItemStyle.FillAlpha = alpha;
|
gp.NextItemStyle.FillAlpha = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNextMarkerStyle(ImPlotMarker marker, const ImVec4& fill, float size, const ImVec4& outline, float weight) {
|
void SetNextMarkerStyle(ImPlotMarker marker, float size, const ImVec4& fill, float weight, const ImVec4& outline) {
|
||||||
ImPlotContext& gp = *GImPlot;
|
ImPlotContext& gp = *GImPlot;
|
||||||
gp.NextItemStyle.Marker = marker;
|
gp.NextItemStyle.Marker = marker;
|
||||||
gp.NextItemStyle.Colors[ImPlotCol_MarkerFill] = fill;
|
gp.NextItemStyle.Colors[ImPlotCol_MarkerFill] = fill;
|
||||||
|
@ -742,7 +743,6 @@ inline void RenderMarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bo
|
||||||
template <typename Transformer, typename Getter>
|
template <typename Transformer, typename Getter>
|
||||||
inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& DrawList, ImPlotMarker marker, float size, bool rend_mk_line, ImU32 col_mk_line, float weight, bool rend_mk_fill, ImU32 col_mk_fill) {
|
inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& DrawList, ImPlotMarker marker, float size, bool rend_mk_line, ImU32 col_mk_line, float weight, bool rend_mk_fill, ImU32 col_mk_fill) {
|
||||||
static void (*marker_table[])(ImDrawList&, const ImVec2&, float s, bool, ImU32, bool, ImU32, float) = {
|
static void (*marker_table[])(ImDrawList&, const ImVec2&, float s, bool, ImU32, bool, ImU32, float) = {
|
||||||
NULL,
|
|
||||||
RenderMarkerCircle,
|
RenderMarkerCircle,
|
||||||
RenderMarkerSquare,
|
RenderMarkerSquare,
|
||||||
RenderMarkerDiamond ,
|
RenderMarkerDiamond ,
|
||||||
|
@ -767,7 +767,7 @@ inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& Dr
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
template <typename Getter>
|
template <typename Getter>
|
||||||
inline void PlotEx(const char* label_id, Getter getter) {
|
inline void PlotLineEx(const char* label_id, Getter getter) {
|
||||||
if (BeginItem(label_id, ImPlotCol_Line)) {
|
if (BeginItem(label_id, ImPlotCol_Line)) {
|
||||||
if (FitThisFrame()) {
|
if (FitThisFrame()) {
|
||||||
for (int i = 0; i < getter.Count; ++i) {
|
for (int i = 0; i < getter.Count; ++i) {
|
||||||
|
@ -804,99 +804,108 @@ inline void PlotEx(const char* label_id, Getter getter) {
|
||||||
// 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);
|
||||||
PlotEx(label_id, getter);
|
PlotLineEx(label_id, getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
||||||
GetterXsYs<float> getter(xs,ys,count,offset,stride);
|
GetterXsYs<float> getter(xs,ys,count,offset,stride);
|
||||||
return PlotEx(label_id, getter);
|
return PlotLineEx(label_id, getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotLine(const char* label_id, const ImVec2* data, int count, int offset) {
|
void PlotLine(const char* label_id, const ImVec2* data, int count, int offset) {
|
||||||
GetterImVec2 getter(data, count, offset);
|
GetterImVec2 getter(data, count, offset);
|
||||||
return PlotEx(label_id, getter);
|
return PlotLineEx(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);
|
||||||
PlotEx(label_id, getter);
|
PlotLineEx(label_id, getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
||||||
GetterXsYs<double> getter(xs,ys,count,offset,stride);
|
GetterXsYs<double> getter(xs,ys,count,offset,stride);
|
||||||
return PlotEx(label_id, getter);
|
return PlotLineEx(label_id, getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset) {
|
void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset) {
|
||||||
GetterImPlotPoint getter(data, count, offset);
|
GetterImPlotPoint getter(data, count, offset);
|
||||||
return PlotEx(label_id, getter);
|
return PlotLineEx(label_id, getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// custom
|
// custom
|
||||||
void PlotLine(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
|
void PlotLine(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
|
||||||
GetterFuncPtrImPlotPoint getter(getter_func,data, count, offset);
|
GetterFuncPtrImPlotPoint getter(getter_func,data, count, offset);
|
||||||
return PlotEx(label_id, getter);
|
return PlotLineEx(label_id, getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// PLOT SCATTER
|
// PLOT SCATTER
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
inline int PushScatterStyle() {
|
template <typename Getter>
|
||||||
int vars = 1;
|
inline void PlotScatterEx(const char* label_id, Getter getter) {
|
||||||
PushStyleVar(ImPlotStyleVar_LineWeight, 0);
|
if (BeginItem(label_id, ImPlotCol_MarkerOutline)) {
|
||||||
if (GetStyle().Marker == ImPlotMarker_None) {
|
if (FitThisFrame()) {
|
||||||
PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
for (int i = 0; i < getter.Count; ++i) {
|
||||||
vars++;
|
ImPlotPoint p = getter(i);
|
||||||
|
FitPoint(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const ImPlotItemStyle& s = GetItemStyle();
|
||||||
|
ImDrawList& DrawList = *GetPlotDrawList();
|
||||||
|
// render markers
|
||||||
|
ImPlotMarker marker = s.Marker == ImPlotMarker_None ? ImPlotMarker_Circle : s.Marker;
|
||||||
|
if (marker != ImPlotMarker_None) {
|
||||||
|
const ImU32 col_line = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerOutline]);
|
||||||
|
const ImU32 col_fill = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerFill]);
|
||||||
|
switch (GetCurrentScale()) {
|
||||||
|
case ImPlotScale_LinLin: RenderMarkers(getter, TransformerLinLin(), DrawList, marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
|
||||||
|
case ImPlotScale_LogLin: RenderMarkers(getter, TransformerLogLin(), DrawList, marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
|
||||||
|
case ImPlotScale_LinLog: RenderMarkers(getter, TransformerLinLog(), DrawList, marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
|
||||||
|
case ImPlotScale_LogLog: RenderMarkers(getter, TransformerLogLog(), DrawList, marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EndItem();
|
||||||
}
|
}
|
||||||
return vars;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// float
|
// float
|
||||||
void PlotScatter(const char* label_id, const float* values, int count, int offset, int stride) {
|
void PlotScatter(const char* label_id, const float* values, int count, int offset, int stride) {
|
||||||
int vars = PushScatterStyle();
|
GetterYs<float> getter(values,count,offset,stride);
|
||||||
PlotLine(label_id, values, count, offset, stride);
|
PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
||||||
int vars = PushScatterStyle();
|
GetterXsYs<float> getter(xs,ys,count,offset,stride);
|
||||||
PlotLine(label_id, xs, ys, count, offset, stride);
|
return PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset) {
|
void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset) {
|
||||||
int vars = PushScatterStyle();
|
GetterImVec2 getter(data, count, offset);
|
||||||
PlotLine(label_id, data, count, offset);
|
return PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// double
|
// double
|
||||||
void PlotScatter(const char* label_id, const double* values, int count, int offset, int stride) {
|
void PlotScatter(const char* label_id, const double* values, int count, int offset, int stride) {
|
||||||
int vars = PushScatterStyle();
|
GetterYs<double> getter(values,count,offset,stride);
|
||||||
PlotLine(label_id, values, count, offset, stride);
|
PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotScatter(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
void PlotScatter(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
||||||
int vars = PushScatterStyle();
|
GetterXsYs<double> getter(xs,ys,count,offset,stride);
|
||||||
PlotLine(label_id, xs, ys, count, offset, stride);
|
return PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotScatter(const char* label_id, const ImPlotPoint* data, int count, int offset) {
|
void PlotScatter(const char* label_id, const ImPlotPoint* data, int count, int offset) {
|
||||||
int vars = PushScatterStyle();
|
GetterImPlotPoint getter(data, count, offset);
|
||||||
PlotLine(label_id, data, count, offset);
|
return PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom
|
// custom
|
||||||
void PlotScatter(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset) {
|
void PlotScatter(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
|
||||||
int vars = PushScatterStyle();
|
GetterFuncPtrImPlotPoint getter(getter_func,data, count, offset);
|
||||||
PlotLine(label_id, getter, data, count, offset);
|
return PlotScatterEx(label_id, getter);
|
||||||
PopStyleVar(vars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -1247,11 +1256,10 @@ void PlotPieChartEx(const char** label_ids, const T* values, int count, T x, T y
|
||||||
T a0 = angle0 * 2 * IM_PI / 360.0f;
|
T a0 = angle0 * 2 * IM_PI / 360.0f;
|
||||||
T a1 = angle0 * 2 * IM_PI / 360.0f;
|
T a1 = angle0 * 2 * IM_PI / 360.0f;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
ImPlotItem* item = RegisterOrGetItem(label_ids[i]);
|
|
||||||
ImU32 col = ImGui::GetColorU32(GetItemFillColor(item));
|
|
||||||
T percent = normalize ? values[i] / sum : values[i];
|
T percent = normalize ? values[i] / sum : values[i];
|
||||||
a1 = a0 + 2 * IM_PI * percent;
|
a1 = a0 + 2 * IM_PI * percent;
|
||||||
if (item->Show) {
|
if (BeginItem(label_ids[i])) {
|
||||||
|
ImU32 col = ImGui::GetColorU32(GetCurrentItem()->Color);
|
||||||
if (percent < 0.5) {
|
if (percent < 0.5) {
|
||||||
RenderPieSlice(DrawList, center, radius, a0, a1, col);
|
RenderPieSlice(DrawList, center, radius, a0, a1, col);
|
||||||
}
|
}
|
||||||
|
@ -1259,6 +1267,7 @@ void PlotPieChartEx(const char** label_ids, const T* values, int count, T x, T y
|
||||||
RenderPieSlice(DrawList, center, radius, a0, a0 + (a1 - a0) * 0.5f, col);
|
RenderPieSlice(DrawList, center, radius, a0, a0 + (a1 - a0) * 0.5f, col);
|
||||||
RenderPieSlice(DrawList, center, radius, a0 + (a1 - a0) * 0.5f, a1, col);
|
RenderPieSlice(DrawList, center, radius, a0 + (a1 - a0) * 0.5f, a1, col);
|
||||||
}
|
}
|
||||||
|
EndItem();
|
||||||
}
|
}
|
||||||
a0 = a1;
|
a0 = a1;
|
||||||
}
|
}
|
||||||
|
@ -1275,7 +1284,7 @@ void PlotPieChartEx(const char** label_ids, const T* values, int count, T x, T y
|
||||||
ImVec2 size = ImGui::CalcTextSize(buffer);
|
ImVec2 size = ImGui::CalcTextSize(buffer);
|
||||||
T angle = a0 + (a1 - a0) * 0.5f;
|
T angle = a0 + (a1 - a0) * 0.5f;
|
||||||
ImVec2 pos = PlotToPixels(center.x + 0.5f * radius * cos(angle), center.y + 0.5f * radius * sin(angle));
|
ImVec2 pos = PlotToPixels(center.x + 0.5f * radius * cos(angle), center.y + 0.5f * radius * sin(angle));
|
||||||
ImU32 col = CalcTextColor(GetItemFillColor(item));
|
ImU32 col = CalcTextColor(item->Color);
|
||||||
DrawList.AddText(pos - size * 0.5f, col, buffer);
|
DrawList.AddText(pos - size * 0.5f, col, buffer);
|
||||||
}
|
}
|
||||||
a0 = a1;
|
a0 = a1;
|
||||||
|
@ -1509,7 +1518,7 @@ void PlotText(const char* text, double x, double y, bool vertical, const ImVec2&
|
||||||
IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "PlotText() needs to be called between BeginPlot() and EndPlot()!");
|
IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "PlotText() needs to be called between BeginPlot() and EndPlot()!");
|
||||||
ImDrawList & DrawList = *GetPlotDrawList();
|
ImDrawList & DrawList = *GetPlotDrawList();
|
||||||
PushPlotClipRect();
|
PushPlotClipRect();
|
||||||
ImU32 colTxt = ImGui::GetColorU32(ImGuiCol_Text);
|
ImU32 colTxt = GetStyleColorU32(ImPlotCol_InlayText);
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
ImVec2 ctr = CalcTextSizeVertical(text) * 0.5f;
|
ImVec2 ctr = CalcTextSizeVertical(text) * 0.5f;
|
||||||
ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) + ImVec2(-ctr.x, ctr.y) + pixel_offset;
|
ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) + ImVec2(-ctr.x, ctr.y) + pixel_offset;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user