1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 23:57:26 -04:00

PlotDigital updates on ImPlot v0.2

This commit is contained in:
ozlb 2020-05-11 13:13:08 +02:00 committed by GitHub
parent 036b4acaab
commit 41ece38678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,10 +20,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// ImPlot v0.1 WIP // ImPlot v0.2 WIP
#pragma once #pragma once
#include <imgui.h> #include "imgui.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Basic types and flags // Basic types and flags
@ -41,12 +41,15 @@ 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_Query = 1 << 4, // the user will be able to draw query rects with middle-mouse
ImPlotFlags_ContextMenu = 1 << 5, // 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 << 6, // 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 << 7, // 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 << 8, // 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 << 9, // 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_YAxis2 = 1 << 10, // enable a 2nd y axis
ImPlotFlags_YAxis3 = 1 << 11, // enable a 3rd y axis
ImPlotFlags_QueryX = 1 << 12,// show x-axis query
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 +64,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 = ImAxisFlags_Default & ~ImAxisFlags_GridLines,
}; };
// Plot styling colors // Plot styling colors
@ -74,13 +78,17 @@ enum ImPlotCol_ {
ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg) ImPlotCol_FrameBg, // plot frame background color (defaults to ImGuiCol_FrameBg)
ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg) ImPlotCol_PlotBg, // plot area background color (defaults to ImGuiCol_WindowBg)
ImPlotCol_PlotBorder, // plot area border color (defaults to ImGuiCol_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 25% ImGuiCol_Text)
ImPlotCol_YAxis, // x-axis grid/label color (defaults to ImGuiCol_Text) ImPlotCol_YAxis, // y-axis grid/label color (defaults to 25% ImGuiCol_Text)
ImPlotCol_YAxis2, // 2nd y-axis grid/label color (defaults to 25% ImGuiCol_Text)
ImPlotCol_YAxis3, // 3rd y-axis grid/label color (defaults to 25% 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_QueryX, // x-axis query color (defaults to red)
ImPlotCol_COUNT ImPlotCol_COUNT
}; };
// Plot styling variables
enum ImPlotStyleVar_ { enum ImPlotStyleVar_ {
ImPlotStyleVar_LineWeight, // float, line weight in pixels ImPlotStyleVar_LineWeight, // float, line weight in pixels
ImPlotStyleVar_Marker, // int, marker specification ImPlotStyleVar_Marker, // int, marker specification
@ -108,11 +116,19 @@ 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 // A range defined by a min/max value. Used for plot axes ranges.
struct ImPlotRange { struct ImPlotRange {
float XMin, XMax, YMin, YMax; float Min, Max;
ImPlotRange(); ImPlotRange();
bool Contains(const ImVec2& p); bool Contains(float value) const;
float Size() const;
};
// Combination of two ranges for X and Y axes.
struct ImPlotLimits {
ImPlotRange X, Y;
ImPlotLimits();
bool Contains(const ImVec2& p) const;
}; };
// Plot style structure // Plot style structure
@ -139,15 +155,16 @@ 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.
// 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,
ImAxisFlags y3_flags = ImAxisFlags_Auxiliary);
// 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();
@ -156,7 +173,7 @@ void EndPlot();
// Plot Items // Plot Items
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Plots a standard 2D line and/or scatter plot . // Plots a standard 2D line and/or scatter plot.
void Plot(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float)); void Plot(const char* label_id, const float* values, int count, int offset = 0, int stride = sizeof(float));
void Plot(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float)); void Plot(const char* label_id, const float* xs, const float* ys, int count, int offset = 0, int stride = sizeof(float));
void Plot(const char* label_id, const ImVec2* data, int count, int offset = 0); void Plot(const char* label_id, const ImVec2* data, int count, int offset = 0);
@ -187,15 +204,16 @@ 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(); ImPlotLimits GetPlotLimits(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(); ImPlotLimits GetPlotQuery(int y_axis = -1);
/// Returns the current x-axis query range.
ImPlotLimits GetPlotQueryX();
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Plot Styling // Plot Styling
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -226,22 +244,25 @@ void PopPlotStyleVar(int count = 1);
// Plot Utils // Plot Utils
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// 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 range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked.
void SetNextPlotRange(float x_min, float x_max, float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once); void SetNextPlotLimits(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 limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis limits will be locked.
void SetNextPlotRangeX(float x_min, float x_max, ImGuiCond cond = ImGuiCond_Once); void SetNextPlotLimitsX(float x_min, float x_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 Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis limits will be locked.
void SetNextPlotRangeY(float y_min, float y_max, ImGuiCond cond = ImGuiCond_Once); void SetNextPlotLimitsY(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 y_axis);
// 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();