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

add highlight circle for radar chart #630

Merged
merged 1 commit into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Charts/Classes/Charts/RadarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public class RadarChartView: PieRadarChartViewBase
/// flag indicating if the web lines should be drawn or not
public var drawWeb = true

/// flag indicating if highlight circle should be drawn or not
public var drawHighlightCircle = true

public var circleFillColor = UIColor.whiteColor()

public var circleInnerRadius = CGFloat(3.0)

public var circleOuterRadius = CGFloat(4.0)

public var circleStrokeWidth = CGFloat(2.0)

public var circleStrokeAlpha = CGFloat(0.3)

/// modulus that determines how many labels and web-lines are skipped before the next is drawn
private var _skipWebLineCount = 0

Expand Down
47 changes: 47 additions & 0 deletions Charts/Classes/Renderers/RadarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,55 @@ public class RadarChartRenderer: LineScatterCandleRadarChartRenderer

// draw the lines
drawHighlightLines(context: context, point: _highlightPointBuffer, set: set)

if (_chart.drawHighlightCircle)
{
let p = ChartUtils.getPosition(center: center, dist: CGFloat(y) * factor,
angle: sliceangle * CGFloat(j) + _chart.rotationAngle)

if (!p.x.isNaN && !p.y.isNaN)
{
highlightDataDot(context: context, atPoint: p, innerRadius: _chart.circleInnerRadius, outerRadius: _chart.circleOuterRadius, fillColor: _chart.circleFillColor, strokeColor: set.colorAt(0), strokeWidth: _chart.circleStrokeWidth, strokeAlpha: _chart.circleStrokeAlpha)
}
}
}

CGContextRestoreGState(context)
}

internal func highlightDataDot(context context:CGContext, atPoint point:CGPoint, innerRadius:CGFloat, outerRadius:CGFloat, fillColor:UIColor, strokeColor:UIColor, strokeWidth: CGFloat, strokeAlpha: CGFloat) {
// draw inner filled dot
let innerPath = CGPathCreateMutable()

CGPathAddArc(innerPath, nil, CGFloat(point.x), CGFloat(point.y), innerRadius, CGFloat(0), CGFloat(M_PI*2), true)
CGPathCloseSubpath(innerPath)

CGContextSaveGState(context)

CGContextSetFillColorWithColor(context, fillColor.CGColor)
CGContextSetAlpha(context, CGFloat(1.0))

CGContextBeginPath(context)
CGContextAddPath(context, innerPath)
CGContextFillPath(context)

CGContextRestoreGState(context)

// draw outer stroke dot
let outerPath = CGPathCreateMutable()
CGPathAddArc(outerPath, nil, CGFloat(point.x), CGFloat(point.y), outerRadius, CGFloat(0), CGFloat(M_PI*2), true)
CGPathCloseSubpath(outerPath)

CGContextSaveGState(context)

CGContextSetStrokeColorWithColor(context, strokeColor.CGColor)
CGContextSetLineWidth(context, strokeWidth)
CGContextSetAlpha(context, strokeAlpha)

CGContextBeginPath(context)
CGContextAddPath(context, outerPath)
CGContextStrokePath(context)

CGContextRestoreGState(context)
}
}