Skip to content

Commit

Permalink
Merge pull request ImpulseAdventure#442 from dirkx/feat_reset_graph
Browse files Browse the repository at this point in the history
Allow for the resetting of a graph.
  • Loading branch information
ImpulseAdventure authored Mar 7, 2022
2 parents 65182bd + 5d4fa42 commit 3c93faa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/elem/XGraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n
pXData->nMargin = 5;

pXData->nBufMax = nBufMax;
pXData->nBufCnt = 0;
pXData->nPlotIndStart = 0;

pXData->colGraph = colGraph;
pXData->eStyle = GSLCX_GRAPH_STYLE_DOT;
Expand All @@ -103,17 +101,6 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n
pXData->nWndHeight = rElem.h - (2*pXData->nMargin);
pXData->nWndWidth = rElem.w - (2*pXData->nMargin);

// Default scale is
// - Each data point (buffer row) gets 1 pixel in X direction
// - Data value is directly mapped to height in Y direction
pXData->nPlotValMin = 0;
pXData->nPlotValMax = pXData->nWndHeight;
pXData->nPlotIndMax = pXData->nWndWidth;


// Clear the buffer
memset(pBuf,0,nBufMax*sizeof(int16_t));


// Determine if scrollbar should be enabled
if (pXData->nPlotIndMax >= pXData->nBufMax) {
Expand All @@ -138,13 +125,15 @@ gslc_tsElemRef* gslc_ElemXGraphCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t n
sElem.colElemFrameGlow = GSLC_COL_WHITE;
if (nPage != GSLC_PAGE_NONE) {
pElemRef = gslc_ElemAdd(pGui,nPage,&sElem,GSLC_ELEMREF_DEFAULT);
gslc_ElemXGraphReset(pGui, pElemRef);
return pElemRef;
#if (GSLC_FEATURE_COMPOUND)
} else {
// Save as temporary element
pGui->sElemTmp = sElem;
pGui->sElemRefTmp.pElem = &(pGui->sElemTmp);
pGui->sElemRefTmp.eElemFlags = GSLC_ELEMREF_DEFAULT | GSLC_ELEMREF_REDRAW_FULL;
gslc_ElemXGraphReset(pGui, &(pGui->sElemRefTmp);
return &(pGui->sElemRefTmp);
#endif
}
Expand Down Expand Up @@ -239,6 +228,21 @@ void gslc_ElemXGraphAdd(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal)
gslc_ElemSetRedraw(pGui,pElemRef,GSLC_REDRAW_INC);
}

void gslc_ElemXGraphReset(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef) {

pXData->nBufCnt = 0;
pXData->nPlotIndStart = 0;

// Default scale is
// - Each data point (buffer row) gets 1 pixel in X direction
// - Data value is directly mapped to height in Y direction
pXData->nPlotValMin = 0;
pXData->nPlotValMax = pXData->nWndHeight;
pXData->nPlotIndMax = pXData->nWndWidth;

memset(pBuf,0,nBufMax*sizeof(int16_t));
}


bool gslc_ElemXGraphDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw)
{
Expand Down
8 changes: 8 additions & 0 deletions src/elem/XGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ bool gslc_ElemXGraphDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
///
void gslc_ElemXGraphAdd(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal);

/// Reset the graphs values.
///
/// \param[in] pGui: Pointer to GUI
/// \param[in] pElemRef: Pointer to Element reference
///
/// \return none
///
void gslc_ElemXGraphReset(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef);

///
/// Set the graph scroll position (nScrollPos) as a fraction of
Expand Down

0 comments on commit 3c93faa

Please sign in to comment.