-
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
Displayed points for series in the graph. #15
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -124,6 +124,12 @@ class Chart: UIControl { | |
@IBInspectable | ||
var lineWidth: CGFloat = 2 | ||
|
||
/** | ||
Width of the chart's poinst. | ||
*/ | ||
@IBInspectable | ||
var pointWidth: CGFloat = 2 | ||
|
||
/** | ||
Delegate for listening to Chart touch events. | ||
*/ | ||
|
@@ -291,6 +297,12 @@ class Chart: UIControl { | |
|
||
if series.line { | ||
drawLine(xValues: scaledXValues, yValues: scaledYValues, seriesIndex: index) | ||
if series.points { | ||
for i in 1..<scaledXValues.count { | ||
drawPoints(xValues: scaledXValues, yValues: scaledYValues, seriesIndex: index, i: i) | ||
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. If I understand it, |
||
} | ||
} | ||
|
||
} | ||
if series.area { | ||
drawArea(xValues: scaledXValues, yValues: scaledYValues, seriesIndex: index) | ||
|
@@ -451,6 +463,38 @@ class Chart: UIControl { | |
return lineLayer | ||
} | ||
|
||
private func drawPoints(xValues xValues: Array<Float>, yValues: Array<Float>, seriesIndex: Int, i: Int) -> CAShapeLayer { | ||
|
||
let circleLayer = CAShapeLayer() | ||
let circleRadius: CGFloat = 2.0 | ||
|
||
func circleFrame(x: CGFloat, y: CGFloat) -> CGRect { | ||
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. Not a good idea declaring a function inside a method which is looped over a relative big amount of values. I'd put the shape layer outside the class. |
||
var circleFrame = CGRect(x: x, y: y, width: 2*circleRadius, height: 2*circleRadius) | ||
circleFrame.origin.x = x - circleRadius | ||
circleFrame.origin.y = y - circleRadius | ||
return circleFrame | ||
} | ||
|
||
func circlePath(i: Int) -> UIBezierPath { | ||
let x = xValues[i] | ||
let y = yValues[i] | ||
return UIBezierPath(ovalInRect: circleFrame(CGFloat(x), y: CGFloat(y))) | ||
} | ||
|
||
circleLayer.frame = self.bounds | ||
circleLayer.path = circlePath(i).CGPath | ||
|
||
circleLayer.lineWidth = pointWidth | ||
circleLayer.fillColor = series[seriesIndex].colors.above.CGColor | ||
circleLayer.strokeColor = series[seriesIndex].colors.above.CGColor | ||
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. |
||
|
||
self.layer.addSublayer(circleLayer) | ||
|
||
layerStore.append(circleLayer) | ||
|
||
return circleLayer | ||
} | ||
|
||
private func drawArea(xValues xValues: Array<Float>, yValues: Array<Float>, seriesIndex: Int) { | ||
let isAboveXAxis = isVerticalSegmentAboveXAxis(yValues) | ||
let area = CGPathCreateMutable() | ||
|
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.
I won't use another loop here because it is resource expensive. I think the right method for adding the markers is the
drawLabelsAndGridOnXAxis
, i.e. where it is drawing the vertical lines for the x-axis.