aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lamp.cpp4
-rw-r--r--main.cpp5
-rw-r--r--scatterplot.cpp48
-rw-r--r--scatterplot.h7
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<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 {