23 #include "KDChartPercentLineDiagram_p.h"
25 #include <QModelIndex>
32 #include "PaintingHelpers_p.h"
34 using namespace KDChart;
38 : LineDiagramType( d )
49 const qreal xMin = 0.0;
50 qreal xMax = diagram()->model() ? diagram()->model()->rowCount( diagram()->rootIndex() ) : 0;
51 if ( !diagram()->centerDataPoints() && diagram()->model() )
53 const qreal yMin = 0.0;
54 const qreal yMax = 100.0;
56 QPointF bottomLeft( QPointF( xMin, yMin ) );
57 QPointF topRight( QPointF( xMax, yMax ) );
63 reverseMapper().clear();
65 const int columnCount = compressor().modelDataColumns();
66 const int rowCount = compressor().modelDataRows();
77 maxFound = columnCount;
79 const int lastVisibleColumn = maxFound - 1;
82 LineAttributesInfoList lineList;
91 for (
int row = 0; row < rowCount; ++row )
93 for (
int col = 0; col < columnCount; ++col )
95 const CartesianDiagramDataCompressor::CachePosition position( row, col );
96 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
97 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
98 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
101 point.value = interpolateMissingValue( position );
102 if ( point.value > 0 )
103 sumValues += point.value;
104 if ( col == lastVisibleColumn )
106 percentSumValues << sumValues ;
113 bool bFirstDataset =
true;
115 for (
int column = 0; column < columnCount; ++column )
119 QModelIndex indexPreviousCell;
123 for (
int row = 0; row < rowCount; ++row )
125 const CartesianDiagramDataCompressor::CachePosition position( row, column );
126 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
127 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
128 const LineAttributes laCell = diagram()->lineAttributes( sourceIndex );
129 const bool bDisplayCellArea = laCell.
displayArea();
131 qreal stackedValues = 0, nextValues = 0, nextKey = 0;
132 for (
int column2 = column;
136 const CartesianDiagramDataCompressor::CachePosition position( row, column2 );
137 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
141 point.value = interpolateMissingValue( position );
143 const qreal val = point.value;
145 stackedValues += val;
147 if ( row + 1 < rowCount ) {
148 const CartesianDiagramDataCompressor::CachePosition position( row + 1, column2 );
149 CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
153 point.value = interpolateMissingValue( position );
155 const qreal val = point.value;
161 if ( percentSumValues.at( row ) != 0 )
162 stackedValues = stackedValues / percentSumValues.at( row ) * maxValue;
166 QPointF nextPoint = ctx->
coordinatePlane()->
translate( QPointF( diagram()->centerDataPoints() ? point.key + 0.5 : point.key, stackedValues ) );
169 const QPointF ptNorthWest( nextPoint );
170 const QPointF ptSouthWest(
174 : bottomPoints.at( row )
180 if ( row + 1 < rowCount ) {
181 if ( percentSumValues.at( row + 1 ) != 0 )
182 nextValues = nextValues / percentSumValues.at( row + 1 ) * maxValue;
185 QPointF toPoint = ctx->
coordinatePlane()->
translate( QPointF( diagram()->centerDataPoints() ? nextKey + 0.5 : nextKey, nextValues ) );
186 lineList.append( LineAttributesInfo( sourceIndex, nextPoint, toPoint ) );
187 ptNorthEast = toPoint;
192 : bottomPoints.at( row + 1 )
195 if ( areas.count() && laCell != laPreviousCell ) {
199 if ( bDisplayCellArea ) {
201 poly << ptNorthWest << ptNorthEast << ptSouthEast << ptSouthWest;
203 laPreviousCell = laCell;
204 indexPreviousCell = sourceIndex;
209 ptNorthEast = ptNorthWest;
210 ptSouthEast = ptSouthWest;
213 if ( !ISNAN( point.value ) )
215 const PositionPoints pts( ptNorthWest, ptNorthEast, ptSouthEast, ptSouthWest );
220 if ( areas.count() ) {
224 bottomPoints = points;
225 bFirstDataset =
false;