23 #include "KDChartPercentPlotter_p.h" 25 #include "PaintingHelpers_p.h" 32 PercentPlotter::PercentPlotter(
Plotter*
d )
44 const int rowCount = compressor().modelDataRows();
45 const int colCount = compressor().modelDataColumns();
46 qreal xMin = std::numeric_limits< qreal >::quiet_NaN();
47 qreal xMax = std::numeric_limits< qreal >::quiet_NaN();
48 const qreal yMin = 0.0;
49 const qreal yMax = 100.0;
51 for (
int column = 0; column < colCount; ++column )
53 for (
int row = 0; row < rowCount; ++row )
55 const CartesianDiagramDataCompressor::CachePosition position( row, column );
56 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
58 const qreal valueX = ISNAN( point.key ) ? 0.0 : point.key;
67 xMin = qMin( xMin, valueX );
68 xMax = qMax( xMax, valueX );
73 const QPointF bottomLeft( QPointF( xMin, yMin ) );
74 const QPointF topRight( QPointF( xMax, yMax ) );
82 : value(
std::numeric_limits< qreal >::quiet_NaN() )
90 operator qreal()
const 101 reverseMapper().clear();
103 Q_ASSERT( dynamic_cast< CartesianCoordinatePlane* >( ctx->
coordinatePlane() ) );
105 const int colCount = compressor().modelDataColumns();
106 const int rowCount = compressor().modelDataRows();
108 if ( colCount == 0 || rowCount == 0 )
116 for (
int col = 0; col < colCount; ++col )
118 for (
int row = 0; row < rowCount; ++row )
120 const CartesianDiagramDataCompressor::CachePosition position( row, col );
121 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
122 diagramValues[ point.key ].resize( colCount );
123 diagramValues[ point.key ][ col ].first = point.value;
124 diagramValues[ point.key ][ col ].second = point.index;
134 Q_FOREACH(
const qreal xValue, xValues )
138 Q_ASSERT( yValues.count() == colCount );
140 for (
int column = 0; column < colCount; ++column )
144 if ( !data.second.isValid() )
150 for ( xIndex = xValues.indexOf( xValue ); xIndex >= 0; --xIndex )
152 if ( diagramValues[ xValues[ xIndex ] ][ column ].second.isValid() )
154 left.first.first = xValues[ xIndex ];
155 left.first.second = diagramValues[ left.first.first ][ column ].first;
156 left.second = diagramValues[ xValues[ xIndex ] ][ column ].second;
161 for ( xIndex = xValues.indexOf( xValue ); xIndex < xValues.count(); ++xIndex )
163 if ( diagramValues[ xValues[ xIndex ] ][ column ].second.isValid() )
165 right.first.first = xValues[ xIndex ];
166 right.first.second = diagramValues[ right.first.first ][ column ].first;
167 right.second = diagramValues[ xValues[ xIndex ] ][ column ].second;
173 const qreal leftX = left.first.first;
174 const qreal rightX = right.first.first;
175 const qreal leftY = left.first.second;
176 const qreal rightY = right.first.second;
178 data.first = leftY + ( rightY - leftY ) * ( xValue - leftX ) / ( rightX - leftX );
180 if ( !ISNAN( data.first.operator qreal() ) )
181 data.second = left.second;
185 if ( !ISNAN( yValues[ column ].first.operator qreal() ) )
186 yValueSums[ xValue ] += yValues[ column ].first;
190 for (
int column = 0; column < colCount; ++column )
192 LineAttributesInfoList lineList;
194 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
196 CartesianDiagramDataCompressor::DataPoint lastPoint;
198 qreal lastExtraY = 0.0;
199 qreal lastValue = 0.0;
201 QMapIterator< qreal, QVector< QPair< Value, QModelIndex > > > i( diagramValues );
202 while ( i.hasNext() )
205 CartesianDiagramDataCompressor::DataPoint point;
208 point.value = data.first;
209 point.index = data.second;
211 if ( ISNAN( point.key ) || ISNAN( point.value ) )
213 previousCellPosition = CartesianDiagramDataCompressor::CachePosition();
218 for (
int col = column - 1; col >= 0; --col )
220 const qreal y = i.value().at( col ).first;
227 const qreal scalingFactor =
228 qFuzzyIsNull( yValueSums[ i.key() ] ) ? 0.0 :
229 100.0 / yValueSums[ i.key() ];
231 const qreal value = ( point.value + extraY ) * scalingFactor;
233 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
235 const QPointF a( plane->
translate( QPointF( lastPoint.key, lastValue ) ) );
236 const QPointF b( plane->
translate( QPointF( point.key, value ) ) );
237 const QPointF c( plane->
translate( QPointF( lastPoint.key, lastExtraY * scalingFactor ) ) );
238 const QPointF
d( plane->
translate( QPointF( point.key, extraY * scalingFactor ) ) );
240 laCell = diagram()->lineAttributes( sourceIndex );
245 if ( laCell.displayArea() ) {
247 polygon << a << b <<
d << c;
251 if ( !point.hidden ) {
254 if ( !ISNAN( lastPoint.key ) && !ISNAN( lastPoint.value ) )
257 attributesModel()->mapToSource( lastPoint.index ),
258 areas, laCell.transparency() );
259 lineList.append( LineAttributesInfo( sourceIndex, a, b ) );
264 laPreviousCell = laCell;
void paintElements(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const LabelPaintCache &lpc, const LineAttributesInfoList &lineList)
AbstractCoordinatePlane * coordinatePlane() const
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
Plotter defines a diagram type plotting two-dimensional data.
Set of attributes for changing the appearance of line charts.
void paintAreas(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, const QModelIndex &index, const QList< QPolygonF > &areas, uint opacity)
static const Position & NorthWest
Stores information about painting diagrams.
Stores the absolute target points of a Position.
Cartesian coordinate plane.