From d7769e6aa4c58e76a4f0b9325ea54c01ada582c4 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Mon, 15 Aug 2016 15:22:05 +0300 Subject: [PATCH] Take care of edge cases when calculating intervals (labelCount == 0) --- Charts/Classes/Renderers/AxisRendererBase.swift | 6 +++++- Charts/Classes/Renderers/YAxisRendererRadarChart.swift | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Charts/Classes/Renderers/AxisRendererBase.swift b/Charts/Classes/Renderers/AxisRendererBase.swift index eb6716a5c7..629d77087b 100644 --- a/Charts/Classes/Renderers/AxisRendererBase.swift +++ b/Charts/Classes/Renderers/AxisRendererBase.swift @@ -110,7 +110,11 @@ public class AxisRendererBase: Renderer } // Find out how much spacing (in y value space) between axis values - let rawInterval = range / Double(labelCount) + var rawInterval = range / Double(labelCount) + if isinf(rawInterval) + { + rawInterval = range > 0.0 && !isinf(range) ? range : 1.0 + } var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval)) // If granularity is enabled, then do not allow the interval to go below specified granularity. diff --git a/Charts/Classes/Renderers/YAxisRendererRadarChart.swift b/Charts/Classes/Renderers/YAxisRendererRadarChart.swift index 89a9a75094..6a755bbc98 100644 --- a/Charts/Classes/Renderers/YAxisRendererRadarChart.swift +++ b/Charts/Classes/Renderers/YAxisRendererRadarChart.swift @@ -43,7 +43,11 @@ public class YAxisRendererRadarChart: YAxisRenderer } // Find out how much spacing (in yValue space) between axis values - let rawInterval = range / Double(labelCount) + var rawInterval = range / Double(labelCount) + if isinf(rawInterval) + { + rawInterval = range > 0.0 && !isinf(range) ? range : 1.0 + } var interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval)) // If granularity is enabled, then do not allow the interval to go below specified granularity.