diff --git a/tools/cabana/chartswidget.cc b/tools/cabana/chartswidget.cc index 3029d9db89..5d530a8c8a 100644 --- a/tools/cabana/chartswidget.cc +++ b/tools/cabana/chartswidget.cc @@ -420,34 +420,35 @@ void ChartView::mouseMoveEvent(QMouseEvent *ev) { const auto plot_area = chart()->plotArea(); if (!is_zooming && plot_area.contains(ev->pos())) { - double sec = chart()->mapToValue(ev->pos()).x(); QStringList text_list; - QPointF pos = plot_area.bottomRight(); - double tm = 0.0; - + QPointF pos = {}; + const double sec = chart()->mapToValue(ev->pos()).x(); for (auto &s : sigs) { - auto value = std::upper_bound(s.vals.begin(), s.vals.end(), sec, [](double x, auto &p) { return x < p.x(); }); - if (value != s.vals.end()) { - text_list.push_back(QString(" %1 : %2 ").arg(sigs.size() > 1 ? s.sig->name.c_str() : "Value").arg(value->y())); - tm = value->x(); - auto y_pos = chart()->mapToPosition(*value); - if (y_pos.y() < pos.y()) pos = y_pos; + QString value = "--"; + // use reverse iterator to find last item <= sec. + auto it = std::lower_bound(s.vals.rbegin(), s.vals.rend(), sec, [](auto &p, double x) { return p.x() > x; }); + if (it != s.vals.rend() && it->x() >= axis_x->min()) { + value = QString::number(it->y()); + auto value_pos = chart()->mapToPosition(*it); + if (value_pos.x() > pos.x()) pos = value_pos; } + text_list.push_back(QString(" %1 : %2 ").arg(sigs.size() > 1 ? s.sig->name.c_str() : "Value").arg(value)); } + if (pos.x() == 0) pos = ev->pos(); - if (!text_list.isEmpty()) { - value_text->setHtml("