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 --- lamp.cpp | 4 ++++ main.cpp | 5 +++++ scatterplot.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- scatterplot.h | 7 +++++++ 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/lamp.cpp b/lamp.cpp index 7d36877..293ce30 100644 --- a/lamp.cpp +++ b/lamp.cpp @@ -54,4 +54,8 @@ void mp::lamp(const arma::mat &X, const arma::uvec &sampleIndices, const arma::m Y(i, arma::span(0, 1)) = (point - Xtil) * M + Ytil; } + + for (arma::uword i = 0; i < sampleSize; i++) { + Y.row(sampleIndices[i]) = Ys.row(i); + } } diff --git a/main.cpp b/main.cpp index 90396ed..3026b1e 100644 --- a/main.cpp +++ b/main.cpp @@ -161,12 +161,17 @@ int main(int argc, char **argv) //QObject::connect(history, SIGNAL(currentItemChanged(const arma::mat &)), // subsamplePlot, SLOT(setXY(const arma::mat &))); + QObject::connect(plot, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), + subsamplePlot, SLOT(setScale(const LinearScale &, const LinearScale &))); + BarChart *barChart = engine.rootObjects()[0]->findChild("barChart"); barChart->setValues(arma::randn(100)); //history->addHistoryItem(Ys); plot->setColorScale(&colorScale); plot->setColorData(labels, false); + + subsamplePlot->setAutoScale(false); subsamplePlot->setColorData(labels(sampleIndices), false); subsamplePlot->setXY(Ys, false); subsamplePlot->update(); 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; } diff --git a/scatterplot.h b/scatterplot.h index fb664a1..1c61656 100644 --- a/scatterplot.h +++ b/scatterplot.h @@ -20,6 +20,8 @@ public: void setColorScale(ColorScale *colorScale); void setXY(const arma::mat &xy, bool updateView); void setColorData(const arma::vec &colorData, bool updateView); + void setScale(const LinearScale &sx, const LinearScale &sy, bool updateView); + void setAutoScale(bool autoScale); Q_INVOKABLE bool saveToFile(const QUrl &url); signals: @@ -28,12 +30,14 @@ signals: void colorDataChanged(const arma::vec &colorData) const; void selectionChanged(const QSet &selection) const; void displaySplatChanged(bool displaySplat) const; + void scaleChanged(const LinearScale &sx, const LinearScale &sy) const; public slots: void setXY(const arma::mat &xy); void setColorData(const arma::vec &colorData); void setSelection(const QSet &selection); void setDisplaySplat(bool displaySplat); + void setScale(const LinearScale &sx, const LinearScale &sy); protected: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); @@ -56,6 +60,9 @@ private: void updateGlyphs(QSGNode *node); arma::mat m_xy; + + void autoScale(); + bool m_autoScale; LinearScale m_sx, m_sy; enum InteractionState { -- cgit v1.2.3