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

fix radar chart negative value rendering bug if startAtZeroEnabled is false for issue #166 #168

Closed
wants to merge 9 commits into from
6 changes: 3 additions & 3 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
renderer?.drawHighlighted(context: context, indices: _indicesToHightlight)
}

// Removes clipping rectangle
CGContextRestoreGState(context)

renderer!.drawExtras(context: context)

// Removes clipping rectangle
CGContextRestoreGState(context)

_xAxisRenderer.renderAxisLabels(context: context)
_leftYAxisRenderer.renderAxisLabels(context: context)
_rightYAxisRenderer.renderAxisLabels(context: context)
Expand Down
5 changes: 5 additions & 0 deletions Charts/Classes/Renderers/ChartYAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public class ChartYAxisRenderer: ChartAxisRendererBase
pt.x = fixedPosition
pt.y += offset

if (pt.y > viewPortHandler.contentRect.height)
{
continue
}

ChartUtils.drawText(context: context, text: text, point: pt, align: textAlign, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ public class ChartYAxisRendererHorizontalBarChart: ChartYAxisRenderer
var labelFont = _yAxis.labelFont
var labelTextColor = _yAxis.labelTextColor

for (var i = 0; i < _yAxis.entryCount; i++)
var labelWidth = _yAxis.requiredSize().width

var modulus = Int(ceil((CGFloat(_yAxis.entryCount) * labelWidth) / (viewPortHandler.contentWidth * viewPortHandler.touchMatrix.a)))

for (var i = 0; i < _yAxis.entryCount; i += modulus)
{
var text = _yAxis.getFormattedLabel(i)

Expand All @@ -159,6 +163,11 @@ public class ChartYAxisRendererHorizontalBarChart: ChartYAxisRenderer
return
}

if (positions[i].x < viewPortHandler.contentRect.origin.x)
{
continue
}

ChartUtils.drawText(context: context, text: text, point: CGPoint(x: positions[i].x, y: fixedPosition - offset), align: .Center, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor])
}
}
Expand Down
18 changes: 16 additions & 2 deletions Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,19 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer
}
else
{
var first = ceil(Double(yMin) / interval) * interval
var rawValue = Double(yMin) / interval

var first: Double;

// if raw value negative, we need to use floor rather than ceil
if (rawValue < 0)
{
first = floor(rawValue) * interval
}
else
{
first = ceil(Double(yMin) / interval) * interval
}

if (first == 0.0)
{ // Fix for IEEE negative zero case (Where value == -0.0, and 0.0 == -0.0)
Expand Down Expand Up @@ -104,6 +116,8 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer
}

_yAxis.axisMaximum = _yAxis.entries[_yAxis.entryCount - 1]
// set axisMinimum to be the minimum value.
_yAxis.axisMinimum = _yAxis.entries[0]
_yAxis.axisRange = abs(_yAxis.axisMaximum - _yAxis.axisMinimum)
}

Expand Down Expand Up @@ -199,4 +213,4 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer

CGContextRestoreGState(context)
}
}
}