-void Plot::PlotGraph(int *buffer, int len, QRect r,QPainter *painter, int graphNum)
+void Plot::PlotGraph(int *buffer, int len, QRect plotRect, QRect annotationRect,QPainter *painter, int graphNum)
int vMin = INT_MAX, vMax = INT_MIN,vMean = 0, v = 0,absVMax = 0;
int sample_index =GraphStart ;
int vMin = INT_MAX, vMax = INT_MIN,vMean = 0, v = 0,absVMax = 0;
int sample_index =GraphStart ;
if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin);
if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax);
absVMax = (int)(absVMax*1.2 + 1);
if(fabs( (double) vMin) > absVMax) absVMax = (int)fabs( (double) vMin);
if(fabs( (double) vMax) > absVMax) absVMax = (int)fabs( (double) vMax);
absVMax = (int)(absVMax*1.2 + 1);
if(labels <= 0) labels = 1;
int pointsPerLabel = span / labels;
if(pointsPerLabel <= 0) pointsPerLabel = 1;
if(labels <= 0) labels = 1;
int pointsPerLabel = span / labels;
if(pointsPerLabel <= 0) pointsPerLabel = 1;
- int x = xCoordOf(0)+40;
- int y = yCoordOf(buffer[0],r,absVMax);
+ int x = xCoordOf(0, plotRect);
+ int y = yCoordOf(buffer[0],plotRect,absVMax);
- int zeroY = yCoordOf( 0 , r , absVMax);
- for(int i = GraphStart; i < len && xCoordOf(i) < r.right(); i++) {
-
- x = xCoordOf(i);
+ x = xCoordOf(i, plotRect);
painter->fillRect(f, QColor(100, 255, 100));
}
painter->fillRect(f, QColor(100, 255, 100));
}
size = metrics.boundingRect(str);
painter->drawText(x - (size.right() - size.left()), zeroY + 9, str);
}
size = metrics.boundingRect(str);
painter->drawText(x - (size.right() - size.left()), zeroY + 9, str);
}
- painter->setPen(getColor(graphNum));
- painter->drawPath(penPath);
- char str[200];
- sprintf(str, "max=%5d min=%5d mean=%5d n=%5d/%5d CursorA=[%5d] CursorB=[%5d]",
- vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]);
- int xo = r.left()+40+(graphNum*40);
- painter->drawLine(xo, r.top(),xo, r.bottom());
-
- int vMarkers = (absVMax - (absVMax % 10)) / 10;
- int minYDist = 20; //Minimum pixel-distance between markers
+ int vMarkers = (absVMax - (absVMax % 10)) / 5;
+ int minYDist = 40; //Minimum pixel-distance between markers
- for(int v = vMarkers; yCoordOf(v,r,absVMax) > r.top() && n < 20; v+= vMarkers ,n++)
+ for(int v = vMarkers; yCoordOf(v,plotRect,absVMax) > plotRect.top() && n < 20; v+= vMarkers ,n++)
- int y0 = yCoordOf(v,r,absVMax);
- int y1 = yCoordOf(-v,r,absVMax);
+ int y0 = yCoordOf(v,plotRect,absVMax);
+ int y1 = yCoordOf(-v,plotRect,absVMax);
+ //Graph annotations
+ painter->drawPath(penPath);
+ char str[200];
+ sprintf(str, "max=%5d min=%5d mean=%5d n=%5d/%5d CursorA=[%5d] CursorB=[%5d]",
+ vMax, vMin, vMean, sample_index, len, buffer[CursorAPos], buffer[CursorBPos]);
+ painter->drawText(20, annotationRect.bottom() - 25 - 15 * graphNum, str);
+
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
printf("Plot time %f\n", elapsed_secs);
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
printf("Plot time %f\n", elapsed_secs);
QBrush brush(QColor(100, 255, 100));
QPen pen(QColor(100, 255, 100));
QBrush brush(QColor(100, 255, 100));
QPen pen(QColor(100, 255, 100));
+ QRect plotRect(WIDTH_AXES, 0, width()-WIDTH_AXES, height()-HEIGHT_INFO);
+ QRect infoRect(0, height()-HEIGHT_INFO, width(), HEIGHT_INFO);
+
+ //Grey background
+ painter.fillRect(rect(), QColor(60, 60, 60));
- painter.fillRect(r, QColor(0, 0, 0));
+ painter.fillRect(plotRect, QColor(0, 0, 0));
- //Draw y-axis
- //painter.setPen(QColor(255, 255, 255));
- //painter.drawLine(r.left()+40, r.top(),r.left() + 40, r.bottom());
+// painter.fillRect(infoRect, QColor(60, 60, 60));
- painter.drawLine(r.left(), zeroHeight, r.right(), zeroHeight);
-
- PageWidth= (int)((r.right() - r.left() - 40) / GraphPixelsPerPoint);
-
+ painter.drawLine(plotRect.left(), zeroHeight, plotRect.right(), zeroHeight);
- PlotGraph(s_Buff, GraphTraceLen,r,&painter,1);
- PlotGraph(GraphBuffer, GraphTraceLen,r,&painter,0);
+ PlotGraph(s_Buff, GraphTraceLen,plotRect,infoRect,&painter,1);
+ PlotGraph(GraphBuffer, GraphTraceLen,plotRect,infoRect,&painter,0);
- painter.drawLine(xCoordOf(CursorAPos),r.top(),xCoordOf(CursorAPos),r.bottom());
+ painter.drawLine(xCoordOf(CursorAPos, plotRect),plotRect.top(),xCoordOf(CursorAPos, plotRect),plotRect.bottom());
- painter.drawLine(xCoordOf(CursorBPos),r.top(),xCoordOf(CursorBPos),r.bottom());
+ painter.drawLine(xCoordOf(CursorBPos, plotRect),plotRect.top(),xCoordOf(CursorBPos, plotRect),plotRect.bottom());
char str[200];
sprintf(str, "@%5d dt=%5d [%2.2f] zoom=%2.2f CursorA= %5d CursorB= %5d GridX=%5d GridY=%5d (%s)",
GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,
GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked");
painter.setPen(QColor(255, 255, 255));
char str[200];
sprintf(str, "@%5d dt=%5d [%2.2f] zoom=%2.2f CursorA= %5d CursorB= %5d GridX=%5d GridY=%5d (%s)",
GraphStart, CursorBPos - CursorAPos, (CursorBPos - CursorAPos)/CursorScaleFactor,
GraphPixelsPerPoint,CursorAPos,CursorBPos,PlotGridXdefault,PlotGridYdefault,GridLocked?"Locked":"Unlocked");
painter.setPen(QColor(255, 255, 255));