23 #include "KDChartStackedLineDiagram_p.h"
25 #include <QAbstractItemModel>
32 #include "PaintingHelpers_p.h"
34 using namespace KDChart;
38 : LineDiagramType( d )
49 const int rowCount = compressor().modelDataRows();
50 const int colCount = compressor().modelDataColumns();
52 qreal xMax = diagram()->model() ? diagram()->model()->rowCount( diagram()->rootIndex() ) : 0;
53 if ( !diagram()->centerDataPoints() && diagram()->model() )
55 qreal yMin = 0, yMax = 0;
57 bool bStarting =
true;
58 for (
int row = 0; row < rowCount; ++row )
61 qreal stackedValues = 0.0;
62 qreal negativeStackedValues = 0.0;
63 for (
int col = datasetDimension() - 1; col < colCount; col += datasetDimension() ) {
64 const CartesianDiagramDataCompressor::CachePosition position( row, col );
65 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
67 if ( ISNAN( point.value ) )
70 if ( point.value >= 0.0 )
71 stackedValues += point.value;
73 negativeStackedValues += point.value;
82 yMin = qMin( qMin( yMin, negativeStackedValues ), stackedValues );
83 yMax = qMax( qMax( yMax, negativeStackedValues ), stackedValues );
87 const QPointF bottomLeft( xMin, yMin );
88 const QPointF topRight( xMax, yMax );
95 reverseMapper().clear();
97 const int columnCount = compressor().modelDataColumns();
98 const int rowCount = compressor().modelDataRows();
113 LineAttributesInfoList lineList;
118 bool bFirstDataset =
true;
120 for (
int column = 0; column < columnCount; ++column )
122 CartesianDiagramDataCompressor::CachePosition previousCellPosition;
126 QModelIndex indexPreviousCell;
130 for (
int row = 0; row < rowCount; ++row ) {
131 const CartesianDiagramDataCompressor::CachePosition position( row, column );
132 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
133 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
135 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
136 const bool bDisplayCellArea = laCell.
displayArea();
143 qreal stackedValues = 0, nextValues = 0, nextKey = 0;
144 for (
int column2 = column; column2 >= 0; --column2 )
146 const CartesianDiagramDataCompressor::CachePosition position( row, column2 );
147 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
148 if ( !ISNAN( point.value ) )
150 stackedValues += point.value;
154 const qreal interpolation = interpolateMissingValue( position );
155 if ( !ISNAN( interpolation ) )
156 stackedValues += interpolation;
160 if ( row + 1 < rowCount ) {
161 const CartesianDiagramDataCompressor::CachePosition position( row + 1, column2 );
162 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
163 if ( !ISNAN( point.value ) )
165 nextValues += point.value;
169 const qreal interpolation = interpolateMissingValue( position );
170 if ( !ISNAN( interpolation ) )
171 nextValues += interpolation;
177 const QPointF nextPoint = ctx->
coordinatePlane()->
translate( QPointF( diagram()->centerDataPoints() ? point.key + 0.5 : point.key, stackedValues ) );
180 const QPointF ptNorthWest( nextPoint );
181 const QPointF ptSouthWest(
185 : bottomPoints.at( row )
191 if ( row + 1 < rowCount ) {
192 QPointF toPoint = ctx->
coordinatePlane()->
translate( QPointF( diagram()->centerDataPoints() ? nextKey + 0.5 : nextKey, nextValues ) );
193 lineList.append( LineAttributesInfo( sourceIndex, nextPoint, toPoint ) );
194 ptNorthEast = toPoint;
199 : bottomPoints.at( row + 1 )
202 if ( areas.count() && laCell != laPreviousCell ) {
206 if ( bDisplayCellArea ) {
208 poly << ptNorthWest << ptNorthEast << ptSouthEast << ptSouthWest;
210 laPreviousCell = laCell;
211 indexPreviousCell = sourceIndex;
216 ptNorthEast = ptNorthWest;
217 ptSouthEast = ptSouthWest;
220 const PositionPoints pts( ptNorthWest, ptNorthEast, ptSouthEast, ptSouthWest );
221 if ( !ISNAN( point.value ) )
225 if ( areas.count() ) {
229 bottomPoints = points;
230 bFirstDataset =
false;