9#include "KChartTernaryGrid.h"
17#include <QApplication>
19#include "TernaryPoint.h"
20#include "TernaryConstants.h"
21#include "KChartPaintContext.h"
22#include "KChartPainterSaver_p.h"
23#include "KChartTernaryCoordinatePlane.h"
24#include "KChartPrintingParameters.h"
28TickInfo::TickInfo( qreal _percentage,
int _depth )
29 : percentage ( _percentage )
34bool KChart::operator==(
const TickInfo& left,
const TickInfo& right)
36 return fabs(
left.percentage -
right.percentage )
37 <= std::numeric_limits<qreal>::epsilon()
41TernaryGrid::TernaryGrid()
46TernaryGrid::~TernaryGrid()
52 static const int GridLineDistanceThreshold = 20;
54 QPainter& painter = *context->painter();
55 PainterSaver s( &painter );
57 Q_ASSERT_X ( plane,
"TernaryGrid::drawGrid",
58 "Bad function call: PaintContext::coodinatePlane() NOT a ternary plane." );
61 const int MaxDepth = 3;
62 qreal xPixels = plane->
translate( TriangleBottomRight ).
x() -
65 if ( xPixels > 10 * GridLineDistanceThreshold ) granularity = 10;
66 if ( xPixels > 20 * GridLineDistanceThreshold ) granularity = 5;
69 for (
int i = granularity; i < 100; i+=granularity )
71 TickInfo tick( ( 1.0 * i ) / 100.0, 2 );
72 if ( i % 10 == 0 ) tick.depth = 1;
73 if ( i % 20 == 0 ) tick.depth = 0;
74 m_tickInfo.append( tick );
78 {
for (
const TickInfo& tick : std::as_const(m_tickInfo) ) {
79 const qreal& percent = tick.percentage;
107 painter.
setPen( PrintingParameters::scalePen(
QPen(
QColor(
"lightgray" ), 1 ) ) );
110 painter.
setPen( PrintingParameters::scalePen(
QPen(
QColor(
"gray" ), 1 ) ) );
113 painter.
setPen( PrintingParameters::scalePen(
QPen(
QColor(
"darkslategray" ), 1 ) ) );
123 points << plane->
translate( TriangleBottomLeft )
124 << plane->
translate( TriangleBottomRight )
143 percentages.erase( std::unique( percentages.begin(), percentages.end() ),
146 {
for (
const TickInfo& tick : std::as_const(percentages) ) {
147 const qreal& percent = tick.percentage;
149 const QPointF markerDistance( FullMarkerDistanceBC
150 / ( tick.depth + 1 ) );
156 const QPointF markerDistance( FullMarkerDistanceAC
157 / ( tick.depth + 1 ) );
158 const QPointF start( TriangleBottomRight + percent * AxisVector_C_A );
165 const QPointF markerDistance( FullMarkerDistanceBA
166 / ( tick.depth +1 ) );
181QPair<QSizeF, QSizeF> TernaryGrid::requiredMargins()
const
184 qreal topMargin = 0.0;
185 qreal leftMargin = fabs( FullMarkerDistanceBA.
x() );
186 qreal bottomMargin = fabs( FullMarkerDistanceBC.
y() );
194 return QPair<QSizeF, QSizeF>
195 (
QSizeF( leftMargin, topMargin ),
196 QSizeF( leftMargin, bottomMargin ) );
Abstract base class for grid classes: cartesian, polar, ...
Stores information about painting diagrams.
Ternary coordinate plane.
const QPointF translate(const QPointF &diagramPoint) const override
Translate the given point in value space coordinates to a position in pixel space.
TernaryPoint defines a point within a ternary coordinate plane.
Q_SCRIPTABLE Q_NOREPLY void start()
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
void append(QList< T > &&value)
void drawLines(const QLine *lines, int lineCount)
void drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fillRule)
void setBrush(Qt::BrushStyle style)
void setPen(Qt::PenStyle style)
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)