@@ -123,8 +123,6 @@ open class PieChartRenderer: NSObject, DataRenderer
123123 let drawAngles = chart. drawAngles
124124 let center = chart. centerCircleBox
125125 let radius = chart. radius
126- let drawInnerArc = chart. drawHoleEnabled && !chart. drawSlicesUnderHoleEnabled
127- let userInnerRadius = drawInnerArc ? radius * chart. holeRadiusPercent : 0.0
128126
129127 var visibleAngleCount = 0
130128 for j in 0 ..< entryCount
@@ -137,6 +135,8 @@ open class PieChartRenderer: NSObject, DataRenderer
137135 }
138136
139137 let sliceSpace = visibleAngleCount <= 1 ? 0.0 : getSliceSpace ( dataSet: dataSet)
138+ let drawInnerArc = chart. drawHoleEnabled && !chart. drawSlicesUnderHoleEnabled || sliceSpace > 0.0
139+ let userInnerRadius = drawInnerArc ? radius * chart. holeRadiusPercent : 0.0
140140
141141 context. saveGState ( )
142142
@@ -180,7 +180,7 @@ open class PieChartRenderer: NSObject, DataRenderer
180180 continue
181181 }
182182
183- let accountForSliceSpacing = sliceSpace > 0.0 && sliceAngle <= 180.0
183+ let accountForSliceSpacing = sliceSpace > 0.0
184184
185185 context. setFillColor ( dataSet. color ( atIndex: j) . cgColor)
186186
@@ -207,6 +207,8 @@ open class PieChartRenderer: NSObject, DataRenderer
207207 if drawInnerArc &&
208208 ( innerRadius > 0.0 || accountForSliceSpacing)
209209 {
210+ var hasZeroInnerRadius = innerRadius == 0.0
211+
210212 if accountForSliceSpacing
211213 {
212214 var minSpacedRadius = calculateMinimumRadiusForSpacedSlice (
@@ -235,42 +237,29 @@ open class PieChartRenderer: NSObject, DataRenderer
235237 }
236238 let endAngleInner = startAngleInner + sweepAngleInner
237239
238- path. addLine (
239- to: CGPoint (
240- x: center. x + innerRadius * cos( endAngleInner. DEG2RAD) ,
241- y: center. y + innerRadius * sin( endAngleInner. DEG2RAD) ) )
242-
243- path. addRelativeArc ( center: center, radius: innerRadius, startAngle: endAngleInner. DEG2RAD, delta: - sweepAngleInner. DEG2RAD)
244- }
245- else
246- {
247- if accountForSliceSpacing
240+ if sliceAngle > 180.0 && hasZeroInnerRadius && accountForSliceSpacing
248241 {
249- let angleMiddle = startAngleOuter + sweepAngleOuter / 2.0
250-
251- let sliceSpaceOffset =
252- calculateMinimumRadiusForSpacedSlice (
253- center: center,
254- radius: radius,
255- angle: sliceAngle * CGFloat( phaseY) ,
256- arcStartPointX: arcStartPointX,
257- arcStartPointY: arcStartPointY,
258- startAngle: startAngleOuter,
259- sweepAngle: sweepAngleOuter)
260-
261- let arcEndPointX = center. x + sliceSpaceOffset * cos( angleMiddle. DEG2RAD)
262- let arcEndPointY = center. y + sliceSpaceOffset * sin( angleMiddle. DEG2RAD)
242+ let midAngleInner = ( startAngleInner + endAngleInner) / 2
263243
264244 path. addLine (
265245 to: CGPoint (
266- x: arcEndPointX ,
267- y: arcEndPointY ) )
246+ x: center . x + innerRadius * cos ( midAngleInner . DEG2RAD ) ,
247+ y: center . y + innerRadius * sin ( midAngleInner . DEG2RAD ) ) )
268248 }
269249 else
270250 {
271- path. addLine ( to: center)
251+ path. addLine (
252+ to: CGPoint (
253+ x: center. x + innerRadius * cos( endAngleInner. DEG2RAD) ,
254+ y: center. y + innerRadius * sin( endAngleInner. DEG2RAD) ) )
255+
256+ path. addRelativeArc ( center: center, radius: innerRadius, startAngle: endAngleInner. DEG2RAD, delta: - sweepAngleInner. DEG2RAD)
272257 }
273258 }
259+ else
260+ {
261+ path. addLine ( to: center)
262+ }
274263
275264 path. closeSubpath ( )
276265
@@ -518,7 +507,7 @@ open class PieChartRenderer: NSObject, DataRenderer
518507 {
519508 // calculate the text position
520509 let x = labelRadius * sliceXBase + center. x
521- let y = labelRadius * sliceYBase + center. y - lineHeight
510+ let y = labelRadius * sliceYBase + center. y - lineHeight / 2.0
522511
523512 if drawXInside && drawYInside
524513 {
@@ -716,8 +705,6 @@ open class PieChartRenderer: NSObject, DataRenderer
716705 let absoluteAngles = chart. absoluteAngles
717706 let center = chart. centerCircleBox
718707 let radius = chart. radius
719- let drawInnerArc = chart. drawHoleEnabled && !chart. drawSlicesUnderHoleEnabled
720- let userInnerRadius = drawInnerArc ? radius * chart. holeRadiusPercent : 0.0
721708
722709 // Append highlighted accessibility slices into this array, so we can prioritize them over unselected slices
723710 var highlightedAccessibleElements : [ NSUIAccessibilityElement ] = [ ]
@@ -755,14 +742,16 @@ open class PieChartRenderer: NSObject, DataRenderer
755742 }
756743
757744 let sliceSpace = visibleAngleCount <= 1 ? 0.0 : set. sliceSpace
745+ let drawInnerArc = chart. drawHoleEnabled && !chart. drawSlicesUnderHoleEnabled || sliceSpace > 0.0
746+ let userInnerRadius = drawInnerArc ? radius * chart. holeRadiusPercent : 0.0
758747
759748 let sliceAngle = drawAngles [ index]
760749 var innerRadius = userInnerRadius
761750
762751 let shift = set. selectionShift
763752 let highlightedRadius = radius + shift
764753
765- let accountForSliceSpacing = sliceSpace > 0.0 && sliceAngle <= 180.0
754+ let accountForSliceSpacing = sliceSpace > 0.0
766755
767756 context. setFillColor ( set. highlightColor? . cgColor ?? set. color ( atIndex: index) . cgColor)
768757
@@ -812,6 +801,8 @@ open class PieChartRenderer: NSObject, DataRenderer
812801 if drawInnerArc &&
813802 ( innerRadius > 0.0 || accountForSliceSpacing)
814803 {
804+ var hasZeroInnerRadius = innerRadius == 0.0
805+
815806 if accountForSliceSpacing
816807 {
817808 var minSpacedRadius = sliceSpaceRadius
@@ -833,34 +824,31 @@ open class PieChartRenderer: NSObject, DataRenderer
833824 }
834825 let endAngleInner = startAngleInner + sweepAngleInner
835826
836- path. addLine (
837- to: CGPoint (
838- x: center. x + innerRadius * cos( endAngleInner. DEG2RAD) ,
839- y: center. y + innerRadius * sin( endAngleInner. DEG2RAD) ) )
840-
841- path. addRelativeArc ( center: center, radius: innerRadius,
842- startAngle: endAngleInner. DEG2RAD,
843- delta: - sweepAngleInner. DEG2RAD)
844- }
845- else
846- {
847- if accountForSliceSpacing
827+ if sliceAngle > 180.0 && hasZeroInnerRadius && accountForSliceSpacing
848828 {
849- let angleMiddle = startAngleOuter + sweepAngleOuter / 2.0
850-
851- let arcEndPointX = center. x + sliceSpaceRadius * cos( angleMiddle. DEG2RAD)
852- let arcEndPointY = center. y + sliceSpaceRadius * sin( angleMiddle. DEG2RAD)
829+ let midAngleInner = ( startAngleInner + endAngleInner) / 2
853830
854831 path. addLine (
855832 to: CGPoint (
856- x: arcEndPointX ,
857- y: arcEndPointY ) )
833+ x: center . x + innerRadius * cos ( midAngleInner . DEG2RAD ) ,
834+ y: center . y + innerRadius * sin ( midAngleInner . DEG2RAD ) ) )
858835 }
859836 else
860837 {
861- path. addLine ( to: center)
838+ path. addLine (
839+ to: CGPoint (
840+ x: center. x + innerRadius * cos( endAngleInner. DEG2RAD) ,
841+ y: center. y + innerRadius * sin( endAngleInner. DEG2RAD) ) )
842+
843+ path. addRelativeArc ( center: center, radius: innerRadius,
844+ startAngle: endAngleInner. DEG2RAD,
845+ delta: - sweepAngleInner. DEG2RAD)
862846 }
863847 }
848+ else
849+ {
850+ path. addLine ( to: center)
851+ }
864852
865853 path. closeSubpath ( )
866854
0 commit comments