24 #include "KDChartTernaryCoordinatePlane_p.h" 30 #include "KDChartPainterSaver_p.h" 40 TernaryCoordinatePlane::Private::Private()
45 TernaryCoordinatePlane::TernaryCoordinatePlane(
Chart* parent )
54 void TernaryCoordinatePlane::init()
60 Q_ASSERT_X ( dynamic_cast<AbstractTernaryDiagram*>( diagram ),
61 "TernaryCoordinatePlane::addDiagram",
"Only ternary " 62 "diagrams can be added to a ternary coordinate plane!" );
70 QRectF diagramNativeRectangle ( QPointF( 0.0, 0.0 ),
74 diagramNativeRectangle.adjust
75 (-margins.first.width(), -margins.first.height(),
76 margins.second.width(), margins.second.height() );
81 QSizeF topleft( 0.0, 0.0 );
82 QSizeF bottomRight( 0.0, 0.0 );
89 topleft = topleft.expandedTo( margin.first );
90 bottomRight = bottomRight.expandedTo( margin.second );
93 d->diagramRectContainer =
94 d->diagramRect.adjusted( topleft.width(),
97 -bottomRight.height() );
102 QPointF zeroZeroPoint =
d->diagramRectContainer.bottomLeft();
103 qreal w =
d->diagramRectContainer.width();
104 qreal h =
d->diagramRectContainer.height();
110 usableWidth = h / diagramNativeRectangle.height();
112 zeroZeroPoint.setX( zeroZeroPoint.x() + ( w - usableWidth ) / 2 );
116 usableHeight = diagramNativeRectangle.height() * w;
117 zeroZeroPoint.setY( zeroZeroPoint.y() - ( h - usableHeight ) / 2 );
121 d->xUnit = usableWidth / diagramNativeRectangle.width();
122 d->yUnit = -usableHeight / diagramNativeRectangle.height();
127 qreal rightShift = -diagramNativeRectangle.x();
128 zeroZeroPoint += QPointF( rightShift *
d->xUnit, descent *
d->yUnit );
131 d->diagramRect.setBottomLeft( zeroZeroPoint );
132 d->diagramRect.setTopRight( QPointF( usableWidth, -usableHeight ) + zeroZeroPoint );
137 return QPointF(
d->diagramRect.bottomLeft().x() + point.x() *
d->xUnit,
138 d->diagramRect.bottomLeft().y() + point.y() *
d->yUnit );
149 return QSizePolicy( QSizePolicy::MinimumExpanding,
150 QSizePolicy::MinimumExpanding );
155 PainterSaver s( painter );
157 painter->setRenderHint(QPainter::Antialiasing,
true );
160 if ( !diags.isEmpty() )
169 Q_ASSERT(
d->grid != 0 );
170 d->grid->drawGrid( &ctx );
173 for (
int i = 0; i < diags.size(); i++ )
175 PainterSaver diagramPainterSaver( painter );
176 diags[i]->paint ( &ctx );
186 TernaryGrid* TernaryCoordinatePlane::grid()
const 188 TernaryGrid* ternaryGrid =
static_cast<TernaryGrid*
>(
d->grid );
189 Q_ASSERT( dynamic_cast<TernaryGrid*>(
d->grid ) );
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
void setPainter(QPainter *painter)
A chart with one or more diagrams.
const qreal TriangleHeight
~TernaryCoordinatePlane() override
QSize minimumSizeHint() const
[reimplemented]
AbstractDiagram defines the interface for diagram classes.
The class for ternary axes.
AbstractDiagram * diagram()
void addDiagram(AbstractDiagram *diagram) override
Adds a diagram to this coordinate plane.
void paint(QPainter *) override
QSizePolicy sizePolicy() const
[reimplemented]
QList< DataDimension > DataDimensionsList
Stores information about painting diagrams.
Base class for diagrams based on a ternary coordinate plane.
DataDimensionsList getDataDimensionsList() const override
QPair< QSizeF, QSizeF > requiredMargins() const
void setCoordinatePlane(AbstractCoordinatePlane *plane)
void setRectangle(const QRectF &rect)
AbstractDiagramList diagrams()
virtual void addDiagram(AbstractDiagram *diagram)
Adds a diagram to this coordinate plane.
void layoutDiagrams() override
Distribute the available space among the diagrams and axes.
QRect areaGeometry() const override
const qreal TriangleWidth
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.