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

ChartDataSet calcYValueSum() bug #604

Closed
yoncise opened this issue Dec 11, 2015 · 13 comments
Closed

ChartDataSet calcYValueSum() bug #604

yoncise opened this issue Dec 11, 2015 · 13 comments
Labels

Comments

@yoncise
Copy link

yoncise commented Dec 11, 2015

notifyDataSetChanged() will call calcYValueSum()

private func calcYValueSum()
{
    _yValueSum = 0

    for var i = 0; i < _yVals.count; i++
    {
        _yValueSum += fabs(_yVals[i].value)
    }
}

Sum calculated from addEntry() and calcYValueSum() is not same, if value is negative. I think fabs() is not needed.

@liuxuan30
Copy link
Member

Good catch! It smells like a bug, but I cannot find a proper fix since I found that it is (only?) used by pie chart, and speaking of angles in pie chart, negative values is supposed to be positive ones?

@danielgindi what do you think? Any charts except pie chart is also using yValueSum? Should it be fabs all the time, or we need to remove fabs?

There are other funcs such as removeFirst(), removeLast(), removeEntry(), addEntryOrdered() , removeDataSetByIndex(), addDataSet(), are not using fabs

@liuxuan30 liuxuan30 added the bug label Dec 14, 2015
@yoncise
Copy link
Author

yoncise commented Dec 14, 2015

LineChart also use calcYValueSum. Actually, I find this issue because my line chart which contains negative value has wrong average value.

@liuxuan30
Copy link
Member

which func in LineChart use yValueSum? Calculating yValueSum but not using it is harmless. I just found pie chart is using yValueSum

@yoncise
Copy link
Author

yoncise commented Dec 16, 2015

As my title said, it's ChartDataSet's calcYValueSum() used fabs() not ChartView's. ChartDataSet is the base class for all DataSet, so I think use fabs() in calcYValueSum() is not reasonable.

@liuxuan30
Copy link
Member

You can search who is using _yValueSum, not just calcYValueSum(). Not every chart will use it, even it is calculated. Otherwise people will find this bug earlier I suppose since abs() or not is quite different.

@yoncise
Copy link
Author

yoncise commented Dec 16, 2015

I find this "bug" because I called notifiedDataSet on ChartDataSet which is not stated on doc (maybe) instead of ChartView. So, maybe this is reason why this bug is not found before. Most people will only call notifiedDataSet on ChartView as doc said.

@danielgindi
Copy link
Collaborator

Pie values should actually just not be negative. It's not valid. There's no good way to represent negative values in the pie chart (except maybe for going back in the other direction with a different width or color).

Anyway I'm looking into the yValueSum thing

@danielgindi
Copy link
Collaborator

@PhilJay I can't find any reason for it being absolutized... Probably something historic but git's blame can only go a certain distance.

There's nothing using yValueSum except for the Pie chart. I think we should remove the abs right?

@PhilJay
Copy link
Collaborator

PhilJay commented Dec 16, 2015

Yes, the abs can be removed!

@liuxuan30
Copy link
Member

@danielgindi how about pie chart? We don't abs the negative values any more?
Just tried, no colorful pies :)

@danielgindi
Copy link
Collaborator

No we shouldn't. Pie charts should not contain negative values... And if they do - they definitely should not increase the total but render in a different way.
Have you encountered a pie chart with negative values?

@liuxuan30
Copy link
Member

I only encountered with test data or some mistaken input. I'm ok to let user abs it rather than us.

@danielgindi
Copy link
Collaborator

I think that it also has another advantage - the user will immediately see that there's something wrong with his data, instead of seeing "correct" data and not being able to understand why it doesn't match another report... :-)

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

No branches or pull requests

4 participants