diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-14 14:24:14 +0100 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2016-01-14 14:24:14 +0100 |
commit | 20970c35ad137314a2cd2a6abb2f5d9981198171 (patch) | |
tree | fafcfd5a4c6206622f921844211fd6c5c448079e | |
parent | 26c4d3e5974f89fe4c140292d4a9b6c33e42450b (diff) |
BarChart: handle empty data.
-rw-r--r-- | barchart.cpp | 15 |
1 files 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); |