Skip to content

Commit

Permalink
Merge branch 'liuxuan30-radar+negative_value'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Aug 12, 2015
2 parents 78e5df8 + 4b0ea28 commit 2068a5c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Charts/Classes/Charts/BarLineChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
// If the values are all negative, let's stay in the negative zone
_leftAxis.axisMaximum = 0.0
}
else
else if _leftAxis.axisMinimum >= 0.0
{
// We have positive values, stay in the positive zone
// We have positive values only, stay in the positive zone
_leftAxis.axisMinimum = 0.0
}
}
Expand All @@ -346,9 +346,9 @@ public class BarLineChartViewBase: ChartViewBase, UIGestureRecognizerDelegate
// If the values are all negative, let's stay in the negative zone
_rightAxis.axisMaximum = 0.0
}
else
else if _rightAxis.axisMinimum >= 0.0
{
// We have positive values, stay in the positive zone
// We have positive values only, stay in the positive zone
_rightAxis.axisMinimum = 0.0
}
}
Expand Down
2 changes: 1 addition & 1 deletion Charts/Classes/Charts/RadarChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class RadarChartView: PieRadarChartViewBase
// consider starting at zero (0)
if (_yAxis.isStartAtZeroEnabled)
{
_yAxis.axisMinimum = 0.0
_yAxis.axisMinimum = min(0.0, _yAxis.axisMinimum)
}

_yAxis.axisRange = abs(_yAxis.axisMaximum - _yAxis.axisMinimum)
Expand Down
4 changes: 3 additions & 1 deletion Charts/Classes/Renderers/ChartYAxisRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public class ChartYAxisRenderer: ChartAxisRendererBase
v += step
}

} else {
}
else
{
// no forced count

// if the labels should only show min and max
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 @@ -78,7 +78,9 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer
v += step
}

} else {
}
else
{
// no forced count

// clean old values
Expand All @@ -96,7 +98,13 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer
}
else
{
var first = ceil(Double(yMin) / interval) * interval
let rawCount = Double(yMin) / interval
var first = rawCount < 0.0 ? floor(rawCount) * interval : ceil(rawCount) * interval;

if (first < yMin && _yAxis.isStartAtZeroEnabled)
{ // Force the first label to be at the 0 (or smallest negative value)
first = yMin
}

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

if !_yAxis.isStartAtZeroEnabled && _yAxis.entries[0] < yMin
{
// If startAtZero is disabled, and the first label is lower that the axis minimum,
// Then adjust the axis minimum
_yAxis.axisMinimum = _yAxis.entries[0]
}
_yAxis.axisMaximum = _yAxis.entries[_yAxis.entryCount - 1]
_yAxis.axisRange = abs(_yAxis.axisMaximum - _yAxis.axisMinimum)
}
Expand Down

0 comments on commit 2068a5c

Please sign in to comment.