From 509251222e32831bc704933a3e24fb78bcdb3687 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 0032c13dc2..b5fecfa811 100644 --- a/Source/Charts/Renderers/AxisRendererBase.swift +++ b/Source/Charts/Renderers/AxisRendererBase.swift @@ -127,7 +127,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 bd04c08470..1a49373521 100644 --- a/Source/Charts/Renderers/YAxisRendererRadarChart.swift +++ b/Source/Charts/Renderers/YAxisRendererRadarChart.swift @@ -60,9 +60,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