mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Added ability to filter out lines from chart on demand from backend.
This commit is contained in:
parent
4a10d86a29
commit
da9720530a
5 changed files with 41 additions and 23 deletions
|
@ -41,6 +41,7 @@ struct StatisticalChart {
|
|||
QString colorKey;
|
||||
QColor color;
|
||||
QColor colorDark;
|
||||
bool isHiddenOnStart = false;
|
||||
};
|
||||
|
||||
std::vector<float64> x;
|
||||
|
|
|
@ -200,20 +200,21 @@ void ChartLinesFilterWidget::resizeToWidth(int outerWidth) {
|
|||
}
|
||||
|
||||
void ChartLinesFilterWidget::fillButtons(
|
||||
const std::vector<QString> &texts,
|
||||
const std::vector<QColor> &colors,
|
||||
const std::vector<int> &ids) {
|
||||
Expects(texts.size() == colors.size());
|
||||
const std::vector<ButtonData> &buttonsData) {
|
||||
_buttons.clear();
|
||||
|
||||
_buttons.reserve(texts.size());
|
||||
for (auto i = 0; i < texts.size(); i++) {
|
||||
_buttons.reserve(buttonsData.size());
|
||||
for (auto i = 0; i < buttonsData.size(); i++) {
|
||||
const auto &buttonData = buttonsData[i];
|
||||
auto button = base::make_unique_q<FlatCheckbox>(
|
||||
this,
|
||||
texts[i],
|
||||
colors[i]);
|
||||
buttonData.text,
|
||||
buttonData.color);
|
||||
button->show();
|
||||
const auto id = ids[i];
|
||||
if (buttonData.disabled) {
|
||||
button->setChecked(false, false);
|
||||
}
|
||||
const auto id = buttonData.id;
|
||||
button->setClickedCallback([=, raw = button.get()] {
|
||||
const auto checked = !raw->checked();
|
||||
if (!checked) {
|
||||
|
|
|
@ -15,10 +15,14 @@ class ChartLinesFilterWidget final : public Ui::RpWidget {
|
|||
public:
|
||||
ChartLinesFilterWidget(not_null<Ui::RpWidget*> parent);
|
||||
|
||||
void fillButtons(
|
||||
const std::vector<QString> &texts,
|
||||
const std::vector<QColor> &colors,
|
||||
const std::vector<int> &ids);
|
||||
struct ButtonData final {
|
||||
QString text;
|
||||
QColor color;
|
||||
int id = 0;
|
||||
bool disabled = false;
|
||||
};
|
||||
|
||||
void fillButtons(const std::vector<ButtonData> &buttonsData);
|
||||
|
||||
void resizeToWidth(int outerWidth);
|
||||
|
||||
|
|
|
@ -1390,19 +1390,22 @@ void ChartWidget::setupFilterButtons() {
|
|||
_filterButtons = base::make_unique_q<ChartLinesFilterWidget>(this);
|
||||
_filterButtons->show();
|
||||
{
|
||||
auto texts = std::vector<QString>();
|
||||
auto colors = std::vector<QColor>();
|
||||
auto ids = std::vector<int>();
|
||||
texts.reserve(_chartData.lines.size());
|
||||
colors.reserve(_chartData.lines.size());
|
||||
ids.reserve(_chartData.lines.size());
|
||||
auto data = std::vector<ChartLinesFilterWidget::ButtonData>();
|
||||
data.reserve(_chartData.lines.size());
|
||||
for (const auto &line : _chartData.lines) {
|
||||
texts.push_back(line.name);
|
||||
colors.push_back(line.color);
|
||||
ids.push_back(line.id);
|
||||
data.push_back({
|
||||
line.name,
|
||||
line.color,
|
||||
line.id,
|
||||
line.isHiddenOnStart,
|
||||
});
|
||||
if (line.isHiddenOnStart) {
|
||||
_linesFilterController->setEnabled(line.id, false, 1);
|
||||
}
|
||||
}
|
||||
|
||||
_filterButtons->fillButtons(texts, colors, ids);
|
||||
_filterButtons->fillButtons(data);
|
||||
_linesFilterController->tick(1.);
|
||||
}
|
||||
|
||||
_filterButtons->buttonEnabledChanges(
|
||||
|
|
|
@ -30,6 +30,14 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
|||
LOG(("API Error: Empty columns list from stats graph received."));
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto hiddenLinesRaw = root.value(u"hidden"_q).toArray();
|
||||
const auto hiddenLines = ranges::views::all(
|
||||
hiddenLinesRaw
|
||||
) | ranges::views::transform([](const auto &q) {
|
||||
return q.toString();
|
||||
}) | ranges::to_vector;
|
||||
|
||||
auto result = Data::StatisticalChart();
|
||||
auto columnIdCount = 0;
|
||||
for (const auto &column : columns) {
|
||||
|
@ -50,6 +58,7 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
|||
const auto length = array.size() - 1;
|
||||
line.id = (++columnIdCount);
|
||||
line.idString = columnId;
|
||||
line.isHiddenOnStart = ranges::contains(hiddenLines, columnId);
|
||||
line.y.resize(length);
|
||||
for (auto i = 0; i < length; i++) {
|
||||
const auto value = array.at(i + 1).toInt();
|
||||
|
|
Loading…
Add table
Reference in a new issue