mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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;
|
QString colorKey;
|
||||||
QColor color;
|
QColor color;
|
||||||
QColor colorDark;
|
QColor colorDark;
|
||||||
|
bool isHiddenOnStart = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<float64> x;
|
std::vector<float64> x;
|
||||||
|
|
|
@ -200,20 +200,21 @@ void ChartLinesFilterWidget::resizeToWidth(int outerWidth) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChartLinesFilterWidget::fillButtons(
|
void ChartLinesFilterWidget::fillButtons(
|
||||||
const std::vector<QString> &texts,
|
const std::vector<ButtonData> &buttonsData) {
|
||||||
const std::vector<QColor> &colors,
|
|
||||||
const std::vector<int> &ids) {
|
|
||||||
Expects(texts.size() == colors.size());
|
|
||||||
_buttons.clear();
|
_buttons.clear();
|
||||||
|
|
||||||
_buttons.reserve(texts.size());
|
_buttons.reserve(buttonsData.size());
|
||||||
for (auto i = 0; i < texts.size(); i++) {
|
for (auto i = 0; i < buttonsData.size(); i++) {
|
||||||
|
const auto &buttonData = buttonsData[i];
|
||||||
auto button = base::make_unique_q<FlatCheckbox>(
|
auto button = base::make_unique_q<FlatCheckbox>(
|
||||||
this,
|
this,
|
||||||
texts[i],
|
buttonData.text,
|
||||||
colors[i]);
|
buttonData.color);
|
||||||
button->show();
|
button->show();
|
||||||
const auto id = ids[i];
|
if (buttonData.disabled) {
|
||||||
|
button->setChecked(false, false);
|
||||||
|
}
|
||||||
|
const auto id = buttonData.id;
|
||||||
button->setClickedCallback([=, raw = button.get()] {
|
button->setClickedCallback([=, raw = button.get()] {
|
||||||
const auto checked = !raw->checked();
|
const auto checked = !raw->checked();
|
||||||
if (!checked) {
|
if (!checked) {
|
||||||
|
|
|
@ -15,10 +15,14 @@ class ChartLinesFilterWidget final : public Ui::RpWidget {
|
||||||
public:
|
public:
|
||||||
ChartLinesFilterWidget(not_null<Ui::RpWidget*> parent);
|
ChartLinesFilterWidget(not_null<Ui::RpWidget*> parent);
|
||||||
|
|
||||||
void fillButtons(
|
struct ButtonData final {
|
||||||
const std::vector<QString> &texts,
|
QString text;
|
||||||
const std::vector<QColor> &colors,
|
QColor color;
|
||||||
const std::vector<int> &ids);
|
int id = 0;
|
||||||
|
bool disabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
void fillButtons(const std::vector<ButtonData> &buttonsData);
|
||||||
|
|
||||||
void resizeToWidth(int outerWidth);
|
void resizeToWidth(int outerWidth);
|
||||||
|
|
||||||
|
|
|
@ -1390,19 +1390,22 @@ void ChartWidget::setupFilterButtons() {
|
||||||
_filterButtons = base::make_unique_q<ChartLinesFilterWidget>(this);
|
_filterButtons = base::make_unique_q<ChartLinesFilterWidget>(this);
|
||||||
_filterButtons->show();
|
_filterButtons->show();
|
||||||
{
|
{
|
||||||
auto texts = std::vector<QString>();
|
auto data = std::vector<ChartLinesFilterWidget::ButtonData>();
|
||||||
auto colors = std::vector<QColor>();
|
data.reserve(_chartData.lines.size());
|
||||||
auto ids = std::vector<int>();
|
|
||||||
texts.reserve(_chartData.lines.size());
|
|
||||||
colors.reserve(_chartData.lines.size());
|
|
||||||
ids.reserve(_chartData.lines.size());
|
|
||||||
for (const auto &line : _chartData.lines) {
|
for (const auto &line : _chartData.lines) {
|
||||||
texts.push_back(line.name);
|
data.push_back({
|
||||||
colors.push_back(line.color);
|
line.name,
|
||||||
ids.push_back(line.id);
|
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(
|
_filterButtons->buttonEnabledChanges(
|
||||||
|
|
|
@ -30,6 +30,14 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
||||||
LOG(("API Error: Empty columns list from stats graph received."));
|
LOG(("API Error: Empty columns list from stats graph received."));
|
||||||
return {};
|
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 result = Data::StatisticalChart();
|
||||||
auto columnIdCount = 0;
|
auto columnIdCount = 0;
|
||||||
for (const auto &column : columns) {
|
for (const auto &column : columns) {
|
||||||
|
@ -50,6 +58,7 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
||||||
const auto length = array.size() - 1;
|
const auto length = array.size() - 1;
|
||||||
line.id = (++columnIdCount);
|
line.id = (++columnIdCount);
|
||||||
line.idString = columnId;
|
line.idString = columnId;
|
||||||
|
line.isHiddenOnStart = ranges::contains(hiddenLines, columnId);
|
||||||
line.y.resize(length);
|
line.y.resize(length);
|
||||||
for (auto i = 0; i < length; i++) {
|
for (auto i = 0; i < length; i++) {
|
||||||
const auto value = array.at(i + 1).toInt();
|
const auto value = array.at(i + 1).toInt();
|
||||||
|
|
Loading…
Add table
Reference in a new issue