1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtCharts/QPolarChart>
5#include <QtCharts/QAbstractAxis>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \enum QPolarChart::PolarOrientation
11
12 This enum type specifies the polar orientation of an axis.
13
14 \value PolarOrientationRadial
15 A radial axis, where the values are placed along the radius of the
16 chart, starting at the pole.
17 \value PolarOrientationAngular
18 An angular axis, where the values are placed around the chart.
19*/
20
21/*!
22 \class QPolarChart
23 \inmodule QtCharts
24 \brief The QPolarChart presents data in polar charts.
25
26 Polar charts present data in a circular graph, where the placement of data
27 is based on the angle and distance from the center of the graph, the \e pole.
28
29 \image examples_polarchart.png
30
31 A polar chart is a specialization of QChart that supports line, spline, area,
32 and scatter series, and all axis types supported by them. Each axis can be used
33 either as a radial or an angular axis.
34
35 The first and last tick mark on an angular QValueAxis are co-located at a 0/360 degree angle.
36
37 If the angular distance between two consecutive points in a series is more than 180 degrees,
38 any direct line connecting the two points becomes meaningless, and will not be drawn. Instead,
39 a line will be drawn to and from the center of the chart. Therefore, the axis ranges must be
40 chosen accordingly when displaying line, spline, or area series.
41
42 Polar charts draw all axes of the same orientation in the same position, so using multiple
43 axes of the same orientation can be confusing, unless the extra axes are only used to customize the
44 grid. For example, you can display a highlighted range with a secondary shaded QCategoryAxis
45 or provide unlabeled subticks with a secondary QValueAxis thas has hidden labels.
46
47 \sa QChart
48 */
49
50/*!
51 Constructs a polar chart as a child of \a parent.
52 The properties specified by \a wFlags are passed to the QChart constructor.
53 */
54QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
55 : QChart(QChart::ChartTypePolar, parent, wFlags)
56{
57}
58
59/*!
60 Deletes the polar chart object and its children, such as the series and axis objects added to it.
61 */
62QPolarChart::~QPolarChart()
63{
64}
65
66/*!
67 Returns the axes added for the series \a series with the polar orientation
68 \a polarOrientation. If no series is provided, any axis with the
69 specified polar orientation is returned.
70
71 \sa addAxis()
72 */
73QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const
74{
75 Qt::Orientations orientation;
76 if (polarOrientation.testFlag(flag: PolarOrientationAngular))
77 orientation |= Qt::Horizontal;
78 if (polarOrientation.testFlag(flag: PolarOrientationRadial))
79 orientation |= Qt::Vertical;
80
81 return QChart::axes(orientation, series);
82}
83
84/*!
85 This convenience method adds the axis \a axis to the polar chart with the polar
86 orientation \a polarOrientation.
87 The chart takes the ownership of the axis.
88
89 \note Axes can be added to a polar chart also with QChart::addAxis().
90 The specified alignment determines the polar orientation: horizontal alignments indicate
91 an angular axis and vertical alignments indicate a radial axis.
92
93 \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis()
94*/
95void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation)
96{
97 if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) {
98 qWarning(msg: "QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts.");
99 } else {
100 Qt::Alignment alignment = Qt::AlignLeft;
101 if (polarOrientation == PolarOrientationAngular)
102 alignment = Qt::AlignBottom;
103 QChart::addAxis(axis, alignment);
104 }
105}
106
107/*!
108 The angular axes of a polar chart report horizontal orientation and the radial axes report
109 vertical orientation.
110 This function is a convenience function for converting the orientation of the axis \a axis to
111 the corresponding polar orientation. If the \a axis is null or not added to a polar chart,
112 the return value is meaningless.
113*/
114QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis)
115{
116 if (axis && axis->orientation() == Qt::Horizontal)
117 return PolarOrientationAngular;
118 else
119 return PolarOrientationRadial;
120}
121
122QT_END_NAMESPACE
123
124#include "moc_qpolarchart.cpp"
125

source code of qtcharts/src/charts/qpolarchart.cpp