From be60addb94a3d95fa5de3af743f46b39ad474192 Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Fri, 19 Jun 2015 18:07:23 +0800 Subject: [PATCH 1/5] fix radar chart negative value rendering bug if startAtZeroEnabled is false --- .../ChartYAxisRendererRadarChart.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift index e3b3f302db..882f9e5a86 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift @@ -69,7 +69,20 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer } else { - var first = ceil(Double(yMin) / interval) * interval; + var rawValue = Double(yMin) / interval; + + var first: Double; + + // if raw value is like -0.35, ceil it will be 0, so use -1 instead + if (rawValue > -1 && rawValue < 0) + { + first = -interval; + } + else + { + first = ceil(Double(yMin) / interval) * interval; + } + if (first == 0.0 && first.isSignMinus) { first = -first; @@ -103,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); } From 8c0ce9cc64b4dee33e4e62a34771638d1ca1c73c Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Fri, 19 Jun 2015 18:51:51 +0800 Subject: [PATCH 2/5] when it is negative value, use floor instead of ceil, to guarentee the minimum value --- Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift index 882f9e5a86..55be21d801 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererRadarChart.swift @@ -73,10 +73,10 @@ public class ChartYAxisRendererRadarChart: ChartYAxisRenderer var first: Double; - // if raw value is like -0.35, ceil it will be 0, so use -1 instead - if (rawValue > -1 && rawValue < 0) + // if raw value negative, we need to minus 1. + if (rawValue < 0) { - first = -interval; + first = floor(rawValue) * interval; } else { From 948a5ab3116ad5a0097f034e327ca97bd593992d Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Mon, 29 Jun 2015 15:12:24 +0800 Subject: [PATCH 3/5] drawExtras should also be included before restoring clipped context --- Charts/Classes/Charts/BarLineChartViewBase.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Charts/Classes/Charts/BarLineChartViewBase.swift b/Charts/Classes/Charts/BarLineChartViewBase.swift index 5170b492c2..f006d440ea 100644 --- a/Charts/Classes/Charts/BarLineChartViewBase.swift +++ b/Charts/Classes/Charts/BarLineChartViewBase.swift @@ -216,12 +216,12 @@ 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); From 226221ca5d3d5da8b278d37d279646449ef352b1 Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Tue, 30 Jun 2015 11:41:24 +0800 Subject: [PATCH 4/5] fix drawing out of bound negative value axis labels issue --- Charts/Classes/Renderers/ChartYAxisRenderer.swift | 5 +++++ .../Renderers/ChartYAxisRendererHorizontalBarChart.swift | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Charts/Classes/Renderers/ChartYAxisRenderer.swift b/Charts/Classes/Renderers/ChartYAxisRenderer.swift index 981d4efa9b..8dfe45a8c7 100644 --- a/Charts/Classes/Renderers/ChartYAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartYAxisRenderer.swift @@ -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]) } } diff --git a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift index 25abe7b80c..59c6cace74 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift @@ -159,6 +159,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]) } } From 3070807e09f76d3bab52258ccdaf41e2dcfddd81 Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Thu, 2 Jul 2015 09:42:45 +0800 Subject: [PATCH 5/5] merge from upstream master --- .../Renderers/ChartYAxisRendererHorizontalBarChart.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift index 59c6cace74..9c8debc8f8 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift @@ -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)