From 0b6df071d94ae8f7c9cdd3c96506a1420129e471 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Fri, 15 May 2015 18:10:52 -0300 Subject: Initial commit. ForceScheme seems bugged. --- scatterplot.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 scatterplot.cpp (limited to 'scatterplot.cpp') 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 +#include "glyph.h" +#include +#include + +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(*it)->updatePaintNode(0, 0)); + } else { + node = static_cast(oldNode); + } + + node->markDirty(QSGNode::DirtyGeometry); + + return node; +} -- cgit v1.2.3