diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-12 17:37:20 +0100 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-12 17:37:26 +0100 |
commit | a5378abcbb3d8ee8dc3b76380dd50a43a2eec22e (patch) | |
tree | 11f29228bdb020f953fbabcfa397b9254d89db4a | |
parent | 44914a9253408d6903272f69bacac1a9144b0e18 (diff) |
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
-rw-r--r-- | lamp.cpp | 4 | ||||
-rw-r--r-- | main.cpp | 5 | ||||
-rw-r--r-- | scatterplot.cpp | 48 | ||||
-rw-r--r-- | scatterplot.h | 7 |
4 files changed, 54 insertions, 10 deletions
@@ -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); + } } @@ -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<float> &, const LinearScale<float> &)), + subsamplePlot, SLOT(setScale(const LinearScale<float> &, const LinearScale<float> &))); + BarChart *barChart = engine.rootObjects()[0]->findChild<BarChart *>("barChart"); barChart->setValues(arma::randn<arma::vec>(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<float> &sx, const LinearScale<float> &sy, bool updateView) +{ + m_sx = sx; + m_sy = sy; + emit scaleChanged(m_sx, m_sy); + + if (updateView) { + updateGeometry(); + } +} + +void Scatterplot::setScale(const LinearScale<float> &sx, const LinearScale<float> &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<float> &sx, const LinearScale<float> &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<int> &selection) const; void displaySplatChanged(bool displaySplat) const; + void scaleChanged(const LinearScale<float> &sx, const LinearScale<float> &sy) const; public slots: void setXY(const arma::mat &xy); void setColorData(const arma::vec &colorData); void setSelection(const QSet<int> &selection); void setDisplaySplat(bool displaySplat); + void setScale(const LinearScale<float> &sx, const LinearScale<float> &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<float> m_sx, m_sy; enum InteractionState { |