From d9d0beb9069d0e1e40499bcfd12b8204d4356b04 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 13 Jan 2016 12:04:55 +0100 Subject: Scatterplot: individual glyph opacity methods & signals. * Removed code that handles selection coordination between cpPlot and full data plot from main * Full plot has control points invisible (opacity = 0) by default --- scatterplot.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'scatterplot.cpp') diff --git a/scatterplot.cpp b/scatterplot.cpp index d779182..fae97e3 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -10,8 +10,8 @@ static const qreal GLYPH_OPACITY_SELECTED = 1.0; static const QColor OUTLINE_COLOR(0, 0, 0); static const QColor SELECTION_COLOR(128, 128, 128, 96); -static const int GLYPH_SIZE = 6.f; -static const float PADDING = 10.f; +static const int GLYPH_SIZE = 4.0f; +static const float PADDING = 10.0f; Scatterplot::Scatterplot(QQuickItem *parent) : QQuickItem(parent) @@ -70,6 +70,12 @@ void Scatterplot::setXY(const arma::mat &xy, bool updateView) autoScale(); } + if (m_opacityData.n_elem != m_xy.n_rows) { + arma::vec opacityData(xy.n_rows); + opacityData.fill(GLYPH_OPACITY); + setOpacityData(opacityData, false); + } + if (updateView) { updateGeometry(); } @@ -107,6 +113,25 @@ void Scatterplot::setAutoScale(bool autoScale) } } +void Scatterplot::setOpacityData(const arma::vec &opacityData, bool updateView) +{ + if (m_xy.n_rows > 0 && opacityData.n_elem != m_xy.n_rows) { + return; + } + + m_opacityData = opacityData; + emit opacityDataChanged(m_opacityData); + + if (updateView) { + update(); + } +} + +void Scatterplot::setOpacityData(const arma::vec &opacityData) +{ + setOpacityData(opacityData, true); +} + void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sy, bool updateView) { m_sx = sx; @@ -320,7 +345,7 @@ void Scatterplot::updateGlyphs(QSGNode *glyphsNode) bool isSelected = m_selectedGlyphs.contains(i); QSGOpacityNode *glyphOpacityNode = static_cast(node); - glyphOpacityNode->setOpacity(isSelected ? GLYPH_OPACITY_SELECTED : GLYPH_OPACITY); + glyphOpacityNode->setOpacity(m_opacityData[i]); QSGGeometryNode *glyphOutlineNode = static_cast(node->firstChild()); QSGGeometryNode *glyphNode = static_cast(node->firstChild()->nextSibling()); @@ -452,6 +477,10 @@ bool Scatterplot::updateSelection(bool mergeSelection) void Scatterplot::setSelection(const QSet &selection) { m_selectedGlyphs = selection; + for (auto it = m_selectedGlyphs.cbegin(); + it != m_selectedGlyphs.cend(); it++) { + m_opacityData[*it] = GLYPH_OPACITY_SELECTED; + } update(); emit selectionChanged(selection); -- cgit v1.2.3