mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 07:37:11 +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;
|
||||
|
||||
struct {
|
||||
float64 min = 0.;
|
||||
float64 max = 0.;
|
||||
} defaultZoomXIndex;
|
||||
|
||||
int maxValue = 0;
|
||||
int minValue = std::numeric_limits<int>::max();
|
||||
|
||||
|
|
|
@ -271,6 +271,9 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
|
|||
: RpMouseWidget(parent) {
|
||||
sizeValue(
|
||||
) | rpl::start_with_next([=](const QSize &s) {
|
||||
if (s.isNull()) {
|
||||
return;
|
||||
}
|
||||
const auto w = float64(st::statisticsChartFooterSideWidth);
|
||||
_width = s.width() - w;
|
||||
_widthBetweenSides = s.width() - w * 2.;
|
||||
|
@ -1105,6 +1108,9 @@ void ChartWidget::setupFooter() {
|
|||
|
||||
_footer->xPercentageLimitsChange(
|
||||
) | rpl::start_with_next([=](Limits xPercentageLimits) {
|
||||
if (!_chartView) {
|
||||
return;
|
||||
}
|
||||
const auto now = crl::now();
|
||||
if (_details.widget
|
||||
&& (_details.widget->xIndex() >= 0)
|
||||
|
@ -1407,9 +1413,14 @@ void ChartWidget::setChartData(
|
|||
setupDetails();
|
||||
setupFilterButtons();
|
||||
|
||||
const auto defaultZoom = Limits{
|
||||
_chartData.xPercentage[_chartData.defaultZoomXIndex.min],
|
||||
_chartData.xPercentage[_chartData.defaultZoomXIndex.max],
|
||||
};
|
||||
_footer->setXPercentageLimits(defaultZoom);
|
||||
_animationController.setXPercentageLimits(
|
||||
_chartData,
|
||||
{ _chartData.xPercentage.front(), _chartData.xPercentage.back() },
|
||||
defaultZoom,
|
||||
_chartView,
|
||||
_linesFilterController,
|
||||
0);
|
||||
|
@ -1440,13 +1451,13 @@ void ChartWidget::setZoomedChartData(
|
|||
ChartViewType type) {
|
||||
_zoomedChartWidget = base::make_unique_q<ChartWidget>(
|
||||
dynamic_cast<Ui::RpWidget*>(parentWidget()));
|
||||
_zoomedChartWidget->setChartData(std::move(chartData), type);
|
||||
geometryValue(
|
||||
) | rpl::start_with_next([=](const QRect &geometry) {
|
||||
_zoomedChartWidget->moveToLeft(geometry.x(), geometry.y());
|
||||
}, _zoomedChartWidget->lifetime());
|
||||
_zoomedChartWidget->show();
|
||||
_zoomedChartWidget->resizeToWidth(width());
|
||||
_zoomedChartWidget->setChartData(std::move(chartData), type);
|
||||
|
||||
const auto customHeader = Ui::CreateChild<Header>(
|
||||
_zoomedChartWidget.get());
|
||||
|
|
|
@ -70,6 +70,30 @@ Data::StatisticalChart StatisticalChartFromJSON(const QByteArray &json) {
|
|||
}
|
||||
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 names = root.value(u"names"_q).toObject();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue