From 10c245f4d3419f89590f049fb4a4158bc413863b Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Sun, 26 Jan 2020 12:38:42 +0200 Subject: [PATCH] Add option to draw grid lines in front of data https://github.com/PhilJay/MPAndroidChart/pull/3451 --- Source/Charts/Charts/BarLineChartViewBase.swift | 17 ++++++++++++++--- Source/Charts/Components/AxisBase.swift | 12 +++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Source/Charts/Charts/BarLineChartViewBase.swift b/Source/Charts/Charts/BarLineChartViewBase.swift index d2cda5c364..82490d23c5 100644 --- a/Source/Charts/Charts/BarLineChartViewBase.swift +++ b/Source/Charts/Charts/BarLineChartViewBase.swift @@ -208,9 +208,12 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD rightYAxisRenderer.renderAxisLine(context: context) // The renderers are responsible for clipping, to account for line-width center etc. - xAxisRenderer.renderGridLines(context: context) - leftYAxisRenderer.renderGridLines(context: context) - rightYAxisRenderer.renderGridLines(context: context) + if xAxis.drawGridLinesBehindDataEnabled + { + xAxisRenderer.renderGridLines(context: context) + leftYAxisRenderer.renderGridLines(context: context) + rightYAxisRenderer.renderGridLines(context: context) + } if _xAxis.isEnabled && _xAxis.isDrawLimitLinesBehindDataEnabled { @@ -234,6 +237,14 @@ open class BarLineChartViewBase: ChartViewBase, BarLineScatterCandleBubbleChartD } renderer.drawData(context: context) + // The renderers are responsible for clipping, to account for line-width center etc. + if !xAxis.drawGridLinesBehindDataEnabled + { + xAxisRenderer.renderGridLines(context: context) + leftYAxisRenderer.renderGridLines(context: context) + rightYAxisRenderer.renderGridLines(context: context) + } + // if highlighting is enabled if (valuesToHighlight()) { diff --git a/Source/Charts/Components/AxisBase.swift b/Source/Charts/Components/AxisBase.swift index feed16fd26..d5b653943e 100644 --- a/Source/Charts/Components/AxisBase.swift +++ b/Source/Charts/Components/AxisBase.swift @@ -63,9 +63,14 @@ open class AxisBase: ComponentBase private var _limitLines = [ChartLimitLine]() /// Are the LimitLines drawn behind the data or in front of the data? - /// + /// /// **default**: false @objc open var drawLimitLinesBehindDataEnabled = false + + /// Are the grid lines drawn behind the data or in front of the data? + /// + /// **default**: true + @objc open var drawGridLinesBehindDataEnabled = true /// the flag can be used to turn off the antialias for grid lines @objc open var gridAntialiasEnabled = true @@ -188,6 +193,11 @@ open class AxisBase: ComponentBase /// **default**: false @objc open var isDrawLimitLinesBehindDataEnabled: Bool { return drawLimitLinesBehindDataEnabled } + /// Are the grid lines drawn behind the data or in front of the data? + /// + /// **default**: true + @objc open var isDrawGridLinesBehindDataEnabled: Bool { return drawGridLinesBehindDataEnabled } + /// Extra spacing for `axisMinimum` to be added to automatically calculated `axisMinimum` @objc open var spaceMin: Double = 0.0