finished axis grid/text for history plot
This commit is contained in:
parent
d17e9422f3
commit
9800baca21
3 changed files with 36 additions and 21 deletions
|
@ -165,8 +165,8 @@ int main ( int argc, char** argv )
|
||||||
|
|
||||||
|
|
||||||
// TEST
|
// TEST
|
||||||
//CServerLogging ServerLogging;
|
CServerLogging ServerLogging;
|
||||||
//exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -31,13 +31,16 @@ CServerLogging::CServerLogging()
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// constants defining the plot properties
|
// constants defining the plot properties
|
||||||
const int iYAxisStart = 0;
|
const int iYAxisStart = 0;
|
||||||
const int iYAxisEnd = 24;
|
const int iYAxisEnd = 24;
|
||||||
const int iNumTicksX = 10;
|
const int iNumTicksX = 9;
|
||||||
const int iNumTicksY = 5;
|
const int iNumTicksY = 5;
|
||||||
const int iPlotWidth = 500;
|
const int iPlotWidth = 500;
|
||||||
const int iPlotHeight = 500;
|
const int iPlotHeight = 500;
|
||||||
const int iGridFrameOffset = 10;
|
const int iGridFrameOffset = 10;
|
||||||
|
const int iTextOffsetToGrid = 3;
|
||||||
|
const int iYAxisTextHeight = 20;
|
||||||
|
const QFont AxisFont ( "Arial", 10 );
|
||||||
const QColor PlotBackgroundColor ( Qt::white ); // white background
|
const QColor PlotBackgroundColor ( Qt::white ); // white background
|
||||||
const QColor PlotFrameColor ( Qt::black ); // black frame
|
const QColor PlotFrameColor ( Qt::black ); // black frame
|
||||||
const QColor PlotGridColor ( Qt::gray ); // gray grid
|
const QColor PlotGridColor ( Qt::gray ); // gray grid
|
||||||
|
@ -58,20 +61,28 @@ CServerLogging::CServerLogging()
|
||||||
PlotCanvasRect.x() + iGridFrameOffset,
|
PlotCanvasRect.x() + iGridFrameOffset,
|
||||||
PlotCanvasRect.y() + iGridFrameOffset,
|
PlotCanvasRect.y() + iGridFrameOffset,
|
||||||
PlotCanvasRect.width() - 2 * iGridFrameOffset,
|
PlotCanvasRect.width() - 2 * iGridFrameOffset,
|
||||||
PlotCanvasRect.height() - 2 * iGridFrameOffset );
|
PlotCanvasRect.height() - 2 * iGridFrameOffset - iYAxisTextHeight );
|
||||||
|
|
||||||
PlotPainter.setPen ( PlotFrameColor );
|
PlotPainter.setPen ( PlotFrameColor );
|
||||||
PlotPainter.drawRect ( PlotGridFrame );
|
PlotPainter.drawRect ( PlotGridFrame );
|
||||||
|
|
||||||
// grid (ticks) for x-axis
|
// grid (ticks) for x-axis
|
||||||
const int iXSpace = PlotGridFrame.width() / ( iNumTicksX - 1 );
|
const int iTextOffsetX = 20;
|
||||||
for ( i = 0; i < ( iNumTicksX - 2 ); i++ )
|
const int iXSpace = PlotGridFrame.width() / ( iNumTicksX + 1 );
|
||||||
|
for ( i = 0; i < iNumTicksX; i++ )
|
||||||
{
|
{
|
||||||
const int iCurX = PlotGridFrame.x() + iXSpace * ( i + 1 );
|
const int iCurX = PlotGridFrame.x() + iXSpace * ( i + 1 );
|
||||||
|
|
||||||
// text
|
// text (only every second tick)
|
||||||
PlotPainter.setPen ( PlotTextColor );
|
if ( !( i % 2 ) )
|
||||||
// TODO
|
{
|
||||||
|
PlotPainter.setPen ( PlotTextColor );
|
||||||
|
PlotPainter.setFont ( AxisFont );
|
||||||
|
PlotPainter.drawText (
|
||||||
|
QPoint ( iCurX - iTextOffsetX,
|
||||||
|
PlotGridFrame.bottom() + iYAxisTextHeight + iTextOffsetToGrid ),
|
||||||
|
QDate::currentDate().addDays ( i - iNumTicksX + 1 ).toString ( "dd.MM." ) );
|
||||||
|
}
|
||||||
|
|
||||||
// grid
|
// grid
|
||||||
PlotPainter.setPen ( PlotGridColor );
|
PlotPainter.setPen ( PlotGridColor );
|
||||||
|
@ -87,10 +98,13 @@ CServerLogging::CServerLogging()
|
||||||
|
|
||||||
// text
|
// text
|
||||||
PlotPainter.setPen ( PlotTextColor );
|
PlotPainter.setPen ( PlotTextColor );
|
||||||
PlotPainter.setFont ( QFont ( "Arial", 10 ) );
|
PlotPainter.setFont ( AxisFont );
|
||||||
PlotPainter.drawText ( QPoint ( PlotGridFrame.x(), iCurY ),
|
PlotPainter.drawText ( QPoint (
|
||||||
QString().setNum ( ( iYAxisEnd - iYAxisStart ) / iNumTicksY * i ) );
|
PlotGridFrame.x() + iTextOffsetToGrid,
|
||||||
|
iCurY - iTextOffsetToGrid ),
|
||||||
|
QString().setNum (
|
||||||
|
( iYAxisEnd - iYAxisStart ) / ( iNumTicksY - 1 ) *
|
||||||
|
( ( iNumTicksY - 2 ) - i ) ) );
|
||||||
|
|
||||||
// grid
|
// grid
|
||||||
PlotPainter.setPen ( PlotGridColor );
|
PlotPainter.setPen ( PlotGridColor );
|
||||||
|
@ -100,7 +114,7 @@ CServerLogging::CServerLogging()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// save plot as a file
|
// save plot as a file
|
||||||
PlotPixmap.save ( "test.jpg", "JPG", 90 );
|
PlotPixmap.save ( "test.jpg", "JPG", 90 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <qpixmap.h>
|
#include <qpixmap.h>
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
|
#include <qdatetime.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue