From 91f7cf281d48974d1caa660d734d596e9667ccfd Mon Sep 17 00:00:00 2001 From: milenovic Date: Sat, 25 Jan 2025 16:09:01 -0800 Subject: [PATCH] Dynamic implementation of proper range for depth node colorer resolves #161 --- graph/nodecolorer.cpp | 18 ++++++++---------- graph/nodecolorer.h | 2 -- graph/nodecolorers.h | 13 +++++++------ ui/mainwindow.cpp | 13 ++++++++----- ui/mainwindow.h | 1 + 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/graph/nodecolorer.cpp b/graph/nodecolorer.cpp index 22e3ba27..0abf546b 100644 --- a/graph/nodecolorer.cpp +++ b/graph/nodecolorer.cpp @@ -33,16 +33,10 @@ #include -graph::Scope DepthNodeColorer::m_Scope = graph::Scope::wholeGraph(); - INodeColorer::INodeColorer(NodeColorScheme scheme) : m_graph(g_assemblyGraph), m_scheme(scheme) { } -void INodeColorer::saveScopeReference(graph::Scope& scope) { - DepthNodeColorer::getScope() = scope; -} - std::pair INodeColorer::get(const GraphicsItemNode *node, const GraphicsItemNode *rcNode) { QColor posColor = this->get(node); @@ -81,11 +75,11 @@ QColor DepthNodeColorer::get(const GraphicsItemNode *node) { double depth = deBruijnNode->getDepth(); double lowValue = g_settings->lowDepthValue, highValue = g_settings->highDepthValue; - auto &scope = getScope(); + if (g_settings->autoDepthValue) { - if (scope.graphScope() == DEPTH_RANGE) { - lowValue = scope.minDepth(); - highValue = scope.maxDepth(); + if (m_scope.graphScope() == DEPTH_RANGE) { + lowValue = m_scope.minDepth(); + highValue = m_scope.maxDepth(); } else { lowValue = m_graph->m_firstQuartileDepth; highValue = m_graph->m_thirdQuartileDepth; @@ -96,6 +90,10 @@ QColor DepthNodeColorer::get(const GraphicsItemNode *node) { return tinycolormap::GetColor(fraction, colorMap(g_settings->colorMap)).ConvertToQColor(); } +void DepthNodeColorer::saveScopeReference(graph::Scope& scope) { + m_scope = scope; +} + QColor UniformNodeColorer::get(const GraphicsItemNode *node) { const DeBruijnNode *deBruijnNode = node->m_deBruijnNode; diff --git a/graph/nodecolorer.h b/graph/nodecolorer.h index 27d6bf21..16ff1970 100644 --- a/graph/nodecolorer.h +++ b/graph/nodecolorer.h @@ -53,8 +53,6 @@ class INodeColorer { static std::unique_ptr create(NodeColorScheme scheme); [[nodiscard]] NodeColorScheme scheme() const { return m_scheme; } - - virtual void saveScopeReference(graph::Scope& scope); protected: NodeColorScheme m_scheme; diff --git a/graph/nodecolorers.h b/graph/nodecolorers.h index b8d941ef..0dd71e5b 100644 --- a/graph/nodecolorers.h +++ b/graph/nodecolorers.h @@ -27,17 +27,18 @@ class DepthNodeColorer : public INodeColorer { public: - using INodeColorer::INodeColorer; - + explicit DepthNodeColorer(NodeColorScheme scheme) + : INodeColorer(scheme), + m_scope(graph::Scope::wholeGraph()) + { + } QColor get(const GraphicsItemNode *node) override; [[nodiscard]] const char* name() const override { return "Color by depth"; }; - [[nodiscard]] static graph::Scope &getScope() { - return m_Scope; - } + void saveScopeReference(graph::Scope& scope); private: - static graph::Scope m_Scope; + graph::Scope m_scope; }; class UniformNodeColorer : public INodeColorer { diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 00da97cd..7fb59de8 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -88,7 +88,8 @@ MainWindow::MainWindow(QString fileToLoadOnStartup, bool drawGraphAfterLoad) : QMainWindow(nullptr), ui(new Ui::MainWindow), m_imageFilter("PNG (*.png)"), m_fileToLoadOnStartup(fileToLoadOnStartup), m_drawGraphAfterLoad(drawGraphAfterLoad), - m_uiState(NO_GRAPH_LOADED), m_blastSearchDialog(nullptr), m_alreadyShown(false) + m_uiState(NO_GRAPH_LOADED), m_blastSearchDialog(nullptr), m_alreadyShown(false), + m_scope(graph::Scope::wholeGraph()) { ui->setupUi(this); @@ -1004,7 +1005,7 @@ void MainWindow::drawGraph() { QString errorMessage; g_settings->doubleMode = ui->doubleNodesRadioButton->isChecked(); - auto scope = + m_scope = graph::scope(g_settings->graphScope, ui->startingNodesLineEdit->text(), ui->minDepthSpinBox->value(), ui->maxDepthSpinBox->value(), @@ -1015,7 +1016,7 @@ void MainWindow::drawGraph() { ui->nodeDistanceSpinBox->value()); auto startingNodes = graph::getStartingNodes(&errorTitle, &errorMessage, - *g_assemblyGraph, scope); + *g_assemblyGraph, m_scope); if (!errorMessage.isEmpty()) { QMessageBox::information(this, errorTitle, errorMessage); @@ -1024,8 +1025,7 @@ void MainWindow::drawGraph() { resetScene(); g_assemblyGraph->resetNodes(); - g_assemblyGraph->markNodesToDraw(scope, startingNodes); - g_settings->nodeColorer->saveScopeReference(scope); + g_assemblyGraph->markNodesToDraw(m_scope, startingNodes); layoutGraph(); } @@ -1382,6 +1382,9 @@ void MainWindow::switchColourScheme(int idx) { if (!g_assemblyGraph->m_csvHeaders.empty()) colorer->setColumnIdx(0); ui->tagsComboBox->setVisible(true); + } else if (scheme == DEPTH_COLOUR) { + dynamic_cast(&*g_settings->nodeColorer)->saveScopeReference(m_scope); + ui->tagsComboBox->setVisible(false); } else { ui->tagsComboBox->setVisible(false); } diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 2b3aa7ee..cd138b28 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -71,6 +71,7 @@ class MainWindow : public QMainWindow bool m_drawGraphAfterLoad; UiState m_uiState; GraphSearchDialog * m_blastSearchDialog; + graph::Scope m_scope; bool m_alreadyShown;