mirror of
https://github.com/gwm17/implot.git
synced 2024-11-26 20:28:50 -05:00
Support multiple Y axes simultaneously
This allows up to 3 Y axes to be used, one on the left side, and up to 2 on the right. To use multiple axes, one of the `ImPlotFlags_Y2Axis` or `ImPlotFlags_Y3Axis` must be passed to `BeginPlot`. Then, before each Plot call, SetPlotYAxis may be used to set that plot on an alternate axis. An extra line and ticks are rendered off to the right if all 3 axes are configured (although those ticks are always only 5 long, regardless of major status). Each of the axes, when present, has a (possibly invisible if ticks and labels are disabled) hit target that can be used to scroll and scale that axis independently. Some other changes were required to make this happen: * Queries are now only in pixel coordinates * ImPlotRange has been renamed to ImPlotBounds (and correspondingly GetPlotRange is now GetPlotBounds) * All APIs which allow querying values in plot coordinates now have an optional "y_axis" argument, which can be -1 to use the currently selected axis, or non-negative to pick a specific axes. * BeginPlot used to lock all flags on the first call. Now it only locks the axis flags, and not the primary plot flags. * The mouseover text now renders the 2nd and 3rd axis in parenthesis.
This commit is contained in:
parent
59bc426aad
commit
5eb4b71384
1069
implot.cpp
1069
implot.cpp
File diff suppressed because it is too large
Load Diff
70
implot.h
70
implot.h
|
@ -41,12 +41,13 @@ enum ImPlotFlags_ {
|
||||||
ImPlotFlags_Legend = 1 << 1, // a legend will be displayed in the top-left
|
ImPlotFlags_Legend = 1 << 1, // a legend will be displayed in the top-left
|
||||||
ImPlotFlags_Highlight = 1 << 2, // plot items will be highlighted when their legend entry is hovered
|
ImPlotFlags_Highlight = 1 << 2, // plot items will be highlighted when their legend entry is hovered
|
||||||
ImPlotFlags_Selection = 1 << 3, // the user will be able to box-select with right-mouse
|
ImPlotFlags_Selection = 1 << 3, // the user will be able to box-select with right-mouse
|
||||||
ImPlotFlags_PixelQuery = 1 << 4, // query ranges will not change their pixel position if the plot is scrolled/zoomed
|
ImPlotFlags_ContextMenu = 1 << 4, // the user will be able to open a context menu with double-right click
|
||||||
ImPlotFlags_ContextMenu = 1 << 5, // the user will be able to open a context menu with double-right click
|
ImPlotFlags_Crosshairs = 1 << 5, // the default mouse cursor will be replaced with a crosshair when hovered
|
||||||
ImPlotFlags_Crosshairs = 1 << 6, // the default mouse cursor will be replaced with a crosshair when hovered
|
ImPlotFlags_CullData = 1 << 6, // plot data outside the plot area will be culled from rendering
|
||||||
ImPlotFlags_CullData = 1 << 7, // plot data outside the plot area will be culled from rendering
|
ImPlotFlags_AntiAliased = 1 << 7, // lines and fills will be anti-aliased (not recommended)
|
||||||
ImPlotFlags_AntiAliased = 1 << 8, // lines and fills will be anti-aliased (not recommended)
|
ImPlotFlags_NoChild = 1 << 8, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications)
|
||||||
ImPlotFlags_NoChild = 1 << 9, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications)
|
ImPlotFlags_Y2Axis = 1 << 9, // enable a second y axis
|
||||||
|
ImPlotFlags_Y3Axis = 1 << 10, // enable a third y axis
|
||||||
ImPlotFlags_Default = ImPlotFlags_MousePos | ImPlotFlags_Legend | ImPlotFlags_Highlight | ImPlotFlags_Selection | ImPlotFlags_ContextMenu | ImPlotFlags_CullData
|
ImPlotFlags_Default = ImPlotFlags_MousePos | ImPlotFlags_Legend | ImPlotFlags_Highlight | ImPlotFlags_Selection | ImPlotFlags_ContextMenu | ImPlotFlags_CullData
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,7 +62,8 @@ enum ImAxisFlags_ {
|
||||||
ImAxisFlags_Adaptive = 1 << 6, // grid divisions will adapt to the current pixel size the axis
|
ImAxisFlags_Adaptive = 1 << 6, // grid divisions will adapt to the current pixel size the axis
|
||||||
ImAxisFlags_LogScale = 1 << 7, // a logartithmic (base 10) axis scale will be used
|
ImAxisFlags_LogScale = 1 << 7, // a logartithmic (base 10) axis scale will be used
|
||||||
ImAxisFlags_Scientific = 1 << 8, // scientific notation will be used for tick labels if displayed (WIP, not very good yet)
|
ImAxisFlags_Scientific = 1 << 8, // scientific notation will be used for tick labels if displayed (WIP, not very good yet)
|
||||||
ImAxisFlags_Default = ImAxisFlags_GridLines | ImAxisFlags_TickMarks | ImAxisFlags_TickLabels | ImAxisFlags_Adaptive
|
ImAxisFlags_Default = ImAxisFlags_GridLines | ImAxisFlags_TickMarks | ImAxisFlags_TickLabels | ImAxisFlags_Adaptive,
|
||||||
|
ImAxisFlags_Auxiliary_Default = ImAxisFlags_Default & ~ImAxisFlags_GridLines,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Plot styling colors
|
// Plot styling colors
|
||||||
|
@ -75,7 +77,9 @@ enum ImPlotCol_ {
|
||||||
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_Text)
|
ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_Text)
|
||||||
ImPlotCol_XAxis, // x-axis grid/label color (defaults to ImGuiCol_Text)
|
ImPlotCol_XAxis, // x-axis grid/label color (defaults to ImGuiCol_Text)
|
||||||
ImPlotCol_YAxis, // x-axis grid/label color (defaults to ImGuiCol_Text)
|
ImPlotCol_YAxis, // y-axis grid/label color (defaults to ImGuiCol_Text)
|
||||||
|
ImPlotCol_Y2Axis, // y2-axis grid/label color (defaults to ImGuiCol_Text)
|
||||||
|
ImPlotCol_Y3Axis, // y3-axis grid/label color (defaults to ImGuiCol_Text)
|
||||||
ImPlotCol_Selection, // box-selection color (defaults to yellow)
|
ImPlotCol_Selection, // box-selection color (defaults to yellow)
|
||||||
ImPlotCol_Query, // box-query color (defaults to green)
|
ImPlotCol_Query, // box-query color (defaults to green)
|
||||||
ImPlotCol_COUNT
|
ImPlotCol_COUNT
|
||||||
|
@ -107,11 +111,18 @@ enum ImMarker_ {
|
||||||
ImMarker_Asterisk = 1 << 10, // a asterisk marker will be rendered at each point (not filled)
|
ImMarker_Asterisk = 1 << 10, // a asterisk marker will be rendered at each point (not filled)
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Plot range utility struct
|
|
||||||
struct ImPlotRange {
|
struct ImPlotRange {
|
||||||
float XMin, XMax, YMin, YMax;
|
float Min, Max;
|
||||||
ImPlotRange();
|
ImPlotRange();
|
||||||
bool Contains(const ImVec2& p);
|
bool Contains(float) const;
|
||||||
|
float Size() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Plot range utility struct
|
||||||
|
struct ImPlotBounds {
|
||||||
|
ImPlotRange X, Y;
|
||||||
|
ImPlotBounds();
|
||||||
|
bool Contains(const ImVec2& p) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Plot style structure
|
// Plot style structure
|
||||||
|
@ -137,15 +148,17 @@ namespace ImGui {
|
||||||
// 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"). If #x_label
|
||||||
// and/or #y_label are provided, axes labels will be displayed. Flags are only
|
// and/or #y_label are provided, axes labels will be displayed. Axis flags are
|
||||||
// set ONCE during the first call to BeginPlot.
|
// only set ONCE during the first call to BeginPlot.
|
||||||
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,
|
||||||
const ImVec2& size = ImVec2(-1,-1),
|
const ImVec2& size = ImVec2(-1,-1),
|
||||||
ImPlotFlags flags = ImPlotFlags_Default,
|
ImPlotFlags flags = ImPlotFlags_Default,
|
||||||
ImAxisFlags x_flags = ImAxisFlags_Default,
|
ImAxisFlags x_flags = ImAxisFlags_Default,
|
||||||
ImAxisFlags y_flags = ImAxisFlags_Default);
|
ImAxisFlags y_flags = ImAxisFlags_Default,
|
||||||
|
ImAxisFlags y2_flags = ImAxisFlags_Auxiliary_Default,
|
||||||
|
ImAxisFlags y3_flags = ImAxisFlags_Auxiliary_Default);
|
||||||
// Only call EndPlot() if BeginPlot() returns true! Typically called at the end
|
// Only call EndPlot() if BeginPlot() returns true! Typically called at the end
|
||||||
// of an if statement conditioned on BeginPlot().
|
// of an if statement conditioned on BeginPlot().
|
||||||
void EndPlot();
|
void EndPlot();
|
||||||
|
@ -185,14 +198,14 @@ void PlotDigital(const char* label_id, ImVec2 (*getter)(void* data, int idx), vo
|
||||||
|
|
||||||
/// Returns true if the plot area in the current or most recent plot is hovered.
|
/// Returns true if the plot area in the current or most recent plot is hovered.
|
||||||
bool IsPlotHovered();
|
bool IsPlotHovered();
|
||||||
/// Returns the mouse position in x,y coordinates of the current or most recent plot.
|
/// Returns the mouse position in x,y coordinates of the current or most recent plot. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
|
||||||
ImVec2 GetPlotMousePos();
|
ImVec2 GetPlotMousePos(int y_axis = -1);
|
||||||
/// Returns the current or most recent plot axis range.
|
/// Returns the current or most recent plot axis range. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
|
||||||
ImPlotRange GetPlotRange();
|
ImPlotBounds GetPlotBounds(int y_axis = -1);
|
||||||
/// Returns true if the current or most recent plot is being queried.
|
/// Returns true if the current or most recent plot is being queried.
|
||||||
bool IsPlotQueried();
|
bool IsPlotQueried();
|
||||||
/// Returns the current or most recent plot querey range.
|
/// Returns the current or most recent plot query bounds.
|
||||||
ImPlotRange GetPlotQuery();
|
ImPlotBounds GetPlotQuery(int y_axis = -1);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Plot Styling
|
// Plot Styling
|
||||||
|
@ -225,21 +238,24 @@ void PopPlotStyleVar(int count = 1);
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Set the axes ranges of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes will be locked.
|
/// Set the axes ranges of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes will be locked.
|
||||||
void SetNextPlotRange(float x_min, float x_max, float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
|
void SetNextPlotBounds(float x_min, float x_max, float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
|
||||||
/// Set the X axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
|
/// Set the X axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
|
||||||
void SetNextPlotRangeX(float x_min, float x_max, ImGuiCond cond = ImGuiCond_Once);
|
void SetNextPlotBoundsX(float x_min, float x_max, ImGuiCond cond = ImGuiCond_Once);
|
||||||
/// Set the Y axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
|
/// Set the Y axis range of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis will be locked.
|
||||||
void SetNextPlotRangeY(float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once);
|
void SetNextPlotBoundsY(float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once, int y_axis = 0);
|
||||||
|
|
||||||
|
/// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first Y axis.
|
||||||
|
void SetPlotYAxis(int);
|
||||||
|
|
||||||
// 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.
|
||||||
ImVec2 GetPlotSize();
|
ImVec2 GetPlotSize();
|
||||||
|
|
||||||
// Convert pixels to a position in the current plot's coordinate system.
|
// Convert pixels to a position in the current plot's coordinate system. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
|
||||||
ImVec2 PixelsToPlot(const ImVec2& pix);
|
ImVec2 PixelsToPlot(const ImVec2& pix, int y_axis = -1);
|
||||||
// Convert a position in the current plot's coordinate system to pixels.
|
// Convert a position in the current plot's coordinate system to pixels. A negative y_axis uses the current value of SetPlotYAxis (0 initially).
|
||||||
ImVec2 PlotToPixels(const ImVec2& plt);
|
ImVec2 PlotToPixels(const ImVec2& plt, int y_axis = -1);
|
||||||
|
|
||||||
// Push clip rect for rendering to current plot area
|
// Push clip rect for rendering to current plot area
|
||||||
void PushPlotClipRect();
|
void PushPlotClipRect();
|
||||||
|
|
|
@ -176,9 +176,9 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
static bool horz = false;
|
static bool horz = false;
|
||||||
ImGui::Checkbox("Horizontal",&horz);
|
ImGui::Checkbox("Horizontal",&horz);
|
||||||
if (horz)
|
if (horz)
|
||||||
ImGui::SetNextPlotRange(0, 110, -0.5f, 9.5f, ImGuiCond_Always);
|
ImGui::SetNextPlotBounds(0, 110, -0.5f, 9.5f, ImGuiCond_Always);
|
||||||
else
|
else
|
||||||
ImGui::SetNextPlotRange(-0.5f, 9.5f, 0, 110, ImGuiCond_Always);
|
ImGui::SetNextPlotBounds(-0.5f, 9.5f, 0, 110, ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", {-1, 300})) {
|
if (ImGui::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score", {-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};
|
||||||
|
@ -203,7 +203,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
float bar[5] = {1,2,5,3,4};
|
float bar[5] = {1,2,5,3,4};
|
||||||
float err1[5] = {0.2f, 0.4f, 0.2f, 0.6f, 0.4f};
|
float err1[5] = {0.2f, 0.4f, 0.2f, 0.6f, 0.4f};
|
||||||
float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
|
float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
|
||||||
ImGui::SetNextPlotRange(0, 6, 0, 10);
|
ImGui::SetNextPlotBounds(0, 6, 0, 10);
|
||||||
if (ImGui::BeginPlot("##ErrorBars",NULL,NULL,ImVec2(-1,300))) {
|
if (ImGui::BeginPlot("##ErrorBars",NULL,NULL,ImVec2(-1,300))) {
|
||||||
|
|
||||||
ImGui::PlotBar("Bar", xs, bar, 5, 0.5f);
|
ImGui::PlotBar("Bar", xs, bar, 5, 0.5f);
|
||||||
|
@ -227,7 +227,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
ImVec2 center(0.5f,0.5f); // in plot units, not pixels
|
ImVec2 center(0.5f,0.5f); // in plot units, not pixels
|
||||||
float radius = 0.4f; // in plot units, not pixels
|
float radius = 0.4f; // in plot units, not pixels
|
||||||
|
|
||||||
SetNextPlotRange(0,1,0,1,ImGuiCond_Always);
|
SetNextPlotBounds(0,1,0,1,ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
|
if (ImGui::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
|
||||||
ImGui::PlotPieChart(labels1, pre_normalized, 4, center, radius);
|
ImGui::PlotPieChart(labels1, pre_normalized, 4, center, radius);
|
||||||
ImGui::EndPlot();
|
ImGui::EndPlot();
|
||||||
|
@ -242,7 +242,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
{0.7412f, 0.0f, 0.1490f, 1.0f},
|
{0.7412f, 0.0f, 0.1490f, 1.0f},
|
||||||
};
|
};
|
||||||
ImGui::SetPlotPalette(YlOrRd, 5);
|
ImGui::SetPlotPalette(YlOrRd, 5);
|
||||||
SetNextPlotRange(0,1,0,1,ImGuiCond_Always);
|
SetNextPlotBounds(0,1,0,1,ImGuiCond_Always);
|
||||||
static const char* labels2[] = {"One","Two","Three","Four","Five"};
|
static const char* labels2[] = {"One","Two","Three","Four","Five"};
|
||||||
static float not_normalized[] = {1,2,3,4,5};
|
static float not_normalized[] = {1,2,3,4,5};
|
||||||
if (ImGui::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
|
if (ImGui::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
|
||||||
|
@ -268,14 +268,14 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
sdata2.AddPoint(t, mouse.y * 0.0005f);
|
sdata2.AddPoint(t, mouse.y * 0.0005f);
|
||||||
rdata2.AddPoint(t, mouse.y * 0.0005f);
|
rdata2.AddPoint(t, mouse.y * 0.0005f);
|
||||||
}
|
}
|
||||||
ImGui::SetNextPlotRangeX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
ImGui::SetNextPlotBoundsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||||
static int rt_axis = ImAxisFlags_Default & ~ImAxisFlags_TickLabels;
|
static int rt_axis = ImAxisFlags_Default & ~ImAxisFlags_TickLabels;
|
||||||
if (ImGui::BeginPlot("##Scrolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) {
|
if (ImGui::BeginPlot("##Scrolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) {
|
||||||
ImGui::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float));
|
ImGui::Plot("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float));
|
||||||
ImGui::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float));
|
ImGui::Plot("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float));
|
||||||
ImGui::EndPlot();
|
ImGui::EndPlot();
|
||||||
}
|
}
|
||||||
ImGui::SetNextPlotRangeX(0, 10, ImGuiCond_Always);
|
ImGui::SetNextPlotBoundsX(0, 10, ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("##Rolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) {
|
if (ImGui::BeginPlot("##Rolling", NULL, NULL, {-1,150}, ImPlotFlags_Default, rt_axis, rt_axis)) {
|
||||||
ImGui::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float));
|
ImGui::Plot("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float));
|
||||||
ImGui::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float));
|
ImGui::Plot("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float));
|
||||||
|
@ -285,7 +285,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
if (ImGui::CollapsingHeader("Markers and Labels")) {
|
if (ImGui::CollapsingHeader("Markers and Labels")) {
|
||||||
ImGui::SetNextPlotRange(0, 10, 0, 12);
|
ImGui::SetNextPlotBounds(0, 10, 0, 12);
|
||||||
if (ImGui::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) {
|
if (ImGui::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,300), 0, 0, 0)) {
|
||||||
float xs[2] = {1,4};
|
float xs[2] = {1,4};
|
||||||
float ys[2] = {10,11};
|
float ys[2] = {10,11};
|
||||||
|
@ -369,7 +369,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
ys2[i] = log(xs[i]);
|
ys2[i] = log(xs[i]);
|
||||||
ys3[i] = pow(10.0f, xs[i]);
|
ys3[i] = pow(10.0f, xs[i]);
|
||||||
}
|
}
|
||||||
ImGui::SetNextPlotRange(0.1f, 100, 0, 10);
|
ImGui::SetNextPlotBounds(0.1f, 100, 0, 10);
|
||||||
if (ImGui::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_Default | ImAxisFlags_LogScale )) {
|
if (ImGui::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_Default | ImAxisFlags_LogScale )) {
|
||||||
ImGui::Plot("f(x) = x", xs, xs, 1001);
|
ImGui::Plot("f(x) = x", xs, xs, 1001);
|
||||||
ImGui::Plot("f(x) = sin(x)+1", xs, ys1, 1001);
|
ImGui::Plot("f(x) = sin(x)+1", xs, ys1, 1001);
|
||||||
|
@ -379,12 +379,51 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
if (ImGui::CollapsingHeader("Multiple Y Axes")) {
|
||||||
|
static float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001];
|
||||||
|
static bool y2_axis = true;
|
||||||
|
static bool y3_axis = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < 1001; ++i) {
|
||||||
|
xs[i] = (float)(i*0.1f);
|
||||||
|
ys1[i] = sin(xs[i]) * 3 + 1;
|
||||||
|
ys2[i] = cos(xs[i]) * 0.2 + 0.5;
|
||||||
|
ys3[i] = sin(xs[i]+.5) * 100 + 200;
|
||||||
|
xs2[i] = xs[i] + 10.0;
|
||||||
|
}
|
||||||
|
ImGui::SetNextPlotBounds(0.1f, 100, 0, 10);
|
||||||
|
ImGui::SetNextPlotBoundsY(0, 1, ImGuiCond_Once, 1);
|
||||||
|
ImGui::SetNextPlotBoundsY(0, 300, ImGuiCond_Once, 2);
|
||||||
|
if (ImGui::BeginPlot("Multi-Axis Plot", NULL, NULL, ImVec2(-1,300),
|
||||||
|
ImPlotFlags_Default |
|
||||||
|
(y2_axis ? ImPlotFlags_Y2Axis : 0) |
|
||||||
|
(y3_axis ? ImPlotFlags_Y3Axis : 0))) {
|
||||||
|
ImGui::Plot("f(x) = x", xs, xs, 1001);
|
||||||
|
ImGui::Plot("f(x) = sin(x)*3+1", xs, ys1, 1001);
|
||||||
|
|
||||||
|
if (y2_axis) {
|
||||||
|
ImGui::SetPlotYAxis(1);
|
||||||
|
ImGui::Plot("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y3_axis) {
|
||||||
|
ImGui::SetPlotYAxis(2);
|
||||||
|
ImGui::Plot("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPlot();
|
||||||
|
}
|
||||||
|
ImGui::Checkbox("Y2 Axis", &y2_axis);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Checkbox("Y3 Axis", &y3_axis);
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
if (ImGui::CollapsingHeader("Querying")) {
|
if (ImGui::CollapsingHeader("Querying")) {
|
||||||
ImGui::BulletText("Ctrl + click in the plot area to draw points.");
|
ImGui::BulletText("Ctrl + click in the plot area to draw points.");
|
||||||
ImGui::BulletText("Middle click (or Ctrl + right click) and drag to query points.");
|
ImGui::BulletText("Middle click (or Ctrl + right click) and drag to query points.");
|
||||||
ImGui::BulletText("Hold the Alt and/or Shift keys to expand the query range.");
|
ImGui::BulletText("Hold the Alt and/or Shift keys to expand the query range.");
|
||||||
static ImVector<ImVec2> data;
|
static ImVector<ImVec2> data;
|
||||||
ImPlotRange range, query;
|
ImPlotBounds range, query;
|
||||||
if (ImGui::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_GridLines, ImAxisFlags_GridLines)) {
|
if (ImGui::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default, ImAxisFlags_GridLines, ImAxisFlags_GridLines)) {
|
||||||
if (ImGui::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl)
|
if (ImGui::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl)
|
||||||
data.push_back(ImGui::GetPlotMousePos());
|
data.push_back(ImGui::GetPlotMousePos());
|
||||||
|
@ -393,7 +432,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
if (data.size() > 0)
|
if (data.size() > 0)
|
||||||
ImGui::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float));
|
ImGui::Plot("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float));
|
||||||
if (ImGui::IsPlotQueried() && data.size() > 0) {
|
if (ImGui::IsPlotQueried() && data.size() > 0) {
|
||||||
ImPlotRange range = ImGui::GetPlotQuery();
|
ImPlotBounds range = ImGui::GetPlotQuery();
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
ImVec2 avg;
|
ImVec2 avg;
|
||||||
for (int i = 0; i < data.size(); ++i) {
|
for (int i = 0; i < data.size(); ++i) {
|
||||||
|
@ -410,12 +449,12 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::PopPlotStyleVar(2);
|
ImGui::PopPlotStyleVar(2);
|
||||||
range = ImGui::GetPlotRange();
|
range = ImGui::GetPlotBounds();
|
||||||
query = ImGui::GetPlotQuery();
|
query = ImGui::GetPlotQuery();
|
||||||
ImGui::EndPlot();
|
ImGui::EndPlot();
|
||||||
}
|
}
|
||||||
ImGui::Text("The current plot range is: [%g,%g,%g,%g]", range.XMin, range.XMax, range.YMin, range.YMax);
|
ImGui::Text("The current plot range is: [%g,%g,%g,%g]", range.X.Min, range.X.Max, range.Y.Min, range.Y.Max);
|
||||||
ImGui::Text("The current query range is: [%g,%g,%g,%g]", query.XMin, query.XMax, query.YMin, query.YMax);
|
ImGui::Text("The current query range is: [%g,%g,%g,%g]", query.X.Min, query.X.Max, query.Y.Min, query.Y.Max);
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
if (ImGui::CollapsingHeader("Views")) {
|
if (ImGui::CollapsingHeader("Views")) {
|
||||||
|
@ -436,9 +475,9 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
}
|
}
|
||||||
ImGui::BulletText("Query the first plot to render a subview in the second plot.");
|
ImGui::BulletText("Query the first plot to render a subview in the second plot.");
|
||||||
ImGui::BulletText("Toggle \"Pixel Query\" in the context menu and then pan the plot.");
|
ImGui::BulletText("Toggle \"Pixel Query\" in the context menu and then pan the plot.");
|
||||||
ImGui::SetNextPlotRange(0,0.01f,-1,1);
|
ImGui::SetNextPlotBounds(0,0.01f,-1,1);
|
||||||
ImAxisFlags flgs = ImAxisFlags_Default & ~ImAxisFlags_TickLabels;
|
ImAxisFlags flgs = ImAxisFlags_Default & ~ImAxisFlags_TickLabels;
|
||||||
ImPlotRange query;
|
ImPlotBounds query;
|
||||||
if (ImGui::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default, flgs, flgs)) {
|
if (ImGui::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default, flgs, flgs)) {
|
||||||
ImGui::Plot("Signal 1", x_data, y_data1, 512);
|
ImGui::Plot("Signal 1", x_data, y_data1, 512);
|
||||||
ImGui::Plot("Signal 2", x_data, y_data2, 512);
|
ImGui::Plot("Signal 2", x_data, y_data2, 512);
|
||||||
|
@ -446,7 +485,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
query = ImGui::GetPlotQuery();
|
query = ImGui::GetPlotQuery();
|
||||||
ImGui::EndPlot();
|
ImGui::EndPlot();
|
||||||
}
|
}
|
||||||
ImGui::SetNextPlotRange(query.XMin, query.XMax, query.YMin, query.YMax, ImGuiCond_Always);
|
ImGui::SetNextPlotBounds(query.X.Min, query.X.Max, query.Y.Min, query.Y.Max, ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("##View2",NULL,NULL,ImVec2(-1,150), 0, 0, 0)) {
|
if (ImGui::BeginPlot("##View2",NULL,NULL,ImVec2(-1,150), 0, 0, 0)) {
|
||||||
ImGui::Plot("Signal 1", x_data, y_data1, 512);
|
ImGui::Plot("Signal 1", x_data, y_data1, 512);
|
||||||
ImGui::Plot("Signal 2", x_data, y_data2, 512);
|
ImGui::Plot("Signal 2", x_data, y_data2, 512);
|
||||||
|
@ -504,7 +543,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
data[i].Data.back().y + (0.005f + 0.0002f * (float)rand() / float(RAND_MAX)) * (-1 + 2 * (float)rand() / float(RAND_MAX)));
|
data[i].Data.back().y + (0.005f + 0.0002f * (float)rand() / float(RAND_MAX)) * (-1 + 2 * (float)rand() / float(RAND_MAX)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::SetNextPlotRangeX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
ImGui::SetNextPlotBoundsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("##DND", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) {
|
if (ImGui::BeginPlot("##DND", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) {
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
if (show[i]) {
|
if (show[i]) {
|
||||||
|
@ -605,8 +644,8 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
if (showAnalog[i])
|
if (showAnalog[i])
|
||||||
dataAnalog[i].AddPoint(t, sin(2*t) - cos(2*t));
|
dataAnalog[i].AddPoint(t, sin(2*t) - cos(2*t));
|
||||||
}
|
}
|
||||||
ImGui::SetNextPlotRangeY(-1, 1);
|
ImGui::SetNextPlotBoundsY(-1, 1);
|
||||||
ImGui::SetNextPlotRangeX(t - 10.0f, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
ImGui::SetNextPlotBoundsX(t - 10.0f, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("##Digital", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) {
|
if (ImGui::BeginPlot("##Digital", NULL, NULL, ImVec2(-1,300), ImPlotFlags_Default)) {
|
||||||
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) {
|
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) {
|
||||||
if (showDigital[i]) {
|
if (showDigital[i]) {
|
||||||
|
@ -653,7 +692,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
ImGui::PushPlotColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192));
|
ImGui::PushPlotColor(ImPlotCol_XAxis, IM_COL32(192, 192, 192, 192));
|
||||||
ImGui::PushPlotColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192));
|
ImGui::PushPlotColor(ImPlotCol_YAxis, IM_COL32(192, 192, 192, 192));
|
||||||
ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 2);
|
ImGui::PushPlotStyleVar(ImPlotStyleVar_LineWeight, 2);
|
||||||
ImGui::SetNextPlotRange(-0.5f, 9.5f, -0.5f, 9.5f);
|
ImGui::SetNextPlotBounds(-0.5f, 9.5f, -0.5f, 9.5f);
|
||||||
if (ImGui::BeginPlot("##Custom", NULL, NULL, {-1,300}, ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) {
|
if (ImGui::BeginPlot("##Custom", NULL, NULL, {-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};
|
||||||
|
@ -688,7 +727,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
static BenchmarkItem items[n_items];
|
static BenchmarkItem items[n_items];
|
||||||
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);
|
||||||
SetNextPlotRange(0,1,0,1, ImGuiCond_Always);
|
SetNextPlotBounds(0,1,0,1, ImGuiCond_Always);
|
||||||
if (ImGui::BeginPlot("##Bench",NULL,NULL,{-1,300},ImPlotFlags_Default | ImPlotFlags_NoChild)) {
|
if (ImGui::BeginPlot("##Bench",NULL,NULL,{-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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user