1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QtGraphs/qscatterseries.h> |
5 | #include <private/qxypoint_p.h> |
6 | #include <private/qscatterseries_p.h> |
7 | #include <private/qgraphsview_p.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | /*! |
12 | \class QScatterSeries |
13 | \inmodule QtGraphs |
14 | \ingroup graphs_2D |
15 | \brief The QScatterSeries class presents data in scatter graphs. |
16 | |
17 | The scatter data is displayed as a collection of points on the graph. For |
18 | each point, two values are specified that determine its position on the |
19 | horizontal axis and the vertical axis. |
20 | */ |
21 | /*! |
22 | \qmltype ScatterSeries |
23 | \nativetype QScatterSeries |
24 | \inqmlmodule QtGraphs |
25 | \ingroup graphs_qml_2D |
26 | \inherits XYSeries |
27 | |
28 | \brief The ScatterSeries type presents data in scatter graphs. |
29 | |
30 | The scatter data is displayed as a collection of points on the graph. For |
31 | each point, two values are specified that determine its position on the |
32 | horizontal axis and the vertical axis. |
33 | |
34 | \image graphs2d-scatter.png |
35 | |
36 | You can represent scatter data by creating a ScatterSeries inside |
37 | GraphsView. The data can be added to the graph by creating XYPoints as |
38 | children for the ScatterSeries that define the x and y values of each |
39 | point. |
40 | |
41 | \code |
42 | GraphsView { |
43 | anchors.fill: parent |
44 | axisX: ValueAxis { |
45 | max: 3 |
46 | } |
47 | axisY: ValueAxis { |
48 | max: 3 |
49 | } |
50 | |
51 | ScatterSeries { |
52 | color: "#00ff00" |
53 | XYPoint { x: 0.5; y: 0.5 } |
54 | XYPoint { x: 1; y: 1 } |
55 | XYPoint { x: 2; y: 2 } |
56 | XYPoint { x: 2.5; y: 1.5 } |
57 | } |
58 | } |
59 | \endcode |
60 | |
61 | Multiple scatter graphs can be created by adding multiple ScatterSeries |
62 | as children of GraphsView. In such cases only one series should define |
63 | the axis used as multiple definitions only override the earlier ones. |
64 | |
65 | \code |
66 | GraphsView { |
67 | anchors.fill: parent |
68 | ScatterSeries { |
69 | color: "#00ff00" |
70 | axisX: ValueAxis { |
71 | max: 3 |
72 | } |
73 | axisY: ValueAxis { |
74 | max: 3 |
75 | } |
76 | |
77 | XYPoint { x: 0.5; y: 0.5 } |
78 | XYPoint { x: 1; y: 1 } |
79 | XYPoint { x: 2; y: 2 } |
80 | XYPoint { x: 2.5; y: 1.5 } |
81 | } |
82 | |
83 | ScatterSeries { |
84 | color: "#ff0000" |
85 | XYPoint { x: 0.5; y: 3 } |
86 | XYPoint { x: 1; y: 2 } |
87 | XYPoint { x: 2; y: 2.5 } |
88 | XYPoint { x: 2.5; y: 1 } |
89 | } |
90 | } |
91 | \endcode |
92 | */ |
93 | |
94 | /*! |
95 | \qmlproperty Component ScatterSeries::pointDelegate |
96 | Marks points with the given QML component. |
97 | |
98 | \code |
99 | pointDelegate: Image { |
100 | source: "images/happy_box.png" |
101 | } |
102 | \endcode |
103 | */ |
104 | |
105 | QScatterSeries::QScatterSeries(QObject *parent) |
106 | : QXYSeries(*(new QScatterSeriesPrivate()), parent) |
107 | {} |
108 | |
109 | QScatterSeries::~QScatterSeries() {} |
110 | |
111 | QScatterSeries::QScatterSeries(QScatterSeriesPrivate &dd, QObject *parent) |
112 | : QXYSeries(dd, parent) |
113 | {} |
114 | |
115 | void QScatterSeries::componentComplete() |
116 | { |
117 | for (auto *child : children()) { |
118 | if (auto point = qobject_cast<QXYPoint *>(object: child)) |
119 | append(x: point->x(), y: point->y()); |
120 | } |
121 | QAbstractSeries::componentComplete(); |
122 | } |
123 | |
124 | QAbstractSeries::SeriesType QScatterSeries::type() const |
125 | { |
126 | return QAbstractSeries::SeriesType::Scatter; |
127 | } |
128 | |
129 | QScatterSeriesPrivate::QScatterSeriesPrivate() |
130 | { |
131 | } |
132 | |
133 | QT_END_NAMESPACE |
134 | |