From 20970c35ad137314a2cd2a6abb2f5d9981198171 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 14 Jan 2016 14:24:14 +0100 Subject: BarChart: handle empty data. --- barchart.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/barchart.cpp b/barchart.cpp index 2227d97..efe5747 100644 --- a/barchart.cpp +++ b/barchart.cpp @@ -26,15 +26,18 @@ BarChart::~BarChart() void BarChart::setValues(const arma::vec &values) { m_values = values; - m_scale.setDomain(m_values.min(), m_values.max()); m_originalIndices.resize(m_values.n_elem); - for (int i = 0; i < m_originalIndices.size(); i++) { - m_originalIndices[i] = i; - } + if (m_values.n_elem > 0) { + m_scale.setDomain(m_values.min(), m_values.max()); + + for (int i = 0; i < m_originalIndices.size(); i++) { + m_originalIndices[i] = i; + } - std::sort(m_originalIndices.begin(), m_originalIndices.end(), - [this](int i, int j) { return m_values[i] > m_values[j]; }); + std::sort(m_originalIndices.begin(), m_originalIndices.end(), + [this](int i, int j) { return m_values[i] > m_values[j]; }); + } m_shouldUpdateBars = true; emit valuesChanged(values); -- cgit v1.2.3