mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of default zoom to statistical charts.
This commit is contained in:
parent
33724be6ea
commit
24c0624704
3 changed files with 42 additions and 2 deletions
|
@ -73,6 +73,11 @@ struct StatisticalChart {
|
||||||
|
|
||||||
std::vector<Line> lines;
|
std::vector<Line> lines;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float64 min = 0.;
|
||||||
|
float64 max = 0.;
|
||||||
|
} defaultZoomXIndex;
|
||||||
|
|
||||||
int maxValue = 0;
|
int maxValue = 0;
|
||||||
int minValue = std::numeric_limits<int>::max();
|
int minValue = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,9 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
|
||||||
: RpMouseWidget(parent) {
|
: RpMouseWidget(parent) {
|
||||||
sizeValue(
|
sizeValue(
|
||||||
) | rpl::start_with_next([=](const QSize &s) {
|
) | rpl::start_with_next([=](const QSize &s) {
|
||||||
|
if (s.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto w = float64(st::statisticsChartFooterSideWidth);
|
const auto w = float64(st::statisticsChartFooterSideWidth);
|
||||||
_width = s.width() - w;
|
_width = s.width() - w;
|
||||||
_widthBetweenSides = s.width() - w * 2.;
|
_widthBetweenSides = s.width() - w * 2.;
|
||||||
|
@ -1105,6 +1108,9 @@ void ChartWidget::setupFooter() {
|
||||||
|
|
||||||
_footer->xPercentageLimitsChange(
|
_footer->xPercentageLimitsChange(
|
||||||
) | rpl::start_with_next([=](Limits xPercentageLimits) {
|
) | rpl::start_with_next([=](Limits xPercentageLimits) {
|
||||||
|
if (!_chartView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto now = crl::now();
|
const auto now = crl::now();
|
||||||
if (_details.widget
|
if (_details.widget
|
||||||
&& (_details.widget->xIndex() >= 0)
|
&& (_details.widget->xIndex() >= 0)
|
||||||
|
@ -1407,9 +1413,14 @@ void ChartWidget::setChartData(
|
||||||
setupDetails();
|
setupDetails();
|
||||||
setupFilterButtons();
|
setupFilterButtons();
|
||||||
|
|
||||||
|
const auto defaultZoom = Limits{
|
||||||
|
_chartData.xPercentage[_chartData.defaultZoomXIndex.min],
|
||||||
|
_chartData.xPercentage[_chartData.defaultZoomXIndex.max],
|
||||||
|
};
|
||||||
|
_footer->setXPercentageLimits(defaultZoom);
|
||||||
_animationController.setXPercentageLimits(
|
_animationController.setXPercentageLimits(
|
||||||
_chartData,
|
_chartData,
|
||||||
{ _chartData.xPercentage.front(), _chartData.xPercentage.back() },
|
defaultZoom,
|
||||||
_chartView,
|
_chartView,
|
||||||
_linesFilterController,
|
_linesFilterController,
|
||||||
0);
|
0);
|
||||||
|
@ -1440,13 +1451,13 @@ void ChartWidget::setZoomedChartData(
|
||||||
ChartViewType type) {
|
ChartViewType type) {
|
||||||
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
||||||
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
||||||
_zoomedChartWidget->setChartData(std::move(chartData), type);
|
|
||||||
geometryValue(
|
geometryValue(
|
||||||
) | rpl::start_with_next([=](const QRect &geometry) {
|
) | rpl::start_with_next([=](const QRect &geometry) {
|
||||||
_zoomedChartWidget->moveToLeft(geometry.x(), geometry.y());
|
_zoomedChartWidget->moveToLeft(geometry.x(), geometry.y());
|
||||||
}, _zoomedChartWidget->lifetime());
|
}, _zoomedChartWidget->lifetime());
|
||||||
_zoomedChartWidget->show();
|
_zoomedChartWidget->show();
|
||||||
_zoomedChartWidget->resizeToWidth(width());
|
_zoomedChartWidget->resizeToWidth(width());
|
||||||
|
_zoomedChartWidget->setChartData(std::move(chartData), type);
|
||||||
|
|
||||||
const auto customHeader = Ui::CreateChild<Header>(
|
const auto customHeader = Ui::CreateChild<Header>(
|
||||||
_zoomedChartWidget.get());
|
_zoomedChartWidget.get());
|
||||||
|
|
|
@ -70,6 +70,30 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
||||||
}
|
}
|
||||||
result.measure();
|
result.measure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto subchart = root.value(u"subchart"_q).toObject();
|
||||||
|
const auto defaultZoomIt = subchart.constFind(u"defaultZoom"_q);
|
||||||
|
auto min = int(0);
|
||||||
|
auto max = int(result.x.size() - 1);
|
||||||
|
if (defaultZoomIt != subchart.constEnd()) {
|
||||||
|
if (const auto array = defaultZoomIt->toArray(); !array.empty()) {
|
||||||
|
const auto minValue = array.first().toDouble();
|
||||||
|
const auto maxValue = array.last().toDouble();
|
||||||
|
for (auto i = 0; i < result.x.size(); i++) {
|
||||||
|
if (result.x[i] == minValue) {
|
||||||
|
min = i;
|
||||||
|
}
|
||||||
|
if (result.x[i] == maxValue) {
|
||||||
|
max = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.defaultZoomXIndex.min = std::min(min, max);
|
||||||
|
result.defaultZoomXIndex.max = std::max(min, max);
|
||||||
|
}
|
||||||
|
|
||||||
const auto colors = root.value(u"colors"_q).toObject();
|
const auto colors = root.value(u"colors"_q).toObject();
|
||||||
const auto names = root.value(u"names"_q).toObject();
|
const auto names = root.value(u"names"_q).toObject();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue