23 #include "KDChartNormalLyingBarDiagram_p.h" 25 #include <QModelIndex> 35 NormalLyingBarDiagram::NormalLyingBarDiagram(
BarDiagram*
d )
48 const int rowCount = compressor().modelDataRows();
49 const int colCount = compressor().modelDataColumns();
51 const qreal xMin = 0.0;
52 const 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 ) );
94 reverseMapper().clear();
101 const int rowCount = attributesModel()->rowCount( attributesModelRootIndex() );
102 const int colCount = attributesModel()->columnCount( attributesModelRootIndex() );
107 qreal width = boundLeft.y() - boundRight.y();
108 qreal groupWidth = width / rowCount;
109 qreal spaceBetweenBars = 0;
110 qreal spaceBetweenGroups = 0;
115 groupWidth += barWidth;
119 if ( groupWidth < 0 )
122 if ( groupWidth * rowCount > width )
123 groupWidth = width / rowCount;
128 qreal maxLimit = rowCount * ( groupWidth + ( colCount - 1 ) * ba.
fixedDataValueGap() );
132 if ( width > maxLimit )
135 spaceBetweenBars = ( width / rowCount - groupWidth ) / ( colCount - 1 );
142 calculateValueAndGapWidths( rowCount, colCount,groupWidth,
143 barWidth, spaceBetweenBars, spaceBetweenGroups );
147 for (
int row = 0; row < rowCount; row++ ) {
148 qreal offset = -groupWidth / 2 + spaceBetweenGroups / 2;
151 if ( spaceBetweenBars > 0 ) {
152 if ( width > maxLimit ) {
155 offset -= ( width / rowCount - groupWidth ) / ( colCount - 1 );
158 offset += barWidth / 2;
162 for (
int column = 0; column < colCount; column++ ) {
164 const CartesianDiagramDataCompressor::CachePosition position( row, column );
165 const CartesianDiagramDataCompressor::DataPoint point = compressor().data( position );
166 const QModelIndex sourceIndex = attributesModel()->mapToSource( point.index );
168 QPointF dataPoint( 0, ( point.key + 0.5 ) );
170 dataPoint.rx() += point.value;
172 QPointF( 0, barWidth );
174 const QRectF rect = QRectF( topLeft, bottomRight ).translated( 1.0, offset );
177 paintBars( ctx, sourceIndex, rect, maxDepth );
179 offset += barWidth + spaceBetweenBars;
182 m_private->paintDataValueTextsAndMarkers( ctx, lpc,
false );
KDChartEnums::PositionValue value() const
Returns an integer value corresponding to this Position.
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.
Stores the absolute target points of a Position.
static const Position & North
qreal fixedDataValueGap() const