From cc5ab9b9dff61d05d7b8df3f7681779a16505989 Mon Sep 17 00:00:00 2001 From: Dor Alon Date: Wed, 1 Jul 2015 17:22:56 +0300 Subject: [PATCH 1/2] #122 Candle chart - make the shadow same color as an increasing/decreasing candle color --- Charts/Classes/Data/CandleChartDataSet.swift | 3 +++ .../Renderers/CandleStickChartRenderer.swift | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Charts/Classes/Data/CandleChartDataSet.swift b/Charts/Classes/Data/CandleChartDataSet.swift index ad1c2b11df..b285bfc64d 100644 --- a/Charts/Classes/Data/CandleChartDataSet.swift +++ b/Charts/Classes/Data/CandleChartDataSet.swift @@ -28,6 +28,9 @@ public class CandleChartDataSet: BarLineScatterCandleChartDataSet /// the color of the shadow line public var shadowColor: UIColor? + /// use candle color for the shadow + public var makeShadowSameColorAsCandle = false + /// color for open <= close public var decreasingColor: UIColor? diff --git a/Charts/Classes/Renderers/CandleStickChartRenderer.swift b/Charts/Classes/Renderers/CandleStickChartRenderer.swift index 7747fa8c9b..957a99f9a5 100644 --- a/Charts/Classes/Renderers/CandleStickChartRenderer.swift +++ b/Charts/Classes/Renderers/CandleStickChartRenderer.swift @@ -98,7 +98,20 @@ public class CandleStickChartRenderer: ChartDataRendererBase // draw the shadow - CGContextSetStrokeColorWithColor(context, (dataSet.shadowColor ?? dataSet.colorAt(j)).CGColor) + var shadowColor = dataSet.shadowColor ?? dataSet.colorAt(j) + if (dataSet.makeShadowSameColorAsCandle) + { + if (e.open > e.close) + { + shadowColor = dataSet.decreasingColor ?? dataSet.colorAt(j) + } + else if (e.open < e.close) + { + shadowColor = dataSet.increasingColor ?? dataSet.colorAt(j) + } + } + + CGContextSetStrokeColorWithColor(context, shadowColor.CGColor); CGContextStrokeLineSegments(context, _shadowPoints, 2) @@ -112,7 +125,12 @@ public class CandleStickChartRenderer: ChartDataRendererBase trans.rectValueToPixel(&_bodyRect) // draw body differently for increasing and decreasing entry - if (e.open >= e.close) + + if (e.open == e.close) { + CGContextSetStrokeColorWithColor(context, shadowColor.CGColor) + CGContextStrokeRect(context, _bodyRect) + } + else if (e.open > e.close) { var color = dataSet.decreasingColor ?? dataSet.colorAt(j) From fe03a4268e84d7dfe09278e3dd4591ee468e576c Mon Sep 17 00:00:00 2001 From: Dor Alon Date: Wed, 1 Jul 2015 17:24:54 +0300 Subject: [PATCH 2/2] #182 ChartData.removeEntryByXIndex removes the wrong entry --- Charts/Classes/Data/ChartData.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Charts/Classes/Data/ChartData.swift b/Charts/Classes/Data/ChartData.swift index 9d8ac45636..c3bce20015 100644 --- a/Charts/Classes/Data/ChartData.swift +++ b/Charts/Classes/Data/ChartData.swift @@ -687,6 +687,10 @@ public class ChartData: NSObject var entry = _dataSets[dataSetIndex].entryForXIndex(xIndex) + if (entry?.xIndex != xIndex) { + return false + } + return removeEntry(entry, dataSetIndex: dataSetIndex) }