diff --git a/Chart/Chart.swift b/Chart/Chart.swift index d058376d5..36ed3aa37 100644 --- a/Chart/Chart.swift +++ b/Chart/Chart.swift @@ -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.., yValues: Array, seriesIndex: Int, i: Int) -> CAShapeLayer { + + let circleLayer = CAShapeLayer() + let circleRadius: CGFloat = 2.0 + + func circleFrame(x: CGFloat, y: CGFloat) -> CGRect { + 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 + + self.layer.addSublayer(circleLayer) + + layerStore.append(circleLayer) + + return circleLayer + } + private func drawArea(xValues xValues: Array, yValues: Array, seriesIndex: Int) { let isAboveXAxis = isVerticalSegmentAboveXAxis(yValues) let area = CGPathCreateMutable() diff --git a/Chart/ChartSeries.swift b/Chart/ChartSeries.swift index d878d1663..154765046 100644 --- a/Chart/ChartSeries.swift +++ b/Chart/ChartSeries.swift @@ -14,6 +14,7 @@ class ChartSeries { var data: Array<(x: Float, y: Float)> var area: Bool = false var line: Bool = true + var points: Bool = false var color: UIColor = ChartColors.blueColor() { didSet { colors = (above: color, below: color)