1
0
Fork 0
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:
epezent 2020-08-31 23:23:48 -05:00
parent 3e21d841a2
commit 71bf19b4c4
5 changed files with 245 additions and 284 deletions

View File

@ -106,7 +106,7 @@ ImPlotStyle::ImPlotStyle() {
DigitalBitHeight = 8;
DigitalBitGap = 4;
AntiAliasedLines = false;
PlotBorderSize = 1;
MinorAlpha = 0.25f;
MajorTickLen = ImVec2(10,10);
@ -414,8 +414,8 @@ void UpdateTransformCache() {
gp.My[i] = (gp.PixelRange[i].Max.y - gp.PixelRange[i].Min.y) / gp.CurrentPlot->YAxis[i].Range.Size();
}
gp.LogDenX = ImLog10(gp.CurrentPlot->XAxis.Range.Max / gp.CurrentPlot->XAxis.Range.Min);
for (int i = 0; i < IMPLOT_Y_AXES; i++)
gp.LogDenY[i] = ImLog10(gp.CurrentPlot->YAxis[i].Range.Max / gp.CurrentPlot->YAxis[i].Range.Min);
for (int i = 0; i < IMPLOT_Y_AXES; i++)
gp.LogDenY[i] = ImLog10(gp.CurrentPlot->YAxis[i].Range.Max / gp.CurrentPlot->YAxis[i].Range.Min);
gp.Mx = (gp.PixelRange[0].Max.x - gp.PixelRange[0].Min.x) / gp.CurrentPlot->XAxis.Range.Size();
}
@ -511,12 +511,12 @@ void AddTicksDefault(const ImPlotRange& range, int nMajor, int nMinor, ImPlotTic
const double graphmin = floor(range.Min / interval) * interval;
const double graphmax = ceil(range.Max / interval) * interval;
for (double major = graphmin; major < graphmax + 0.5 * interval; major += interval) {
if (range.Contains(major))
if (range.Contains(major))
ticks.AddTick(major, true, true, LabelTickDefault);
for (int i = 1; i < nMinor; ++i) {
double minor = major + i * interval / nMinor;
if (range.Contains(minor))
ticks.AddTick(minor, false, true, LabelTickDefault);
if (range.Contains(minor))
ticks.AddTick(minor, false, true, LabelTickDefault);
}
}
}
@ -537,17 +537,17 @@ void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImPlotTickCollect
double major1 = ImPow(10, (double)(e));
double major2 = ImPow(10, (double)(e + 1));
double interval = (major2 - major1) / 9;
if (major1 >= (range.Min - DBL_EPSILON) && major1 <= (range.Max + DBL_EPSILON))
ticks.AddTick(major1, true, true, LabelTickScientific);
if (major1 >= (range.Min - DBL_EPSILON) && major1 <= (range.Max + DBL_EPSILON))
ticks.AddTick(major1, true, true, LabelTickScientific);
for (int j = 0; j < exp_step; ++j) {
major1 = ImPow(10, (double)(e+j));
major2 = ImPow(10, (double)(e+j+1));
interval = (major2 - major1) / 9;
for (int i = 1; i < (9 + (int)(j < (exp_step - 1))); ++i) {
double minor = major1 + i * interval;
if (minor >= (range.Min - DBL_EPSILON) && minor <= (range.Max + DBL_EPSILON))
ticks.AddTick(minor, false, false, LabelTickScientific);
if (minor >= (range.Min - DBL_EPSILON) && minor <= (range.Max + DBL_EPSILON))
ticks.AddTick(minor, false, false, LabelTickScientific);
}
}
}
@ -691,7 +691,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
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;
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;
}
@ -699,7 +699,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// CONSTRAINTS ------------------------------------------------------------
ConstrainAxis(plot.XAxis);
for (int i = 0; i < IMPLOT_Y_AXES; i++)
for (int i = 0; i < IMPLOT_Y_AXES; i++)
ConstrainAxis(plot.YAxis[i]);
// AXIS COLORS -----------------------------------------------------------------
@ -1484,15 +1484,17 @@ void EndPlot() {
col_hl_txt = ImGui::GetColorU32(col_txt);
}
ImU32 iconColor;
ImVec4 item_color = item->Color;
item_color.w = 1;
if (hov_legend && icon_bb.Contains(IO.MousePos)) {
ImVec4 colAlpha = item->Color;
ImVec4 colAlpha = item_color;
colAlpha.w = 0.5f;
iconColor = item->Show ? ImGui::GetColorU32(colAlpha)
: ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f);
if (IO.MouseClicked[0])
item->Show = !item->Show;
} 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);
const char* label = GetLegendLabel(i);
@ -2175,7 +2177,7 @@ void ShowColormapScale(double scale_min, double scale_max, float height) {
ImPlotRange range;
range.Min = scale_min;
range.Max = scale_max;
AddTicksDefault(range, 10, 0, ticks);
@ -2192,7 +2194,7 @@ void ShowColormapScale(double scale_min, double scale_max, float height) {
ImGui::ItemSize(bb_frame);
if (!ImGui::ItemAdd(bb_frame, 0, &bb_frame))
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));
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)));
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);
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);
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.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.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), GetStyleColorU32(ImPlotCol_TitleText), ticks.GetLabel(i));
}
ImGui::PopClipRect();
DrawList.AddRect(bb_grad.Min, bb_grad.Max, col_border);
DrawList.AddRect(bb_grad.Min, bb_grad.Max, GetStyleColorU32(ImPlotCol_PlotBorder));
}

View File

@ -33,7 +33,7 @@
#define IMPLOT_VERSION "0.5 WIP"
// Indicates variable should deduced automatically.
#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)
//-----------------------------------------------------------------------------
@ -82,13 +82,13 @@ enum ImPlotAxisFlags_ {
// Plot styling colors.
enum ImPlotCol_ {
// item related colors
// item styling colors
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_MarkerOutline, // marker outline 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)
// plot related colors
// plot styling colors
ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg)
ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg)
ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Border)
@ -142,7 +142,7 @@ enum ImPlotStyleVar_ {
// Marker specifications.
enum ImPlotMarker_ {
ImPlotMarker_None, // no marker
ImPlotMarker_None = -1, // no marker
ImPlotMarker_Circle, // a circle marker
ImPlotMarker_Square, // a square maker
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
// 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
// title in the plot, use double hashes (e.g. "MyPlot##Hidden"). If #x_label
// and/or #y_label are provided, axes labels will be displayed.
// title in the plot, use double hashes (e.g. "MyPlot##Hidden" or "##NoTitle").
// If #x_label and/or #y_label are provided, axes labels will be displayed.
bool BeginPlot(const char* title_id,
const char* x_label = NULL,
const char* y_label = NULL,
@ -401,6 +401,9 @@ ImVec2 PlotToPixels(double x, double y, int y_axis = IMPLOT_AUTO);
// 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.
ImVec2 GetPlotPos();
// Get the curent Plot size in pixels.
@ -423,7 +426,7 @@ ImPlotLimits GetPlotQuery(int y_axis = IMPLOT_AUTO);
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.
@ -438,19 +441,14 @@ void StyleColorsDark(ImPlotStyle* dst = NULL);
// Style colors for ImGui "Light".
void StyleColorsLight(ImPlotStyle* dst = NULL);
// Set the line color and weight for the next item only.
void SetNextLineStyle(const ImVec4& col, float weight = IMPLOT_AUTO);
// Set the fill color for the next item only.
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);
// Use PushStyleX to temporarily modify your ImPlotStyle. The modification
// will last until the matching call to PopStyleX. You MUST call a pop for
// every push, otherwise you will leak memory! This behaves just like ImGui.
// Temporarily modify a plot color. Don't forget to call PopStyleColor!
void PushStyleColor(ImPlotCol idx, ImU32 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);
// 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);
// Temporarily modify a style variable of ImVec2 type. Don't forget to call PopStyleVar!
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);
// 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.
void PushColormap(ImPlotColormap colormap);
// 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);
// 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);
// Returns the size of the current colormap.
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);
// Linearly interpolates a color from the current colormap given t between 0 and 1.
ImVec4 LerpColormap(float t);
// Returns the next unused colormap color and advances the colormap. Can be used to skip colors if desired.
ImVec4 NextColormapColor();
// 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.
// Renders a vertical color scale using the current color map. Call this outside of Begin/EndPlot.
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

View File

@ -181,7 +181,7 @@ void ShowDemoWindow(bool* p_open) {
ImGui::BulletText("Software AA can be enabled globally with ImPlotStyle.AntiAliasedLines.");
ImGui::BulletText("Software AA can be enabled per plot with ImPlotFlags_AntiAliased.");
ImGui::BulletText("AA for plots can be toggled from the plot's context menu.");
ImGui::BulletText("If permitable, you are better off using hardware AA (e.g. MSAA).");
ImGui::BulletText("If permitable, you are better off using hardware AA (e.g. MSAA).");
ImGui::Unindent();
ImGui::BulletText("If you see visual artifacts, do one of the following:");
ImGui::Indent();
@ -236,9 +236,7 @@ void ShowDemoWindow(bool* p_open) {
xs2[i] = i * 0.1f;
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).");
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
ImPlot::PlotLine("sin(x)", xs1, ys1, 1001);
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle);
@ -322,11 +320,10 @@ void ShowDemoWindow(bool* p_open) {
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL)) {
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::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::PopStyleVar(3);
ImPlot::PopStyleVar();
ImPlot::EndPlot();
}
}
@ -348,19 +345,19 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::SetNextPlotLimits(-0.5, 9.5, 0, 110, ImGuiCond_Always);
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,
horz ? ImPlotAxisFlags_Default | ImPlotAxisFlags_Invert : ImPlotAxisFlags_Default))
{
if (horz) {
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2f, -0.2f);
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2f, 0.2f);
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2f, 0.2f);
}
else {
ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2f, -0.2f);
ImPlot::PlotBars("Final Exam", final, 10, 0.2f, 0);
ImPlot::PlotBars("Course Grade", grade, 10, 0.2f, 0.2f);
ImPlot::PlotBars("Final Exam", final, 10, 0.2f, 0);
ImPlot::PlotBars("Course Grade", grade, 10, 0.2f, 0.2f);
}
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 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 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);
if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL)) {
ImPlot::PushStyleVar(ImPlotStyleVar_ErrorBarSize, size);
ImPlot::PushStyleVar(ImPlotStyleVar_ErrorBarWeight, weight);
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::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::SetNextMarkerStyle(ImPlotMarker_Circle);
ImPlot::PlotLine("Line", xs, lin1, 5);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(2));
ImPlot::PlotErrorBars("Scatter", xs, lin2, err2, 5);
ImPlot::PlotErrorBarsH("Scatter", xs, lin2, err3, err4, 5);
ImPlot::PopStyleColor();
ImPlot::PlotScatter("Scatter", xs, lin2, 5);
ImPlot::PopStyleVar(4);
ImPlot::PopStyleColor(2);
ImPlot::EndPlot();
}
}
@ -462,7 +455,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PushColormap(map);
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)) {
ImPlot::PlotHeatmap("heat",values1[0],7,7,scale_min,scale_max);
ImPlot::EndPlot();
@ -514,7 +507,7 @@ void ShowDemoWindow(bool* p_open) {
// two methods of plotting Data
// as ImVec2* (or ImPlot*):
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::EndPlot();
}
@ -531,37 +524,30 @@ void ShowDemoWindow(bool* p_open) {
t_float xs[2] = {1,4};
t_float ys[2] = {10,11};
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, mk_size);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerWeight, mk_weight);
// filled markers
for (int m = 1; m < ImPlotMarker_COUNT; ++m) {
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, m);
ImGui::PushID(m);
ImPlot::SetNextMarkerStyle(m, mk_size, IMPLOT_AUTO_COL, mk_weight);
ImPlot::PlotLine("##Filled", xs, ys, 2);
ImGui::PopID();
ImPlot::PopStyleVar();
ys[0]--; ys[1]--;
}
xs[0] = 6; xs[1] = 9; ys[0] = 10; ys[1] = 11;
// open markers
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(0,0,0,0));
for (int m = 1; m < ImPlotMarker_COUNT; ++m) {
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, m);
ImGui::PushID(m);
ImPlot::SetNextMarkerStyle(m, mk_size, ImVec4(0,0,0,0), mk_weight);
ImPlot::PlotLine("##Open", xs, ys, 2);
ImGui::PopID();
ImPlot::PopStyleVar();
ys[0]--; ys[1]--;
}
ImPlot::PopStyleColor();
ImPlot::PopStyleVar(2);
ImPlot::PlotText("Filled Markers", 2.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);
ImGui::PopStyleColor();
ImPlot::PopStyleColor();
ImPlot::EndPlot();
}
@ -649,7 +635,6 @@ void ShowDemoWindow(bool* p_open) {
ImPlotPoint pt = ImPlot::GetPlotMousePos();
data.push_back(t_float2((t_float)pt.x, (t_float)pt.y));
}
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond);
if (data.size() > 0)
ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(t_float));
if (ImPlot::IsPlotQueried() && data.size() > 0) {
@ -666,10 +651,10 @@ void ShowDemoWindow(bool* p_open) {
if (cnt > 0) {
avg.x = avg.x / cnt;
avg.y = avg.y / cnt;
ImPlot::SetNextMarkerStyle(ImPlotMarker_Square);
ImPlot::PlotScatter("Average", &avg.x, &avg.y, 1);
}
}
ImPlot::PopStyleVar();
range = ImPlot::GetPlotLimits();
query = ImPlot::GetPlotQuery();
ImPlot::EndPlot();
@ -1042,8 +1027,8 @@ void ShowDemoWindow(bool* p_open) {
ImVec2 rmin = ImPlot::PlotToPixels(ImPlotPoint(0.25f, 0.75f));
ImVec2 rmax = ImPlot::PlotToPixels(ImPlotPoint(0.75f, 0.25f));
ImPlot::PushPlotClipRect();
ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
ImPlot::GetPlotDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
ImPlot::GetPlotDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
ImPlot::PopPlotClipRect();
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) {
// get current implot context
ImPlotContext* implot = ImPlot::GetCurrentContext();
// register item
ImPlotItem* item = ImPlot::RegisterOrGetItem(label_id);
// override legend icon color
item->Color = ImVec4(1,1,1,1);
// return if item not shown (i.e. hidden by legend button)
if (!item->Show)
return;
// 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]));
// begin plot item
if (ImPlot::BeginItem(label_id)) {
// override legend icon color
ImPlot::GetCurrentItem()->Color = ImVec4(1,1,1,1);
// 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
ImDrawList* draw_list = ImGui::GetWindowDrawList();
// push clip rect for the current plot
ImPlot::PushPlotClipRect();
// calc real value width
double half_width = count > 1 ? (xs[1] - xs[0]) * width_percent : width_percent;
// render data
for (int i = 0; i < count; ++i) {
ImVec2 open_pos = ImPlot::PlotToPixels(xs[i] - half_width, opens[i]);
ImVec2 close_pos = ImPlot::PlotToPixels(xs[i] + half_width, closes[i]);
ImVec2 low_pos = ImPlot::PlotToPixels(xs[i], lows[i]);
ImVec2 high_pos = ImPlot::PlotToPixels(xs[i], highs[i]);
ImU32 color = ImGui::GetColorU32(opens[i] > closes[i] ? bearCol : bullCol);
draw_list->AddLine(low_pos, high_pos, color);
draw_list->AddRectFilled(open_pos, close_pos, color);
}
// pop clip rect for the current plot
ImPlot::PopPlotClipRect();
// custom tool
if (!ImPlot::IsPlotHovered() || !tooltip)
return;
ImPlotPoint mouse = ImPlot::GetPlotMousePos();
mouse.x = round(mouse.x);
float tool_l = ImPlot::PlotToPixels(mouse.x - half_width * 1.5, mouse.y).x;
float tool_r = ImPlot::PlotToPixels(mouse.x + half_width * 1.5, mouse.y).x;
float tool_t = ImPlot::GetPlotPos().y;
float tool_b = tool_t + ImPlot::GetPlotSize().y;
ImPlot::PushPlotClipRect();
draw_list->AddRectFilled(ImVec2(tool_l, tool_t), ImVec2(tool_r, tool_b), IM_COL32(0,255,255,64));
ImPlot::PopPlotClipRect();
// find mouse location index
int idx = BinarySearch(xs, 0, count - 1, mouse.x);
// render tool tip
if (idx != -1) {
ImGui::BeginTooltip();
ImGui::Text("Day: %.0f", xs[idx]);
ImGui::Text("Open: $%.2f", opens[idx]);
ImGui::Text("Close: $%.2f", closes[idx]);
ImGui::Text("Low: $%.2f", lows[idx]);
ImGui::Text("High: $%.2f", highs[idx]);
ImGui::EndTooltip();
// get ImGui window DrawList
ImDrawList* draw_list = ImPlot::GetPlotDrawList();
// calc real value width
double half_width = count > 1 ? (xs[1] - xs[0]) * width_percent : width_percent;
// render data
for (int i = 0; i < count; ++i) {
ImVec2 open_pos = ImPlot::PlotToPixels(xs[i] - half_width, opens[i]);
ImVec2 close_pos = ImPlot::PlotToPixels(xs[i] + half_width, closes[i]);
ImVec2 low_pos = ImPlot::PlotToPixels(xs[i], lows[i]);
ImVec2 high_pos = ImPlot::PlotToPixels(xs[i], highs[i]);
ImU32 color = ImGui::GetColorU32(opens[i] > closes[i] ? bearCol : bullCol);
draw_list->AddLine(low_pos, high_pos, color);
draw_list->AddRectFilled(open_pos, close_pos, color);
}
// custom tool
if (ImPlot::IsPlotHovered() && tooltip) {
ImPlotPoint mouse = ImPlot::GetPlotMousePos();
mouse.x = round(mouse.x);
float tool_l = ImPlot::PlotToPixels(mouse.x - half_width * 1.5, mouse.y).x;
float tool_r = ImPlot::PlotToPixels(mouse.x + half_width * 1.5, mouse.y).x;
float tool_t = ImPlot::GetPlotPos().y;
float tool_b = tool_t + ImPlot::GetPlotSize().y;
draw_list->AddRectFilled(ImVec2(tool_l, tool_t), ImVec2(tool_r, tool_b), IM_COL32(0,255,255,64));
// find mouse location index
int idx = BinarySearch(xs, 0, count - 1, mouse.x);
// render tool tip (won't be affected by plot clip rect)
if (idx != -1) {
ImGui::BeginTooltip();
ImGui::Text("Day: %.0f", xs[idx]);
ImGui::Text("Open: $%.2f", opens[idx]);
ImGui::Text("Close: $%.2f", closes[idx]);
ImGui::Text("Low: $%.2f", lows[idx]);
ImGui::Text("High: $%.2f", highs[idx]);
ImGui::EndTooltip();
}
}
// end plot item
ImPlot::EndItem();
}
}
@ -1297,17 +1274,17 @@ void ShowBenchmarkTool() {
t1 = ImGui::GetTime();
}
if (L > max_lines) {
running = false;
L = max_lines;
}
running = false;
L = max_lines;
}
}
ImGui::Text("ImDrawIdx: %d-bit", (int)(sizeof(ImDrawIdx) * 8));
ImGui::Text("ImGuiBackendFlags_RendererHasVtxOffset: %s", (ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) ? "True" : "False");
ImGui::Text("ImGuiBackendFlags_RendererHasVtxOffset: %s", (ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) ? "True" : "False");
ImGui::Text("%.2f FPS", ImGui::GetIO().Framerate);
ImGui::Separator();
bool was_running = running;
if (was_running) {
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
@ -1321,9 +1298,9 @@ void ShowBenchmarkTool() {
t1 = ImGui::GetTime();
}
ImGui::SameLine();
ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines);
ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines);
if (was_running) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); }
ImGui::ProgressBar((float)L / (float)(max_lines - 1));
ImPlot::SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);

View File

@ -219,7 +219,7 @@ struct ImPlotTickCollection {
Ticks.push_back(tick);
Size++;
}
void AddTick(double value, bool major, bool show_label, void (*labeler)(ImPlotTick& tick, ImGuiTextBuffer& buf)) {
ImPlotTick tick(value, major, show_label);
if (labeler)
@ -231,9 +231,9 @@ struct ImPlotTickCollection {
return Labels.Buf.Data + Ticks[idx].BufferOffset;
}
void Reset() {
Ticks.shrink(0);
Labels.Buf.shrink(0);
void Reset() {
Ticks.shrink(0);
Labels.Buf.shrink(0);
TotalWidth = TotalHeight = MaxWidth = MaxHeight = 0;
Size = 0;
}
@ -299,7 +299,6 @@ struct ImPlotItem
{
ImGuiID ID;
ImVec4 Color;
ImPlotMarker Marker;
int NameOffset;
bool Show;
bool Highlight;
@ -308,7 +307,6 @@ struct ImPlotItem
ImPlotItem() {
ID = 0;
Color = ImPlot::NextColormapColor();
Marker = ImPlotMarker_None;
NameOffset = -1;
Show = true;
SeenThisFrame = false;
@ -335,7 +333,6 @@ struct ImPlotState
bool Queried;
bool DraggingQuery;
int ColormapIdx;
int MarkerIdx;
int CurrentYAxis;
ImPlotState() {
@ -375,15 +372,15 @@ struct ImPlotNextPlotData
// Temporary data storage for upcoming item
struct ImPlotItemStyle {
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;
float LineWeight;
ImPlotMarker Marker;
float MarkerSize;
float MarkerWeight;
float FillAlpha;
float ErrorBarSize;
float ErrorBarWeight;
float DigitalBitHeight;
float DigitalBitGap;
bool RenderLine;
bool RenderFill;
bool RenderMarkerLine;
@ -394,7 +391,7 @@ struct ImPlotItemStyle {
LineWeight = MarkerWeight = FillAlpha = ErrorBarSize =
ErrorBarSize = ErrorBarWeight = DigitalBitHeight = DigitalBitGap = IMPLOT_AUTO;
Marker = IMPLOT_AUTO;
}
}
};
// Holds state information that must persist between calls to BeginPlot()/EndPlot()
@ -625,55 +622,6 @@ inline ImU32 GetStyleColorU32(ImPlotCol idx) { return ImGui::ColorConvertFloat
// 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; }
// 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
// No guarantee of forward compatibility here!

View File

@ -135,19 +135,20 @@ bool BeginItem(const char* label_id, ImPlotCol recolor_from) {
s.LineWeight = s.LineWeight < 0 ? gp.Style.LineWeight : s.LineWeight;
s.Marker = s.Marker < 0 ? gp.Style.Marker : s.Marker;
s.MarkerSize = s.MarkerSize < 0 ? gp.Style.MarkerSize : s.MarkerSize;
s.MarkerWeight = s.MarkerWeight < 0 ? gp.Style.MarkerWeight : s.MarkerWeight;
s.FillAlpha = s.FillAlpha < 0 ? gp.Style.FillAlpha : s.FillAlpha;
s.ErrorBarSize = s.ErrorBarSize < 0 ? gp.Style.ErrorBarSize : s.ErrorBarSize;
s.MarkerWeight = s.MarkerWeight < 0 ? gp.Style.MarkerWeight : s.MarkerWeight;
s.FillAlpha = s.FillAlpha < 0 ? gp.Style.FillAlpha : s.FillAlpha;
s.ErrorBarSize = s.ErrorBarSize < 0 ? gp.Style.ErrorBarSize : s.ErrorBarSize;
s.ErrorBarWeight = s.ErrorBarWeight < 0 ? gp.Style.ErrorBarWeight : s.ErrorBarWeight;
s.DigitalBitHeight = s.DigitalBitHeight < 0 ? gp.Style.DigitalBitHeight : s.DigitalBitHeight;
s.DigitalBitGap = s.DigitalBitGap < 0 ? gp.Style.DigitalBitGap : s.DigitalBitGap;
s.DigitalBitGap = s.DigitalBitGap < 0 ? gp.Style.DigitalBitGap : s.DigitalBitGap;
// apply alpha modifier(s)
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
if (item->Highlight) {
s.LineWeight *= 2;
s.MarkerWeight *= 2;
// TODO: highlight fills?
}
// set render flags
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;
}
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;
gp.NextItemStyle.Marker = marker;
gp.NextItemStyle.Colors[ImPlotCol_MarkerFill] = fill;
@ -741,24 +742,23 @@ inline void RenderMarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bo
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) {
static void (*marker_table[])(ImDrawList&, const ImVec2&, float s, bool, ImU32, bool, ImU32, float) = {
NULL,
RenderMarkerCircle,
RenderMarkerSquare,
RenderMarkerDiamond ,
RenderMarkerUp ,
RenderMarkerDown ,
RenderMarkerLeft,
RenderMarkerRight,
RenderMarkerCross,
RenderMarkerPlus,
static void (*marker_table[])(ImDrawList&, const ImVec2&, float s, bool, ImU32, bool, ImU32, float) = {
RenderMarkerCircle,
RenderMarkerSquare,
RenderMarkerDiamond ,
RenderMarkerUp ,
RenderMarkerDown ,
RenderMarkerLeft,
RenderMarkerRight,
RenderMarkerCross,
RenderMarkerPlus,
RenderMarkerAsterisk
};
ImPlotContext& gp = *GImPlot;
for (int i = 0; i < getter.Count; ++i) {
ImVec2 c = transformer(getter(i));
if (gp.BB_Plot.Contains(c))
marker_table[marker](DrawList, c, size, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, weight);
if (gp.BB_Plot.Contains(c))
marker_table[marker](DrawList, c, size, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, weight);
}
}
@ -767,7 +767,7 @@ inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& Dr
//-----------------------------------------------------------------------------
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 (FitThisFrame()) {
for (int i = 0; i < getter.Count; ++i) {
@ -783,7 +783,7 @@ inline void PlotEx(const char* label_id, Getter getter) {
case ImPlotScale_LinLin: RenderLineStrip(getter, TransformerLinLin(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LogLin: RenderLineStrip(getter, TransformerLogLin(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LinLog: RenderLineStrip(getter, TransformerLinLog(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LogLog: RenderLineStrip(getter, TransformerLogLog(), DrawList, s.LineWeight, col_line); break;
case ImPlotScale_LogLog: RenderLineStrip(getter, TransformerLogLog(), DrawList, s.LineWeight, col_line); break;
}
}
// render markers
@ -794,7 +794,7 @@ inline void PlotEx(const char* label_id, Getter getter) {
case ImPlotScale_LinLin: RenderMarkers(getter, TransformerLinLin(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LogLin: RenderMarkers(getter, TransformerLogLin(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LinLog: RenderMarkers(getter, TransformerLinLog(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LogLog: RenderMarkers(getter, TransformerLogLog(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
case ImPlotScale_LogLog: RenderMarkers(getter, TransformerLogLog(), DrawList, s.Marker, s.MarkerSize, s.RenderMarkerLine, col_line, s.MarkerWeight, s.RenderMarkerFill, col_fill); break;
}
}
EndItem();
@ -804,99 +804,108 @@ inline void PlotEx(const char* label_id, Getter getter) {
// float
void PlotLine(const char* label_id, const float* values, int count, int offset, int 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) {
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) {
GetterImVec2 getter(data, count, offset);
return PlotEx(label_id, getter);
return PlotLineEx(label_id, getter);
}
// double
void PlotLine(const char* label_id, const double* values, int count, int offset, int 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) {
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) {
GetterImPlotPoint getter(data, count, offset);
return PlotEx(label_id, getter);
return PlotLineEx(label_id, getter);
}
// custom
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);
return PlotEx(label_id, getter);
return PlotLineEx(label_id, getter);
}
//-----------------------------------------------------------------------------
// PLOT SCATTER
//-----------------------------------------------------------------------------
inline int PushScatterStyle() {
int vars = 1;
PushStyleVar(ImPlotStyleVar_LineWeight, 0);
if (GetStyle().Marker == ImPlotMarker_None) {
PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
vars++;
template <typename Getter>
inline void PlotScatterEx(const char* label_id, Getter getter) {
if (BeginItem(label_id, ImPlotCol_MarkerOutline)) {
if (FitThisFrame()) {
for (int i = 0; i < getter.Count; ++i) {
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
void PlotScatter(const char* label_id, const float* values, int count, int offset, int stride) {
int vars = PushScatterStyle();
PlotLine(label_id, values, count, offset, stride);
PopStyleVar(vars);
GetterYs<float> getter(values,count,offset,stride);
PlotScatterEx(label_id, getter);
}
void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
int vars = PushScatterStyle();
PlotLine(label_id, xs, ys, count, offset, stride);
PopStyleVar(vars);
GetterXsYs<float> getter(xs,ys,count,offset,stride);
return PlotScatterEx(label_id, getter);
}
void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset) {
int vars = PushScatterStyle();
PlotLine(label_id, data, count, offset);
PopStyleVar(vars);
GetterImVec2 getter(data, count, offset);
return PlotScatterEx(label_id, getter);
}
// double
void PlotScatter(const char* label_id, const double* values, int count, int offset, int stride) {
int vars = PushScatterStyle();
PlotLine(label_id, values, count, offset, stride);
PopStyleVar(vars);
GetterYs<double> getter(values,count,offset,stride);
PlotScatterEx(label_id, getter);
}
void PlotScatter(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
int vars = PushScatterStyle();
PlotLine(label_id, xs, ys, count, offset, stride);
PopStyleVar(vars);
GetterXsYs<double> getter(xs,ys,count,offset,stride);
return PlotScatterEx(label_id, getter);
}
void PlotScatter(const char* label_id, const ImPlotPoint* data, int count, int offset) {
int vars = PushScatterStyle();
PlotLine(label_id, data, count, offset);
PopStyleVar(vars);
GetterImPlotPoint getter(data, count, offset);
return PlotScatterEx(label_id, getter);
}
// custom
void PlotScatter(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset) {
int vars = PushScatterStyle();
PlotLine(label_id, getter, data, count, offset);
PopStyleVar(vars);
void PlotScatter(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
GetterFuncPtrImPlotPoint getter(getter_func,data, count, offset);
return PlotScatterEx(label_id, getter);
}
//-----------------------------------------------------------------------------
@ -922,7 +931,7 @@ inline void PlotShadedEx(const char* label_id, Getter1 getter1, Getter2 getter2)
case ImPlotScale_LinLin: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLinLin>(getter1,getter2,TransformerLinLin(), col), DrawList); break;
case ImPlotScale_LogLin: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLin>(getter1,getter2,TransformerLogLin(), col), DrawList); break;
case ImPlotScale_LinLog: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLinLog>(getter1,getter2,TransformerLinLog(), col), DrawList); break;
case ImPlotScale_LogLog: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLog>(getter1,getter2,TransformerLogLog(), col), DrawList); break;
case ImPlotScale_LogLog: RenderPrimitives(ShadedRenderer<Getter1,Getter2,TransformerLogLog>(getter1,getter2,TransformerLogLog(), col), DrawList); break;
}
}
EndItem();
@ -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 a1 = angle0 * 2 * IM_PI / 360.0f;
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];
a1 = a0 + 2 * IM_PI * percent;
if (item->Show) {
if (BeginItem(label_ids[i])) {
ImU32 col = ImGui::GetColorU32(GetCurrentItem()->Color);
if (percent < 0.5) {
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 + (a1 - a0) * 0.5f, a1, col);
}
EndItem();
}
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);
T angle = a0 + (a1 - a0) * 0.5f;
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);
}
a0 = a1;
@ -1354,7 +1363,7 @@ void PlotHeatmapEx(const char* label_id, const T* values, int rows, int cols, T
case ImPlotScale_LinLin: RenderHeatmap(TransformerLinLin(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
case ImPlotScale_LogLin: RenderHeatmap(TransformerLogLin(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
case ImPlotScale_LinLog: RenderHeatmap(TransformerLinLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
case ImPlotScale_LogLog: RenderHeatmap(TransformerLogLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
case ImPlotScale_LogLog: RenderHeatmap(TransformerLogLog(), DrawList, values, rows, cols, scale_min, scale_max, fmt, bounds_min, bounds_max); break;
}
EndItem();
}
@ -1470,7 +1479,7 @@ void PlotRectsEx(const char* label_id, Getter getter) {
case ImPlotScale_LinLin: RenderPrimitives(RectRenderer<Getter,TransformerLinLin>(getter, TransformerLinLin(), col), DrawList); break;
case ImPlotScale_LogLin: RenderPrimitives(RectRenderer<Getter,TransformerLogLin>(getter, TransformerLogLin(), col), DrawList); break;
case ImPlotScale_LinLog: RenderPrimitives(RectRenderer<Getter,TransformerLinLog>(getter, TransformerLinLog(), col), DrawList); break;
case ImPlotScale_LogLog: RenderPrimitives(RectRenderer<Getter,TransformerLogLog>(getter, TransformerLogLog(), col), DrawList); break;
case ImPlotScale_LogLog: RenderPrimitives(RectRenderer<Getter,TransformerLogLog>(getter, TransformerLogLog(), col), DrawList); break;
}
}
EndItem();
@ -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()!");
ImDrawList & DrawList = *GetPlotDrawList();
PushPlotClipRect();
ImU32 colTxt = ImGui::GetColorU32(ImGuiCol_Text);
ImU32 colTxt = GetStyleColorU32(ImPlotCol_InlayText);
if (vertical) {
ImVec2 ctr = CalcTextSizeVertical(text) * 0.5f;
ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) + ImVec2(-ctr.x, ctr.y) + pixel_offset;