From aa8645c2c921d61f01927e3fe44aa516eb892a5c Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Thu, 27 Aug 2015 15:10:09 +0300 Subject: [PATCH] Avoid crashes when datasets are empty (fixes #320) --- Charts/Classes/Renderers/BarChartRenderer.swift | 2 +- Charts/Classes/Renderers/BubbleChartRenderer.swift | 4 ++-- Charts/Classes/Renderers/CandleStickChartRenderer.swift | 4 ++-- Charts/Classes/Renderers/HorizontalBarChartRenderer.swift | 2 +- Charts/Classes/Renderers/LineChartRenderer.swift | 2 +- Charts/Classes/Renderers/PieChartRenderer.swift | 2 +- Charts/Classes/Renderers/RadarChartRenderer.swift | 4 ++-- Charts/Classes/Renderers/ScatterChartRenderer.swift | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Charts/Classes/Renderers/BarChartRenderer.swift b/Charts/Classes/Renderers/BarChartRenderer.swift index cdac1ef88c..9049d4343e 100644 --- a/Charts/Classes/Renderers/BarChartRenderer.swift +++ b/Charts/Classes/Renderers/BarChartRenderer.swift @@ -293,7 +293,7 @@ public class BarChartRenderer: ChartDataRendererBase { var dataSet = dataSets[i] as! BarChartDataSet - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue } diff --git a/Charts/Classes/Renderers/BubbleChartRenderer.swift b/Charts/Classes/Renderers/BubbleChartRenderer.swift index b43e7687fc..f50ba14a96 100644 --- a/Charts/Classes/Renderers/BubbleChartRenderer.swift +++ b/Charts/Classes/Renderers/BubbleChartRenderer.swift @@ -44,7 +44,7 @@ public class BubbleChartRenderer: ChartDataRendererBase for set in bubbleData.dataSets as! [BubbleChartDataSet] { - if (set.isVisible) + if set.isVisible && set.entryCount > 0 { drawDataSet(context: context, dataSet: set) } @@ -152,7 +152,7 @@ public class BubbleChartRenderer: ChartDataRendererBase for dataSet in dataSets { - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue } diff --git a/Charts/Classes/Renderers/CandleStickChartRenderer.swift b/Charts/Classes/Renderers/CandleStickChartRenderer.swift index d1eb3c0b0b..608afbf079 100644 --- a/Charts/Classes/Renderers/CandleStickChartRenderer.swift +++ b/Charts/Classes/Renderers/CandleStickChartRenderer.swift @@ -45,7 +45,7 @@ public class CandleStickChartRenderer: LineScatterCandleRadarChartRenderer for set in candleData.dataSets as! [CandleChartDataSet] { - if (set.isVisible) + if set.isVisible && set.entryCount > 0 { drawDataSet(context: context, dataSet: set) } @@ -190,7 +190,7 @@ public class CandleStickChartRenderer: LineScatterCandleRadarChartRenderer { var dataSet = dataSets[i] - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue } diff --git a/Charts/Classes/Renderers/HorizontalBarChartRenderer.swift b/Charts/Classes/Renderers/HorizontalBarChartRenderer.swift index e6b4576937..9972228ecc 100644 --- a/Charts/Classes/Renderers/HorizontalBarChartRenderer.swift +++ b/Charts/Classes/Renderers/HorizontalBarChartRenderer.swift @@ -260,7 +260,7 @@ public class HorizontalBarChartRenderer: BarChartRenderer { var dataSet = dataSets[i] as! BarChartDataSet - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue } diff --git a/Charts/Classes/Renderers/LineChartRenderer.swift b/Charts/Classes/Renderers/LineChartRenderer.swift index 014b1c14b9..c5106b7759 100644 --- a/Charts/Classes/Renderers/LineChartRenderer.swift +++ b/Charts/Classes/Renderers/LineChartRenderer.swift @@ -418,7 +418,7 @@ public class LineChartRenderer: LineScatterCandleRadarChartRenderer { var dataSet = dataSets[i] as! LineChartDataSet - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue } diff --git a/Charts/Classes/Renderers/PieChartRenderer.swift b/Charts/Classes/Renderers/PieChartRenderer.swift index 0994b1f83f..0ce03b7e73 100755 --- a/Charts/Classes/Renderers/PieChartRenderer.swift +++ b/Charts/Classes/Renderers/PieChartRenderer.swift @@ -50,7 +50,7 @@ public class PieChartRenderer: ChartDataRendererBase { for set in pieData!.dataSets as! [PieChartDataSet] { - if (set.isVisible) + if set.isVisible && set.entryCount > 0 { drawDataSet(context: context, dataSet: set) } diff --git a/Charts/Classes/Renderers/RadarChartRenderer.swift b/Charts/Classes/Renderers/RadarChartRenderer.swift index 6598209bd8..63f7a6b808 100644 --- a/Charts/Classes/Renderers/RadarChartRenderer.swift +++ b/Charts/Classes/Renderers/RadarChartRenderer.swift @@ -36,7 +36,7 @@ public class RadarChartRenderer: LineScatterCandleRadarChartRenderer { for set in radarData!.dataSets as! [RadarChartDataSet] { - if (set.isVisible) + if set.isVisible && set.entryCount > 0 { drawDataSet(context: context, dataSet: set) } @@ -133,7 +133,7 @@ public class RadarChartRenderer: LineScatterCandleRadarChartRenderer { var dataSet = data.getDataSetByIndex(i) as! RadarChartDataSet - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue } diff --git a/Charts/Classes/Renderers/ScatterChartRenderer.swift b/Charts/Classes/Renderers/ScatterChartRenderer.swift index 0fd6ccd1f7..8e723b5096 100644 --- a/Charts/Classes/Renderers/ScatterChartRenderer.swift +++ b/Charts/Classes/Renderers/ScatterChartRenderer.swift @@ -191,7 +191,7 @@ public class ScatterChartRenderer: LineScatterCandleRadarChartRenderer { var dataSet = dataSets[i] - if (!dataSet.isDrawValuesEnabled) + if !dataSet.isDrawValuesEnabled || dataSet.entryCount == 0 { continue }