Fixed display of outer points on linear chart.

This commit is contained in:
23rd 2023-09-28 03:22:25 +03:00 committed by John Preston
parent aeee016dc9
commit 4624d34f68
2 changed files with 20 additions and 12 deletions

View File

@ -1155,6 +1155,12 @@ void ChartWidget::setupDetails() {
currentXLimits,
chartRect,
state.point.x());
if (nearestXIndex < 0) {
_details.widget->setXIndex(nearestXIndex);
_details.widget->hide();
_chartArea->update();
return;
}
const auto currentX = 0
+ chartRect.width() * InterpolationRatio(
currentXLimits.min,

View File

@ -31,10 +31,11 @@ void PaintChartLine(
auto chartPoints = QPolygonF();
const auto localStart = std::max(0, int(c.xIndices.min));
const auto localEnd = std::min(
int(c.chartData.xPercentage.size() - 1),
int(c.xIndices.max));
constexpr auto kOffset = float64(2);
const auto localStart = int(std::max(0., c.xIndices.min - kOffset));
const auto localEnd = int(std::min(
float64(c.chartData.xPercentage.size() - 1),
c.xIndices.max + kOffset));
const auto ratio = Ratio(ratios, line.id);
@ -185,10 +186,8 @@ int LinearChartView::findXIndexByPosition(
const Limits &xPercentageLimits,
const QRect &rect,
float64 x) {
if (x < rect.x()) {
return 0;
} else if (x > (rect.x() + rect.width())) {
return chartData.xPercentage.size() - 1;
if ((x < rect.x()) || (x > (rect.x() + rect.width()))) {
return -1;
}
const auto pointerRatio = std::clamp(
(x - rect.x()) / rect.width(),
@ -203,10 +202,13 @@ int LinearChartView::findXIndexByPosition(
rawXPercentage);
const auto left = rawXPercentage - (*(it - 1));
const auto right = (*it) - rawXPercentage;
const auto nearestXPercentageIt = ((right) > (left)) ? (it - 1) : it;
return std::distance(
begin(chartData.xPercentage),
nearestXPercentageIt);
const auto nearest = ((right) > (left)) ? (it - 1) : it;
const auto resultXPercentageIt = ((*nearest) > xPercentageLimits.max)
? (nearest - 1)
: ((*nearest) < xPercentageLimits.min)
? (nearest + 1)
: nearest;
return std::distance(begin(chartData.xPercentage), resultXPercentageIt);
}
AbstractChartView::HeightLimits LinearChartView::heightLimits(