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

Min and Max reset when clearing ChartDataSet (Fixes #3260) #3265

Merged
merged 1 commit into from
Feb 22, 2018
Merged
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 @@ -86,22 +86,22 @@ open class ChartDataSet: ChartBaseDataSet

open override func calcMinMax()
{
guard !values.isEmpty else { return }

_yMax = -Double.greatestFiniteMagnitude
_yMin = Double.greatestFiniteMagnitude
_xMax = -Double.greatestFiniteMagnitude
_xMin = Double.greatestFiniteMagnitude

guard !values.isEmpty else { return }

values.forEach { calcMinMax(entry: $0) }
}

open override func calcMinMaxY(fromX: Double, toX: Double)
{
guard !values.isEmpty else { return }

_yMax = -Double.greatestFiniteMagnitude
_yMin = Double.greatestFiniteMagnitude

guard !values.isEmpty else { return }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change here seems legit. But how you find calcMinMaxY needs fix as well? I don't see clear() will eventually call calcMinMaxY?
I just want to make sure we don't missed other similar issues. Can you help do a double check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, calcMinMaxY isn't triggered when calling clear(), and I haven't had any trouble from its current implementation, but I thought it would still be better to reset _yMax and _yMin to their defaults rather than leaving them with random numbers from the previous set. Feel free to edit my changes if you'd rather leave that alone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, got you. seems fine to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird that this issue is only coming up now, as the implementation hasn't changed in a very long time. @carlo I think you're right and that the guard statement should be removed entirely.


let indexFrom = entryIndex(x: fromX, closestToY: Double.nan, rounding: .down)
let indexTo = entryIndex(x: toX, closestToY: Double.nan, rounding: .up)
Expand Down