mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-20 21:42:05 +08:00
cabana: extend color palette, make chart colors match signal view (#27258)
* cabana: extend color palette, make chart colors match signal view * vary saturation too * cleanup
This commit is contained in:
@@ -173,7 +173,6 @@ void BinaryViewModel::refresh() {
|
||||
if ((dbc_msg = dbc()->msg(msg_id))) {
|
||||
row_count = dbc_msg->size;
|
||||
items.resize(row_count * column_count);
|
||||
int i = 0;
|
||||
for (auto sig : dbc_msg->getSignals()) {
|
||||
auto [start, end] = getSignalRange(sig);
|
||||
for (int j = start; j <= end; ++j) {
|
||||
@@ -185,10 +184,9 @@ void BinaryViewModel::refresh() {
|
||||
}
|
||||
if (j == start) sig->is_little_endian ? items[idx].is_lsb = true : items[idx].is_msb = true;
|
||||
if (j == end) sig->is_little_endian ? items[idx].is_msb = true : items[idx].is_lsb = true;
|
||||
items[idx].bg_color = getColor(i);
|
||||
items[idx].bg_color = getColor(sig);
|
||||
items[idx].sigs.push_back(sig);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
} else {
|
||||
row_count = can->lastMessage(msg_id).dat.size();
|
||||
|
||||
@@ -525,6 +525,7 @@ void ChartView::updateSeries(const Signal *sig, const std::vector<Event *> *even
|
||||
s.vals.clear();
|
||||
s.vals.reserve(settings.max_cached_minutes * 60 * 100); // [n]seconds * 100hz
|
||||
s.last_value_mono_time = 0;
|
||||
s.series->setColor(getColor(sig));
|
||||
}
|
||||
|
||||
struct Chunk {
|
||||
|
||||
@@ -49,7 +49,7 @@ QVariant HistoryLogModel::headerData(int section, Qt::Orientation orientation, i
|
||||
}
|
||||
return show_signals ? QString::fromStdString(sigs[section - 1]->name).replace('_', ' ') : "Data";
|
||||
} else if (role == Qt::BackgroundRole && section > 0 && show_signals) {
|
||||
return QBrush(QColor(getColor(section - 1)));
|
||||
return QBrush(getColor(sigs[section - 1]));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -279,7 +279,7 @@ void SignalItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
||||
}
|
||||
|
||||
// color label
|
||||
auto bg_color = QColor(getColor(item->row()));
|
||||
auto bg_color = getColor(item->sig);
|
||||
QRect rc{option.rect.left() + 3, option.rect.top(), 22, option.rect.height()};
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(item->highlight ? bg_color.darker(125) : bg_color);
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include <QApplication>
|
||||
#include <QFontDatabase>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
@@ -96,6 +100,17 @@ void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||
}
|
||||
}
|
||||
|
||||
QColor getColor(const Signal *sig) {
|
||||
float h = 19 * (float)sig->lsb / 64.0;
|
||||
h = fmod(h, 1.0);
|
||||
|
||||
size_t hash = qHash(QString::fromStdString(sig->name));
|
||||
float s = 0.25 + 0.25 * (float)(hash & 0xff) / 255.0;
|
||||
float v = 0.75 + 0.25 * (float)((hash >> 8) & 0xff) / 255.0;
|
||||
|
||||
return QColor::fromHsvF(h, s, v);
|
||||
}
|
||||
|
||||
NameValidator::NameValidator(QObject *parent) : QRegExpValidator(QRegExp("^(\\w+)"), parent) { }
|
||||
|
||||
QValidator::State NameValidator::validate(QString &input, int &pos) const {
|
||||
|
||||
+3
-5
@@ -7,6 +7,8 @@
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QVector>
|
||||
|
||||
#include "opendbc/can/common_dbc.h"
|
||||
|
||||
class ChangeTracker {
|
||||
public:
|
||||
void compute(const QByteArray &dat, double ts, uint32_t freq);
|
||||
@@ -33,11 +35,7 @@ public:
|
||||
|
||||
inline QString toHex(const QByteArray &dat) { return dat.toHex(' ').toUpper(); }
|
||||
inline char toHex(uint value) { return "0123456789ABCDEF"[value & 0xF]; }
|
||||
inline const QString &getColor(int i) {
|
||||
// TODO: add more colors
|
||||
static const QString SIGNAL_COLORS[] = {"#9FE2BF", "#40E0D0", "#6495ED", "#CCCCFF", "#FF7F50", "#FFBF00"};
|
||||
return SIGNAL_COLORS[i % std::size(SIGNAL_COLORS)];
|
||||
}
|
||||
QColor getColor(const Signal *sig);
|
||||
|
||||
class NameValidator : public QRegExpValidator {
|
||||
Q_OBJECT
|
||||
|
||||
Reference in New Issue
Block a user