-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Minor cleanup to Highlighter types #3003
Changes from 1 commit
c28880a
df3b852
e66ba14
796cb2d
fa1297a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,10 @@ open class PieHighlighter: PieRadarHighlighter | |
{ | ||
open override func closestHighlight(index: Int, x: CGFloat, y: CGFloat) -> Highlight? | ||
{ | ||
guard let set = chart?.data?.dataSets[0] | ||
guard let set = chart?.data?.dataSets[0], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combining these guard statements makes it harder to read. I think it was easier to understand before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about all the other places in the framework where we are writing
|
||
let entry = set.entryForIndex(index) | ||
else { return nil } | ||
|
||
guard let entry = set.entryForIndex(index) | ||
else { return nil } | ||
|
||
|
||
return Highlight(x: Double(index), y: entry.y, xPx: x, yPx: y, dataSetIndex: 0, axis: set.axisDependency) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,32 +23,30 @@ open class PieRadarHighlighter: ChartHighlighter | |
let touchDistanceToCenter = chart.distanceToCenter(x: x, y: y) | ||
|
||
// check if a slice was touched | ||
if touchDistanceToCenter > chart.radius | ||
{ | ||
guard touchDistanceToCenter <= chart.radius else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. guard or if here doesn't really make a difference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So in this case the guard makes it extra clear that the method can return early here |
||
// if no slice was touched, highlight nothing | ||
return nil | ||
} | ||
|
||
var angle = chart.angleForPoint(x: x ,y: y) | ||
|
||
if chart is PieChartView | ||
{ | ||
angle /= CGFloat(chart.chartAnimator.phaseY) | ||
} | ||
|
||
let index = chart.indexForAngle(angle) | ||
|
||
// check if the index could be found | ||
if index < 0 || index >= chart.data?.maxEntryCountSet?.entryCount ?? 0 | ||
{ | ||
return nil | ||
} | ||
else | ||
{ | ||
var angle = chart.angleForPoint(x: x ,y: y) | ||
|
||
if chart is PieChartView | ||
{ | ||
angle /= CGFloat(chart.chartAnimator.phaseY) | ||
} | ||
|
||
let index = chart.indexForAngle(angle) | ||
|
||
// check if the index could be found | ||
if index < 0 || index >= chart.data?.maxEntryCountSet?.entryCount ?? 0 | ||
{ | ||
return nil | ||
} | ||
else | ||
{ | ||
return closestHighlight(index: index, x: x, y: y) | ||
} | ||
return closestHighlight(index: index, x: x, y: y) | ||
} | ||
|
||
} | ||
|
||
/// - returns: The closest Highlight object of the given objects based on the touch position inside the chart. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guard is harder to read than how it was before. I have to think about it for a second when I try to understand this line. It was more straightforward before. It doesn't reduce nesting so we can switch it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While
guard
often does reduce nesting, it's purpose is to indicate thatIt seems reasonable to me to expect reading "only continue if
closestValues
is not empty"