23 #include <QModelIndex> 29 #include "KDChartStackedLyingBarDiagram_p.h" 33 StackedLyingBarDiagram::StackedLyingBarDiagram(
BarDiagram*
d )
45 const int rowCount = compressor().modelDataRows();
46 const int colCount = compressor().modelDataColumns();
49 const qreal xMax = rowCount;
54 for (
int row = 0; row < rowCount; ++row ) {
56 qreal stackedValues = 0.0;
57 qreal negativeStackedValues = 0.0;
58 for (
int col = 0; col < colCount; ++col ) {
59 const CartesianDiagramDataCompressor::CachePosition position( row, col );
60 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
62 if ( point.value > 0.0 )
63 stackedValues += point.value;
65 negativeStackedValues += point.value;
71 yMin = negativeStackedValues < 0.0 ? negativeStackedValues : stackedValues;
72 yMax = stackedValues > 0.0 ? stackedValues : negativeStackedValues;
75 yMin = qMin( qMin( yMin, stackedValues ), negativeStackedValues );
76 yMax = qMax( qMax( yMax, stackedValues ), negativeStackedValues );
85 }
else if ( yMax < 0.0 ) {
87 }
else if ( yMin > 0.0 ) {
97 reverseMapper().clear();
104 const int rowCount = compressor().modelDataRows();
105 const int colCount = compressor().modelDataColumns();
110 qreal width = boundLeft.y() - boundRight.y();
111 qreal groupWidth = width / rowCount;
112 qreal spaceBetweenBars = 0;
113 qreal spaceBetweenGroups = 0;
117 groupWidth += barWidth;
121 if ( groupWidth < 0 )
124 if ( groupWidth * rowCount > width )
125 groupWidth = width / rowCount;
130 qreal maxLimit = rowCount * (groupWidth + ((colCount-1) * ba.
fixedDataValueGap()) );
135 if ( ctx->
rectangle().width() > maxLimit )
138 spaceBetweenBars = ((width/rowCount) - groupWidth)/(colCount-1);
144 calculateValueAndGapWidths( rowCount, colCount,groupWidth,
145 barWidth, spaceBetweenBars, spaceBetweenGroups );
148 for (
int row = 0; row < rowCount; ++row )
150 qreal offset = spaceBetweenGroups;
157 for (
int col = 0; col < colCount; ++col )
159 qreal threeDOffset = 0.0;
160 const CartesianDiagramDataCompressor::CachePosition position( row, col );
161 const CartesianDiagramDataCompressor::DataPoint p = compressor().data( position );
163 const QModelIndex index = attributesModel()->mapToSource( p.index );
165 const qreal value = p.value;
166 qreal stackedValues = 0.0;
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 for (
int k = col; k >= 0; --k )
184 const CartesianDiagramDataCompressor::CachePosition position( row, k );
185 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
186 if ( ( p.value >= 0.0 && point.value >= 0.0 ) || ( p.value < 0.0 && point.value < 0.0 ) )
187 stackedValues += point.value;
191 point.ry() -= offset + threeDOffset;
193 const qreal barHeight = point.x() - previousPoint.x();
194 point.rx() -= barHeight;
196 const QRectF rect = QRectF( point, QSizeF( barHeight , barWidth ) ).translated( 1, 0 );
199 paintBars( ctx, index, rect, maxDepth );
202 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