23 #include "KDChartPercentBarDiagram_p.h" 25 #include <QModelIndex> 34 PercentBarDiagram::PercentBarDiagram(
BarDiagram*
d )
46 const int rowCount = diagram()->model() ? diagram()->model()->rowCount( diagram()->rootIndex() ) : 0;
47 const int colCount = diagram()->model() ? diagram()->model()->columnCount( diagram()->rootIndex() ) : 0;
49 const qreal xMin = 0.0;
50 const qreal xMax = rowCount;
51 const qreal yMin = 0.0;
52 const qreal yMax = 100.0;
56 for (
int row = 0; row < rowCount ; ++row ) {
57 for (
int col = 0; col < colCount; ++col ) {
58 const CartesianDiagramDataCompressor::CachePosition position( row, col );
59 const CartesianDiagramDataCompressor::DataPoint p = compressor().data( position );
60 QModelIndex sourceIndex = attributesModel()->mapToSource( p.index );
63 if ( threeDAttrs.
isEnabled() && threeDAttrs.
depth() > usedDepth ) {
64 usedDepth = threeDAttrs.
depth();
74 reverseMapper().clear();
81 const int rowCount = compressor().modelDataRows();
82 const int colCount = compressor().modelDataColumns();
87 qreal width = boundRight.x() - boundLeft.x();
88 qreal groupWidth = width / rowCount;
89 qreal spaceBetweenBars = 0;
90 qreal spaceBetweenGroups = 0;
94 groupWidth += barWidth;
101 if ( groupWidth * rowCount > width )
102 groupWidth = width / rowCount;
107 qreal maxLimit = rowCount * (groupWidth + ((colCount-1) * ba.
fixedDataValueGap()) );
112 if ( width > maxLimit )
115 spaceBetweenBars = ((width/rowCount) - groupWidth)/(colCount-1);
121 calculateValueAndGapWidths( rowCount, colCount,groupWidth,
122 barWidth, spaceBetweenBars, spaceBetweenGroups );
125 const qreal maxValue = 100;
130 for (
int row = 0; row < rowCount; ++row )
132 for (
int col = 0; col < colCount; ++col )
134 const CartesianDiagramDataCompressor::CachePosition position( row, col );
135 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
137 sumValues += qMax( point.value, -point.value );
138 if ( col == colCount - 1 ) {
139 sumValuesVector << sumValues ;
146 for (
int col = 0; col < colCount; ++col )
148 qreal offset = spaceBetweenGroups;
155 for (
int row = 0; row < rowCount ; ++row )
157 const CartesianDiagramDataCompressor::CachePosition position( row, col );
158 const CartesianDiagramDataCompressor::DataPoint p = compressor().data( position );
159 QModelIndex sourceIndex = attributesModel()->mapToSource( p.index );
164 barWidth = (width - ((offset+(threeDAttrs.
depth()))*rowCount))/ rowCount;
165 if ( barWidth <= 0 ) {
167 maxDepth = offset - ( width/rowCount);
170 barWidth = (width - (offset*rowCount))/ rowCount;
173 const qreal value = qMax( p.value, -p.value );
174 qreal stackedValues = 0.0;
179 for (
int k = col; k >= 0 ; --k )
181 const CartesianDiagramDataCompressor::CachePosition position( row, k );
182 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
183 stackedValues += qMax( point.value, -point.value );
187 QPointF point, previousPoint;
188 if ( sumValuesVector.at( row ) != 0 && value > 0 ) {
190 point.rx() += offset / 2;
192 previousPoint = ctx->
coordinatePlane()->
translate( QPointF( key, ( stackedValues - value)/sumValuesVector.at(row)* maxValue ) );
194 const qreal barHeight = previousPoint.y() - point.y();
196 const QRectF rect( point, QSizeF( barWidth, barHeight ) );
199 paintBars( ctx, sourceIndex, rect, maxDepth );
202 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.
static const Position & North
qreal fixedDataValueGap() const