23 #include "KDChartPercentLyingBarDiagram_p.h" 25 #include <QModelIndex> 34 PercentLyingBarDiagram::PercentLyingBarDiagram(
BarDiagram*
d )
50 const qreal xMax = diagram()->model() ? diagram()->model()->rowCount( diagram()->rootIndex() ) : 0;
51 qreal yMin = 0.0, yMax = 100.0;
71 const QPointF bottomLeft( QPointF( yMin, xMin ) );
72 const QPointF topRight( QPointF( yMax, xMax ) );
80 reverseMapper().clear();
87 const int rowCount = compressor().modelDataRows();
88 const int colCount = compressor().modelDataColumns();
93 qreal width = boundLeft.y() - boundRight.y();
94 qreal groupWidth = width / rowCount;
95 qreal spaceBetweenBars = 0;
96 qreal spaceBetweenGroups = 0;
100 groupWidth += barWidth;
104 if ( groupWidth < 0 )
107 if ( groupWidth * rowCount > width )
108 groupWidth = width / rowCount;
113 qreal maxLimit = rowCount * (groupWidth + ((colCount-1) * ba.
fixedDataValueGap()) );
118 if ( width > maxLimit )
121 spaceBetweenBars = ((ctx->
rectangle().width()/rowCount) - groupWidth)/(colCount-1);
127 calculateValueAndGapWidths( rowCount, colCount,groupWidth,
128 barWidth, spaceBetweenBars, spaceBetweenGroups );
131 const qreal maxValue = 100.0;
136 for (
int row = 0; row < rowCount; ++row )
138 for (
int col = 0; col < colCount; ++col )
140 const CartesianDiagramDataCompressor::CachePosition position( row, col );
141 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
143 sumValues += qMax( point.value, -point.value );
144 if ( col == colCount - 1 ) {
145 sumValuesVector << sumValues ;
152 for (
int curRow = rowCount - 1; curRow >= 0; --curRow )
154 qreal offset = spaceBetweenGroups;
161 for (
int col = 0; col < colCount ; ++col )
163 qreal threeDOffset = 0.0;
164 const CartesianDiagramDataCompressor::CachePosition position( curRow, col );
165 const CartesianDiagramDataCompressor::DataPoint p = compressor().data( position );
166 QModelIndex sourceIndex = attributesModel()->mapToSource( p.index );
170 if ( barWidth > 0 ) {
171 barWidth = (width - ((offset+(threeDAttrs.
depth()))*rowCount))/ rowCount;
172 threeDOffset = threeDAttrs.
depth();
174 if ( barWidth <= 0 ) {
176 threeDOffset = (width - (offset*rowCount))/ rowCount;
179 barWidth = (width - (offset*rowCount))/ rowCount;
182 const qreal value = qMax( p.value, -p.value );
183 qreal stackedValues = 0.0;
188 for (
int k = col; k >= 0 ; --k )
190 const CartesianDiagramDataCompressor::CachePosition position( curRow, k );
191 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
192 stackedValues += qMax( point.value, -point.value );
196 QPointF point, previousPoint;
197 if ( sumValuesVector.at( curRow ) != 0 && value > 0 ) {
198 QPointF dataPoint( ( stackedValues / sumValuesVector.at( curRow ) * maxValue ), key );
200 point.ry() -= offset + threeDOffset;
202 previousPoint = ctx->
coordinatePlane()->
translate( QPointF( ( ( stackedValues - value) / sumValuesVector.at( curRow ) * maxValue ), key ) );
205 const qreal barHeight = point.x() - previousPoint.x();
207 point.setX( point.x() - barHeight );
209 const QRectF rect = QRectF( point, QSizeF( barHeight, barWidth ) ).translated( 1, 0 );
212 paintBars( ctx, sourceIndex, rect, maxDepth );
215 m_private->paintDataValueTextsAndMarkers( ctx, lpc,
false );
const QRectF rectangle() const
bool useFixedDataValueGap() const
virtual const QPointF translate(const QPointF &diagramPoint) const =0
Translate the given point in value space coordinates to a position in pixel space.
AbstractCoordinatePlane * coordinatePlane() const
Set of attributes for changing the appearance of bar charts.
qreal fixedValueBlockGap() const
static const Position & South
bool useFixedBarWidth() const
qreal fixedBarWidth() const
BarDiagram defines a common bar diagram.
bool useFixedValueBlockGap() const
Stores information about painting diagrams.
A set of 3D bar attributes.
Stores the absolute target points of a Position.
static const Position & North
qreal fixedDataValueGap() const