[db] avoid reusing the same chart colors

This just covers the basic case and doesn't address reuse
with JSON values.

Related to #1047
This commit is contained in:
Tim Stack 2022-09-19 02:25:26 -07:00
parent 1faa95df94
commit 5060b38f99
5 changed files with 37 additions and 27 deletions

View File

@ -143,6 +143,13 @@ struct text_attrs {
};
}
bool operator==(const text_attrs& other) const
{
return this->ta_attrs == other.ta_attrs &&
this->ta_fg_color == other.ta_fg_color &&
this->ta_bg_color == other.ta_bg_color;
}
int32_t ta_attrs{0};
nonstd::optional<short> ta_fg_color;
nonstd::optional<short> ta_bg_color;

View File

@ -925,8 +925,17 @@ sql_callback(exec_context& ec, sqlite3_stmt* stmt)
dls.push_header(colname, type, graphable);
if (graphable) {
auto attrs = vc.attrs_for_ident(colname);
auto name_for_ident_attrs = colname;
auto attrs = vc.attrs_for_ident(name_for_ident_attrs);
for (size_t attempt = 0;
chart.attrs_in_use(attrs) && attempt < 3;
attempt++)
{
name_for_ident_attrs += " ";
attrs = vc.attrs_for_ident(name_for_ident_attrs);
}
chart.with_attrs_for_ident(colname, attrs);
dls.dls_headers.back().hm_title_attrs = attrs;
}
}
set_vars = true;

View File

@ -293,9 +293,9 @@ db_overlay_source::list_overlay_count(const listview_curses& lv)
return retval;
}
view_colors& vc = view_colors::singleton();
vis_line_t top = lv.get_top();
const std::vector<const char*>& cols = this->dos_labels->dls_rows[top];
auto& vc = view_colors::singleton();
auto top = lv.get_top();
const auto& cols = this->dos_labels->dls_rows[top];
unsigned long width;
vis_line_t height;
@ -404,8 +404,6 @@ db_overlay_source::list_value_for_overlay(const listview_curses& lv,
vis_line_t row,
attr_line_t& value_out)
{
view_colors& vc = view_colors::singleton();
if (y == 0) {
this->list_overlay_count(lv);
std::string& line = value_out.get_string();
@ -436,7 +434,7 @@ db_overlay_source::list_value_for_overlay(const listview_curses& lv,
text_attrs attrs;
if (this->dos_labels->dls_headers[lpc].hm_graphable) {
attrs = vc.attrs_for_ident(dls->dls_headers[lpc].hm_name)
attrs = dls->dls_headers[lpc].hm_title_attrs
| text_attrs{A_REVERSE};
} else {
attrs.ta_attrs = A_UNDERLINE;

View File

@ -111,6 +111,7 @@ public:
unsigned int hm_sub_type{0};
bool hm_graphable{false};
size_t hm_column_size{0};
text_attrs hm_title_attrs;
};
stacked_bar_chart<std::string> dls_chart;

View File

@ -53,10 +53,8 @@ STRONG_INT_TYPE(int, bucket_type);
struct stacked_bar_chart_base {
virtual ~stacked_bar_chart_base() = default;
struct show_none {
};
struct show_all {
};
struct show_none {};
struct show_all {};
struct show_one {
size_t so_index;
@ -94,6 +92,15 @@ public:
return *this;
}
bool attrs_in_use(const text_attrs& attrs) const {
for (const auto& ident : this->sbc_idents) {
if (ident.ci_attrs == attrs) {
return true;
}
}
return false;
}
show_state show_next_ident(direction dir)
{
bool single_ident = this->sbc_idents.size() == 1;
@ -322,29 +329,17 @@ public:
HT__MAX
} hist_type_t;
hist_source2()
{
this->clear();
}
hist_source2() { this->clear(); }
~hist_source2() override = default;
void init();
void set_time_slice(int64_t slice)
{
this->hs_time_slice = slice;
}
void set_time_slice(int64_t slice) { this->hs_time_slice = slice; }
int64_t get_time_slice() const
{
return this->hs_time_slice;
}
int64_t get_time_slice() const { return this->hs_time_slice; }
size_t text_line_count() override
{
return this->hs_line_count;
}
size_t text_line_count() override { return this->hs_line_count; }
size_t text_line_width(textview_curses& curses) override
{