From a5378abcbb3d8ee8dc3b76380dd50a43a2eec22e Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 12 Jan 2016 17:37:20 +0100 Subject: Scatterplot: autoscaling & signals. * Added methods & signal/slots to handle auto/manual scaling * The subsample plot is now scaled by the full data plot, naturally superimposing them * LAMP was corrected in order to always preserve the mapping of the subsample --- scatterplot.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'scatterplot.cpp') diff --git a/scatterplot.cpp b/scatterplot.cpp index cad93c7..c85e19f 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -15,6 +15,7 @@ static const float PADDING = 10.f; Scatterplot::Scatterplot(QQuickItem *parent) : QQuickItem(parent) + , m_autoScale(true) , m_sx(0, 1, 0, 1) , m_sy(0, 1, 0, 1) , m_currentInteractionState(INTERACTION_NONE) @@ -63,18 +64,12 @@ void Scatterplot::setXY(const arma::mat &xy, bool updateView) } m_xy = xy; - - float min, max; - min = m_xy.col(0).min(); - max = m_xy.col(0).max(); - m_sx.setDomain(min, max); - - min = m_xy.col(1).min(); - max = m_xy.col(1).max(); - m_sy.setDomain(min, max); - emit xyChanged(m_xy); + if (m_autoScale) { + autoScale(); + } + if (updateView) { updateGeometry(); } @@ -104,6 +99,38 @@ void Scatterplot::setColorData(const arma::vec &colorData) setColorData(colorData, true); } +void Scatterplot::setAutoScale(bool autoScale) +{ + m_autoScale = autoScale; + if (autoScale) { + this->autoScale(); + } +} + +void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sy, bool updateView) +{ + m_sx = sx; + m_sy = sy; + emit scaleChanged(m_sx, m_sy); + + if (updateView) { + updateGeometry(); + } +} + +void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sy) +{ + setScale(sx, sy, true); +} + +void Scatterplot::autoScale() +{ + m_sx.setDomain(m_xy.col(0).min(), m_xy.col(0).max()); + m_sy.setDomain(m_xy.col(1).min(), m_xy.col(1).max()); + + emit scaleChanged(m_sx, m_sy); +} + void Scatterplot::updateGeometry() { m_shouldUpdateGeometry = true; @@ -209,6 +236,7 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { QSGNode *root = oldNode ? oldNode : newSceneGraph(); + qDebug() << "updatePaintNode: " << this; if (m_xy.n_rows < 1) { return root; } -- cgit v1.2.3