23 #include <QModelIndex> 29 #include "KDChartStackedBarDiagram_p.h" 33 StackedBarDiagram::StackedBarDiagram(
BarDiagram*
d )
45 const int rowCount = compressor().modelDataRows();
46 const int colCount = compressor().modelDataColumns();
48 const qreal xMin = 0.0;
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 );
61 const double value = ISNAN( point.value ) ? 0.0 : point.value;
64 stackedValues += value;
66 negativeStackedValues += value;
73 yMin = negativeStackedValues < 0.0 ? negativeStackedValues : stackedValues;
74 yMax = stackedValues > 0.0 ? stackedValues : negativeStackedValues;
77 yMin = qMin( qMin( yMin, stackedValues ), negativeStackedValues );
78 yMax = qMax( qMax( yMax, stackedValues ), negativeStackedValues );
87 }
else if ( yMax < 0.0 ) {
89 }
else if ( yMin > 0.0 ) {
99 reverseMapper().clear();
106 const int rowCount = compressor().modelDataRows();
107 const int colCount = compressor().modelDataColumns();
112 qreal width = boundRight.x() - boundLeft.x();
113 qreal groupWidth = width / rowCount;
114 qreal spaceBetweenBars = 0;
115 qreal spaceBetweenGroups = 0;
119 groupWidth += barWidth;
123 if ( groupWidth < 0 )
126 if ( groupWidth * rowCount > width )
127 groupWidth = width / rowCount;
132 qreal maxLimit = rowCount * (groupWidth + ((colCount-1) * ba.
fixedDataValueGap()) );
137 if ( width > maxLimit )
140 spaceBetweenBars = ((width/rowCount) - groupWidth)/(colCount-1);
146 calculateValueAndGapWidths( rowCount, colCount,groupWidth,
147 barWidth, spaceBetweenBars, spaceBetweenGroups );
150 for (
int col = 0; col < colCount; ++col )
152 qreal offset = spaceBetweenGroups;
159 for (
int row = 0; row < rowCount; ++row )
161 const CartesianDiagramDataCompressor::CachePosition position( row, col );
162 const CartesianDiagramDataCompressor::DataPoint p = compressor().data( position );
164 const QModelIndex index = attributesModel()->mapToSource( p.index );
166 const qreal value = p.value;
167 qreal stackedValues = 0.0;
172 barWidth = (width - ((offset+(threeDAttrs.
depth()))*rowCount))/ rowCount;
173 if ( barWidth <= 0 ) {
175 maxDepth = offset - (width/rowCount);
178 barWidth = (width - (offset*rowCount))/ rowCount ;
181 for (
int k = col; k >= 0; --k )
183 const CartesianDiagramDataCompressor::CachePosition position( row, k );
184 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
185 if ( !ISNAN( point.value ) && (( p.value >= 0.0 && point.value >= 0.0 ) || ( p.value < 0.0 && point.value < 0.0 )) )
186 stackedValues += point.value;
192 const qreal usedDepth = threeDAttrs.
depth();
196 const qreal dy = point.y() - usedDepth;
198 threeDAttrs.
setDepth( point.y() - 1 );
199 diagram()->setThreeDBarAttributes( threeDAttrs );
202 point.rx() += offset / 2;
204 const qreal barHeight = previousPoint.y() - point.y();
206 const QRectF rect( point, QSizeF( barWidth , barHeight ) );
209 paintBars( ctx, index, rect, maxDepth );
213 m_private->paintDataValueTextsAndMarkers( ctx, lpc,
false );
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.
void setDepth(qreal depth)
static const Position & North
qreal fixedDataValueGap() const