Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in XBounds calculation of minimum/maximum visible entry index. #4839

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ open class ChartDataSet: ChartBaseDataSet
rounding: ChartDataSetRounding) -> Int
{
var closest = partitioningIndex { $0.x >= xValue }
guard closest < endIndex else { return rounding == .closest ? (endIndex-1) : -1 }
guard closest < endIndex else { return [.down, .closest].contains(rounding) ? (endIndex-1) : -1 }

var closestXValue = self[closest].x

Expand Down
12 changes: 9 additions & 3 deletions Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ open class BarLineScatterCandleBubbleRenderer: NSObject, DataRenderer

let low = chart.lowestVisibleX
let high = chart.highestVisibleX

let entryFrom = dataSet.entryForXValue(low, closestToY: .nan, rounding: .down)
let entryTo = dataSet.entryForXValue(high, closestToY: .nan, rounding: .up)

// First, try to find entries on the boundary of or outside of the visible range. Then, if there are none, try to find entries
// inside of the visible range.
//
// We want to allow and prioritize entries outside of the visible range because renderers may draw graphics in between entries.
// For example, a zoomed-in line graph should still show a line connecting the entry outside of the visible range with the entry
// inside of the visible range even if the line is only partially shown.
let entryFrom = dataSet.entryForXValue(low, closestToY: .nan, rounding: .down) ?? dataSet.entryForXValue(low, closestToY: .nan, rounding: .up)
let entryTo = dataSet.entryForXValue(high, closestToY: .nan, rounding: .up) ?? dataSet.entryForXValue(high, closestToY: .nan, rounding: .down)

self.min = entryFrom == nil ? 0 : dataSet.entryIndex(entry: entryFrom!)
self.max = entryTo == nil ? 0 : dataSet.entryIndex(entry: entryTo!)
Expand Down