2023-09-18 18:07:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "statistics/view/stack_chart_common.h"
|
|
|
|
|
|
|
|
#include "data/data_statistics.h"
|
|
|
|
#include "statistics/statistics_common.h"
|
2023-09-26 00:06:48 +00:00
|
|
|
#include "ui/effects/animation_value_f.h"
|
2023-09-18 18:07:02 +00:00
|
|
|
|
|
|
|
namespace Statistic {
|
|
|
|
|
|
|
|
LeftStartAndStep ComputeLeftStartAndStep(
|
|
|
|
const Data::StatisticalChart &chartData,
|
|
|
|
const Limits &xPercentageLimits,
|
|
|
|
const QRect &rect,
|
|
|
|
float64 xIndexStart) {
|
|
|
|
const auto fullWidth = rect.width()
|
|
|
|
/ (xPercentageLimits.max - xPercentageLimits.min);
|
|
|
|
const auto offset = fullWidth * xPercentageLimits.min;
|
|
|
|
const auto p = (chartData.xPercentage.size() < 2)
|
|
|
|
? 1.
|
|
|
|
: chartData.xPercentage[1] * fullWidth;
|
|
|
|
const auto w = chartData.xPercentage[1] * (fullWidth - p);
|
|
|
|
const auto leftStart = rect.x()
|
|
|
|
+ chartData.xPercentage[xIndexStart] * (fullWidth - p)
|
|
|
|
- offset;
|
|
|
|
return { leftStart, w };
|
|
|
|
}
|
|
|
|
|
2023-09-26 00:06:48 +00:00
|
|
|
Limits FindStackXIndicesFromRawXPercentages(
|
|
|
|
const Data::StatisticalChart &chartData,
|
|
|
|
const Limits &rawXPercentageLimits,
|
|
|
|
const Limits &zoomedInLimitXIndices) {
|
|
|
|
const auto zoomLimit = Limits{
|
|
|
|
chartData.xPercentage[zoomedInLimitXIndices.min],
|
|
|
|
chartData.xPercentage[zoomedInLimitXIndices.max],
|
|
|
|
};
|
2023-09-26 13:43:35 +00:00
|
|
|
// Due to a specificity of the stack chart plotting,
|
|
|
|
// the right edge has a special offset to the left.
|
|
|
|
// This reduces the number of displayed points by 1,
|
|
|
|
// but allows the last point to be displayed.
|
2023-09-26 00:06:48 +00:00
|
|
|
const auto offset = (zoomLimit.max == 1.) ? 0 : -1;
|
|
|
|
const auto minIt = ranges::upper_bound(
|
|
|
|
chartData.xPercentage,
|
|
|
|
anim::interpolateF(
|
|
|
|
zoomLimit.min,
|
|
|
|
zoomLimit.max,
|
|
|
|
rawXPercentageLimits.min));
|
|
|
|
const auto maxIt = ranges::upper_bound(
|
|
|
|
chartData.xPercentage,
|
|
|
|
anim::interpolateF(
|
|
|
|
zoomLimit.min,
|
|
|
|
zoomLimit.max,
|
|
|
|
rawXPercentageLimits.max));
|
|
|
|
const auto start = begin(chartData.xPercentage);
|
|
|
|
return {
|
|
|
|
.min = std::clamp(
|
|
|
|
float64(std::distance(start, minIt) + offset),
|
|
|
|
zoomedInLimitXIndices.min,
|
|
|
|
zoomedInLimitXIndices.max),
|
|
|
|
.max = std::clamp(
|
|
|
|
float64(std::distance(start, maxIt) + offset),
|
|
|
|
zoomedInLimitXIndices.min,
|
|
|
|
zoomedInLimitXIndices.max),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-09-18 18:07:02 +00:00
|
|
|
} // namespace Statistic
|