mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Cached current x-axis indices to reduce redundant calculations.
This commit is contained in:
parent
8256a4c686
commit
73b4621121
4 changed files with 24 additions and 12 deletions
|
@ -538,9 +538,18 @@ void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
||||||
_animationValueXMax.start(xPercentageLimits.max);
|
_animationValueXMax.start(xPercentageLimits.max);
|
||||||
_lastUserInteracted = now;
|
_lastUserInteracted = now;
|
||||||
|
|
||||||
_finalHeightLimits = FindHeightLimitsBetweenXLimits(
|
const auto startXIndex = chartData.findStartIndex(
|
||||||
chartData,
|
_animationValueXMin.to());
|
||||||
{ _animationValueXMin.to(), _animationValueXMax.to() });
|
const auto endXIndex = chartData.findEndIndex(
|
||||||
|
startXIndex,
|
||||||
|
_animationValueXMax.to());
|
||||||
|
_currentXIndices = { float64(startXIndex), float64(endXIndex) };
|
||||||
|
|
||||||
|
_finalHeightLimits = Limits{
|
||||||
|
float64(FindMinValue(chartData, startXIndex, endXIndex)),
|
||||||
|
float64(FindMaxValue(chartData, startXIndex, endXIndex)),
|
||||||
|
};
|
||||||
|
|
||||||
_animationValueHeightMin = anim::value(
|
_animationValueHeightMin = anim::value(
|
||||||
_animationValueHeightMin.current(),
|
_animationValueHeightMin.current(),
|
||||||
_finalHeightLimits.min);
|
_finalHeightLimits.min);
|
||||||
|
@ -720,6 +729,10 @@ Limits ChartWidget::ChartAnimationController::currentXLimits() const {
|
||||||
return { _animationValueXMin.current(), _animationValueXMax.current() };
|
return { _animationValueXMin.current(), _animationValueXMax.current() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Limits ChartWidget::ChartAnimationController::currentXIndices() const {
|
||||||
|
return _currentXIndices;
|
||||||
|
}
|
||||||
|
|
||||||
Limits ChartWidget::ChartAnimationController::finalXLimits() const {
|
Limits ChartWidget::ChartAnimationController::finalXLimits() const {
|
||||||
return { _animationValueXMin.to(), _animationValueXMax.to() };
|
return { _animationValueXMin.to(), _animationValueXMax.to() };
|
||||||
}
|
}
|
||||||
|
@ -841,6 +854,7 @@ void ChartWidget::setupChartArea() {
|
||||||
Statistic::PaintLinearChartView(
|
Statistic::PaintLinearChartView(
|
||||||
p,
|
p,
|
||||||
_chartData,
|
_chartData,
|
||||||
|
_animationController.currentXIndices(),
|
||||||
_animationController.currentXLimits(),
|
_animationController.currentXLimits(),
|
||||||
_animationController.currentHeightLimits(),
|
_animationController.currentHeightLimits(),
|
||||||
chartRect,
|
chartRect,
|
||||||
|
@ -961,6 +975,7 @@ void ChartWidget::setupFooter() {
|
||||||
Statistic::PaintLinearChartView(
|
Statistic::PaintLinearChartView(
|
||||||
p,
|
p,
|
||||||
_chartData,
|
_chartData,
|
||||||
|
{ 0., float64(_chartData.x.size() - 1) },
|
||||||
fullXLimits,
|
fullXLimits,
|
||||||
_footer->fullHeightLimits(),
|
_footer->fullHeightLimits(),
|
||||||
r,
|
r,
|
||||||
|
|
|
@ -58,6 +58,7 @@ private:
|
||||||
std::vector<BottomCaptionLineData> &dateLines);
|
std::vector<BottomCaptionLineData> &dateLines);
|
||||||
|
|
||||||
[[nodiscard]] Limits currentXLimits() const;
|
[[nodiscard]] Limits currentXLimits() const;
|
||||||
|
[[nodiscard]] Limits currentXIndices() const;
|
||||||
[[nodiscard]] Limits finalXLimits() const;
|
[[nodiscard]] Limits finalXLimits() const;
|
||||||
[[nodiscard]] Limits currentHeightLimits() const;
|
[[nodiscard]] Limits currentHeightLimits() const;
|
||||||
[[nodiscard]] Limits finalHeightLimits() const;
|
[[nodiscard]] Limits finalHeightLimits() const;
|
||||||
|
@ -84,6 +85,7 @@ private:
|
||||||
anim::value _animValueBottomLineAlpha;
|
anim::value _animValueBottomLineAlpha;
|
||||||
|
|
||||||
Limits _finalHeightLimits;
|
Limits _finalHeightLimits;
|
||||||
|
Limits _currentXIndices;
|
||||||
|
|
||||||
float _dtHeightSpeed = 0.;
|
float _dtHeightSpeed = 0.;
|
||||||
Limits _dtCurrent;
|
Limits _dtCurrent;
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace Statistic {
|
||||||
void PaintLinearChartView(
|
void PaintLinearChartView(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
const Data::StatisticalChart &chartData,
|
const Data::StatisticalChart &chartData,
|
||||||
|
const Limits &xIndices,
|
||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
const Limits &heightLimits,
|
const Limits &heightLimits,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
|
@ -32,21 +33,14 @@ void PaintLinearChartView(
|
||||||
const auto additionalP = (chartData.xPercentage.size() < 2)
|
const auto additionalP = (chartData.xPercentage.size() < 2)
|
||||||
? 0.
|
? 0.
|
||||||
: (chartData.xPercentage.front() * rect.width());
|
: (chartData.xPercentage.front() * rect.width());
|
||||||
const auto additionalPoints = 0;
|
|
||||||
|
|
||||||
auto first = true;
|
auto first = true;
|
||||||
auto chartPath = QPainterPath();
|
auto chartPath = QPainterPath();
|
||||||
|
|
||||||
const auto startXIndex = chartData.findStartIndex(
|
const auto localStart = std::max(0, int(xIndices.min));
|
||||||
xPercentageLimits.min);
|
|
||||||
const auto endXIndex = chartData.findEndIndex(
|
|
||||||
startXIndex,
|
|
||||||
xPercentageLimits.max);
|
|
||||||
|
|
||||||
const auto localStart = std::max(0, startXIndex - additionalPoints);
|
|
||||||
const auto localEnd = std::min(
|
const auto localEnd = std::min(
|
||||||
int(chartData.xPercentage.size() - 1),
|
int(chartData.xPercentage.size() - 1),
|
||||||
endXIndex + additionalPoints);
|
int(xIndices.max));
|
||||||
|
|
||||||
for (auto i = localStart; i <= localEnd; i++) {
|
for (auto i = localStart; i <= localEnd; i++) {
|
||||||
if (line.y[i] < 0) {
|
if (line.y[i] < 0) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct DetailsPaintContext;
|
||||||
void PaintLinearChartView(
|
void PaintLinearChartView(
|
||||||
QPainter &p,
|
QPainter &p,
|
||||||
const Data::StatisticalChart &chartData,
|
const Data::StatisticalChart &chartData,
|
||||||
|
const Limits &xIndices,
|
||||||
const Limits &xPercentageLimits,
|
const Limits &xPercentageLimits,
|
||||||
const Limits &heightLimits,
|
const Limits &heightLimits,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
|
|
Loading…
Add table
Reference in a new issue