summaryrefslogtreecommitdiffstats
path: root/stats/boxseries.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-05 12:11:46 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-06 12:31:22 -0800
commit4ab9f1c6b06204285267e79b5ed993514e0213e2 (patch)
tree5e8e792ec76639b1493937d6401bb92d05dabb1c /stats/boxseries.cpp
parent598058e21ebc93834b71cc1b66e881451a596ce6 (diff)
downloadsubsurface-4ab9f1c6b06204285267e79b5ed993514e0213e2.tar.gz
statistics: replace QtCharts' axes
Replace by custom implementation, with the ultimate goal to remove the QtCharts module. This doesn't yet display axis titles or a grid. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'stats/boxseries.cpp')
-rw-r--r--stats/boxseries.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/stats/boxseries.cpp b/stats/boxseries.cpp
index 99651345b..b5e4422ea 100644
--- a/stats/boxseries.cpp
+++ b/stats/boxseries.cpp
@@ -39,7 +39,7 @@ BoxSeries::Item::Item(QtCharts::QChart *chart, BoxSeries *series, double lowerBo
bottomBar.setZValue(ZValues::series);
center.setZValue(ZValues::series);
highlight(false);
- updatePosition(chart, series);
+ updatePosition(series);
}
BoxSeries::Item::~Item()
@@ -59,7 +59,7 @@ void BoxSeries::Item::highlight(bool highlight)
center.setPen(pen);
}
-void BoxSeries::Item::updatePosition(QtCharts::QChart *chart, BoxSeries *series)
+void BoxSeries::Item::updatePosition(BoxSeries *series)
{
double delta = (upperBound - lowerBound) * boxWidth;
double from = (lowerBound + upperBound - delta) / 2.0;
@@ -68,17 +68,17 @@ void BoxSeries::Item::updatePosition(QtCharts::QChart *chart, BoxSeries *series)
QPointF topLeft, bottomRight;
QMarginsF margins(boxBorderWidth / 2.0, boxBorderWidth / 2.0, boxBorderWidth / 2.0, boxBorderWidth / 2.0);
- topLeft = chart->mapToPosition(QPointF(from, q.max), series);
- bottomRight = chart->mapToPosition(QPointF(to, q.min), series);
+ topLeft = series->toScreen(QPointF(from, q.max));
+ bottomRight = series->toScreen(QPointF(to, q.min));
bounding = QRectF(topLeft, bottomRight).marginsAdded(margins);
double left = topLeft.x();
double right = bottomRight.x();
double width = right - left;
double top = topLeft.y();
double bottom = bottomRight.y();
- QPointF q1 = chart->mapToPosition(QPointF(mid, q.q1), series);
- QPointF q2 = chart->mapToPosition(QPointF(mid, q.q2), series);
- QPointF q3 = chart->mapToPosition(QPointF(mid, q.q3), series);
+ QPointF q1 = series->toScreen(QPointF(mid, q.q1));
+ QPointF q2 = series->toScreen(QPointF(mid, q.q2));
+ QPointF q3 = series->toScreen(QPointF(mid, q.q3));
box.setRect(left, q3.y(), width, q1.y() - q3.y());
topWhisker.setLine(q3.x(), top, q3.x(), q3.y());
bottomWhisker.setLine(q1.x(), q1.y(), q1.x(), bottom);
@@ -89,15 +89,13 @@ void BoxSeries::Item::updatePosition(QtCharts::QChart *chart, BoxSeries *series)
void BoxSeries::append(double lowerBound, double upperBound, const StatsQuartiles &q, const QString &binName)
{
- QtCharts::QChart *c = chart();
- items.emplace_back(new Item(c, this, lowerBound, upperBound, q, binName));
+ items.emplace_back(new Item(chart, this, lowerBound, upperBound, q, binName));
}
void BoxSeries::updatePositions()
{
- QtCharts::QChart *c = chart();
for (auto &item: items)
- item->updatePosition(c, this);
+ item->updatePosition(this);
}
// Attention: this supposes that items are sorted by position and no box is inside another box!
@@ -149,7 +147,7 @@ bool BoxSeries::hover(QPointF pos)
Item &item = *items[highlighted];
item.highlight(true);
if (!information)
- information.reset(new InformationBox(chart()));
+ information.reset(new InformationBox(chart));
information->setText(formatInformation(item), pos);
} else {
information.reset();