Constrain displayed plot coordinates to within plot
MODIFY
src/cachesim/cacheplotview.cpp
src/cachesim/cacheplotview.cpp
#include <QtCharts/QChart>
#include <QtCharts/QLineSeries>
#include <QtCharts/QSplineSeries>
+#include <QtCharts/QValueAxis>
#include <QtGui/QMouseEvent>
#include <QtGui/QResizeEvent>
#include <QtWidgets/QGraphicsScene>
@@ -13,14 +14,14 @@ void constrainInPlotRange(QPointF& pos, QChart* chart) {
const auto plotValue = chart->mapToValue(pos);
const QPointF chartBottomLeft = chart->mapToPosition({0, 0});
- const QRectF cbr = chart->boundingRect();
- const QPointF chartTopRight = QPointF{chartBottomLeft.x() + cbr.width(), chartBottomLeft.y() + cbr.height()};
+ const QValueAxis* axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first());
+ const QValueAxis* axisX = qobject_cast<QValueAxis*>(chart->axes(Qt::Horizontal).first());
pos.rx() = plotValue.x() < 0 ? chartBottomLeft.x() : pos.x();
pos.ry() = plotValue.y() < 0 ? chartBottomLeft.y() : pos.y();
- pos.rx() = pos.x() > chartTopRight.x() ? chartTopRight.x() : pos.x();
- pos.ry() = pos.y() > chartTopRight.y() ? chartTopRight.y() : pos.y();
+ pos.rx() = plotValue.x() > axisX->max() ? chart->mapToPosition({axisX->max(), 0.0}).x() : pos.x();
+ pos.ry() = plotValue.y() > axisY->max() ? chart->mapToPosition({0.0, axisY->max()}).y() : pos.y();
}
namespace Ripes {

MODIFY
src/cachesim/cacheplotwidget.ui
src/cachesim/cacheplotwidget.ui
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
+ <property name="topMargin">
+ <number>0</number>
+ </property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>

Constrain displayed plot coordinates to within plot