aboutsummaryrefslogtreecommitdiff
path: root/scatterplot.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2015-05-15 18:10:52 -0300
committerSamuel Fadel <samuelfadel@gmail.com>2015-05-15 18:10:52 -0300
commit0b6df071d94ae8f7c9cdd3c96506a1420129e471 (patch)
treeea73a59457beba89ef6bab2b16d2d679d8dd1078 /scatterplot.cpp
Initial commit. ForceScheme seems bugged.
Diffstat (limited to 'scatterplot.cpp')
-rw-r--r--scatterplot.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/scatterplot.cpp b/scatterplot.cpp
new file mode 100644
index 0000000..e775661
--- /dev/null
+++ b/scatterplot.cpp
@@ -0,0 +1,60 @@
+#include "scatterplot.h"
+
+#include <cstdio>
+#include "glyph.h"
+#include <QSGNode>
+#include <QSGGeometryNode>
+
+const int GLYPH_SIZE = 10;
+
+Scatterplot::Scatterplot()
+{
+ setFlag(QQuickItem::ItemHasContents);
+}
+
+Scatterplot::~Scatterplot()
+{
+}
+
+void Scatterplot::setData(const arma::mat &data)
+{
+ if (data.n_cols != 2)
+ return;
+
+ m_data = data;
+ qreal xmin = m_data.col(0).min(),
+ xmax = m_data.col(0).max(),
+ ymin = m_data.col(1).min(),
+ ymax = m_data.col(1).max();
+
+ for (arma::uword i = 0; i < m_data.n_rows; i++) {
+ arma::rowvec row = m_data.row(i);
+
+ Glyph *glyph = new Glyph();
+
+ glyph->setSize(5);
+ glyph->setX((row[0] - xmin) / (xmax - xmin) * width());
+ glyph->setY((row[1] - ymin) / (ymax - ymin) * height());
+
+ glyph->setParent(this);
+ }
+
+ update();
+}
+
+QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+{
+ QSGNode *node = 0;
+
+ if (!oldNode) {
+ node = new QSGNode;
+ for (QObjectList::const_iterator it = children().begin(); it != children().end(); it++)
+ node->appendChildNode(static_cast<Glyph *>(*it)->updatePaintNode(0, 0));
+ } else {
+ node = static_cast<QSGNode *>(oldNode);
+ }
+
+ node->markDirty(QSGNode::DirtyGeometry);
+
+ return node;
+}