summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Kosinski <lukasz@scythe-studio.com>2021-05-26 13:13:41 +0200
committerLukas Kosinski <lukasz@scythe-studio.com>2021-06-02 10:11:18 +0200
commit92b136373dcca34ae2a32872885a84b0833d0143 (patch)
tree8844fa42c3504b7db78d76f03ac4a2e5402cc5e0 /src
parentddbb7743982d47a830283f039b6e85aa8d02e02d (diff)
Add sizeBy method to QXYSeries
This feature adds the availability to pass list of values that will be used to change points's sizes using points configuration feature. Size of the particular point is calculated by mapping corresponding value to range built upon passed values. Then it's adjusted by provided minimum and maximum size. Task-number: QTBUG-89448 Change-Id: I3f2fe4464ace34f64b381cd61184c743814a2f10 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/charts/xychart/qxyseries.cpp39
-rw-r--r--src/charts/xychart/qxyseries.h2
2 files changed, 41 insertions, 0 deletions
diff --git a/src/charts/xychart/qxyseries.cpp b/src/charts/xychart/qxyseries.cpp
index fb4e4138..a6b722b3 100644
--- a/src/charts/xychart/qxyseries.cpp
+++ b/src/charts/xychart/qxyseries.cpp
@@ -865,6 +865,8 @@ void QXYSeries::setPointConfiguration(const int index, const QXYSeries::PointCon
if (conf.contains(key)) {
if (conf[key] != value)
callSignal = true;
+ } else {
+ callSignal = true;
}
conf[key] = value;
@@ -919,6 +921,43 @@ QHash<int, QHash<QXYSeries::PointConfiguration, QVariant>> QXYSeries::pointsConf
}
/*!
+ Sets the points' sizes according to a passed list of values. Values from
+ \a sourceData are sorted and mapped to a point size which is between \a minSize
+ and \a maxSize.
+
+ \note If \a sourceData length is smaller than number of points in the series, then
+ size of the points at the end of the series will stay the same.
+ \sa setPointConfiguration(), pointConfiguration()
+ \since 6.2
+*/
+void QXYSeries::sizeBy(const QList<qreal> &sourceData, const qreal minSize, const qreal maxSize)
+{
+ Q_D(QXYSeries);
+
+ Q_ASSERT(minSize <= maxSize);
+ Q_ASSERT(minSize >= 0);
+
+ qreal min = std::numeric_limits<qreal>::max();
+ qreal max = -std::numeric_limits<qreal>::max();
+ for (const auto &p : sourceData) {
+ min = qMin(min, p);
+ max = qMax(max, p);
+ }
+
+ const qreal range = max - min;
+
+ for (int i = 0; i < sourceData.size() && i < d->m_points.size(); ++i) {
+ qreal pointSize = minSize;
+ if (range != 0) {
+ const qreal startValue = sourceData.at(i) - min;
+ const qreal percentage = startValue / range;
+ pointSize = qMax(minSize, percentage * maxSize);
+ }
+ setPointConfiguration(i, QXYSeries::PointConfiguration::Size, pointSize);
+ }
+}
+
+/*!
Returns true if point at given \a index is among selected points and false otherwise.
\note Selected points are drawn using the selected color if it was specified.
\sa selectedPoints(), setPointSelected(), setSelectedColor()
diff --git a/src/charts/xychart/qxyseries.h b/src/charts/xychart/qxyseries.h
index 4ff7f3cf..f02caa5a 100644
--- a/src/charts/xychart/qxyseries.h
+++ b/src/charts/xychart/qxyseries.h
@@ -169,6 +169,8 @@ public:
QHash<PointConfiguration, QVariant> pointConfiguration(const int index) const;
QHash<int, QHash<PointConfiguration, QVariant>> pointsConfiguration() const;
+ void sizeBy(const QList<qreal> &sourceData, const qreal minSize, const qreal maxSize);
+
Q_SIGNALS:
void clicked(const QPointF &point);
void hovered(const QPointF &point, bool state);