Home |
Class PegStripChart HMI (Human-Machine Interface) Classes |
Class PegStripChartPegStripChart supports the drawing of discrete lines plotted against the Y axis, with new data samples added in series along the X axis. class PegStripChart : public PegChart { public: PegStripChart(const PegRect& Rect, PEGUINT wSamples, LONG lMinY, LONG lMaxY, PEGUINT wXScale=0, PEGUINT wYScale=0); void Draw(void); PEGINT Message(const PegMessage& Mesg); virtual void Resize(PegRect NewSize); virtual void RecalcSize(const PegRect& NewSize, BOOL bRedraw = TRUE); UCHAR AddLine(COLORVAL tColor, COLORVAL tAgedColor, COLORVAL tFillColor = 0); BOOL RemoveLine(UCHAR ucID); BOOL AddData(UCHAR ucID, LONG rawData, BOOL bRedraw = TRUE); PEGINT ValToPointY(LONG lVal); PEGINT IndexToPointX(PEGUINT wIndex); COLORVAL GetLineColor(UCHAR ucID); COLORVAL GetLineAgedColor(UCHAR ucID); COLORVAL GetLineFillColor(UCHAR ucID); COLORVAL GetLineLeaderColor(UCHAR ucID); void SetLineColor(UCHAR ucID, COLORVAL tColor); void SetLineAgedColor(UCHAR ucID, COLORVAL tColor); void SetLineFillColor(UCHAR ucID, COLORVAL tColor); void SetLineLeaderColor(UCHAR ucID, COLORVAL tColor); }; Style FlagsIn addition to the PegChart style flags, PegStripChart supports: CS_DRAWAGEDIf the chart is in paged mode (CS_PAGED is turned on), then the chart will redraw the current line in a secondary color when the data has reached the right side of the chart. New data, restarting over at the left side of the chart, will then overwrite this line. If this flag is turned off, all of the line segments are removed from the chart when the data reaches the right side of the chart. CS_DRAWLEADERThis flag causes the chart to draw a vertical line indicating the position of the most recently added data and corresponding line segment. CS_DRAWXAXISThis flag draws a single horizontal line across the entire chart region. It is situated at 0 on the Y scale. This line does not draw tic marks or labels. If CS_XAXISONZEROY is also turned on, then this flag is ignored CS_PAGEDThis flag is mutually exclusive with CS_SCROLLED. This causes the data to be drawn along a leading edge as it is added to the line. When the edge reaches the right side of the chart region, the line wraps. At this point, the existing data becomes aged, and is drawn in a second color specified in the AddLine call. The behavior of the strip chart when this flag is on is somewhat akin to a heart beat monitor. CS_SCROLLEDThis flag is mutually exclusive with CS_PAGED. This causes the data to be drawn beginning from the left and moving toward the right side of the chart region. When there is enough data for the line to extend all the way across the chart region, the line scrolls itself. Thus, new data points are added on the right, and old data points are subtracted from the left. This behavior most closely resembles a seismograph. ConstructorThe constructor receives the rectange of the chart it should occupy. If you have CS_AUTOSIZE turned on, you may just want to pass it the parent's mClient rectangle. The wSamples parameter specifies how many samples will fit into the chart region. If you would like to see 100 samples of data at one time, then you would set this parameter to 100. The last two parameters are for setting the major tick mark frequency for the X and Y axis, respectively. For instance, if your minimum Y value is -100 and your maximum Y value is 900, and you specify a Y scale of 100, if the CS_DRAWYTICS bit is set in the extended style flag, you will see tick marks on the Y axis starting at -100 and incrementing 100 all the way to 900. Therefore, there will be 11 tick marks drawn on the Y axis. If you were to also turn on the CS_DRAWYGRID bit, you would see a grid line at the same interval as the tick marks. Label scaling, or interval, is independant of the tick mark/grid line scaling. Therefore, it is possible to specify tick marks to appear at intervals of 100, while specifying labels to be drawn every 200. No matter the scaling, all drawing starts at the minimum value and works its way toward the maximum value until it meets or exceeds the maximum value. This holds true for both the X and Y axis. AddDataThis method adds a data point to a given line specified by ucID. Method AddLineAdds a new line to the chart. The colors are used to draw the line when its new data, and in the case of the paged chart, the line color when its drawing the aged data. It returns the id of the newly added line. Method DrawPegStripChart overrides the Draw() function to draw the individual lines. Method GetLineAgedColorReturns the COLORVAL used by line identified by ucID to draw its historical data. Method GetLineColorReturns the COLORVAL used by line identified by ucID to draw its current data. Method GetLineFillColorReturns the COLORVAL used by line identified by ucID to draw the filled polygon from the current line segment to 0 on the Y scale. Method GetLineLeaderColorThis function returns the current color of the leader. The leader is the straight vertical line drawn at the furthest point on the X axis where data is being inserted. The leader is only used when CS_PAGED is turned on. Every line may have its own leader color. By default, if a color is not initially specified for the leader, the normal line color is used. Method IndexToPointXDetermines the screen location along the X axis given the current index. The location is based on the chart region size and the number of samples being put into that region. This method is used internally by the chart. It returns a screen point on the X axis as a PEGINT value. Method MessagePegStripChart overrides the Message method in order to provide appropriate layout recalculation when its parent is moved, or optionally, resized. Method RecalcSizeThis method is overridden in order to ensure that the line data is up to date. In other words, if the chart is moved or resized, the screen coordinates associated with a given data point will change. In order to keep up with these changes, this method calls the RecalcLine method to update the screen coordinates of all the data points associated with the line. Method ResizeThis method overrides the PegThing::Resize method. Internally, it calls its own RecalcLayout method with the NewSize PegRectangle. It also calls the PegThing::Resize method to ensure proper layout. Method RemoveLineRemoves the line with the id of ucID. It returns a boolean of success or failure. Method SetLineAgedColorThis method sets the color used by line ucID to draw its historical data. Method SetLineColorThis method sets the color used by line identified by ucID to draw its current data. Method SetLineFillColorThis method sets the color used by line identified by ucID to draw a filled polygon from the current line segment to 0 on the Y axis. Method SetLineLeaderColorThis method sets the color of the leader of the specified line denoted by the ucID parameter. Method ValToPointYConverts a data value to a screen pixel location based on the size of the chart region and the minimum and maximum allowable values on the Y axis. This method is used internally by the chart to plot data points on the screen. It returns the screen point on the Y axis as a PEGINT value. ExamplesThe following code snippet produces the PegStripChart pictured below. This strip chart is using the CS_PAGED method of drawing. PegRect Rect; Rect.Set(40, 40, 590, 240); pChart = new PegStripChart(Rect, 240, -100, 120, 0, 20); mucID = pChart->AddLine(LIGHTGREEN, DARKGRAY, 0); Add(pChart);
|