-
Notifications
You must be signed in to change notification settings - Fork 165
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
Left inset & a option to hide highlight line when touched #83
Open
IeuanTudurPeace
wants to merge
16
commits into
gpbl:master
Choose a base branch
from
IeuanTudurPeace:Improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
037b830
Show highlited line on touch
IeuanTudurPeace 5d1d496
Add a left inset
IeuanTudurPeace 45ee242
Update readme
IeuanTudurPeace 7c2a8e7
Update README.md
IeuanTudurPeace 1d17aa3
Merge pull request #1 from IeuanTudurPeace/Improvements
IeuanTudurPeace cfeec12
Add comment
IeuanTudurPeace 2194e51
Remove the magic number
IeuanTudurPeace 2a7d031
Correct comment
IeuanTudurPeace 9d5b473
Remove showHighlightLine option
IeuanTudurPeace 04a3c35
Update README.md
IeuanTudurPeace 5fb6bcc
Re add highlightLineColor
IeuanTudurPeace af13a03
Move var highlightLineColor to below maxY
IeuanTudurPeace ca99e51
Merge pull request #2 from IeuanTudurPeace/requested_changes
IeuanTudurPeace c286ad8
Merge branch 'Improvements' into master
IeuanTudurPeace 24bcfd6
Merge pull request #3 from IeuanTudurPeace/master
IeuanTudurPeace dfe31fa
Merge branch 'master' into Improvements
IeuanTudurPeace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,12 @@ open class Chart: UIControl { | |
Height of the area at the top of the chart, acting a padding to make place for the top y-axis label. | ||
*/ | ||
open var topInset: CGFloat = 20 | ||
|
||
|
||
/** | ||
Height of the area at the left of the chart, acting a padding to make place for the left x-axis label. | ||
*/ | ||
open var leftInset: CGFloat = 0 | ||
|
||
/** | ||
Width of the chart's lines. | ||
*/ | ||
|
@@ -186,8 +191,13 @@ open class Chart: UIControl { | |
open var maxY: Float? | ||
|
||
/** | ||
Color for the highlight line. | ||
*/ | ||
Should show highlight line when touched. | ||
*/ | ||
open var showHighlightLine: Bool = true | ||
|
||
/** | ||
Color for the highlight line | ||
*/ | ||
open var highlightLineColor = UIColor.gray | ||
|
||
/** | ||
|
@@ -302,8 +312,8 @@ open class Chart: UIControl { | |
fileprivate func drawChart() { | ||
|
||
drawingHeight = bounds.height - bottomInset - topInset | ||
drawingWidth = bounds.width | ||
|
||
drawingWidth = bounds.width - leftInset | ||
let minMax = getMinMax() | ||
min = minMax.min | ||
max = minMax.max | ||
|
@@ -413,8 +423,9 @@ open class Chart: UIControl { | |
} else { | ||
factor = width / (max.x - min.x) | ||
} | ||
|
||
let scaled = values.map { factor * ($0 - self.min.x) } | ||
|
||
let reversedValues = Array(values.reversed()) | ||
let scaled = reversedValues.map {Float(self.leftInset) + width - factor * ($0 - self.min.x) } | ||
return scaled | ||
} | ||
|
||
|
@@ -521,30 +532,32 @@ open class Chart: UIControl { | |
|
||
// horizontal axis at the bottom | ||
context.move(to: CGPoint(x: CGFloat(0), y: drawingHeight + topInset)) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth), y: drawingHeight + topInset)) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth + leftInset), y: drawingHeight + topInset)) | ||
context.strokePath() | ||
|
||
// horizontal axis at the top | ||
context.move(to: CGPoint(x: CGFloat(0), y: CGFloat(0))) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth), y: CGFloat(0))) | ||
context.move(to: CGPoint(x: CGFloat(drawingWidth + leftInset), y: CGFloat(0))) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth + leftInset), y: CGFloat(0))) | ||
context.strokePath() | ||
|
||
// horizontal axis when y = 0 | ||
if min.y < 0 && max.y > 0 { | ||
let y = CGFloat(getZeroValueOnYAxis(zeroLevel: 0)) | ||
context.move(to: CGPoint(x: CGFloat(0), y: y)) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth), y: y)) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth + leftInset), y: y)) | ||
context.strokePath() | ||
} | ||
|
||
// vertical axis on the left | ||
context.move(to: CGPoint(x: CGFloat(0), y: CGFloat(0))) | ||
context.addLine(to: CGPoint(x: CGFloat(0), y: drawingHeight + topInset)) | ||
context.strokePath() | ||
|
||
|
||
if leftInset < 20 { | ||
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 is this this magic number? |
||
// vertical axis on the left | ||
context.move(to: CGPoint(x: CGFloat(0), y: CGFloat(0))) | ||
context.addLine(to: CGPoint(x: CGFloat(0), y: drawingHeight + topInset)) | ||
context.strokePath() | ||
} | ||
|
||
// vertical axis on the right | ||
context.move(to: CGPoint(x: CGFloat(drawingWidth), y: CGFloat(0))) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth), y: drawingHeight + topInset)) | ||
context.move(to: CGPoint(x: CGFloat(drawingWidth + leftInset), y: CGFloat(0))) | ||
context.addLine(to: CGPoint(x: CGFloat(drawingWidth + leftInset), y: drawingHeight + topInset)) | ||
context.strokePath() | ||
|
||
} | ||
|
@@ -631,7 +644,11 @@ open class Chart: UIControl { | |
|
||
var labels: [Float] | ||
if yLabels == nil { | ||
labels = [(min.y + max.y) / 2, max.y] | ||
if leftInset < 20 { | ||
labels = [(min.y + max.y) / 2, max.y] | ||
} else { | ||
labels = [min.y, (min.y + max.y) / 2, max.y] | ||
} | ||
if yLabelsOnRightSide || min.y != 0 { | ||
labels.insert(min.y, at: 0) | ||
} | ||
|
@@ -726,9 +743,11 @@ open class Chart: UIControl { | |
delegate?.didFinishTouchingChart(self) | ||
return | ||
} | ||
|
||
drawHighlightLineFromLeftPosition(left) | ||
|
||
|
||
if showHighlightLine == true { | ||
drawHighlightLineFromLeftPosition(left) | ||
} | ||
|
||
if delegate == nil { | ||
return | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Uhm is it height or width ? :)