2
KDChart - a multi-platform charting engine
5
/****************************************************************************
6
** Copyright (C) 2005-2007 Klarälvdalens Datakonsult AB. All rights reserved.
8
** This file is part of the KD Chart library.
10
** This file may be used under the terms of the GNU General Public
11
** License versions 2.0 or 3.0 as published by the Free Software
12
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
13
** included in the packaging of this file. Alternatively you may (at
14
** your option) use any later version of the GNU General Public
15
** License if such license has been publicly approved by
16
** Klarälvdalens Datakonsult AB (or its successors, if any).
18
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
19
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
20
** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
21
** not expressly granted herein.
23
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26
**********************************************************************/
28
#include "KDChartTernaryLineDiagram.h"
29
#include "KDChartTernaryLineDiagram_p.h"
35
#include <KDChartPaintContext>
37
#include "KDChartLineAttributes.h"
38
#include "KDChartDataValueAttributes.h"
39
#include "KDChartMarkerAttributes.h"
40
#include "TernaryPoint.h"
41
#include "TernaryConstants.h"
42
#include "KDChartPainterSaver_p.h"
44
using namespace KDChart;
48
TernaryLineDiagram::Private::Private()
49
: AbstractTernaryDiagram::Private()
53
TernaryLineDiagram::TernaryLineDiagram ( QWidget* parent,
54
TernaryCoordinatePlane* plane )
55
: AbstractTernaryDiagram( new Private(), parent, plane )
58
setDatasetDimensionInternal( 3 ); // the third column is implicit
60
DataValueAttributes dataValueAttributes;
61
dataValueAttributes.setVisible( true );
62
MarkerAttributes markerAttributes;
63
markerAttributes.setMarkerStyle( MarkerAttributes::MarkerCircle );
64
markerAttributes.setVisible( true );
65
dataValueAttributes.setMarkerAttributes( markerAttributes );
66
attributesModel()->setDefaultForRole(
67
KDChart::DataValueLabelAttributesRole,
68
qVariantFromValue( dataValueAttributes ) );
71
TernaryLineDiagram::~TernaryLineDiagram()
75
void TernaryLineDiagram::init()
79
void TernaryLineDiagram::resize (const QSizeF& area)
84
void TernaryLineDiagram::paint (PaintContext *paintContext)
86
d->reverseMapper.clear();
88
d->paint( paintContext );
90
if ( model() == 0 ) return;
92
QPainter* p = paintContext->painter();
95
TernaryCoordinatePlane* plane =
96
(TernaryCoordinatePlane*) paintContext->coordinatePlane();
102
// for some reason(?) TernaryPointDiagram is using per-diagram DVAs only:
103
const DataValueAttributes attrs( dataValueAttributes() );
106
d->clearListOfAlreadyDrawnDataValueTexts();
108
int columnCount = model()->columnCount( rootIndex() );
110
for(int column=0; column<columnCount; column+=datasetDimension() )
112
int numrows = model()->rowCount( rootIndex() );
113
for( int row = 0; row < numrows; row++ )
115
// see if there is data otherwise skip
116
QModelIndex base = model()->index( row, column );
117
if( ! model()->data( base ).isNull() )
119
p->setPen( PrintingParameters::scalePen( pen( base ) ) );
120
p->setBrush( brush( base ) );
123
x = qMax( model()->data( model()->index( row, column, rootIndex() ) ).toDouble(),
125
y = qMax( model()->data( model()->index( row, column+1, rootIndex() ) ).toDouble(),
127
z = qMax( model()->data( model()->index( row, column+2, rootIndex() ) ).toDouble(),
130
double total = x + y + z;
131
if ( fabs( total ) > 3 * std::numeric_limits<double>::epsilon() ) {
132
TernaryPoint tPunkt( x / total, y / total );
133
QPointF diagramLocation = translate( tPunkt );
134
QPointF widgetLocation = plane->translate( diagramLocation );
137
p->drawLine( start, widgetLocation );
139
paintMarker( p, model()->index( row, column, rootIndex() ), widgetLocation );
140
start = widgetLocation;
141
// retrieve text and data value attributes
142
// FIXME use data model DisplayRole text
143
QString text = tr( "(%1, %2, %3)" )
144
.arg( x * 100, 0, 'f', 0 )
145
.arg( y * 100, 0, 'f', 0 )
146
.arg( z * 100, 0, 'f', 0 );
147
d->paintDataValueText( this, p, attrs, widgetLocation, text, true );
149
// ignore and do not paint this point, garbage data
150
qDebug() << "TernaryPointDiagram::paint: data point x/y/z:"
151
<< x << "/" << y << "/" << z << "ignored, unusable.";
158
const QPair< QPointF, QPointF > TernaryLineDiagram::calculateDataBoundaries () const
160
// this is a constant, because we defined it to be one:
161
static QPair<QPointF, QPointF> Boundaries(
163
QPointF( TriangleBottomRight.x(), TriangleHeight ) );