diff --git a/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift b/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift index 796c757290..5ff9a87305 100644 --- a/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift +++ b/Source/Charts/Renderers/BarLineScatterCandleBubbleRenderer.swift @@ -26,15 +26,7 @@ open class BarLineScatterCandleBubbleRenderer: DataRenderer @objc internal func isInBoundsX(entry e: ChartDataEntry, dataSet: IBarLineScatterCandleBubbleChartDataSet) -> Bool { let entryIndex = dataSet.entryIndex(entry: e) - - if Double(entryIndex) >= Double(dataSet.entryCount) * (animator?.phaseX ?? 1.0) - { - return false - } - else - { - return true - } + return Double(entryIndex) < Double(dataSet.entryCount) * (animator?.phaseX ?? 1.0) } /// Calculates and returns the x-bounds for the given DataSet in terms of index in their values array. @@ -94,5 +86,4 @@ open class BarLineScatterCandleBubbleRenderer: DataRenderer range = Int(Double(self.max - self.min) * phaseX) } } - } diff --git a/Source/Charts/Renderers/BubbleChartRenderer.swift b/Source/Charts/Renderers/BubbleChartRenderer.swift index 4f4265db3b..d77311c459 100644 --- a/Source/Charts/Renderers/BubbleChartRenderer.swift +++ b/Source/Charts/Renderers/BubbleChartRenderer.swift @@ -35,12 +35,9 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let bubbleData = dataProvider.bubbleData else { return } - for set in bubbleData.dataSets as! [IBubbleChartDataSet] + for set in bubbleData.dataSets as! [IBubbleChartDataSet] where set.isVisible { - if set.isVisible - { - drawDataSet(context: context, dataSet: set) - } + drawDataSet(context: context, dataSet: set) } } @@ -84,6 +81,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer trans.pointValuesToPixel(&_sizeBuffer) context.saveGState() + defer { context.restoreGState() } let normalizeSize = dataSet.isNormalizeSizeEnabled @@ -103,21 +101,13 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer let shapeSize = getShapeSize(entrySize: entry.size, maxSize: dataSet.maxSize, reference: referenceSize, normalizeSize: normalizeSize) let shapeHalf = shapeSize / 2.0 - if !viewPortHandler.isInBoundsTop(_pointBuffer.y + shapeHalf) - || !viewPortHandler.isInBoundsBottom(_pointBuffer.y - shapeHalf) - { - continue - } - - if !viewPortHandler.isInBoundsLeft(_pointBuffer.x + shapeHalf) - { - continue - } - - if !viewPortHandler.isInBoundsRight(_pointBuffer.x - shapeHalf) - { - break - } + guard + viewPortHandler.isInBoundsTop(_pointBuffer.y + shapeHalf), + viewPortHandler.isInBoundsBottom(_pointBuffer.y - shapeHalf), + viewPortHandler.isInBoundsLeft(_pointBuffer.x + shapeHalf) + else { continue } + + guard viewPortHandler.isInBoundsRight(_pointBuffer.x - shapeHalf) else { break } let color = dataSet.color(atIndex: Int(entry.x)) @@ -131,100 +121,88 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer context.setFillColor(color.cgColor) context.fillEllipse(in: rect) } - - context.restoreGState() } open override func drawValues(context: CGContext) { - guard let - dataProvider = dataProvider, + guard + let dataProvider = dataProvider, let viewPortHandler = self.viewPortHandler, let bubbleData = dataProvider.bubbleData, - let animator = animator + let animator = animator, + isDrawingValuesAllowed(dataProvider: dataProvider), + let dataSets = bubbleData.dataSets as? [IBubbleChartDataSet] else { return } - - // if values are drawn - if isDrawingValuesAllowed(dataProvider: dataProvider) + + let phaseX = max(0.0, min(1.0, animator.phaseX)) + let phaseY = animator.phaseY + + var pt = CGPoint() + + for i in 0..