![]() |
Desktop Development »
Miscellaneous »
Charting Controls
Advanced
A 2D data visualisation classBy Paul BarvinkoA comprehensive set of classes for displaying 2 dimensional data |
VC6, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

CGraphWnd is a class that provides multiplot 2D data visualization. CGraphWnd class is derived from the MFC class CWnd and could be used as a base class for different kinds of 2D data plot views. The following features are supported:
See the sample picture above of a 2D plot with three graphs.
The class interface provides several groups of functions.
CGraphWnd(long maximum_graphs = 32);
The constructor that creates a graph and initializes the storage for plots. The maximum_graphs parameter specifies the maximum number of plots.
BOOL Create(LPCTSTR lpszWindowName, const RECT& rect, CWnd* pParentWnd,
UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE,
BOOL bAutoUpdateTimer = FALSE);
The function creates a graph window. bAutoUpdateTimer parameter specifies whether to start a toolbar update timer in situations where the Idle functionality is not available (modal dialog boxes). For more description on other parameters - see the MSDN help on CWnd::Create.
virtual int AddGraph(COLORREF newColor = 0, char* title = "", BOOL bRedraw = TRUE, BOOL b_sort_x = TRUE, BOOL b_keep_same_x = FALSE);
The function adds a new graph to the view. It returns the graph index if successful and -1 if not. If the bInvalidate flag is set then the view will be updated. If b_sort_x flag is set, then the points will be sorted by the X-axis.
virtual int RemoveGraph(int index, BOOL bRedraw = TRUE);
The function removes the graph from the collection.
virtual int UpdateGraph(int index, BOOL bRedraw = TRUE);
The function updates the graph information and the view, if the bInvalidate flag is set. It is useful after collective operations on a hidden graph.
virtual CGraphProps* GetGraph(int index);
The function returns the properties of a given graph or NULL in case of an error.
virtual CGraphProps* GetFirstGraph(int* index); virtual CGraphProps* GetNextGraph(int* index);
These functions are used to enumerate through all the existing graphs in the view.
virtual void SetGraphFlags(DWORD new_flags, BOOL bRedraw); virtual DWORD GetGraphFlags();
These functions are used to get or set the graph view flags. The flag value is an OR'ed combination of:
enum GRAPH_PANEL_FLAGS { GRAPH_AUTOSCALE = 0x00000001, //turns autoscale feature on/off GRAPH_SQUAREPOINTS = 0x00000002, //defines whether to draw points // as squares GRAPH_SHOW_TOOLTIP = 0x00000004, //defines whether to show tooltip // with mouse coordinates information GRAPH_DRAW_AXIS = 0x00000008, //defines whether to draw axis GRAPH_GRAPH_SCATTER = 0x00000010 //specifies if graph is shown as // "scatter" graph };
virtual int AddPoint(int graphnum, double x, double y, BOOL bRedraw, int index = -1);
It adds (if index == -1) or inserts a new point to the graph. If bRedraw is set - the graph will be invalidated.
virtual int EditPoint(int graphnum, int index, double x, double y, BOOL bRedraw);
It sets the new point coordinates. If bRedraw is set - it invalidates the graph.
virtual int RemovePoint(int graphnum, int index, BOOL bRedraw);
It removes the point from the graph.
virtual void ClearGraph(int graphnum, BOOL bRedraw);
It removes all the points from a specified graph or from all the graphs if graphnum == -1.
virtual void SetAxisProps(char* _title, char* _UOM, int _precision, BOOL bXAxis, BOOL bRedraw);
It sets the properties for the axis. The properties include: Axis' title (_title), unit of measurement (_UOM) and precision - number of digits after comma (_precision). The bXAxis parameter specifies axis to apply attributes to and could be one of the following: GRAPH_X_AXIS or GRAPH_Y_AXIS.
virtual void FormatAxisOutput(double value, BOOL bXAxis, int format_level, CString& res_str);
It returns a formatted value parameter, regarding the current axis' properties and format level. Currently, three levels of format information are defined:
virtual void SetGraphWorldCoords(double x1, double x2, double y1, double y2, BOOL bRedraw = TRUE);
The function sets a new world coordinates for the graph and, if bRedraw flag is set, it redraws the graph.
virtual void GetGraphWorldCoords(double* x1, double* x2, double* y1, double* y2);
The function retrieves the graph's world coordinates.
virtual BOOL GetBoundRect(double* minx, double* maxx, double* miny, double* maxy);
The function retrieves the bounding rectangle for all the visible graphs.
virtual void UpdateWindows(unsigned long what_to_update);
The function updates (redraws) the specified views and/or windows. what_to_update parameter could be an OR'ed combination of the following values:
enum GRAPH_WINDOW_UPDATE_VALUES
{
GRAPH_WUV_GRAPH = 0x00000001,
GRAPH_WUV_PVIEW = 0x00000002,
GRAPH_WUV_RULERS = 0x00000004,
GRAPH_WUV_ALL = 0xFFFFFFFF
};virtual void OperateWithPointView(unsigned long pview_operations);
The function does the following operations with the point view:
pview_operations parameter can take one of the following values:
enum GRAPH_PVIEW_OPERATIONS
{
GRAPH_PO_SHOW = 0x00000001,
GRAPH_PO_HIDE = 0x00000002,
GRAPH_PO_DISABLE = 0x00000004,
GRAPH_PO_ENABLE = 0x00000008
};void DrawGraphToDC(CDC* dest_dc, CRect& rect_to_draw);
Using the function graph with rulers this can be drawn on the device context, specified by the dest_dc parameter. rect_to_draw parameter defines a rectangle in pixels where the graph should be drawn.
virtual void AppendMenuItems(CMenu* menu);
Overwrite this function to change the contents of RB-menu.
virtual void AppendPropertyPage(CPropertySheet* prop_sheet);
Overwrite this function to add a property page to the Property Sheet with graph properties.
virtual void ReleasePropertyPage(UINT dialog_status);
This function should apply changes to the graph (if any) and delete the previously added property pages. The dialog_status parameter is a result of the DoModal() function of the Property Sheet (either IDOK or IDCANCEL).
There are several steps that you should do in order to use this class in your application:
IDD_GRAPH_CHANGE_TITLE dialog
IDD_GRAPH_AXIS_PROP_PAGE dialog
IDD_GRAPH_GRAPH_PROP_PAGE dialog
IDD_GRAPH_GRAPHICS_PROPS dialog CGraphWnd or use it directly - and off we go! There are no specific steps that you should make in order to use this class in dialogs except when using it in modal dialog boxes. In this case, you must set the bAutoUpdateTimer parameter in the CGraphWnd::Create function to TRUE.
The latest sources, demos and the updates for the class can be found here. You can drop an e-mail to the author here. This class uses the CSizingControlBar class, written by Cristi Posea.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 20 Mar 2000 Editor: Chris Maunder |
Copyright 2000 by Paul Barvinko Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |