00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "KDChartPlotter.h"
00031 #include "KDChartNormalPlotter_p.h"
00032
00033 using namespace KDChart;
00034
00035 NormalPlotter::NormalPlotter( Plotter* d )
00036 : PlotterType( d )
00037 {
00038 }
00039
00040 Plotter::PlotType NormalPlotter::type() const
00041 {
00042 return Plotter::Normal;
00043 }
00044
00045 const QPair< QPointF, QPointF > NormalPlotter::calculateDataBoundaries() const
00046 {
00047 const int rowCount = compressor().modelDataRows();
00048 const int colCount = compressor().modelDataColumns();
00049 double xMin = 0;
00050 double xMax = 0;
00051 double yMin = 0;
00052 double yMax = 0;
00053
00054 bool first = true;
00055 for( int column = 0; column < colCount; ++column )
00056 {
00057 for ( int row = 0; row < rowCount; ++row )
00058 {
00059 const CartesianDiagramDataCompressor::CachePosition position( row, column );
00060 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00061
00062 const double valueX = point.key;
00063 const double valueY = point.value;
00064
00065 if( first )
00066 {
00067 xMin = valueX;
00068 xMax = valueX;
00069 yMin = valueY;
00070 yMax = valueY;
00071 }
00072 else
00073 {
00074 xMin = qMin( xMin, valueX );
00075 xMax = qMax( xMax, valueX );
00076 yMin = qMin( yMin, valueY );
00077 yMax = qMax( yMax, valueY );
00078 }
00079
00080 first = false;
00081 }
00082 }
00083
00084 const QPointF bottomLeft( QPointF( xMin, qMin( 0.0, yMin ) ) );
00085 const QPointF topRight( QPointF( xMax, yMax ) );
00086 return QPair< QPointF, QPointF >( bottomLeft, topRight );
00087 }
00088
00089 void NormalPlotter::paint( PaintContext* ctx )
00090 {
00091 reverseMapper().clear();
00092
00093 Q_ASSERT( dynamic_cast< CartesianCoordinatePlane* >( ctx->coordinatePlane() ) );
00094 const CartesianCoordinatePlane* const plane = static_cast< CartesianCoordinatePlane* >( ctx->coordinatePlane() );
00095 const int colCount = compressor().modelDataColumns();
00096 const int rowCount = compressor().modelDataRows();
00097
00098 if( colCount == 0 || rowCount == 0 )
00099 return;
00100
00101 DataValueTextInfoList textInfoList;
00102 LineAttributesInfoList lineList;
00103 LineAttributes::MissingValuesPolicy policy;
00104
00105 for( int column = 0; column < colCount; ++column )
00106 {
00107 LineAttributes laPreviousCell;
00108 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
00109
00110 for( int row = 0; row < rowCount; ++row )
00111 {
00112 const CartesianDiagramDataCompressor::CachePosition position( row, column );
00113 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
00114 LineAttributes laCell;
00115 if( row > 0 )
00116 {
00117 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
00118 const CartesianDiagramDataCompressor::DataPoint lastPoint = compressor().data( previousCellPosition );
00119
00120 const QPointF a( plane->translate( QPointF( lastPoint.key, lastPoint.value ) ) );
00121 const QPointF b( plane->translate( QPointF( point.key, point.value ) ) );
00122 const QPointF c( plane->translate( QPointF( lastPoint.key, 0.0 ) ) );
00123 const QPointF d( plane->translate( QPointF( point.key, 0.0 ) ) );
00124
00125 laCell = diagram()->lineAttributes( sourceIndex );
00126
00127 const PositionPoints pts = PositionPoints( b, a, d, c );
00128
00129 QList<QPolygonF> areas;
00130 if ( laCell.displayArea() ) {
00131 QPolygonF polygon;
00132 polygon << a << b << d << c;
00133 areas << polygon;
00134 }
00135
00136 if ( ! point.hidden ) {
00137 appendDataValueTextInfoToList( diagram(), textInfoList, sourceIndex, pts,
00138 Position::NorthWest, Position::SouthWest,
00139 point.value );
00140 paintAreas( ctx, attributesModel()->mapToSource( lastPoint.index ), areas, laCell.transparency() );
00141 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
00142 }
00143 }
00144
00145 previousCellPosition = position;
00146 laPreviousCell = laCell;
00147 }
00148 }
00149 paintElements( ctx, textInfoList, lineList, policy );
00150 }