Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiqian committed Dec 17, 2021
1 parent d0ad2b6 commit e3fc574
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -191,6 +191,7 @@ open class KChart(
drawBarKChart(canvas)
}
}
drawAvgPriceLine(canvas)
drawHighestAndLowestLabel(canvas)
drawIndex(canvas)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -843,8 +844,6 @@ open class KChart(
)
preIdx = idx
}

drawAvgPriceLine(canvas)
}

private fun drawLabels(canvas: Canvas) {
Expand Down
4 changes: 2 additions & 2 deletions samples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

0 comments on commit e3fc574

Please sign in to comment.