Cabana: display dashes if no value available (#26557)

show dot if no value
old-commit-hash: efbfbc0622
taco
Dean Lee 2 years ago committed by GitHub
parent 7bf05bc4d2
commit dfdede362f
  1. 45
      tools/cabana/chartswidget.cc

@ -420,34 +420,35 @@ void ChartView::mouseMoveEvent(QMouseEvent *ev) {
const auto plot_area = chart()->plotArea(); const auto plot_area = chart()->plotArea();
if (!is_zooming && plot_area.contains(ev->pos())) { if (!is_zooming && plot_area.contains(ev->pos())) {
double sec = chart()->mapToValue(ev->pos()).x();
QStringList text_list; QStringList text_list;
QPointF pos = plot_area.bottomRight(); QPointF pos = {};
double tm = 0.0; const double sec = chart()->mapToValue(ev->pos()).x();
for (auto &s : sigs) { for (auto &s : sigs) {
auto value = std::upper_bound(s.vals.begin(), s.vals.end(), sec, [](double x, auto &p) { return x < p.x(); }); QString value = "--";
if (value != s.vals.end()) { // use reverse iterator to find last item <= sec.
text_list.push_back(QString("&nbsp;%1 : %2&nbsp;").arg(sigs.size() > 1 ? s.sig->name.c_str() : "Value").arg(value->y())); auto it = std::lower_bound(s.vals.rbegin(), s.vals.rend(), sec, [](auto &p, double x) { return p.x() > x; });
tm = value->x(); if (it != s.vals.rend() && it->x() >= axis_x->min()) {
auto y_pos = chart()->mapToPosition(*value); value = QString::number(it->y());
if (y_pos.y() < pos.y()) pos = y_pos; auto value_pos = chart()->mapToPosition(*it);
if (value_pos.x() > pos.x()) pos = value_pos;
} }
text_list.push_back(QString("&nbsp;%1 : %2&nbsp;").arg(sigs.size() > 1 ? s.sig->name.c_str() : "Value").arg(value));
} }
if (pos.x() == 0) pos = ev->pos();
if (!text_list.isEmpty()) { QString time = QString::number(chart()->mapToValue(pos).x(), 'f', 3);
value_text->setHtml("<div style=\"background-color: darkGray;color: white;\">&nbsp;Time: " + value_text->setHtml(QString("<div style=\"background-color: darkGray;color: white;\">&nbsp;Time: %1 &nbsp;<br />%2</div>")
QString::number(tm, 'f', 3) + "&nbsp;<br />" + text_list.join("<br />") + "</div>"); .arg(time).arg(text_list.join("<br />")));
track_line->setLine(pos.x(), plot_area.top(), pos.x(), plot_area.bottom());
int text_x = pos.x() + 8; QRectF text_rect = value_text->boundingRect();
QRectF text_rect = value_text->boundingRect(); int text_x = pos.x() + 8;
if ((text_x + text_rect.width()) > plot_area.right()) { if ((text_x + text_rect.width()) > plot_area.right()) {
text_x = pos.x() - text_rect.width() - 8; text_x = pos.x() - text_rect.width() - 8;
}
value_text->setPos(text_x, pos.y() - text_rect.height() / 2);
track_ellipse->setRect(pos.x() - 5, pos.y() - 5, 10, 10);
} }
item_group->setVisible(!text_list.isEmpty()); value_text->setPos(text_x, pos.y() - text_rect.height() / 2);
track_line->setLine(pos.x(), plot_area.top(), pos.x(), plot_area.bottom());
track_ellipse->setRect(pos.x() - 5, pos.y() - 5, 10, 10);
item_group->setVisible(true);
} else { } else {
item_group->setVisible(false); item_group->setVisible(false);
} }

Loading…
Cancel
Save