From c6fc9986f057adca08992823494cea8696b6140b Mon Sep 17 00:00:00 2001 From: Xuan Liu Date: Thu, 20 Apr 2017 09:48:15 +0800 Subject: [PATCH] fix #2356 When `floor(10.0 * intervalMagnitude)` is 0.0, we use the old value to avoid crash at `axis.decimals = Int(ceil(-log10(interval)))` --- Source/Charts/Renderers/AxisRendererBase.swift | 3 ++- Source/Charts/Renderers/YAxisRendererRadarChart.swift | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Charts/Renderers/AxisRendererBase.swift b/Source/Charts/Renderers/AxisRendererBase.swift index 19ebf9527e..14cd25ee4d 100644 --- a/Source/Charts/Renderers/AxisRendererBase.swift +++ b/Source/Charts/Renderers/AxisRendererBase.swift @@ -119,7 +119,8 @@ open class AxisRendererBase: Renderer if intervalSigDigit > 5 { // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 - interval = floor(10.0 * Double(intervalMagnitude)) + // if it's 0.0 after floor(), we use the old value + interval = floor(10.0 * intervalMagnitude) == 0.0 ? interval : floor(10.0 * intervalMagnitude) } var n = axis.centerAxisLabelsEnabled ? 1 : 0 diff --git a/Source/Charts/Renderers/YAxisRendererRadarChart.swift b/Source/Charts/Renderers/YAxisRendererRadarChart.swift index 0e5efd23c5..5247d6c2a7 100644 --- a/Source/Charts/Renderers/YAxisRendererRadarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererRadarChart.swift @@ -56,9 +56,9 @@ open class YAxisRendererRadarChart: YAxisRenderer if intervalSigDigit > 5 { - // Use one order of magnitude higher, to avoid intervals like 0.9 or - // 90 - interval = floor(10 * intervalMagnitude) + // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 + // if it's 0.0 after floor(), we use the old value + interval = floor(10.0 * intervalMagnitude) == 0.0 ? interval : floor(10.0 * intervalMagnitude) } let centeringEnabled = axis.isCenterAxisLabelsEnabled