Cached current x-axis indices to reduce redundant calculations.
This commit is contained in:
parent
8256a4c686
commit
73b4621121
|
@ -538,9 +538,18 @@ void ChartWidget::ChartAnimationController::setXPercentageLimits(
|
|||
_animationValueXMax.start(xPercentageLimits.max);
|
||||
_lastUserInteracted = now;
|
||||
|
||||
_finalHeightLimits = FindHeightLimitsBetweenXLimits(
|
||||
chartData,
|
||||
{ _animationValueXMin.to(), _animationValueXMax.to() });
|
||||
const auto startXIndex = chartData.findStartIndex(
|
||||
_animationValueXMin.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.current(),
|
||||
_finalHeightLimits.min);
|
||||
|
@ -720,6 +729,10 @@ Limits ChartWidget::ChartAnimationController::currentXLimits() const {
|
|||
return { _animationValueXMin.current(), _animationValueXMax.current() };
|
||||
}
|
||||
|
||||
Limits ChartWidget::ChartAnimationController::currentXIndices() const {
|
||||
return _currentXIndices;
|
||||
}
|
||||
|
||||
Limits ChartWidget::ChartAnimationController::finalXLimits() const {
|
||||
return { _animationValueXMin.to(), _animationValueXMax.to() };
|
||||
}
|
||||
|
@ -841,6 +854,7 @@ void ChartWidget::setupChartArea() {
|
|||
Statistic::PaintLinearChartView(
|
||||
p,
|
||||
_chartData,
|
||||
_animationController.currentXIndices(),
|
||||
_animationController.currentXLimits(),
|
||||
_animationController.currentHeightLimits(),
|
||||
chartRect,
|
||||
|
@ -961,6 +975,7 @@ void ChartWidget::setupFooter() {
|
|||
Statistic::PaintLinearChartView(
|
||||
p,
|
||||
_chartData,
|
||||
{ 0., float64(_chartData.x.size() - 1) },
|
||||
fullXLimits,
|
||||
_footer->fullHeightLimits(),
|
||||
r,
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
std::vector<BottomCaptionLineData> &dateLines);
|
||||
|
||||
[[nodiscard]] Limits currentXLimits() const;
|
||||
[[nodiscard]] Limits currentXIndices() const;
|
||||
[[nodiscard]] Limits finalXLimits() const;
|
||||
[[nodiscard]] Limits currentHeightLimits() const;
|
||||
[[nodiscard]] Limits finalHeightLimits() const;
|
||||
|
@ -84,6 +85,7 @@ private:
|
|||
anim::value _animValueBottomLineAlpha;
|
||||
|
||||
Limits _finalHeightLimits;
|
||||
Limits _currentXIndices;
|
||||
|
||||
float _dtHeightSpeed = 0.;
|
||||
Limits _dtCurrent;
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace Statistic {
|
|||
void PaintLinearChartView(
|
||||
QPainter &p,
|
||||
const Data::StatisticalChart &chartData,
|
||||
const Limits &xIndices,
|
||||
const Limits &xPercentageLimits,
|
||||
const Limits &heightLimits,
|
||||
const QRect &rect,
|
||||
|
@ -32,21 +33,14 @@ void PaintLinearChartView(
|
|||
const auto additionalP = (chartData.xPercentage.size() < 2)
|
||||
? 0.
|
||||
: (chartData.xPercentage.front() * rect.width());
|
||||
const auto additionalPoints = 0;
|
||||
|
||||
auto first = true;
|
||||
auto chartPath = QPainterPath();
|
||||
|
||||
const auto startXIndex = chartData.findStartIndex(
|
||||
xPercentageLimits.min);
|
||||
const auto endXIndex = chartData.findEndIndex(
|
||||
startXIndex,
|
||||
xPercentageLimits.max);
|
||||
|
||||
const auto localStart = std::max(0, startXIndex - additionalPoints);
|
||||
const auto localStart = std::max(0, int(xIndices.min));
|
||||
const auto localEnd = std::min(
|
||||
int(chartData.xPercentage.size() - 1),
|
||||
endXIndex + additionalPoints);
|
||||
int(xIndices.max));
|
||||
|
||||
for (auto i = localStart; i <= localEnd; i++) {
|
||||
if (line.y[i] < 0) {
|
||||
|
|
|
@ -19,6 +19,7 @@ struct DetailsPaintContext;
|
|||
void PaintLinearChartView(
|
||||
QPainter &p,
|
||||
const Data::StatisticalChart &chartData,
|
||||
const Limits &xIndices,
|
||||
const Limits &xPercentageLimits,
|
||||
const Limits &heightLimits,
|
||||
const QRect &rect,
|
||||
|
|
Loading…
Reference in New Issue