Fixed paint of selected X index in stack linear chart view.

This commit is contained in:
23rd 2023-09-26 17:16:37 +03:00 committed by John Preston
parent c19a527872
commit cee833f102
2 changed files with 19 additions and 18 deletions

View file

@ -799,37 +799,38 @@ void StackLinearChartView::paintSelectedXIndex(
const PaintContext &c, const PaintContext &c,
int selectedXIndex, int selectedXIndex,
float64 progress) { float64 progress) {
if (selectedXIndex < 0) { if ((selectedXIndex < 0) || c.footer) {
return; return;
} }
const auto &[localStart, localEnd] = _transition.zoomedOutXIndices;
const auto xPercentageLimits = Limits{
c.chartData.xPercentage[localStart],
c.chartData.xPercentage[localEnd],
};
p.setBrush(st::boxBg); p.setBrush(st::boxBg);
const auto r = st::statisticsDetailsDotRadius; const auto r = st::statisticsDetailsDotRadius;
const auto i = selectedXIndex; const auto i = selectedXIndex;
const auto isSameToken = (_selectedPoints.lastXIndex == selectedXIndex) const auto isSameToken = (_selectedPoints.lastXIndex == selectedXIndex)
&& (_selectedPoints.lastHeightLimits.min == c.heightLimits.min) && (_selectedPoints.lastHeightLimits.min == c.heightLimits.min)
&& (_selectedPoints.lastHeightLimits.max == c.heightLimits.max) && (_selectedPoints.lastHeightLimits.max == c.heightLimits.max)
&& (_selectedPoints.lastXLimits.min == c.xPercentageLimits.min) && (_selectedPoints.lastXLimits.min == xPercentageLimits.min)
&& (_selectedPoints.lastXLimits.max == c.xPercentageLimits.max); && (_selectedPoints.lastXLimits.max == xPercentageLimits.max);
for (const auto &line : c.chartData.lines) { {
const auto lineAlpha = alpha(line.id); const auto useCache = isSameToken;
const auto useCache = isSameToken
|| (lineAlpha < 1. && !isEnabled(line.id));
if (!useCache) { if (!useCache) {
// Calculate. // Calculate.
const auto xPoint = c.rect.width() const auto xPoint = c.rect.width()
* ((c.chartData.xPercentage[i] - c.xPercentageLimits.min) * ((c.chartData.xPercentage[i] - xPercentageLimits.min)
/ (c.xPercentageLimits.max - c.xPercentageLimits.min)); / (xPercentageLimits.max - xPercentageLimits.min));
const auto yPercentage = (line.y[i] - c.heightLimits.min) _selectedPoints.xPoint = xPoint;
/ float64(c.heightLimits.max - c.heightLimits.min);
_selectedPoints.points[line.id] = QPointF(xPoint, 0)
+ c.rect.topLeft();
} }
{ {
[[maybe_unused]] const auto o = ScopedPainterOpacity(
p,
p.opacity() * progress);
const auto lineRect = QRectF( const auto lineRect = QRectF(
c.rect.x() _selectedPoints.xPoint - (st::lineWidth / 2.),
+ begin(_selectedPoints.points)->second.x()
- (st::lineWidth / 2.),
c.rect.y(), c.rect.y(),
st::lineWidth, st::lineWidth,
c.rect.height()); c.rect.height());
@ -838,7 +839,7 @@ void StackLinearChartView::paintSelectedXIndex(
} }
_selectedPoints.lastXIndex = selectedXIndex; _selectedPoints.lastXIndex = selectedXIndex;
_selectedPoints.lastHeightLimits = c.heightLimits; _selectedPoints.lastHeightLimits = c.heightLimits;
_selectedPoints.lastXLimits = c.xPercentageLimits; _selectedPoints.lastXLimits = xPercentageLimits;
} }
int StackLinearChartView::findXIndexByPosition( int StackLinearChartView::findXIndexByPosition(

View file

@ -92,7 +92,7 @@ private:
int lastXIndex = -1; int lastXIndex = -1;
Limits lastHeightLimits; Limits lastHeightLimits;
Limits lastXLimits; Limits lastXLimits;
base::flat_map<int, QPointF> points; float64 xPoint = 0.;
}; };
SelectedPoints _selectedPoints; SelectedPoints _selectedPoints;