From e3fc574d35cac0c69417c0dc0fcaa82ac5362bf5 Mon Sep 17 00:00:00 2001 From: wangyiqian Date: Fri, 17 Dec 2021 17:55:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wangyiqian/stockchart/childchart/kchart/KChart.kt | 11 +++++------ samples/build.gradle | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt index dfcaeac..a614eb8 100644 --- a/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt +++ b/lib/src/main/java/com/github/wangyiqian/stockchart/childchart/kchart/KChart.kt @@ -134,7 +134,7 @@ open class KChart( yMax = max(yMax, kEntity.getClosePrice()) } kEntity.getAvgPrice()?.let { avgPrice -> - if (chartConfig.showAvgLine) { + if (needDrawAvgPriceLine()) { yMin = min(yMin, avgPrice) yMax = max(yMax, avgPrice) } @@ -191,6 +191,7 @@ open class KChart( drawBarKChart(canvas) } } + drawAvgPriceLine(canvas) drawHighestAndLowestLabel(canvas) drawIndex(canvas) } @@ -671,12 +672,12 @@ open class KChart( ) preIdx = idx } - - drawAvgPriceLine(canvas) } + private fun needDrawAvgPriceLine() = chartConfig.showAvgLine && (chartConfig.kChartType is KChartConfig.KChartType.LINE || chartConfig.kChartType is KChartConfig.KChartType.MOUNTAIN) + private fun drawAvgPriceLine(canvas: Canvas) { - if (chartConfig.showAvgLine) { + if (needDrawAvgPriceLine()) { avgPriceLinePaint.strokeWidth = chartConfig.avgLineStrokeWidth avgPriceLinePaint.color = chartConfig.avgLineColor @@ -843,8 +844,6 @@ open class KChart( ) preIdx = idx } - - drawAvgPriceLine(canvas) } private fun drawLabels(canvas: Canvas) { diff --git a/samples/build.gradle b/samples/build.gradle index ce45362..f7bc477 100644 --- a/samples/build.gradle +++ b/samples/build.gradle @@ -70,6 +70,6 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'com.google.android:flexbox:2.0.1' -// implementation project(':lib') - implementation 'com.github.wangyiqian:StockChart:1.0.14' + implementation project(':lib') +// implementation 'com.github.wangyiqian:StockChart:1.0.14' } \ No newline at end of file