23 #include "KDChartNormalLyingBarDiagram_p.h"
25 #include <QModelIndex>
32 using namespace KDChart;
35 NormalLyingBarDiagram::NormalLyingBarDiagram(
BarDiagram*
d )
48 const int rowCount = compressor().modelDataRows();
49 const int colCount = compressor().modelDataColumns();
52 qreal xMax = rowCount;
57 for (
int column = 0; column < colCount; ++column ) {
58 for (
int row = 0; row < rowCount; ++row ) {
59 const CartesianDiagramDataCompressor::CachePosition position( row, column );
60 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
61 const qreal value = ISNAN( point.value ) ? 0.0 : point.value;
70 yMin = qMin( yMin, value );
71 yMax = qMax( yMax, value );
80 }
else if ( yMax < 0.0 ) {
82 }
else if ( yMin > 0.0 ) {
86 const QPointF bottomLeft( QPointF( yMin, xMin ) );
87 const QPointF topRight( QPointF( yMax, xMax ) );
96 reverseMapper().clear();
103 const int rowCount = attributesModel()->rowCount( attributesModelRootIndex() );
104 const int colCount = attributesModel()->columnCount( attributesModelRootIndex() );
109 qreal width = boundLeft.y() - boundRight.y();
110 qreal groupWidth = width / rowCount;
111 qreal spaceBetweenBars = 0;
112 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() );
134 if ( width > maxLimit )
137 spaceBetweenBars = ( width / rowCount - groupWidth ) / ( colCount - 1 );
144 calculateValueAndGapWidths( rowCount, colCount,groupWidth,
145 barWidth, spaceBetweenBars, spaceBetweenGroups );
149 for (
int row = 0; row < rowCount; row++ ) {
150 qreal offset = -groupWidth / 2 + spaceBetweenGroups / 2;
153 if ( spaceBetweenBars > 0 ) {
154 if ( width > maxLimit ) {
157 offset -= ( width / rowCount - groupWidth ) / ( colCount - 1 );
160 offset += barWidth / 2;
164 for (
int column = 0; column < colCount; column++ ) {
166 const CartesianDiagramDataCompressor::CachePosition position( row, column );
167 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
168 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
169 const qreal value = point.value;
172 const qreal barHeight = topPoint.x() - bottomPoint.x();
173 topPoint.ry() += offset;
174 topPoint.rx() -= barHeight;
175 const QRectF rect( topPoint, QSizeF( barHeight, barWidth ) );
178 paintBars( ctx, sourceIndex, rect, maxDepth );
180 offset += barWidth + spaceBetweenBars;
183 m_private->paintDataValueTextsAndMarkers( ctx, lpc,
false );