WINDEX
Public Member Functions | List of all members
wex::plot::plot Class Reference

Draw a 2D plot. More...

#include <plot2d.h>

Inheritance diagram for wex::plot::plot:
wex::gui

Public Member Functions

 plot (gui *parent)
 CTOR. More...
 
traceAddStaticTrace ()
 Add static trace. More...
 
traceAddRealTimeTrace (int w)
 Add real time trace. More...
 
traceAddScatterTrace ()
 Add scatter trace. More...
 
void grid (bool enable)
 Enable display of grid markings.
 
void setFixedScale (double minX, double maxX, double minY, double maxY)
 Set fixed scale. More...
 
void setFitScale ()
 
int traceCount () const
 
void clear ()
 Remove all traces from plot.
 
void dragExtend (sMouse &m)
 Disable auto-fit scaling and set Y minumum, maximum. More...
 
void XUValues (float start_xu, float scale_xi2xu)
 Set conversion from index of x value buffer to x user units. More...
 
void XValues (float start_xu, float scale_xi2xu)
 for backward compatability More...
 
bool CalcScale (int w, int h)
 calculate scaling factors so plot will fit in window client area More...
 
std::vector< trace * > & traces ()
 
double pixel2Xuser (int xpixel) const
 get X user value from x pixel
 
int xuser2pixel (double xu) const
 
double pixel2Yuser (int ypixel) const
 get Y user value from y pixel
 
- Public Member Functions inherited from wex::gui
 gui ()
 Construct top level window with no parent. More...
 
 gui (gui *parent, const char *window_class="windex", unsigned long style=WS_CHILD, unsigned long exstyle=WS_EX_CONTROLPARENT)
 Construct child of a parent. More...
 
void child (gui *w)
 register child on this window
 
children_t & children ()
 get vector of children
 
guiparent ()
 
guifind (int id)
 find child window with specified id
 
void focus ()
 
void bgcolor (int color)
 Change background color. More...
 
void nobgerase ()
 
void enable (bool f=true)
 Enable/Disable, default enable.
 
bool isEnabled () const
 
void fontHeight (int h)
 Change font height for this and all child windows.
 
void fontName (const std::string &name)
 
void icon (const std::string &iconfilename)
 Change icon. More...
 
void cursor (char *cursorID)
 
int id ()
 
int bgcolor () const
 
void textColor (int c)
 Set text color. More...
 
void text (const std::string &text)
 
std::string text () const
 
void scroll (bool fHoriz=true)
 Add scrollbars. More...
 
void scrollRange (int width, int height)
 Set the scrolling range. More...
 
sMouse getMouseStatus ()
 Get mouse status. More...
 
void run ()
 Run the windows message loop. More...
 
void tooltip (const std::string &text, int width=0)
 Add tooltip that pops up helpfully when mouse cursor hovers over widget. More...
 
virtual LRESULT WindowMessageHandler (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
virtual void show (bool f=true)
 Show window and all children.
 
void showModal (gui &appWindow)
 Show this window and suspend all other windows interactions until this is closed. More...
 
void endModal ()
 Stop modal interaction and close window.
 
void update ()
 force widget to redraw completely More...
 
void move (const std::vector< int > &r)
 Move the window. More...
 
void size (int w, int h)
 Change size without moving top left corner. More...
 
void move (int x, int y)
 Change position without changing size. More...
 
void move (int x, int y, int w, int h)
 
std::vector< int > size ()
 Size of window client area. More...
 
std::vector< int > lefttop ()
 
eventhandlerevents ()
 Get event handler.
 
HWND handle ()
 get window handle
 
void delete_list (std::vector< HWND > *list)
 set delete list for when gui is detroyed
 
void setfont (LOGFONT &logfont, HFONT &font)
 change font for this and all child windows
 
void setAsyncReadCompleteMsgID (int id)
 

Additional Inherited Members

- Protected Member Functions inherited from wex::gui
void Create (HWND parent, const char *window_class, DWORD style, DWORD exstyle=0, int id=0)
 Create the managed window. More...
 
void font (LOGFONT &logfont, HFONT &font)
 get font details More...
 
void createNewFont ()
 Replace font used by this and child windows from logfont.
 
virtual void draw (PAINTSTRUCT &ps)
 
int NewID ()
 Create new, unique ID for gui element. More...
 
int scrollMove (SCROLLINFO &si, int code)
 
- Protected Attributes inherited from wex::gui
HWND myHandle
 
guimyParent
 
eventhandler myEvents
 
int myBGColor
 
int myTextColor
 
HBRUSH myBGBrush
 
LOGFONT myLogFont
 
HFONT myFont
 
std::vector< HWND > * myDeleteList
 
std::string myText
 
int myID
 
std::vector< gui * > myChild
 gui elements to be displayed in this window
 
bool myfModal
 true if element is being shown as modal
 
bool myfEnabled
 true if not disabled
 
bool myfnobgerase
 
HWND myToolTip
 
unsigned int myAsyncReadCompleteMsgID
 handle to tooltip control for this gui element
 
char * myCursorID
 
bool myfScrollHoriz
 

Detailed Description

Draw a 2D plot.

The plot contains one or more traces.

Each trace can be of one of three types:

Any number of plot and scatter traces can be shown together, only one realtime trace may be present in a plot.

ZOOM

To zoom into a selected area of the plot click on the top left of the area and drag the mouse to the bottom right. The plot will draw a box around the area selected. When the left button is released, the plot will zoom in to show just the selected area. To restore auto-fit, right click on the plot.

If application code is required to use the right click ( e.g. for a context pop-up menu ) the event handler must first call the plot method autofit.

    myPlotB.events().clickRight([&]
    {
        myPlotB.autoFit();
        ...
    });

Sample plot application:

#include "wex.h"
#include "plot2d.h"

int main()
{
        wex::gui& fm = wex::maker::make();
        fm.move( {50,50,1200,600} );

        // construct plot to be drawn on form
        wex::plot::plot& thePlot = wex::maker::make<wex::plot::plot>(fm);
        thePlot.move( {30,30,1200,600});
        //thePlot.Grid( true );

        // resize plot when form resizes
        fm.events().resize([&](int w, int h )
        {
            thePlot.move( {30,30,w,h} );
            thePlot.update();
        });

        // construct plot traces
        wex::plot::trace& t1 = thePlot.AddStaticTrace();
        wex::plot::trace& t2 = thePlot.AddStaticTrace();

        // provide some data for first trace
        std::vector< double > d1 { 10, 15, 20, 25, 30, 25, 20, 15, 10 };
        t1.set( d1 );

        // plot in blue
        t1.color( 0x0000FF );

        // provide data for second trace
        std::vector< double > d2 { 20, 30, 40, 50, 60, 50, 40, 30, 20 };
        t2.set( d2 );

        // plot in red
        t2.color( 0xFF0000 );

        // show and run
        fm.show();
        fm.run();
}

Constructor & Destructor Documentation

◆ plot()

wex::plot::plot::plot ( gui parent)
inline

CTOR.

Parameters
[in]parentwindow where plot will be drawn

Member Function Documentation

◆ AddRealTimeTrace()

trace& wex::plot::plot::AddRealTimeTrace ( int  w)
inline

Add real time trace.

Parameters
[in]wnumber of recent data points to display
Returns
reference to new trace

The data in a real time trace receives new values from time to time The display shows w recent values. Older values scroll off the left hand side of the plot and disappear.

◆ AddScatterTrace()

trace& wex::plot::plot::AddScatterTrace ( )
inline

Add scatter trace.

Returns
reference to new trace

A static trace for scatter plots No line between points, box around each point. Specify x AND y locations for each point.

◆ AddStaticTrace()

trace& wex::plot::plot::AddStaticTrace ( )
inline

Add static trace.

Returns
reference to new trace

The data in a static trace does not change A line is drawn between successive points Specify y location only for each point. The points will be evenly distributed along the x-axis

◆ CalcScale()

bool wex::plot::plot::CalcScale ( int  w,
int  h 
)
inline

calculate scaling factors so plot will fit in window client area

Returns
true if succesful

◆ dragExtend()

void wex::plot::plot::dragExtend ( sMouse m)
inline

Disable auto-fit scaling and set Y minumum, maximum.

Parameters
[in]minenforced min Y
[in]maxenforced max Y Enable auto-fit scaling and remove any zoom setting

◆ setFixedScale()

void wex::plot::plot::setFixedScale ( double  minX,
double  maxX,
double  minY,
double  maxY 
)
inline

Set fixed scale.

Parameters
minXminimum user x
maxXmaximum user X
minYminimum Y
maxYmaximum Y

◆ XUValues()

void wex::plot::plot::XUValues ( float  start_xu,
float  scale_xi2xu 
)
inline

Set conversion from index of x value buffer to x user units.

Parameters
[in]startx user value of first data point
[in]scaleto convert from index to user value

Used to label the x-axis and draw grid lines if enabled

◆ XValues()

void wex::plot::plot::XValues ( float  start_xu,
float  scale_xi2xu 
)
inline

for backward compatability

Parameters
start_xu
scale_xi2xu

The documentation for this class was generated from the following file: