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

ChartData.removeEntryByXIndex removes the wrong entry #182

Closed
dorsoft opened this issue Jul 1, 2015 · 9 comments
Closed

ChartData.removeEntryByXIndex removes the wrong entry #182

dorsoft opened this issue Jul 1, 2015 · 9 comments

Comments

@dorsoft
Copy link

dorsoft commented Jul 1, 2015

scenario:

  1. ChartData contains 1 dataset with 10 values (xIndex 0-9)
  2. Call ChartData.removeEntryByXIndex(xIndex:10, datasetIndex:0)
    Expected result: no entry is removed and the method returns false
    Actual result: the entry at xIndex 9 is removed, repeated method calls remove the last index (8,7,6...)

The fix:

public func removeEntryByXIndex(xIndex: Int, dataSetIndex: Int) -> Bool
{
if (dataSetIndex >= _dataSets.count)
{
return false
}

var entry = _dataSets[dataSetIndex].entryForXIndex(xIndex)

if (entry?.xIndex != xIndex) {
return false
}

return removeEntry(entry, dataSetIndex: dataSetIndex)
}

@danielgindi
Copy link
Collaborator

How exactly does constraining dataSetIndex solve this issue?... If at all, you would want to constrain the xIndex. But that is already done by check for the right xIndex in case that it does not exist and we got the closest one.

@dorsoft
Copy link
Author

dorsoft commented Jul 1, 2015

I've added:
if (entry?.xIndex != xIndex) {
return false
}

@dorsoft
Copy link
Author

dorsoft commented Jul 1, 2015

sorry for not mentioning it

@danielgindi
Copy link
Collaborator

@dorsoft Oh now it makes sense. But shouldn't you check for nil first?

@dorsoft
Copy link
Author

dorsoft commented Jul 1, 2015

you are right

if (entry == nil || entry?.xIndex != xIndex) {
return false
}

@danielgindi
Copy link
Collaborator

@dorsoft Actually - my bad! It's Swift. It will check the optional for you when using an if. Your previous post was correct :)

@danielgindi
Copy link
Collaborator

@dorsoft Do you want to open a PR? I'm not in front of Mac. Please format it according to the surrounding coding style and have a clean commit/PR :)

@dorsoft
Copy link
Author

dorsoft commented Jul 1, 2015

Done

dorsoft pushed a commit to dorsoft/ios-charts that referenced this issue Jul 2, 2015
danielgindi added a commit that referenced this issue Jul 2, 2015
ChartData.removeEntryByXIndex removes the wrong entry #182
@danielgindi
Copy link
Collaborator

#185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants