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

Refactors optionTapped func, adds guard to avoid crash. #3329

Closed
wants to merge 13 commits into from
Closed

Refactors optionTapped func, adds guard to avoid crash. #3329

wants to merge 13 commits into from

Conversation

valeriyvan
Copy link
Contributor

Solves #3327.
As for me it doesn't solve origin of a problem.
For charts with the only dataset option to toggle dataset should't be shown at all.

@codecov-io
Copy link

codecov-io commented Mar 12, 2018

Codecov Report

Merging #3329 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3329   +/-   ##
=======================================
  Coverage   28.32%   28.32%           
=======================================
  Files         117      117           
  Lines       15669    15669           
  Branches      320      320           
=======================================
  Hits         4438     4438           
  Misses      11188    11188           
  Partials       43       43

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 695979e...64e41b5. Read the comment docs.

Copy link
Collaborator

@jjatie jjatie left a comment

Choose a reason for hiding this comment

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

You're going to need to put the guard statement in all demos, not just the base class implementation.

@@ -142,35 +142,30 @@ class LineChart1ViewController: DemoBaseViewController {
}

override func optionTapped(_ option: Option) {
guard let sets = chartView.data?.dataSets as? [LineChartDataSet] else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

"{" on a new line please.

for set in chartView.data!.dataSets as! [LineChartDataSet] {
set.drawFilledEnabled = !set.drawFilledEnabled
}
sets.forEach{ $0.drawFilledEnabled = !$0.drawFilledEnabled }
Copy link
Collaborator

Choose a reason for hiding this comment

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

a space between forEach and {

@valeriyvan valeriyvan changed the title Refactors optionTapped func, adds guard to avoid crash. WIP: Refactors optionTapped func, adds guard to avoid crash. Mar 12, 2018
}
}
data.dataSets.filter { $0 is LineChartDataSet }
.forEach { $0.drawValuesEnabled = !$0.drawValuesEnabled }
Copy link
Collaborator

@jjatie jjatie Mar 12, 2018

Choose a reason for hiding this comment

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

This is fine here, but if you plan on contributing to the Charts framework avoid this. Here we have to loop through dataSets twice to enable toggle drawValuesEnabled, whereas something like :

for case let set as LineChartDataSet in data.dataSets {
    set.drawValuesEnabled = !set.drawValuesEnabled
}

only has to loop once. In the framework, performance matters.
I am curious what the performance characteristics of:

data.dataSets.lazy
    .flter { ... }
    .forEach { ... }

are like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know an answer for your last question.
Definitely, sequence.filter{ $0.condition }.forEach{ $0.doSomething } is slower than sequence.forEach{ if $0.condition { $0.doSomething } }. One is faster, another is readable. I guess, here, where we loop over data sets, minor performance loss could be sacrificed for readability.

@valeriyvan valeriyvan changed the title WIP: Refactors optionTapped func, adds guard to avoid crash. Refactors optionTapped func, adds guard to avoid crash. Mar 12, 2018
@valeriyvan
Copy link
Contributor Author

done

@valeriyvan
Copy link
Contributor Author

done done

@jjatie
Copy link
Collaborator

jjatie commented Mar 14, 2018

@valeriyvan take a look at my comment on #3327

@jjatie jjatie closed this Mar 14, 2018
@valeriyvan
Copy link
Contributor Author

After putting so much effort into fixing bug the way you suggested, you change your mind(

@jjatie
Copy link
Collaborator

jjatie commented Mar 15, 2018

I know it sucks (it happens with my own PRs a lot). Sometimes you just need to see the outcome of a decision before you see it's wrong.

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

Successfully merging this pull request may close these issues.

3 participants