mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of theme colors for lines on statistical charts.
This commit is contained in:
parent
4624d34f68
commit
33724be6ea
3 changed files with 35 additions and 2 deletions
|
@ -62,7 +62,7 @@ struct StatisticalChart {
|
||||||
QString name;
|
QString name;
|
||||||
int maxValue = 0;
|
int maxValue = 0;
|
||||||
int minValue = std::numeric_limits<int>::max();
|
int minValue = std::numeric_limits<int>::max();
|
||||||
int colorKey = 0;
|
QString colorKey;
|
||||||
QColor color;
|
QColor color;
|
||||||
QColor colorDark;
|
QColor colorDark;
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,6 +40,32 @@ inline float64 InterpolationRatio(float64 from, float64 to, float64 result) {
|
||||||
return (result - from) / (to - from);
|
return (result - from) / (to - from);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void FillLineColorsByKey(Data::StatisticalChart &chartData) {
|
||||||
|
for (auto &line : chartData.lines) {
|
||||||
|
if (line.colorKey == u"BLUE"_q) {
|
||||||
|
line.color = st::statisticsChartLineBlue->c;
|
||||||
|
} else if (line.colorKey == u"GREEN"_q) {
|
||||||
|
line.color = st::statisticsChartLineGreen->c;
|
||||||
|
} else if (line.colorKey == u"RED"_q) {
|
||||||
|
line.color = st::statisticsChartLineRed->c;
|
||||||
|
} else if (line.colorKey == u"GOLDEN"_q) {
|
||||||
|
line.color = st::statisticsChartLineGolden->c;
|
||||||
|
} else if (line.colorKey == u"LIGHTBLUE"_q) {
|
||||||
|
line.color = st::statisticsChartLineLightblue->c;
|
||||||
|
} else if (line.colorKey == u"LIGHTGREEN"_q) {
|
||||||
|
line.color = st::statisticsChartLineLightgreen->c;
|
||||||
|
} else if (line.colorKey == u"ORANGE"_q) {
|
||||||
|
line.color = st::statisticsChartLineOrange->c;
|
||||||
|
} else if (line.colorKey == u"INDIGO"_q) {
|
||||||
|
line.color = st::statisticsChartLineIndigo->c;
|
||||||
|
} else if (line.colorKey == u"PURPLE"_q) {
|
||||||
|
line.color = st::statisticsChartLinePurple->c;
|
||||||
|
} else if (line.colorKey == u"CYAN"_q) {
|
||||||
|
line.color = st::statisticsChartLineCyan->c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] QString HeaderRightInfo(
|
[[nodiscard]] QString HeaderRightInfo(
|
||||||
const Data::StatisticalChart &chartData,
|
const Data::StatisticalChart &chartData,
|
||||||
const Limits &limits) {
|
const Limits &limits) {
|
||||||
|
@ -816,6 +842,12 @@ ChartWidget::ChartWidget(not_null<Ui::RpWidget*> parent)
|
||||||
_footer->update();
|
_footer->update();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
style::PaletteChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
if (_chartData) {
|
||||||
|
FillLineColorsByKey(_chartData);
|
||||||
|
}
|
||||||
|
}, lifetime());
|
||||||
setupChartArea();
|
setupChartArea();
|
||||||
setupFooter();
|
setupFooter();
|
||||||
}
|
}
|
||||||
|
@ -1366,6 +1398,7 @@ void ChartWidget::setChartData(
|
||||||
Data::StatisticalChart chartData,
|
Data::StatisticalChart chartData,
|
||||||
ChartViewType type) {
|
ChartViewType type) {
|
||||||
_chartData = std::move(chartData);
|
_chartData = std::move(chartData);
|
||||||
|
FillLineColorsByKey(_chartData);
|
||||||
|
|
||||||
_chartView = CreateChartView(type);
|
_chartView = CreateChartView(type);
|
||||||
_chartView->setLinesFilterController(_linesFilterController);
|
_chartView->setLinesFilterController(_linesFilterController);
|
||||||
|
|
|
@ -80,7 +80,7 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
||||||
const auto match = QRegularExpression(colorPattern).match(
|
const auto match = QRegularExpression(colorPattern).match(
|
||||||
colorIt->toString());
|
colorIt->toString());
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
// const auto colorKey = match.captured(1);
|
line.colorKey = match.captured(1);
|
||||||
line.color = QColor(match.captured(2));
|
line.color = QColor(match.captured(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue