1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05:00

Merge branch 'master' of https://github.com/ozlb/implot into ozlb-master

This commit is contained in:
Evan Pezent 2020-05-14 07:15:25 -05:00
commit daa689beb5
2 changed files with 153 additions and 132 deletions

View File

@ -315,7 +315,6 @@ struct ImPlotState {
}; };
struct ImNextPlotData { struct ImNextPlotData {
ImNextPlotData() : HasXRange{}, HasYRange{} {}
ImGuiCond XRangeCond; ImGuiCond XRangeCond;
ImGuiCond YRangeCond[MAX_Y_AXES]; ImGuiCond YRangeCond[MAX_Y_AXES];
bool HasXRange; bool HasXRange;
@ -375,7 +374,7 @@ struct ImPlotContext {
ImPlotRange ExtentsY[MAX_Y_AXES]; ImPlotRange ExtentsY[MAX_Y_AXES];
bool FitThisFrame; bool FitX; bool FitThisFrame; bool FitX;
bool FitY[MAX_Y_AXES] = {}; bool FitY[MAX_Y_AXES];
int VisibleItemCount; int VisibleItemCount;
// Render flags // Render flags
bool RenderX, RenderY[MAX_Y_AXES]; bool RenderX, RenderY[MAX_Y_AXES];
@ -488,8 +487,8 @@ struct Plt2PixLinLin {
ImVec2 operator()(const ImVec2& plt) { return (*this)(plt.x, plt.y); } ImVec2 operator()(const ImVec2& plt) { return (*this)(plt.x, plt.y); }
ImVec2 operator()(float x, float y) { ImVec2 operator()(float x, float y) {
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min), return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) }; gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
} }
int y_axis; int y_axis;
@ -502,8 +501,8 @@ struct Plt2PixLogLin {
ImVec2 operator()(float x, float y) { ImVec2 operator()(float x, float y) {
float t = log10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX; float t = log10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, t); x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, t);
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min), return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) }; gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
} }
int y_axis; int y_axis;
@ -516,8 +515,8 @@ struct Plt2PixLinLog {
ImVec2 operator()(float x, float y) { ImVec2 operator()(float x, float y) {
float t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis]; float t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, t); y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, t);
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min), return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) }; gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
} }
int y_axis; int y_axis;
@ -532,8 +531,8 @@ struct Plt2PixLogLog {
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, t); x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, t);
t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis]; t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, t); y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, t);
return { gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min), return ImVec2( gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min),
gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) }; gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min) );
} }
int y_axis; int y_axis;
@ -614,15 +613,16 @@ inline void GetTicks(const ImPlotRange& scale, int nMajor, int nMinor, bool logs
inline void LabelTicks(ImVector<ImTick> &ticks, bool scientific, ImGuiTextBuffer& buffer) { inline void LabelTicks(ImVector<ImTick> &ticks, bool scientific, ImGuiTextBuffer& buffer) {
buffer.Buf.resize(0); buffer.Buf.resize(0);
char temp[32]; char temp[32];
for (ImTick &tk : ticks) { for (int t = 0; t < ticks.Size; t++) {
if (tk.RenderLabel) { ImTick *tk = &ticks[t];
tk.TextOffset = buffer.size(); if (tk->RenderLabel) {
tk->TextOffset = buffer.size();
if (scientific) if (scientific)
sprintf(temp, "%.0e", tk.PlotPos); sprintf(temp, "%.0e", tk->PlotPos);
else else
sprintf(temp, "%g", tk.PlotPos); sprintf(temp, "%g", tk->PlotPos);
buffer.append(temp, temp + strlen(temp) + 1); buffer.append(temp, temp + strlen(temp) + 1);
tk.Size = ImGui::CalcTextSize(buffer.Buf.Data + tk.TextOffset); tk->Size = ImGui::CalcTextSize(buffer.Buf.Data + tk->TextOffset);
} }
} }
} }
@ -667,7 +667,7 @@ void UpdateAxisColor(int axis_flag, ImPlotContext::AxisColor* col) {
const ImVec4 col_Axis = gp.Style.Colors[axis_flag].w == -1 ? ImGui::GetStyle().Colors[ImGuiCol_Text] * ImVec4(1, 1, 1, 0.25f) : gp.Style.Colors[axis_flag]; const ImVec4 col_Axis = gp.Style.Colors[axis_flag].w == -1 ? ImGui::GetStyle().Colors[ImGuiCol_Text] * ImVec4(1, 1, 1, 0.25f) : gp.Style.Colors[axis_flag];
col->Major = ImGui::GetColorU32(col_Axis); col->Major = ImGui::GetColorU32(col_Axis);
col->Minor = ImGui::GetColorU32(col_Axis * ImVec4(1, 1, 1, 0.25f)); col->Minor = ImGui::GetColorU32(col_Axis * ImVec4(1, 1, 1, 0.25f));
col->Txt = ImGui::GetColorU32({col_Axis.x, col_Axis.y, col_Axis.z, 1}); col->Txt = ImGui::GetColorU32(ImVec4(col_Axis.x, col_Axis.y, col_Axis.z, 1));
} }
ImRect GetAxisScale(int y_axis, float tx, float ty, float zoom_rate) { ImRect GetAxisScale(int y_axis, float tx, float ty, float zoom_rate) {
@ -901,8 +901,9 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
for (int i = 0; i < MAX_Y_AXES; i++) { for (int i = 0; i < MAX_Y_AXES; i++) {
if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_TickLabels)) { if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_TickLabels)) {
LabelTicks(gp.YTicks[i], HasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_Scientific), gp.YTickLabels[i]); LabelTicks(gp.YTicks[i], HasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_Scientific), gp.YTickLabels[i]);
for (ImTick &yt : gp.YTicks[i]) { for (int t = 0; t < gp.YTicks[i].Size; t++) {
max_label_width[i] = yt.Size.x > max_label_width[i] ? yt.Size.x : max_label_width[i]; ImTick *yt = &gp.YTicks[i][t];
max_label_width[i] = yt->Size.x > max_label_width[i] ? yt->Size.x : max_label_width[i];
} }
} }
} }
@ -936,15 +937,15 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
(gp.AxisLabelReference[1] + y_axis_pad(1) + 6); (gp.AxisLabelReference[1] + y_axis_pad(1) + 6);
ImRect yAxisRegion_bb[MAX_Y_AXES]; ImRect yAxisRegion_bb[MAX_Y_AXES];
yAxisRegion_bb[0] = ImRect({gp.BB_Frame.Min.x, gp.BB_Grid.Min.y}, {gp.BB_Grid.Min.x + 6, gp.BB_Grid.Max.y - 10}); yAxisRegion_bb[0] = ImRect(ImVec2(gp.BB_Frame.Min.x, gp.BB_Grid.Min.y), ImVec2(gp.BB_Grid.Min.x + 6, gp.BB_Grid.Max.y - 10));
// The auxiliary y axes are off to the right of the BB grid. // The auxiliary y axes are off to the right of the BB grid.
yAxisRegion_bb[1] = ImRect({gp.BB_Grid.Max.x - 6, gp.BB_Grid.Min.y}, yAxisRegion_bb[1] = ImRect(ImVec2(gp.BB_Grid.Max.x - 6, gp.BB_Grid.Min.y),
gp.BB_Grid.Max + ImVec2(y_axis_pad(1), 0)); gp.BB_Grid.Max + ImVec2(y_axis_pad(1), 0));
yAxisRegion_bb[2] = ImRect({gp.AxisLabelReference[2] - 6, gp.BB_Grid.Min.y}, yAxisRegion_bb[2] = ImRect(ImVec2(gp.AxisLabelReference[2] - 6, gp.BB_Grid.Min.y),
yAxisRegion_bb[1].Max + ImVec2(y_axis_pad(2), 0)); yAxisRegion_bb[1].Max + ImVec2(y_axis_pad(2), 0));
ImRect centralRegion({gp.BB_Grid.Min.x + 6, gp.BB_Grid.Min.y}, ImRect centralRegion(ImVec2(gp.BB_Grid.Min.x + 6, gp.BB_Grid.Min.y),
{gp.BB_Grid.Max.x - 6, gp.BB_Grid.Max.y}); ImVec2(gp.BB_Grid.Max.x - 6, gp.BB_Grid.Max.y));
const bool hov_y_axis_region[MAX_Y_AXES] = { const bool hov_y_axis_region[MAX_Y_AXES] = {
y[0].present && (yAxisRegion_bb[0].Contains(IO.MousePos) || centralRegion.Contains(IO.MousePos)), y[0].present && (yAxisRegion_bb[0].Contains(IO.MousePos) || centralRegion.Contains(IO.MousePos)),
@ -1209,26 +1210,34 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// transform ticks // transform ticks
if (gp.RenderX) { if (gp.RenderX) {
for (ImTick& xt : gp.XTicks) for (int t = 0; t < gp.XTicks.Size; t++) {
xt.PixelPos = PlotToPixels((float)xt.PlotPos, 0, 0).x; ImTick *xt = &gp.XTicks[t];
xt->PixelPos = PlotToPixels((float)xt->PlotPos, 0, 0).x;
}
} }
for (int i = 0; i < MAX_Y_AXES; i++) { for (int i = 0; i < MAX_Y_AXES; i++) {
if (gp.RenderY[i]) { if (gp.RenderY[i]) {
for (ImTick& yt : gp.YTicks[i]) for (int t = 0; t < gp.YTicks[i].Size; t++) {
yt.PixelPos = PlotToPixels(0, (float)yt.PlotPos, i).y; ImTick *yt = &gp.YTicks[i][t];
yt->PixelPos = PlotToPixels(0, (float)yt->PlotPos, i).y;
}
} }
} }
// render grid // render grid
if (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_GridLines)) { if (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_GridLines)) {
for (ImTick &xt : gp.XTicks) for (int t = 0; t < gp.XTicks.Size; t++) {
DrawList.AddLine({xt.PixelPos, gp.BB_Grid.Min.y}, {xt.PixelPos, gp.BB_Grid.Max.y}, xt.Major ? gp.Col_X.Major : gp.Col_X.Minor, 1); ImTick *xt = &gp.XTicks[t];
DrawList.AddLine(ImVec2(xt->PixelPos, gp.BB_Grid.Min.y), ImVec2(xt->PixelPos, gp.BB_Grid.Max.y), xt->Major ? gp.Col_X.Major : gp.Col_X.Minor, 1);
}
} }
for (int i = 0; i < MAX_Y_AXES; i++) { for (int i = 0; i < MAX_Y_AXES; i++) {
if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_GridLines)) { if (y[i].present && HasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_GridLines)) {
for (ImTick &yt : gp.YTicks[i]) for (int t = 0; t < gp.YTicks[i].Size; t++) {
DrawList.AddLine({gp.BB_Grid.Min.x, yt.PixelPos}, {gp.BB_Grid.Max.x, yt.PixelPos}, yt.Major ? gp.Col_Y[i].Major : gp.Col_Y[i].Minor, 1); ImTick *yt = &gp.YTicks[i][t];
DrawList.AddLine(ImVec2(gp.BB_Grid.Min.x, yt->PixelPos), ImVec2(gp.BB_Grid.Max.x, yt->PixelPos), yt->Major ? gp.Col_Y[i].Major : gp.Col_Y[i].Minor, 1);
}
} }
} }
@ -1242,9 +1251,10 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
// render labels // render labels
if (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_TickLabels)) { if (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_TickLabels)) {
ImGui::PushClipRect(gp.BB_Frame.Min, gp.BB_Frame.Max, true); ImGui::PushClipRect(gp.BB_Frame.Min, gp.BB_Frame.Max, true);
for (ImTick &xt : gp.XTicks) { for (int t = 0; t < gp.XTicks.Size; t++) {
if (xt.RenderLabel && xt.PixelPos >= gp.BB_Grid.Min.x - 1 && xt.PixelPos <= gp.BB_Grid.Max.x + 1) ImTick *xt = &gp.XTicks[t];
DrawList.AddText({xt.PixelPos - xt.Size.x * 0.5f, gp.BB_Grid.Max.y + txt_off}, gp.Col_X.Txt, gp.XTickLabels.Buf.Data + xt.TextOffset); if (xt->RenderLabel && xt->PixelPos >= gp.BB_Grid.Min.x - 1 && xt->PixelPos <= gp.BB_Grid.Max.x + 1)
DrawList.AddText(ImVec2(xt->PixelPos - xt->Size.x * 0.5f, gp.BB_Grid.Max.y + txt_off), gp.Col_X.Txt, gp.XTickLabels.Buf.Data + xt->TextOffset);
} }
ImGui::PopClipRect(); ImGui::PopClipRect();
} }
@ -1262,10 +1272,11 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
((i == 0) ? ((i == 0) ?
(-txt_off - max_label_width[0]) : (-txt_off - max_label_width[0]) :
txt_off); txt_off);
for (ImTick &yt : gp.YTicks[i]) { for (int t = 0; t < gp.YTicks[i].Size; t++) {
if (yt.RenderLabel && yt.PixelPos >= gp.BB_Grid.Min.y - 1 && yt.PixelPos <= gp.BB_Grid.Max.y + 1) { ImTick *yt = &gp.YTicks[i][t];
ImVec2 start(x_start, yt.PixelPos - 0.5f * yt.Size.y); if (yt->RenderLabel && yt->PixelPos >= gp.BB_Grid.Min.y - 1 && yt->PixelPos <= gp.BB_Grid.Max.y + 1) {
DrawList.AddText(start, gp.Col_Y[i].Txt, gp.YTickLabels[i].Buf.Data + yt.TextOffset); ImVec2 start(x_start, yt->PixelPos - 0.5f * yt->Size.y);
DrawList.AddText(start, gp.Col_Y[i].Txt, gp.YTickLabels[i].Buf.Data + yt->TextOffset);
} }
} }
} }
@ -1471,12 +1482,14 @@ void EndPlot() {
// render ticks // render ticks
PushPlotClipRect(); PushPlotClipRect();
if (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_TickMarks)) { if (HasFlag(plot.XAxis.Flags, ImPlotAxisFlags_TickMarks)) {
for (ImTick &xt : gp.XTicks) for (int t = 0; t < gp.XTicks.Size; t++) {
DrawList.AddLine({xt.PixelPos, gp.BB_Grid.Max.y},{xt.PixelPos, gp.BB_Grid.Max.y - (xt.Major ? 10.0f : 5.0f)}, gp.Col_Border, 1); ImTick *xt = &gp.XTicks[t];
DrawList.AddLine(ImVec2(xt->PixelPos, gp.BB_Grid.Max.y),ImVec2(xt->PixelPos, gp.BB_Grid.Max.y - (xt->Major ? 10.0f : 5.0f)), gp.Col_Border, 1);
}
} }
PopPlotClipRect(); PopPlotClipRect();
ImGui::PushClipRect(gp.BB_Grid.Min, {gp.BB_Frame.Max.x, gp.BB_Grid.Max.y}, true); ImGui::PushClipRect(gp.BB_Grid.Min, ImVec2(gp.BB_Frame.Max.x, gp.BB_Grid.Max.y), true);
int axis_count = 0; int axis_count = 0;
for (int i = 0; i < MAX_Y_AXES; i++) { for (int i = 0; i < MAX_Y_AXES; i++) {
if (!y[i].present) { continue; } if (!y[i].present) { continue; }
@ -1488,12 +1501,13 @@ void EndPlot() {
float direction = (i == 0) ? 1.0f : -1.0f; float direction = (i == 0) ? 1.0f : -1.0f;
bool no_major = axis_count >= 3; bool no_major = axis_count >= 3;
for (ImTick &yt : gp.YTicks[i]) { for (int t = 0; t < gp.YTicks[i].Size; t++) {
ImVec2 start = ImVec2(x_start, yt.PixelPos); ImTick *yt = &gp.YTicks[i][t];
ImVec2 start = ImVec2(x_start, yt->PixelPos);
DrawList.AddLine( DrawList.AddLine(
start, start,
start + ImVec2(direction * ((!no_major && yt.Major) ? 10.0f : 5.0f), 0), start + ImVec2(direction * ((!no_major && yt->Major) ? 10.0f : 5.0f), 0),
gp.Col_Border, 1); gp.Col_Border, 1);
} }
@ -1832,16 +1846,16 @@ void SetPalette(const ImVec4* colors, int num_colors) {
/// Returns the next unused default plot color /// Returns the next unused default plot color
void RestorePalette() { void RestorePalette() {
static ImVec4 default_colors[10] = { static ImVec4 default_colors[10] = {
{(0.0F), (0.7490196228F), (1.0F), (1.0F)}, // Blues::DeepSkyBlue, ImVec4((0.0F), (0.7490196228F), (1.0F), (1.0F)), // Blues::DeepSkyBlue,
{(1.0F), (0.0F), (0.0F), (1.0F)}, // Reds::Red, ImVec4((1.0F), (0.0F), (0.0F), (1.0F)), // Reds::Red,
{(0.4980392158F), (1.0F), (0.0F), (1.0F)}, // Greens::Chartreuse, ImVec4((0.4980392158F), (1.0F), (0.0F), (1.0F)), // Greens::Chartreuse,
{(1.0F), (1.0F), (0.0F), (1.0F)}, // Yellows::Yellow, ImVec4((1.0F), (1.0F), (0.0F), (1.0F)), // Yellows::Yellow,
{(0.0F), (1.0F), (1.0F), (1.0F)}, // Cyans::Cyan, ImVec4((0.0F), (1.0F), (1.0F), (1.0F)), // Cyans::Cyan,
{(1.0F), (0.6470588446F), (0.0F), (1.0F)}, // Oranges::Orange, ImVec4((1.0F), (0.6470588446F), (0.0F), (1.0F)), // Oranges::Orange,
{(1.0F), (0.0F), (1.0F), (1.0F)}, // Purples::Magenta, ImVec4((1.0F), (0.0F), (1.0F), (1.0F)), // Purples::Magenta,
{(0.5411764979F), (0.1686274558F), (0.8862745166F), (1.0F)}, // Purples::BlueViolet, ImVec4((0.5411764979F), (0.1686274558F), (0.8862745166F), (1.0F)), // Purples::BlueViolet,
{(0.5f), (0.5f), (0.5f), (1.0F)}, // Grays::Gray50, ImVec4((0.5f), (0.5f), (0.5f), (1.0F)), // Grays::Gray50,
{(0.8235294223F), (0.7058823705F), (0.5490196347F), (1.0F)} // Browns::Tan ImVec4((0.8235294223F), (0.7058823705F), (0.5490196347F), (1.0F)) // Browns::Tan
}; };
SetPalette(default_colors, 10); SetPalette(default_colors, 10);
} }
@ -1945,51 +1959,51 @@ inline void MarkerGeneral(ImDrawList& DrawList, ImVec2* points, int n, const ImV
} }
inline void MarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[10] = {{1.0f, 0.0f}, ImVec2 marker[10] = {ImVec2(1.0f, 0.0f),
{0.809017f, 0.58778524f}, ImVec2(0.809017f, 0.58778524f),
{0.30901697f, 0.95105654f}, ImVec2(0.30901697f, 0.95105654f),
{-0.30901703f, 0.9510565f}, ImVec2(-0.30901703f, 0.9510565f),
{-0.80901706f, 0.5877852f}, ImVec2(-0.80901706f, 0.5877852f),
{-1.0f, 0.0f}, ImVec2(-1.0f, 0.0f),
{-0.80901694f, -0.58778536f}, ImVec2(-0.80901694f, -0.58778536f),
{-0.3090171f, -0.9510565f}, ImVec2(-0.3090171f, -0.9510565f),
{0.30901712f, -0.9510565f}, ImVec2(0.30901712f, -0.9510565f),
{0.80901694f, -0.5877853f}}; ImVec2(0.80901694f, -0.5877853f)};
MarkerGeneral(DrawList, marker, 10, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 10, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerDiamond(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerDiamond(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}}; ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)};
MarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerSquare(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerSquare(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{SQRT_1_2,SQRT_1_2},{SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,SQRT_1_2}}; ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
MarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerUp(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerUp(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{SQRT_3_2,0.5f},{0,-1},{-SQRT_3_2,0.5f}}; ImVec2 marker[3] = {ImVec2(SQRT_3_2,0.5f),ImVec2(0,-1),ImVec2(-SQRT_3_2,0.5f)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerDown(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerDown(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{SQRT_3_2,-0.5f},{0,1},{-SQRT_3_2,-0.5f}}; ImVec2 marker[3] = {ImVec2(SQRT_3_2,-0.5f),ImVec2(0,1),ImVec2(-SQRT_3_2,-0.5f)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerLeft(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerLeft(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{-1,0}, {0.5, SQRT_3_2}, {0.5, -SQRT_3_2}}; ImVec2 marker[3] = {ImVec2(-1,0), ImVec2(0.5, SQRT_3_2), ImVec2(0.5, -SQRT_3_2)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerRight(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerRight(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[3] = {{1,0}, {-0.5, SQRT_3_2}, {-0.5, -SQRT_3_2}}; ImVec2 marker[3] = {ImVec2(1,0), ImVec2(-0.5, SQRT_3_2), ImVec2(-0.5, -SQRT_3_2)};
MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); MarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight);
} }
inline void MarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[6] = {{SQRT_3_2, 0.5f}, {0, -1}, {-SQRT_3_2, 0.5f}, {SQRT_3_2, -0.5f}, {0, 1}, {-SQRT_3_2, -0.5f}}; ImVec2 marker[6] = {ImVec2(SQRT_3_2, 0.5f), ImVec2(0, -1), ImVec2(-SQRT_3_2, 0.5f), ImVec2(SQRT_3_2, -0.5f), ImVec2(0, 1), ImVec2(-SQRT_3_2, -0.5f)};
TransformMarker(marker, 6, c, s); TransformMarker(marker, 6, c, s);
DrawList.AddLine(marker[0], marker[5], col_outline, weight); DrawList.AddLine(marker[0], marker[5], col_outline, weight);
DrawList.AddLine(marker[1], marker[4], col_outline, weight); DrawList.AddLine(marker[1], marker[4], col_outline, weight);
@ -1997,14 +2011,14 @@ inline void MarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool
} }
inline void MarkerPlus(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerPlus(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}}; ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)};
TransformMarker(marker, 4, c, s); TransformMarker(marker, 4, c, s);
DrawList.AddLine(marker[0], marker[2], col_outline, weight); DrawList.AddLine(marker[0], marker[2], col_outline, weight);
DrawList.AddLine(marker[1], marker[3], col_outline, weight); DrawList.AddLine(marker[1], marker[3], col_outline, weight);
} }
inline void MarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { inline void MarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) {
ImVec2 marker[4] = {{SQRT_1_2,SQRT_1_2},{SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,-SQRT_1_2},{-SQRT_1_2,SQRT_1_2}}; ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)};
TransformMarker(marker, 4, c, s); TransformMarker(marker, 4, c, s);
DrawList.AddLine(marker[0], marker[2], col_outline, weight); DrawList.AddLine(marker[0], marker[2], col_outline, weight);
DrawList.AddLine(marker[1], marker[3], col_outline, weight); DrawList.AddLine(marker[1], marker[3], col_outline, weight);
@ -2544,7 +2558,7 @@ void Text(const char* text, float x, float y, bool vertical, const ImVec2& pixel
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Text() Needs to be called between BeginPlot() and EndPlot()!"); IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Text() Needs to be called between BeginPlot() and EndPlot()!");
ImDrawList & DrawList = *ImGui::GetWindowDrawList(); ImDrawList & DrawList = *ImGui::GetWindowDrawList();
PushPlotClipRect(); PushPlotClipRect();
ImVec2 pos = PlotToPixels({x,y}) + pixel_offset; ImVec2 pos = PlotToPixels(ImVec2(x,y)) + pixel_offset;
if (vertical) if (vertical)
AddTextVertical(&DrawList, text, pos, gp.Col_Txt); AddTextVertical(&DrawList, text, pos, gp.Col_Txt);
else else

View File

@ -43,10 +43,14 @@ float RandomRange( float min, float max ) {
} }
struct ScrollingData { struct ScrollingData {
int MaxSize = 1000; int MaxSize;
int Offset = 0; int Offset;
ImVector<ImVec2> Data; ImVector<ImVec2> Data;
ScrollingData() { Data.reserve(MaxSize); } ScrollingData() {
MaxSize = 1000;
Offset = 0;
Data.reserve(MaxSize);
}
void AddPoint(float x, float y) { void AddPoint(float x, float y) {
if (Data.size() < MaxSize) if (Data.size() < MaxSize)
Data.push_back(ImVec2(x,y)); Data.push_back(ImVec2(x,y));
@ -64,9 +68,12 @@ struct ScrollingData {
}; };
struct RollingData { struct RollingData {
float Span = 10.0f; float Span;
ImVector<ImVec2> Data; ImVector<ImVec2> Data;
RollingData() { Data.reserve(1000); } RollingData() {
Span = 10.0f;
Data.reserve(1000);
}
void AddPoint(float x, float y) { void AddPoint(float x, float y) {
float xmod = fmodf(x, Span); float xmod = fmodf(x, Span);
if (!Data.empty() && xmod < Data.back().x) if (!Data.empty() && xmod < Data.back().x)
@ -147,7 +154,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];
} }
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", {-1,300})) { if (ImPlot::BeginPlot("Line Plot", "x", "f(x)", ImVec2(-1,300))) {
ImPlot::Plot("sin(50*x)", xs1, ys1, 1001); ImPlot::Plot("sin(50*x)", xs1, ys1, 1001);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::Plot("x^2", xs2, ys2, 11); ImPlot::Plot("x^2", xs2, ys2, 11);
@ -168,14 +175,14 @@ void ShowDemoWindow(bool* p_open) {
xs2[i] = 0.25f + 0.2f * ((float)rand() / (float)RAND_MAX); xs2[i] = 0.25f + 0.2f * ((float)rand() / (float)RAND_MAX);
ys2[i] = 0.75f + 0.2f * ((float)rand() / (float)RAND_MAX); ys2[i] = 0.75f + 0.2f * ((float)rand() / (float)RAND_MAX);
} }
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, {-1,300})) { if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL, ImVec2(-1,300))) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Cross);
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3); ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3);
ImPlot::Plot("Data 1", xs1, ys1, 100); ImPlot::Plot("Data 1", xs1, ys1, 100);
ImPlot::PopStyleVar(2); ImPlot::PopStyleVar(2);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle); ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4{1,0,0,0.25f}); ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f));
ImPlot::Plot("Data 2", xs2, ys2, 50); ImPlot::Plot("Data 2", xs2, ys2, 50);
ImPlot::PopStyleColor(); ImPlot::PopStyleColor();
ImPlot::PopStyleVar(2); ImPlot::PopStyleVar(2);
@ -190,7 +197,7 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::SetNextPlotLimits(0, 110, -0.5f, 9.5f, ImGuiCond_Always); ImPlot::SetNextPlotLimits(0, 110, -0.5f, 9.5f, ImGuiCond_Always);
else else
ImPlot::SetNextPlotLimits(-0.5f, 9.5f, 0, 110, ImGuiCond_Always); ImPlot::SetNextPlotLimits(-0.5f, 9.5f, 0, 110, ImGuiCond_Always);
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", {-1, 300})) { if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", ImVec2(-1, 300))) {
static float midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90}; static float midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90};
static float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100}; static float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100};
static float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; static float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95};
@ -246,11 +253,11 @@ void ShowDemoWindow(bool* p_open) {
ImGui::SameLine(); ImGui::SameLine();
static ImVec4 YlOrRd[5] = { static ImVec4 YlOrRd[5] = {
{1.0000f, 1.0000f, 0.8000f, 1.0f}, ImVec4(1.0000f, 1.0000f, 0.8000f, 1.0f),
{0.9961f, 0.8510f, 0.4627f, 1.0f}, ImVec4(0.9961f, 0.8510f, 0.4627f, 1.0f),
{0.9961f, 0.6314f, 0.2627f, 1.0f}, ImVec4(0.9961f, 0.6314f, 0.2627f, 1.0f),
{0.9882f, 0.3059f, 0.1647f, 1.0f}, ImVec4(0.9882f, 0.3059f, 0.1647f, 1.0f),
{0.7412f, 0.0f, 0.1490f, 1.0f}, ImVec4(0.7412f, 0.0f, 0.1490f, 1.0f),
}; };
ImPlot::SetPalette(YlOrRd, 5); ImPlot::SetPalette(YlOrRd, 5);
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
@ -280,13 +287,13 @@ void ShowDemoWindow(bool* p_open) {
} }
ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always); ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
static int rt_axis = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels; static int rt_axis = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) { if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
ImPlot::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float)); ImPlot::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float));
ImPlot::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float)); ImPlot::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float));
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
ImPlot::SetNextPlotLimitsX(0, 10, ImGuiCond_Always); ImPlot::SetNextPlotLimitsX(0, 10, ImGuiCond_Always);
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) { if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
ImPlot::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float)); ImPlot::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float));
ImPlot::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float)); ImPlot::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float));
ImPlot::EndPlot(); ImPlot::EndPlot();
@ -536,20 +543,20 @@ void ShowDemoWindow(bool* p_open) {
} }
ImGui::BulletText("Drag data items from the left column onto the plot."); ImGui::BulletText("Drag data items from the left column onto the plot.");
ImGui::BeginGroup(); ImGui::BeginGroup();
if (ImGui::Button("Clear", {100, 0})) { if (ImGui::Button("Clear", ImVec2(100, 0))) {
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
show[i] = false; show[i] = false;
data[i].Data.shrink(0); data[i].Data.shrink(0);
data[i].Offset = 0; data[i].Offset = 0;
} }
} }
if (ImGui::Button(paused ? "Resume" : "Pause", {100,0})) if (ImGui::Button(paused ? "Resume" : "Pause", ImVec2(100,0)))
paused = !paused; paused = !paused;
ImGui::Separator(); ImGui::Separator();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
char label[8]; char label[8];
sprintf(label, "data_%d", i); sprintf(label, "data_%d", i);
ImGui::Selectable(label, false, 0, {100, 0}); ImGui::Selectable(label, false, 0, ImVec2(100, 0));
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) { if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
ImGui::SetDragDropPayload("DND_PLOT", &i, sizeof(int)); ImGui::SetDragDropPayload("DND_PLOT", &i, sizeof(int));
ImGui::TextUnformatted(label); ImGui::TextUnformatted(label);
@ -603,13 +610,13 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Text("you can drag analog signals over the rising/falling digital edge."); ImGui::Text("you can drag analog signals over the rising/falling digital edge.");
ImGui::Unindent(); ImGui::Unindent();
ImGui::BeginGroup(); ImGui::BeginGroup();
if (ImGui::Button("Clear", {100, 0})) { if (ImGui::Button("Clear", ImVec2(100, 0))) {
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i)
showDigital[i] = false; showDigital[i] = false;
for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i) for (int i = 0; i < K_PLOT_ANALOG_CH_COUNT; ++i)
showAnalog[i] = false; showAnalog[i] = false;
} }
if (ImGui::Button(paused ? "Resume" : "Pause", {100,0})) if (ImGui::Button(paused ? "Resume" : "Pause", ImVec2(100,0)))
paused = !paused; paused = !paused;
ImGui::SetNextItemWidth(100); ImGui::SetNextItemWidth(100);
static float bitHeight = 8; static float bitHeight = 8;
@ -722,19 +729,19 @@ void ShowDemoWindow(bool* p_open) {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Styles")) { if (ImGui::CollapsingHeader("Custom Styles")) {
static ImVec4 my_palette[3] = { static ImVec4 my_palette[3] = {
{0.000f, 0.980f, 0.604f, 1.0f}, ImVec4(0.000f, 0.980f, 0.604f, 1.0f),
{0.996f, 0.278f, 0.380f, 1.0f}, ImVec4(0.996f, 0.278f, 0.380f, 1.0f),
{(0.1176470593F), (0.5647059083F), (1.0F), (1.0F)}, ImVec4(0.1176470593f, 0.5647059083f, 1.0f, 1.0f),
}; };
ImPlot::SetPalette(my_palette, 3); ImPlot::SetPalette(my_palette, 3);
ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(32,51,77,255)); ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(32,51,77,255));
ImPlot::PushStyleColor(ImPlotCol_PlotBg, {0,0,0,0}); ImPlot::PushStyleColor(ImPlotCol_PlotBg, ImVec4(0,0,0,0));
ImPlot::PushStyleColor(ImPlotCol_PlotBorder, {0,0,0,0}); ImPlot::PushStyleColor(ImPlotCol_PlotBorder, ImVec4(0,0,0,0));
ImPlot::PushStyleColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192)); ImPlot::PushStyleColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192));
ImPlot::PushStyleColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192)); ImPlot::PushStyleColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192));
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2); ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2);
ImPlot::SetNextPlotLimits(-0.5f, 9.5f, -0.5f, 9.5f); ImPlot::SetNextPlotLimits(-0.5f, 9.5f, -0.5f, 9.5f);
if (ImPlot::BeginPlot("##Custom", NULL, NULL, {-1,300}, ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) { if (ImPlot::BeginPlot("##Custom", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) {
float lin[10] = {8,8,9,7,8,8,8,9,7,8}; float lin[10] = {8,8,9,7,8,8,8,9,7,8};
float bar[10] = {1,2,5,3,4,1,2,5,3,4}; float bar[10] = {1,2,5,3,4,1,2,5,3,4};
float dot[10] = {7,6,6,7,8,5,6,5,8,7}; float dot[10] = {7,6,6,7,8,5,6,5,8,7};
@ -752,10 +759,10 @@ void ShowDemoWindow(bool* p_open) {
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Rendering")) { if (ImGui::CollapsingHeader("Custom Rendering")) {
if (ImPlot::BeginPlot("##CustomRend",NULL,NULL,{-1,300})) { if (ImPlot::BeginPlot("##CustomRend",NULL,NULL,ImVec2(-1,300))) {
ImVec2 cntr = ImPlot::PlotToPixels({0.5f, 0.5f}); ImVec2 cntr = ImPlot::PlotToPixels(ImVec2(0.5f, 0.5f));
ImVec2 rmin = ImPlot::PlotToPixels({0.25f, 0.75f}); ImVec2 rmin = ImPlot::PlotToPixels(ImVec2(0.25f, 0.75f));
ImVec2 rmax = ImPlot::PlotToPixels({0.75f, 0.25f}); ImVec2 rmax = ImPlot::PlotToPixels(ImVec2(0.75f, 0.25f));
ImPlot::PushPlotClipRect(); ImPlot::PushPlotClipRect();
ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20); ImGui::GetWindowDrawList()->AddCircleFilled(cntr,20,IM_COL32(255,255,0,255),20);
ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255)); ImGui::GetWindowDrawList()->AddRect(rmin, rmax, IM_COL32(128,0,255,255));
@ -770,7 +777,7 @@ void ShowDemoWindow(bool* p_open) {
ImGui::BulletText("Make sure VSync is disabled."); ImGui::BulletText("Make sure VSync is disabled.");
ImGui::BulletText("%d lines with %d points each @ %.3f FPS.",n_items,1000,ImGui::GetIO().Framerate); ImGui::BulletText("%d lines with %d points each @ %.3f FPS.",n_items,1000,ImGui::GetIO().Framerate);
SetNextPlotLimits(0,1,0,1, ImGuiCond_Always); SetNextPlotLimits(0,1,0,1, ImGuiCond_Always);
if (ImPlot::BeginPlot("##Bench",NULL,NULL,{-1,300},ImPlotFlags_Default | ImPlotFlags_NoChild)) { if (ImPlot::BeginPlot("##Bench",NULL,NULL,ImVec2(-1,300),ImPlotFlags_Default | ImPlotFlags_NoChild)) {
char buff[16]; char buff[16];
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
sprintf(buff, "item_%d",i); sprintf(buff, "item_%d",i);